com.sun.org.apache.xalan.internal.xsltc.compiler.util.NodeSortRecordGenerator Java Examples

The following examples show how to use com.sun.org.apache.xalan.internal.xsltc.compiler.util.NodeSortRecordGenerator. 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: Sort.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * Create a constructor for the new class. Updates the reference to the
 * collator in the super calls only when the stylesheet specifies a new
 * language in xsl:sort.
 */
private static MethodGenerator compileInit(NodeSortRecordGenerator sortRecord,
                                       ConstantPoolGen cpg,
                                       String className)
{
    final InstructionList il = new InstructionList();
    final MethodGenerator init =
        new MethodGenerator(ACC_PUBLIC,
                            com.sun.org.apache.bcel.internal.generic.Type.VOID,
                            null, null, "<init>", className,
                            il, cpg);

    // Call the constructor in the NodeSortRecord superclass
    il.append(ALOAD_0);
    il.append(new INVOKESPECIAL(cpg.addMethodref(NODE_SORT_RECORD,
                                                 "<init>", "()V")));



    il.append(RETURN);

    return init;
}
 
Example #2
Source File: Sort.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create a constructor for the new class. Updates the reference to the
 * collator in the super calls only when the stylesheet specifies a new
 * language in xsl:sort.
 */
private static MethodGenerator compileInit(Vector sortObjects,
                                       NodeSortRecordGenerator sortRecord,
                                       ConstantPoolGen cpg,
                                       String className)
{
    final InstructionList il = new InstructionList();
    final MethodGenerator init =
        new MethodGenerator(ACC_PUBLIC,
                            com.sun.org.apache.bcel.internal.generic.Type.VOID,
                            null, null, "<init>", className,
                            il, cpg);

    // Call the constructor in the NodeSortRecord superclass
    il.append(ALOAD_0);
    il.append(new INVOKESPECIAL(cpg.addMethodref(NODE_SORT_RECORD,
                                                 "<init>", "()V")));



    il.append(RETURN);

    return init;
}
 
Example #3
Source File: Sort.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create a constructor for the new class. Updates the reference to the
 * collator in the super calls only when the stylesheet specifies a new
 * language in xsl:sort.
 */
private static MethodGenerator compileInit(Vector sortObjects,
                                       NodeSortRecordGenerator sortRecord,
                                       ConstantPoolGen cpg,
                                       String className)
{
    final InstructionList il = new InstructionList();
    final MethodGenerator init =
        new MethodGenerator(ACC_PUBLIC,
                            com.sun.org.apache.bcel.internal.generic.Type.VOID,
                            null, null, "<init>", className,
                            il, cpg);

    // Call the constructor in the NodeSortRecord superclass
    il.append(ALOAD_0);
    il.append(new INVOKESPECIAL(cpg.addMethodref(NODE_SORT_RECORD,
                                                 "<init>", "()V")));



    il.append(RETURN);

    return init;
}
 
Example #4
Source File: Sort.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create a constructor for the new class. Updates the reference to the
 * collator in the super calls only when the stylesheet specifies a new
 * language in xsl:sort.
 */
private static MethodGenerator compileInit(NodeSortRecordGenerator sortRecord,
                                       ConstantPoolGen cpg,
                                       String className)
{
    final InstructionList il = new InstructionList();
    final MethodGenerator init =
        new MethodGenerator(ACC_PUBLIC,
                            com.sun.org.apache.bcel.internal.generic.Type.VOID,
                            null, null, "<init>", className,
                            il, cpg);

    // Call the constructor in the NodeSortRecord superclass
    il.append(ALOAD_0);
    il.append(new INVOKESPECIAL(cpg.addMethodref(NODE_SORT_RECORD,
                                                 "<init>", "()V")));



    il.append(RETURN);

    return init;
}
 
Example #5
Source File: Sort.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create a constructor for the new class. Updates the reference to the
 * collator in the super calls only when the stylesheet specifies a new
 * language in xsl:sort.
 */
private static MethodGenerator compileInit(NodeSortRecordGenerator sortRecord,
                                       ConstantPoolGen cpg,
                                       String className)
{
    final InstructionList il = new InstructionList();
    final MethodGenerator init =
        new MethodGenerator(ACC_PUBLIC,
                            com.sun.org.apache.bcel.internal.generic.Type.VOID,
                            null, null, "<init>", className,
                            il, cpg);

    // Call the constructor in the NodeSortRecord superclass
    il.append(ALOAD_0);
    il.append(new INVOKESPECIAL(cpg.addMethodref(NODE_SORT_RECORD,
                                                 "<init>", "()V")));



    il.append(RETURN);

    return init;
}
 
Example #6
Source File: Sort.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Create a constructor for the new class. Updates the reference to the
 * collator in the super calls only when the stylesheet specifies a new
 * language in xsl:sort.
 */
private static MethodGenerator compileInit(NodeSortRecordGenerator sortRecord,
                                       ConstantPoolGen cpg,
                                       String className)
{
    final InstructionList il = new InstructionList();
    final MethodGenerator init =
        new MethodGenerator(ACC_PUBLIC,
                            com.sun.org.apache.bcel.internal.generic.Type.VOID,
                            null, null, "<init>", className,
                            il, cpg);

    // Call the constructor in the NodeSortRecord superclass
    il.append(ALOAD_0);
    il.append(new INVOKESPECIAL(cpg.addMethodref(NODE_SORT_RECORD,
                                                 "<init>", "()V")));



    il.append(RETURN);

    return init;
}
 
Example #7
Source File: Sort.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create a constructor for the new class. Updates the reference to the
 * collator in the super calls only when the stylesheet specifies a new
 * language in xsl:sort.
 */
private static MethodGenerator compileInit(NodeSortRecordGenerator sortRecord,
                                       ConstantPoolGen cpg,
                                       String className)
{
    final InstructionList il = new InstructionList();
    final MethodGenerator init =
        new MethodGenerator(ACC_PUBLIC,
                            com.sun.org.apache.bcel.internal.generic.Type.VOID,
                            null, null, "<init>", className,
                            il, cpg);

    // Call the constructor in the NodeSortRecord superclass
    il.append(ALOAD_0);
    il.append(new INVOKESPECIAL(cpg.addMethodref(NODE_SORT_RECORD,
                                                 "<init>", "()V")));



    il.append(RETURN);

    return init;
}
 
