com.sun.org.apache.bcel.internal.generic.ConstantPoolGen

Here are the examples of the java api class com.sun.org.apache.bcel.internal.generic.ConstantPoolGen taken from open source projects.

1. GenerateIdCall#translate()

Project: openjdk
Source File: GenerateIdCall.java
View license
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final InstructionList il = methodGen.getInstructionList();
    if (argumentCount() == 0) {
        il.append(methodGen.loadContextNode());
    } else {
        // one argument
        argument().translate(classGen, methodGen);
    }
    final ConstantPoolGen cpg = classGen.getConstantPool();
    il.append(new INVOKESTATIC(cpg.addMethodref(BASIS_LIBRARY_CLASS, "generate_idF", // reuse signature
    GET_NODE_NAME_SIG)));
}

2. LangCall#translate()

Project: openjdk
Source File: LangCall.java
View license
/**
     * This method is called when the constructor is compiled in
     * Stylesheet.compileConstructor() and not as the syntax tree is traversed.
     */
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    final int tst = cpg.addMethodref(BASIS_LIBRARY_CLASS, "testLanguage", "(" + STRING_SIG + DOM_INTF_SIG + "I)Z");
    _lang.translate(classGen, methodGen);
    il.append(methodGen.loadDOM());
    if (classGen instanceof FilterGenerator)
        il.append(new ILOAD(1));
    else
        il.append(methodGen.loadContextNode());
    il.append(new INVOKESTATIC(tst));
}

3. LocalNameCall#translate()

Project: openjdk
Source File: LocalNameCall.java
View license
/**
     * This method is called when the constructor is compiled in
     * Stylesheet.compileConstructor() and not as the syntax tree is traversed.
     */
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    // Returns the name of a node in the DOM
    final int getNodeName = cpg.addInterfaceMethodref(DOM_INTF, "getNodeName", "(I)" + STRING_SIG);
    final int getLocalName = cpg.addMethodref(BASIS_LIBRARY_CLASS, "getLocalName", "(Ljava/lang/String;)" + "Ljava/lang/String;");
    super.translate(classGen, methodGen);
    il.append(new INVOKEINTERFACE(getNodeName, 2));
    il.append(new INVOKESTATIC(getLocalName));
}

4. Mode#compileGetChildren()

Project: openjdk
Source File: Mode.java
View license
public static void compileGetChildren(ClassGenerator classGen, MethodGenerator methodGen, int node) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    final int git = cpg.addInterfaceMethodref(DOM_INTF, GET_CHILDREN, GET_CHILDREN_SIG);
    il.append(methodGen.loadDOM());
    il.append(new ILOAD(node));
    il.append(new INVOKEINTERFACE(git, 2));
}

5. Mode#compileDefaultRecursion()

Project: openjdk
Source File: Mode.java
View license
/**
     * Compiles the default handling for DOM elements: traverse all children
     */
private InstructionList compileDefaultRecursion(ClassGenerator classGen, MethodGenerator methodGen, InstructionHandle next) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = new InstructionList();
    final String applyTemplatesSig = classGen.getApplyTemplatesSig();
    final int git = cpg.addInterfaceMethodref(DOM_INTF, GET_CHILDREN, GET_CHILDREN_SIG);
    final int applyTemplates = cpg.addMethodref(getClassName(), functionName(), applyTemplatesSig);
    il.append(classGen.loadTranslet());
    il.append(methodGen.loadDOM());
    il.append(methodGen.loadDOM());
    il.append(new ILOAD(_currentIndex));
    il.append(new INVOKEINTERFACE(git, 2));
    il.append(methodGen.loadHandler());
    il.append(new INVOKEVIRTUAL(applyTemplates));
    il.append(new GOTO_W(next));
    return il;
}

6. Mode#compileDefaultText()

Project: openjdk
Source File: Mode.java
View license
/**
     * Compiles the default action for DOM text nodes and attribute nodes:
     * output the node's text value
     */
private InstructionList compileDefaultText(ClassGenerator classGen, MethodGenerator methodGen, InstructionHandle next) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = new InstructionList();
    final int chars = cpg.addInterfaceMethodref(DOM_INTF, CHARACTERS, CHARACTERS_SIG);
    il.append(methodGen.loadDOM());
    il.append(new ILOAD(_currentIndex));
    il.append(methodGen.loadHandler());
    il.append(new INVOKEINTERFACE(chars, 3));
    il.append(new GOTO_W(next));
    return il;
}

7. NamespaceUriCall#translate()

Project: openjdk
Source File: NamespaceUriCall.java
View license
/**
     * Translate code that leaves a node's namespace URI (as a String)
     * on the stack
     */
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    // Returns the string value for a node in the DOM
    final int getNamespace = cpg.addInterfaceMethodref(DOM_INTF, "getNamespaceName", "(I)" + STRING_SIG);
    super.translate(classGen, methodGen);
    il.append(new INVOKEINTERFACE(getNamespace, 2));
}

8. Predicate#translate()

Project: openjdk
Source File: Predicate.java
View license
/**
     * Translate a predicate expression. If non of the optimizations apply
     * then this translation pushes two references on the stack: a reference
     * to a newly created filter object and a reference to the predicate's
     * closure. See class <code>Step</code> for further details.
     */
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    if (_nthPositionFilter || _nthDescendant) {
        _exp.translate(classGen, methodGen);
    } else if (isNodeValueTest() && (getParent() instanceof Step)) {
        _value.translate(classGen, methodGen);
        il.append(new CHECKCAST(cpg.addClass(STRING_CLASS)));
        il.append(new PUSH(cpg, ((EqualityExpr) _exp).getOp()));
    } else {
        translateFilter(classGen, methodGen);
    }
}

9. StringLengthCall#translate()

Project: openjdk
Source File: StringLengthCall.java
View license
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    if (argumentCount() > 0) {
        argument().translate(classGen, methodGen);
    } else {
        il.append(methodGen.loadContextNode());
        Type.Node.translateTo(classGen, methodGen, Type.String);
    }
    il.append(new INVOKESTATIC(cpg.addMethodref(BASIS_LIBRARY_CLASS, "getStringLength", "(Ljava/lang/String;)I")));
}

10. Text#loadAsArrayOffsetLength()

Project: openjdk
Source File: Text.java
View license
/**
     * Generates code that loads the array that will contain the character
     * data represented by this Text node, followed by the offset of the
     * data from the start of the array, and then the length of the data.
     *
     * The pre-condition to calling this method is that
     * canLoadAsArrayOffsetLength() returns true.
     * @see #canLoadArrayOffsetLength()
     */
public void loadAsArrayOffsetLength(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    final XSLTC xsltc = classGen.getParser().getXSLTC();
    // The XSLTC object keeps track of character data
    // that is to be stored in char arrays.
    final int offset = xsltc.addCharacterData(_text);
    final int length = _text.length();
    String charDataFieldName = STATIC_CHAR_DATA_FIELD + (xsltc.getCharacterDataCount() - 1);
    il.append(new GETSTATIC(cpg.addFieldref(xsltc.getClassName(), charDataFieldName, STATIC_CHAR_DATA_FIELD_SIG)));
    il.append(new PUSH(cpg, offset));
    il.append(new PUSH(cpg, _text.length()));
}

11. UnparsedEntityUriCall#translate()

Project: openjdk
Source File: UnparsedEntityUriCall.java
View license
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    // Feck the this pointer on the stack...
    il.append(methodGen.loadDOM());
    // ...then the entity name...
    _entity.translate(classGen, methodGen);
    // ...to get the URI from the DOM object.
    il.append(new INVOKEINTERFACE(cpg.addInterfaceMethodref(DOM_INTF, GET_UNPARSED_ENTITY_URI, GET_UNPARSED_ENTITY_URI_SIG), 2));
}

12. NodeType#translateTo()

Project: openjdk
Source File: NodeType.java
View license
/**
     * Expects a node on the stack and pushes a singleton node-set. Singleton
     * iterators are already started after construction.
     *
     * @see     com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo
     */
public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, NodeSetType type) {
    ConstantPoolGen cpg = classGen.getConstantPool();
    InstructionList il = methodGen.getInstructionList();
    // Create a new instance of SingletonIterator
    il.append(new NEW(cpg.addClass(SINGLETON_ITERATOR)));
    il.append(DUP_X1);
    il.append(SWAP);
    final int init = cpg.addMethodref(SINGLETON_ITERATOR, "<init>", "(" + NODE_SIG + ")V");
    il.append(new INVOKESPECIAL(init));
}

13. ObjectType#translateTo()

Project: openjdk
Source File: ObjectType.java
View license
/**
     * Expects an integer on the stack and pushes its string value by calling
     * <code>Integer.toString(int i)</code>.
     *
     * @see     com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo
     */
public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, StringType type) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    il.append(DUP);
    final BranchHandle ifNull = il.append(new IFNULL(null));
    il.append(new INVOKEVIRTUAL(cpg.addMethodref(_javaClassName, "toString", "()" + STRING_SIG)));
    final BranchHandle gotobh = il.append(new GOTO(null));
    ifNull.setTarget(il.append(POP));
    il.append(new PUSH(cpg, ""));
    gotobh.setTarget(il.append(NOP));
}

14. ReferenceType#translateTo()

Project: openjdk
Source File: ReferenceType.java
View license
/**
     * Translates reference into object of internal type <code>type</code>.
     *
     * @see     com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo
     */
public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, StringType type) {
    final int current = methodGen.getLocalIndex("current");
    ConstantPoolGen cpg = classGen.getConstantPool();
    InstructionList il = methodGen.getInstructionList();
    // If no current, conversion is a top-level
    if (current < 0) {
        // push root node
        il.append(new PUSH(cpg, DTM.ROOT_NODE));
    } else {
        il.append(new ILOAD(current));
    }
    il.append(methodGen.loadDOM());
    final int stringF = cpg.addMethodref(BASIS_LIBRARY_CLASS, "stringF", "(" + OBJECT_SIG + NODE_SIG + DOM_INTF_SIG + ")" + STRING_SIG);
    il.append(new INVOKESTATIC(stringF));
}

15. ReferenceType#translateTo()

Project: openjdk
Source File: ReferenceType.java
View license
/**
     * Translates a reference into an object of internal type <code>type</code>.
     *
     * @see     com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo
     */
public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, RealType type) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    il.append(methodGen.loadDOM());
    int index = cpg.addMethodref(BASIS_LIBRARY_CLASS, "numberF", "(" + OBJECT_SIG + DOM_INTF_SIG + ")D");
    il.append(new INVOKESTATIC(index));
}

16. ReferenceType#translateTo()

Project: openjdk
Source File: ReferenceType.java
View license
/**
     * Casts a reference into a NodeIterator.
     *
     * @see     com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo
     */
public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, NodeSetType type) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    int index = cpg.addMethodref(BASIS_LIBRARY_CLASS, "referenceToNodeSet", "(" + OBJECT_SIG + ")" + NODE_ITERATOR_SIG);
    il.append(new INVOKESTATIC(index));
    // Reset this iterator
    index = cpg.addInterfaceMethodref(NODE_ITERATOR, RESET, RESET_SIG);
    il.append(new INVOKEINTERFACE(index, 1));
}

17. StringType#translateFrom()

Project: openjdk
Source File: StringType.java
View license
/**
     * Translates an external (primitive) Java type into a string.
     *
     * @see     com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateFrom
     */
public void translateFrom(ClassGenerator classGen, MethodGenerator methodGen, Class clazz) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    if (clazz.getName().equals("java.lang.String")) {
        // same internal representation, convert null to ""
        il.append(DUP);
        final BranchHandle ifNonNull = il.append(new IFNONNULL(null));
        il.append(POP);
        il.append(new PUSH(cpg, ""));
        ifNonNull.setTarget(il.append(NOP));
    } else {
        ErrorMsg err = new ErrorMsg(ErrorMsg.DATA_CONVERSION_ERR, toString(), clazz.getName());
        classGen.getParser().reportError(Constants.FATAL, err);
    }
}

18. XslElement#translateLiteral()

Project: openjdk
Source File: XslElement.java
View license
/**
     * This method is called when the name of the element is known at compile time.
     * In this case, there is no need to inspect the element name at runtime to
     * determine if a prefix exists, needs to be generated, etc.
     */
public void translateLiteral(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    if (!_ignore) {
        il.append(methodGen.loadHandler());
        _name.translate(classGen, methodGen);
        il.append(DUP2);
        il.append(methodGen.startElement());
        if (_namespace != null) {
            il.append(methodGen.loadHandler());
            il.append(new PUSH(cpg, _prefix));
            _namespace.translate(classGen, methodGen);
            il.append(methodGen.namespace());
        }
    }
    translateContents(classGen, methodGen);
    if (!_ignore) {
        il.append(methodGen.endElement());
    }
}

19. AbsoluteLocationPath#translate()

Project: openjdk
Source File: AbsoluteLocationPath.java
View license
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    if (_path != null) {
        final int initAI = cpg.addMethodref(ABSOLUTE_ITERATOR, "<init>", "(" + NODE_ITERATOR_SIG + ")V");
        // Compile relative path iterator(s)
        //
        // 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
        // this argument to its constructor.  Instead we calculate the
        // value of the argument to the constructor first, store it in
        // a temporary variable, create the object and reload the argument
        // from the temporary to avoid the problem.
        _path.translate(classGen, methodGen);
        LocalVariableGen relPathIterator = methodGen.addLocalVariable("abs_location_path_tmp", Util.getJCRefType(NODE_ITERATOR_SIG), null, null);
        relPathIterator.setStart(il.append(new ASTORE(relPathIterator.getIndex())));
        // Create new AbsoluteIterator
        il.append(new NEW(cpg.addClass(ABSOLUTE_ITERATOR)));
        il.append(DUP);
        relPathIterator.setEnd(il.append(new ALOAD(relPathIterator.getIndex())));
        // Initialize AbsoluteIterator with iterator from the stack
        il.append(new INVOKESPECIAL(initAI));
    } else {
        final int gitr = cpg.addInterfaceMethodref(DOM_INTF, "getIterator", "()" + NODE_ITERATOR_SIG);
        il.append(methodGen.loadDOM());
        il.append(new INVOKEINTERFACE(gitr, 1));
    }
}

20. AbsolutePathPattern#translate()

Project: openjdk
Source File: AbsolutePathPattern.java
View license
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    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), null);
            il.append(DUP);
            local.setStart(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);
        }
    }
    final int getParent = cpg.addInterfaceMethodref(DOM_INTF, GET_PARENT, GET_PARENT_SIG);
    final int getType = cpg.addInterfaceMethodref(DOM_INTF, "getExpandedTypeID", "(I)I");
    InstructionHandle begin = il.append(methodGen.loadDOM());
    il.append(SWAP);
    il.append(new INVOKEINTERFACE(getParent, 2));
    if (_left instanceof AncestorPattern) {
        il.append(methodGen.loadDOM());
        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);
        /*
             * If _left is an ancestor pattern, backpatch this pattern's false
             * list to the loop that searches for more ancestors.
             */
        if (_left instanceof AncestorPattern) {
            final AncestorPattern ancestor = (AncestorPattern) _left;
            // clears list
            _falseList.backPatch(ancestor.getLoopHandle());
        }
        _falseList.append(_left._falseList);
    }
}

21. AncestorPattern#translate()

Project: openjdk
Source File: AncestorPattern.java
View license
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    InstructionHandle parent;
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    /*
         * The scope of this local var must be the entire method since
         * a another pattern may decide to jump back into the loop
         */
    final LocalVariableGen local = methodGen.addLocalVariable2("app", Util.getJCRefType(NODE_SIG), il.getEnd());
    final com.sun.org.apache.bcel.internal.generic.Instruction loadLocal = new ILOAD(local.getIndex());
    final com.sun.org.apache.bcel.internal.generic.Instruction storeLocal = new ISTORE(local.getIndex());
    if (_right instanceof StepPattern) {
        il.append(DUP);
        il.append(storeLocal);
        _right.translate(classGen, methodGen);
        il.append(methodGen.loadDOM());
        il.append(loadLocal);
    } else {
        _right.translate(classGen, methodGen);
        if (_right instanceof AncestorPattern) {
            il.append(methodGen.loadDOM());
            il.append(SWAP);
        }
    }
    if (_left != null) {
        final int getParent = cpg.addInterfaceMethodref(DOM_INTF, GET_PARENT, GET_PARENT_SIG);
        parent = il.append(new INVOKEINTERFACE(getParent, 2));
        il.append(DUP);
        il.append(storeLocal);
        _falseList.add(il.append(new IFLT(null)));
        il.append(loadLocal);
        _left.translate(classGen, methodGen);
        final SyntaxTreeNode p = getParent();
        if (p == null || p instanceof Instruction || p instanceof TopLevelElement) {
        // do nothing
        } 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 {
        il.append(POP2);
    }
    /*
         * If _right is an ancestor pattern, backpatch this pattern's false
         * list to the loop that searches for more ancestors.
         */
    if (_right instanceof AncestorPattern) {
        final AncestorPattern ancestor = (AncestorPattern) _right;
        // clears list
        _falseList.backPatch(ancestor.getLoopHandle());
    }
    _trueList.append(_right._trueList);
    _falseList.append(_right._falseList);
}

22. ApplyImports#translate()

Project: openjdk
Source File: ApplyImports.java
View license
/**
     * Translate call-template. A parameter frame is pushed only if
     * some template in the stylesheet uses parameters.
     */
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final Stylesheet stylesheet = classGen.getStylesheet();
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    final int current = methodGen.getLocalIndex("current");
    // Push the arguments that are passed to applyTemplates()
    il.append(classGen.loadTranslet());
    il.append(methodGen.loadDOM());
    il.append(methodGen.loadIterator());
    il.append(methodGen.loadHandler());
    il.append(methodGen.loadCurrentNode());
    // parameters.  The apply-imports has nothing that it can pass.
    if (stylesheet.hasLocalParams()) {
        il.append(classGen.loadTranslet());
        final int pushFrame = cpg.addMethodref(TRANSLET_CLASS, PUSH_PARAM_FRAME, PUSH_PARAM_FRAME_SIG);
        il.append(new INVOKEVIRTUAL(pushFrame));
    }
    // Get the [min,max> precedence of all templates imported under the
    // current stylesheet
    final int maxPrecedence = _precedence;
    final int minPrecedence = getMinPrecedence(maxPrecedence);
    final Mode mode = stylesheet.getMode(_modeName);
    // Get name of appropriate apply-templates function for this
    // xsl:apply-imports instruction
    String functionName = mode.functionName(minPrecedence, maxPrecedence);
    // Construct the translet class-name and the signature of the method
    final String className = classGen.getStylesheet().getClassName();
    final String signature = classGen.getApplyTemplatesSigForImport();
    final int applyTemplates = cpg.addMethodref(className, functionName, signature);
    il.append(new INVOKEVIRTUAL(applyTemplates));
    // Pop any parameter frame that was pushed above.
    if (stylesheet.hasLocalParams()) {
        il.append(classGen.loadTranslet());
        final int pushFrame = cpg.addMethodref(TRANSLET_CLASS, POP_PARAM_FRAME, POP_PARAM_FRAME_SIG);
        il.append(new INVOKEVIRTUAL(pushFrame));
    }
}

23. ApplyTemplates#translate()

