Java Code Examples for com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator#getInstructionList()

The following examples show how to use com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator#getInstructionList() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NumberCall.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final InstructionList il = methodGen.getInstructionList();
    Type targ;

    if (argumentCount() == 0) {
        il.append(methodGen.loadContextNode());
        targ = Type.Node;
    }
    else {
        final Expression arg = argument();
        arg.translate(classGen, methodGen);
        arg.startIterator(classGen, methodGen);
        targ = arg.getType();
    }

    if (!targ.identicalTo(Type.Real)) {
        targ.translateTo(classGen, methodGen, Type.Real);
    }
}
 
Example 2
Source File: StringCall.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final InstructionList il = methodGen.getInstructionList();
    Type targ;

    if (argumentCount() == 0) {
        il.append(methodGen.loadContextNode());
        targ = Type.Node;
    }
    else {
        final Expression arg = argument();
        arg.translate(classGen, methodGen);
        arg.startIterator(classGen, methodGen);
        targ = arg.getType();
    }

    if (!targ.identicalTo(Type.String)) {
        targ.translateTo(classGen, methodGen, Type.String);
    }
}
 
Example 3
Source File: NumberCall.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final InstructionList il = methodGen.getInstructionList();
    Type targ;

    if (argumentCount() == 0) {
        il.append(methodGen.loadContextNode());
        targ = Type.Node;
    }
    else {
        final Expression arg = argument();
        arg.translate(classGen, methodGen);
        arg.startIterator(classGen, methodGen);
        targ = arg.getType();
    }

    if (!targ.identicalTo(Type.Real)) {
        targ.translateTo(classGen, methodGen, Type.Real);
    }
}
 
Example 4
Source File: StepPattern.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    if (hasPredicates()) {
        switch (_contextCase) {
        case NO_CONTEXT:
            translateNoContext(classGen, methodGen);
            break;

        case SIMPLE_CONTEXT:
            translateSimpleContext(classGen, methodGen);
            break;

        default:
            translateGeneralContext(classGen, methodGen);
            break;
        }
    }
    else if (isWildcard()) {
        il.append(POP);     // true list falls through
    }
    else {
        translateKernel(classGen, methodGen);
    }
}
 
Example 5
Source File: PositionCall.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final InstructionList il = methodGen.getInstructionList();

    if (methodGen instanceof CompareGenerator) {
        il.append(((CompareGenerator)methodGen).loadCurrentNode());
    }
    else if (methodGen instanceof TestGenerator) {
        il.append(new ILOAD(POSITION_INDEX));
    }
    else {
        final ConstantPoolGen cpg = classGen.getConstantPool();
        final int index = cpg.addInterfaceMethodref(NODE_ITERATOR,
                                                   "getPosition",
                                                   "()I");

        il.append(methodGen.loadIterator());
        il.append(new INVOKEINTERFACE(index,1));
    }
}
 
Example 6
Source File: CastCall.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    _right.translate(classGen, methodGen);
    il.append(new CHECKCAST(cpg.addClass(_className)));
}
 
Example 7
Source File: LiteralExpr.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    il.append(new PUSH(cpg, _value));
}
 
Example 8
Source File: RelationalExpr.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
public void translateDesynthesized(ClassGenerator classGen,
                                   MethodGenerator methodGen) {
    if (hasNodeSetArgs() || hasReferenceArgs()) {
        translate(classGen, methodGen);
        desynthesize(classGen, methodGen);
    }
    else {
        BranchInstruction bi = null;
        final InstructionList il = methodGen.getInstructionList();

        _left.translate(classGen, methodGen);
        _right.translate(classGen, methodGen);

        // TODO: optimize if one of the args is 0

        boolean tozero = false;
        Type tleft = _left.getType();

        if (tleft instanceof RealType) {
    il.append(tleft.CMP(_op == Operators.LT || _op == Operators.LE));
            tleft = Type.Int;
            tozero = true;
        }

        switch (_op) {
    case Operators.LT:
            bi = tleft.GE(tozero);
            break;

    case Operators.GT:
            bi = tleft.LE(tozero);
            break;

    case Operators.LE:
            bi = tleft.GT(tozero);
            break;

    case Operators.GE:
            bi = tleft.LT(tozero);
            break;

        default:
            ErrorMsg msg = new ErrorMsg(ErrorMsg.ILLEGAL_RELAT_OP_ERR,this);
            getParser().reportError(Constants.FATAL, msg);
        }

        _falseList.add(il.append(bi));              // must be backpatched
    }
}
 
