Package org.apache.bcel.generic

Examples of org.apache.bcel.generic.BranchHandle


      // 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) {
    il.append(new INVOKEVIRTUAL(lookupId));
      }
      else {
    il.append(new INVOKEVIRTUAL(lookupKey));
      }

      // Call to returnIndex.merge(searchIndex);
      il.append(new INVOKEVIRTUAL(merge));
   
      // Go on with next node in the 2nd parameter node-set
      nextNode.setTarget(il.append(methodGen.loadIterator()));
      il.append(methodGen.nextNode());
      il.append(DUP);
      il.append(methodGen.storeCurrentNode());
      il.append(new IFGT(loop));
View Full Code Here


  InstructionList il = methodGen.getInstructionList();

  // next element will hold a handle to the beginning of next
  // When/Otherwise if test on current When fails
  BranchHandle nextElement = null;
  Vector exitHandles = new Vector();
  InstructionHandle exit = null;

  Enumeration whens = whenElements.elements();
  while (whens.hasMoreElements()) {
      final When when = (When)whens.nextElement();
      final Expression test = when.getTest();

      InstructionHandle truec = il.getEnd();

      if (nextElement != null)
    nextElement.setTarget(il.append(NOP));
      test.translateDesynthesized(classGen, methodGen);

      if (test instanceof FunctionCall) {
    FunctionCall call = (FunctionCall)test;
    try {
        Type type = call.typeCheck(getParser().getSymbolTable());
        if (type != Type.Boolean) {
      test._falseList.add(il.append(new IFEQ(null)));
        }
    }
    catch (TypeCheckError e) {
        // handled later!
    }
      }
      // remember end of condition
      truec = il.getEnd();

      // The When object should be ignored completely in case it tests
      // for the support of a non-available element
      if (!when.ignore()) when.translateContents(classGen, methodGen);

      // goto exit after executing the body of when
      exitHandles.addElement(il.append(new GOTO(null)));
      if (whens.hasMoreElements() || otherwise != null) {
    nextElement = il.append(new GOTO(null));
    test.backPatchFalseList(nextElement);
      }
      else
    test.backPatchFalseList(exit = il.append(NOP));
      test.backPatchTrueList(truec.getNext());
  }
 
  // Translate any <xsl:otherwise> element
  if (otherwise != null) {
      nextElement.setTarget(il.append(NOP));
      otherwise.translateContents(classGen, methodGen);
      exit = il.append(NOP);
  }

  // now that end is known set targets of exit gotos
  Enumeration exitGotos = exitHandles.elements();
  while (exitGotos.hasMoreElements()) {
      BranchHandle gotoExit = (BranchHandle)exitGotos.nextElement();
      gotoExit.setTarget(exit);
  }
    }
View Full Code Here

      il.append(methodGen.loadDOM());
      il.append(SWAP);
      il.append(new INVOKEINTERFACE(check, 2));
 
      // Need to allow for long jumps here
      final BranchHandle icmp = il.append(new IFNE(null));
      _falseList.add(il.append(new GOTO_W(null)));
      icmp.setTarget(il.append(NOP));
  }
  else if (_nodeType == DTM.ATTRIBUTE_NODE) {
      final int check = cpg.addInterfaceMethodref(DOM_INTF,
              "isAttribute", "(I)Z");
      il.append(methodGen.loadDOM());
      il.append(SWAP);
      il.append(new INVOKEINTERFACE(check, 2));
 
      // Need to allow for long jumps here
      final BranchHandle icmp = il.append(new IFNE(null));
      _falseList.add(il.append(new GOTO_W(null)));
      icmp.setTarget(il.append(NOP));
  }
  else {
      // context node is on the stack
      final int getEType = cpg.addInterfaceMethodref(DOM_INTF,
                "getExpandedTypeID",
                                                          "(I)I");
      il.append(methodGen.loadDOM());
      il.append(SWAP);
      il.append(new INVOKEINTERFACE(getEType, 2));
      il.append(new PUSH(cpg, _nodeType));
 
      // Need to allow for long jumps here
      final BranchHandle icmp = il.append(new IF_ICMPEQ(null));
      _falseList.add(il.append(new GOTO_W(null)));
      icmp.setTarget(il.append(NOP));
  }
    }
