Java Code Examples for com.sun.org.apache.bcel.internal.generic.InstructionList#append()

The following examples show how to use com.sun.org.apache.bcel.internal.generic.InstructionList#append() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReferenceType.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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) {
        il.append(new PUSH(cpg, DTM.ROOT_NODE));  // push 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));
}
 
Example 2
Source File: StepPattern.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

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

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

        default:
            translateGeneralContext(classGen, methodGen);
            break;
        }
    }
    else if (isWildcard()) {
        il.append(POP);     // true list falls through
    }
    else {
        translateKernel(classGen, methodGen);
    }
}
 
Example 3
Source File: ObjectType.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * 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));
}
 
Example 4
Source File: IntType.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Expects an integer on the stack and pushes a 0 if its value is 0 and
 * a 1 otherwise.
 *
 * @see     com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo
 */
public void translateTo(ClassGenerator classGen, MethodGenerator methodGen,
                        BooleanType type) {
    final InstructionList il = methodGen.getInstructionList();
    final BranchHandle falsec = il.append(new IFEQ(null));
    il.append(ICONST_1);
    final BranchHandle truec = il.append(new GOTO(null));
    falsec.setTarget(il.append(ICONST_0));
    truec.setTarget(il.append(NOP));
}
 
Example 5
Source File: ReferenceType.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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));
}
 
Example 6
Source File: NodeType.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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)));
}
 
Example 7
Source File: Expression.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Synthesize a boolean expression, i.e., either push a 0 or 1 onto the
 * operand stack for the next statement to succeed. Returns the handle
 * of the instruction to be backpatched.
 */
public void synthesize(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    _trueList.backPatch(il.append(ICONST_1));
    final BranchHandle truec = il.append(new GOTO_W(null));
    _falseList.backPatch(il.append(ICONST_0));
    truec.setTarget(il.append(NOP));
}
 
Example 8
Source File: NotCall.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void translateDesynthesized(ClassGenerator classGen,
                                   MethodGenerator methodGen) {
    final InstructionList il = methodGen.getInstructionList();
    final Expression exp = argument();
    exp.translateDesynthesized(classGen, methodGen);
    final BranchHandle gotoh = il.append(new GOTO(null));
    _trueList = exp._falseList;     // swap flow lists
    _falseList = exp._trueList;
    _falseList.add(gotoh);
}
 
Example 9
Source File: RealType.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
    flowlist.add(il.append(new IFNE(null)));        // NaN != NaN
    return flowlist;
}
 
Example 10
Source File: RealType.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Expects a real on the stack and pushes a truncated integer value
 *
 * @see     com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo
 */
public void translateTo(ClassGenerator classGen, MethodGenerator methodGen,
                        IntType type) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    il.append(new INVOKESTATIC(cpg.addMethodref(BASIS_LIBRARY_CLASS,
                                                "realToInt","(D)I")));
}
 
Example 11
Source File: ContainsCall.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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)));
}
 
Example 12
Source File: Mode.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
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;

    // For simple named templates, the signature of the generated method
    // is not fixed. It depends on the number of parameters declared in the
    // 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);
}
 
Example 13
Source File: StepPattern.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
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));
}
 
Example 14
Source File: ProcessingInstruction.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    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());
        il.append(DUP);     // first arg to "attributes" call

        // 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());
        il.append(DUP);     // first arg to "attributes" call

        // Push attribute name
        _name.translate(classGen, methodGen);// 2nd arg

    }

    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());
}
 
Example 15
Source File: ResultTreeType.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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.
    il.append(classGen.loadTranslet()); // get names array
    il.append(new GETFIELD(cpg.addFieldref(TRANSLET_CLASS,
                                           NAMES_INDEX,
                                           NAMES_INDEX_SIG)));
    il.append(classGen.loadTranslet()); // get uris array
    il.append(new GETFIELD(cpg.addFieldref(TRANSLET_CLASS,
                                           URIS_INDEX,
                                           URIS_INDEX_SIG)));
    il.append(classGen.loadTranslet()); // get types array
    il.append(new GETFIELD(cpg.addFieldref(TRANSLET_CLASS,
                                           TYPES_INDEX,
                                           TYPES_INDEX_SIG)));
    il.append(classGen.loadTranslet()); // get namespaces array
    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));
}
 
Example 16
Source File: KeyCall.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This method is called when the constructor is compiled in
 * Stylesheet.compileConstructor() and not as the syntax tree is traversed.
 * <p>This method will generate byte code that produces an iterator
 * for the nodes in the node set for the key or id function call.
 * @param classGen The Java class generator
 * @param methodGen The method generator
 */
