Package com.sun.org.apache.bcel.internal.generic

Examples of com.sun.org.apache.bcel.internal.generic.LocalVariableGen


  /*
   * The scope of this local var must be the entire method since
   * a another pattern may decide to jump back into the loop
   */
  final LocalVariableGen local =
      methodGen.addLocalVariable2("app", Util.getJCRefType(NODE_SIG),
          il.getEnd());

  final com.sun.org.apache.bcel.internal.generic.Instruction loadLocal =
      new ILOAD(local.getIndex());
  final com.sun.org.apache.bcel.internal.generic.Instruction storeLocal =
      new ISTORE(local.getIndex());

  if (_right instanceof StepPattern) {
      il.append(DUP);
      il.append(storeLocal);
      _right.translate(classGen, methodGen);
      il.append(methodGen.loadDOM());
      il.append(loadLocal);
  }
  else {
      _right.translate(classGen, methodGen);

      if (_right instanceof AncestorPattern) {
    il.append(methodGen.loadDOM());
    il.append(SWAP);
      }
  }

  if (_left != null) {
      final int getParent = cpg.addInterfaceMethodref(DOM_INTF,
                  GET_PARENT,
                  GET_PARENT_SIG);
      parent = il.append(new INVOKEINTERFACE(getParent, 2));
     
      il.append(DUP);
      il.append(storeLocal);
      _falseList.add(il.append(new IFLT(null)));
      il.append(loadLocal);

      _left.translate(classGen, methodGen);

      final SyntaxTreeNode p = getParent();
      if (p == null || p instanceof Instruction ||
    p instanceof TopLevelElement)
      {
    // do nothing
      }
      else {
    il.append(loadLocal);
      }

      final BranchHandle exit = il.append(new GOTO(null));
      _loop = il.append(methodGen.loadDOM());
      il.append(loadLocal);
      local.setEnd(_loop);
      il.append(new GOTO(parent));
      exit.setTarget(il.append(NOP));
      _left.backPatchFalseList(_loop);

      _trueList.append(_left._trueList)
View Full Code Here


     * @see  com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateToDesynthesized
     */
    public FlowList translateToDesynthesized(ClassGenerator classGen,
               MethodGenerator methodGen,
               BooleanType type) {
  LocalVariableGen local;
  final FlowList flowlist = new FlowList();
  final ConstantPoolGen cpg = classGen.getConstantPool();
  final InstructionList il = methodGen.getInstructionList();

  // Store real into a local variable
  il.append(DUP2);
  local = methodGen.addLocalVariable("real_to_boolean_tmp",
             com.sun.org.apache.bcel.internal.generic.Type.DOUBLE,
             il.getEnd(), null);
  il.append(new DSTORE(local.getIndex()));

  // Compare it to 0.0
  il.append(DCONST_0);
  il.append(DCMPG);
  flowlist.add(il.append(new IFEQ(null)));

  //!!! call isNaN
  // Compare it to itself to see if NaN
  il.append(new DLOAD(local.getIndex()));
  il.append(new DLOAD(local.getIndex()));
  il.append(DCMPG);
  flowlist.add(il.append(new IFNE(null)))// NaN != NaN
  return flowlist;
    }
View Full Code Here

     * (iv) calls startElement() on the handler (v) looks up a uri in the XML
     * when the prefix is not known at compile time (vi) calls namespace()
     * on the handler (vii) evaluates the contents (viii) calls endElement().
     */
    public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
  LocalVariableGen local = null;
  final ConstantPoolGen cpg = classGen.getConstantPool();
  final InstructionList il = methodGen.getInstructionList();

  // Optimize translation if element name is a literal
  if (_isLiteralName) {
      translateLiteral(classGen, methodGen);
      return;
  }

  if (!_ignore) {
      
            // if the qname is an AVT, then the qname has to be checked at runtime if it is a valid qname
            LocalVariableGen nameValue = methodGen.addLocalVariable2("nameValue",
                    Util.getJCRefType(STRING_SIG),
                    il.getEnd());
                   
            // store the name into a variable first so _name.translate only needs to be called once 
            _name.translate(classGen, methodGen);
            il.append(new ASTORE(nameValue.getIndex()));
            il.append(new ALOAD(nameValue.getIndex()));
           
            // call checkQName if the name is an AVT
            final int check = cpg.addMethodref(BASIS_LIBRARY_CLASS, "checkQName",
                            "("
                            +STRING_SIG
                            +")V");                
            il.append(new INVOKESTATIC(check));
           
            // Push handler for call to endElement()
            il.append(methodGen.loadHandler());        
           
            // load name value again   
            il.append(new ALOAD(nameValue.getIndex()))
                   
      if (_namespace != null) {
    _namespace.translate(classGen, methodGen);
      }
      else {
View Full Code Here

     * Notice that local variables need to be "unboxed".
     */
    private void compileFilter(ClassGenerator classGen,
             MethodGenerator methodGen) {
  TestGenerator testGen;
  LocalVariableGen local;
  FilterGenerator filterGen;

  _className = getXSLTC().getHelperClassName();
  filterGen = new FilterGenerator(_className,
          "java.lang.Object",
          toString(),
          ACC_PUBLIC | ACC_SUPER,
          new String[] {
              CURRENT_NODE_LIST_FILTER
          },
          classGen.getStylesheet())

  final ConstantPoolGen cpg = filterGen.getConstantPool();
  final int length = (_closureVars == null) ? 0 : _closureVars.size();

  // Add a new instance variable for each var in closure
  for (int i = 0; i < length; i++) {
      VariableBase var = ((VariableRefBase) _closureVars.get(i)).getVariable();

      filterGen.addField(new Field(ACC_PUBLIC,
          cpg.addUtf8(var.getEscapedName()),
          cpg.addUtf8(var.getType().toSignature()),
          null, cpg.getConstantPool()));
  }

  final InstructionList il = new InstructionList();
  testGen = new TestGenerator(ACC_PUBLIC | ACC_FINAL,
            com.sun.org.apache.bcel.internal.generic.Type.BOOLEAN,
            new com.sun.org.apache.bcel.internal.generic.Type[] {
          com.sun.org.apache.bcel.internal.generic.Type.INT,
          com.sun.org.apache.bcel.internal.generic.Type.INT,
          com.sun.org.apache.bcel.internal.generic.Type.INT,
          com.sun.org.apache.bcel.internal.generic.Type.INT,
          Util.getJCRefType(TRANSLET_SIG),
          Util.getJCRefType(NODE_ITERATOR_SIG)
            },
            new String[] {
          "node",
          "position",
          "last",
          "current",
          "translet",
          "iterator"
            },
            "test", _className, il, cpg);
   
  // Store the dom in a local variable
  local = testGen.addLocalVariable("document",
           Util.getJCRefType(DOM_INTF_SIG),
           null, null);
  final String className = classGen.getClassName();
  il.append(filterGen.loadTranslet());
  il.append(new CHECKCAST(cpg.addClass(className)));
  il.append(new GETFIELD(cpg.addFieldref(className,
                 DOM_FIELD, DOM_INTF_SIG)));
  il.append(new ASTORE(local.getIndex()));

  // Store the dom index in the test generator
  testGen.setDomIndex(local.getIndex());

  _exp.translate(filterGen, testGen);
  il.append(IRETURN);
 
  testGen.stripAttributes(true);
View Full Code Here

        getClassName(), mainIL,
        classGen.getConstantPool());
  methodGen.addException("com.sun.org.apache.xalan.internal.xsltc.TransletException");

  // Create a local variable to hold the current node
  final LocalVariableGen current;
  current = methodGen.addLocalVariable2("current",
                com.sun.org.apache.bcel.internal.generic.Type.INT,
                mainIL.getEnd());
  _currentIndex = current.getIndex();

  // Create the "body" instruction list that will eventually hold the
  // code for the entire method (other ILs will be appended).
  final InstructionList body = new InstructionList();
  body.append(NOP);
View Full Code Here

        getClassName(), mainIL,
        classGen.getConstantPool());
  methodGen.addException("com.sun.org.apache.xalan.internal.xsltc.TransletException");

  // Create the local variable to hold the current node
  final LocalVariableGen current;
  current = methodGen.addLocalVariable2("current",
                com.sun.org.apache.bcel.internal.generic.Type.INT,
                mainIL.getEnd());
  _currentIndex = current.getIndex();

    mainIL.append(new ILOAD(methodGen.getLocalIndex(NODE_PNAME)));
    mainIL.append(new ISTORE(_currentIndex));
   
  // Create the "body" instruction list that will eventually hold the
View Full Code Here

    }

    public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
  final ConstantPoolGen cpg = classGen.getConstantPool();
  final InstructionList il = methodGen.getInstructionList();
  final LocalVariableGen local =
      methodGen.addLocalVariable2("ppt",
          Util.getJCRefType(NODE_SIG),
          il.getEnd());
 
  final com.sun.org.apache.bcel.internal.generic.Instruction loadLocal =
      new ILOAD(local.getIndex());
  final com.sun.org.apache.bcel.internal.generic.Instruction storeLocal =
      new ISTORE(local.getIndex());

  if (_right.isWildcard()) {
      il.append(methodGen.loadDOM());
      il.append(SWAP);
  }
  else if (_right instanceof StepPattern) {
      il.append(DUP);
      il.append(storeLocal);
     
      _right.translate(classGen, methodGen);
     
      il.append(methodGen.loadDOM());
      local.setEnd(il.append(loadLocal));
  }
  else {
      _right.translate(classGen, methodGen);

      if (_right instanceof AncestorPattern) {
    il.append(methodGen.loadDOM());
    il.append(SWAP);
      }
  }

  final int getParent = cpg.addInterfaceMethodref(DOM_INTF,
              GET_PARENT,
              GET_PARENT_SIG);
  il.append(new INVOKEINTERFACE(getParent, 2));

  final SyntaxTreeNode p = getParent();
  if (p == null || p instanceof Instruction ||
      p instanceof TopLevelElement)
  {
      _left.translate(classGen, methodGen);
  }
  else {
      il.append(DUP);
      il.append(storeLocal);
     
      _left.translate(classGen, methodGen);

      il.append(methodGen.loadDOM());
      local.setEnd(il.append(loadLocal));
  }

  methodGen.removeLocalVariable(local);
 
  /*
 
View Full Code Here

  int index;
  final ConstantPoolGen cpg = classGen.getConstantPool();
  final InstructionList il = methodGen.getInstructionList();

  // Store matching node into a local variable
  LocalVariableGen match;
  match = methodGen.addLocalVariable("step_pattern_tmp1",
             Util.getJCRefType(NODE_SIG),
             il.getEnd(), null);
  il.append(new ISTORE(match.getIndex()));

  // If pattern not reduced then check kernel
  if (!_isEpsilon) {
      il.append(new ILOAD(match.getIndex()));
       translateKernel(classGen, methodGen);
  }

  // Push current iterator and current node on the stack
  il.append(methodGen.loadCurrentNode());
  il.append(methodGen.loadIterator());

  // Create a new matching iterator using the matching node
  index = cpg.addMethodref(MATCHING_ITERATOR, "<init>",
         "(I" + NODE_ITERATOR_SIG + ")V");

        // Backwards branches are prohibited if an uninitialized object is
        // on the stack by section 4.9.4 of the JVM Specification, 2nd Ed.
        // We don't know whether this code might contain backwards branches,
        // so we mustn't create the new object until after we've created
        // the suspect arguments to its constructor.  Instead we calculate
        // the values of the arguments to the constructor first, store them
        // in temporary variables, create the object and reload the
        // arguments from the temporaries to avoid the problem.

  _step.translate(classGen, methodGen);
        LocalVariableGen stepIteratorTemp =
                methodGen.addLocalVariable("step_pattern_tmp2",
                                           Util.getJCRefType(NODE_ITERATOR_SIG),
                                           il.getEnd(), null);
        il.append(new ASTORE(stepIteratorTemp.getIndex()));

  il.append(new NEW(cpg.addClass(MATCHING_ITERATOR)));
  il.append(DUP);
  il.append(new ILOAD(match.getIndex()));
        il.append(new ALOAD(stepIteratorTemp.getIndex()));
  il.append(new INVOKESPECIAL(index));

  // Get the parent of the matching node
  il.append(methodGen.loadDOM());
  il.append(new ILOAD(match.getIndex()));
View Full Code Here

  final ConstantPoolGen cpg = classGen.getConstantPool();
  final InstructionList il = methodGen.getInstructionList();

  int iteratorIndex = 0;
  BranchHandle ifBlock = null;
  LocalVariableGen iter, node, node2;
  final String iteratorName = getNextFieldName();

  // Store node on the stack into a local variable
  node = methodGen.addLocalVariable("step_pattern_tmp1",
            Util.getJCRefType(NODE_SIG),
            il.getEnd(), null);
  il.append(new ISTORE(node.getIndex()));

  // Create a new local to store the iterator
  iter = methodGen.addLocalVariable("step_pattern_tmp2",
            Util.getJCRefType(NODE_ITERATOR_SIG),
            il.getEnd(), null);

  // Add a new private field if this is the main class
  if (!classGen.isExternal()) {
      final Field iterator =
    new Field(ACC_PRIVATE,
        cpg.addUtf8(iteratorName),
        cpg.addUtf8(NODE_ITERATOR_SIG),
        null, cpg.getConstantPool());
      classGen.addField(iterator);
      iteratorIndex = cpg.addFieldref(classGen.getClassName(),
              iteratorName,
              NODE_ITERATOR_SIG);

      il.append(classGen.loadTranslet());
      il.append(new GETFIELD(iteratorIndex));
      il.append(DUP);
      il.append(new ASTORE(iter.getIndex()));
      ifBlock = il.append(new IFNONNULL(null));
      il.append(classGen.loadTranslet());
 

  // Compile the step created at type checking time
  _step.translate(classGen, methodGen);
  il.append(new ASTORE(iter.getIndex()));

  // If in the main class update the field too
  if (!classGen.isExternal()) {
      il.append(new ALOAD(iter.getIndex()));
      il.append(new PUTFIELD(iteratorIndex));
      ifBlock.setTarget(il.append(NOP));
  }

  // Get the parent of the node on the stack
  il.append(methodGen.loadDOM());
  il.append(new ILOAD(node.getIndex()));
  int index = cpg.addInterfaceMethodref(DOM_INTF,
                GET_PARENT, GET_PARENT_SIG);
  il.append(new INVOKEINTERFACE(index, 2));

  // Initialize the iterator with the parent
  il.append(new ALOAD(iter.getIndex()));
  il.append(SWAP);
  il.append(methodGen.setStartNode());

  /*
   * Inline loop:
   *
   * int node2;
   * while ((node2 = iter.next()) != NodeIterator.END
   *      && node2 < node);
   * return node2 == node;
   */
  BranchHandle skipNext;
  InstructionHandle begin, next;
  node2 = methodGen.addLocalVariable("step_pattern_tmp3",
             Util.getJCRefType(NODE_SIG),
             il.getEnd(), null);

  skipNext = il.append(new GOTO(null));
  next = il.append(new ALOAD(iter.getIndex()));
  begin = il.append(methodGen.nextNode());
  il.append(DUP);
  il.append(new ISTORE(node2.getIndex()));
  _falseList.add(il.append(new IFLT(null)))// NodeIterator.END

View Full Code Here

  _iloadCurrent = new ILOAD(CURRENT_INDEX);
  _istoreCurrent = new ISTORE(CURRENT_INDEX);
  _aloadDom = new ALOAD(DOM_INDEX);
  _iloadLast = new ILOAD(LAST_INDEX);

  LocalVariableGen iterator =
      addLocalVariable("iterator",
           Util.getJCRefType(Constants.NODE_ITERATOR_SIG),
           null, null);
  ITERATOR_INDEX = iterator.getIndex();
  _aloadIterator = new ALOAD(ITERATOR_INDEX);
  _astoreIterator = new ASTORE(ITERATOR_INDEX);
  il.append(new ACONST_NULL());
  il.append(storeIterator());
    }
View Full Code Here

TOP

Related Classes of com.sun.org.apache.bcel.internal.generic.LocalVariableGen

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.