com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator - java examples

Here are the examples of the java api com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

69 Examples 7

19 View Complete Implementation : SyntaxTreeNode.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
/**
 * Utility method used by parameters and variables to store result trees
 * @param clreplacedGen BCEL Java clreplaced generator
 * @param methodGen BCEL Java method generator
 */
protected void compileResultTree(ClreplacedGenerator clreplacedGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = clreplacedGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    final Stylesheet stylesheet = clreplacedGen.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_CLreplaced = clreplacedGen.getDOMClreplaced();
    // Create new instance of DOM clreplaced (with RTF_INITIAL_SIZE nodes)
    // int index = cpg.addMethodref(DOM_IMPL, "<init>", "(I)V");
    // il.append(new NEW(cpg.addClreplaced(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 startDoreplacedent on the new handler
    il.append(methodGen.startDoreplacedent());
    // Instantiate result tree fragment
    translateContents(clreplacedGen, methodGen);
    // Call endDoreplacedent on the new handler
    il.append(methodGen.loadHandler());
    il.append(methodGen.endDoreplacedent());
    // Check if we need to wrap the DOMImpl object in a DOMAdapter object.
    // DOMAdapter is not needed if the RTF is a simple RTF and the nodeset()
    // function is not used.
    if (stylesheet.callsNodeset() && !DOM_CLreplaced.equals(DOM_IMPL_CLreplaced)) {
        // new com.sun.org.apache.xalan.internal.xsltc.dom.DOMAdapter(DOMImpl,String[]);
        index = cpg.addMethodref(DOM_ADAPTER_CLreplaced, "<init>", "(" + DOM_INTF_SIG + "[" + STRING_SIG + "[" + STRING_SIG + "[I" + "[" + STRING_SIG + ")V");
        il.append(new NEW(cpg.addClreplaced(DOM_ADAPTER_CLreplaced)));
        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.addClreplaced(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_CLreplaced, NAMES_INDEX, NAMES_INDEX_SIG)));
            il.append(ALOAD_0);
            il.append(new GETFIELD(cpg.addFieldref(TRANSLET_CLreplaced, URIS_INDEX, URIS_INDEX_SIG)));
            il.append(ALOAD_0);
            il.append(new GETFIELD(cpg.addFieldref(TRANSLET_CLreplaced, TYPES_INDEX, TYPES_INDEX_SIG)));
            il.append(ALOAD_0);
            il.append(new GETFIELD(cpg.addFieldref(TRANSLET_CLreplaced, NAMESPACE_INDEX, NAMESPACE_INDEX_SIG)));
            // Initialized DOM adapter
            il.append(new INVOKESPECIAL(index));
            // Add DOM adapter to MultiDOM clreplaced by calling addDOMAdapter()
            il.append(DUP);
            il.append(methodGen.loadDOM());
            il.append(new CHECKCAST(cpg.addClreplaced(clreplacedGen.getDOMClreplaced())));
            il.append(SWAP);
            index = cpg.addMethodref(MULTI_DOM_CLreplaced, "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());
}

19 View Complete Implementation : Whitespace.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
/**
 * Takes a vector of WhitespaceRule objects and generates a predicate
 * method. This method returns the translets default action for handling
 * whitespace text-nodes:
 *    - USE_PREDICATE  (run the method generated by this method)
 *    - STRIP_SPACE    (always strip whitespace text-nodes)
 *    - PRESERVE_SPACE (always preserve whitespace text-nodes)
 */
public static int translateRules(Vector rules, ClreplacedGenerator clreplacedGen) {
    // Get the core rules in prioritized order
    final int defaultAction = prioritizeRules(rules);
    // The rules vector may be empty after prioritising
    if (rules.size() == 0) {
        compileDefault(defaultAction, clreplacedGen);
        return defaultAction;
    }
    // Now - create a predicate method and sequence through rules...
    compilePredicate(rules, defaultAction, clreplacedGen);
    // Return with the translets required action (
    return USE_PREDICATE;
}

19 View Complete Implementation : Sort.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
public void translateLang(ClreplacedGenerator clreplacedGen, MethodGenerator methodGen) {
    _lang.translate(clreplacedGen, methodGen);
}

19 View Complete Implementation : StepPattern.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
public void translate(ClreplacedGenerator clreplacedGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = clreplacedGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    if (hasPredicates()) {
        switch(_contextCase) {
            case NO_CONTEXT:
                translateNoContext(clreplacedGen, methodGen);
                break;
            case SIMPLE_CONTEXT:
                translateSimpleContext(clreplacedGen, methodGen);
                break;
            default:
                translateGeneralContext(clreplacedGen, methodGen);
                break;
        }
    } else if (isWildcard()) {
        // true list falls through
        il.append(POP);
    } else {
        translateKernel(clreplacedGen, methodGen);
    }
}

