Examples of BranchHandle


Examples of org.apache.bcel.generic.BranchHandle

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

  // Finally do the call to add an entry in the index for this key.
  il.append(new INVOKEVIRTUAL(buildKeyIndex));
 
  il.append(classGen.loadTranslet());
  il.append(new PUSH(cpg, getName()));
  il.append(methodGen.loadDOM());
  il.append(new INVOKEVIRTUAL(keyDom));

  nextNode.setTarget(il.append(methodGen.loadIterator()));
  il.append(methodGen.nextNode())

  il.append(DUP);
  il.append(methodGen.storeCurrentNode());
  il.append(new IFGE(loop)); // Go on to next matching node....
View Full Code Here

Examples of org.apache.bcel.generic.BranchHandle

  il.append(methodGen.loadCurrentNode());
  il.append(methodGen.setStartNode());
  il.append(methodGen.storeIterator());

  // Loop for traversing all nodes in the DOM
  final BranchHandle nextNode = il.append(new GOTO(null));
  final InstructionHandle loop = il.append(NOP);

  // Check if the current node matches the pattern in "match"
  il.append(methodGen.loadCurrentNode());
  _match.translate(classGen, methodGen);
  _match.synthesize(classGen, methodGen); // Leaves 0 or 1 on stack
  final BranchHandle skipNode = il.append(new IFEQ(null));
 
  // If this is a node-set we must go through each node in the set
  if (_useType instanceof NodeSetType) {
      // Pass current node as parameter (we're indexing on that node)
      il.append(methodGen.loadCurrentNode());
      traverseNodeSet(classGen, methodGen, key);
  }
  else {
      il.append(classGen.loadTranslet());
      il.append(DUP);
      il.append(new PUSH(cpg, _name.toString()));
      il.append(DUP_X1);
      il.append(methodGen.loadCurrentNode());
      _use.translate(classGen, methodGen);
      il.append(new INVOKEVIRTUAL(key));
     
      il.append(methodGen.loadDOM());
      il.append(new INVOKEVIRTUAL(keyDom));
  }
 
  // Get the next node from the iterator and do loop again...
  final InstructionHandle skip = il.append(NOP);
 
  il.append(methodGen.loadIterator());
  il.append(methodGen.nextNode());
  il.append(DUP);
  il.append(methodGen.storeCurrentNode());
  il.append(new IFGT(loop));

  // Restore current node and current iterator from the stack
  il.append(methodGen.storeIterator());
  il.append(methodGen.storeCurrentNode());
 
  nextNode.setTarget(skip);
  skipNode.setTarget(skip);
    }
View Full Code Here

Examples of org.apache.bcel.generic.BranchHandle

  }

  // Check if field is initialized (runtime)
  il.append(classGen.loadTranslet());
  il.append(new GETFIELD(fieldIndexes[_level]));
  final BranchHandle ifBlock1 = il.append(new IFNONNULL(null));

  // Create an instance of DefaultNodeCounter
  index = cpg.addMethodref(ClassNames[_level],
         "getDefaultNodeCounter",
         "(" + TRANSLET_INTF_SIG
         + DOM_INTF_SIG
         + NODE_ITERATOR_SIG
         + ")" + NODE_COUNTER_SIG);
  il.append(classGen.loadTranslet());
  il.append(methodGen.loadDOM());
  il.append(methodGen.loadIterator());
  il.append(new INVOKESTATIC(index));
  il.append(DUP);

  // Store the node counter in the field
  il.append(classGen.loadTranslet());
  il.append(SWAP);
  il.append(new PUTFIELD(fieldIndexes[_level]));
  final BranchHandle ifBlock2 = il.append(new GOTO(null));

  // Backpatch conditionals
  ifBlock1.setTarget(il.append(classGen.loadTranslet()));
  il.append(new GETFIELD(fieldIndexes[_level]));
 
  ifBlock2.setTarget(il.append(NOP));
    }
View Full Code Here