Example #8
Source File: Sort.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create a constructor for the new class. Updates the reference to the
 * collator in the super calls only when the stylesheet specifies a new
 * language in xsl:sort.
 */
private static MethodGenerator compileInit(NodeSortRecordGenerator sortRecord,
                                       ConstantPoolGen cpg,
                                       String className)
{
    final InstructionList il = new InstructionList();
    final MethodGenerator init =
        new MethodGenerator(ACC_PUBLIC,
                            com.sun.org.apache.bcel.internal.generic.Type.VOID,
                            null, null, "<init>", className,
                            il, cpg);

    // Call the constructor in the NodeSortRecord superclass
    il.append(ALOAD_0);
    il.append(new INVOKESPECIAL(cpg.addMethodref(NODE_SORT_RECORD,
                                                 "<init>", "()V")));



    il.append(RETURN);

    return init;
}
 
Example #9
Source File: Sort.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Create a constructor for the new class. Updates the reference to the
 * collator in the super calls only when the stylesheet specifies a new
 * language in xsl:sort.
 */
private static MethodGenerator compileInit(NodeSortRecordGenerator sortRecord,
                                       ConstantPoolGen cpg,
                                       String className)
{
    final InstructionList il = new InstructionList();
    final MethodGenerator init =
        new MethodGenerator(ACC_PUBLIC,
                            com.sun.org.apache.bcel.internal.generic.Type.VOID,
                            null, null, "<init>", className,
                            il, cpg);

    // Call the constructor in the NodeSortRecord superclass
    il.append(ALOAD_0);
    il.append(new INVOKESPECIAL(cpg.addMethodref(NODE_SORT_RECORD,
                                                 "<init>", "()V")));



    il.append(RETURN);

    return init;
}
 
Example #10
Source File: Sort.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create a constructor for the new class. Updates the reference to the
 * collator in the super calls only when the stylesheet specifies a new
 * language in xsl:sort.
 */
private static MethodGenerator compileInit(Vector sortObjects,
                                       NodeSortRecordGenerator sortRecord,
                                       ConstantPoolGen cpg,
                                       String className)
{
    final InstructionList il = new InstructionList();
    final MethodGenerator init =
        new MethodGenerator(ACC_PUBLIC,
                            com.sun.org.apache.bcel.internal.generic.Type.VOID,
                            null, null, "<init>", className,
                            il, cpg);

    // Call the constructor in the NodeSortRecord superclass
    il.append(ALOAD_0);
    il.append(new INVOKESPECIAL(cpg.addMethodref(NODE_SORT_RECORD,
                                                 "<init>", "()V")));



    il.append(RETURN);

    return init;
}
 
Example #11
Source File: Sort.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create a constructor for the new class. Updates the reference to the
 * collator in the super calls only when the stylesheet specifies a new
 * language in xsl:sort.
 */
private static MethodGenerator compileInit(NodeSortRecordGenerator sortRecord,
                                       ConstantPoolGen cpg,
                                       String className)
{
    final InstructionList il = new InstructionList();
    final MethodGenerator init =
        new MethodGenerator(ACC_PUBLIC,
                            com.sun.org.apache.bcel.internal.generic.Type.VOID,
                            null, null, "<init>", className,
                            il, cpg);

    // Call the constructor in the NodeSortRecord superclass
    il.append(ALOAD_0);
    il.append(new INVOKESPECIAL(cpg.addMethodref(NODE_SORT_RECORD,
                                                 "<init>", "()V")));



    il.append(RETURN);

    return init;
}
 
Example #12
Source File: Sort.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Create a new auxillary class extending NodeSortRecord.
 */
private static String compileSortRecord(Vector<Sort> sortObjects,
                                        ClassGenerator classGen,
                                        MethodGenerator methodGen) {
    final XSLTC  xsltc = sortObjects.firstElement().getXSLTC();
    final String className = xsltc.getHelperClassName();

    // This generates a new class for handling this specific sort
    final NodeSortRecordGenerator sortRecord =
        new NodeSortRecordGenerator(className,
                                    NODE_SORT_RECORD,
                                    "sort$0.java",
                                    ACC_PUBLIC | ACC_SUPER | ACC_FINAL,
                                    new String[] {},
                                    classGen.getStylesheet());

    final ConstantPoolGen cpg = sortRecord.getConstantPool();

    // Add a new instance variable for each var in closure
    final int nsorts = sortObjects.size();
    final ArrayList<VariableRefBase> dups = new ArrayList<>();

    for (int j = 0; j < nsorts; j++) {
        final Sort sort = sortObjects.get(j);

        // Set the name of the inner class in this sort object
        sort.setInnerClassName(className);

        final int length = (sort._closureVars == null) ? 0 :
            sort._closureVars.size();
        for (int i = 0; i < length; i++) {
            final VariableRefBase varRef = (VariableRefBase) sort._closureVars.get(i);

            // Discard duplicate variable references
            if (dups.contains(varRef)) continue;

            final VariableBase var = varRef.getVariable();
            sortRecord.addField(new Field(ACC_PUBLIC,
                                cpg.addUtf8(var.getEscapedName()),
                                cpg.addUtf8(var.getType().toSignature()),
                                null, cpg.getConstantPool()));
            dups.add(varRef);
        }
    }

    MethodGenerator init = compileInit(sortRecord, cpg, className);
    MethodGenerator extract = compileExtract(sortObjects, sortRecord,
                                    cpg, className);
    sortRecord.addMethod(init);
    sortRecord.addMethod(extract);

    xsltc.dumpClass(sortRecord.getJavaClass());
    return className;
}
 
Example #13
Source File: Sort.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Compiles a method that overloads NodeSortRecord.extractValueFromDOM()
 */