public void translate(ClassGenerator classGen,
                      MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

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

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

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

    // Initialise the index specified in the first parameter of key()
    il.append(classGen.loadTranslet());
    if (_name == null) {
        il.append(new PUSH(cpg,"##id"));
    } else if (_resolvedQName != null) {
        il.append(new PUSH(cpg, _resolvedQName.toString()));
    } else {
        _name.translate(classGen, methodGen);
    }

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

    _value.translate(classGen, methodGen);
    il.append((_name != null) ? ICONST_1: ICONST_0);
    il.append(new INVOKEVIRTUAL(getKeyIterator));
}
 
Example 17
Source File: StepPattern.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
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));
}
 
Example 18
Source File: ForEach.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    // 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();
    Enumeration children = elements();
    while (children.hasMoreElements()) {
        final Object child = children.nextElement();
        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());
}
 
Example 19
Source File: Whitespace.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * Compiles the predicate method
 */
private static void compilePredicate(Vector rules,
                                     int defaultAction,
                                     ClassGenerator classGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = new InstructionList();
    final XSLTC xsltc = classGen.getParser().getXSLTC();

    // private boolean Translet.stripSpace(int type) - cannot be static
    final MethodGenerator stripSpace =
        new MethodGenerator(ACC_PUBLIC | ACC_FINAL ,
                    com.sun.org.apache.bcel.internal.generic.Type.BOOLEAN,
                    new com.sun.org.apache.bcel.internal.generic.Type[] {
                        Util.getJCRefType(DOM_INTF_SIG),
                        com.sun.org.apache.bcel.internal.generic.Type.INT,
                        com.sun.org.apache.bcel.internal.generic.Type.INT
                    },
                    new String[] { "dom","node","type" },
                    "stripSpace",classGen.getClassName(),il,cpg);

    classGen.addInterface("com/sun/org/apache/xalan/internal/xsltc/StripFilter");

    final int paramDom = stripSpace.getLocalIndex("dom");
    final int paramCurrent = stripSpace.getLocalIndex("node");
    final int paramType = stripSpace.getLocalIndex("type");

    BranchHandle strip[] = new BranchHandle[rules.size()];
    BranchHandle preserve[] = new BranchHandle[rules.size()];
    int sCount = 0;
    int pCount = 0;

    // Traverse all strip/preserve rules
    for (int i = 0; i<rules.size(); i++) {
        // Get the next rule in the prioritised list
        WhitespaceRule rule = (WhitespaceRule)rules.elementAt(i);

        // Returns the namespace for a node in the DOM
        final int gns = cpg.addInterfaceMethodref(DOM_INTF,
                                                  "getNamespaceName",
                                                  "(I)Ljava/lang/String;");

        final int strcmp = cpg.addMethodref("java/lang/String",
                                            "compareTo",
                                            "(Ljava/lang/String;)I");

        // Handle elements="ns:*" type rule
        if (rule.getStrength() == RULE_NAMESPACE) {
            il.append(new ALOAD(paramDom));
            il.append(new ILOAD(paramCurrent));
            il.append(new INVOKEINTERFACE(gns,2));
            il.append(new PUSH(cpg, rule.getNamespace()));
            il.append(new INVOKEVIRTUAL(strcmp));
            il.append(ICONST_0);

            if (rule.getAction() == STRIP_SPACE) {
                strip[sCount++] = il.append(new IF_ICMPEQ(null));
            }
            else {
                preserve[pCount++] = il.append(new IF_ICMPEQ(null));
            }
        }
        // Handle elements="ns:el" type rule
        else if (rule.getStrength() == RULE_ELEMENT) {
            // Create the QName for the element
            final Parser parser = classGen.getParser();
            QName qname;
            if (rule.getNamespace() != Constants.EMPTYSTRING )
                qname = parser.getQName(rule.getNamespace(), null,
                                        rule.getElement());
            else
                qname = parser.getQName(rule.getElement());

            // Register the element.
            final int elementType = xsltc.registerElement(qname);
            il.append(new ILOAD(paramType));
            il.append(new PUSH(cpg, elementType));

            // Compare current node type with wanted element type
            if (rule.getAction() == STRIP_SPACE)
                strip[sCount++] = il.append(new IF_ICMPEQ(null));
            else
                preserve[pCount++] = il.append(new IF_ICMPEQ(null));
        }
    }

    if (defaultAction == STRIP_SPACE) {
        compileStripSpace(strip, sCount, il);
        compilePreserveSpace(preserve, pCount, il);
    }
    else {
        compilePreserveSpace(preserve, pCount, il);
        compileStripSpace(strip, sCount, il);
    }

    classGen.addMethod(stripSpace);
}
 
Example 20
Source File: NodeType.java    From hottub with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Translates a node 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.
 *
 * @see     com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateToDesynthesized
 */
public FlowList translateToDesynthesized(ClassGenerator classGen,
                                         MethodGenerator methodGen,
                                         BooleanType type) {
    final InstructionList il = methodGen.getInstructionList();
    return new FlowList(il.append(new IFEQ(null)));
}