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

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

1. 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;
}

2. 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;
}

3. 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));
}

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. Sort#compileInit()

Project: openjdk
Source File: Sort.java
View license
/**
     * Create a constructor for the new class. Updates the reference to the
     * collator in the super calls only when the stylesheet specifies a new
     * language in xsl:sort.
     */
private static MethodGenerator compileInit(NodeSortRecordGenerator sortRecord, ConstantPoolGen cpg, String className) {
    final InstructionList il = new InstructionList();
    final MethodGenerator init = new MethodGenerator(ACC_PUBLIC, com.sun.org.apache.bcel.internal.generic.Type.VOID, null, null, "<init>", className, il, cpg);
    // Call the constructor in the NodeSortRecord superclass
    il.append(ALOAD_0);
    il.append(new INVOKESPECIAL(cpg.addMethodref(NODE_SORT_RECORD, "<init>", "()V")));
    il.append(RETURN);
    return init;
}

6. 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()));
}

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

8. 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));
}

9. 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));
}

10. 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);
}

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. NodeSetType#translateTo()

Project: openjdk
Source File: NodeSetType.java
View license
/**
     * Translates a node-set into a string. The string value of a node-set is
     * value of its first element.
     *
     * @see     com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo
     */
public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, StringType type) {
    final InstructionList il = methodGen.getInstructionList();
    getFirstNode(classGen, methodGen);
    il.append(DUP);
    final BranchHandle falsec = il.append(new IFLT(null));
    Type.Node.translateTo(classGen, methodGen, type);
    final BranchHandle truec = il.append(new GOTO(null));
    falsec.setTarget(il.append(POP));
    il.append(new PUSH(classGen.getConstantPool(), ""));
    truec.setTarget(il.append(NOP));
}

13. 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));
}

14. 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));
}

15. 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));
}

16. AlternativePattern#translate()

Project: openjdk
Source File: AlternativePattern.java
View license
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final InstructionList il = methodGen.getInstructionList();
    _left.translate(classGen, methodGen);
    final InstructionHandle gotot = il.append(new GOTO(null));
    il.append(methodGen.loadContextNode());
    _right.translate(classGen, methodGen);
    _left._trueList.backPatch(gotot);
    _left._falseList.backPatch(gotot.getNext());
    _trueList.append(_right._trueList.add(gotot));
    _falseList.append(_right._falseList);
}

17. 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)));
}

18. 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));
}

19. 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")));
}

20. FunctionCall#translateDesynthesized()

Project: openjdk
Source File: FunctionCall.java
View license
/**
     * Compile the function call and treat as an expression
     * Update true/false-lists.
     */
@Override
public void translateDesynthesized(ClassGenerator classGen, MethodGenerator methodGen) {
    Type type = Type.Boolean;
    if (_chosenMethodType != null)
        type = _chosenMethodType.resultType();
    final InstructionList il = methodGen.getInstructionList();
    translate(classGen, methodGen);
    if ((type instanceof BooleanType) || (type instanceof IntType)) {
        _falseList.add(il.append(new IFEQ(null)));
    }
}

21. LastCall#translate()

Project: openjdk
Source File: LastCall.java
View license
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final InstructionList il = methodGen.getInstructionList();
    if (methodGen instanceof CompareGenerator) {
        il.append(((CompareGenerator) methodGen).loadLastNode());
    } else if (methodGen instanceof TestGenerator) {
        il.append(new ILOAD(LAST_INDEX));
    } else {
        final ConstantPoolGen cpg = classGen.getConstantPool();
        final int getLast = cpg.addInterfaceMethodref(NODE_ITERATOR, "getLast", "()I");
        il.append(methodGen.loadIterator());
        il.append(new INVOKEINTERFACE(getLast, 1));
    }
}

22. NumberCall#translate()

Project: openjdk
Source File: NumberCall.java
View license
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final InstructionList il = methodGen.getInstructionList();
    Type targ;
    if (argumentCount() == 0) {
        il.append(methodGen.loadContextNode());
        targ = Type.Node;
    } else {
        final Expression arg = argument();
        arg.translate(classGen, methodGen);
        arg.startIterator(classGen, methodGen);
        targ = arg.getType();
    }
    if (!targ.identicalTo(Type.Real)) {
        targ.translateTo(classGen, methodGen, Type.Real);
    }
}

23. PositionCall#translate()