private static MethodGenerator compileExtract(Vector sortObjects,
                                     NodeSortRecordGenerator sortRecord,
                                     ConstantPoolGen cpg,
                                     String className) {
    final InstructionList il = new InstructionList();

    // String NodeSortRecord.extractValueFromDOM(dom,node,level);
    final CompareGenerator extractMethod =
        new CompareGenerator(ACC_PUBLIC | ACC_FINAL,
                             com.sun.org.apache.bcel.internal.generic.Type.STRING,
                             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,
                                 Util.getJCRefType(TRANSLET_SIG),
                                 com.sun.org.apache.bcel.internal.generic.Type.INT
                             },
                             new String[] { "dom",
                                            "current",
                                            "level",
                                            "translet",
                                            "last"
                             },
                             "extractValueFromDOM", className, il, cpg);

    // Values needed for the switch statement
    final int levels = sortObjects.size();
    final int match[] = new int[levels];
    final InstructionHandle target[] = new InstructionHandle[levels];
    InstructionHandle tblswitch = null;

    // Compile switch statement only if the key has multiple levels
    if (levels > 1) {
        // Put the parameter to the swtich statement on the stack
        il.append(new ILOAD(extractMethod.getLocalIndex("level")));
        // Append the switch statement here later on
        tblswitch = il.append(new NOP());
    }

    // Append all the cases for the switch statment
    for (int level = 0; level < levels; level++) {
        match[level] = level;
        final Sort sort = (Sort)sortObjects.elementAt(level);
        target[level] = il.append(NOP);
        sort.translateSelect(sortRecord, extractMethod);
        il.append(ARETURN);
    }

    // Compile def. target for switch statement if key has multiple levels
    if (levels > 1) {
        // Append the default target - it will _NEVER_ be reached
        InstructionHandle defaultTarget =
            il.append(new PUSH(cpg, EMPTYSTRING));
        il.insert(tblswitch,new TABLESWITCH(match, target, defaultTarget));
        il.append(ARETURN);
    }

    return extractMethod;
}
 
Example #14
Source File: Sort.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * Create a new auxillary class extending NodeSortRecord.
 */
private static String compileSortRecord(Vector<Sort> sortObjects,
                                        ClassGenerator classGen,
                                        MethodGenerator methodGen) {
    final XSLTC  xsltc = sortObjects.firstElement().getXSLTC();
    final String className = xsltc.getHelperClassName();

    // This generates a new class for handling this specific sort
    final NodeSortRecordGenerator sortRecord =
        new NodeSortRecordGenerator(className,
                                    NODE_SORT_RECORD,
                                    "sort$0.java",
                                    ACC_PUBLIC | ACC_SUPER | ACC_FINAL,
                                    new String[] {},
                                    classGen.getStylesheet());

    final ConstantPoolGen cpg = sortRecord.getConstantPool();

    // Add a new instance variable for each var in closure
    final int nsorts = sortObjects.size();
    final ArrayList<VariableRefBase> dups = new ArrayList<>();

    for (int j = 0; j < nsorts; j++) {
        final Sort sort = sortObjects.get(j);

        // Set the name of the inner class in this sort object
        sort.setInnerClassName(className);

        final int length = (sort._closureVars == null) ? 0 :
            sort._closureVars.size();
        for (int i = 0; i < length; i++) {
            final VariableRefBase varRef = (VariableRefBase) sort._closureVars.get(i);

            // Discard duplicate variable references
            if (dups.contains(varRef)) continue;

            final VariableBase var = varRef.getVariable();
            sortRecord.addField(new Field(ACC_PUBLIC,
                                cpg.addUtf8(var.getEscapedName()),
                                cpg.addUtf8(var.getType().toSignature()),
                                null, cpg.getConstantPool()));
            dups.add(varRef);
        }
    }

    MethodGenerator init = compileInit(sortRecord, cpg, className);
    MethodGenerator extract = compileExtract(sortObjects, sortRecord,
                                    cpg, className);
    sortRecord.addMethod(init);
    sortRecord.addMethod(extract);

    xsltc.dumpClass(sortRecord.getJavaClass());
    return className;
}
 
Example #15
Source File: Sort.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Create a new auxillary class extending NodeSortRecord.
 */
private static String compileSortRecord(Vector sortObjects,
                                        ClassGenerator classGen,
                                        MethodGenerator methodGen) {
    final XSLTC  xsltc = ((Sort)sortObjects.firstElement()).getXSLTC();
    final String className = xsltc.getHelperClassName();

    // This generates a new class for handling this specific sort
    final NodeSortRecordGenerator sortRecord =
        new NodeSortRecordGenerator(className,
                                    NODE_SORT_RECORD,
                                    "sort$0.java",
                                    ACC_PUBLIC | ACC_SUPER | ACC_FINAL,
                                    new String[] {},
                                    classGen.getStylesheet());

    final ConstantPoolGen cpg = sortRecord.getConstantPool();

    // Add a new instance variable for each var in closure
    final int nsorts = sortObjects.size();
    final ArrayList dups = new ArrayList();

    for (int j = 0; j < nsorts; j++) {
        final Sort sort = (Sort) sortObjects.get(j);

        // Set the name of the inner class in this sort object
        sort.setInnerClassName(className);

        final int length = (sort._closureVars == null) ? 0 :
            sort._closureVars.size();
        for (int i = 0; i < length; i++) {
            final VariableRefBase varRef = (VariableRefBase) sort._closureVars.get(i);

            // Discard duplicate variable references
            if (dups.contains(varRef)) continue;

            final VariableBase var = varRef.getVariable();
            sortRecord.addField(new Field(ACC_PUBLIC,
                                cpg.addUtf8(var.getEscapedName()),
                                cpg.addUtf8(var.getType().toSignature()),
                                null, cpg.getConstantPool()));
            dups.add(varRef);
        }
    }

    MethodGenerator init = compileInit(sortObjects, sortRecord,
                                     cpg, className);
    MethodGenerator extract = compileExtract(sortObjects, sortRecord,
                                    cpg, className);
    sortRecord.addMethod(init);
    sortRecord.addMethod(extract);

    xsltc.dumpClass(sortRecord.getJavaClass());
    return className;
}
 
Example #16
Source File: Sort.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Compiles a method that overloads NodeSortRecord.extractValueFromDOM()
 */