Example 9
Source File: KeyCall.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * This method is called when the constructor is compiled in
 * Stylesheet.compileConstructor() and not as the syntax tree is traversed.
 * <p>This method will generate byte code that produces an iterator
 * for the nodes in the node set for the key or id function call.
 * @param classGen The Java class generator
 * @param methodGen The method generator
 */
public void translate(ClassGenerator classGen,
                      MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    // Returns the KeyIndex object of a given name
    final int getKeyIndex = cpg.addMethodref(TRANSLET_CLASS,
                                             "getKeyIndex",
                                             "(Ljava/lang/String;)"+
                                             KEY_INDEX_SIG);

    // KeyIndex.setDom(Dom, node) => void
    final int keyDom = cpg.addMethodref(KEY_INDEX_CLASS,
                                        "setDom",
                                        "(" + DOM_INTF_SIG + "I)V");

    // Initialises a KeyIndex to return nodes with specific values
    final int getKeyIterator =
                    cpg.addMethodref(KEY_INDEX_CLASS,
                                     "getKeyIndexIterator",
                                     "(" + _valueType.toSignature() + "Z)"
                                         + KEY_INDEX_ITERATOR_SIG);

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

    // Generate following byte code:
    //
    //   KeyIndex ki = translet.getKeyIndex(_name)
    //   ki.setDom(translet.dom);
    //   ki.getKeyIndexIterator(_value, true)  - for key()
    //        OR
    //   ki.getKeyIndexIterator(_value, false)  - for id()
    il.append(new INVOKEVIRTUAL(getKeyIndex));
    il.append(DUP);
    il.append(methodGen.loadDOM());
    il.append(methodGen.loadCurrentNode());
    il.append(new INVOKEVIRTUAL(keyDom));

    _value.translate(classGen, methodGen);
    il.append((_name != null) ? ICONST_1: ICONST_0);
    il.append(new INVOKEVIRTUAL(getKeyIterator));
}
 
Example 10
Source File: Copy.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    final LocalVariableGen name =
        methodGen.addLocalVariable2("name",
                                    Util.getJCRefType(STRING_SIG),
                                    null);
    final LocalVariableGen length =
        methodGen.addLocalVariable2("length",
                                    Util.getJCRefType("I"),
                                    null);

    // Get the name of the node to copy and save for later
    il.append(methodGen.loadDOM());
    il.append(methodGen.loadCurrentNode());
    il.append(methodGen.loadHandler());
    final int cpy = cpg.addInterfaceMethodref(DOM_INTF,
                                              "shallowCopy",
                                              "("
                                              + NODE_SIG
                                              + 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));
    il.append(DUP);
    length.setStart(il.append(new ISTORE(length.getIndex())));

    // Ignore attribute sets if current node is ROOT. DOM.shallowCopy()
    // returns "" for ROOT, so skip attribute sets if length == 0
    final BranchHandle ifBlock4 = il.append(new IFEQ(null));

    // 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
    ifBlock4.setTarget(il.append(NOP));
    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);
}
 
