Examples of BranchHandle


Examples of org.apache.bcel.generic.BranchHandle

     */
    public void synthesize(ClassGenerator classGen, MethodGenerator methodGen) {
  final ConstantPoolGen cpg = classGen.getConstantPool();
  final InstructionList il = methodGen.getInstructionList();
  _trueList.backPatch(il.append(ICONST_1));
  final BranchHandle truec = il.append(new GOTO_W(null));
  _falseList.backPatch(il.append(ICONST_0));
  truec.setTarget(il.append(NOP));
    }
View Full Code Here

Examples of org.apache.bcel.generic.BranchHandle

              + TRANSLET_OUTPUT_SIG
              + ")" + STRING_SIG);
  il.append(new INVOKEINTERFACE(cpy, 3));
  il.append(DUP);
  name.setStart(il.append(new ASTORE(name.getIndex())));
  final BranchHandle ifBlock1 = il.append(new IFNULL(null));

  // Get the length of the node name and save for later
  il.append(new ALOAD(name.getIndex()));
  final int lengthMethod = cpg.addMethodref(STRING_CLASS,"length","()I");
  il.append(new INVOKEVIRTUAL(lengthMethod));
  length.setStart(il.append(new ISTORE(length.getIndex())));

  // Copy in attribute sets if specified
  if (_useSets != null) {
      // If the parent of this element will result in an element being
      // output then we know that it is safe to copy out the attributes
      final SyntaxTreeNode parent = getParent();
      if ((parent instanceof LiteralElement) ||
    (parent instanceof LiteralElement)) {
    _useSets.translate(classGen, methodGen);
      }
      // If not we have to check to see if the copy will result in an
      // element being output.
      else {
    // check if element; if not skip to translate body
    il.append(new ILOAD(length.getIndex()));
    final BranchHandle ifBlock2 = il.append(new IFEQ(null));
    // length != 0 -> element -> do attribute sets
    _useSets.translate(classGen, methodGen);
    // not an element; root
    ifBlock2.setTarget(il.append(NOP));
      }
  }

  // Instantiate body of xsl:copy
  translateContents(classGen, methodGen);

  // Call the output handler's endElement() if we copied an element
  // (The DOM.shallowCopy() method calls startElement().)
  length.setEnd(il.append(new ILOAD(length.getIndex())));
  final BranchHandle ifBlock3 = il.append(new IFEQ(null));
  il.append(methodGen.loadHandler());
  name.setEnd(il.append(new ALOAD(name.getIndex())));
  il.append(methodGen.endElement());
 
  final InstructionHandle end = il.append(NOP);
  ifBlock1.setTarget(end);
  ifBlock3.setTarget(end);
  methodGen.removeLocalVariable(name);
  methodGen.removeLocalVariable(length);
    }
View Full Code Here

Examples of org.apache.bcel.generic.BranchHandle

  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;
  List exitHandles = new ArrayList();
  InstructionHandle exit = null;

  Iterator whens = whenElements.iterator();
  while (whens.hasNext()) {
      final When when = (When)whens.next();
      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.add(il.append(new GOTO(null)));
      if (whens.hasNext() || 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
  Iterator exitGotos = exitHandles.iterator();
  while (exitGotos.hasNext()) {
      BranchHandle gotoExit = (BranchHandle)exitGotos.next();
      gotoExit.setTarget(exit);
  }
    }
View Full Code Here

Examples of org.apache.bcel.generic.BranchHandle

      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

Examples of org.apache.bcel.generic.BranchHandle

      }
      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)
  }
  else {
View Full Code Here

Examples of org.apache.bcel.generic.BranchHandle

     */
    public void backPatch(InstructionHandle target) {
  if (_elements != null) {
      final int n = _elements.size();
      for (int i = 0; i < n; i++) {
    BranchHandle bh = (BranchHandle)_elements.elementAt(i);
    bh.setTarget(target);
      }
      _elements.clear();    // avoid backpatching more than once
  }
    }
View Full Code Here

Examples of org.apache.bcel.generic.BranchHandle

    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

Examples of org.apache.bcel.generic.BranchHandle

    public void translateDesynthesized(ClassGenerator classGen,
               MethodGenerator methodGen) {
  final InstructionList il = methodGen.getInstructionList();
  final Expression exp = argument();
  exp.translateDesynthesized(classGen, methodGen);
  final BranchHandle gotoh = il.append(new GOTO(null));
  _trueList = exp._falseList;   // swap flow lists
  _falseList = exp._trueList;
  _falseList.add(gotoh);
    }
View Full Code Here

Examples of org.apache.bcel.generic.BranchHandle

              * param using its default value:
              *       if (param == null) param = <default-value>
              */
            if (_isInSimpleNamedTemplate) {
    il.append(loadInstruction());
                BranchHandle ifBlock = il.append(new IFNONNULL(null));
                translateValue(classGen, methodGen);
                il.append(storeInstruction());
                ifBlock.setTarget(il.append(NOP));
                return;
            }
           
      il.append(classGen.loadTranslet());
      il.append(new PUSH(cpg, name));
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
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.