private static MethodGenerator compileExtract(Vector sortObjects,
                                     NodeSortRecordGenerator sortRecord,
                                     ConstantPoolGen cpg,
                                     String className) {
    final InstructionList il = new InstructionList();

    // String NodeSortRecord.extractValueFromDOM(dom,node,level);
    final CompareGenerator extractMethod =
        new CompareGenerator(ACC_PUBLIC | ACC_FINAL,
                             com.sun.org.apache.bcel.internal.generic.Type.STRING,
                             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,
                                 Util.getJCRefType(TRANSLET_SIG),
                                 com.sun.org.apache.bcel.internal.generic.Type.INT
                             },
                             new String[] { "dom",
                                            "current",
                                            "level",
                                            "translet",
                                            "last"
                             },
                             "extractValueFromDOM", className, il, cpg);

    // Values needed for the switch statement
    final int levels = sortObjects.size();
    final int match[] = new int[levels];
    final InstructionHandle target[] = new InstructionHandle[levels];
    InstructionHandle tblswitch = null;

    // Compile switch statement only if the key has multiple levels
    if (levels > 1) {
        // Put the parameter to the swtich statement on the stack
        il.append(new ILOAD(extractMethod.getLocalIndex("level")));
        // Append the switch statement here later on
        tblswitch = il.append(new NOP());
    }

    // Append all the cases for the switch statment
    for (int level = 0; level < levels; level++) {
        match[level] = level;
        final Sort sort = (Sort)sortObjects.elementAt(level);
        target[level] = il.append(NOP);
        sort.translateSelect(sortRecord, extractMethod);
        il.append(ARETURN);
    }

    // Compile def. target for switch statement if key has multiple levels
    if (levels > 1) {
        // Append the default target - it will _NEVER_ be reached
        InstructionHandle defaultTarget =
            il.append(new PUSH(cpg, EMPTYSTRING));
        il.insert(tblswitch,new TABLESWITCH(match, target, defaultTarget));
        il.append(ARETURN);
    }

    return extractMethod;
}
 
Example #17
Source File: Sort.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * Compiles a method that overloads NodeSortRecord.extractValueFromDOM()
 */
private static MethodGenerator compileExtract(Vector<Sort> sortObjects,
                                     NodeSortRecordGenerator sortRecord,
                                     ConstantPoolGen cpg,
                                     String className) {
    final InstructionList il = new InstructionList();

    // String NodeSortRecord.extractValueFromDOM(dom,node,level);
    final CompareGenerator extractMethod =
        new CompareGenerator(ACC_PUBLIC | ACC_FINAL,
                             com.sun.org.apache.bcel.internal.generic.Type.STRING,
                             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,
                                 Util.getJCRefType(TRANSLET_SIG),
                                 com.sun.org.apache.bcel.internal.generic.Type.INT
                             },
                             new String[] { "dom",
                                            "current",
                                            "level",
                                            "translet",
                                            "last"
                             },
                             "extractValueFromDOM", className, il, cpg);

    // Values needed for the switch statement
    final int levels = sortObjects.size();
    final int match[] = new int[levels];
    final InstructionHandle target[] = new InstructionHandle[levels];
    InstructionHandle tblswitch = null;

    // Compile switch statement only if the key has multiple levels
    if (levels > 1) {
        // Put the parameter to the swtich statement on the stack
        il.append(new ILOAD(extractMethod.getLocalIndex("level")));
        // Append the switch statement here later on
        tblswitch = il.append(new NOP());
    }

    // Append all the cases for the switch statment
    for (int level = 0; level < levels; level++) {
        match[level] = level;
        final Sort sort = sortObjects.elementAt(level);
        target[level] = il.append(NOP);
        sort.translateSelect(sortRecord, extractMethod);
        il.append(ARETURN);
    }

    // Compile def. target for switch statement if key has multiple levels
    if (levels > 1) {
        // Append the default target - it will _NEVER_ be reached
        InstructionHandle defaultTarget =
            il.append(new PUSH(cpg, EMPTYSTRING));
        il.insert(tblswitch,new TABLESWITCH(match, target, defaultTarget));
        il.append(ARETURN);
    }

    return extractMethod;
}
 
Example #18
Source File: Sort.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Create a new auxillary class extending NodeSortRecord.
 */
private static String compileSortRecord(Vector sortObjects,
                                        ClassGenerator classGen,
                                        MethodGenerator methodGen) {
    final XSLTC  xsltc = ((Sort)sortObjects.firstElement()).getXSLTC();
    final String className = xsltc.getHelperClassName();

    // This generates a new class for handling this specific sort
    final NodeSortRecordGenerator sortRecord =
        new NodeSortRecordGenerator(className,
                                    NODE_SORT_RECORD,
                                    "sort$0.java",
                                    ACC_PUBLIC | ACC_SUPER | ACC_FINAL,
                                    new String[] {},
                                    classGen.getStylesheet());

    final ConstantPoolGen cpg = sortRecord.getConstantPool();

    // Add a new instance variable for each var in closure
    final int nsorts = sortObjects.size();
    final ArrayList dups = new ArrayList();

    for (int j = 0; j < nsorts; j++) {
        final Sort sort = (Sort) sortObjects.get(j);

        // Set the name of the inner class in this sort object
        sort.setInnerClassName(className);

        final int length = (sort._closureVars == null) ? 0 :
            sort._closureVars.size();
        for (int i = 0; i < length; i++) {
            final VariableRefBase varRef = (VariableRefBase) sort._closureVars.get(i);

            // Discard duplicate variable references
            if (dups.contains(varRef)) continue;

            final VariableBase var = varRef.getVariable();
            sortRecord.addField(new Field(ACC_PUBLIC,
                                cpg.addUtf8(var.getEscapedName()),
                                cpg.addUtf8(var.getType().toSignature()),
                                null, cpg.getConstantPool()));
            dups.add(varRef);
        }
    }

    MethodGenerator init = compileInit(sortObjects, sortRecord,
                                     cpg, className);
    MethodGenerator extract = compileExtract(sortObjects, sortRecord,
                                    cpg, className);
    sortRecord.addMethod(init);
    sortRecord.addMethod(extract);

    xsltc.dumpClass(sortRecord.getJavaClass());
    return className;
}
 
Example #19
Source File: Sort.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Compiles a method that overloads NodeSortRecord.extractValueFromDOM()
 */
