Package org.apache.bcel.generic

Examples of org.apache.bcel.generic.LocalVariableGen


  if (_methodName == null) {
      il.append(NOP);
  }
  else {
      LocalVariableGen domBuilder, newDom;
      final String className = classGen.getClassName();
      final int current = methodGen.getLocalIndex("current");

      // Push required parameters
      il.append(classGen.loadTranslet());
      if (classGen.isExternal()) {
    il.append(new CHECKCAST(cpg.addClass(className)));
      }
      il.append(methodGen.loadDOM());

      // Create new instance of DOM class (with RTF_INITIAL_SIZE nodes)
      il.append(methodGen.loadDOM());
      int index = cpg.addInterfaceMethodref(DOM_INTF,
         "getResultTreeFrag",
         "(IZ)" + DOM_INTF_SIG);
      il.append(new PUSH(cpg, RTF_INITIAL_SIZE));
      il.append(new PUSH(cpg, false));
      il.append(new INVOKEINTERFACE(index,3));
      il.append(DUP);
     
      // Store new DOM into a local variable
      newDom = methodGen.addLocalVariable("rt_to_reference_dom",
            Util.getJCRefType(DOM_INTF_SIG),
            null, null);
      il.append(new CHECKCAST(cpg.addClass(DOM_INTF_SIG)));
      il.append(new ASTORE(newDom.getIndex()));

      // Overwrite old handler with DOM handler
      index = cpg.addInterfaceMethodref(DOM_INTF,
         "getOutputDomBuilder",
         "()" + TRANSLET_OUTPUT_SIG);

      il.append(new INVOKEINTERFACE(index,1));
      //index = cpg.addMethodref(DOM_IMPL,
    //         "getOutputDomBuilder",
    //         "()" + TRANSLET_OUTPUT_SIG);
      //il.append(new INVOKEVIRTUAL(index));
      il.append(DUP);
      il.append(DUP);

      // Store DOM handler in a local in order to call endDocument()
      domBuilder =
    methodGen.addLocalVariable("rt_to_reference_handler",
             Util.getJCRefType(TRANSLET_OUTPUT_SIG),
             null, null);
      il.append(new ASTORE(domBuilder.getIndex()));

      // Call startDocument on the new handler
      index = cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE,
                "startDocument", "()V");
      il.append(new INVOKEINTERFACE(index, 1));

      // 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));

      // Call endDocument on the DOM handler
      il.append(new ALOAD(domBuilder.getIndex()));
      index = cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE,
                "endDocument", "()V");
      il.append(new INVOKEINTERFACE(index, 1));

      // Push the new DOM on the stack
View Full Code Here


        // in temporary variables, create the object and reload the
        // arguments from the temporaries to avoid the problem.

  // Recursively compile 2 iterators
  _filterExpr.translate(classGen, methodGen);
        LocalVariableGen filterTemp =
                methodGen.addLocalVariable("filter_parent_path_tmp1",
                                           Util.getJCRefType(NODE_ITERATOR_SIG),
                                           il.getEnd(), null);
        il.append(new ASTORE(filterTemp.getIndex()));

  _path.translate(classGen, methodGen);
        LocalVariableGen pathTemp =
                methodGen.addLocalVariable("filter_parent_path_tmp2",
                                           Util.getJCRefType(NODE_ITERATOR_SIG),
                                           il.getEnd(), null);
        il.append(new ASTORE(pathTemp.getIndex()));

  il.append(new NEW(cpg.addClass(STEP_ITERATOR_CLASS)));
  il.append(DUP);
        il.append(new ALOAD(filterTemp.getIndex()));
        il.append(new ALOAD(pathTemp.getIndex()));

  // Initialize StepIterator with iterators from the stack
  il.append(new INVOKESPECIAL(initSI));

  // This is a special case for the //* path with or without predicates
View Full Code Here

  final ConstantPoolGen cpg = classGen.getConstantPool();
  final InstructionList il = methodGen.getInstructionList();
   
        if (!_isLiteral) {
            // if the ncname is an AVT, then the ncname has to be checked at runtime if it is a valid ncname
            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 checkNCName if the name is an AVT
            final int check = cpg.addMethodref(BASIS_LIBRARY_CLASS, "checkNCName",
                                "("
                                +STRING_SIG
                                +")V");                
                                il.append(new INVOKESTATIC(check));
           
            // Save the current handler base on the stack
            il.append(methodGen.loadHandler());
            il.append(DUP);     // first arg to "attributes" call           
           
            // load name value again   
            il.append(new ALOAD(nameValue.getIndex()));           
        } else {   
            // Save the current handler base on the stack
            il.append(methodGen.loadHandler());
            il.append(DUP);     // first arg to "attributes" call
           
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

            // 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 relative path iterator(s)
            LocalVariableGen pathTemp =
               methodGen.addLocalVariable("filtered_absolute_location_path_tmp",
                                          Util.getJCRefType(NODE_ITERATOR_SIG),
                                          il.getEnd(), null);
      _path.translate(classGen, methodGen);
            il.append(new ASTORE(pathTemp.getIndex()));

      // Create new Dup Filter Iterator
      il.append(new NEW(cpg.addClass(DUP_FILTERED_ITERATOR)));
      il.append(DUP);
            il.append(new ALOAD(pathTemp.getIndex()));

      // Initialize Dup Filter Iterator with iterator from the stack
      il.append(new INVOKESPECIAL(initDFI));
  }
  else {
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

        // 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 keyIterator = translateCall(classGen, methodGen);

  il.append(new NEW(cpg.addClass(DUP_FILTERED_ITERATOR)))
  il.append(DUP);
        il.append(new ALOAD(keyIterator.getIndex()));
  il.append(new INVOKESPECIAL(dupInit));
    }
View Full Code Here

           "setDom",
           "("+DOM_INTF_SIG+")V");        
                 
 
  // 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) {
      // 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.startIterator(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(DUP);
      il.append(methodGen.loadDOM());
      il.append(new INVOKEVIRTUAL(keyDom));
      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

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

  if (_left != null) {
      if (_left instanceof StepPattern) {
    final LocalVariableGen local =
        // absolute path pattern temporary
        methodGen.addLocalVariable2("apptmp",
            Util.getJCRefType(NODE_SIG),
            il.getEnd());
    il.append(DUP);
    il.append(new ISTORE(local.getIndex()));
    _left.translate(classGen, methodGen);
    il.append(methodGen.loadDOM());
    local.setEnd(il.append(new ILOAD(local.getIndex())));
    methodGen.removeLocalVariable(local);
      }
      else {
    _left.translate(classGen, methodGen);
      }
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.