Project: openjdk
Source File: ApplyTemplates.java
View license
/**
     * Translate call-template. A parameter frame is pushed only if
     * some template in the stylesheet uses parameters.
     */
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    boolean setStartNodeCalled = false;
    final Stylesheet stylesheet = classGen.getStylesheet();
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    final int current = methodGen.getLocalIndex("current");
    // check if sorting nodes is required
    final Vector<Sort> sortObjects = new Vector<>();
    for (final SyntaxTreeNode child : getContents()) {
        if (child instanceof Sort) {
            sortObjects.addElement((Sort) child);
        }
    }
    // Push a new parameter frame
    if (stylesheet.hasLocalParams() || hasContents()) {
        il.append(classGen.loadTranslet());
        final int pushFrame = cpg.addMethodref(TRANSLET_CLASS, PUSH_PARAM_FRAME, PUSH_PARAM_FRAME_SIG);
        il.append(new INVOKEVIRTUAL(pushFrame));
        // translate with-params
        translateContents(classGen, methodGen);
    }
    il.append(classGen.loadTranslet());
    // The 'select' expression is a result-tree
    if ((_type != null) && (_type instanceof ResultTreeType)) {
        // <xsl:sort> cannot be applied to a result tree - issue warning
        if (sortObjects.size() > 0) {
            ErrorMsg err = new ErrorMsg(ErrorMsg.RESULT_TREE_SORT_ERR, this);
            getParser().reportError(WARNING, err);
        }
        // Put the result tree (a DOM adapter) on the stack
        _select.translate(classGen, methodGen);
        // Get back the DOM and iterator (not just iterator!!!)
        _type.translateTo(classGen, methodGen, Type.NodeSet);
    } else {
        il.append(methodGen.loadDOM());
        // compute node iterator for applyTemplates
        if (sortObjects.size() > 0) {
            Sort.translateSortIterator(classGen, methodGen, _select, sortObjects);
            int setStartNode = cpg.addInterfaceMethodref(NODE_ITERATOR, SET_START_NODE, "(I)" + NODE_ITERATOR_SIG);
            il.append(methodGen.loadCurrentNode());
            il.append(new INVOKEINTERFACE(setStartNode, 2));
            setStartNodeCalled = true;
        } else {
            if (_select == null)
                Mode.compileGetChildren(classGen, methodGen, current);
            else
                _select.translate(classGen, methodGen);
        }
    }
    if (_select != null && !setStartNodeCalled) {
        _select.startIterator(classGen, methodGen);
    }
    //!!! need to instantiate all needed modes
    final String className = classGen.getStylesheet().getClassName();
    il.append(methodGen.loadHandler());
    final String applyTemplatesSig = classGen.getApplyTemplatesSig();
    final int applyTemplates = cpg.addMethodref(className, _functionName, applyTemplatesSig);
    il.append(new INVOKEVIRTUAL(applyTemplates));
    // unmap parameters to release temporary result trees
    for (final SyntaxTreeNode child : getContents()) {
        if (child instanceof WithParam) {
            ((WithParam) child).releaseResultTree(classGen, methodGen);
        }
    }
    // Pop parameter frame
    if (stylesheet.hasLocalParams() || hasContents()) {
        il.append(classGen.loadTranslet());
        final int popFrame = cpg.addMethodref(TRANSLET_CLASS, POP_PARAM_FRAME, POP_PARAM_FRAME_SIG);
        il.append(new INVOKEVIRTUAL(popFrame));
    }
}

24. BooleanExpr#translate()

Project: openjdk
Source File: BooleanExpr.java
View license
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    ConstantPoolGen cpg = classGen.getConstantPool();
    InstructionList il = methodGen.getInstructionList();
    il.append(new PUSH(cpg, _value));
}

25. CallTemplate#translate()

Project: openjdk
Source File: CallTemplate.java
View license
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();
        } else // This is only needed when the called template is not
        // a simple named template.
        {
            // 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) {
        int numParams = _parameters.length;
        for (int i = 0; i < numParams; i++) {
            SyntaxTreeNode node = _parameters[i];
            // append Object to signature
            methodSig.append(OBJECT_SIG);
            // 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())));
    // release temporary result trees
    if (_parameters != null) {
        for (int i = 0; i < _parameters.length; i++) {
            if (_parameters[i] instanceof WithParam) {
                ((WithParam) _parameters[i]).releaseResultTree(classGen, methodGen);
            }
        }
    }
    // 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));
    }
}

26. CastCall#translate()

Project: openjdk
Source File: CastCall.java
View license
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)));
}

27. CeilingCall#translate()

Project: openjdk
Source File: CeilingCall.java
View license
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    argument(0).translate(classGen, methodGen);
    il.append(new INVOKESTATIC(cpg.addMethodref(MATH_CLASS, "ceil", "(D)D")));
}

28. Comment#translate()

Project: openjdk
Source File: Comment.java
View license
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    // Shortcut for literal strings
    Text rawText = null;
    if (elementCount() == 1) {
        Object content = elementAt(0);
        if (content instanceof Text) {
            rawText = (Text) content;
        }
    }
    // and call comment(String) with the result.
    if (rawText != null) {
        il.append(methodGen.loadHandler());
        if (rawText.canLoadAsArrayOffsetLength()) {
            rawText.loadAsArrayOffsetLength(classGen, methodGen);
            final int comment = cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE, "comment", "([CII)V");
            il.append(new INVOKEINTERFACE(comment, 4));
        } else {
            il.append(new PUSH(cpg, rawText.getText()));
            final int comment = cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE, "comment", "(" + STRING_SIG + ")V");
            il.append(new INVOKEINTERFACE(comment, 2));
        }
    } else {
        // Save the current handler base on the stack
        il.append(methodGen.loadHandler());
        // first arg to "comment" call
        il.append(DUP);
        // Get the translet's StringValueHandler
        il.append(classGen.loadTranslet());
        il.append(new GETFIELD(cpg.addFieldref(TRANSLET_CLASS, "stringValueHandler", STRING_VALUE_HANDLER_SIG)));
        il.append(DUP);
        il.append(methodGen.storeHandler());
        // translate contents with substituted handler
        translateContents(classGen, methodGen);
        // get String out of the handler
        il.append(new INVOKEVIRTUAL(cpg.addMethodref(STRING_VALUE_HANDLER, "getValue", "()" + STRING_SIG)));
        // call "comment"
        final int comment = cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE, "comment", "(" + STRING_SIG + ")V");
        il.append(new INVOKEINTERFACE(comment, 2));
        // Restore old handler base from stack
        il.append(methodGen.storeHandler());
    }
}

29. ConcatCall#translate()

Project: openjdk
Source File: ConcatCall.java
View license
/** translate leaves a String on the stack */
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    final int nArgs = argumentCount();
    switch(nArgs) {
        case 0:
            il.append(new PUSH(cpg, EMPTYSTRING));
            break;
        case 1:
            argument().translate(classGen, methodGen);
            break;
        default:
            final int initBuffer = cpg.addMethodref(STRING_BUFFER_CLASS, "<init>", "()V");
            final Instruction append = new INVOKEVIRTUAL(cpg.addMethodref(STRING_BUFFER_CLASS, "append", "(" + STRING_SIG + ")" + STRING_BUFFER_SIG));
            final int toString = cpg.addMethodref(STRING_BUFFER_CLASS, "toString", "()" + STRING_SIG);
            il.append(new NEW(cpg.addClass(STRING_BUFFER_CLASS)));
            il.append(DUP);
            il.append(new INVOKESPECIAL(initBuffer));
            for (int i = 0; i < nArgs; i++) {
                argument(i).translate(classGen, methodGen);
                il.append(append);
            }
            il.append(new INVOKEVIRTUAL(toString));
    }
}

30. ContainsCall#translateDesynthesized()

Project: openjdk
Source File: ContainsCall.java
View license
/**
     * Compile expression and update true/false-lists
     */
public void translateDesynthesized(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    _base.translate(classGen, methodGen);
    _token.translate(classGen, methodGen);
    il.append(new INVOKEVIRTUAL(cpg.addMethodref(STRING_CLASS, "indexOf", "(" + STRING_SIG + ")I")));
    _falseList.add(il.append(new IFLT(null)));
}

31. Copy#translate()

Project: openjdk
Source File: Copy.java
View license
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);
        } else // If not we have to check to see if the copy will result in an
        // element being output.
        {
            // 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);
}

32. CopyOf#translate()

Project: openjdk
Source File: CopyOf.java
View license
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
        //need a pointer to the DOM ;
        il.append(DUP);
        //ICONST_0);
        il.append(new INVOKEINTERFACE(getDoc, 1));
        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)));
    }
}

33. DecimalFormatting#translate()

Project: openjdk
Source File: DecimalFormatting.java
View license
/**
     * This method is called when the constructor is compiled in
     * Stylesheet.compileConstructor() and not as the syntax tree is traversed.
     */
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    ConstantPoolGen cpg = classGen.getConstantPool();
    InstructionList il = methodGen.getInstructionList();
    // DecimalFormatSymbols.<init>(Locale);
    // xsl:decimal-format - except for the NaN and infinity attributes.
    final int init = cpg.addMethodref(DFS_CLASS, "<init>", "(" + LOCALE_SIG + ")V");
    // Push the format name on the stack for call to addDecimalFormat()
    il.append(classGen.loadTranslet());
    il.append(new PUSH(cpg, _name.toString()));
    // Manufacture a DecimalFormatSymbols on the stack
    // for call to addDecimalFormat()
    // Use the US Locale as the default, as most of its settings
    // are equivalent to the default settings required of
    il.append(new NEW(cpg.addClass(DFS_CLASS)));
    il.append(DUP);
    il.append(new GETSTATIC(cpg.addFieldref(LOCALE_CLASS, "US", LOCALE_SIG)));
    il.append(new INVOKESPECIAL(init));
    String tmp = getAttribute("NaN");
    if ((tmp == null) || (tmp.equals(EMPTYSTRING))) {
        int nan = cpg.addMethodref(DFS_CLASS, "setNaN", "(Ljava/lang/String;)V");
        il.append(DUP);
        il.append(new PUSH(cpg, "NaN"));
        il.append(new INVOKEVIRTUAL(nan));
    }
    tmp = getAttribute("infinity");
    if ((tmp == null) || (tmp.equals(EMPTYSTRING))) {
        int inf = cpg.addMethodref(DFS_CLASS, "setInfinity", "(Ljava/lang/String;)V");
        il.append(DUP);
        il.append(new PUSH(cpg, "Infinity"));
        il.append(new INVOKEVIRTUAL(inf));
    }
    final int nAttributes = _attributes.getLength();
    for (int i = 0; i < nAttributes; i++) {
        final String name = _attributes.getQName(i);
        final String value = _attributes.getValue(i);
        boolean valid = true;
        int method = 0;
        if (name.equals("decimal-separator")) {
            // DecimalFormatSymbols.setDecimalSeparator();
            method = cpg.addMethodref(DFS_CLASS, "setDecimalSeparator", "(C)V");
        } else if (name.equals("grouping-separator")) {
            method = cpg.addMethodref(DFS_CLASS, "setGroupingSeparator", "(C)V");
        } else if (name.equals("minus-sign")) {
            method = cpg.addMethodref(DFS_CLASS, "setMinusSign", "(C)V");
        } else if (name.equals("percent")) {
            method = cpg.addMethodref(DFS_CLASS, "setPercent", "(C)V");
        } else if (name.equals("per-mille")) {
            method = cpg.addMethodref(DFS_CLASS, "setPerMill", "(C)V");
        } else if (name.equals("zero-digit")) {
            method = cpg.addMethodref(DFS_CLASS, "setZeroDigit", "(C)V");
        } else if (name.equals("digit")) {
            method = cpg.addMethodref(DFS_CLASS, "setDigit", "(C)V");
        } else if (name.equals("pattern-separator")) {
            method = cpg.addMethodref(DFS_CLASS, "setPatternSeparator", "(C)V");
        } else if (name.equals("NaN")) {
            method = cpg.addMethodref(DFS_CLASS, "setNaN", "(Ljava/lang/String;)V");
            il.append(DUP);
            il.append(new PUSH(cpg, value));
            il.append(new INVOKEVIRTUAL(method));
            valid = false;
        } else if (name.equals("infinity")) {
            method = cpg.addMethodref(DFS_CLASS, "setInfinity", "(Ljava/lang/String;)V");
            il.append(DUP);
            il.append(new PUSH(cpg, value));
            il.append(new INVOKEVIRTUAL(method));
            valid = false;
        } else {
            valid = false;
        }
        if (valid) {
            il.append(DUP);
            il.append(new PUSH(cpg, value.charAt(0)));
            il.append(new INVOKEVIRTUAL(method));
        }
    }
    final int put = cpg.addMethodref(TRANSLET_CLASS, "addDecimalFormat", "(" + STRING_SIG + DFS_SIG + ")V");
    il.append(new INVOKEVIRTUAL(put));
}

34. DecimalFormatting#translateDefaultDFS()

Project: openjdk
Source File: DecimalFormatting.java
View license
/**
     * Creates the default, nameless, DecimalFormat object in
     * AbstractTranslet's format_symbols hashtable.
     * This should be called for every stylesheet, and the entry
     * may be overridden by later nameless xsl:decimal-format instructions.
     */
public static void translateDefaultDFS(ClassGenerator classGen, MethodGenerator methodGen) {
    ConstantPoolGen cpg = classGen.getConstantPool();
    InstructionList il = methodGen.getInstructionList();
    final int init = cpg.addMethodref(DFS_CLASS, "<init>", "(" + LOCALE_SIG + ")V");
    // Push the format name, which is empty, on the stack
    // for call to addDecimalFormat()
    il.append(classGen.loadTranslet());
    il.append(new PUSH(cpg, EMPTYSTRING));
    // Manufacture a DecimalFormatSymbols on the stack for
    // call to addDecimalFormat().  Use the US Locale as the
    // default, as most of its settings are equivalent to
    // the default settings required of xsl:decimal-format -
    // except for the NaN and infinity attributes.
    il.append(new NEW(cpg.addClass(DFS_CLASS)));
    il.append(DUP);
    il.append(new GETSTATIC(cpg.addFieldref(LOCALE_CLASS, "US", LOCALE_SIG)));
    il.append(new INVOKESPECIAL(init));
    int nan = cpg.addMethodref(DFS_CLASS, "setNaN", "(Ljava/lang/String;)V");
    il.append(DUP);
    il.append(new PUSH(cpg, "NaN"));
    il.append(new INVOKEVIRTUAL(nan));
    int inf = cpg.addMethodref(DFS_CLASS, "setInfinity", "(Ljava/lang/String;)V");
    il.append(DUP);
    il.append(new PUSH(cpg, "Infinity"));
    il.append(new INVOKEVIRTUAL(inf));
    final int put = cpg.addMethodref(TRANSLET_CLASS, "addDecimalFormat", "(" + STRING_SIG + DFS_SIG + ")V");
    il.append(new INVOKEVIRTUAL(put));
}

35. DocumentCall#translate()

Project: openjdk
Source File: DocumentCall.java
View license
/**
     * Translates the document() function call to a call to LoadDocument()'s
     * static method document().
     */
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    final int ac = argumentCount();
    final int domField = cpg.addFieldref(classGen.getClassName(), DOM_FIELD, DOM_INTF_SIG);
    String docParamList = null;
    if (ac == 1) {
        // documentF(Object,String,AbstractTranslet,DOM)
        docParamList = "(" + OBJECT_SIG + STRING_SIG + TRANSLET_SIG + DOM_INTF_SIG + ")" + NODE_ITERATOR_SIG;
    } else {
        //ac == 2; ac < 1 or as >2  was tested in typeChec()
        // documentF(Object,DTMAxisIterator,String,AbstractTranslet,DOM)
        docParamList = "(" + OBJECT_SIG + NODE_ITERATOR_SIG + STRING_SIG + TRANSLET_SIG + DOM_INTF_SIG + ")" + NODE_ITERATOR_SIG;
    }
    final int docIdx = cpg.addMethodref(LOAD_DOCUMENT_CLASS, "documentF", docParamList);
    // The URI can be either a node-set or something else cast to a string
    _arg1.translate(classGen, methodGen);
    if (_arg1Type == Type.NodeSet) {
        _arg1.startIterator(classGen, methodGen);
    }
    if (ac == 2) {
        //_arg2 == null was tested in typeChec()
        _arg2.translate(classGen, methodGen);
        _arg2.startIterator(classGen, methodGen);
    }
    // Feck the rest of the parameters on the stack
    il.append(new PUSH(cpg, getStylesheet().getSystemId()));
    il.append(classGen.loadTranslet());
    il.append(DUP);
    il.append(new GETFIELD(domField));
    il.append(new INVOKESTATIC(docIdx));
}

36. ElementAvailableCall#translate()

Project: openjdk
Source File: ElementAvailableCall.java
View license
/**
     * Calls to 'element-available' are resolved at compile time since
     * the namespaces declared in the stylsheet are not available at run
     * time. Consequently, arguments to this function must be literals.
     */
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final boolean result = getResult();
    methodGen.getInstructionList().append(new PUSH(cpg, result));
}

37. EqualityExpr#translate()

Project: openjdk
Source File: EqualityExpr.java
View license
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    final Type tleft = _left.getType();
    Type tright = _right.getType();
    if (tleft instanceof BooleanType || tleft instanceof NumberType) {
        translateDesynthesized(classGen, methodGen);
        synthesize(classGen, methodGen);
        return;
    }
    if (tleft instanceof StringType) {
        final int equals = cpg.addMethodref(STRING_CLASS, "equals", "(" + OBJECT_SIG + ")Z");
        _left.translate(classGen, methodGen);
        _right.translate(classGen, methodGen);
        il.append(new INVOKEVIRTUAL(equals));
        if (_op == Operators.NE) {
            il.append(ICONST_1);
            // not x <-> x xor 1
            il.append(IXOR);
        }
        return;
    }
    BranchHandle truec, falsec;
    if (tleft instanceof ResultTreeType) {
        if (tright instanceof BooleanType) {
            _right.translate(classGen, methodGen);
            if (_op == Operators.NE) {
                il.append(ICONST_1);
                // not x <-> x xor 1
                il.append(IXOR);
            }
            return;
        }
        if (tright instanceof RealType) {
            _left.translate(classGen, methodGen);
            tleft.translateTo(classGen, methodGen, Type.Real);
            _right.translate(classGen, methodGen);
            il.append(DCMPG);
            falsec = il.append(_op == Operators.EQ ? (BranchInstruction) new IFNE(null) : (BranchInstruction) new IFEQ(null));
            il.append(ICONST_1);
            truec = il.append(new GOTO(null));
            falsec.setTarget(il.append(ICONST_0));
            truec.setTarget(il.append(NOP));
            return;
        }
        // Next, result-tree/string and result-tree/result-tree comparisons
        _left.translate(classGen, methodGen);
        tleft.translateTo(classGen, methodGen, Type.String);
        _right.translate(classGen, methodGen);
        if (tright instanceof ResultTreeType) {
            tright.translateTo(classGen, methodGen, Type.String);
        }
        final int equals = cpg.addMethodref(STRING_CLASS, "equals", "(" + OBJECT_SIG + ")Z");
        il.append(new INVOKEVIRTUAL(equals));
        if (_op == Operators.NE) {
            il.append(ICONST_1);
            // not x <-> x xor 1
            il.append(IXOR);
        }
        return;
    }
    if (tleft instanceof NodeSetType && tright instanceof BooleanType) {
        _left.translate(classGen, methodGen);
        _left.startIterator(classGen, methodGen);
        Type.NodeSet.translateTo(classGen, methodGen, Type.Boolean);
        _right.translate(classGen, methodGen);
        // x != y <-> x xor y
        il.append(IXOR);
        if (_op == Operators.EQ) {
            il.append(ICONST_1);
            // not x <-> x xor 1
            il.append(IXOR);
        }
        return;
    }
    if (tleft instanceof NodeSetType && tright instanceof StringType) {
        _left.translate(classGen, methodGen);
        // needed ?
        _left.startIterator(classGen, methodGen);
        _right.translate(classGen, methodGen);
        il.append(new PUSH(cpg, _op));
        il.append(methodGen.loadDOM());
        final int cmp = cpg.addMethodref(BASIS_LIBRARY_CLASS, "compare", "(" + tleft.toSignature() + tright.toSignature() + "I" + DOM_INTF_SIG + ")Z");
        il.append(new INVOKESTATIC(cmp));
        return;
    }
    // Next, node-set/t for t in {real, string, node-set, result-tree}
    _left.translate(classGen, methodGen);
    _left.startIterator(classGen, methodGen);
    _right.translate(classGen, methodGen);
    _right.startIterator(classGen, methodGen);
    // Cast a result tree to a string to use an existing compare
    if (tright instanceof ResultTreeType) {
        tright.translateTo(classGen, methodGen, Type.String);
        tright = Type.String;
    }
    // Call the appropriate compare() from the BasisLibrary
    il.append(new PUSH(cpg, _op));
    il.append(methodGen.loadDOM());
    final int compare = cpg.addMethodref(BASIS_LIBRARY_CLASS, "compare", "(" + tleft.toSignature() + tright.toSignature() + "I" + DOM_INTF_SIG + ")Z");
    il.append(new INVOKESTATIC(compare));
}