Examples of org.apache.bcel.generic.BranchHandle

             ih = ih.getNext()) {
            Instruction inst = ih.getInstruction();

            if (inst instanceof IfInstruction) {
                IfInstruction oldIfInst = (IfInstruction)inst;
                BranchHandle oldIfHandle = (BranchHandle)ih;
                InstructionHandle target = oldIfInst.getTarget();
                int relativeTargetOffset = target.getPosition()
                                               - oldIfHandle.getPosition();

                // Consider the worst case scenario in which the conditional
                // branch and its target are separated by all the instructions
                // in the method that might increase in size.  If that results
                // in a relative offset that cannot be represented as a 32-bit
                // signed quantity, rewrite the instruction as described above.
                if ((relativeTargetOffset - maxOffsetChange
                             < MIN_BRANCH_TARGET_OFFSET)
                        || (relativeTargetOffset + maxOffsetChange
                                    > MAX_BRANCH_TARGET_OFFSET)) {
                    // Invert the logic of the IF instruction, and append
                    // that to the InstructionList following the original IF
                    // instruction
                    InstructionHandle nextHandle = oldIfHandle.getNext();
                    IfInstruction invertedIfInst = oldIfInst.negate();
                    BranchHandle invertedIfHandle = il.append(oldIfHandle,
                                                              invertedIfInst);

                    // Append an unconditional branch to the target of the
                    // original IF instruction after the new IF instruction
                    BranchHandle gotoHandle = il.append(invertedIfHandle,
                                                        new GOTO(target));

                    // If the original IF was the last instruction in
                    // InstructionList, add a new no-op to act as the target
                    // of the new IF
View Full Code Here

Examples of org.apache.bcel.generic.BranchHandle

  ilLoop.append(DUP);
  ilLoop.append(new ISTORE(_currentIndex));

  // The body of this code can get very large - large than can be handled
  // by a single IFNE(body.getStart()) instruction - need workaround:
        final BranchHandle ifeq = ilLoop.append(new IFLT(null));
  final BranchHandle loop = ilLoop.append(new GOTO_W(null));
  ifeq.setTarget(ilLoop.append(RETURN));   // applyTemplates() ends here!
  final InstructionHandle ihLoop = ilLoop.getStart();

        current.setStart(mainIL.append(new GOTO_W(ihLoop)));

        // Live range of "current" ends at end of loop
        current.setEnd(loop);

  // Compile default handling of elements (traverse children)
  InstructionList ilRecurse =
      compileDefaultRecursion(classGen, methodGen, ihLoop);
  InstructionHandle ihRecurse = ilRecurse.getStart();

  // Compile default handling of text/attribute nodes (output text)
  InstructionList ilText =
      compileDefaultText(classGen, methodGen, ihLoop);
  InstructionHandle ihText = ilText.getStart();

  // Distinguish attribute/element/namespace tests for further processing
  final int[] types = new int[DTM.NTYPES + names.size()];
  for (int i = 0; i < types.length; i++) {
      types[i] = i;
  }

  // Initialize isAttribute[] and isNamespace[] arrays
  final boolean[] isAttribute = new boolean[types.length];
  final boolean[] isNamespace = new boolean[types.length];
  for (int i = 0; i < names.size(); i++) {
      final String name = (String)names.elementAt(i);
      isAttribute[i + DTM.NTYPES] = isAttributeName(name);
      isNamespace[i + DTM.NTYPES] = isNamespaceName(name);
  }

  // Compile all templates - regardless of pattern type
  compileTemplates(classGen, methodGen, ihLoop);

  // Handle template with explicit "*" pattern
  final TestSeq elemTest = _testSeq[DTM.ELEMENT_NODE];
  InstructionHandle ihElem = ihRecurse;
  if (elemTest != null)
      ihElem = elemTest.compile(classGen, methodGen, ihRecurse);

  // Handle template with explicit "@*" pattern
  final TestSeq attrTest = _testSeq[DTM.ATTRIBUTE_NODE];
  InstructionHandle ihAttr = ihText;
  if (attrTest != null)
      ihAttr = attrTest.compile(classGen, methodGen, ihAttr);

  // Do tests for id() and key() patterns first
  InstructionList ilKey = null;
  if (_idxTestSeq != null) {
      loop.setTarget(_idxTestSeq.compile(classGen, methodGen, body.getStart()));
      ilKey = _idxTestSeq.getInstructionList();
  }
  else {
      loop.setTarget(body.getStart());
  }

  // If there is a match on node() we need to replace ihElem
  // and ihText if the priority of node() is higher
  if (_childNodeTestSeq != null) {
View Full Code Here

Examples of org.apache.bcel.generic.BranchHandle

  // Backpatch true list and restore current iterator/node
  InstructionHandle restore;
  restore = il.append(methodGen.storeCurrentNode());
  backPatchTrueList(restore);
  BranchHandle skipFalse = il.append(new GOTO(null));

  // Backpatch false list and restore current iterator/node
  restore = il.append(methodGen.storeCurrentNode());
  backPatchFalseList(restore);
  _falseList.add(il.append(new GOTO(null)));

  // True list falls through
  skipFalse.setTarget(il.append(NOP));
    }
View Full Code Here

Examples of org.apache.bcel.generic.BranchHandle

      }
     
      //check to validate that the GOTO instruction is less than the other incoming...
      if(comparator.before(otherLine, line)) {
        //take the lower condition...
        BranchHandle refHandle = null;
        if(comparator.before(nestedLine, line)) {
          refHandle = (BranchHandle)nestedLine.getInstruction();
        }
        else {
          refHandle = (BranchHandle)line.getInstruction();
View Full Code Here

Examples of org.apache.bcel.generic.BranchHandle

  @Override
  public void process(InstructionHandle ih) {
    if(ih instanceof BranchHandle) {
      //ok, now we need to replace existing successor edges appropriately.
      BranchHandle bh = (BranchHandle)ih;
     
      List<InstructionHandle> successors = igc.getSuccessors(ih);
      TreeSet<InstructionHandle> orderedSuccessors = new TreeSet<InstructionHandle>(new InstructionComparator());
      orderedSuccessors.addAll(successors);
     
View Full Code Here

Examples of org.apache.bcel.generic.BranchHandle

  // Backpatch true list and restore current iterator/node
  InstructionHandle restore;
  restore = il.append(methodGen.storeCurrentNode());
  backPatchTrueList(restore);
  BranchHandle skipFalse = il.append(new GOTO(null));

  // Backpatch false list and restore current iterator/node
  restore = il.append(methodGen.storeCurrentNode());
  backPatchFalseList(restore);
  _falseList.add(il.append(new GOTO(null)));

  // True list falls through
  skipFalse.setTarget(il.append(NOP));
    }
View Full Code Here

Examples of org.apache.bcel.generic.BranchHandle

  final int paramDom = stripSpace.getLocalIndex("dom");
  final int paramCurrent = stripSpace.getLocalIndex("node");
  final int paramType = stripSpace.getLocalIndex("type");

  BranchHandle strip[] = new BranchHandle[rules.size()];
  BranchHandle preserve[] = new BranchHandle[rules.size()];
  int sCount = 0;
  int pCount = 0;

  // Traverse all strip/preserve rules
  for (int i = 0; i<rules.size(); i++) {
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.