19 View Complete Implementation : FunctionCall.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
private void generateAddReads(ClreplacedGenerator clreplacedGen, MethodGenerator methodGen, String clazz) {
    final ConstantPoolGen cpg = clreplacedGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    // Generate call to Module.addReads:
    // <TransletClreplaced>.clreplaced.getModule().addReads(
    // Clreplaced.forName(<clazz>).getModule());
    // Clreplaced.forName may throw ClreplacedNotFoundException.
    // This is OK as it will caught higher up the stack in
    // TransformerImpl.transform() and wrapped into a
    // TransformerException.
    methodGen.markChunkStart();
    int index = cpg.addMethodref(CLreplaced_CLreplaced, GET_MODULE, GET_MODULE_SIG);
    int index2 = cpg.addMethodref(CLreplaced_CLreplaced, FOR_NAME, FOR_NAME_SIG);
    il.append(new LDC(cpg.addString(clreplacedGen.getClreplacedName())));
    il.append(new INVOKESTATIC(index2));
    il.append(new INVOKEVIRTUAL(index));
    il.append(new LDC(cpg.addString(clazz)));
    il.append(new INVOKESTATIC(index2));
    il.append(new INVOKEVIRTUAL(index));
    index = cpg.addMethodref(MODULE_CLreplaced, ADD_READS, ADD_READS_SIG);
    il.append(new INVOKEVIRTUAL(index));
    il.append(InstructionConstants.POP);
    methodGen.markChunkEnd();
}

19 View Complete Implementation : ParentLocationPath.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
public void translate(ClreplacedGenerator clreplacedGen, MethodGenerator methodGen) {
    // Compile path iterator
    // iterator on stack....
    _path.translate(clreplacedGen, methodGen);
    translateStep(clreplacedGen, methodGen);
}

19 View Complete Implementation : SyntaxTreeNode.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
/**
 * Translate this abstract syntax tree node into JVM bytecodes.
 * @param clreplacedGen BCEL Java clreplaced generator
 * @param methodGen BCEL Java method generator
 */
public abstract void translate(ClreplacedGenerator clreplacedGen, MethodGenerator methodGen);

19 View Complete Implementation : ForEach.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
/**
 * The code that is generated by nested for-each loops can appear to some
 * JVMs as if it is accessing un-initialized variables. We must add some
 * code that pushes the default variable value on the stack and pops it
 * into the variable slot. This is done by the Variable.initialize()
 * method. The code that we compile for this loop looks like this:
 *
 *           initialize iterator
 *           initialize variables <-- HERE!!!
 *           goto   Iterate
 *  Loop:    :
 *           : (code for <xsl:for-each> contents)
 *           :
 *  Iterate: node = iterator.next();
 *           if (node != END) goto Loop
 */
public void initializeVariables(ClreplacedGenerator clreplacedGen, MethodGenerator methodGen) {
    final int n = elementCount();
    for (int i = 0; i < n; i++) {
        final SyntaxTreeNode child = getContents().get(i);
        if (child instanceof Variable) {
            Variable var = (Variable) child;
            var.initialize(clreplacedGen, methodGen);
        }
    }
}

19 View Complete Implementation : Sort.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
public void translateLang(ClreplacedGenerator clreplacedGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = clreplacedGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    // bug! see 26869
    il.append(new PUSH(cpg, _lang));
}

19 View Complete Implementation : Sort.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
public void translateCaseOrder(ClreplacedGenerator clreplacedGen, MethodGenerator methodGen) {
    _caseOrder.translate(clreplacedGen, methodGen);
}

19 View Complete Implementation : Step.java
Copyright Apache License 2.0
Author : mirkosertic
/**
 * Translate a step by pushing the appropriate iterator onto the stack.
 * The abbreviated steps '.' and '@attr' do not create new iterators
 * if they are not part of a LocationPath and have no filters.
 * In these cases a node index instead of an iterator is pushed
 * onto the stack.
 */
public void translate(ClreplacedGenerator clreplacedGen, MethodGenerator methodGen) {
    translateStep(clreplacedGen, methodGen, hasPredicates() ? _predicates.size() - 1 : -1);
}

19 View Complete Implementation : Sort.java
Copyright Apache License 2.0
Author : aphex-
/**
 * Create a new auxillary clreplaced extending NodeSortRecord.
 */
private static String compileSortRecord(Vector sortObjects, ClreplacedGenerator clreplacedGen, MethodGenerator methodGen) {
    final XSLTC xsltc = ((Sort) sortObjects.firstElement()).getXSLTC();
    final String clreplacedName = xsltc.getHelperClreplacedName();
    // This generates a new clreplaced for handling this specific sort
    final NodeSortRecordGenerator sortRecord = new NodeSortRecordGenerator(clreplacedName, NODE_SORT_RECORD, "sort$0.java", ACC_PUBLIC | ACC_SUPER | ACC_FINAL, new String[] {}, clreplacedGen.getStylesheet());
    final ConstantPoolGen cpg = sortRecord.getConstantPool();
    // Add a new instance variable for each var in closure
    final int nsorts = sortObjects.size();
    final ArrayList dups = new ArrayList();
    for (int j = 0; j < nsorts; j++) {
        final Sort sort = (Sort) sortObjects.get(j);
        // Set the name of the inner clreplaced in this sort object
        sort.setInnerClreplacedName(clreplacedName);
        final int length = (sort._closureVars == null) ? 0 : sort._closureVars.size();
        for (int i = 0; i < length; i++) {
            final VariableRefBase varRef = (VariableRefBase) sort._closureVars.get(i);
            // Discard duplicate variable references
            if (dups.contains(varRef))
                continue;
            final VariableBase var = varRef.getVariable();
            sortRecord.addField(new Field(ACC_PUBLIC, cpg.addUtf8(var.getEscapedName()), cpg.addUtf8(var.getType().toSignature()), null, cpg.getConstantPool()));
            dups.add(varRef);
        }
    }
    MethodGenerator init = compileInit(sortObjects, sortRecord, cpg, clreplacedName);
    MethodGenerator extract = compileExtract(sortObjects, sortRecord, cpg, clreplacedName);
    sortRecord.addMethod(init);
    sortRecord.addMethod(extract);
    xsltc.dumpClreplaced(sortRecord.getJavaClreplaced());
    return clreplacedName;
}