38. Expression#synthesize()

Project: openjdk
Source File: Expression.java
View license
/**
     * Synthesize a boolean expression, i.e., either push a 0 or 1 onto the
     * operand stack for the next statement to succeed. Returns the handle
     * of the instruction to be backpatched.
     */
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));
}

39. Fallback#translate()

Project: openjdk
Source File: Fallback.java
View license
/**
     * Translate contents only if this fallback element is put in place of
     * some unsupported element or non-XSLTC extension element
     */
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    if (_active)
        translateContents(classGen, methodGen);
}

40. FilteredAbsoluteLocationPath#translate()

View license
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    if (_path != null) {
        final int initDFI = cpg.addMethodref(DUP_FILTERED_ITERATOR, "<init>", "(" + 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.
        // Compile relative path iterator(s)
        LocalVariableGen pathTemp = methodGen.addLocalVariable("filtered_absolute_location_path_tmp", Util.getJCRefType(NODE_ITERATOR_SIG), null, null);
        _path.translate(classGen, methodGen);
        pathTemp.setStart(il.append(new ASTORE(pathTemp.getIndex())));
        // Create new Dup Filter Iterator
        il.append(new NEW(cpg.addClass(DUP_FILTERED_ITERATOR)));
        il.append(DUP);
        pathTemp.setEnd(il.append(new ALOAD(pathTemp.getIndex())));
        // Initialize Dup Filter Iterator with iterator from the stack
        il.append(new INVOKESPECIAL(initDFI));
    } else {
        final int git = cpg.addInterfaceMethodref(DOM_INTF, "getIterator", "()" + NODE_ITERATOR_SIG);
        il.append(methodGen.loadDOM());
        il.append(new INVOKEINTERFACE(git, 1));
    }
}

41. FilterExpr#translatePredicates()

Project: openjdk
Source File: FilterExpr.java
View license
/**
     * Translate a sequence of predicates. Each predicate is translated
     * by constructing an instance of <code>CurrentNodeListIterator</code>
     * which is initialized from another iterator (recursive call), a
     * filter and a closure (call to translate on the predicate) and "this".
     */
public void translatePredicates(ClassGenerator classGen, MethodGenerator methodGen, int predicateIndex) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    // If not predicates left, translate primary expression
    if (predicateIndex < 0) {
        translateFilterExpr(classGen, methodGen, predicateIndex);
    } else {
        // Get the next predicate to be translated
        Predicate predicate = (Predicate) _predicates.get(predicateIndex--);
        // Translate the rest of the predicates from right to left
        translatePredicates(classGen, methodGen, predicateIndex);
        if (predicate.isNthPositionFilter()) {
            int nthIteratorIdx = cpg.addMethodref(NTH_ITERATOR_CLASS, "<init>", "(" + NODE_ITERATOR_SIG + "I)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 unti
            // 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 iteratorTemp = methodGen.addLocalVariable("filter_expr_tmp1", Util.getJCRefType(NODE_ITERATOR_SIG), null, null);
            iteratorTemp.setStart(il.append(new ASTORE(iteratorTemp.getIndex())));
            predicate.translate(classGen, methodGen);
            LocalVariableGen predicateValueTemp = methodGen.addLocalVariable("filter_expr_tmp2", Util.getJCRefType("I"), null, null);
            predicateValueTemp.setStart(il.append(new ISTORE(predicateValueTemp.getIndex())));
            il.append(new NEW(cpg.addClass(NTH_ITERATOR_CLASS)));
            il.append(DUP);
            iteratorTemp.setEnd(il.append(new ALOAD(iteratorTemp.getIndex())));
            predicateValueTemp.setEnd(il.append(new ILOAD(predicateValueTemp.getIndex())));
            il.append(new INVOKESPECIAL(nthIteratorIdx));
        } else {
            // Translate predicates from right to left
            final int initCNLI = cpg.addMethodref(CURRENT_NODE_LIST_ITERATOR, "<init>", "(" + NODE_ITERATOR_SIG + "Z" + CURRENT_NODE_LIST_FILTER_SIG + NODE_SIG + TRANSLET_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.
            LocalVariableGen nodeIteratorTemp = methodGen.addLocalVariable("filter_expr_tmp1", Util.getJCRefType(NODE_ITERATOR_SIG), null, null);
            nodeIteratorTemp.setStart(il.append(new ASTORE(nodeIteratorTemp.getIndex())));
            predicate.translate(classGen, methodGen);
            LocalVariableGen filterTemp = methodGen.addLocalVariable("filter_expr_tmp2", Util.getJCRefType(CURRENT_NODE_LIST_FILTER_SIG), null, null);
            filterTemp.setStart(il.append(new ASTORE(filterTemp.getIndex())));
            // Create a CurrentNodeListIterator
            il.append(new NEW(cpg.addClass(CURRENT_NODE_LIST_ITERATOR)));
            il.append(DUP);
            // Initialize CurrentNodeListIterator
            nodeIteratorTemp.setEnd(il.append(new ALOAD(nodeIteratorTemp.getIndex())));
            il.append(ICONST_1);
            filterTemp.setEnd(il.append(new ALOAD(filterTemp.getIndex())));
            il.append(methodGen.loadCurrentNode());
            il.append(classGen.loadTranslet());
            il.append(new INVOKESPECIAL(initCNLI));
        }
    }
}

42. FilterParentPath#translate()

Project: openjdk
Source File: FilterParentPath.java
View license
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    // Create new StepIterator
    final int initSI = cpg.addMethodref(STEP_ITERATOR_CLASS, "<init>", "(" + NODE_ITERATOR_SIG + 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.
    // Recursively compile 2 iterators
    _filterExpr.translate(classGen, methodGen);
    LocalVariableGen filterTemp = methodGen.addLocalVariable("filter_parent_path_tmp1", Util.getJCRefType(NODE_ITERATOR_SIG), null, null);
    filterTemp.setStart(il.append(new ASTORE(filterTemp.getIndex())));
    _path.translate(classGen, methodGen);
    LocalVariableGen pathTemp = methodGen.addLocalVariable("filter_parent_path_tmp2", Util.getJCRefType(NODE_ITERATOR_SIG), null, null);
    pathTemp.setStart(il.append(new ASTORE(pathTemp.getIndex())));
    il.append(new NEW(cpg.addClass(STEP_ITERATOR_CLASS)));
    il.append(DUP);
    filterTemp.setEnd(il.append(new ALOAD(filterTemp.getIndex())));
    pathTemp.setEnd(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
    if (_hasDescendantAxis) {
        final int incl = cpg.addMethodref(NODE_ITERATOR_BASE, "includeSelf", "()" + NODE_ITERATOR_SIG);
        il.append(new INVOKEVIRTUAL(incl));
    }
    SyntaxTreeNode parent = getParent();
    boolean parentAlreadyOrdered = (parent instanceof RelativeLocationPath) || (parent instanceof FilterParentPath) || (parent instanceof KeyCall) || (parent instanceof CurrentCall) || (parent instanceof DocumentCall);
    if (!parentAlreadyOrdered) {
        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));
    }
}

43. ForEach#translate()

Project: openjdk
Source File: ForEach.java
View license
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    // Save current node and current iterator on the stack
    il.append(methodGen.loadCurrentNode());
    il.append(methodGen.loadIterator());
    // Collect sort objects associated with this instruction
    final Vector sortObjects = new Vector();
    Iterator<SyntaxTreeNode> children = elements();
    while (children.hasNext()) {
        final Object child = children.next();
        if (child instanceof Sort) {
            sortObjects.addElement(child);
        }
    }
    if ((_type != null) && (_type instanceof ResultTreeType)) {
        // Store existing DOM on stack - must be restored when loop is done
        il.append(methodGen.loadDOM());
        // <xsl:sort> cannot be applied to a result tree - issue warning
        if (sortObjects.size() > 0) {
            ErrorMsg msg = new ErrorMsg(ErrorMsg.RESULT_TREE_SORT_ERR, this);
            getParser().reportError(WARNING, msg);
        }
        // Put the result tree on the stack (DOM)
        _select.translate(classGen, methodGen);
        // Get an iterator for the whole DOM - excluding the root node
        _type.translateTo(classGen, methodGen, Type.NodeSet);
        // Store the result tree as the default DOM
        il.append(SWAP);
        il.append(methodGen.storeDOM());
    } else {
        // Compile node iterator
        if (sortObjects.size() > 0) {
            Sort.translateSortIterator(classGen, methodGen, _select, sortObjects);
        } else {
            _select.translate(classGen, methodGen);
        }
        if (_type instanceof ReferenceType == false) {
            il.append(methodGen.loadContextNode());
            il.append(methodGen.setStartNode());
        }
    }
    // Overwrite current iterator
    il.append(methodGen.storeIterator());
    // Give local variables (if any) default values before starting loop
    initializeVariables(classGen, methodGen);
    final BranchHandle nextNode = il.append(new GOTO(null));
    final InstructionHandle loop = il.append(NOP);
    translateContents(classGen, methodGen);
    nextNode.setTarget(il.append(methodGen.loadIterator()));
    il.append(methodGen.nextNode());
    il.append(DUP);
    il.append(methodGen.storeCurrentNode());
    il.append(new IFGT(loop));
    // Restore current DOM (if result tree was used instead for this loop)
    if ((_type != null) && (_type instanceof ResultTreeType)) {
        il.append(methodGen.storeDOM());
    }
    // Restore current node and current iterator from the stack
    il.append(methodGen.storeIterator());
    il.append(methodGen.storeCurrentNode());
}

44. FormatNumberCall#translate()

Project: openjdk
Source File: FormatNumberCall.java
View license
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    _value.translate(classGen, methodGen);
    _format.translate(classGen, methodGen);
    final int fn3arg = cpg.addMethodref(BASIS_LIBRARY_CLASS, "formatNumber", "(DLjava/lang/String;" + "Ljava/text/DecimalFormat;)" + "Ljava/lang/String;");
    final int get = cpg.addMethodref(TRANSLET_CLASS, "getDecimalFormat", "(Ljava/lang/String;)" + "Ljava/text/DecimalFormat;");
    il.append(classGen.loadTranslet());
    if (_name == null) {
        il.append(new PUSH(cpg, EMPTYSTRING));
    } else if (_resolvedQName != null) {
        il.append(new PUSH(cpg, _resolvedQName.toString()));
    } else {
        _name.translate(classGen, methodGen);
    }
    il.append(new INVOKEVIRTUAL(get));
    il.append(new INVOKESTATIC(fn3arg));
}

45. FunctionAvailableCall#translate()

Project: openjdk
Source File: FunctionAvailableCall.java
View license
/**
     * Calls to 'function-available' are resolved at compile time since
     * the namespaces declared in the stylsheet are not available at run
     * time. Consequently, arguments to this function must be literals.
     */
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    methodGen.getInstructionList().append(new PUSH(cpg, getResult()));
}

46. FunctionCall#translate()

Project: openjdk
Source File: FunctionCall.java
View license
/**
     * Translate a function call. The compiled code will leave the function's
     * return value on the JVM's stack.
     */
@Override
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final int n = argumentCount();
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    final boolean isSecureProcessing = classGen.getParser().getXSLTC().isSecureProcessing();
    final boolean isExtensionFunctionEnabled = classGen.getParser().getXSLTC().getFeature(FeatureManager.Feature.ORACLE_ENABLE_EXTENSION_FUNCTION);
    int index;
    // Translate calls to methods in the BasisLibrary
    if (isStandard() || isExtension()) {
        for (int i = 0; i < n; i++) {
            final Expression exp = argument(i);
            exp.translate(classGen, methodGen);
            exp.startIterator(classGen, methodGen);
        }
        // append "F" to the function's name
        final String name = _fname.toString().replace('-', '_') + "F";
        String args = Constants.EMPTYSTRING;
        // Special precautions for some method calls
        if (name.equals("sumF")) {
            args = DOM_INTF_SIG;
            il.append(methodGen.loadDOM());
        } else if (name.equals("normalize_spaceF")) {
            if (_chosenMethodType.toSignature(args).equals("()Ljava/lang/String;")) {
                args = "I" + DOM_INTF_SIG;
                il.append(methodGen.loadContextNode());
                il.append(methodGen.loadDOM());
            }
        }
        // Invoke the method in the basis library
        index = cpg.addMethodref(BASIS_LIBRARY_CLASS, name, _chosenMethodType.toSignature(args));
        il.append(new INVOKESTATIC(index));
    } else // run-time error message for unsupported external functions
    if (unresolvedExternal) {
        index = cpg.addMethodref(BASIS_LIBRARY_CLASS, "unresolved_externalF", "(Ljava/lang/String;)V");
        il.append(new PUSH(cpg, _fname.toString()));
        il.append(new INVOKESTATIC(index));
    } else if (_isExtConstructor) {
        if (isSecureProcessing && !isExtensionFunctionEnabled)
            translateUnallowedExtension(cpg, il);
        final String clazz = _chosenConstructor.getDeclaringClass().getName();
        Class[] paramTypes = _chosenConstructor.getParameterTypes();
        LocalVariableGen[] paramTemp = new LocalVariableGen[n];
        for (int i = 0; i < n; i++) {
            final Expression exp = argument(i);
            Type expType = exp.getType();
            exp.translate(classGen, methodGen);
            // Convert the argument to its Java type
            exp.startIterator(classGen, methodGen);
            expType.translateTo(classGen, methodGen, paramTypes[i]);
            paramTemp[i] = methodGen.addLocalVariable("function_call_tmp" + i, expType.toJCType(), null, null);
            paramTemp[i].setStart(il.append(expType.STORE(paramTemp[i].getIndex())));
        }
        il.append(new NEW(cpg.addClass(_className)));
        il.append(InstructionConstants.DUP);
        for (int i = 0; i < n; i++) {
            final Expression arg = argument(i);
            paramTemp[i].setEnd(il.append(arg.getType().LOAD(paramTemp[i].getIndex())));
        }
        final StringBuffer buffer = new StringBuffer();
        buffer.append('(');
        for (int i = 0; i < paramTypes.length; i++) {
            buffer.append(getSignature(paramTypes[i]));
        }
        buffer.append(')');
        buffer.append("V");
        index = cpg.addMethodref(clazz, "<init>", buffer.toString());
        il.append(new INVOKESPECIAL(index));
        // Convert the return type back to our internal type
        (Type.Object).translateFrom(classGen, methodGen, _chosenConstructor.getDeclaringClass());
    } else // Invoke function calls that are handled in separate classes
    {
        if (isSecureProcessing && !isExtensionFunctionEnabled)
            translateUnallowedExtension(cpg, il);
        final String clazz = _chosenMethod.getDeclaringClass().getName();
        Class[] paramTypes = _chosenMethod.getParameterTypes();
        // Push "this" if it is an instance method
        if (_thisArgument != null) {
            _thisArgument.translate(classGen, methodGen);
        }
        for (int i = 0; i < n; i++) {
            final Expression exp = argument(i);
            exp.translate(classGen, methodGen);
            // Convert the argument to its Java type
            exp.startIterator(classGen, methodGen);
            exp.getType().translateTo(classGen, methodGen, paramTypes[i]);
        }
        final StringBuffer buffer = new StringBuffer();
        buffer.append('(');
        for (int i = 0; i < paramTypes.length; i++) {
            buffer.append(getSignature(paramTypes[i]));
        }
        buffer.append(')');
        buffer.append(getSignature(_chosenMethod.getReturnType()));
        if (_thisArgument != null && _clazz.isInterface()) {
            index = cpg.addInterfaceMethodref(clazz, _fname.getLocalPart(), buffer.toString());
            il.append(new INVOKEINTERFACE(index, n + 1));
        } else {
            index = cpg.addMethodref(clazz, _fname.getLocalPart(), buffer.toString());
            il.append(_thisArgument != null ? (InvokeInstruction) new INVOKEVIRTUAL(index) : (InvokeInstruction) new INVOKESTATIC(index));
        }
        // Convert the return type back to our internal type
        _type.translateFrom(classGen, methodGen, _chosenMethod.getReturnType());
    }
}

47. IdKeyPattern#translate()

Project: openjdk
Source File: IdKeyPattern.java
View license
/**
     * This method is called when the constructor is compiled in
     * Stylesheet.compileConstructor() and not as the syntax tree is traversed.
     */
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);
    // Initialises a KeyIndex to return nodes with specific values
    final int lookupId = cpg.addMethodref(KEY_INDEX_CLASS, "containsID", "(ILjava/lang/Object;)I");
    final int lookupKey = cpg.addMethodref(KEY_INDEX_CLASS, "containsKey", "(ILjava/lang/Object;)I");
    final int getNodeIdent = cpg.addInterfaceMethodref(DOM_INTF, "getNodeIdent", "(I)" + NODE_SIG);
    // Call getKeyIndex in AbstractTranslet with the name of the key
    // to get the index for this key (which is also a node iterator).
    il.append(classGen.loadTranslet());
    il.append(new PUSH(cpg, _index));
    il.append(new INVOKEVIRTUAL(getKeyIndex));
    // Now use the value in the second argument to determine what nodes
    // the iterator should return.
    il.append(SWAP);
    il.append(new PUSH(cpg, _value));
    if (this instanceof IdPattern) {
        il.append(new INVOKEVIRTUAL(lookupId));
    } else {
        il.append(new INVOKEVIRTUAL(lookupKey));
    }
    _trueList.add(il.append(new IFNE(null)));
    _falseList.add(il.append(new GOTO(null)));
}

48. IntExpr#translate()

Project: openjdk
Source File: IntExpr.java
View license
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    ConstantPoolGen cpg = classGen.getConstantPool();
    InstructionList il = methodGen.getInstructionList();
    il.append(new PUSH(cpg, _value));
}

49. Key#traverseNodeSet()

Project: openjdk
Source File: Key.java
View license
/**
     * This method is called if the "use" attribute of the key contains a
     * node set. In this case we must traverse all nodes in the set and
     * create one entry in this key's index for each node in the set.
     */