private static MethodGenerator compileExtract(Vector<Sort> sortObjects,
                                     NodeSortRecordGenerator sortRecord,
                                     ConstantPoolGen cpg,
                                     String className) {
    final InstructionList il = new InstructionList();

    // String NodeSortRecord.extractValueFromDOM(dom,node,level);
    final CompareGenerator extractMethod =
        new CompareGenerator(ACC_PUBLIC | ACC_FINAL,
                             com.sun.org.apache.bcel.internal.generic.Type.STRING,
                             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,
                                 Util.getJCRefType(TRANSLET_SIG),
                                 com.sun.org.apache.bcel.internal.generic.Type.INT
                             },
                             new String[] { "dom",
                                            "current",
                                            "level",
                                            "translet",
                                            "last"
                             },
                             "extractValueFromDOM", className, il, cpg);

    // Values needed for the switch statement
    final int levels = sortObjects.size();
    final int match[] = new int[levels];
    final InstructionHandle target[] = new InstructionHandle[levels];
    InstructionHandle tblswitch = null;

    // Compile switch statement only if the key has multiple levels
    if (levels > 1) {
        // Put the parameter to the swtich statement on the stack
        il.append(new ILOAD(extractMethod.getLocalIndex("level")));
        // Append the switch statement here later on
        tblswitch = il.append(new NOP());
    }

    // Append all the cases for the switch statment
    for (int level = 0; level < levels; level++) {
        match[level] = level;
        final Sort sort = sortObjects.elementAt(level);
        target[level] = il.append(NOP);
        sort.translateSelect(sortRecord, extractMethod);
        il.append(ARETURN);
    }

    // Compile def. target for switch statement if key has multiple levels
    if (levels > 1) {
        // Append the default target - it will _NEVER_ be reached
        InstructionHandle defaultTarget =
            il.append(new PUSH(cpg, EMPTYSTRING));
        il.insert(tblswitch,new TABLESWITCH(match, target, defaultTarget));
        il.append(ARETURN);
    }

    return extractMethod;
}
 
Example #20
Source File: Sort.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Create a new auxillary class extending NodeSortRecord.
 */
private static String compileSortRecord(Vector<Sort> sortObjects,
                                        ClassGenerator classGen,
                                        MethodGenerator methodGen) {
    final XSLTC  xsltc = sortObjects.firstElement().getXSLTC();
    final String className = xsltc.getHelperClassName();

    // This generates a new class for handling this specific sort
    final NodeSortRecordGenerator sortRecord =
        new NodeSortRecordGenerator(className,
                                    NODE_SORT_RECORD,
                                    "sort$0.java",
                                    ACC_PUBLIC | ACC_SUPER | ACC_FINAL,
                                    new String[] {},
                                    classGen.getStylesheet());

    final ConstantPoolGen cpg = sortRecord.getConstantPool();

    // Add a new instance variable for each var in closure
    final int nsorts = sortObjects.size();
    final ArrayList<VariableRefBase> dups = new ArrayList<>();

    for (int j = 0; j < nsorts; j++) {
        final Sort sort = sortObjects.get(j);

        // Set the name of the inner class in this sort object
        sort.setInnerClassName(className);

        final int length = (sort._closureVars == null) ? 0 :
            sort._closureVars.size();
        for (int i = 0; i < length; i++) {
            final VariableRefBase varRef = (VariableRefBase) sort._closureVars.get(i);

            // Discard duplicate variable references
            if (dups.contains(varRef)) continue;

            final VariableBase var = varRef.getVariable();
            sortRecord.addField(new Field(ACC_PUBLIC,
                                cpg.addUtf8(var.getEscapedName()),
                                cpg.addUtf8(var.getType().toSignature()),
                                null, cpg.getConstantPool()));
            dups.add(varRef);
        }
    }

    MethodGenerator init = compileInit(sortRecord, cpg, className);
    MethodGenerator extract = compileExtract(sortObjects, sortRecord,
                                    cpg, className);
    sortRecord.addMethod(init);
    sortRecord.addMethod(extract);

    xsltc.dumpClass(sortRecord.getJavaClass());
    return className;
}
 
Example #21
Source File: Sort.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Create a new auxillary class extending NodeSortRecord.
 */
private static String compileSortRecord(Vector<Sort> sortObjects,
                                        ClassGenerator classGen,
                                        MethodGenerator methodGen) {
    final XSLTC  xsltc = sortObjects.firstElement().getXSLTC();
    final String className = xsltc.getHelperClassName();

    // This generates a new class for handling this specific sort
    final NodeSortRecordGenerator sortRecord =
        new NodeSortRecordGenerator(className,
                                    NODE_SORT_RECORD,
                                    "sort$0.java",
                                    ACC_PUBLIC | ACC_SUPER | ACC_FINAL,
                                    new String[] {},
                                    classGen.getStylesheet());

    final ConstantPoolGen cpg = sortRecord.getConstantPool();

    // Add a new instance variable for each var in closure
    final int nsorts = sortObjects.size();
    final ArrayList<VariableRefBase> dups = new ArrayList<>();

    for (int j = 0; j < nsorts; j++) {
        final Sort sort = sortObjects.get(j);

        // Set the name of the inner class in this sort object
        sort.setInnerClassName(className);

        final int length = (sort._closureVars == null) ? 0 :
            sort._closureVars.size();
        for (int i = 0; i < length; i++) {
            final VariableRefBase varRef = (VariableRefBase) sort._closureVars.get(i);

            // Discard duplicate variable references
            if (dups.contains(varRef)) continue;

            final VariableBase var = varRef.getVariable();
            sortRecord.addField(new Field(ACC_PUBLIC,
                                cpg.addUtf8(var.getEscapedName()),
                                cpg.addUtf8(var.getType().toSignature()),
                                null, cpg.getConstantPool()));
            dups.add(varRef);
        }
    }

    MethodGenerator init = compileInit(sortRecord, cpg, className);
    MethodGenerator extract = compileExtract(sortObjects, sortRecord,
                                    cpg, className);
    sortRecord.addMethod(init);
    sortRecord.addMethod(extract);

    xsltc.dumpClass(sortRecord.getJavaClass());
    return className;
}
 
Example #22
Source File: Sort.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Compiles a method that overloads NodeSortRecord.extractValueFromDOM()
 */