19 View Complete Implementation : Number.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
/**
 * Compiles a constructor for the clreplaced <tt>_clreplacedName</tt> that
 * inherits from {Any,Single,Multiple}NodeCounter. This constructor
 * simply calls the same constructor in the super clreplaced.
 */
private void compileConstructor(ClreplacedGenerator clreplacedGen) {
    MethodGenerator cons;
    final InstructionList il = new InstructionList();
    final ConstantPoolGen cpg = clreplacedGen.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>", _clreplacedName, 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(ClreplacedNames[_level], "<init>", "(" + TRANSLET_INTF_SIG + DOM_INTF_SIG + NODE_ITERATOR_SIG + "Z)V");
    il.append(new INVOKESPECIAL(index));
    il.append(RETURN);
    clreplacedGen.addMethod(cons);
}

19 View Complete Implementation : StepPattern.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
private void translateKernel(ClreplacedGenerator clreplacedGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = clreplacedGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    if (_nodeType == DTM.ELEMENT_NODE) {
        final int check = cpg.addInterfaceMethodref(DOM_INTF, "isElement", "(I)Z");
        il.append(methodGen.loadDOM());
        il.append(SWAP);
        il.append(new INVOKEINTERFACE(check, 2));
        // Need to allow for long jumps here
        final BranchHandle icmp = il.append(new IFNE(null));
        _falseList.add(il.append(new GOTO_W(null)));
        icmp.setTarget(il.append(NOP));
    } else if (_nodeType == DTM.ATTRIBUTE_NODE) {
        final int check = cpg.addInterfaceMethodref(DOM_INTF, "isAttribute", "(I)Z");
        il.append(methodGen.loadDOM());
        il.append(SWAP);
        il.append(new INVOKEINTERFACE(check, 2));
        // Need to allow for long jumps here
        final BranchHandle icmp = il.append(new IFNE(null));
        _falseList.add(il.append(new GOTO_W(null)));
        icmp.setTarget(il.append(NOP));
    } else {
        // context node is on the stack
        final int getEType = cpg.addInterfaceMethodref(DOM_INTF, "getExpandedTypeID", "(I)I");
        il.append(methodGen.loadDOM());
        il.append(SWAP);
        il.append(new INVOKEINTERFACE(getEType, 2));
        il.append(new PUSH(cpg, _nodeType));
        // Need to allow for long jumps here
        final BranchHandle icmp = il.append(new IF_ICMPEQ(null));
        _falseList.add(il.append(new GOTO_W(null)));
        icmp.setTarget(il.append(NOP));
    }
}

19 View Complete Implementation : FunctionCall.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
/**
 * Compile the function call and treat as an expression
 * Update true/false-lists.
 */
@Override
public void translateDesynthesized(ClreplacedGenerator clreplacedGen, MethodGenerator methodGen) {
    Type type = Type.Boolean;
    if (_chosenMethodType != null)
        type = _chosenMethodType.resultType();
    final InstructionList il = methodGen.getInstructionList();
    translate(clreplacedGen, methodGen);
    if ((type instanceof BooleanType) || (type instanceof IntType)) {
        _falseList.add(il.append(new IFEQ(null)));
    }
}

19 View Complete Implementation : SyntaxTreeNode.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
/**
 * Call translate() on all child syntax tree nodes.
 * @param clreplacedGen BCEL Java clreplaced generator
 * @param methodGen BCEL Java method generator
 */
protected void translateContents(ClreplacedGenerator clreplacedGen, MethodGenerator methodGen) {
    // Call translate() on all child nodes
    final int n = elementCount();
    for (SyntaxTreeNode item : _contents) {
        methodGen.markChunkStart();
        item.translate(clreplacedGen, methodGen);
        methodGen.markChunkEnd();
    }
    // After translation, unmap any registers for any variables/parameters
    // that were declared in this scope. Performing this unmapping in the
    // same AST scope as the declaration deals with the problems of
    // references falling out-of-scope inside the for-each element.
    // (the cause of which being 'lazy' register allocation for references)
    for (int i = 0; i < n; i++) {
        if (_contents.get(i) instanceof VariableBase) {
            final VariableBase var = (VariableBase) _contents.get(i);
            var.unmapRegister(clreplacedGen, methodGen);
        }
    }
}

19 View Complete Implementation : Sort.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
/**
 * This method should not produce any code
 */
public void translate(ClreplacedGenerator clreplacedGen, MethodGenerator methodGen) {
// empty
}

19 View Complete Implementation : Whitespace.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
/**
 * This method should not produce any code
 */
