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

The following examples show how to use com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator#getClassName() . 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: Whitespace.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Compiles the predicate method
 */
private static void compileDefault(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");

    if (defaultAction == STRIP_SPACE)
        il.append(ICONST_1);
    else
        il.append(ICONST_0);
    il.append(IRETURN);

    classGen.addMethod(stripSpace);
}
 
Example 2
Source File: Whitespace.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Compiles the predicate method
 */
private static void compileDefault(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");

    if (defaultAction == STRIP_SPACE)
        il.append(ICONST_1);
    else
        il.append(ICONST_0);
    il.append(IRETURN);

    classGen.addMethod(stripSpace);
}
 
Example 3
Source File: Whitespace.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Compiles the predicate method
 */
private static void compileDefault(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");

    if (defaultAction == STRIP_SPACE)
        il.append(ICONST_1);
    else
        il.append(ICONST_0);
    il.append(IRETURN);

    classGen.addMethod(stripSpace);
}
 
Example 4
Source File: Whitespace.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Compiles the predicate method
 */
private static void compileDefault(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");

    if (defaultAction == STRIP_SPACE)
        il.append(ICONST_1);
    else
        il.append(ICONST_0);
    il.append(IRETURN);

    classGen.addMethod(stripSpace);
}
 
Example 5
Source File: VariableRef.java    From hottub 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();

    // Fall-through for variables that are implemented as methods
    if (_type.implementedAsMethod()) return;

    final String name = _variable.getEscapedName();
    final String signature = _type.toSignature();

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

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

    if (_variable.getType() instanceof NodeSetType) {
        // The method cloneIterator() also does resetting
        final int clone = cpg.addInterfaceMethodref(NODE_ITERATOR,
                                                   "cloneIterator",
                                                   "()" +
                                                    NODE_ITERATOR_SIG);
        il.append(new INVOKEINTERFACE(clone, 1));
    }
}
 
Example 6
Source File: Template.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    if (_disabled) return;
    // bug fix #4433133, add a call to named template from applyTemplates
    String className = classGen.getClassName();

    if (_compiled && isNamed()){
        String methodName = Util.escape(_name.toString());
        il.append(classGen.loadTranslet());
        il.append(methodGen.loadDOM());
        il.append(methodGen.loadIterator());
        il.append(methodGen.loadHandler());
        il.append(methodGen.loadCurrentNode());
        il.append(new INVOKEVIRTUAL(cpg.addMethodref(className,
                                                     methodName,
                                                     "("
                                                     + DOM_INTF_SIG
                                                     + NODE_ITERATOR_SIG
                                                     + TRANSLET_OUTPUT_SIG
                                                     + "I)V")));
        return;
    }

    if (_compiled) return;
    _compiled = true;

    // %OPT% Special handling for simple named templates.
    if (_isSimpleNamedTemplate && methodGen instanceof NamedMethodGenerator) {
        int numParams = _parameters.size();
        NamedMethodGenerator namedMethodGen = (NamedMethodGenerator)methodGen;

        // Update load/store instructions to access Params from the stack
        for (int i = 0; i < numParams; i++) {
            Param param = (Param)_parameters.elementAt(i);
            param.setLoadInstruction(namedMethodGen.loadParameter(i));
            param.setStoreInstruction(namedMethodGen.storeParameter(i));
        }
    }

    translateContents(classGen, methodGen);
    il.setPositions(true);
}
 
Example 7
Source File: Whitespace.java    From openjdk-8 with GNU General Public License v2.0 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 8
Source File: Template.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 (_disabled) return;
    // bug fix #4433133, add a call to named template from applyTemplates
    String className = classGen.getClassName();

    if (_compiled && isNamed()){
        String methodName = Util.escape(_name.toString());
        il.append(classGen.loadTranslet());
        il.append(methodGen.loadDOM());
        il.append(methodGen.loadIterator());
        il.append(methodGen.loadHandler());
        il.append(methodGen.loadCurrentNode());
        il.append(new INVOKEVIRTUAL(cpg.addMethodref(className,
                                                     methodName,
                                                     "("
                                                     + DOM_INTF_SIG
                                                     + NODE_ITERATOR_SIG
                                                     + TRANSLET_OUTPUT_SIG
                                                     + "I)V")));
        return;
    }

    if (_compiled) return;
    _compiled = true;

    // %OPT% Special handling for simple named templates.
    if (_isSimpleNamedTemplate && methodGen instanceof NamedMethodGenerator) {
        int numParams = _parameters.size();
        NamedMethodGenerator namedMethodGen = (NamedMethodGenerator)methodGen;

        // Update load/store instructions to access Params from the stack
        for (int i = 0; i < numParams; i++) {
            Param param = _parameters.get(i);
            param.setLoadInstruction(namedMethodGen.loadParameter(i));
            param.setStoreInstruction(namedMethodGen.storeParameter(i));
        }
    }

    translateContents(classGen, methodGen);
    il.setPositions(true);
}
 