Project: openjdk
Source File: PositionCall.java
View license
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final InstructionList il = methodGen.getInstructionList();
    if (methodGen instanceof CompareGenerator) {
        il.append(((CompareGenerator) methodGen).loadCurrentNode());
    } else if (methodGen instanceof TestGenerator) {
        il.append(new ILOAD(POSITION_INDEX));
    } else {
        final ConstantPoolGen cpg = classGen.getConstantPool();
        final int index = cpg.addInterfaceMethodref(NODE_ITERATOR, "getPosition", "()I");
        il.append(methodGen.loadIterator());
        il.append(new INVOKEINTERFACE(index, 1));
    }
}

24. 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);
    }
}

25. StringCall#translate()

Project: openjdk
Source File: StringCall.java
View license
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final InstructionList il = methodGen.getInstructionList();
    Type targ;
    if (argumentCount() == 0) {
        il.append(methodGen.loadContextNode());
        targ = Type.Node;
    } else {
        final Expression arg = argument();
        arg.translate(classGen, methodGen);
        arg.startIterator(classGen, methodGen);
        targ = arg.getType();
    }
    if (!targ.identicalTo(Type.String)) {
        targ.translateTo(classGen, methodGen, Type.String);
    }
}

26. Stylesheet#peepHoleOptimization()

Project: openjdk
Source File: Stylesheet.java
View license
/**
     * Peephole optimization: Remove sequences of [ALOAD, POP].
     */
private void peepHoleOptimization(MethodGenerator methodGen) {
    final String pattern = "`aload'`pop'`instruction'";
    final InstructionList il = methodGen.getInstructionList();
    final InstructionFinder find = new InstructionFinder(il);
    for (Iterator iter = find.search(pattern); iter.hasNext(); ) {
        InstructionHandle[] match = (InstructionHandle[]) iter.next();
        try {
            il.delete(match[0], match[1]);
        } catch (TargetLostException e) {
        }
    }
}

27. RealType#translateFrom()

Project: openjdk
Source File: RealType.java
View license
/**
     * Translates an external (primitive) Java type into a real. Expects a java
     * object on the stack and pushes a real (i.e., a double).
     */
public void translateFrom(ClassGenerator classGen, MethodGenerator methodGen, Class clazz) {
    InstructionList il = methodGen.getInstructionList();
    if (clazz == Character.TYPE || clazz == Byte.TYPE || clazz == Short.TYPE || clazz == Integer.TYPE) {
        il.append(I2D);
    } else if (clazz == Long.TYPE) {
        il.append(L2D);
    } else if (clazz == Float.TYPE) {
        il.append(F2D);
    } else if (clazz == Double.TYPE) {
        il.append(NOP);
    } else {
        ErrorMsg err = new ErrorMsg(ErrorMsg.DATA_CONVERSION_ERR, toString(), clazz.getName());
        classGen.getParser().reportError(Constants.FATAL, err);
    }
}

28. 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);
    }
}

29. 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());
    }
}

30. 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());
}

31. 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;
}

32. 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);
}

33. 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);
}

34. 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());
}

35. 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);
        }
    }
}

36. 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));
}

37. 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));
}

38. 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);
}

39. ResultTreeType#translateTo()