public void translate(ClreplacedGenerator clreplacedGen, MethodGenerator methodGen) {
}

19 View Complete Implementation : Expression.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
/**
 * Translate this node into JVM bytecodes.
 */
public void translate(ClreplacedGenerator clreplacedGen, MethodGenerator methodGen) {
    ErrorMsg msg = new ErrorMsg(ErrorMsg.NOT_IMPLEMENTED_ERR, getClreplaced(), this);
    getParser().reportError(FATAL, msg);
}

19 View Complete Implementation : XslElement.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
/**
 * Override this method to make sure that xsl:attributes are not
 * copied to output if this xsl:element is to be ignored
 */
public void translateContents(ClreplacedGenerator clreplacedGen, MethodGenerator methodGen) {
    final int n = elementCount();
    for (int i = 0; i < n; i++) {
        final SyntaxTreeNode item = getContents().get(i);
        if (_ignore && item instanceof XslAttribute)
            continue;
        item.translate(clreplacedGen, methodGen);
    }
}

19 View Complete Implementation : Sort.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
/**
 * These two methods are needed in the static methods that compile the
 * overloaded NodeSortRecord.compareType() and NodeSortRecord.sortOrder()
 */
public void translateSortType(ClreplacedGenerator clreplacedGen, MethodGenerator methodGen) {
    _dataType.translate(clreplacedGen, methodGen);
}

19 View Complete Implementation : ForEach.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
/**
 * The code that is generated by nested for-each loops can appear to some
 * JVMs as if it is accessing un-initialized variables. We must add some
 * code that pushes the default variable value on the stack and pops it
 * into the variable slot. This is done by the Variable.initialize()
 * method. The code that we compile for this loop looks like this:
 *
 *           initialize iterator
 *           initialize variables <-- HERE!!!
 *           goto   Iterate
 *  Loop:    :
 *           : (code for <xsl:for-each> contents)
 *           :
 *  Iterate: node = iterator.next();
 *           if (node != END) goto Loop
 */
public void initializeVariables(ClreplacedGenerator clreplacedGen, MethodGenerator methodGen) {
    final int n = elementCount();
    for (int i = 0; i < n; i++) {
        final Object child = getContents().get(i);
        if (child instanceof Variable) {
            Variable var = (Variable) child;
            var.initialize(clreplacedGen, methodGen);
        }
    }
}

19 View Complete Implementation : Expression.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
/**
 * Redefined by expressions of type boolean that use flow lists.
 */
public void translateDesynthesized(ClreplacedGenerator clreplacedGen, MethodGenerator methodGen) {
    translate(clreplacedGen, methodGen);
    if (_type instanceof BooleanType) {
        desynthesize(clreplacedGen, methodGen);
    }
}

19 View Complete Implementation : ForEach.java
Copyright Apache License 2.0
Author : aphex-
/**
 * The code that is generated by nested for-each loops can appear to some
 * JVMs as if it is accessing un-initialized variables. We must add some
 * code that pushes the default variable value on the stack and pops it
 * into the variable slot. This is done by the Variable.initialize()
 * method. The code that we compile for this loop looks like this:
 *
 *           initialize iterator
 *           initialize variables <-- HERE!!!
 *           goto   Iterate
 *  Loop:    :
 *           : (code for <xsl:for-each> contents)
 *           :
 *  Iterate: node = iterator.next();
 *           if (node != END) goto Loop
 */
public void initializeVariables(ClreplacedGenerator clreplacedGen, MethodGenerator methodGen) {
    final int n = elementCount();
    for (int i = 0; i < n; i++) {
        final Object child = getContents().elementAt(i);
        if (child instanceof Variable) {
            Variable var = (Variable) child;
            var.initialize(clreplacedGen, methodGen);
        }
    }
}

19 View Complete Implementation : Sort.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
public void translateSortOrder(ClreplacedGenerator clreplacedGen, MethodGenerator methodGen) {
    _order.translate(clreplacedGen, methodGen);
}

19 View Complete Implementation : FunctionCall.java
Copyright GNU General Public License v2.0
Author : hzio
private void generateAddReads(ClreplacedGenerator clreplacedGen, MethodGenerator methodGen, String clazz) {
    final ConstantPoolGen cpg = clreplacedGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    // Generate call to Module.addReads:
    // <TransletClreplaced>.clreplaced.getModule().addReads(
    // Clreplaced.forName(<clazz>).getModule());
    // Clreplaced.forName may throw ClreplacedNotFoundException.
    // This is OK as it will caught higher up the stack in
    // TransformerImpl.transform() and wrapped into a
    // TransformerException.
    methodGen.markChunkStart();
    int index = cpg.addMethodref(CLreplaced_CLreplaced, GET_MODULE, GET_MODULE_SIG);
    int index2 = cpg.addMethodref(CLreplaced_CLreplaced, FOR_NAME, FOR_NAME_SIG);
    il.append(new LDC(cpg.addString(clreplacedGen.getClreplacedName())));
    il.append(new INVOKESTATIC(index2));
    il.append(new INVOKEVIRTUAL(index));
    il.append(new LDC(cpg.addString(clazz)));
    il.append(new INVOKESTATIC(index2));
    il.append(new INVOKEVIRTUAL(index));
    index = cpg.addMethodref(MODULE_CLreplaced, ADD_READS, ADD_READS_SIG);
    il.append(new INVOKEVIRTUAL(index));
    il.append(InstructionConst.POP);
    methodGen.markChunkEnd();
}