private static MethodGenerator compileExtract(Vector<Sort> sortObjects,
                                     NodeSortRecordGenerator sortRecord,
                                     ConstantPoolGen cpg,
                                     String className) {
    final InstructionList il = new InstructionList();

    // String NodeSortRecord.extractValueFromDOM(dom,node,level);
    final CompareGenerator extractMethod =
        new CompareGenerator(ACC_PUBLIC | ACC_FINAL,
                             com.sun.org.apache.bcel.internal.generic.Type.STRING,
                             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,
                                 Util.getJCRefType(TRANSLET_SIG),
                                 com.sun.org.apache.bcel.internal.generic.Type.INT
                             },
                             new String[] { "dom",
                                            "current",
                                            "level",
                                            "translet",
                                            "last"
                             },
                             "extractValueFromDOM", className, il, cpg);

    // Values needed for the switch statement
    final int levels = sortObjects.size();
    final int match[] = new int[levels];
    final InstructionHandle target[] = new InstructionHandle[levels];
    InstructionHandle tblswitch = null;

    // Compile switch statement only if the key has multiple levels
    if (levels > 1) {
        // Put the parameter to the swtich statement on the stack
        il.append(new ILOAD(extractMethod.getLocalIndex("level")));
        // Append the switch statement here later on
        tblswitch = il.append(new NOP());
    }

    // Append all the cases for the switch statment
    for (int level = 0; level < levels; level++) {
        match[level] = level;
        final Sort sort = sortObjects.elementAt(level);
        target[level] = il.append(NOP);
        sort.translateSelect(sortRecord, extractMethod);
        il.append(ARETURN);
    }

    // Compile def. target for switch statement if key has multiple levels
    if (levels > 1) {
        // Append the default target - it will _NEVER_ be reached
        InstructionHandle defaultTarget =
            il.append(new PUSH(cpg, EMPTYSTRING));
        il.insert(tblswitch,new TABLESWITCH(match, target, defaultTarget));
        il.append(ARETURN);
    }

    return extractMethod;
}
 
Example #23
Source File: Sort.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * Create a new auxillary class extending NodeSortRecord.
 */
private static String compileSortRecord(Vector<Sort> sortObjects,
                                        ClassGenerator classGen,
                                        MethodGenerator methodGen) {
    final XSLTC  xsltc = sortObjects.firstElement().getXSLTC();
    final String className = xsltc.getHelperClassName();

    // This generates a new class for handling this specific sort
    final NodeSortRecordGenerator sortRecord =
        new NodeSortRecordGenerator(className,
                                    NODE_SORT_RECORD,
                                    "sort$0.java",
                                    ACC_PUBLIC | ACC_SUPER | ACC_FINAL,
                                    new String[] {},
                                    classGen.getStylesheet());

    final ConstantPoolGen cpg = sortRecord.getConstantPool();

    // Add a new instance variable for each var in closure
    final int nsorts = sortObjects.size();
    final ArrayList<VariableRefBase> dups = new ArrayList<>();

    for (int j = 0; j < nsorts; j++) {
        final Sort sort = sortObjects.get(j);

        // Set the name of the inner class in this sort object
        sort.setInnerClassName(className);

        final int length = (sort._closureVars == null) ? 0 :
            sort._closureVars.size();
        for (int i = 0; i < length; i++) {
            final VariableRefBase varRef = (VariableRefBase) sort._closureVars.get(i);

            // Discard duplicate variable references
            if (dups.contains(varRef)) continue;

            final VariableBase var = varRef.getVariable();
            sortRecord.addField(new Field(ACC_PUBLIC,
                                cpg.addUtf8(var.getEscapedName()),
                                cpg.addUtf8(var.getType().toSignature()),
                                null, cpg.getConstantPool()));
            dups.add(varRef);
        }
    }

    MethodGenerator init = compileInit(sortRecord, cpg, className);
    MethodGenerator extract = compileExtract(sortObjects, sortRecord,
                                    cpg, className);
    sortRecord.addMethod(init);
    sortRecord.addMethod(extract);

    xsltc.dumpClass(sortRecord.getJavaClass());
    return className;
}
 
Example #24
Source File: Sort.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Compiles a method that overloads NodeSortRecord.extractValueFromDOM()
 */
private static MethodGenerator compileExtract(List<Sort> sortObjects,
                                     NodeSortRecordGenerator sortRecord,
                                     ConstantPoolGen cpg,
                                     String className) {
    final InstructionList il = new InstructionList();

    // String NodeSortRecord.extractValueFromDOM(dom,node,level);
    final CompareGenerator extractMethod =
        new CompareGenerator(ACC_PUBLIC | ACC_FINAL,
                             com.sun.org.apache.bcel.internal.generic.Type.STRING,
                             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,
                                 Util.getJCRefType(TRANSLET_SIG),
                                 com.sun.org.apache.bcel.internal.generic.Type.INT
                             },
                             new String[] { "dom",
                                            "current",
                                            "level",
                                            "translet",
                                            "last"
                             },
                             "extractValueFromDOM", className, il, cpg);

    // Values needed for the switch statement
    final int levels = sortObjects.size();
    final int match[] = new int[levels];
    final InstructionHandle target[] = new InstructionHandle[levels];
    InstructionHandle tblswitch = null;

    // Compile switch statement only if the key has multiple levels
    if (levels > 1) {
        // Put the parameter to the swtich statement on the stack
        il.append(new ILOAD(extractMethod.getLocalIndex("level")));
        // Append the switch statement here later on
        tblswitch = il.append(new NOP());
    }

    // Append all the cases for the switch statment
    for (int level = 0; level < levels; level++) {
        match[level] = level;
        final Sort sort = sortObjects.get(level);
        target[level] = il.append(NOP);
        sort.translateSelect(sortRecord, extractMethod);
        il.append(ARETURN);
    }

    // Compile def. target for switch statement if key has multiple levels
    if (levels > 1) {
        // Append the default target - it will _NEVER_ be reached
        InstructionHandle defaultTarget =
            il.append(new PUSH(cpg, EMPTYSTRING));
        il.insert(tblswitch,new TABLESWITCH(match, target, defaultTarget));
        il.append(ARETURN);
    }

    return extractMethod;
}
 
Example #25
Source File: Sort.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Compiles a method that overloads NodeSortRecord.extractValueFromDOM()
 */