Project: openjdk
Source File: ResultTreeType.java
View license
/**
     * Expects a result tree on the stack and pushes a node-set (iterator).
     * Note that the produced iterator is an iterator for the DOM that
     * contains the result tree, and not the DOM that is currently in use.
     * This conversion here will therefore not directly work with elements
     * such as <xsl:apply-templates> and <xsl:for-each> without the DOM
     * parameter/variable being updates as well.
     *
     * @param classGen A BCEL class generator
     * @param methodGen A BCEL method generator
     * @param type An instance of NodeSetType (any)
     * @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();
    // Put an extra copy of the result tree (DOM) on the stack
    il.append(DUP);
    // DOM adapters containing a result tree are not initialised with
    // translet-type to DOM-type mapping. This must be done now for
    // XPath expressions and patterns to work for the iterator we create.
    // get names array
    il.append(classGen.loadTranslet());
    il.append(new GETFIELD(cpg.addFieldref(TRANSLET_CLASS, NAMES_INDEX, NAMES_INDEX_SIG)));
    // get uris array
    il.append(classGen.loadTranslet());
    il.append(new GETFIELD(cpg.addFieldref(TRANSLET_CLASS, URIS_INDEX, URIS_INDEX_SIG)));
    // get types array
    il.append(classGen.loadTranslet());
    il.append(new GETFIELD(cpg.addFieldref(TRANSLET_CLASS, TYPES_INDEX, TYPES_INDEX_SIG)));
    // get namespaces array
    il.append(classGen.loadTranslet());
    il.append(new GETFIELD(cpg.addFieldref(TRANSLET_CLASS, NAMESPACE_INDEX, NAMESPACE_INDEX_SIG)));
    // Pass the type mappings to the DOM adapter
    final int mapping = cpg.addInterfaceMethodref(DOM_INTF, "setupMapping", "([" + STRING_SIG + "[" + STRING_SIG + "[I" + "[" + STRING_SIG + ")V");
    il.append(new INVOKEINTERFACE(mapping, 5));
    il.append(DUP);
    // Create an iterator for the root node of the DOM adapter
    final int iter = cpg.addInterfaceMethodref(DOM_INTF, "getIterator", "()" + NODE_ITERATOR_SIG);
    il.append(new INVOKEINTERFACE(iter, 1));
}

40. 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));
}

41. 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);
}

42. 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);
}

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

45. 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));
}

46. 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);
}

47. 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));
}

48. 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));
}

49. 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);
}

50. 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())));
    }
}

51. 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());
}

52. 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));
    }
}

53. 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));
    }
}

54. 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));
}

55. 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)));
}

56. 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());
}

57. NodeType#translateTo()

Project: openjdk
Source File: NodeType.java
View license
/**
     * Expects a node on the stack and pushes a boxed node. Boxed nodes
     * are represented by an instance of <code>com.sun.org.apache.xalan.internal.xsltc.dom.Node</code>.
     *
     * @see     com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo
     */
public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, ReferenceType type) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    il.append(new NEW(cpg.addClass(RUNTIME_NODE_CLASS)));
    il.append(DUP_X1);
    il.append(SWAP);
    il.append(new PUSH(cpg, _type));
    il.append(new INVOKESPECIAL(cpg.addMethodref(RUNTIME_NODE_CLASS, "<init>", "(II)V")));
}

58. RealType#translateToDesynthesized()

Project: openjdk
Source File: RealType.java
View license
/**
     * Translates a real into a non-synthesized boolean. It does not push a
     * 0 or a 1 but instead returns branchhandle list to be appended to the
     * false list. A NaN must be converted to "false".
     *
     * @see     com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateToDesynthesized
     */
public FlowList translateToDesynthesized(ClassGenerator classGen, MethodGenerator methodGen, BooleanType type) {
    LocalVariableGen local;
    final FlowList flowlist = new FlowList();
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    // Store real into a local variable
    il.append(DUP2);
    local = methodGen.addLocalVariable("real_to_boolean_tmp", com.sun.org.apache.bcel.internal.generic.Type.DOUBLE, null, null);
    local.setStart(il.append(new DSTORE(local.getIndex())));
    // Compare it to 0.0
    il.append(DCONST_0);
    il.append(DCMPG);
    flowlist.add(il.append(new IFEQ(null)));
    //!!! call isNaN
    // Compare it to itself to see if NaN
    il.append(new DLOAD(local.getIndex()));
    local.setEnd(il.append(new DLOAD(local.getIndex())));
    il.append(DCMPG);
    // NaN != NaN
    flowlist.add(il.append(new IFNE(null)));
    return flowlist;
}

59. RealType#translateTo()

Project: openjdk
Source File: RealType.java
View license
/**
     * Expects a double on the stack and pushes a boxed double. Boxed
     * double are represented by an instance of <code>java.lang.Double</code>.
     *
     * @see     com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo
     */
public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, ReferenceType type) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    il.append(new NEW(cpg.addClass(DOUBLE_CLASS)));
    il.append(DUP_X2);
    il.append(DUP_X2);
    il.append(POP);
    il.append(new INVOKESPECIAL(cpg.addMethodref(DOUBLE_CLASS, "<init>", "(D)V")));
}

60. WithParam#translate()

Project: openjdk
Source File: WithParam.java
View license
/**
     * This code generates a sequence of bytecodes that call the
     * addParameter() method in AbstractTranslet. The method call will add
     * (or update) the parameter frame with the new parameter value.
     */
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    // Translate the value and put it on the stack
    if (_doParameterOptimization) {
        translateValue(classGen, methodGen);
        return;
    }
    // Make name acceptable for use as field name in class
    String name = Util.escape(getEscapedName());
    // Load reference to the translet (method is in AbstractTranslet)
    il.append(classGen.loadTranslet());
    // Load the name of the parameter
    // TODO: namespace ?
    il.append(new PUSH(cpg, name));
    // Generete the value of the parameter (use value in 'select' by def.)
    translateValue(classGen, methodGen);
    // Mark this parameter value is not being the default value
    il.append(new PUSH(cpg, false));
    // Pass the parameter to the template
    il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS, ADD_PARAMETER, ADD_PARAMETER_SIG)));
    // cleanup stack
    il.append(POP);
}