19 View Complete Implementation : SyntaxTreeNode.java
Copyright Apache License 2.0
Author : aphex-
/**
 * Call translate() on all child syntax tree nodes.
 * @param clreplacedGen BCEL Java clreplaced generator
 * @param methodGen BCEL Java method generator
 */
protected void translateContents(ClreplacedGenerator clreplacedGen, MethodGenerator methodGen) {
    // Call translate() on all child nodes
    final int n = elementCount();
    for (int i = 0; i < n; i++) {
        methodGen.markChunkStart();
        final SyntaxTreeNode item = (SyntaxTreeNode) _contents.elementAt(i);
        item.translate(clreplacedGen, methodGen);
        methodGen.markChunkEnd();
    }
    // After translation, unmap any registers for any variables/parameters
    // that were declared in this scope. Performing this unmapping in the
    // same AST scope as the declaration deals with the problems of
    // references falling out-of-scope inside the for-each element.
    // (the cause of which being 'lazy' register allocation for references)
    for (int i = 0; i < n; i++) {
        if (_contents.elementAt(i) instanceof VariableBase) {
            final VariableBase var = (VariableBase) _contents.elementAt(i);
            var.unmapRegister(methodGen);
        }
    }
}

19 View Complete Implementation : Sort.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
/**
 * This method compiles code for the select expression for this
 * xsl:sort element. The method is called from the static code-generating
 * methods in this clreplaced.
 */
public void translateSelect(ClreplacedGenerator clreplacedGen, MethodGenerator methodGen) {
    _select.translate(clreplacedGen, methodGen);
}

19 View Complete Implementation : Whitespace.java
Copyright Apache License 2.0
Author : mirkosertic
/**
 * Takes a vector of WhitespaceRule objects and generates a predicate
 * method. This method returns the translets default action for handling
 * whitespace text-nodes:
 *    - USE_PREDICATE  (run the method generated by this method)
 *    - STRIP_SPACE    (always strip whitespace text-nodes)
 *    - PRESERVE_SPACE (always preserve whitespace text-nodes)
 */
public static int translateRules(List<WhitespaceRule> rules, ClreplacedGenerator clreplacedGen) {
    // Get the core rules in prioritized order
    final int defaultAction = prioritizeRules(rules);
    // The rules vector may be empty after prioritising
    if (rules.size() == 0) {
        compileDefault(defaultAction, clreplacedGen);
        return defaultAction;
    }
    // Now - create a predicate method and sequence through rules...
    compilePredicate(rules, defaultAction, clreplacedGen);
    // Return with the translets required action (
    return USE_PREDICATE;
}

19 View Complete Implementation : FilterExpr.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
/**
 * Translate a filter expression by pushing the appropriate iterator
 * onto the stack.
 */
public void translate(ClreplacedGenerator clreplacedGen, MethodGenerator methodGen) {
    translateFilterExpr(clreplacedGen, methodGen, _predicates == null ? -1 : _predicates.size() - 1);
}

19 View Complete Implementation : FilterExpr.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
private void translateFilterExpr(ClreplacedGenerator clreplacedGen, MethodGenerator methodGen, int predicateIndex) {
    if (predicateIndex >= 0) {
        translatePredicates(clreplacedGen, methodGen, predicateIndex);
    } else {
        _primary.translate(clreplacedGen, methodGen);
    }
}

19 View Complete Implementation : LogicalExpr.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
/**
 * Compile the expression - leave boolean expression on stack
 */
public void translate(ClreplacedGenerator clreplacedGen, MethodGenerator methodGen) {
    translateDesynthesized(clreplacedGen, methodGen);
    synthesize(clreplacedGen, methodGen);
}

19 View Complete Implementation : Sort.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
/**
 * Create a new auxillary clreplaced extending NodeSortRecord.
 */
private static String compileSortRecord(Vector<Sort> sortObjects, ClreplacedGenerator clreplacedGen, MethodGenerator methodGen) {
    final XSLTC xsltc = sortObjects.firstElement().getXSLTC();
    final String clreplacedName = xsltc.getHelperClreplacedName();
    // This generates a new clreplaced for handling this specific sort
    final NodeSortRecordGenerator sortRecord = new NodeSortRecordGenerator(clreplacedName, NODE_SORT_RECORD, "sort$0.java", ACC_PUBLIC | ACC_SUPER | ACC_FINAL, new String[] {}, clreplacedGen.getStylesheet());
    final ConstantPoolGen cpg = sortRecord.getConstantPool();
    // Add a new instance variable for each var in closure
    final int nsorts = sortObjects.size();
    final ArrayList<VariableRefBase> dups = new ArrayList<>();
    for (int j = 0; j < nsorts; j++) {
        final Sort sort = sortObjects.get(j);
        // Set the name of the inner clreplaced in this sort object
        sort.setInnerClreplacedName(clreplacedName);
        final int length = (sort._closureVars == null) ? 0 : sort._closureVars.size();
        for (int i = 0; i < length; i++) {
            final VariableRefBase varRef = (VariableRefBase) sort._closureVars.get(i);
            // Discard duplicate variable references
            if (dups.contains(varRef))
                continue;
            final VariableBase var = varRef.getVariable();
            sortRecord.addField(new Field(ACC_PUBLIC, cpg.addUtf8(var.getEscapedName()), cpg.addUtf8(var.getType().toSignature()), null, cpg.getConstantPool()));
            dups.add(varRef);
        }
    }
    MethodGenerator init = compileInit(sortRecord, cpg, clreplacedName);
    MethodGenerator extract = compileExtract(sortObjects, sortRecord, cpg, clreplacedName);
    sortRecord.addMethod(init);
    sortRecord.addMethod(extract);
    xsltc.dumpClreplaced(sortRecord.getJavaClreplaced());
    return clreplacedName;
}