View Full Code Here

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

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

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

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

           MethodGenerator methodGen) {
  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

  il.append(new ILOAD(node2.getIndex()));
  il.append(new ILOAD(node.getIndex()));
  il.append(new IF_ICMPLT(next));

  il.append(new ILOAD(node2.getIndex()));
  il.append(new ILOAD(node.getIndex()));
  _falseList.add(il.append(new IF_ICMPNE(null)));

  skipNext.setTarget(begin);
    }
View Full Code Here

      il.append(SWAP);
  }
  il.append(new INVOKEINTERFACE(getType, 2));
  il.append(new PUSH(cpg, DTM.DOCUMENT_NODE));
 
  final BranchHandle skip = il.append(new IF_ICMPEQ(null));
  _falseList.add(il.append(new GOTO_W(null)));
  skip.setTarget(il.append(NOP));

  if (_left != null) {
      _left.backPatchTrueList(begin);
     
      /*
 
View Full Code Here

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

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

    public void translateTo(ClassGenerator classGen, MethodGenerator methodGen,
          BooleanType type) {
  final InstructionList il = methodGen.getInstructionList();
  FlowList falsel = translateToDesynthesized(classGen, methodGen, type);
  il.append(ICONST_1);
  final BranchHandle truec = il.append(new GOTO(null));
  falsel.backPatch(il.append(ICONST_0));
  truec.setTarget(il.append(NOP));
    }
View Full Code Here

  il.append(new PUSH(cp, 1)); ASTFunDecl.push(); // Push TRUE
  il.append(InstructionConstants.IXOR); ASTFunDecl.pop();
      }
    }
    else { // Apply binary operand
      BranchHandle bh=null;

      exprs[1].byte_code(il, method, cp);

      switch(kind) {
      case PLUS:  il.append(InstructionConstants.IADD); ASTFunDecl.pop()break;
      case MINUS: il.append(InstructionConstants.ISUB); ASTFunDecl.pop()break;
      case MULT:  il.append(InstructionConstants.IMUL); ASTFunDecl.pop()break;
      case DIV:   il.append(InstructionConstants.IDIV); ASTFunDecl.pop()break;
      case AND:   il.append(InstructionConstants.IAND); ASTFunDecl.pop()break;
      case OR:    il.append(InstructionConstants.IOR);  ASTFunDecl.pop()break;

  /* Use negated operands */
      case EQ:    bh = il.append(new IF_ICMPNE(null)); ASTFunDecl.pop(2); break;
      case LEQ:   bh = il.append(new IF_ICMPGT(null)); ASTFunDecl.pop(2); break;
      case GEQ:   bh = il.append(new IF_ICMPLT(null)); ASTFunDecl.pop(2); break;
      case NEQ:   bh = il.append(new IF_ICMPEQ(null)); ASTFunDecl.pop(2); break;
      case LT:    bh = il.append(new IF_ICMPGE(null)); ASTFunDecl.pop(2); break;
      case GT:    bh = il.append(new IF_ICMPLE(null)); ASTFunDecl.pop(2); break;
      default: System.err.println("Ooops");
      }

      switch(kind) {
      case EQ: case LEQ: case GEQ: case NEQ: case LT: case GT:
  BranchHandle g;

  il.append(new PUSH(cp, 1));
  g = il.append(new GOTO(null));
  bh.setTarget(il.append(new PUSH(cp, 0)));
  g.setTarget(il.append(InstructionConstants.NOP)); // May be optimized away later
  ASTFunDecl.push();
  break;

      default: break;
      }
View Full Code Here

TOP

Related Classes of org.apache.bcel.generic.BranchHandle

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.