public void traverseNodeSet(ClassGenerator classGen, MethodGenerator methodGen, int buildKeyIndex) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    // DOM.getStringValueX(nodeIndex) => String
    final int getNodeValue = cpg.addInterfaceMethodref(DOM_INTF, GET_NODE_VALUE, "(I)" + STRING_SIG);
    final int getNodeIdent = cpg.addInterfaceMethodref(DOM_INTF, "getNodeIdent", "(I)" + NODE_SIG);
    // AbstractTranslet.SetKeyIndexDom(name, Dom) => void
    final int keyDom = cpg.addMethodref(TRANSLET_CLASS, "setKeyIndexDom", "(" + STRING_SIG + DOM_INTF_SIG + ")V");
    // This variable holds the id of the node we found with the "match"
    // attribute of xsl:key. This is the id we store, with the value we
    // get from the nodes we find here, in the index for this key.
    final LocalVariableGen parentNode = methodGen.addLocalVariable("parentNode", Util.getJCRefType("I"), null, null);
    // Get the 'parameter' from the stack and store it in a local var.
    parentNode.setStart(il.append(new ISTORE(parentNode.getIndex())));
    // Save current node and current iterator on the stack
    il.append(methodGen.loadCurrentNode());
    il.append(methodGen.loadIterator());
    // 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());
    // Go on to next matching node....
    il.append(new IFGE(loop));
    // Restore current node and current iterator from the stack
    il.append(methodGen.storeIterator());
    il.append(methodGen.storeCurrentNode());
}

50. Key#translate()

Project: openjdk
Source File: Key.java
View license
/**
     * Gather all nodes that match the expression in the attribute "match"
     * and add one (or more) entries in this key's index.
     */
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    final int current = methodGen.getLocalIndex("current");
    // AbstractTranslet.buildKeyIndex(name,node_id,value) => void
    final int key = cpg.addMethodref(TRANSLET_CLASS, "buildKeyIndex", "(" + STRING_SIG + "I" + STRING_SIG + ")V");
    // AbstractTranslet.SetKeyIndexDom(name, Dom) => void
    final int keyDom = cpg.addMethodref(TRANSLET_CLASS, "setKeyIndexDom", "(" + STRING_SIG + DOM_INTF_SIG + ")V");
    final int getNodeIdent = cpg.addInterfaceMethodref(DOM_INTF, "getNodeIdent", "(I)" + NODE_SIG);
    // DOM.getAxisIterator(root) => NodeIterator
    final int git = cpg.addInterfaceMethodref(DOM_INTF, "getAxisIterator", "(I)" + NODE_ITERATOR_SIG);
    il.append(methodGen.loadCurrentNode());
    il.append(methodGen.loadIterator());
    // Get an iterator for all nodes in the DOM
    il.append(methodGen.loadDOM());
    il.append(new PUSH(cpg, Axis.DESCENDANT));
    il.append(new INVOKEINTERFACE(git, 2));
    // Reset the iterator to start with the root node
    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);
    // Leaves 0 or 1 on stack
    _match.synthesize(classGen, methodGen);
    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);
}

51. KeyCall#translate()

Project: openjdk
Source File: KeyCall.java
View license
/**
     * 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));
}

52. LiteralAttribute#translate()

Project: openjdk
Source File: LiteralAttribute.java
View license
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    // push handler
    il.append(methodGen.loadHandler());
    // push attribute name - namespace prefix set by parent node
    il.append(new PUSH(cpg, _name));
    // push attribute value
    _value.translate(classGen, methodGen);
    // Generate code that calls SerializationHandler.addUniqueAttribute()
    // if all attributes are unique.
    SyntaxTreeNode parent = getParent();
    if (parent instanceof LiteralElement && ((LiteralElement) parent).allAttributesUnique()) {
        int flags = 0;
        boolean isHTMLAttrEmpty = false;
        ElemDesc elemDesc = ((LiteralElement) parent).getElemDesc();
        // Set the HTML flags
        if (elemDesc != null) {
            if (elemDesc.isAttrFlagSet(_name, ElemDesc.ATTREMPTY)) {
                flags = flags | SerializationHandler.HTML_ATTREMPTY;
                isHTMLAttrEmpty = true;
            } else if (elemDesc.isAttrFlagSet(_name, ElemDesc.ATTRURL)) {
                flags = flags | SerializationHandler.HTML_ATTRURL;
            }
        }
        if (_value instanceof SimpleAttributeValue) {
            String attrValue = ((SimpleAttributeValue) _value).toString();
            if (!hasBadChars(attrValue) && !isHTMLAttrEmpty) {
                flags = flags | SerializationHandler.NO_BAD_CHARS;
            }
        }
        il.append(new PUSH(cpg, flags));
        il.append(methodGen.uniqueAttribute());
    } else {
        // call attribute
        il.append(methodGen.attribute());
    }
}

53. LiteralElement#translate()

Project: openjdk
Source File: LiteralElement.java
View license
/**
     * Compiles code that emits the literal element to the output handler,
     * first the start tag, then namespace declaration, then attributes,
     * then the element contents, and then the element end tag. Since the
     * value of an attribute may depend on a variable, variables must be
     * compiled first.
     */
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    // Check whether all attributes are unique.
    _allAttributesUnique = checkAttributesUnique();
    // Compile code to emit element start tag
    il.append(methodGen.loadHandler());
    il.append(new PUSH(cpg, _name));
    // duplicate these 2 args for endElement
    il.append(DUP2);
    il.append(methodGen.startElement());
    // The value of an attribute may depend on a (sibling) variable
    int j = 0;
    while (j < elementCount()) {
        final SyntaxTreeNode item = (SyntaxTreeNode) elementAt(j);
        if (item instanceof Variable) {
            item.translate(classGen, methodGen);
        }
        j++;
    }
    // Compile code to emit namespace attributes
    if (_accessedPrefixes != null) {
        boolean declaresDefaultNS = false;
        for (Map.Entry<String, String> entry : _accessedPrefixes.entrySet()) {
            final String prefix = entry.getKey();
            final String uri = entry.getValue();
            if (uri != Constants.EMPTYSTRING || prefix != Constants.EMPTYSTRING) {
                if (prefix == Constants.EMPTYSTRING) {
                    declaresDefaultNS = true;
                }
                il.append(methodGen.loadHandler());
                il.append(new PUSH(cpg, prefix));
                il.append(new PUSH(cpg, uri));
                il.append(methodGen.namespace());
            }
        }
        /*
             * If our XslElement parent redeclares the default NS, and this
             * element doesn't, it must be redeclared one more time.
             */
        if (!declaresDefaultNS && (_parent instanceof XslElement) && ((XslElement) _parent).declaresDefaultNS()) {
            il.append(methodGen.loadHandler());
            il.append(new PUSH(cpg, Constants.EMPTYSTRING));
            il.append(new PUSH(cpg, Constants.EMPTYSTRING));
            il.append(methodGen.namespace());
        }
    }
    // Output all attributes
    if (_attributeElements != null) {
        for (SyntaxTreeNode node : _attributeElements) {
            if (!(node instanceof XslAttribute)) {
                node.translate(classGen, methodGen);
            }
        }
    }
    // Compile code to emit attributes and child elements
    translateContents(classGen, methodGen);
    // Compile code to emit element end tag
    il.append(methodGen.endElement());
}

54. LiteralExpr#translate()

Project: openjdk
Source File: LiteralExpr.java
View license
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    il.append(new PUSH(cpg, _value));
}

55. Message#translate()

Project: openjdk
Source File: Message.java
View license
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    // Load the translet (for call to displayMessage() function)
    il.append(classGen.loadTranslet());
    switch(elementCount()) {
        case 0:
            il.append(new PUSH(cpg, ""));
            break;
        case 1:
            SyntaxTreeNode child = (SyntaxTreeNode) elementAt(0);
            if (child instanceof Text) {
                il.append(new PUSH(cpg, ((Text) child).getText()));
                break;
            }
        // falls through
        default:
            // Push current output handler onto the stack
            il.append(methodGen.loadHandler());
            // Replace the current output handler by a ToXMLStream
            il.append(new NEW(cpg.addClass(STREAM_XML_OUTPUT)));
            il.append(methodGen.storeHandler());
            // Push a reference to a StringWriter
            il.append(new NEW(cpg.addClass(STRING_WRITER)));
            il.append(DUP);
            il.append(DUP);
            il.append(new INVOKESPECIAL(cpg.addMethodref(STRING_WRITER, "<init>", "()V")));
            // Load ToXMLStream
            il.append(methodGen.loadHandler());
            il.append(new INVOKESPECIAL(cpg.addMethodref(STREAM_XML_OUTPUT, "<init>", "()V")));
            // Invoke output.setWriter(STRING_WRITER)
            il.append(methodGen.loadHandler());
            il.append(SWAP);
            il.append(new INVOKEINTERFACE(cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE, "setWriter", "(" + WRITER_SIG + ")V"), 2));
            // Invoke output.setEncoding("UTF-8")
            il.append(methodGen.loadHandler());
            // other encodings?
            il.append(new PUSH(cpg, "UTF-8"));
            il.append(new INVOKEINTERFACE(cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE, "setEncoding", "(" + STRING_SIG + ")V"), 2));
            // Invoke output.setOmitXMLDeclaration(true)
            il.append(methodGen.loadHandler());
            il.append(ICONST_1);
            il.append(new INVOKEINTERFACE(cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE, "setOmitXMLDeclaration", "(Z)V"), 2));
            il.append(methodGen.loadHandler());
            il.append(new INVOKEINTERFACE(cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE, "startDocument", "()V"), 1));
            // Inline translation of contents
            translateContents(classGen, methodGen);
            il.append(methodGen.loadHandler());
            il.append(new INVOKEINTERFACE(cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE, "endDocument", "()V"), 1));
            // Call toString() on StringWriter
            il.append(new INVOKEVIRTUAL(cpg.addMethodref(STRING_WRITER, "toString", "()" + STRING_SIG)));
            // Restore old output handler
            il.append(SWAP);
            il.append(methodGen.storeHandler());
            break;
    }
    // Send the resulting string to the message handling method
    il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS, "displayMessage", "(" + STRING_SIG + ")V")));
    // RunTimeException, but it on the stack and throw an exception
    if (_terminate == true) {
        // Create a new instance of RunTimeException
        final int einit = cpg.addMethodref("java.lang.RuntimeException", "<init>", "(Ljava/lang/String;)V");
        il.append(new NEW(cpg.addClass("java.lang.RuntimeException")));
        il.append(DUP);
        il.append(new PUSH(cpg, "Termination forced by an " + "xsl:message instruction"));
        il.append(new INVOKESPECIAL(einit));
        il.append(ATHROW);
    }
}

56. Mode#compileNamedTemplate()

Project: openjdk
Source File: Mode.java
View license
private void compileNamedTemplate(Template template, ClassGenerator classGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = new InstructionList();
    String methodName = Util.escape(template.getName().toString());
    int numParams = 0;
    if (template.isSimpleNamedTemplate()) {
        Vector parameters = template.getParameters();
        numParams = parameters.size();
    }
    // Initialize the types and names arrays for the NamedMethodGenerator.
    com.sun.org.apache.bcel.internal.generic.Type[] types = new com.sun.org.apache.bcel.internal.generic.Type[4 + numParams];
    String[] names = new String[4 + numParams];
    types[0] = Util.getJCRefType(DOM_INTF_SIG);
    types[1] = Util.getJCRefType(NODE_ITERATOR_SIG);
    types[2] = Util.getJCRefType(TRANSLET_OUTPUT_SIG);
    types[3] = com.sun.org.apache.bcel.internal.generic.Type.INT;
    names[0] = DOCUMENT_PNAME;
    names[1] = ITERATOR_PNAME;
    names[2] = TRANSLET_OUTPUT_PNAME;
    names[3] = NODE_PNAME;
    // template.
    for (int i = 4; i < 4 + numParams; i++) {
        types[i] = Util.getJCRefType(OBJECT_SIG);
        names[i] = "param" + String.valueOf(i - 4);
    }
    NamedMethodGenerator methodGen = new NamedMethodGenerator(ACC_PUBLIC, com.sun.org.apache.bcel.internal.generic.Type.VOID, types, names, methodName, getClassName(), il, cpg);
    il.append(template.compile(classGen, methodGen));
    il.append(RETURN);
    classGen.addMethod(methodGen);
}

57. Mode#compileNamespaces()

Project: openjdk
Source File: Mode.java
View license
private InstructionList compileNamespaces(ClassGenerator classGen, MethodGenerator methodGen, boolean[] isNamespace, boolean[] isAttribute, boolean attrFlag, InstructionHandle defaultTarget) {
    final XSLTC xsltc = classGen.getParser().getXSLTC();
    final ConstantPoolGen cpg = classGen.getConstantPool();
    // Append switch() statement - namespace test dispatch loop
    final Vector namespaces = xsltc.getNamespaceIndex();
    final Vector names = xsltc.getNamesIndex();
    final int namespaceCount = namespaces.size() + 1;
    final int namesCount = names.size();
    final InstructionList il = new InstructionList();
    final int[] types = new int[namespaceCount];
    final InstructionHandle[] targets = new InstructionHandle[types.length];
    if (namespaceCount > 0) {
        boolean compiled = false;
        // Initialize targets for namespace() switch statement
        for (int i = 0; i < namespaceCount; i++) {
            targets[i] = defaultTarget;
            types[i] = i;
        }
        // Add test sequences for known namespace types
        for (int i = DTM.NTYPES; i < (DTM.NTYPES + namesCount); i++) {
            if ((isNamespace[i]) && (isAttribute[i] == attrFlag)) {
                String name = (String) names.elementAt(i - DTM.NTYPES);
                String namespace = name.substring(0, name.lastIndexOf(':'));
                final int type = xsltc.registerNamespace(namespace);
                if ((i < _testSeq.length) && (_testSeq[i] != null)) {
                    targets[type] = (_testSeq[i]).compile(classGen, methodGen, defaultTarget);
                    compiled = true;
                }
            }
        }
        // Return "null" if no test sequences were compiled
        if (!compiled)
            return (null);
        // Append first code in applyTemplates() - get type of current node
        final int getNS = cpg.addInterfaceMethodref(DOM_INTF, "getNamespaceType", "(I)I");
        il.append(methodGen.loadDOM());
        il.append(new ILOAD(_currentIndex));
        il.append(new INVOKEINTERFACE(getNS, 2));
        il.append(new SWITCH(types, targets, defaultTarget));
        return (il);
    } else {
        return (null);
    }
}

58. NameBase#translate()

Project: openjdk
Source File: NameBase.java
View license
/**
     * Translate the code required for getting the node for which the
     * QName, local-name or namespace URI should be extracted.
     */
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    il.append(methodGen.loadDOM());
    // Function was called with no parameters
    if (argumentCount() == 0) {
        il.append(methodGen.loadContextNode());
    } else // Function was called with node parameter
    if (_paramType == Type.Node) {
        _param.translate(classGen, methodGen);
    } else if (_paramType == Type.Reference) {
        _param.translate(classGen, methodGen);
        il.append(new INVOKESTATIC(cpg.addMethodref(BASIS_LIBRARY_CLASS, "referenceToNodeSet", "(" + OBJECT_SIG + ")" + NODE_ITERATOR_SIG)));
        il.append(methodGen.nextNode());
    } else // Function was called with node-set parameter
    {
        _param.translate(classGen, methodGen);
        _param.startIterator(classGen, methodGen);
        il.append(methodGen.nextNode());
    }
}

59. NameCall#translate()

Project: openjdk
Source File: NameCall.java
View license
/**
     * Translate code that leaves a node's QName (as a String) on the stack
     */
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    final int getName = cpg.addInterfaceMethodref(DOM_INTF, GET_NODE_NAME, GET_NODE_NAME_SIG);
    super.translate(classGen, methodGen);
    il.append(new INVOKEINTERFACE(getName, 2));
}

60. Number#compileDefault()

Project: openjdk
Source File: Number.java
View license
private void compileDefault(ClassGenerator classGen, MethodGenerator methodGen) {
    int index;
    ConstantPoolGen cpg = classGen.getConstantPool();
    InstructionList il = methodGen.getInstructionList();
    int[] fieldIndexes = getXSLTC().getNumberFieldIndexes();
    if (fieldIndexes[_level] == -1) {
        Field defaultNode = new Field(ACC_PRIVATE, cpg.addUtf8(FieldNames[_level]), cpg.addUtf8(NODE_COUNTER_SIG), null, cpg.getConstantPool());
        // Add a new private field to this class
        classGen.addField(defaultNode);
        // Get a reference to the newly added field
        fieldIndexes[_level] = cpg.addFieldref(classGen.getClassName(), FieldNames[_level], NODE_COUNTER_SIG);
    }
    // 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));
}

61. Number#compileConstructor()

Project: openjdk
Source File: Number.java
View license
/**
     * Compiles a constructor for the class <tt>_className</tt> that
     * inherits from {Any,Single,Multiple}NodeCounter. This constructor
     * simply calls the same constructor in the super class.
     */
private void compileConstructor(ClassGenerator classGen) {
    MethodGenerator cons;
    final InstructionList il = new InstructionList();
    final ConstantPoolGen cpg = classGen.getConstantPool();
    cons = new MethodGenerator(ACC_PUBLIC, com.sun.org.apache.bcel.internal.generic.Type.VOID, new com.sun.org.apache.bcel.internal.generic.Type[] { Util.getJCRefType(TRANSLET_INTF_SIG), Util.getJCRefType(DOM_INTF_SIG), Util.getJCRefType(NODE_ITERATOR_SIG), com.sun.org.apache.bcel.internal.generic.Type.BOOLEAN }, new String[] { "dom", "translet", "iterator", "hasFrom" }, "<init>", _className, il, cpg);
    // this
    il.append(ALOAD_0);
    // translet
    il.append(ALOAD_1);
    // DOM
    il.append(ALOAD_2);
    // iterator
    il.append(new ALOAD(3));
    // hasFrom
    il.append(new ILOAD(4));
    int index = cpg.addMethodref(ClassNames[_level], "<init>", "(" + TRANSLET_INTF_SIG + DOM_INTF_SIG + NODE_ITERATOR_SIG + "Z)V");
    il.append(new INVOKESPECIAL(index));
    il.append(RETURN);
    classGen.addMethod(cons);
}

62. Number#compileLocals()

Project: openjdk
Source File: Number.java
View license
/**
     * This method compiles code that is common to matchesFrom() and
     * matchesCount() in the auxillary class.
     */
private void compileLocals(NodeCounterGenerator nodeCounterGen, MatchGenerator matchGen, InstructionList il) {
    int field;
    LocalVariableGen local;
    ConstantPoolGen cpg = nodeCounterGen.getConstantPool();
    // Get NodeCounter._iterator and store locally
    local = matchGen.addLocalVariable("iterator", Util.getJCRefType(NODE_ITERATOR_SIG), null, null);
    field = cpg.addFieldref(NODE_COUNTER, "_iterator", ITERATOR_FIELD_SIG);
    // 'this' pointer on stack
    il.append(ALOAD_0);
    il.append(new GETFIELD(field));
    local.setStart(il.append(new ASTORE(local.getIndex())));
    matchGen.setIteratorIndex(local.getIndex());
    // Get NodeCounter._translet and store locally
    local = matchGen.addLocalVariable("translet", Util.getJCRefType(TRANSLET_SIG), null, null);
    field = cpg.addFieldref(NODE_COUNTER, "_translet", "Lcom/sun/org/apache/xalan/internal/xsltc/Translet;");
    // 'this' pointer on stack
    il.append(ALOAD_0);
    il.append(new GETFIELD(field));
    il.append(new CHECKCAST(cpg.addClass(TRANSLET_CLASS)));
    local.setStart(il.append(new ASTORE(local.getIndex())));
    nodeCounterGen.setTransletIndex(local.getIndex());
    // Get NodeCounter._document and store locally
    local = matchGen.addLocalVariable("document", Util.getJCRefType(DOM_INTF_SIG), null, null);
    field = cpg.addFieldref(_className, "_document", DOM_INTF_SIG);
    // 'this' pointer on stack
    il.append(ALOAD_0);
    il.append(new GETFIELD(field));
    // Make sure we have the correct DOM type on the stack!!!
    local.setStart(il.append(new ASTORE(local.getIndex())));
    matchGen.setDomIndex(local.getIndex());
}

