Examples of LocalVariableGen


Examples of org.apache.bcel.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 org.apache.bcel.generic.Instruction loadLocal =
      new ILOAD(local.getIndex());
  final org.apache.bcel.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 IFEQ(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

Examples of org.apache.bcel.generic.LocalVariableGen

     * 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.getVariable()),
          cpg.addUtf8(var.getType().toSignature()),
          null, cpg.getConstantPool()));
  }

  final InstructionList il = new InstructionList();
  testGen = new TestGenerator(ACC_PUBLIC | ACC_FINAL,
            org.apache.bcel.generic.Type.BOOLEAN,
            new org.apache.bcel.generic.Type[] {
          org.apache.bcel.generic.Type.INT,
          org.apache.bcel.generic.Type.INT,
          org.apache.bcel.generic.Type.INT,
          org.apache.bcel.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

Examples of org.apache.bcel.generic.LocalVariableGen

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

  // Create a local variable to hold the current node
  final LocalVariableGen current;
  current = methodGen.addLocalVariable2("current",
                org.apache.bcel.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

Examples of org.apache.bcel.generic.LocalVariableGen

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

  // Create the local variable to hold the current node
  final LocalVariableGen current;
  current = methodGen.addLocalVariable2("current",
                org.apache.bcel.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

Examples of org.apache.bcel.generic.LocalVariableGen

        // 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.

        LocalVariableGen nodesTemp =
            methodGen.addLocalVariable("sort_tmp1",
                                       Util.getJCRefType(NODE_ITERATOR_SIG),
                                       null, null);

        LocalVariableGen sortRecordFactoryTemp =
            methodGen.addLocalVariable("sort_tmp2",
                                      Util.getJCRefType(NODE_SORT_FACTORY_SIG),
                                      null, null);

  // Get the current node iterator
  if (nodeSet == null) {  // apply-templates default
      final int children = cpg.addInterfaceMethodref(DOM_INTF,
                 "getAxisIterator",
                 "(I)"+
                 NODE_ITERATOR_SIG);
      il.append(methodGen.loadDOM());
      il.append(new PUSH(cpg, Axis.CHILD));
      il.append(new INVOKEINTERFACE(children, 2));
  }
  else {
      nodeSet.translate(classGen, methodGen);
  }

        nodesTemp.setStart(il.append(new ASTORE(nodesTemp.getIndex())));
 
  // Compile the code for the NodeSortRecord producing class and pass
  // that as the last argument to the SortingIterator constructor.
  compileSortRecordFactory(sortObjects, classGen, methodGen);
        sortRecordFactoryTemp.setStart(
                il.append(new ASTORE(sortRecordFactoryTemp.getIndex())));

  il.append(new NEW(cpg.addClass(SORT_ITERATOR)));
  il.append(DUP);
        nodesTemp.setEnd(il.append(new ALOAD(nodesTemp.getIndex())));
        sortRecordFactoryTemp.setEnd(
                il.append(new ALOAD(sortRecordFactoryTemp.getIndex())));
  il.append(new INVOKESPECIAL(init));
    }
View Full Code Here

Examples of org.apache.bcel.generic.LocalVariableGen

        // 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.

  // Compile code that initializes the static _sortOrder
        LocalVariableGen sortOrderTemp
                 = methodGen.addLocalVariable("sort_order_tmp",
                                      Util.getJCRefType("[" + STRING_SIG),
                                      null, null);
  il.append(new PUSH(cpg, nsorts));
  il.append(new ANEWARRAY(cpg.addClass(STRING)));
  for (int level = 0; level < nsorts; level++) {
      final Sort sort = (Sort)sortObjects.elementAt(level);
      il.append(DUP);
      il.append(new PUSH(cpg, level));
      sort.translateSortOrder(classGen, methodGen);
      il.append(AASTORE);
  }
        sortOrderTemp.setStart(il.append(new ASTORE(sortOrderTemp.getIndex())));

        LocalVariableGen sortTypeTemp
                 = methodGen.addLocalVariable("sort_type_tmp",
                                      Util.getJCRefType("[" + STRING_SIG),
                                      null, null);
  il.append(new PUSH(cpg, nsorts));
  il.append(new ANEWARRAY(cpg.addClass(STRING)));
  for (int level = 0; level < nsorts; level++) {
      final Sort sort = (Sort)sortObjects.elementAt(level);
      il.append(DUP);
      il.append(new PUSH(cpg, level));
      sort.translateSortType(classGen, methodGen);
      il.append(AASTORE);
  }
        sortTypeTemp.setStart(il.append(new ASTORE(sortTypeTemp.getIndex())));

        LocalVariableGen sortLangTemp
                 = methodGen.addLocalVariable("sort_lang_tmp",
                                      Util.getJCRefType("[" + STRING_SIG),
                                      null, null);
        il.append(new PUSH(cpg, nsorts));
        il.append(new ANEWARRAY(cpg.addClass(STRING)));
        for (int level = 0; level < nsorts; level++) {
              final Sort sort = (Sort)sortObjects.elementAt(level);
              il.append(DUP);
              il.append(new PUSH(cpg, level));
              sort.translateLang(classGen, methodGen);
              il.append(AASTORE);
        }
        sortLangTemp.setStart(il.append(new ASTORE(sortLangTemp.getIndex())));

        LocalVariableGen sortCaseOrderTemp
                 = methodGen.addLocalVariable("sort_case_order_tmp",
                                      Util.getJCRefType("[" + STRING_SIG),
                                      null, null);
        il.append(new PUSH(cpg, nsorts));
        il.append(new ANEWARRAY(cpg.addClass(STRING)));
        for (int level = 0; level < nsorts; level++) {
            final Sort sort = (Sort)sortObjects.elementAt(level);
            il.append(DUP);
            il.append(new PUSH(cpg, level));
            sort.translateCaseOrder(classGen, methodGen);
            il.append(AASTORE);
        }
        sortCaseOrderTemp.setStart(
                il.append(new ASTORE(sortCaseOrderTemp.getIndex())));
 
  il.append(new NEW(cpg.addClass(sortRecordFactoryClass)));
  il.append(DUP);
  il.append(methodGen.loadDOM());
  il.append(new PUSH(cpg, sortRecordClass));
  il.append(classGen.loadTranslet());

        sortOrderTemp.setEnd(il.append(new ALOAD(sortOrderTemp.getIndex())));
        sortTypeTemp.setEnd(il.append(new ALOAD(sortTypeTemp.getIndex())));
        sortLangTemp.setEnd(il.append(new ALOAD(sortLangTemp.getIndex())));
        sortCaseOrderTemp.setEnd(
                il.append(new ALOAD(sortCaseOrderTemp.getIndex())));

  il.append(new INVOKESPECIAL(
      cpg.addMethodref(sortRecordFactoryClass, "<init>",
    "(" + DOM_INTF_SIG
        + STRING_SIG
View Full Code Here

Examples of org.apache.bcel.generic.LocalVariableGen

                           

  // This variable holds the id of the node we found with the "match"
  // attribute of xsl:key. This is the id we store, with the value we
  // get from the nodes we find here, in the index for this key.
  final LocalVariableGen parentNode =
      methodGen.addLocalVariable("parentNode",
               Util.getJCRefType("I"),
               null, null);

  // Get the 'parameter' from the stack and store it in a local var.
  parentNode.setStart(il.append(new ISTORE(parentNode.getIndex())))

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

  // Overwrite current iterator with one that gives us only what we want
  _use.translate(classGen, methodGen);
  _use.startIterator(classGen, methodGen);
  il.append(methodGen.storeIterator());

  final BranchHandle nextNode = il.append(new GOTO(null));
  final InstructionHandle loop = il.append(NOP);

  // Prepare to call buildKeyIndex(String name, int node, String value);
  il.append(classGen.loadTranslet());
  il.append(new PUSH(cpg, _name.toString()));
  parentNode.setEnd(il.append(new ILOAD(parentNode.getIndex())));

  // Now get the node value and push it on the parameter stack
  il.append(methodGen.loadDOM());
  il.append(methodGen.loadCurrentNode());
  il.append(new INVOKEINTERFACE(getNodeValue, 2));   
View Full Code Here

Examples of org.apache.bcel.generic.LocalVariableGen

        classGen.getConstantPool());

  toplevel.addException("org.apache.xalan.xsltc.TransletException");

  // Define and initialize 'current' variable with the root node
  final LocalVariableGen current =
      toplevel.addLocalVariable("current",
              org.apache.bcel.generic.Type.INT,
              null, null);

  final int setFilter = cpg.addInterfaceMethodref(DOM_INTF,
             "setFilter",
             "(Lorg/apache/xalan/xsltc/StripFilter;)V");

  final int gitr = cpg.addInterfaceMethodref(DOM_INTF,
              "getIterator",
              "()"+NODE_ITERATOR_SIG);
  il.append(toplevel.loadDOM());
  il.append(new INVOKEINTERFACE(gitr, 1));
        il.append(toplevel.nextNode());
  current.setStart(il.append(new ISTORE(current.getIndex())));

    // Create a new list containing variables/params + keys
    Vector varDepElements = new Vector(_globals);       
    Enumeration elements = elements();
    while (elements.hasMoreElements()) {
View Full Code Here

Examples of org.apache.bcel.generic.LocalVariableGen

        il,
        classGen.getConstantPool());
  transf.addException("org.apache.xalan.xsltc.TransletException");

  // Define and initialize current with the root node
  final LocalVariableGen current =
      transf.addLocalVariable("current",
            org.apache.bcel.generic.Type.INT,
            null, null);
  final String applyTemplatesSig = classGen.getApplyTemplatesSig();
  final int applyTemplates = cpg.addMethodref(getClassName(),
                "applyTemplates",
                applyTemplatesSig);
  final int domField = cpg.addFieldref(getClassName(),
               DOM_FIELD,
               DOM_INTF_SIG);

  // push translet for PUTFIELD
  il.append(classGen.loadTranslet());
  // prepare appropriate DOM implementation
 
  if (isMultiDocument()) {
      il.append(new NEW(cpg.addClass(MULTI_DOM_CLASS)));
      il.append(DUP);
  }
 
  il.append(classGen.loadTranslet());
  il.append(transf.loadDOM());
  il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS,
                 "makeDOMAdapter",
                 "("+DOM_INTF_SIG+")"+
                 DOM_ADAPTER_SIG)));
  // DOMAdapter is on the stack

  if (isMultiDocument()) {
      final int init = cpg.addMethodref(MULTI_DOM_CLASS,
                "<init>",
                "("+DOM_INTF_SIG+")V");
      il.append(new INVOKESPECIAL(init));
      // MultiDOM is on the stack
  }
 
  //store to _dom variable
  il.append(new PUTFIELD(domField));

  // continue with globals initialization
  final int gitr = cpg.addInterfaceMethodref(DOM_INTF,
              "getIterator",
              "()"+NODE_ITERATOR_SIG);
  il.append(transf.loadDOM());
  il.append(new INVOKEINTERFACE(gitr, 1));
        il.append(transf.nextNode());
  current.setStart(il.append(new ISTORE(current.getIndex())));

  // Transfer the output settings to the output post-processor
  il.append(classGen.loadTranslet());
  il.append(transf.loadHandler());
  final int index = cpg.addMethodref(TRANSLET_CLASS,
View Full Code Here

Examples of org.apache.bcel.generic.LocalVariableGen

                // 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.
                LocalVariableGen iteratorTemp
                        = methodGen.addLocalVariable("filter_expr_tmp1",
                                         Util.getJCRefType(NODE_ITERATOR_SIG),
                                         null, null);
                iteratorTemp.setStart(
                        il.append(new ASTORE(iteratorTemp.getIndex())));

                predicate.translate(classGen, methodGen);
                LocalVariableGen predicateValueTemp
                        = methodGen.addLocalVariable("filter_expr_tmp2",
                                         Util.getJCRefType("I"),
                                         null, null);
                predicateValueTemp.setStart(
                        il.append(new ISTORE(predicateValueTemp.getIndex())));

                il.append(new NEW(cpg.addClass(NTH_ITERATOR_CLASS)));
                il.append(DUP);
                iteratorTemp.setEnd(
                        il.append(new ALOAD(iteratorTemp.getIndex())));
                predicateValueTemp.setEnd(
                        il.append(new ILOAD(predicateValueTemp.getIndex())));
                il.append(new INVOKESPECIAL(nthIteratorIdx));
            } else {
                // Translate predicates from right to left
                final int initCNLI =
                                 cpg.addMethodref(CURRENT_NODE_LIST_ITERATOR,
                                                 "<init>",
                                                 "("+NODE_ITERATOR_SIG+"Z"+
                                                 CURRENT_NODE_LIST_FILTER_SIG +
                                                 NODE_SIG+TRANSLET_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.


                LocalVariableGen nodeIteratorTemp =
                    methodGen.addLocalVariable("filter_expr_tmp1",
                                           Util.getJCRefType(NODE_ITERATOR_SIG),
                                           null, null);
                nodeIteratorTemp.setStart(
                        il.append(new ASTORE(nodeIteratorTemp.getIndex())));

                predicate.translate(classGen, methodGen);
                LocalVariableGen filterTemp =
                    methodGen.addLocalVariable("filter_expr_tmp2",
                              Util.getJCRefType(CURRENT_NODE_LIST_FILTER_SIG),
                              null, null);
                filterTemp.setStart(
                        il.append(new ASTORE(filterTemp.getIndex())));

                // Create a CurrentNodeListIterator
                il.append(new NEW(cpg.addClass(CURRENT_NODE_LIST_ITERATOR)));
                il.append(DUP);
           
                // Initialize CurrentNodeListIterator
                nodeIteratorTemp.setEnd(
                        il.append(new ALOAD(nodeIteratorTemp.getIndex())));
                il.append(ICONST_1);
                filterTemp.setEnd(il.append(new ALOAD(filterTemp.getIndex())));
                il.append(methodGen.loadCurrentNode());
                il.append(classGen.loadTranslet());
                il.append(new INVOKESPECIAL(initCNLI));
      }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.