Example 11
Source File: ParameterRef.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    /*
     * To fix bug 24518 related to setting parameters of the form
     * {namespaceuri}localName, which will get mapped to an instance
     * variable in the class.
     */
    final String name = BasisLibrary.mapQNameToJavaName (_name.toString());
    final String signature = _type.toSignature();

    if (_variable.isLocal()) {
        if (classGen.isExternal()) {
            Closure variableClosure = _closure;
            while (variableClosure != null) {
                if (variableClosure.inInnerClass()) break;
                variableClosure = variableClosure.getParentClosure();
            }

            if (variableClosure != null) {
                il.append(ALOAD_0);
                il.append(new GETFIELD(
                    cpg.addFieldref(variableClosure.getInnerClassName(),
                        name, signature)));
            }
            else {
                il.append(_variable.loadInstruction());
            }
        }
        else {
            il.append(_variable.loadInstruction());
        }
    }
    else {
        final String className = classGen.getClassName();
        il.append(classGen.loadTranslet());
        if (classGen.isExternal()) {
            il.append(new CHECKCAST(cpg.addClass(className)));
        }
        il.append(new GETFIELD(cpg.addFieldref(className,name,signature)));
    }

    if (_variable.getType() instanceof NodeSetType) {
        // The method cloneIterator() also does resetting
        final int clone = cpg.addInterfaceMethodref(NODE_ITERATOR,
                                                   "cloneIterator",
                                                   "()" +
                                                    NODE_ITERATOR_SIG);
        il.append(new INVOKEINTERFACE(clone, 1));
    }
}
 
Example 12
Source File: NotCall.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final InstructionList il = methodGen.getInstructionList();
    argument().translate(classGen, methodGen);
    il.append(ICONST_1);
    il.append(IXOR);
}
 
Example 13
Source File: ProcessingInstructionPattern.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    // context node is on the stack
    int gname = cpg.addInterfaceMethodref(DOM_INTF,
                                          "getNodeName",
                                          "(I)Ljava/lang/String;");
    int cmp = cpg.addMethodref(STRING_CLASS,
                               "equals", "(Ljava/lang/Object;)Z");

    // Push current node on the stack
    il.append(methodGen.loadCurrentNode());
    il.append(SWAP);

    // Overwrite current node with matching node
    il.append(methodGen.storeCurrentNode());

    // If pattern not reduced then check kernel
    if (!_typeChecked) {
        il.append(methodGen.loadCurrentNode());
        final int getType = cpg.addInterfaceMethodref(DOM_INTF,
                                                      "getExpandedTypeID",
                                                      "(I)I");
        il.append(methodGen.loadDOM());
        il.append(methodGen.loadCurrentNode());
        il.append(new INVOKEINTERFACE(getType, 2));
        il.append(new PUSH(cpg, DTM.PROCESSING_INSTRUCTION_NODE));
        _falseList.add(il.append(new IF_ICMPEQ(null)));
    }

    // Load the requested processing instruction name
    il.append(new PUSH(cpg, _name));
    // Load the current processing instruction's name
    il.append(methodGen.loadDOM());
    il.append(methodGen.loadCurrentNode());
    il.append(new INVOKEINTERFACE(gname, 2));
    // Compare the two strings
    il.append(new INVOKEVIRTUAL(cmp));
    _falseList.add(il.append(new IFEQ(null)));

    // Compile the expressions within the predicates
    if (hasPredicates()) {
        final int n = _predicates.size();
        for (int i = 0; i < n; i++) {
            Predicate pred = (Predicate)_predicates.elementAt(i);
            Expression exp = pred.getExpr();
            exp.translateDesynthesized(classGen, methodGen);
            _trueList.append(exp._trueList);
            _falseList.append(exp._falseList);
        }
    }

    // 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));
}
 