63. Number#compilePatterns()

Project: openjdk
Source File: Number.java
View license
private void compilePatterns(ClassGenerator classGen, MethodGenerator methodGen) {
    int current;
    int field;
    LocalVariableGen local;
    MatchGenerator matchGen;
    NodeCounterGenerator nodeCounterGen;
    _className = getXSLTC().getHelperClassName();
    nodeCounterGen = new NodeCounterGenerator(_className, ClassNames[_level], toString(), ACC_PUBLIC | ACC_SUPER, null, classGen.getStylesheet());
    InstructionList il = null;
    ConstantPoolGen cpg = nodeCounterGen.getConstantPool();
    // Add a new instance variable for each var in closure
    final int closureLen = (_closureVars == null) ? 0 : _closureVars.size();
    for (int i = 0; i < closureLen; i++) {
        VariableBase var = ((VariableRefBase) _closureVars.get(i)).getVariable();
        nodeCounterGen.addField(new Field(ACC_PUBLIC, cpg.addUtf8(var.getEscapedName()), cpg.addUtf8(var.getType().toSignature()), null, cpg.getConstantPool()));
    }
    // Add a single constructor to the class
    compileConstructor(nodeCounterGen);
    /*
         * Compile method matchesFrom()
         */
    if (_from != null) {
        il = new InstructionList();
        matchGen = new MatchGenerator(ACC_PUBLIC | ACC_FINAL, com.sun.org.apache.bcel.internal.generic.Type.BOOLEAN, new com.sun.org.apache.bcel.internal.generic.Type[] { com.sun.org.apache.bcel.internal.generic.Type.INT }, new String[] { "node" }, "matchesFrom", _className, il, cpg);
        compileLocals(nodeCounterGen, matchGen, il);
        // Translate Pattern
        il.append(matchGen.loadContextNode());
        _from.translate(nodeCounterGen, matchGen);
        _from.synthesize(nodeCounterGen, matchGen);
        il.append(IRETURN);
        nodeCounterGen.addMethod(matchGen);
    }
    /*
         * Compile method matchesCount()
         */
    if (_count != null) {
        il = new InstructionList();
        matchGen = new MatchGenerator(ACC_PUBLIC | ACC_FINAL, com.sun.org.apache.bcel.internal.generic.Type.BOOLEAN, new com.sun.org.apache.bcel.internal.generic.Type[] { com.sun.org.apache.bcel.internal.generic.Type.INT }, new String[] { "node" }, "matchesCount", _className, il, cpg);
        compileLocals(nodeCounterGen, matchGen, il);
        // Translate Pattern
        il.append(matchGen.loadContextNode());
        _count.translate(nodeCounterGen, matchGen);
        _count.synthesize(nodeCounterGen, matchGen);
        il.append(IRETURN);
        nodeCounterGen.addMethod(matchGen);
    }
    getXSLTC().dumpClass(nodeCounterGen.getJavaClass());
    // Push an instance of the newly created class
    cpg = classGen.getConstantPool();
    il = methodGen.getInstructionList();
    final int index = cpg.addMethodref(_className, "<init>", "(" + TRANSLET_INTF_SIG + DOM_INTF_SIG + NODE_ITERATOR_SIG + "Z)V");
    il.append(new NEW(cpg.addClass(_className)));
    il.append(DUP);
    il.append(classGen.loadTranslet());
    il.append(methodGen.loadDOM());
    il.append(methodGen.loadIterator());
    il.append(_from != null ? ICONST_1 : ICONST_0);
    il.append(new INVOKESPECIAL(index));
    // Initialize closure variables
    for (int i = 0; i < closureLen; i++) {
        final VariableRefBase varRef = (VariableRefBase) _closureVars.get(i);
        final VariableBase var = varRef.getVariable();
        final Type varType = var.getType();
        // Store variable in new closure
        il.append(DUP);
        il.append(var.loadInstruction());
        il.append(new PUTFIELD(cpg.addFieldref(_className, var.getEscapedName(), varType.toSignature())));
    }
}

64. Number#translate()

Project: openjdk
Source File: Number.java
View license
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    int index;
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    // Push "this" for the call to characters()
    il.append(classGen.loadTranslet());
    if (hasValue()) {
        compileDefault(classGen, methodGen);
        _value.translate(classGen, methodGen);
        // Using java.lang.Math.floor(number + 0.5) to return a double value
        il.append(new PUSH(cpg, 0.5));
        il.append(DADD);
        index = cpg.addMethodref(MATH_CLASS, "floor", "(D)D");
        il.append(new INVOKESTATIC(index));
        // Call setValue on the node counter
        index = cpg.addMethodref(NODE_COUNTER, "setValue", "(D)" + NODE_COUNTER_SIG);
        il.append(new INVOKEVIRTUAL(index));
    } else if (isDefault()) {
        compileDefault(classGen, methodGen);
    } else {
        compilePatterns(classGen, methodGen);
    }
    // Call setStartNode()
    if (!hasValue()) {
        il.append(methodGen.loadContextNode());
        index = cpg.addMethodref(NODE_COUNTER, SET_START_NODE, "(I)" + NODE_COUNTER_SIG);
        il.append(new INVOKEVIRTUAL(index));
    }
    // Call getCounter() with or without args
    if (_formatNeeded) {
        if (_format != null) {
            _format.translate(classGen, methodGen);
        } else {
            il.append(new PUSH(cpg, "1"));
        }
        if (_lang != null) {
            _lang.translate(classGen, methodGen);
        } else {
            // TODO ??
            il.append(new PUSH(cpg, "en"));
        }
        if (_letterValue != null) {
            _letterValue.translate(classGen, methodGen);
        } else {
            il.append(new PUSH(cpg, Constants.EMPTYSTRING));
        }
        if (_groupingSeparator != null) {
            _groupingSeparator.translate(classGen, methodGen);
        } else {
            il.append(new PUSH(cpg, Constants.EMPTYSTRING));
        }
        if (_groupingSize != null) {
            _groupingSize.translate(classGen, methodGen);
        } else {
            il.append(new PUSH(cpg, "0"));
        }
        index = cpg.addMethodref(NODE_COUNTER, "getCounter", "(" + STRING_SIG + STRING_SIG + STRING_SIG + STRING_SIG + STRING_SIG + ")" + STRING_SIG);
        il.append(new INVOKEVIRTUAL(index));
    } else {
        index = cpg.addMethodref(NODE_COUNTER, "setDefaultFormatting", "()" + NODE_COUNTER_SIG);
        il.append(new INVOKEVIRTUAL(index));
        index = cpg.addMethodref(NODE_COUNTER, "getCounter", "()" + STRING_SIG);
        il.append(new INVOKEVIRTUAL(index));
    }
    // Output the resulting string to the handler
    il.append(methodGen.loadHandler());
    index = cpg.addMethodref(TRANSLET_CLASS, CHARACTERSW, CHARACTERSW_SIG);
    il.append(new INVOKEVIRTUAL(index));
}

65. Output#translate()

Project: openjdk
Source File: Output.java
View license
/**
     * Compile code that passes the information in this <xsl:output> element
     * to the appropriate fields in the translet
     */
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    // Do nothing if other <xsl:output> element has higher precedence
    if (_disabled)
        return;
    ConstantPoolGen cpg = classGen.getConstantPool();
    InstructionList il = methodGen.getInstructionList();
    int field = 0;
    il.append(classGen.loadTranslet());
    // Only update _version field if set and different from default
    if ((_version != null) && (!_version.equals(XML_VERSION))) {
        field = cpg.addFieldref(TRANSLET_CLASS, "_version", STRING_SIG);
        il.append(DUP);
        il.append(new PUSH(cpg, _version));
        il.append(new PUTFIELD(field));
    }
    // Only update _method field if "method" attribute used
    if (_method != null) {
        field = cpg.addFieldref(TRANSLET_CLASS, "_method", STRING_SIG);
        il.append(DUP);
        il.append(new PUSH(cpg, _method));
        il.append(new PUTFIELD(field));
    }
    // Only update if _encoding field is "encoding" attribute used
    if (_encoding != null) {
        field = cpg.addFieldref(TRANSLET_CLASS, "_encoding", STRING_SIG);
        il.append(DUP);
        il.append(new PUSH(cpg, _encoding));
        il.append(new PUTFIELD(field));
    }
    // Only update if "omit-xml-declaration" used and set to 'yes'
    if (_omitHeader) {
        field = cpg.addFieldref(TRANSLET_CLASS, "_omitHeader", "Z");
        il.append(DUP);
        il.append(new PUSH(cpg, _omitHeader));
        il.append(new PUTFIELD(field));
    }
    // Add 'standalone' decaration to output - use text as is
    if (_standalone != null) {
        field = cpg.addFieldref(TRANSLET_CLASS, "_standalone", STRING_SIG);
        il.append(DUP);
        il.append(new PUSH(cpg, _standalone));
        il.append(new PUTFIELD(field));
    }
    // Set system/public doctype only if both are set
    field = cpg.addFieldref(TRANSLET_CLASS, "_doctypeSystem", STRING_SIG);
    il.append(DUP);
    il.append(new PUSH(cpg, _doctypeSystem));
    il.append(new PUTFIELD(field));
    field = cpg.addFieldref(TRANSLET_CLASS, "_doctypePublic", STRING_SIG);
    il.append(DUP);
    il.append(new PUSH(cpg, _doctypePublic));
    il.append(new PUTFIELD(field));
    // Add 'medye-type' decaration to output - if used
    if (_mediaType != null) {
        field = cpg.addFieldref(TRANSLET_CLASS, "_mediaType", STRING_SIG);
        il.append(DUP);
        il.append(new PUSH(cpg, _mediaType));
        il.append(new PUTFIELD(field));
    }
    // Compile code to set output indentation on/off
    if (_indent) {
        field = cpg.addFieldref(TRANSLET_CLASS, "_indent", "Z");
        il.append(DUP);
        il.append(new PUSH(cpg, _indent));
        il.append(new PUTFIELD(field));
    }
    //Compile code to set indent amount.
    if (_indentamount != null && !_indentamount.equals(EMPTYSTRING)) {
        field = cpg.addFieldref(TRANSLET_CLASS, "_indentamount", "I");
        il.append(DUP);
        il.append(new PUSH(cpg, Integer.parseInt(_indentamount)));
        il.append(new PUTFIELD(field));
    }
    // Forward to the translet any elements that should be output as CDATA
    if (_cdata != null) {
        int index = cpg.addMethodref(TRANSLET_CLASS, "addCdataElement", "(Ljava/lang/String;)V");
        StringTokenizer tokens = new StringTokenizer(_cdata);
        while (tokens.hasMoreTokens()) {
            il.append(DUP);
            il.append(new PUSH(cpg, tokens.nextToken()));
            il.append(new INVOKEVIRTUAL(index));
        }
    }
    // Cleanup - pop last translet reference off stack
    il.append(POP);
}

66. Param#translate()

Project: openjdk
Source File: Param.java
View license
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    if (_ignore)
        return;
    _ignore = true;
    /*
         * 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();
    final String className = _type.getClassName();
    if (isLocal()) {
        /*
              * If simple named template then generate a conditional init of the
              * 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));
        translateValue(classGen, methodGen);
        il.append(new PUSH(cpg, true));
        // Call addParameter() from this class
        il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS, ADD_PARAMETER, ADD_PARAMETER_SIG)));
        if (className != EMPTYSTRING) {
            il.append(new CHECKCAST(cpg.addClass(className)));
        }
        _type.translateUnBox(classGen, methodGen);
        if (_refs.isEmpty()) {
            // nobody uses the value
            il.append(_type.POP());
            _local = null;
        } else {
            // normal case
            _local = methodGen.addLocalVariable2(name, _type.toJCType(), il.getEnd());
            // Cache the result of addParameter() in a local variable
            il.append(_type.STORE(_local.getIndex()));
        }
    } else {
        if (classGen.containsField(name) == null) {
            classGen.addField(new Field(ACC_PUBLIC, cpg.addUtf8(name), cpg.addUtf8(signature), null, cpg.getConstantPool()));
            il.append(classGen.loadTranslet());
            il.append(DUP);
            il.append(new PUSH(cpg, name));
            translateValue(classGen, methodGen);
            il.append(new PUSH(cpg, true));
            // Call addParameter() from this class
            il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS, ADD_PARAMETER, ADD_PARAMETER_SIG)));
            _type.translateUnBox(classGen, methodGen);
            // Cache the result of addParameter() in a field
            if (className != EMPTYSTRING) {
                il.append(new CHECKCAST(cpg.addClass(className)));
            }
            il.append(new PUTFIELD(cpg.addFieldref(classGen.getClassName(), name, signature)));
        }
    }
}

67. ParameterRef#translate()

Project: openjdk
Source File: ParameterRef.java
View license
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));
    }
}

68. ParentLocationPath#translateStep()

Project: openjdk
Source File: ParentLocationPath.java
View license
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));
    }
}

69. ParentPattern#translate()

Project: openjdk
Source File: ParentPattern.java
View license
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    final LocalVariableGen local = methodGen.addLocalVariable2("ppt", Util.getJCRefType(NODE_SIG), null);
    final com.sun.org.apache.bcel.internal.generic.Instruction loadLocal = new ILOAD(local.getIndex());
    final com.sun.org.apache.bcel.internal.generic.Instruction storeLocal = new ISTORE(local.getIndex());
    if (_right.isWildcard()) {
        il.append(methodGen.loadDOM());
        il.append(SWAP);
    } else if (_right instanceof StepPattern) {
        il.append(DUP);
        local.setStart(il.append(storeLocal));
        _right.translate(classGen, methodGen);
        il.append(methodGen.loadDOM());
        local.setEnd(il.append(loadLocal));
    } else {
        _right.translate(classGen, methodGen);
        if (_right instanceof AncestorPattern) {
            il.append(methodGen.loadDOM());
            il.append(SWAP);
        }
    }
    final int getParent = cpg.addInterfaceMethodref(DOM_INTF, GET_PARENT, GET_PARENT_SIG);
    il.append(new INVOKEINTERFACE(getParent, 2));
    final SyntaxTreeNode p = getParent();
    if (p == null || p instanceof Instruction || p instanceof TopLevelElement) {
        _left.translate(classGen, methodGen);
    } else {
        il.append(DUP);
        InstructionHandle storeInst = il.append(storeLocal);
        if (local.getStart() == null) {
            local.setStart(storeInst);
        }
        _left.translate(classGen, methodGen);
        il.append(methodGen.loadDOM());
        local.setEnd(il.append(loadLocal));
    }
    methodGen.removeLocalVariable(local);
    /*
         * If _right is an ancestor pattern, backpatch _left false
         * list to the loop that searches for more ancestors.
         */
    if (_right instanceof AncestorPattern) {
        final AncestorPattern ancestor = (AncestorPattern) _right;
        // clears list
        _left.backPatchFalseList(ancestor.getLoopHandle());
    }
    _trueList.append(_right._trueList.append(_left._trueList));
    _falseList.append(_right._falseList.append(_left._falseList));
}

70. Predicate#compileFilter()

Project: openjdk
Source File: Predicate.java
View license
/**
     * Create a new "Filter" class implementing
     * <code>CurrentNodeListFilter</code>. Allocate registers for local
     * variables and local parameters passed in the closure to test().
     * Notice that local variables need to be "unboxed".
     */
private void compileFilter(ClassGenerator classGen, MethodGenerator methodGen) {
    TestGenerator testGen;
    LocalVariableGen local;
    FilterGenerator filterGen;
    _className = getXSLTC().getHelperClassName();
    filterGen = new FilterGenerator(_className, "java.lang.Object", toString(), ACC_PUBLIC | ACC_SUPER, new String[] { CURRENT_NODE_LIST_FILTER }, classGen.getStylesheet());
    final ConstantPoolGen cpg = filterGen.getConstantPool();
    final int length = (_closureVars == null) ? 0 : _closureVars.size();
    // Add a new instance variable for each var in closure
    for (int i = 0; i < length; i++) {
        VariableBase var = ((VariableRefBase) _closureVars.get(i)).getVariable();
        filterGen.addField(new Field(ACC_PUBLIC, cpg.addUtf8(var.getEscapedName()), cpg.addUtf8(var.getType().toSignature()), null, cpg.getConstantPool()));
    }
    final InstructionList il = new InstructionList();
    testGen = new TestGenerator(ACC_PUBLIC | ACC_FINAL, com.sun.org.apache.bcel.internal.generic.Type.BOOLEAN, new com.sun.org.apache.bcel.internal.generic.Type[] { com.sun.org.apache.bcel.internal.generic.Type.INT, com.sun.org.apache.bcel.internal.generic.Type.INT, com.sun.org.apache.bcel.internal.generic.Type.INT, com.sun.org.apache.bcel.internal.generic.Type.INT, Util.getJCRefType(TRANSLET_SIG), Util.getJCRefType(NODE_ITERATOR_SIG) }, new String[] { "node", "position", "last", "current", "translet", "iterator" }, "test", _className, il, cpg);
    // Store the dom in a local variable
    local = testGen.addLocalVariable("document", Util.getJCRefType(DOM_INTF_SIG), null, null);
    final String className = classGen.getClassName();
    il.append(filterGen.loadTranslet());
    il.append(new CHECKCAST(cpg.addClass(className)));
    il.append(new GETFIELD(cpg.addFieldref(className, DOM_FIELD, DOM_INTF_SIG)));
    local.setStart(il.append(new ASTORE(local.getIndex())));
    // Store the dom index in the test generator
    testGen.setDomIndex(local.getIndex());
    _exp.translate(filterGen, testGen);
    il.append(IRETURN);
    filterGen.addEmptyConstructor(ACC_PUBLIC);
    filterGen.addMethod(testGen);
    getXSLTC().dumpClass(filterGen.getJavaClass());
}

71. Predicate#translateFilter()

Project: openjdk
Source File: Predicate.java
View license
/**
     * Translate a predicate expression. This translation pushes
     * two references on the stack: a reference to a newly created
     * filter object and a reference to the predicate's closure.
     */
public void translateFilter(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    // Compile auxiliary class for filter
    compileFilter(classGen, methodGen);
    // Create new instance of filter
    il.append(new NEW(cpg.addClass(_className)));
    il.append(DUP);
    il.append(new INVOKESPECIAL(cpg.addMethodref(_className, "<init>", "()V")));
    // Initialize closure variables
    final int length = (_closureVars == null) ? 0 : _closureVars.size();
    for (int i = 0; i < length; i++) {
        VariableRefBase varRef = (VariableRefBase) _closureVars.get(i);
        VariableBase var = varRef.getVariable();
        Type varType = var.getType();
        il.append(DUP);
        // Find nearest closure implemented as an inner class
        Closure variableClosure = _parentClosure;
        while (variableClosure != null) {
            if (variableClosure.inInnerClass())
                break;
            variableClosure = variableClosure.getParentClosure();
        }
        // Use getfield if in an inner class
        if (variableClosure != null) {
            il.append(ALOAD_0);
            il.append(new GETFIELD(cpg.addFieldref(variableClosure.getInnerClassName(), var.getEscapedName(), varType.toSignature())));
        } else {
            // Use a load of instruction if in translet class
            il.append(var.loadInstruction());
        }
        // Store variable in new closure
        il.append(new PUTFIELD(cpg.addFieldref(_className, var.getEscapedName(), varType.toSignature())));
    }
}