19 View Complete Implementation : XslElement.java
Copyright Apache License 2.0
Author : aphex-
/**
 * Override this method to make sure that xsl:attributes are not
 * copied to output if this xsl:element is to be ignored
 */
public void translateContents(ClreplacedGenerator clreplacedGen, MethodGenerator methodGen) {
    final int n = elementCount();
    for (int i = 0; i < n; i++) {
        final SyntaxTreeNode item = (SyntaxTreeNode) getContents().elementAt(i);
        if (_ignore && item instanceof XslAttribute)
            continue;
        item.translate(clreplacedGen, methodGen);
    }
}

18 View Complete Implementation : EqualityExpr.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
public void translate(ClreplacedGenerator clreplacedGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = clreplacedGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    final Type tleft = _left.getType();
    Type tright = _right.getType();
    if (tleft instanceof BooleanType || tleft instanceof NumberType) {
        translateDesynthesized(clreplacedGen, methodGen);
        synthesize(clreplacedGen, methodGen);
        return;
    }
    if (tleft instanceof StringType) {
        final int equals = cpg.addMethodref(STRING_CLreplaced, "equals", "(" + OBJECT_SIG + ")Z");
        _left.translate(clreplacedGen, methodGen);
        _right.translate(clreplacedGen, 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(clreplacedGen, methodGen);
            if (_op == Operators.NE) {
                il.append(ICONST_1);
                // not x <-> x xor 1
                il.append(IXOR);
            }
            return;
        }
        if (tright instanceof RealType) {
            _left.translate(clreplacedGen, methodGen);
            tleft.translateTo(clreplacedGen, methodGen, Type.Real);
            _right.translate(clreplacedGen, 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(clreplacedGen, methodGen);
        tleft.translateTo(clreplacedGen, methodGen, Type.String);
        _right.translate(clreplacedGen, methodGen);
        if (tright instanceof ResultTreeType) {
            tright.translateTo(clreplacedGen, methodGen, Type.String);
        }
        final int equals = cpg.addMethodref(STRING_CLreplaced, "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(clreplacedGen, methodGen);
        _left.starreplacederator(clreplacedGen, methodGen);
        Type.NodeSet.translateTo(clreplacedGen, methodGen, Type.Boolean);
        _right.translate(clreplacedGen, 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(clreplacedGen, methodGen);
        // needed ?
        _left.starreplacederator(clreplacedGen, methodGen);
        _right.translate(clreplacedGen, methodGen);
        il.append(new PUSH(cpg, _op));
        il.append(methodGen.loadDOM());
        final int cmp = cpg.addMethodref(BASIS_LIBRARY_CLreplaced, "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(clreplacedGen, methodGen);
    _left.starreplacederator(clreplacedGen, methodGen);
    _right.translate(clreplacedGen, methodGen);
    _right.starreplacederator(clreplacedGen, methodGen);
    // Cast a result tree to a string to use an existing compare
    if (tright instanceof ResultTreeType) {
        tright.translateTo(clreplacedGen, 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_CLreplaced, "compare", "(" + tleft.toSignature() + tright.toSignature() + "I" + DOM_INTF_SIG + ")Z");
    il.append(new INVOKESTATIC(compare));
}

18 View Complete Implementation : EqualityExpr.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
public void translateDesynthesized(ClreplacedGenerator clreplacedGen, MethodGenerator methodGen) {
    final Type tleft = _left.getType();
    final InstructionList il = methodGen.getInstructionList();
    if (tleft instanceof BooleanType) {
        _left.translate(clreplacedGen, methodGen);
        _right.translate(clreplacedGen, methodGen);
        _falseList.add(il.append(_op == Operators.EQ ? (BranchInstruction) new IF_ICMPNE(null) : (BranchInstruction) new IF_ICMPEQ(null)));
    } else if (tleft instanceof NumberType) {
        _left.translate(clreplacedGen, methodGen);
        _right.translate(clreplacedGen, methodGen);
        if (tleft instanceof RealType) {
            il.append(DCMPG);
            _falseList.add(il.append(_op == Operators.EQ ? (BranchInstruction) new IFNE(null) : (BranchInstruction) new IFEQ(null)));
        } else {
            _falseList.add(il.append(_op == Operators.EQ ? (BranchInstruction) new IF_ICMPNE(null) : (BranchInstruction) new IF_ICMPEQ(null)));
        }
    } else {
        translate(clreplacedGen, methodGen);
        desynthesize(clreplacedGen, methodGen);
    }
}

18 View Complete Implementation : Expression.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
/**
 * If this expression is of type node-set and it is not a variable
 * reference, then call setStartNode() preplaceding the context node.
 */
public void starreplacederator(ClreplacedGenerator clreplacedGen, MethodGenerator methodGen) {
    // Ignore if type is not node-set
    if (_type instanceof NodeSetType == false) {
        return;
    }
    // setStartNode() should not be called if expr is a variable ref
    Expression expr = this;
    if (expr instanceof CastExpr) {
        expr = ((CastExpr) expr).getExpr();
    }
    if (expr instanceof VariableRefBase == false) {
        final InstructionList il = methodGen.getInstructionList();
        il.append(methodGen.loadContextNode());
        il.append(methodGen.setStartNode());
    }
}

18 View Complete Implementation : Expression.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
/**
 * Translate this node into a fresh instruction list.
 * The original instruction list is saved and restored.
 */
public final InstructionList compile(ClreplacedGenerator clreplacedGen, MethodGenerator methodGen) {
    final InstructionList result, save = methodGen.getInstructionList();
    methodGen.setInstructionList(result = new InstructionList());
    translate(clreplacedGen, methodGen);
    methodGen.setInstructionList(save);
    return result;
}

18 View Complete Implementation : Expression.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
public void desynthesize(ClreplacedGenerator clreplacedGen, MethodGenerator methodGen) {
    final InstructionList il = methodGen.getInstructionList();
    _falseList.add(il.append(new IFEQ(null)));
}

18 View Complete Implementation : Expression.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
/**
 * 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(ClreplacedGenerator clreplacedGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = clreplacedGen.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));
}

18 View Complete Implementation : ForEach.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
public void translate(ClreplacedGenerator clreplacedGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = clreplacedGen.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 replacedociated with this instruction
    final Vector sortObjects = new Vector();
    Iterator<SyntaxTreeNode> children = elements();
    while (children.hasNext()) {
        final SyntaxTreeNode 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(clreplacedGen, methodGen);
        // Get an iterator for the whole DOM - excluding the root node
        _type.translateTo(clreplacedGen, 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.translateSorreplacederator(clreplacedGen, methodGen, _select, sortObjects);
        } else {
            _select.translate(clreplacedGen, 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(clreplacedGen, methodGen);
    final BranchHandle nextNode = il.append(new GOTO(null));
    final InstructionHandle loop = il.append(NOP);
    translateContents(clreplacedGen, 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());
}

18 View Complete Implementation : Import.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
public void translate(ClreplacedGenerator clreplacedGen, MethodGenerator methodGen) {
// do nothing
}

18 View Complete Implementation : LiteralElement.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
/**
 * 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(ClreplacedGenerator clreplacedGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = clreplacedGen.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 = elementAt(j);
        if (item instanceof Variable) {
            item.translate(clreplacedGen, methodGen);
        }
        j++;
    }
    // Compile code to emit namespace attributes
    if (_accessedPrefixes != null) {
        for (Map.Entry<String, String> entry : _accessedPrefixes.entrySet()) {
            final String prefix = entry.getKey();
            final String uri = entry.getValue();
            il.append(methodGen.loadHandler());
            il.append(new PUSH(cpg, prefix));
            il.append(new PUSH(cpg, uri));
            il.append(methodGen.namespace());
        }
    }
    // Output all attributes
    if (_attributeElements != null) {
        for (SyntaxTreeNode node : _attributeElements) {
            if (!(node instanceof XslAttribute)) {
                node.translate(clreplacedGen, methodGen);
            }
        }
    }
    // Compile code to emit attributes and child elements
    translateContents(clreplacedGen, methodGen);
    // Compile code to emit element end tag
    il.append(methodGen.endElement());
}

18 View Complete Implementation : LocationPathPattern.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
public void translate(ClreplacedGenerator clreplacedGen, MethodGenerator methodGen) {
// TODO: What does it mean to translate a Pattern ?
}

18 View Complete Implementation : NamespaceAlias.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
public void translate(ClreplacedGenerator clreplacedGen, MethodGenerator methodGen) {
// do nada
}

18 View Complete Implementation : Number.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
private void compileDefault(ClreplacedGenerator clreplacedGen, MethodGenerator methodGen) {
    int index;
    ConstantPoolGen cpg = clreplacedGen.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 clreplaced
        clreplacedGen.addField(defaultNode);
        // Get a reference to the newly added field
        fieldIndexes[_level] = cpg.addFieldref(clreplacedGen.getClreplacedName(), FieldNames[_level], NODE_COUNTER_SIG);
    }
    // Check if field is initialized (runtime)
    il.append(clreplacedGen.loadTranslet());
    il.append(new GETFIELD(fieldIndexes[_level]));
    final BranchHandle ifBlock1 = il.append(new IFNONNULL(null));
    // Create an instance of DefaultNodeCounter
    index = cpg.addMethodref(ClreplacedNames[_level], "getDefaultNodeCounter", "(" + TRANSLET_INTF_SIG + DOM_INTF_SIG + NODE_ITERATOR_SIG + ")" + NODE_COUNTER_SIG);
    il.append(clreplacedGen.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(clreplacedGen.loadTranslet());
    il.append(SWAP);
    il.append(new PUTFIELD(fieldIndexes[_level]));
    final BranchHandle ifBlock2 = il.append(new GOTO(null));
    // Backpatch conditionals
    ifBlock1.setTarget(il.append(clreplacedGen.loadTranslet()));
    il.append(new GETFIELD(fieldIndexes[_level]));
    ifBlock2.setTarget(il.append(NOP));
}

18 View Complete Implementation : Number.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
public void translate(ClreplacedGenerator clreplacedGen, MethodGenerator methodGen) {
    int index;
    final ConstantPoolGen cpg = clreplacedGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    // Push "this" for the call to characters()
    il.append(clreplacedGen.loadTranslet());
    if (hasValue()) {
        compileDefault(clreplacedGen, methodGen);
        _value.translate(clreplacedGen, 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_CLreplaced, "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(clreplacedGen, methodGen);
    } else {
        compilePatterns(clreplacedGen, 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(clreplacedGen, methodGen);
        } else {
            il.append(new PUSH(cpg, "1"));
        }
        if (_lang != null) {
            _lang.translate(clreplacedGen, methodGen);
        } else {
            // TODO ??
            il.append(new PUSH(cpg, "en"));
        }
        if (_letterValue != null) {
            _letterValue.translate(clreplacedGen, methodGen);
        } else {
            il.append(new PUSH(cpg, Constants.EMPTYSTRING));
        }
        if (_groupingSeparator != null) {
            _groupingSeparator.translate(clreplacedGen, methodGen);
        } else {
            il.append(new PUSH(cpg, Constants.EMPTYSTRING));
        }
        if (_groupingSize != null) {
            _groupingSize.translate(clreplacedGen, 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_CLreplaced, CHARACTERSW, CHARACTERSW_SIG);
    il.append(new INVOKEVIRTUAL(index));
}

18 View Complete Implementation : Output.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
/**
 * Compile code that preplacedes the information in this <xsl:output> element
 * to the appropriate fields in the translet
 */
public void translate(ClreplacedGenerator clreplacedGen, MethodGenerator methodGen) {
    // Do nothing if other <xsl:output> element has higher precedence
    if (_disabled)
        return;
    ConstantPoolGen cpg = clreplacedGen.getConstantPool();
    InstructionList il = methodGen.getInstructionList();
    int field = 0;
    il.append(clreplacedGen.loadTranslet());
    // Only update _version field if set and different from default
    if ((_version != null) && (!_version.equals(XML_VERSION))) {
        field = cpg.addFieldref(TRANSLET_CLreplaced, "_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_CLreplaced, "_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_CLreplaced, "_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_CLreplaced, "_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_CLreplaced, "_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_CLreplaced, "_doctypeSystem", STRING_SIG);
    il.append(DUP);
    il.append(new PUSH(cpg, _doctypeSystem));
    il.append(new PUTFIELD(field));
    field = cpg.addFieldref(TRANSLET_CLreplaced, "_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_CLreplaced, "_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_CLreplaced, "_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_CLreplaced, "_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_CLreplaced, "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);
}

18 View Complete Implementation : Pattern.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
/**
 * Translate this node into JVM bytecodes. Patterns are translated as
 * boolean expressions with true/false lists. Before calling
 * <code>translate</code> on a pattern, make sure that the node being
 * matched is on top of the stack. After calling <code>translate</code>,
 * make sure to backpatch both true and false lists. True lists are the
 * default, in the sense that they always <em>"fall through"</em>. If this
 * is not the intended semantics (e.g., see
 * {@link com.sun.org.apache.xalan.internal.xsltc.compiler.AlternativePattern#translate})
 * then a GOTO must be appended to the instruction list after calling
 * <code>translate</code>.
 */
public abstract void translate(ClreplacedGenerator clreplacedGen, MethodGenerator methodGen);

18 View Complete Implementation : Predicate.java
Copyright GNU General Public License v2.0
Author : AdoptOpenJDK
/**
 * 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(ClreplacedGenerator clreplacedGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = clreplacedGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    // Compile auxiliary clreplaced for filter
    compileFilter(clreplacedGen, methodGen);
    // Create new instance of filter
    il.append(new NEW(cpg.addClreplaced(_clreplacedName)));
    il.append(DUP);
    il.append(new INVOKESPECIAL(cpg.addMethodref(_clreplacedName, "<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 clreplaced
        Closure variableClosure = _parentClosure;
        while (variableClosure != null) {
            if (variableClosure.inInnerClreplaced())
                break;
            variableClosure = variableClosure.getParentClosure();
        }
        // Use getfield if in an inner clreplaced
        if (variableClosure != null) {
            il.append(ALOAD_0);
            il.append(new GETFIELD(cpg.addFieldref(variableClosure.getInnerClreplacedName(), var.getEscapedName(), varType.toSignature())));
        } else {
            // Use a load of instruction if in translet clreplaced
            il.append(var.loadInstruction());
        }
        // Store variable in new closure
        il.append(new PUTFIELD(cpg.addFieldref(_clreplacedName, var.getEscapedName(), varType.toSignature())));
    }
}