61. 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);
    }
}

62. 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());
}

63. 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");
}

64. 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));
    }
}

65. BooleanType#translateTo()

Project: openjdk
Source File: BooleanType.java
View license
/**
     * Expects a boolean on the stack and pushes a boxed boolean.
     * Boxed booleans are represented by an instance of
     * <code>java.lang.Boolean</code>.
     *
     * @see     com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo
     */
public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, ReferenceType type) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    il.append(new NEW(cpg.addClass(BOOLEAN_CLASS)));
    il.append(DUP_X1);
    il.append(SWAP);
    il.append(new INVOKESPECIAL(cpg.addMethodref(BOOLEAN_CLASS, "<init>", "(Z)V")));
}

66. IntType#translateTo()

Project: openjdk
Source File: IntType.java
View license
/**
     * Expects an integer on the stack and pushes a boxed integer.
     * Boxed integers are represented by an instance of
     * <code>java.lang.Integer</code>.
     *
     * @see     com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo
     */
public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, ReferenceType type) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    il.append(new NEW(cpg.addClass(INTEGER_CLASS)));
    il.append(DUP_X1);
    il.append(SWAP);
    il.append(new INVOKESPECIAL(cpg.addMethodref(INTEGER_CLASS, "<init>", "(I)V")));
}

67. 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));
    }
}

68. 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));
}

69. 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));
    }
}

70. 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));
}

71. 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));
}

72. 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));
    }
}

73. 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())));
    }
}

74. 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));
}

75. 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));
}

76. 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());
    }
}

77. 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);
    }
}

78. 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);
}

79. NotCall#translate()

Project: openjdk
Source File: NotCall.java
View license
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final InstructionList il = methodGen.getInstructionList();
    argument().translate(classGen, methodGen);
    il.append(ICONST_1);
    il.append(IXOR);
}

80. BooleanType#translateUnBox()

Project: openjdk
Source File: BooleanType.java
View license
/**
     * Translates an object of this type to its unboxed representation.
     */
public void translateUnBox(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    il.append(new CHECKCAST(cpg.addClass(BOOLEAN_CLASS)));
    il.append(new INVOKEVIRTUAL(cpg.addMethodref(BOOLEAN_CLASS, BOOLEAN_VALUE, BOOLEAN_VALUE_SIG)));
}

81. IntType#translateUnBox()

Project: openjdk
Source File: IntType.java
View license
/**
     * Translates an object of this type to its unboxed representation.
     */
public void translateUnBox(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    il.append(new CHECKCAST(cpg.addClass(INTEGER_CLASS)));
    final int index = cpg.addMethodref(INTEGER_CLASS, INT_VALUE, INT_VALUE_SIG);
    il.append(new INVOKEVIRTUAL(index));
}

82. NodeSetType#translateTo()

Project: openjdk
Source File: NodeSetType.java
View license
/**
     * Translates a node-set into the Java type denoted by <code>clazz</code>.
     * Expects a node-set on the stack and pushes an object of the appropriate
     * type after coercion.
     */
public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, Class clazz) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    final String className = clazz.getName();
    il.append(methodGen.loadDOM());
    il.append(SWAP);
    if (className.equals("org.w3c.dom.Node")) {
        int index = cpg.addInterfaceMethodref(DOM_INTF, MAKE_NODE, MAKE_NODE_SIG2);
        il.append(new INVOKEINTERFACE(index, 2));
    } else if (className.equals("org.w3c.dom.NodeList") || className.equals("java.lang.Object")) {
        int index = cpg.addInterfaceMethodref(DOM_INTF, MAKE_NODE_LIST, MAKE_NODE_LIST_SIG2);
        il.append(new INVOKEINTERFACE(index, 2));
    } else if (className.equals("java.lang.String")) {
        int next = cpg.addInterfaceMethodref(NODE_ITERATOR, "next", "()I");
        int index = cpg.addInterfaceMethodref(DOM_INTF, GET_NODE_VALUE, "(I)" + STRING_SIG);
        // Get next node from the iterator
        il.append(new INVOKEINTERFACE(next, 1));
        // Get the node's string value (from the DOM)
        il.append(new INVOKEINTERFACE(index, 2));
    } else {
        ErrorMsg err = new ErrorMsg(ErrorMsg.DATA_CONVERSION_ERR, toString(), className);
        classGen.getParser().reportError(Constants.FATAL, err);
    }
}