Example 9
Source File: Template.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();

    if (_disabled) return;
    // bug fix #4433133, add a call to named template from applyTemplates
    String className = classGen.getClassName();

    if (_compiled && isNamed()){
        String methodName = Util.escape(_name.toString());
        il.append(classGen.loadTranslet());
        il.append(methodGen.loadDOM());
        il.append(methodGen.loadIterator());
        il.append(methodGen.loadHandler());
        il.append(methodGen.loadCurrentNode());
        il.append(new INVOKEVIRTUAL(cpg.addMethodref(className,
                                                     methodName,
                                                     "("
                                                     + DOM_INTF_SIG
                                                     + NODE_ITERATOR_SIG
                                                     + TRANSLET_OUTPUT_SIG
                                                     + "I)V")));
        return;
    }

    if (_compiled) return;
    _compiled = true;

    // %OPT% Special handling for simple named templates.
    if (_isSimpleNamedTemplate && methodGen instanceof NamedMethodGenerator) {
        int numParams = _parameters.size();
        NamedMethodGenerator namedMethodGen = (NamedMethodGenerator)methodGen;

        // Update load/store instructions to access Params from the stack
        for (int i = 0; i < numParams; i++) {
            Param param = (Param)_parameters.elementAt(i);
            param.setLoadInstruction(namedMethodGen.loadParameter(i));
            param.setStoreInstruction(namedMethodGen.storeParameter(i));
        }
    }

    translateContents(classGen, methodGen);
    il.setPositions(true);
}
 
Example 10
Source File: ParameterRef.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

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

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

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

    if (_variable.getType() instanceof NodeSetType) {
        // The method cloneIterator() also does resetting
        final int clone = cpg.addInterfaceMethodref(NODE_ITERATOR,
                                                   "cloneIterator",
                                                   "()" +
                                                    NODE_ITERATOR_SIG);
        il.append(new INVOKEINTERFACE(clone, 1));
    }
}
 
Example 11
Source File: Whitespace.java    From jdk8u60 with GNU General Public License v2.0 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 12
Source File: Whitespace.java    From openjdk-8-source with GNU General Public License v2.0 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 13
Source File: Template.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    if (_disabled) return;
    // bug fix #4433133, add a call to named template from applyTemplates
    String className = classGen.getClassName();

    if (_compiled && isNamed()){
        String methodName = Util.escape(_name.toString());
        il.append(classGen.loadTranslet());
        il.append(methodGen.loadDOM());
        il.append(methodGen.loadIterator());
        il.append(methodGen.loadHandler());
        il.append(methodGen.loadCurrentNode());
        il.append(new INVOKEVIRTUAL(cpg.addMethodref(className,
                                                     methodName,
                                                     "("
                                                     + DOM_INTF_SIG
                                                     + NODE_ITERATOR_SIG
                                                     + TRANSLET_OUTPUT_SIG
                                                     + "I)V")));
        return;
    }

    if (_compiled) return;
    _compiled = true;

    // %OPT% Special handling for simple named templates.
    if (_isSimpleNamedTemplate && methodGen instanceof NamedMethodGenerator) {
        int numParams = _parameters.size();
        NamedMethodGenerator namedMethodGen = (NamedMethodGenerator)methodGen;

        // Update load/store instructions to access Params from the stack
        for (int i = 0; i < numParams; i++) {
            Param param = (Param)_parameters.elementAt(i);
            param.setLoadInstruction(namedMethodGen.loadParameter(i));
            param.setStoreInstruction(namedMethodGen.storeParameter(i));
        }
    }

    translateContents(classGen, methodGen);
    il.setPositions(true);
}
 