Example 14
Source File: CopyOf.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    final Type tselect = _select.getType();

    final String CPY1_SIG = "("+NODE_ITERATOR_SIG+TRANSLET_OUTPUT_SIG+")V";
    final int cpy1 = cpg.addInterfaceMethodref(DOM_INTF, "copy", CPY1_SIG);

    final String CPY2_SIG = "("+NODE_SIG+TRANSLET_OUTPUT_SIG+")V";
    final int cpy2 = cpg.addInterfaceMethodref(DOM_INTF, "copy", CPY2_SIG);

    final String getDoc_SIG = "()"+NODE_SIG;
    final int getDoc = cpg.addInterfaceMethodref(DOM_INTF, "getDocument", getDoc_SIG);


    if (tselect instanceof NodeSetType) {
        il.append(methodGen.loadDOM());

        // push NodeIterator
        _select.translate(classGen, methodGen);
        _select.startIterator(classGen, methodGen);

        // call copy from the DOM 'library'
        il.append(methodGen.loadHandler());
        il.append(new INVOKEINTERFACE(cpy1, 3));
    }
    else if (tselect instanceof NodeType) {
        il.append(methodGen.loadDOM());
        _select.translate(classGen, methodGen);
        il.append(methodGen.loadHandler());
        il.append(new INVOKEINTERFACE(cpy2, 3));
    }
    else if (tselect instanceof ResultTreeType) {
        _select.translate(classGen, methodGen);
        // We want the whole tree, so we start with the root node
        il.append(DUP); //need a pointer to the DOM ;
        il.append(new INVOKEINTERFACE(getDoc,1)); //ICONST_0);
        il.append(methodGen.loadHandler());
        il.append(new INVOKEINTERFACE(cpy2, 3));
    }
    else if (tselect instanceof ReferenceType) {
        _select.translate(classGen, methodGen);
        il.append(methodGen.loadHandler());
        il.append(methodGen.loadCurrentNode());
        il.append(methodGen.loadDOM());
        final int copy = cpg.addMethodref(BASIS_LIBRARY_CLASS, "copy",
                                          "("
                                          + OBJECT_SIG
                                          + TRANSLET_OUTPUT_SIG
                                          + NODE_SIG
                                          + DOM_INTF_SIG
                                          + ")V");
        il.append(new INVOKESTATIC(copy));
    }
    else {
        il.append(classGen.loadTranslet());
        _select.translate(classGen, methodGen);
        il.append(methodGen.loadHandler());
        il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS,
                                                     CHARACTERSW,
                                                     CHARACTERSW_SIG)));
    }

}
 
Example 15
Source File: Sort.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public void translateLang(ClassGenerator classGen,
               MethodGenerator methodGen) {
final ConstantPoolGen cpg = classGen.getConstantPool();
final InstructionList il = methodGen.getInstructionList();
il.append(new PUSH(cpg, _lang)); // bug! see 26869
}
 
Example 16
Source File: XslElement.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * At runtime the compilation of xsl:element results in code that: (i)
 * evaluates the avt for the name, (ii) checks for a prefix in the name
 * (iii) generates a new prefix and create a new qname when necessary
 * (iv) calls startElement() on the handler (v) looks up a uri in the XML
 * when the prefix is not known at compile time (vi) calls namespace()
 * on the handler (vii) evaluates the contents (viii) calls endElement().
 */
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    // Optimize translation if element name is a literal
    if (_isLiteralName) {
        translateLiteral(classGen, methodGen);
        return;
    }

    if (!_ignore) {

        // if the qname is an AVT, then the qname has to be checked at runtime if it is a valid qname
        LocalVariableGen nameValue =
                methodGen.addLocalVariable2("nameValue",
                                            Util.getJCRefType(STRING_SIG),
                                            null);

        // store the name into a variable first so _name.translate only needs to be called once
        _name.translate(classGen, methodGen);
        nameValue.setStart(il.append(new ASTORE(nameValue.getIndex())));
        il.append(new ALOAD(nameValue.getIndex()));

        // call checkQName if the name is an AVT
        final int check = cpg.addMethodref(BASIS_LIBRARY_CLASS, "checkQName",
                        "("
                        +STRING_SIG
                        +")V");
        il.append(new INVOKESTATIC(check));

        // Push handler for call to endElement()
        il.append(methodGen.loadHandler());

        // load name value again
        nameValue.setEnd(il.append(new ALOAD(nameValue.getIndex())));

        if (_namespace != null) {
            _namespace.translate(classGen, methodGen);
        }
        else {
            il.append(ACONST_NULL);
        }

        // Push additional arguments
        il.append(methodGen.loadHandler());
        il.append(methodGen.loadDOM());
        il.append(methodGen.loadCurrentNode());

        // Invoke BasisLibrary.startXslElemCheckQName()
        il.append(new INVOKESTATIC(
        cpg.addMethodref(BASIS_LIBRARY_CLASS, "startXslElement",
                "(" + STRING_SIG
                + STRING_SIG
                + TRANSLET_OUTPUT_SIG
                + DOM_INTF_SIG + "I)" + STRING_SIG)));


    }

    translateContents(classGen, methodGen);

    if (!_ignore) {
        il.append(methodGen.endElement());
    }
}
 