83. NodeType#translateTo()

Project: openjdk
Source File: NodeType.java
View license
/**
     * Translates a node into the Java type denoted by <code>clazz</code>.
     * Expects a node on the stack and pushes an object of the appropriate
     * type after coercion.
     */
public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, Class clazz) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    String className = clazz.getName();
    if (className.equals("java.lang.String")) {
        translateTo(classGen, methodGen, Type.String);
        return;
    }
    il.append(methodGen.loadDOM());
    // dom ref must be below node index
    il.append(SWAP);
    if (className.equals("org.w3c.dom.Node") || className.equals("java.lang.Object")) {
        int index = cpg.addInterfaceMethodref(DOM_INTF, MAKE_NODE, MAKE_NODE_SIG);
        il.append(new INVOKEINTERFACE(index, 2));
    } else if (className.equals("org.w3c.dom.NodeList")) {
        int index = cpg.addInterfaceMethodref(DOM_INTF, MAKE_NODE_LIST, MAKE_NODE_LIST_SIG);
        il.append(new INVOKEINTERFACE(index, 2));
    } else {
        ErrorMsg err = new ErrorMsg(ErrorMsg.DATA_CONVERSION_ERR, toString(), className);
        classGen.getParser().reportError(Constants.FATAL, err);
    }
}

84. NodeType#translateUnBox()

Project: openjdk
Source File: NodeType.java
View license
/**
     * Translates an object of this type to its unboxed representation.
     */
public void translateUnBox(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    il.append(new CHECKCAST(cpg.addClass(RUNTIME_NODE_CLASS)));
    il.append(new GETFIELD(cpg.addFieldref(RUNTIME_NODE_CLASS, NODE_FIELD, NODE_FIELD_SIG)));
}

85. RealType#translateUnBox()

Project: openjdk
Source File: RealType.java
View license
/**
     * Translates an object of this type to its unboxed representation.
     */
public void translateUnBox(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    il.append(new CHECKCAST(cpg.addClass(DOUBLE_CLASS)));
    il.append(new INVOKEVIRTUAL(cpg.addMethodref(DOUBLE_CLASS, DOUBLE_VALUE, DOUBLE_VALUE_SIG)));
}

86. ResultTreeType#translateTo()

Project: openjdk
Source File: ResultTreeType.java
View license
/**
     * Expects an result tree on the stack and pushes a boolean.
     * Translates a result tree to a boolean by first converting it to string.
     *
     * @param classGen A BCEL class generator
     * @param methodGen A BCEL method generator
     * @param type An instance of BooleanType (any)
     * @see com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo
     */
public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, BooleanType type) {
    // A result tree is always 'true' when converted to a boolean value,
    // since the tree always has at least one node (the root).
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    // don't need the DOM reference
    il.append(POP);
    // push 'true' on the stack
    il.append(ICONST_1);
}

87. AttributeSet#translate()

Project: openjdk
Source File: AttributeSet.java
View license
/**
     * Compile a method that outputs the attributes in this set
     */
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    if (_ignore)
        return;
    // Create a new method generator for an attribute set method
    methodGen = new AttributeSetMethodGenerator(_method, classGen);
    // same name first.  Those later in the stylesheet take precedence.
    if (_mergeSet != null) {
        final ConstantPoolGen cpg = classGen.getConstantPool();
        final InstructionList il = methodGen.getInstructionList();
        final String methodName = _mergeSet.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));
    }
    // take precedence (last attributes overrides first)
    if (_useSets != null)
        _useSets.translate(classGen, methodGen);
    // Translate all local attributes
    final Iterator<SyntaxTreeNode> attributes = elements();
    while (attributes.hasNext()) {
        SyntaxTreeNode element = (SyntaxTreeNode) attributes.next();
        if (element instanceof XslAttribute) {
            final XslAttribute attribute = (XslAttribute) element;
            attribute.translate(classGen, methodGen);
        }
    }
    final InstructionList il = methodGen.getInstructionList();
    il.append(RETURN);
    classGen.addMethod(methodGen);
}

88. 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));
}

89. 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)));
}

90. 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")));
}

91. 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)));
}

92. 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));
}

93. 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));
}

94. 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());
    }
}

95. 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));
}

96. 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));
}

97. 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));
}

98. 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")));
}

99. 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));
}

100. 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));
}