Example 14
Source File: Template.java    From openjdk-jdk8u 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();

    if (_disabled) return;
    // bug fix #4433133, add a call to named template from applyTemplates
    String className = classGen.getClassName();

    if (_compiled && isNamed()){
        String methodName = Util.escape(_name.toString());
        il.append(classGen.loadTranslet());
        il.append(methodGen.loadDOM());
        il.append(methodGen.loadIterator());
        il.append(methodGen.loadHandler());
        il.append(methodGen.loadCurrentNode());
        il.append(new INVOKEVIRTUAL(cpg.addMethodref(className,
                                                     methodName,
                                                     "("
                                                     + DOM_INTF_SIG
                                                     + NODE_ITERATOR_SIG
                                                     + TRANSLET_OUTPUT_SIG
                                                     + "I)V")));
        return;
    }

    if (_compiled) return;
    _compiled = true;

    // %OPT% Special handling for simple named templates.
    if (_isSimpleNamedTemplate && methodGen instanceof NamedMethodGenerator) {
        int numParams = _parameters.size();
        NamedMethodGenerator namedMethodGen = (NamedMethodGenerator)methodGen;

        // Update load/store instructions to access Params from the stack
        for (int i = 0; i < numParams; i++) {
            Param param = (Param)_parameters.elementAt(i);
            param.setLoadInstruction(namedMethodGen.loadParameter(i));
            param.setStoreInstruction(namedMethodGen.storeParameter(i));
        }
    }

    translateContents(classGen, methodGen);
    il.setPositions(true);
}
 
Example 15
Source File: VariableRef.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    // Fall-through for variables that are implemented as methods
    if (_type.implementedAsMethod()) return;

    final String name = _variable.getEscapedName();
    final String signature = _type.toSignature();

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

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

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

    // Fall-through for variables that are implemented as methods
    if (_type.implementedAsMethod()) return;

    final String name = _variable.getEscapedName();
    final String signature = _type.toSignature();

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

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

    if (_variable.getType() instanceof NodeSetType) {
        // The method cloneIterator() also does resetting
        final int clone = cpg.addInterfaceMethodref(NODE_ITERATOR,
                                                   "cloneIterator",
                                                   "()" +
                                                    NODE_ITERATOR_SIG);
        il.append(new INVOKEINTERFACE(clone, 1));
    }
}
 
Example 17
Source File: Template.java    From jdk1.8-source-analysis 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 (_disabled) return;
    // bug fix #4433133, add a call to named template from applyTemplates
    String className = classGen.getClassName();

    if (_compiled && isNamed()){
        String methodName = Util.escape(_name.toString());
        il.append(classGen.loadTranslet());
        il.append(methodGen.loadDOM());
        il.append(methodGen.loadIterator());
        il.append(methodGen.loadHandler());
        il.append(methodGen.loadCurrentNode());
        il.append(new INVOKEVIRTUAL(cpg.addMethodref(className,
                                                     methodName,
                                                     "("
                                                     + DOM_INTF_SIG
                                                     + NODE_ITERATOR_SIG
                                                     + TRANSLET_OUTPUT_SIG
                                                     + "I)V")));
        return;
    }

    if (_compiled) return;
    _compiled = true;

    // %OPT% Special handling for simple named templates.
    if (_isSimpleNamedTemplate && methodGen instanceof NamedMethodGenerator) {
        int numParams = _parameters.size();
        NamedMethodGenerator namedMethodGen = (NamedMethodGenerator)methodGen;

        // Update load/store instructions to access Params from the stack
        for (int i = 0; i < numParams; i++) {
            Param param = (Param)_parameters.elementAt(i);
            param.setLoadInstruction(namedMethodGen.loadParameter(i));
            param.setStoreInstruction(namedMethodGen.storeParameter(i));
        }
    }

    translateContents(classGen, methodGen);
    il.setPositions(true);
}
 
Example 18
Source File: Whitespace.java    From openjdk-jdk9 with GNU General Public License v2.0 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 19
Source File: ParameterRef.java    From hottub 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();

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

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

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

    if (_variable.getType() instanceof NodeSetType) {
        // The method cloneIterator() also does resetting
        final int clone = cpg.addInterfaceMethodref(NODE_ITERATOR,
                                                   "cloneIterator",
                                                   "()" +
                                                    NODE_ITERATOR_SIG);
        il.append(new INVOKEINTERFACE(clone, 1));
    }
}
 
Example 20
Source File: Whitespace.java    From jdk1.8-source-analysis with Apache License 2.0 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);
}