private static MethodGenerator compileExtract(Vector<Sort> sortObjects,
                                     NodeSortRecordGenerator sortRecord,
                                     ConstantPoolGen cpg,
                                     String className) {
    final InstructionList il = new InstructionList();

    // String NodeSortRecord.extractValueFromDOM(dom,node,level);
    final CompareGenerator extractMethod =
        new CompareGenerator(ACC_PUBLIC | ACC_FINAL,
                             com.sun.org.apache.bcel.internal.generic.Type.STRING,
                             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,
                                 Util.getJCRefType(TRANSLET_SIG),
                                 com.sun.org.apache.bcel.internal.generic.Type.INT
                             },
                             new String[] { "dom",
                                            "current",
                                            "level",
                                            "translet",
                                            "last"
                             },
                             "extractValueFromDOM", className, il, cpg);

    // Values needed for the switch statement
    final int levels = sortObjects.size();
    final int match[] = new int[levels];
    final InstructionHandle target[] = new InstructionHandle[levels];
    InstructionHandle tblswitch = null;

    // Compile switch statement only if the key has multiple levels
    if (levels > 1) {
        // Put the parameter to the swtich statement on the stack
        il.append(new ILOAD(extractMethod.getLocalIndex("level")));
        // Append the switch statement here later on
        tblswitch = il.append(new NOP());
    }

    // Append all the cases for the switch statment
    for (int level = 0; level < levels; level++) {
        match[level] = level;
        final Sort sort = sortObjects.elementAt(level);
        target[level] = il.append(NOP);
        sort.translateSelect(sortRecord, extractMethod);
        il.append(ARETURN);
    }

    // Compile def. target for switch statement if key has multiple levels
    if (levels > 1) {
        // Append the default target - it will _NEVER_ be reached
        InstructionHandle defaultTarget =
            il.append(new PUSH(cpg, EMPTYSTRING));
        il.insert(tblswitch,new TABLESWITCH(match, target, defaultTarget));
        il.append(ARETURN);
    }

    return extractMethod;
}
 
Example #26
Source File: Sort.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Create a new auxillary class extending NodeSortRecord.
 */
private static String compileSortRecord(List<Sort> sortObjects,
                                        ClassGenerator classGen,
                                        MethodGenerator methodGen) {
    final XSLTC  xsltc = sortObjects.get(0).getXSLTC();
    final String className = xsltc.getHelperClassName();

    // This generates a new class for handling this specific sort
    final NodeSortRecordGenerator sortRecord =
        new NodeSortRecordGenerator(className,
                                    NODE_SORT_RECORD,
                                    "sort$0.java",
                                    ACC_PUBLIC | ACC_SUPER | ACC_FINAL,
                                    new String[] {},
                                    classGen.getStylesheet());

    final ConstantPoolGen cpg = sortRecord.getConstantPool();

    // Add a new instance variable for each var in closure
    final int nsorts = sortObjects.size();
    final List<VariableRefBase> dups = new ArrayList<>();

    for (int j = 0; j < nsorts; j++) {
        final Sort sort = sortObjects.get(j);

        // Set the name of the inner class in this sort object
        sort.setInnerClassName(className);

        final int length = (sort._closureVars == null) ? 0 :
            sort._closureVars.size();
        for (int i = 0; i < length; i++) {
            final VariableRefBase varRef = sort._closureVars.get(i);

            // Discard duplicate variable references
            if (dups.contains(varRef)) continue;

            final VariableBase var = varRef.getVariable();
            sortRecord.addField(new Field(ACC_PUBLIC,
                                cpg.addUtf8(var.getEscapedName()),
                                cpg.addUtf8(var.getType().toSignature()),
                                null, cpg.getConstantPool()));
            dups.add(varRef);
        }
    }

    MethodGenerator init = compileInit(sortRecord, cpg, className);
    MethodGenerator extract = compileExtract(sortObjects, sortRecord,
                                    cpg, className);
    sortRecord.addMethod(init);
    sortRecord.addMethod(extract);

    xsltc.dumpClass(sortRecord.getJavaClass());
    return className;
}
 
Example #27
Source File: Sort.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Compiles a method that overloads NodeSortRecord.extractValueFromDOM()
 */
private static MethodGenerator compileExtract(Vector<Sort> sortObjects,
                                     NodeSortRecordGenerator sortRecord,
                                     ConstantPoolGen cpg,
                                     String className) {
    final InstructionList il = new InstructionList();

    // String NodeSortRecord.extractValueFromDOM(dom,node,level);
    final CompareGenerator extractMethod =
        new CompareGenerator(ACC_PUBLIC | ACC_FINAL,
                             com.sun.org.apache.bcel.internal.generic.Type.STRING,
                             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,
                                 Util.getJCRefType(TRANSLET_SIG),
                                 com.sun.org.apache.bcel.internal.generic.Type.INT
                             },
                             new String[] { "dom",
                                            "current",
                                            "level",
                                            "translet",
                                            "last"
                             },
                             "extractValueFromDOM", className, il, cpg);

    // Values needed for the switch statement
    final int levels = sortObjects.size();
    final int match[] = new int[levels];
    final InstructionHandle target[] = new InstructionHandle[levels];
    InstructionHandle tblswitch = null;

    // Compile switch statement only if the key has multiple levels
    if (levels > 1) {
        // Put the parameter to the swtich statement on the stack
        il.append(new ILOAD(extractMethod.getLocalIndex("level")));
        // Append the switch statement here later on
        tblswitch = il.append(new NOP());
    }

    // Append all the cases for the switch statment
    for (int level = 0; level < levels; level++) {
        match[level] = level;
        final Sort sort = sortObjects.elementAt(level);
        target[level] = il.append(NOP);
        sort.translateSelect(sortRecord, extractMethod);
        il.append(ARETURN);
    }

    // Compile def. target for switch statement if key has multiple levels
    if (levels > 1) {
        // Append the default target - it will _NEVER_ be reached
        InstructionHandle defaultTarget =
            il.append(new PUSH(cpg, EMPTYSTRING));
        il.insert(tblswitch,new TABLESWITCH(match, target, defaultTarget));
        il.append(ARETURN);
    }

    return extractMethod;
}
 
Example #28
Source File: Sort.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Create a new auxillary class extending NodeSortRecord.
 */
