Package org.apache.bcel.generic

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.getEscapedName()),
          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)));
  local.setStart(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);
 
  filterGen.addEmptyConstructor(ACC_PUBLIC);
View Full Code Here


                 "(I)"+STRING_SIG);

  // 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"),
               il.getEnd(), null);

  // Get the 'parameter' from the stack and store it in a local var.
  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.startResetIterator(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()));
  il.append(new ILOAD(parentNode.getIndex()));

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

  final int indexConstructor = cpg.addMethodref(TRANSLET_CLASS,
                  "createKeyIndex",
                  "()"+KEY_INDEX_SIG);
 
  // This local variable holds the index/iterator we will return
  final LocalVariableGen returnIndex =
      methodGen.addLocalVariable("returnIndex",
               Util.getJCRefType(KEY_INDEX_SIG),
               il.getEnd(), null);

  // This local variable holds the index we're using for search
  final LocalVariableGen searchIndex =
      methodGen.addLocalVariable("searchIndex",
               Util.getJCRefType(KEY_INDEX_SIG),
               il.getEnd(), null);

  // If the second paramter is a node-set we need to go through each
  // node in the set, convert each one to a string and do a look up in
  // the named index, and then merge all the resulting node sets.
  if (_valueType == Type.NodeSet || _valueType == Type.ResultTree) {
      // Save current node and current iterator on the stack
      il.append(methodGen.loadCurrentNode());
      il.append(methodGen.loadIterator());

      // Get new iterator from 2nd parameter node-set & store in variable
      _value.translate(classGen, methodGen);
      _value.startResetIterator(classGen, methodGen);
      il.append(methodGen.storeIterator());

      // Create the KeyIndex object (the iterator) we'll return
      il.append(classGen.loadTranslet());
      il.append(new INVOKEVIRTUAL(indexConstructor));
      il.append(new ASTORE(returnIndex.getIndex()));

      // Initialise the index specified in the first parameter of key()
      il.append(classGen.loadTranslet());
      if (_name == null) {
    il.append(new PUSH(cpg,"##id"));
      }
      else if (_resolvedQName != null) {
    il.append(new PUSH(cpg, _resolvedQName.toString()));
      }
      else {
    _name.translate(classGen, methodGen);
      }

      il.append(new INVOKEVIRTUAL(getKeyIndex));
      il.append(new ASTORE(searchIndex.getIndex()));

      // LOOP STARTS HERE

      // Now we're ready to start traversing the node-set given in
      // the key() function's second argument....
      final BranchHandle nextNode = il.append(new GOTO(null));
      final InstructionHandle loop = il.append(NOP);

      // Push returnIndex on stack to prepare for call to merge()
      il.append(new ALOAD(returnIndex.getIndex()));
     
      // Lookup index using the string value from the current node
      il.append(new ALOAD(searchIndex.getIndex()));
      il.append(DUP);
      il.append(methodGen.loadDOM());
      il.append(methodGen.loadCurrentNode());
      il.append(new INVOKEINTERFACE(getNodeValue, 2));
      if (_name == null) {
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");
  il.append(new NEW(cpg.addClass(MATCHING_ITERATOR)));
  il.append(DUP);
  il.append(new ILOAD(match.getIndex()));
  _step.translate(classGen, methodGen);
  il.append(new INVOKESPECIAL(index));

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

  // Start the iterator with the parent
  il.append(methodGen.setStartNode());

  // Overwrite current iterator and current node
  il.append(methodGen.storeIterator());
  il.append(new ILOAD(match.getIndex()));
  il.append(methodGen.storeCurrentNode());

  // Translate the expression of the predicate
  Predicate pred = (Predicate) _predicates.elementAt(0);
  Expression exp = pred.getExpr();
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 IFEQ(null)))// NodeIterator.END

View Full Code Here

        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,
            il.getEnd(), null);

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

  il.append(new PUSH(cpg, DTM.ROOT_NODE));
  il.append(new ISTORE(current.getIndex()));

  // Resolve any forward referenes and translate global variables/params
  _globals = resolveReferences(_globals);
  final int count = _globals.size();
  for (int i = 0; i < count; i++) {
View Full Code Here

        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,
            il.getEnd(), 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
  il.append(new PUSH(cpg, DTM.ROOT_NODE));
  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

                           

  // 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"),
               il.getEnd(), null);

  // Get the 'parameter' from the stack and store it in a local var.
  il.append(new ISTORE(parentNode.getIndex()))
  il.append(methodGen.loadDOM());
  il.append(new ILOAD(parentNode.getIndex()))
  il.append(new INVOKEINTERFACE(getNodeIdent, 2));
  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()));
  il.append(new ILOAD(parentNode.getIndex()));

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

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

      il.append(DUP);
      il.append(DUP);
      il.append(new INVOKESPECIAL(index));
     
      // Store new Handler into a local variable
      final LocalVariableGen handler =
    methodGen.addLocalVariable("rt_to_string_handler",
             Util.getJCRefType(STRING_VALUE_HANDLER_SIG),
             null, null);
      il.append(new ASTORE(handler.getIndex()));

      // Call the method that implements this result tree
      index = cpg.addMethodref(className, _methodName,
             "("+DOM_INTF_SIG+TRANSLET_OUTPUT_SIG+")V");
      il.append(new INVOKEVIRTUAL(index));
     
      // Restore new handler and call getValue()
      il.append(new ALOAD(handler.getIndex()));
      index = cpg.addMethodref(STRING_VALUE_HANDLER,
             "getValue",
             "()" + STRING_SIG);
      il.append(new INVOKEVIRTUAL(index));
  }
View Full Code Here

TOP

Related Classes of org.apache.bcel.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.