72. ProcessingInstruction#translate()

Project: openjdk
Source File: ProcessingInstruction.java
View license
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    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), 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 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());
        // first arg to "attributes" call
        il.append(DUP);
        // load name value again
        nameValue.setEnd(il.append(new ALOAD(nameValue.getIndex())));
    } else {
        // Save the current handler base on the stack
        il.append(methodGen.loadHandler());
        // first arg to "attributes" call
        il.append(DUP);
        // Push attribute name
        // 2nd arg
        _name.translate(classGen, methodGen);
    }
    il.append(classGen.loadTranslet());
    il.append(new GETFIELD(cpg.addFieldref(TRANSLET_CLASS, "stringValueHandler", STRING_VALUE_HANDLER_SIG)));
    il.append(DUP);
    il.append(methodGen.storeHandler());
    // translate contents with substituted handler
    translateContents(classGen, methodGen);
    // get String out of the handler
    il.append(new INVOKEVIRTUAL(cpg.addMethodref(STRING_VALUE_HANDLER, "getValueOfPI", "()" + STRING_SIG)));
    // call "processingInstruction"
    final int processingInstruction = cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE, "processingInstruction", "(" + STRING_SIG + STRING_SIG + ")V");
    il.append(new INVOKEINTERFACE(processingInstruction, 3));
    // Restore old handler base from stack
    il.append(methodGen.storeHandler());
}

73. ProcessingInstructionPattern#translate()

View license
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));
}

74. RealExpr#translate()

Project: openjdk
Source File: RealExpr.java
View license
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    ConstantPoolGen cpg = classGen.getConstantPool();
    InstructionList il = methodGen.getInstructionList();
    il.append(new PUSH(cpg, _value));
}

75. RoundCall#translate()

Project: openjdk
Source File: RoundCall.java
View license
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    // Get two copies of the argument on the stack
    argument().translate(classGen, methodGen);
    il.append(new INVOKESTATIC(cpg.addMethodref(BASIS_LIBRARY_CLASS, "roundF", "(D)D")));
}

76. SimpleAttributeValue#translate()

Project: openjdk
Source File: SimpleAttributeValue.java
View license
/**
     * Translate this attribute value into JVM bytecodes that pushes the
     * attribute value onto the JVM's stack.
     * @param classGen BCEL Java class generator
     * @param methodGen BCEL Java method generator
     */
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    il.append(new PUSH(cpg, _value));
}

77. Sort#translateLang()

Project: openjdk
Source File: Sort.java
View license
public void translateLang(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    // bug! see 26869
    il.append(new PUSH(cpg, _lang));
}

78. Sort#translateSortIterator()

Project: openjdk
Source File: Sort.java
View license
/**
     * Compiles code that instantiates a SortingIterator object.
     * This object's constructor needs referencdes to the current iterator
     * and a node sort record producing objects as its parameters.
     */
public static void translateSortIterator(ClassGenerator classGen, MethodGenerator methodGen, Expression nodeSet, Vector<Sort> sortObjects) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    // SortingIterator.SortingIterator(NodeIterator,NodeSortRecordFactory);
    final int init = cpg.addMethodref(SORT_ITERATOR, "<init>", "(" + NODE_ITERATOR_SIG + NODE_SORT_FACTORY_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.
    LocalVariableGen nodesTemp = methodGen.addLocalVariable("sort_tmp1", Util.getJCRefType(NODE_ITERATOR_SIG), null, null);
    LocalVariableGen sortRecordFactoryTemp = methodGen.addLocalVariable("sort_tmp2", Util.getJCRefType(NODE_SORT_FACTORY_SIG), null, null);
    // Get the current node iterator
    if (nodeSet == null) {
        // apply-templates default
        final int children = cpg.addInterfaceMethodref(DOM_INTF, "getAxisIterator", "(I)" + NODE_ITERATOR_SIG);
        il.append(methodGen.loadDOM());
        il.append(new PUSH(cpg, Axis.CHILD));
        il.append(new INVOKEINTERFACE(children, 2));
    } else {
        nodeSet.translate(classGen, methodGen);
    }
    nodesTemp.setStart(il.append(new ASTORE(nodesTemp.getIndex())));
    // Compile the code for the NodeSortRecord producing class and pass
    // that as the last argument to the SortingIterator constructor.
    compileSortRecordFactory(sortObjects, classGen, methodGen);
    sortRecordFactoryTemp.setStart(il.append(new ASTORE(sortRecordFactoryTemp.getIndex())));
    il.append(new NEW(cpg.addClass(SORT_ITERATOR)));
    il.append(DUP);
    nodesTemp.setEnd(il.append(new ALOAD(nodesTemp.getIndex())));
    sortRecordFactoryTemp.setEnd(il.append(new ALOAD(sortRecordFactoryTemp.getIndex())));
    il.append(new INVOKESPECIAL(init));
}

79. Sort#compileSortRecordFactory()

Project: openjdk
Source File: Sort.java
View license
/**
     * Compiles code that instantiates a NodeSortRecordFactory object which
     * will produce NodeSortRecord objects of a specific type.
     */
public static void compileSortRecordFactory(Vector<Sort> sortObjects, ClassGenerator classGen, MethodGenerator methodGen) {
    String sortRecordClass = compileSortRecord(sortObjects, classGen, methodGen);
    boolean needsSortRecordFactory = false;
    final int nsorts = sortObjects.size();
    for (int i = 0; i < nsorts; i++) {
        final Sort sort = sortObjects.elementAt(i);
        needsSortRecordFactory |= sort._needsSortRecordFactory;
    }
    String sortRecordFactoryClass = NODE_SORT_FACTORY;
    if (needsSortRecordFactory) {
        sortRecordFactoryClass = compileSortRecordFactory(sortObjects, classGen, methodGen, sortRecordClass);
    }
    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.
    // Compile code that initializes the static _sortOrder
    LocalVariableGen sortOrderTemp = methodGen.addLocalVariable("sort_order_tmp", Util.getJCRefType("[" + STRING_SIG), null, null);
    il.append(new PUSH(cpg, nsorts));
    il.append(new ANEWARRAY(cpg.addClass(STRING)));
    for (int level = 0; level < nsorts; level++) {
        final Sort sort = (Sort) sortObjects.elementAt(level);
        il.append(DUP);
        il.append(new PUSH(cpg, level));
        sort.translateSortOrder(classGen, methodGen);
        il.append(AASTORE);
    }
    sortOrderTemp.setStart(il.append(new ASTORE(sortOrderTemp.getIndex())));
    LocalVariableGen sortTypeTemp = methodGen.addLocalVariable("sort_type_tmp", Util.getJCRefType("[" + STRING_SIG), null, null);
    il.append(new PUSH(cpg, nsorts));
    il.append(new ANEWARRAY(cpg.addClass(STRING)));
    for (int level = 0; level < nsorts; level++) {
        final Sort sort = (Sort) sortObjects.elementAt(level);
        il.append(DUP);
        il.append(new PUSH(cpg, level));
        sort.translateSortType(classGen, methodGen);
        il.append(AASTORE);
    }
    sortTypeTemp.setStart(il.append(new ASTORE(sortTypeTemp.getIndex())));
    LocalVariableGen sortLangTemp = methodGen.addLocalVariable("sort_lang_tmp", Util.getJCRefType("[" + STRING_SIG), null, null);
    il.append(new PUSH(cpg, nsorts));
    il.append(new ANEWARRAY(cpg.addClass(STRING)));
    for (int level = 0; level < nsorts; level++) {
        final Sort sort = (Sort) sortObjects.elementAt(level);
        il.append(DUP);
        il.append(new PUSH(cpg, level));
        sort.translateLang(classGen, methodGen);
        il.append(AASTORE);
    }
    sortLangTemp.setStart(il.append(new ASTORE(sortLangTemp.getIndex())));
    LocalVariableGen sortCaseOrderTemp = methodGen.addLocalVariable("sort_case_order_tmp", Util.getJCRefType("[" + STRING_SIG), null, null);
    il.append(new PUSH(cpg, nsorts));
    il.append(new ANEWARRAY(cpg.addClass(STRING)));
    for (int level = 0; level < nsorts; level++) {
        final Sort sort = (Sort) sortObjects.elementAt(level);
        il.append(DUP);
        il.append(new PUSH(cpg, level));
        sort.translateCaseOrder(classGen, methodGen);
        il.append(AASTORE);
    }
    sortCaseOrderTemp.setStart(il.append(new ASTORE(sortCaseOrderTemp.getIndex())));
    il.append(new NEW(cpg.addClass(sortRecordFactoryClass)));
    il.append(DUP);
    il.append(methodGen.loadDOM());
    il.append(new PUSH(cpg, sortRecordClass));
    il.append(classGen.loadTranslet());
    sortOrderTemp.setEnd(il.append(new ALOAD(sortOrderTemp.getIndex())));
    sortTypeTemp.setEnd(il.append(new ALOAD(sortTypeTemp.getIndex())));
    sortLangTemp.setEnd(il.append(new ALOAD(sortLangTemp.getIndex())));
    sortCaseOrderTemp.setEnd(il.append(new ALOAD(sortCaseOrderTemp.getIndex())));
    il.append(new INVOKESPECIAL(cpg.addMethodref(sortRecordFactoryClass, "<init>", "(" + DOM_INTF_SIG + STRING_SIG + TRANSLET_INTF_SIG + "[" + STRING_SIG + "[" + STRING_SIG + "[" + STRING_SIG + "[" + STRING_SIG + ")V")));
    // Initialize closure variables in sortRecordFactory
    final ArrayList<VariableRefBase> dups = new ArrayList<>();
    for (int j = 0; j < nsorts; j++) {
        final Sort sort = (Sort) sortObjects.get(j);
        final int length = (sort._closureVars == null) ? 0 : sort._closureVars.size();
        for (int i = 0; i < length; i++) {
            VariableRefBase varRef = sort._closureVars.get(i);
            // Discard duplicate variable references
            if (dups.contains(varRef))
                continue;
            final VariableBase var = varRef.getVariable();
            // Store variable in new closure
            il.append(DUP);
            il.append(var.loadInstruction());
            il.append(new PUTFIELD(cpg.addFieldref(sortRecordFactoryClass, var.getEscapedName(), var.getType().toSignature())));
            dups.add(varRef);
        }
    }
}

80. Sort#compileSortRecordFactory()

Project: openjdk
Source File: Sort.java
View license
public static String compileSortRecordFactory(Vector<Sort> sortObjects, ClassGenerator classGen, MethodGenerator methodGen, String sortRecordClass) {
    final XSLTC xsltc = (sortObjects.firstElement()).getXSLTC();
    final String className = xsltc.getHelperClassName();
    final NodeSortRecordFactGenerator sortRecordFactory = new NodeSortRecordFactGenerator(className, NODE_SORT_FACTORY, className + ".java", ACC_PUBLIC | ACC_SUPER | ACC_FINAL, new String[] {}, classGen.getStylesheet());
    ConstantPoolGen cpg = sortRecordFactory.getConstantPool();
    // Add a new instance variable for each var in closure
    final int nsorts = sortObjects.size();
    final ArrayList<VariableRefBase> dups = new ArrayList<>();
    for (int j = 0; j < nsorts; j++) {
        final Sort sort = sortObjects.get(j);
        final int length = (sort._closureVars == null) ? 0 : sort._closureVars.size();
        for (int i = 0; i < length; i++) {
            final VariableRefBase varRef = sort._closureVars.get(i);
            // Discard duplicate variable references
            if (dups.contains(varRef))
                continue;
            final VariableBase var = varRef.getVariable();
            sortRecordFactory.addField(new Field(ACC_PUBLIC, cpg.addUtf8(var.getEscapedName()), cpg.addUtf8(var.getType().toSignature()), null, cpg.getConstantPool()));
            dups.add(varRef);
        }
    }
    // Define a constructor for this class
    final com.sun.org.apache.bcel.internal.generic.Type[] argTypes = new com.sun.org.apache.bcel.internal.generic.Type[7];
    argTypes[0] = Util.getJCRefType(DOM_INTF_SIG);
    argTypes[1] = Util.getJCRefType(STRING_SIG);
    argTypes[2] = Util.getJCRefType(TRANSLET_INTF_SIG);
    argTypes[3] = Util.getJCRefType("[" + STRING_SIG);
    argTypes[4] = Util.getJCRefType("[" + STRING_SIG);
    argTypes[5] = Util.getJCRefType("[" + STRING_SIG);
    argTypes[6] = Util.getJCRefType("[" + STRING_SIG);
    final String[] argNames = new String[7];
    argNames[0] = DOCUMENT_PNAME;
    argNames[1] = "className";
    argNames[2] = TRANSLET_PNAME;
    argNames[3] = "order";
    argNames[4] = "type";
    argNames[5] = "lang";
    argNames[6] = "case_order";
    InstructionList il = new InstructionList();
    final MethodGenerator constructor = new MethodGenerator(ACC_PUBLIC, com.sun.org.apache.bcel.internal.generic.Type.VOID, argTypes, argNames, "<init>", className, il, cpg);
    // Push all parameters onto the stack and called super.<init>()
    il.append(ALOAD_0);
    il.append(ALOAD_1);
    il.append(ALOAD_2);
    il.append(new ALOAD(3));
    il.append(new ALOAD(4));
    il.append(new ALOAD(5));
    il.append(new ALOAD(6));
    il.append(new ALOAD(7));
    il.append(new INVOKESPECIAL(cpg.addMethodref(NODE_SORT_FACTORY, "<init>", "(" + DOM_INTF_SIG + STRING_SIG + TRANSLET_INTF_SIG + "[" + STRING_SIG + "[" + STRING_SIG + "[" + STRING_SIG + "[" + STRING_SIG + ")V")));
    il.append(RETURN);
    // Override the definition of makeNodeSortRecord()
    il = new InstructionList();
    final MethodGenerator makeNodeSortRecord = new MethodGenerator(ACC_PUBLIC, Util.getJCRefType(NODE_SORT_RECORD_SIG), new com.sun.org.apache.bcel.internal.generic.Type[] { com.sun.org.apache.bcel.internal.generic.Type.INT, com.sun.org.apache.bcel.internal.generic.Type.INT }, new String[] { "node", "last" }, "makeNodeSortRecord", className, il, cpg);
    il.append(ALOAD_0);
    il.append(ILOAD_1);
    il.append(ILOAD_2);
    il.append(new INVOKESPECIAL(cpg.addMethodref(NODE_SORT_FACTORY, "makeNodeSortRecord", "(II)" + NODE_SORT_RECORD_SIG)));
    il.append(DUP);
    il.append(new CHECKCAST(cpg.addClass(sortRecordClass)));
    // Initialize closure in record class
    final int ndups = dups.size();
    for (int i = 0; i < ndups; i++) {
        final VariableRefBase varRef = (VariableRefBase) dups.get(i);
        final VariableBase var = varRef.getVariable();
        final Type varType = var.getType();
        il.append(DUP);
        // Get field from factory class
        il.append(ALOAD_0);
        il.append(new GETFIELD(cpg.addFieldref(className, var.getEscapedName(), varType.toSignature())));
        // Put field in record class
        il.append(new PUTFIELD(cpg.addFieldref(sortRecordClass, var.getEscapedName(), varType.toSignature())));
    }
    il.append(POP);
    il.append(ARETURN);
    constructor.setMaxLocals();
    constructor.setMaxStack();
    sortRecordFactory.addMethod(constructor);
    makeNodeSortRecord.setMaxLocals();
    makeNodeSortRecord.setMaxStack();
    sortRecordFactory.addMethod(makeNodeSortRecord);
    xsltc.dumpClass(sortRecordFactory.getJavaClass());
    return className;
}

81. Sort#compileSortRecord()

Project: openjdk
Source File: Sort.java
View license
/**
     * Create a new auxillary class extending NodeSortRecord.
     */
private static String compileSortRecord(Vector<Sort> sortObjects, ClassGenerator classGen, MethodGenerator methodGen) {
    final XSLTC xsltc = sortObjects.firstElement().getXSLTC();
    final String className = xsltc.getHelperClassName();
    // This generates a new class for handling this specific sort
    final NodeSortRecordGenerator sortRecord = new NodeSortRecordGenerator(className, NODE_SORT_RECORD, "sort$0.java", ACC_PUBLIC | ACC_SUPER | ACC_FINAL, new String[] {}, classGen.getStylesheet());
    final ConstantPoolGen cpg = sortRecord.getConstantPool();
    // Add a new instance variable for each var in closure
    final int nsorts = sortObjects.size();
    final ArrayList<VariableRefBase> dups = new ArrayList<>();
    for (int j = 0; j < nsorts; j++) {
        final Sort sort = sortObjects.get(j);
        // Set the name of the inner class in this sort object
        sort.setInnerClassName(className);
        final int length = (sort._closureVars == null) ? 0 : sort._closureVars.size();
        for (int i = 0; i < length; i++) {
            final VariableRefBase varRef = (VariableRefBase) sort._closureVars.get(i);
            // Discard duplicate variable references
            if (dups.contains(varRef))
                continue;
            final VariableBase var = varRef.getVariable();
            sortRecord.addField(new Field(ACC_PUBLIC, cpg.addUtf8(var.getEscapedName()), cpg.addUtf8(var.getType().toSignature()), null, cpg.getConstantPool()));
            dups.add(varRef);
        }
    }
    MethodGenerator init = compileInit(sortRecord, cpg, className);
    MethodGenerator extract = compileExtract(sortObjects, sortRecord, cpg, className);
    sortRecord.addMethod(init);
    sortRecord.addMethod(extract);
    xsltc.dumpClass(sortRecord.getJavaClass());
    return className;
}

82. StartsWithCall#translate()

Project: openjdk
Source File: StartsWithCall.java
View license
/**
     * Compile the expression - leave boolean expression on stack
     */
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    _base.translate(classGen, methodGen);
    _token.translate(classGen, methodGen);
    il.append(new INVOKEVIRTUAL(cpg.addMethodref(STRING_CLASS, "startsWith", "(" + STRING_SIG + ")Z")));
}

83. Step#translateStep()