Example 17
Source File: ParentLocationPath.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public void translateStep(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

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

    LocalVariableGen pathTemp
            = methodGen.addLocalVariable("parent_location_path_tmp1",
                                     Util.getJCRefType(NODE_ITERATOR_SIG),
                                     null, null);
    pathTemp.setStart(il.append(new ASTORE(pathTemp.getIndex())));

    _step.translate(classGen, methodGen);
    LocalVariableGen stepTemp
            = methodGen.addLocalVariable("parent_location_path_tmp2",
                                     Util.getJCRefType(NODE_ITERATOR_SIG),
                                     null, null);
    stepTemp.setStart(il.append(new ASTORE(stepTemp.getIndex())));

    // Create new StepIterator
    final int initSI = cpg.addMethodref(STEP_ITERATOR_CLASS,
                                        "<init>",
                                        "("
                                        +NODE_ITERATOR_SIG
                                        +NODE_ITERATOR_SIG
                                        +")V");
    il.append(new NEW(cpg.addClass(STEP_ITERATOR_CLASS)));
    il.append(DUP);

    pathTemp.setEnd(il.append(new ALOAD(pathTemp.getIndex())));
    stepTemp.setEnd(il.append(new ALOAD(stepTemp.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
    Expression stp = _step;
    if (stp instanceof ParentLocationPath)
        stp = ((ParentLocationPath)stp).getStep();

    if ((_path instanceof Step) && (stp instanceof Step)) {
        final int path = ((Step)_path).getAxis();
        final int step = ((Step)stp).getAxis();
        if ((path == Axis.DESCENDANTORSELF && step == Axis.CHILD) ||
            (path == Axis.PRECEDING        && step == Axis.PARENT)) {
            final int incl = cpg.addMethodref(NODE_ITERATOR_BASE,
                                              "includeSelf",
                                              "()" + NODE_ITERATOR_SIG);
            il.append(new INVOKEVIRTUAL(incl));
        }
    }

    /*
     * If this pattern contains a sequence of descendant iterators we
     * run the risk of returning the same node several times. We put
     * a new iterator on top of the existing one to assure node order
     * and prevent returning a single node multiple times.
     */
    if (_orderNodes) {
        final int order = cpg.addInterfaceMethodref(DOM_INTF,
                                                    ORDER_ITERATOR,
                                                    ORDER_ITERATOR_SIG);
        il.append(methodGen.loadDOM());
        il.append(SWAP);
        il.append(methodGen.loadContextNode());
        il.append(new INVOKEINTERFACE(order, 3));
    }
}
 
Example 18
Source File: LogicalExpr.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Compile expression and update true/false-lists
 */
public void translateDesynthesized(ClassGenerator classGen,
                                   MethodGenerator methodGen) {

    final InstructionList il = methodGen.getInstructionList();
    final SyntaxTreeNode parent = getParent();

    // Compile AND-expression
    if (_op == AND) {

        // Translate left hand side - must be true
        _left.translateDesynthesized(classGen, methodGen);

        // Need this for chaining any OR-expression children
        InstructionHandle middle = il.append(NOP);

        // Translate left right side - must be true
        _right.translateDesynthesized(classGen, methodGen);

        // Need this for chaining any OR-expression children
        InstructionHandle after = il.append(NOP);

        // Append child expression false-lists to our false-list
        _falseList.append(_right._falseList.append(_left._falseList));

        // Special case for OR-expression as a left child of AND.
        // The true-list of OR must point to second clause of AND.
        if ((_left instanceof LogicalExpr) &&
            (((LogicalExpr)_left).getOp() == OR)) {
            _left.backPatchTrueList(middle);
        }
        else if (_left instanceof NotCall) {
            _left.backPatchTrueList(middle);
        }
        else {
            _trueList.append(_left._trueList);
        }

        // Special case for OR-expression as a right child of AND
        // The true-list of OR must point to true-list of AND.
        if ((_right instanceof LogicalExpr) &&
            (((LogicalExpr)_right).getOp() == OR)) {
            _right.backPatchTrueList(after);
        }
        else if (_right instanceof NotCall) {
            _right.backPatchTrueList(after);
        }
        else {
            _trueList.append(_right._trueList);
        }
    }
    // Compile OR-expression
    else {
        // Translate left-hand side expression and produce true/false list
        _left.translateDesynthesized(classGen, methodGen);

        // This GOTO is used to skip over the code for the last test
        // in the case where the the first test succeeds
        InstructionHandle ih = il.append(new GOTO(null));

        // Translate right-hand side expression and produce true/false list
        _right.translateDesynthesized(classGen, methodGen);

        _left._trueList.backPatch(ih);
        _left._falseList.backPatch(ih.getNext());

        _falseList.append(_right._falseList);
        _trueList.add(ih).append(_right._trueList);
    }
}
 
Example 19
Source File: CallTemplate.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final Stylesheet stylesheet = classGen.getStylesheet();
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    // If there are Params in the stylesheet or WithParams in this call?
    if (stylesheet.hasLocalParams() || hasContents()) {
        _calleeTemplate = getCalleeTemplate();

        // Build the parameter list if the called template is simple named
        if (_calleeTemplate != null) {
            buildParameterList();
        }
        // This is only needed when the called template is not
        // a simple named template.
        else {
            // Push parameter frame
            final int push = cpg.addMethodref(TRANSLET_CLASS,
                                              PUSH_PARAM_FRAME,
                                              PUSH_PARAM_FRAME_SIG);
            il.append(classGen.loadTranslet());
            il.append(new INVOKEVIRTUAL(push));
            translateContents(classGen, methodGen);
        }
    }

    // Generate a valid Java method name
    final String className = stylesheet.getClassName();
    String methodName = Util.escape(_name.toString());

    // Load standard arguments
    il.append(classGen.loadTranslet());
    il.append(methodGen.loadDOM());
    il.append(methodGen.loadIterator());
    il.append(methodGen.loadHandler());
    il.append(methodGen.loadCurrentNode());

    // Initialize prefix of method signature
    StringBuffer methodSig = new StringBuffer("(" + DOM_INTF_SIG
        + NODE_ITERATOR_SIG + TRANSLET_OUTPUT_SIG + NODE_SIG);

    // If calling a simply named template, push actual arguments
    if (_calleeTemplate != null) {
        Vector calleeParams = _calleeTemplate.getParameters();
        int numParams = _parameters.length;

        for (int i = 0; i < numParams; i++) {
            SyntaxTreeNode node = (SyntaxTreeNode)_parameters[i];
            methodSig.append(OBJECT_SIG);   // append Object to signature

            // Push 'null' if Param to indicate no actual parameter specified
            if (node instanceof Param) {
                il.append(ACONST_NULL);
            }
            else {  // translate WithParam
                node.translate(classGen, methodGen);
            }
        }
    }

    // Complete signature and generate invokevirtual call
    methodSig.append(")V");
    il.append(new INVOKEVIRTUAL(cpg.addMethodref(className,
                                                 methodName,
                                                 methodSig.toString())));

    // Do not need to call Translet.popParamFrame() if we are
    // calling a simple named template.
    if (_calleeTemplate == null && (stylesheet.hasLocalParams() || hasContents())) {
        // Pop parameter frame
        final int pop = cpg.addMethodref(TRANSLET_CLASS,
                                         POP_PARAM_FRAME,
                                         POP_PARAM_FRAME_SIG);
        il.append(classGen.loadTranslet());
        il.append(new INVOKEVIRTUAL(pop));
    }
}
 
Example 20
Source File: BooleanExpr.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    ConstantPoolGen cpg = classGen.getConstantPool();
    InstructionList il = methodGen.getInstructionList();
    il.append(new PUSH(cpg, _value));
}