private static String compileSortRecord(Vector sortObjects,
                                        ClassGenerator classGen,
                                        MethodGenerator methodGen) {
    final XSLTC  xsltc = ((Sort)sortObjects.firstElement()).getXSLTC();
    final String className = xsltc.getHelperClassName();

    // This generates a new class for handling this specific sort
    final NodeSortRecordGenerator sortRecord =
        new NodeSortRecordGenerator(className,
                                    NODE_SORT_RECORD,
                                    "sort$0.java",
                                    ACC_PUBLIC | ACC_SUPER | ACC_FINAL,
                                    new String[] {},
                                    classGen.getStylesheet());

    final ConstantPoolGen cpg = sortRecord.getConstantPool();

    // Add a new instance variable for each var in closure
    final int nsorts = sortObjects.size();
    final ArrayList dups = new ArrayList();

    for (int j = 0; j < nsorts; j++) {
        final Sort sort = (Sort) sortObjects.get(j);

        // Set the name of the inner class in this sort object
        sort.setInnerClassName(className);

        final int length = (sort._closureVars == null) ? 0 :
            sort._closureVars.size();
        for (int i = 0; i < length; i++) {
            final VariableRefBase varRef = (VariableRefBase) sort._closureVars.get(i);

            // Discard duplicate variable references
            if (dups.contains(varRef)) continue;

            final VariableBase var = varRef.getVariable();
            sortRecord.addField(new Field(ACC_PUBLIC,
                                cpg.addUtf8(var.getEscapedName()),
                                cpg.addUtf8(var.getType().toSignature()),
                                null, cpg.getConstantPool()));
            dups.add(varRef);
        }
    }

    MethodGenerator init = compileInit(sortObjects, sortRecord,
                                     cpg, className);
    MethodGenerator extract = compileExtract(sortObjects, sortRecord,
                                    cpg, className);
    sortRecord.addMethod(init);
    sortRecord.addMethod(extract);

    xsltc.dumpClass(sortRecord.getJavaClass());
    return className;
}
 
Example #29
Source File: Sort.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Create a new auxillary class extending NodeSortRecord.
 */
private static String compileSortRecord(Vector<Sort> sortObjects,
                                        ClassGenerator classGen,
                                        MethodGenerator methodGen) {
    final XSLTC  xsltc = sortObjects.firstElement().getXSLTC();
    final String className = xsltc.getHelperClassName();

    // This generates a new class for handling this specific sort
    final NodeSortRecordGenerator sortRecord =
        new NodeSortRecordGenerator(className,
                                    NODE_SORT_RECORD,
                                    "sort$0.java",
                                    ACC_PUBLIC | ACC_SUPER | ACC_FINAL,
                                    new String[] {},
                                    classGen.getStylesheet());

    final ConstantPoolGen cpg = sortRecord.getConstantPool();

    // Add a new instance variable for each var in closure
    final int nsorts = sortObjects.size();
    final ArrayList<VariableRefBase> dups = new ArrayList<>();

    for (int j = 0; j < nsorts; j++) {
        final Sort sort = sortObjects.get(j);

        // Set the name of the inner class in this sort object
        sort.setInnerClassName(className);

        final int length = (sort._closureVars == null) ? 0 :
            sort._closureVars.size();
        for (int i = 0; i < length; i++) {
            final VariableRefBase varRef = (VariableRefBase) sort._closureVars.get(i);

            // Discard duplicate variable references
            if (dups.contains(varRef)) continue;

            final VariableBase var = varRef.getVariable();
            sortRecord.addField(new Field(ACC_PUBLIC,
                                cpg.addUtf8(var.getEscapedName()),
                                cpg.addUtf8(var.getType().toSignature()),
                                null, cpg.getConstantPool()));
            dups.add(varRef);
        }
    }

    MethodGenerator init = compileInit(sortRecord, cpg, className);
    MethodGenerator extract = compileExtract(sortObjects, sortRecord,
                                    cpg, className);
    sortRecord.addMethod(init);
    sortRecord.addMethod(extract);

    xsltc.dumpClass(sortRecord.getJavaClass());
    return className;
}
 
Example #30
Source File: Sort.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Compiles a method that overloads NodeSortRecord.extractValueFromDOM()
 */
private static MethodGenerator compileExtract(Vector<Sort> sortObjects,
                                     NodeSortRecordGenerator sortRecord,
                                     ConstantPoolGen cpg,
                                     String className) {
    final InstructionList il = new InstructionList();

    // String NodeSortRecord.extractValueFromDOM(dom,node,level);
    final CompareGenerator extractMethod =
        new CompareGenerator(ACC_PUBLIC | ACC_FINAL,
                             com.sun.org.apache.bcel.internal.generic.Type.STRING,
                             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,
                                 Util.getJCRefType(TRANSLET_SIG),
                                 com.sun.org.apache.bcel.internal.generic.Type.INT
                             },
                             new String[] { "dom",
                                            "current",
                                            "level",
                                            "translet",
                                            "last"
                             },
                             "extractValueFromDOM", className, il, cpg);

    // Values needed for the switch statement
    final int levels = sortObjects.size();
    final int match[] = new int[levels];
    final InstructionHandle target[] = new InstructionHandle[levels];
    InstructionHandle tblswitch = null;

    // Compile switch statement only if the key has multiple levels
    if (levels > 1) {
        // Put the parameter to the swtich statement on the stack
        il.append(new ILOAD(extractMethod.getLocalIndex("level")));
        // Append the switch statement here later on
        tblswitch = il.append(new NOP());
    }

    // Append all the cases for the switch statment
    for (int level = 0; level < levels; level++) {
        match[level] = level;
        final Sort sort = sortObjects.elementAt(level);
        target[level] = il.append(NOP);
        sort.translateSelect(sortRecord, extractMethod);
        il.append(ARETURN);
    }

    // Compile def. target for switch statement if key has multiple levels
    if (levels > 1) {
        // Append the default target - it will _NEVER_ be reached
        InstructionHandle defaultTarget =
            il.append(new PUSH(cpg, EMPTYSTRING));
        il.insert(tblswitch,new TABLESWITCH(match, target, defaultTarget));
        il.append(ARETURN);
    }

    return extractMethod;
}