Project: openjdk
Source File: Step.java
View license
private void translateStep(ClassGenerator classGen, MethodGenerator methodGen, int predicateIndex) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    if (predicateIndex >= 0) {
        translatePredicates(classGen, methodGen, predicateIndex);
    } else {
        int star = 0;
        String name = null;
        final XSLTC xsltc = getParser().getXSLTC();
        if (_nodeType >= DTM.NTYPES) {
            final Vector ni = xsltc.getNamesIndex();
            name = (String) ni.elementAt(_nodeType - DTM.NTYPES);
            star = name.lastIndexOf('*');
        }
        // and has no parent
        if (_axis == Axis.ATTRIBUTE && _nodeType != NodeTest.ATTRIBUTE && _nodeType != NodeTest.ANODE && !hasParentPattern() && star == 0) {
            int iter = cpg.addInterfaceMethodref(DOM_INTF, "getTypedAxisIterator", "(II)" + NODE_ITERATOR_SIG);
            il.append(methodGen.loadDOM());
            il.append(new PUSH(cpg, Axis.ATTRIBUTE));
            il.append(new PUSH(cpg, _nodeType));
            il.append(new INVOKEINTERFACE(iter, 3));
            return;
        }
        SyntaxTreeNode parent = getParent();
        // Special case for '.'
        if (isAbbreviatedDot()) {
            if (_type == Type.Node) {
                // Put context node on stack if using Type.Node
                il.append(methodGen.loadContextNode());
            } else {
                if (parent instanceof ParentLocationPath) {
                    // Wrap the context node in a singleton iterator if not.
                    int init = cpg.addMethodref(SINGLETON_ITERATOR, "<init>", "(" + NODE_SIG + ")V");
                    il.append(new NEW(cpg.addClass(SINGLETON_ITERATOR)));
                    il.append(DUP);
                    il.append(methodGen.loadContextNode());
                    il.append(new INVOKESPECIAL(init));
                } else {
                    // DOM.getAxisIterator(int axis);
                    int git = cpg.addInterfaceMethodref(DOM_INTF, "getAxisIterator", "(I)" + NODE_ITERATOR_SIG);
                    il.append(methodGen.loadDOM());
                    il.append(new PUSH(cpg, _axis));
                    il.append(new INVOKEINTERFACE(git, 2));
                }
            }
            return;
        }
        // Special case for /foo/*/bar
        if ((parent instanceof ParentLocationPath) && (parent.getParent() instanceof ParentLocationPath)) {
            if ((_nodeType == NodeTest.ELEMENT) && (!_hadPredicates)) {
                _nodeType = NodeTest.ANODE;
            }
        }
        // "ELEMENT" or "*" or "@*" or ".." or "@attr" with a parent.
        switch(_nodeType) {
            case NodeTest.ATTRIBUTE:
                _axis = Axis.ATTRIBUTE;
            case NodeTest.ANODE:
                // DOM.getAxisIterator(int axis);
                int git = cpg.addInterfaceMethodref(DOM_INTF, "getAxisIterator", "(I)" + NODE_ITERATOR_SIG);
                il.append(methodGen.loadDOM());
                il.append(new PUSH(cpg, _axis));
                il.append(new INVOKEINTERFACE(git, 2));
                break;
            default:
                if (star > 1) {
                    final String namespace;
                    if (_axis == Axis.ATTRIBUTE)
                        namespace = name.substring(0, star - 2);
                    else
                        namespace = name.substring(0, star - 1);
                    final int nsType = xsltc.registerNamespace(namespace);
                    final int ns = cpg.addInterfaceMethodref(DOM_INTF, "getNamespaceAxisIterator", "(II)" + NODE_ITERATOR_SIG);
                    il.append(methodGen.loadDOM());
                    il.append(new PUSH(cpg, _axis));
                    il.append(new PUSH(cpg, nsType));
                    il.append(new INVOKEINTERFACE(ns, 3));
                    break;
                }
            case NodeTest.ELEMENT:
                // DOM.getTypedAxisIterator(int axis, int type);
                final int ty = cpg.addInterfaceMethodref(DOM_INTF, "getTypedAxisIterator", "(II)" + NODE_ITERATOR_SIG);
                // Get the typed iterator we're after
                il.append(methodGen.loadDOM());
                il.append(new PUSH(cpg, _axis));
                il.append(new PUSH(cpg, _nodeType));
                il.append(new INVOKEINTERFACE(ty, 3));
                break;
        }
    }
}

84. StepPattern#translateKernel()

Project: openjdk
Source File: StepPattern.java
View license
private void translateKernel(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    if (_nodeType == DTM.ELEMENT_NODE) {
        final int check = cpg.addInterfaceMethodref(DOM_INTF, "isElement", "(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 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));
    }
}

85. StepPattern#translateNoContext()

Project: openjdk
Source File: StepPattern.java
View license
private void translateNoContext(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    // 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 (!_isEpsilon) {
        il.append(methodGen.loadCurrentNode());
        translateKernel(classGen, methodGen);
    }
    // Compile the expressions within the predicates
    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));
}

86. StepPattern#translateSimpleContext()

Project: openjdk
Source File: StepPattern.java
View license
private void translateSimpleContext(ClassGenerator classGen, MethodGenerator methodGen) {
    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), null, null);
    match.setStart(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), null, null);
    stepIteratorTemp.setStart(il.append(new ASTORE(stepIteratorTemp.getIndex())));
    il.append(new NEW(cpg.addClass(MATCHING_ITERATOR)));
    il.append(DUP);
    il.append(new ILOAD(match.getIndex()));
    stepIteratorTemp.setEnd(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()));
    index = cpg.addInterfaceMethodref(DOM_INTF, GET_PARENT, GET_PARENT_SIG);
    il.append(new INVOKEINTERFACE(index, 2));
    // Start the iterator with the parent
    il.append(methodGen.setStartNode());
    // Overwrite current iterator and current node
    il.append(methodGen.storeIterator());
    match.setEnd(il.append(new ILOAD(match.getIndex())));
    il.append(methodGen.storeCurrentNode());
    // Translate the expression of the predicate
    Predicate pred = (Predicate) _predicates.elementAt(0);
    Expression exp = pred.getExpr();
    exp.translateDesynthesized(classGen, methodGen);
    // 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));
}

87. StepPattern#translateGeneralContext()

Project: openjdk
Source File: StepPattern.java
View license
private void translateGeneralContext(ClassGenerator classGen, 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), null, null);
    node.setStart(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), null, 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);
        iter.setStart(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);
    InstructionHandle iterStore = 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));
    } else {
        // If class is not external, start of range for iter variable was
        // set above
        iter.setStart(iterStore);
    }
    // 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), null, null);
    skipNext = il.append(new GOTO(null));
    next = il.append(new ALOAD(iter.getIndex()));
    node2.setStart(next);
    begin = il.append(methodGen.nextNode());
    il.append(DUP);
    il.append(new ISTORE(node2.getIndex()));
    // NodeIterator.END
    _falseList.add(il.append(new IFLT(null)));
    il.append(new ILOAD(node2.getIndex()));
    il.append(new ILOAD(node.getIndex()));
    iter.setEnd(il.append(new IF_ICMPLT(next)));
    node2.setEnd(il.append(new ILOAD(node2.getIndex())));
    node.setEnd(il.append(new ILOAD(node.getIndex())));
    _falseList.add(il.append(new IF_ICMPNE(null)));
    skipNext.setTarget(begin);
}

88. StepPattern#translate()

Project: openjdk
Source File: StepPattern.java
View license
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()) {
        // true list falls through
        il.append(POP);
    } else {
        translateKernel(classGen, methodGen);
    }
}

89. Stylesheet#compileStaticInitializer()

Project: openjdk
Source File: Stylesheet.java
View license
/**
     * Compile the namesArray, urisArray and typesArray into
     * the static initializer. They are read-only from the
     * translet. All translet instances can share a single
     * copy of this informtion.
     */
private void compileStaticInitializer(ClassGenerator classGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = new InstructionList();
    final MethodGenerator staticConst = new MethodGenerator(ACC_PUBLIC | ACC_STATIC, com.sun.org.apache.bcel.internal.generic.Type.VOID, null, null, "<clinit>", _className, il, cpg);
    addStaticField(classGen, "[" + STRING_SIG, STATIC_NAMES_ARRAY_FIELD);
    addStaticField(classGen, "[" + STRING_SIG, STATIC_URIS_ARRAY_FIELD);
    addStaticField(classGen, "[I", STATIC_TYPES_ARRAY_FIELD);
    addStaticField(classGen, "[" + STRING_SIG, STATIC_NAMESPACE_ARRAY_FIELD);
    // Create fields of type char[] that will contain literal text from
    // the stylesheet.
    final int charDataFieldCount = getXSLTC().getCharacterDataCount();
    for (int i = 0; i < charDataFieldCount; i++) {
        addStaticField(classGen, STATIC_CHAR_DATA_FIELD_SIG, STATIC_CHAR_DATA_FIELD + i);
    }
    // Put the names array into the translet - used for dom/translet mapping
    final Vector namesIndex = getXSLTC().getNamesIndex();
    int size = namesIndex.size();
    String[] namesArray = new String[size];
    String[] urisArray = new String[size];
    int[] typesArray = new int[size];
    int index;
    for (int i = 0; i < size; i++) {
        String encodedName = (String) namesIndex.elementAt(i);
        if ((index = encodedName.lastIndexOf(':')) > -1) {
            urisArray[i] = encodedName.substring(0, index);
        }
        index = index + 1;
        if (encodedName.charAt(index) == '@') {
            typesArray[i] = DTM.ATTRIBUTE_NODE;
            index++;
        } else if (encodedName.charAt(index) == '?') {
            typesArray[i] = DTM.NAMESPACE_NODE;
            index++;
        } else {
            typesArray[i] = DTM.ELEMENT_NODE;
        }
        if (index == 0) {
            namesArray[i] = encodedName;
        } else {
            namesArray[i] = encodedName.substring(index);
        }
    }
    staticConst.markChunkStart();
    il.append(new PUSH(cpg, size));
    il.append(new ANEWARRAY(cpg.addClass(STRING)));
    int namesArrayRef = cpg.addFieldref(_className, STATIC_NAMES_ARRAY_FIELD, NAMES_INDEX_SIG);
    il.append(new PUTSTATIC(namesArrayRef));
    staticConst.markChunkEnd();
    for (int i = 0; i < size; i++) {
        final String name = namesArray[i];
        staticConst.markChunkStart();
        il.append(new GETSTATIC(namesArrayRef));
        il.append(new PUSH(cpg, i));
        il.append(new PUSH(cpg, name));
        il.append(AASTORE);
        staticConst.markChunkEnd();
    }
    staticConst.markChunkStart();
    il.append(new PUSH(cpg, size));
    il.append(new ANEWARRAY(cpg.addClass(STRING)));
    int urisArrayRef = cpg.addFieldref(_className, STATIC_URIS_ARRAY_FIELD, URIS_INDEX_SIG);
    il.append(new PUTSTATIC(urisArrayRef));
    staticConst.markChunkEnd();
    for (int i = 0; i < size; i++) {
        final String uri = urisArray[i];
        staticConst.markChunkStart();
        il.append(new GETSTATIC(urisArrayRef));
        il.append(new PUSH(cpg, i));
        il.append(new PUSH(cpg, uri));
        il.append(AASTORE);
        staticConst.markChunkEnd();
    }
    staticConst.markChunkStart();
    il.append(new PUSH(cpg, size));
    il.append(new NEWARRAY(BasicType.INT));
    int typesArrayRef = cpg.addFieldref(_className, STATIC_TYPES_ARRAY_FIELD, TYPES_INDEX_SIG);
    il.append(new PUTSTATIC(typesArrayRef));
    staticConst.markChunkEnd();
    for (int i = 0; i < size; i++) {
        final int nodeType = typesArray[i];
        staticConst.markChunkStart();
        il.append(new GETSTATIC(typesArrayRef));
        il.append(new PUSH(cpg, i));
        il.append(new PUSH(cpg, nodeType));
        il.append(IASTORE);
    }
    // Put the namespace names array into the translet
    final Vector namespaces = getXSLTC().getNamespaceIndex();
    staticConst.markChunkStart();
    il.append(new PUSH(cpg, namespaces.size()));
    il.append(new ANEWARRAY(cpg.addClass(STRING)));
    int namespaceArrayRef = cpg.addFieldref(_className, STATIC_NAMESPACE_ARRAY_FIELD, NAMESPACE_INDEX_SIG);
    il.append(new PUTSTATIC(namespaceArrayRef));
    staticConst.markChunkEnd();
    for (int i = 0; i < namespaces.size(); i++) {
        final String ns = (String) namespaces.elementAt(i);
        staticConst.markChunkStart();
        il.append(new GETSTATIC(namespaceArrayRef));
        il.append(new PUSH(cpg, i));
        il.append(new PUSH(cpg, ns));
        il.append(AASTORE);
        staticConst.markChunkEnd();
    }
    // Grab all the literal text in the stylesheet and put it in a char[]
    final int charDataCount = getXSLTC().getCharacterDataCount();
    final int toCharArray = cpg.addMethodref(STRING, "toCharArray", "()[C");
    for (int i = 0; i < charDataCount; i++) {
        staticConst.markChunkStart();
        il.append(new PUSH(cpg, getXSLTC().getCharacterData(i)));
        il.append(new INVOKEVIRTUAL(toCharArray));
        il.append(new PUTSTATIC(cpg.addFieldref(_className, STATIC_CHAR_DATA_FIELD + i, STATIC_CHAR_DATA_FIELD_SIG)));
        staticConst.markChunkEnd();
    }
    il.append(RETURN);
    classGen.addMethod(staticConst);
}

90. Stylesheet#compileConstructor()

Project: openjdk
Source File: Stylesheet.java
View license
/**
     * Compile the translet's constructor
     */
private void compileConstructor(ClassGenerator classGen, Output output) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = new InstructionList();
    final MethodGenerator constructor = new MethodGenerator(ACC_PUBLIC, com.sun.org.apache.bcel.internal.generic.Type.VOID, null, null, "<init>", _className, il, cpg);
    // Call the constructor in the AbstractTranslet superclass
    il.append(classGen.loadTranslet());
    il.append(new INVOKESPECIAL(cpg.addMethodref(TRANSLET_CLASS, "<init>", "()V")));
    constructor.markChunkStart();
    il.append(classGen.loadTranslet());
    il.append(new GETSTATIC(cpg.addFieldref(_className, STATIC_NAMES_ARRAY_FIELD, NAMES_INDEX_SIG)));
    il.append(new PUTFIELD(cpg.addFieldref(TRANSLET_CLASS, NAMES_INDEX, NAMES_INDEX_SIG)));
    il.append(classGen.loadTranslet());
    il.append(new GETSTATIC(cpg.addFieldref(_className, STATIC_URIS_ARRAY_FIELD, URIS_INDEX_SIG)));
    il.append(new PUTFIELD(cpg.addFieldref(TRANSLET_CLASS, URIS_INDEX, URIS_INDEX_SIG)));
    constructor.markChunkEnd();
    constructor.markChunkStart();
    il.append(classGen.loadTranslet());
    il.append(new GETSTATIC(cpg.addFieldref(_className, STATIC_TYPES_ARRAY_FIELD, TYPES_INDEX_SIG)));
    il.append(new PUTFIELD(cpg.addFieldref(TRANSLET_CLASS, TYPES_INDEX, TYPES_INDEX_SIG)));
    constructor.markChunkEnd();
    constructor.markChunkStart();
    il.append(classGen.loadTranslet());
    il.append(new GETSTATIC(cpg.addFieldref(_className, STATIC_NAMESPACE_ARRAY_FIELD, NAMESPACE_INDEX_SIG)));
    il.append(new PUTFIELD(cpg.addFieldref(TRANSLET_CLASS, NAMESPACE_INDEX, NAMESPACE_INDEX_SIG)));
    constructor.markChunkEnd();
    constructor.markChunkStart();
    il.append(classGen.loadTranslet());
    il.append(new PUSH(cpg, AbstractTranslet.CURRENT_TRANSLET_VERSION));
    il.append(new PUTFIELD(cpg.addFieldref(TRANSLET_CLASS, TRANSLET_VERSION_INDEX, TRANSLET_VERSION_INDEX_SIG)));
    constructor.markChunkEnd();
    if (_hasIdCall) {
        constructor.markChunkStart();
        il.append(classGen.loadTranslet());
        il.append(new PUSH(cpg, Boolean.TRUE));
        il.append(new PUTFIELD(cpg.addFieldref(TRANSLET_CLASS, HASIDCALL_INDEX, HASIDCALL_INDEX_SIG)));
        constructor.markChunkEnd();
    }
    // Compile in code to set the output configuration from <xsl:output>
    if (output != null) {
        // Set all the output settings files in the translet
        constructor.markChunkStart();
        output.translate(classGen, constructor);
        constructor.markChunkEnd();
    }
    // This is an implicit, nameless xsl:decimal-format top-level element.
    if (_numberFormattingUsed) {
        constructor.markChunkStart();
        DecimalFormatting.translateDefaultDFS(classGen, constructor);
        constructor.markChunkEnd();
    }
    il.append(RETURN);
    classGen.addMethod(constructor);
}

91. Stylesheet#compileTopLevel()

Project: openjdk
Source File: Stylesheet.java
View license
/**
     * Compile a topLevel() method into the output class. This method is
     * called from transform() to handle all non-template top-level elements.
     * Returns the signature of the topLevel() method.
     *
     * Global variables/params and keys are first sorted to resolve
     * dependencies between them. The XSLT 1.0 spec does not allow a key
     * to depend on a variable. However, for compatibility with Xalan
     * interpretive, that type of dependency is allowed. Note also that
     * the buildKeys() method is still generated as it is used by the
     * LoadDocument class, but it no longer called from transform().
     */
private String compileTopLevel(ClassGenerator classGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final com.sun.org.apache.bcel.internal.generic.Type[] argTypes = { Util.getJCRefType(DOM_INTF_SIG), Util.getJCRefType(NODE_ITERATOR_SIG), Util.getJCRefType(TRANSLET_OUTPUT_SIG) };
    final String[] argNames = { DOCUMENT_PNAME, ITERATOR_PNAME, TRANSLET_OUTPUT_PNAME };
    final InstructionList il = new InstructionList();
    final MethodGenerator toplevel = new MethodGenerator(ACC_PUBLIC, com.sun.org.apache.bcel.internal.generic.Type.VOID, argTypes, argNames, "topLevel", _className, il, classGen.getConstantPool());
    toplevel.addException("com.sun.org.apache.xalan.internal.xsltc.TransletException");
    // Define and initialize 'current' variable with the root node
    final LocalVariableGen current = toplevel.addLocalVariable("current", com.sun.org.apache.bcel.internal.generic.Type.INT, null, null);
    final int setFilter = cpg.addInterfaceMethodref(DOM_INTF, "setFilter", "(Lcom/sun/org/apache/xalan/internal/xsltc/StripFilter;)V");
    final int gitr = cpg.addInterfaceMethodref(DOM_INTF, "getIterator", "()" + NODE_ITERATOR_SIG);
    il.append(toplevel.loadDOM());
    il.append(new INVOKEINTERFACE(gitr, 1));
    il.append(toplevel.nextNode());
    current.setStart(il.append(new ISTORE(current.getIndex())));
    // Create a new list containing variables/params + keys
    Vector varDepElements = new Vector(_globals);
    Iterator<SyntaxTreeNode> elements = elements();
    while (elements.hasNext()) {
        SyntaxTreeNode element = elements.next();
        if (element instanceof Key) {
            varDepElements.add(element);
        }
    }
    // Determine a partial order for the variables/params and keys
    varDepElements = resolveDependencies(varDepElements);
    // Translate vars/params and keys in the right order
    final int count = varDepElements.size();
    for (int i = 0; i < count; i++) {
        final TopLevelElement tle = (TopLevelElement) varDepElements.elementAt(i);
        tle.translate(classGen, toplevel);
        if (tle instanceof Key) {
            final Key key = (Key) tle;
            _keys.put(key.getName(), key);
        }
    }
    // Compile code for other top-level elements
    Vector whitespaceRules = new Vector();
    elements = elements();
    while (elements.hasNext()) {
        SyntaxTreeNode element = elements.next();
        // xsl:decimal-format
        if (element instanceof DecimalFormatting) {
            ((DecimalFormatting) element).translate(classGen, toplevel);
        } else // xsl:strip/preserve-space
        if (element instanceof Whitespace) {
            whitespaceRules.addAll(((Whitespace) element).getRules());
        }
    }
    // Translate all whitespace strip/preserve rules
    if (whitespaceRules.size() > 0) {
        Whitespace.translateRules(whitespaceRules, classGen);
    }
    if (classGen.containsMethod(STRIP_SPACE, STRIP_SPACE_PARAMS) != null) {
        il.append(toplevel.loadDOM());
        il.append(classGen.loadTranslet());
        il.append(new INVOKEINTERFACE(setFilter, 2));
    }
    il.append(RETURN);
    // Compute max locals + stack and add method to class
    classGen.addMethod(toplevel);
    return ("(" + DOM_INTF_SIG + NODE_ITERATOR_SIG + TRANSLET_OUTPUT_SIG + ")V");
}

92. Stylesheet#compileBuildKeys()

Project: openjdk
Source File: Stylesheet.java
View license
/**
     * Compile a buildKeys() method into the output class. Note that keys
     * for the input document are created in topLevel(), not in this method.
     * However, we still need this method to create keys for documents loaded
     * via the XPath document() function.
     */
private String compileBuildKeys(ClassGenerator classGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final com.sun.org.apache.bcel.internal.generic.Type[] argTypes = { Util.getJCRefType(DOM_INTF_SIG), Util.getJCRefType(NODE_ITERATOR_SIG), Util.getJCRefType(TRANSLET_OUTPUT_SIG), com.sun.org.apache.bcel.internal.generic.Type.INT };
    final String[] argNames = { DOCUMENT_PNAME, ITERATOR_PNAME, TRANSLET_OUTPUT_PNAME, "current" };
    final InstructionList il = new InstructionList();
    final MethodGenerator buildKeys = new MethodGenerator(ACC_PUBLIC, com.sun.org.apache.bcel.internal.generic.Type.VOID, argTypes, argNames, "buildKeys", _className, il, classGen.getConstantPool());
    buildKeys.addException("com.sun.org.apache.xalan.internal.xsltc.TransletException");
    final Iterator<SyntaxTreeNode> elements = elements();
    while (elements.hasNext()) {
        // xsl:key
        final SyntaxTreeNode element = elements.next();
        if (element instanceof Key) {
            final Key key = (Key) element;
            key.translate(classGen, buildKeys);
            _keys.put(key.getName(), key);
        }
    }
    il.append(RETURN);
    // Compute max locals + stack and add method to class
    buildKeys.stripAttributes(true);
    buildKeys.setMaxLocals();
    buildKeys.setMaxStack();
    buildKeys.removeNOPs();
    classGen.addMethod(buildKeys.getMethod());
    return ("(" + DOM_INTF_SIG + NODE_ITERATOR_SIG + TRANSLET_OUTPUT_SIG + "I)V");
}

93. Stylesheet#compileTransform()

Project: openjdk
Source File: Stylesheet.java
View license
/**
     * Compile transform() into the output class. This method is used to
     * initialize global variables and global parameters. The current node
     * is set to be the document's root node.
     */
private void compileTransform(ClassGenerator classGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    /*
         * Define the the method transform with the following signature:
         * void transform(DOM, NodeIterator, HandlerBase)
         */
    final com.sun.org.apache.bcel.internal.generic.Type[] argTypes = new com.sun.org.apache.bcel.internal.generic.Type[3];
    argTypes[0] = Util.getJCRefType(DOM_INTF_SIG);
    argTypes[1] = Util.getJCRefType(NODE_ITERATOR_SIG);
    argTypes[2] = Util.getJCRefType(TRANSLET_OUTPUT_SIG);
    final String[] argNames = new String[3];
    argNames[0] = DOCUMENT_PNAME;
    argNames[1] = ITERATOR_PNAME;
    argNames[2] = TRANSLET_OUTPUT_PNAME;
    final InstructionList il = new InstructionList();
    final MethodGenerator transf = new MethodGenerator(ACC_PUBLIC, com.sun.org.apache.bcel.internal.generic.Type.VOID, argTypes, argNames, "transform", _className, il, classGen.getConstantPool());
    transf.addException("com.sun.org.apache.xalan.internal.xsltc.TransletException");
    // Define and initialize current with the root node
    final LocalVariableGen current = transf.addLocalVariable("current", com.sun.org.apache.bcel.internal.generic.Type.INT, null, null);
    final String applyTemplatesSig = classGen.getApplyTemplatesSig();
    final int applyTemplates = cpg.addMethodref(getClassName(), "applyTemplates", applyTemplatesSig);
    final int domField = cpg.addFieldref(getClassName(), DOM_FIELD, DOM_INTF_SIG);
    // push translet for PUTFIELD
    il.append(classGen.loadTranslet());
    if (isMultiDocument()) {
        il.append(new NEW(cpg.addClass(MULTI_DOM_CLASS)));
        il.append(DUP);
    }
    il.append(classGen.loadTranslet());
    il.append(transf.loadDOM());
    il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS, "makeDOMAdapter", "(" + DOM_INTF_SIG + ")" + DOM_ADAPTER_SIG)));
    if (isMultiDocument()) {
        final int init = cpg.addMethodref(MULTI_DOM_CLASS, "<init>", "(" + DOM_INTF_SIG + ")V");
        il.append(new INVOKESPECIAL(init));
    // MultiDOM is on the stack
    }
    //store to _dom variable
    il.append(new PUTFIELD(domField));
    // continue with globals initialization
    final int gitr = cpg.addInterfaceMethodref(DOM_INTF, "getIterator", "()" + NODE_ITERATOR_SIG);
    il.append(transf.loadDOM());
    il.append(new INVOKEINTERFACE(gitr, 1));
    il.append(transf.nextNode());
    current.setStart(il.append(new ISTORE(current.getIndex())));
    // Transfer the output settings to the output post-processor
    il.append(classGen.loadTranslet());
    il.append(transf.loadHandler());
    final int index = cpg.addMethodref(TRANSLET_CLASS, "transferOutputSettings", "(" + OUTPUT_HANDLER_SIG + ")V");
    il.append(new INVOKEVIRTUAL(index));
    /*
         * Compile buildKeys() method. Note that this method is not
         * invoked here as keys for the input document are now created
         * in topLevel(). However, this method is still needed by the
         * LoadDocument class.
         */
    final String keySig = compileBuildKeys(classGen);
    final int keyIdx = cpg.addMethodref(getClassName(), "buildKeys", keySig);
    // Look for top-level elements that need handling
    final Iterator<SyntaxTreeNode> toplevel = elements();
    if (_globals.size() > 0 || toplevel.hasNext()) {
        // Compile method for handling top-level elements
        final String topLevelSig = compileTopLevel(classGen);
        // Get a reference to that method
        final int topLevelIdx = cpg.addMethodref(getClassName(), "topLevel", topLevelSig);
        // Push all parameters on the stack and call topLevel()
        // The 'this' pointer
        il.append(classGen.loadTranslet());
        il.append(classGen.loadTranslet());
        // The DOM reference
        il.append(new GETFIELD(domField));
        il.append(transf.loadIterator());
        // The output handler
        il.append(transf.loadHandler());
        il.append(new INVOKEVIRTUAL(topLevelIdx));
    }
    // start document
    il.append(transf.loadHandler());
    il.append(transf.startDocument());
    // push first arg for applyTemplates
    il.append(classGen.loadTranslet());
    // push translet for GETFIELD to get DOM arg
    il.append(classGen.loadTranslet());
    il.append(new GETFIELD(domField));
    // push remaining 2 args
    il.append(transf.loadIterator());
    il.append(transf.loadHandler());
    il.append(new INVOKEVIRTUAL(applyTemplates));
    // endDocument
    il.append(transf.loadHandler());
    il.append(transf.endDocument());
    il.append(RETURN);
    // Compute max locals + stack and add method to class
    classGen.addMethod(transf);
}

94. SyntaxTreeNode#compileResultTree()

Project: openjdk
Source File: SyntaxTreeNode.java
View license
/**
     * Utility method used by parameters and variables to store result trees
     * @param classGen BCEL Java class generator
     * @param methodGen BCEL Java method generator
     */
protected void compileResultTree(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    final Stylesheet stylesheet = classGen.getStylesheet();
    boolean isSimple = isSimpleRTF(this);
    boolean isAdaptive = false;
    if (!isSimple) {
        isAdaptive = isAdaptiveRTF(this);
    }
    int rtfType = isSimple ? DOM.SIMPLE_RTF : (isAdaptive ? DOM.ADAPTIVE_RTF : DOM.TREE_RTF);
    // Save the current handler base on the stack
    il.append(methodGen.loadHandler());
    final String DOM_CLASS = classGen.getDOMClass();
    // Create new instance of DOM class (with RTF_INITIAL_SIZE nodes)
    //int index = cpg.addMethodref(DOM_IMPL, "<init>", "(I)V");
    //il.append(new NEW(cpg.addClass(DOM_IMPL)));
    il.append(methodGen.loadDOM());
    int index = cpg.addInterfaceMethodref(DOM_INTF, "getResultTreeFrag", "(IIZ)" + DOM_INTF_SIG);
    il.append(new PUSH(cpg, RTF_INITIAL_SIZE));
    il.append(new PUSH(cpg, rtfType));
    il.append(new PUSH(cpg, stylesheet.callsNodeset()));
    il.append(new INVOKEINTERFACE(index, 4));
    il.append(DUP);
    // Overwrite old handler with DOM handler
    index = cpg.addInterfaceMethodref(DOM_INTF, "getOutputDomBuilder", "()" + TRANSLET_OUTPUT_SIG);
    il.append(new INVOKEINTERFACE(index, 1));
    il.append(DUP);
    il.append(methodGen.storeHandler());
    // Call startDocument on the new handler
    il.append(methodGen.startDocument());
    // Instantiate result tree fragment
    translateContents(classGen, methodGen);
    // Call endDocument on the new handler
    il.append(methodGen.loadHandler());
    il.append(methodGen.endDocument());
    // function is not used.
    if (stylesheet.callsNodeset() && !DOM_CLASS.equals(DOM_IMPL_CLASS)) {
        // new com.sun.org.apache.xalan.internal.xsltc.dom.DOMAdapter(DOMImpl,String[]);
        index = cpg.addMethodref(DOM_ADAPTER_CLASS, "<init>", "(" + DOM_INTF_SIG + "[" + STRING_SIG + "[" + STRING_SIG + "[I" + "[" + STRING_SIG + ")V");
        il.append(new NEW(cpg.addClass(DOM_ADAPTER_CLASS)));
        il.append(new DUP_X1());
        il.append(SWAP);
        /*
             * Give the DOM adapter an empty type mapping if the nodeset
             * extension function is never called.
             */
        if (!stylesheet.callsNodeset()) {
            il.append(new ICONST(0));
            il.append(new ANEWARRAY(cpg.addClass(STRING)));
            il.append(DUP);
            il.append(DUP);
            il.append(new ICONST(0));
            il.append(new NEWARRAY(BasicType.INT));
            il.append(SWAP);
            il.append(new INVOKESPECIAL(index));
        } else {
            // Push name arrays on the stack
            il.append(ALOAD_0);
            il.append(new GETFIELD(cpg.addFieldref(TRANSLET_CLASS, NAMES_INDEX, NAMES_INDEX_SIG)));
            il.append(ALOAD_0);
            il.append(new GETFIELD(cpg.addFieldref(TRANSLET_CLASS, URIS_INDEX, URIS_INDEX_SIG)));
            il.append(ALOAD_0);
            il.append(new GETFIELD(cpg.addFieldref(TRANSLET_CLASS, TYPES_INDEX, TYPES_INDEX_SIG)));
            il.append(ALOAD_0);
            il.append(new GETFIELD(cpg.addFieldref(TRANSLET_CLASS, NAMESPACE_INDEX, NAMESPACE_INDEX_SIG)));
            // Initialized DOM adapter
            il.append(new INVOKESPECIAL(index));
            // Add DOM adapter to MultiDOM class by calling addDOMAdapter()
            il.append(DUP);
            il.append(methodGen.loadDOM());
            il.append(new CHECKCAST(cpg.addClass(classGen.getDOMClass())));
            il.append(SWAP);
            index = cpg.addMethodref(MULTI_DOM_CLASS, "addDOMAdapter", "(" + DOM_ADAPTER_SIG + ")I");
            il.append(new INVOKEVIRTUAL(index));
            // ignore mask returned by addDOMAdapter
            il.append(POP);
        }
    }
    // Restore old handler base from stack
    il.append(SWAP);
    il.append(methodGen.storeHandler());
}

95. Template#translate()

Project: openjdk
Source File: Template.java
View license
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    if (_disabled)
        return;
    // bug fix #4433133, add a call to named template from applyTemplates
    String className = classGen.getClassName();
    if (_compiled && isNamed()) {
        String methodName = Util.escape(_name.toString());
        il.append(classGen.loadTranslet());
        il.append(methodGen.loadDOM());
        il.append(methodGen.loadIterator());
        il.append(methodGen.loadHandler());
        il.append(methodGen.loadCurrentNode());
        il.append(new INVOKEVIRTUAL(cpg.addMethodref(className, methodName, "(" + DOM_INTF_SIG + NODE_ITERATOR_SIG + TRANSLET_OUTPUT_SIG + "I)V")));
        return;
    }
    if (_compiled)
        return;
    _compiled = true;
    // %OPT% Special handling for simple named templates.
    if (_isSimpleNamedTemplate && methodGen instanceof NamedMethodGenerator) {
        int numParams = _parameters.size();
        NamedMethodGenerator namedMethodGen = (NamedMethodGenerator) methodGen;
        // Update load/store instructions to access Params from the stack
        for (int i = 0; i < numParams; i++) {
            Param param = (Param) _parameters.elementAt(i);
            param.setLoadInstruction(namedMethodGen.loadParameter(i));
            param.setStoreInstruction(namedMethodGen.storeParameter(i));
        }
    }
    translateContents(classGen, methodGen);
    il.setPositions(true);
}

96. Text#translate()

Project: openjdk
Source File: Text.java
View license
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    if (!_ignore) {
        // Turn off character escaping if so is wanted.
        final int esc = cpg.addInterfaceMethodref(OUTPUT_HANDLER, "setEscaping", "(Z)Z");
        if (!_escaping) {
            il.append(methodGen.loadHandler());
            il.append(new PUSH(cpg, false));
            il.append(new INVOKEINTERFACE(esc, 2));
        }
        il.append(methodGen.loadHandler());
        // appropriate.
        if (!canLoadAsArrayOffsetLength()) {
            final int characters = cpg.addInterfaceMethodref(OUTPUT_HANDLER, "characters", "(" + STRING_SIG + ")V");
            il.append(new PUSH(cpg, _text));
            il.append(new INVOKEINTERFACE(characters, 2));
        } else {
            final int characters = cpg.addInterfaceMethodref(OUTPUT_HANDLER, "characters", "([CII)V");
            loadAsArrayOffsetLength(classGen, methodGen);
            il.append(new INVOKEINTERFACE(characters, 4));
        }
        // Note: setEscaping(bool) returns the original (old) value
        if (!_escaping) {
            il.append(methodGen.loadHandler());
            il.append(SWAP);
            il.append(new INVOKEINTERFACE(esc, 2));
            il.append(POP);
        }
    }
    translateContents(classGen, methodGen);
}

97. TransletOutput#translate()

Project: openjdk
Source File: TransletOutput.java
View license
/**
     * Compile code that opens the give file for output, dumps the contents of
     * the element to the file, then closes the file.
     */
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    final boolean isSecureProcessing = classGen.getParser().getXSLTC().isSecureProcessing();
    if (isSecureProcessing) {
        int index = cpg.addMethodref(BASIS_LIBRARY_CLASS, "unallowed_extension_elementF", "(Ljava/lang/String;)V");
        il.append(new PUSH(cpg, "redirect"));
        il.append(new INVOKESTATIC(index));
        return;
    }
    // Save the current output handler on the stack
    il.append(methodGen.loadHandler());
    final int open = cpg.addMethodref(TRANSLET_CLASS, "openOutputHandler", "(" + STRING_SIG + "Z)" + TRANSLET_OUTPUT_SIG);
    final int close = cpg.addMethodref(TRANSLET_CLASS, "closeOutputHandler", "(" + TRANSLET_OUTPUT_SIG + ")V");
    // Create the new output handler (leave it on stack)
    il.append(classGen.loadTranslet());
    _filename.translate(classGen, methodGen);
    il.append(new PUSH(cpg, _append));
    il.append(new INVOKEVIRTUAL(open));
    // Overwrite current handler
    il.append(methodGen.storeHandler());
    // Translate contents with substituted handler
    translateContents(classGen, methodGen);
    // Close the output handler (close file)
    il.append(classGen.loadTranslet());
    il.append(methodGen.loadHandler());
    il.append(new INVOKEVIRTUAL(close));
    // Restore old output handler from stack
    il.append(methodGen.storeHandler());
}

98. UnionPathExpr#translate()

Project: openjdk
Source File: UnionPathExpr.java
View license
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    final int init = cpg.addMethodref(UNION_ITERATOR_CLASS, "<init>", "(" + DOM_INTF_SIG + ")V");
    final int iter = cpg.addMethodref(UNION_ITERATOR_CLASS, ADD_ITERATOR, ADD_ITERATOR_SIG);
    // Create the UnionIterator and leave it on the stack
    il.append(new NEW(cpg.addClass(UNION_ITERATOR_CLASS)));
    il.append(DUP);
    il.append(methodGen.loadDOM());
    il.append(new INVOKESPECIAL(init));
    // Add the various iterators to the UnionIterator
    final int length = _components.length;
    for (int i = 0; i < length; i++) {
        _components[i].translate(classGen, methodGen);
        il.append(new INVOKEVIRTUAL(iter));
    }
    // Order the iterator only if strictly needed
    if (_reverse) {
        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));
    }
}

99. UseAttributeSets#translate()

Project: openjdk
Source File: UseAttributeSets.java
View license
/**
     * Generate a call to the method compiled for this attribute set
     */
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    final SymbolTable symbolTable = getParser().getSymbolTable();
    // Go through each attribute set and generate a method call
    for (int i = 0; i < _sets.size(); i++) {
        // Get the attribute set name
        final QName name = (QName) _sets.elementAt(i);
        // Get the AttributeSet reference from the symbol table
        final AttributeSet attrs = symbolTable.lookupAttributeSet(name);
        // Compile the call to the set's method if the set exists
        if (attrs != null) {
            final String methodName = attrs.getMethodName();
            il.append(classGen.loadTranslet());
            il.append(methodGen.loadDOM());
            il.append(methodGen.loadIterator());
            il.append(methodGen.loadHandler());
            il.append(methodGen.loadCurrentNode());
            final int method = cpg.addMethodref(classGen.getClassName(), methodName, ATTR_SET_SIG);
            il.append(new INVOKESPECIAL(method));
        } else // Generate an error if the attribute set does not exist
        {
            final Parser parser = getParser();
            final String atrs = name.toString();
            reportError(this, parser, ErrorMsg.ATTRIBSET_UNDEF_ERR, atrs);
        }
    }
}

100. BooleanType#translateTo()

Project: openjdk
Source File: BooleanType.java
View license
/**
     * Expects a boolean on the stack and pushes a string. If the value on the
     * stack is zero, then the string 'false' is pushed. Otherwise, the string
     * 'true' is pushed.
     *
     * @see     com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo
     */
public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, StringType type) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    final BranchHandle falsec = il.append(new IFEQ(null));
    il.append(new PUSH(cpg, "true"));
    final BranchHandle truec = il.append(new GOTO(null));
    falsec.setTarget(il.append(new PUSH(cpg, "false")));
    truec.setTarget(il.append(NOP));
}