Java Code Examples for com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator#addMethod()
The following examples show how to use
com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator#addMethod() .
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 openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * 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-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * 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 jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** * 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-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * 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: Whitespace.java From hottub with GNU General Public License v2.0 | 4 votes |
/** * 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 6
Source File: Mode.java From jdk1.8-source-analysis with Apache License 2.0 | 4 votes |
private void compileNamedTemplate(Template template, ClassGenerator classGen) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = new InstructionList(); String methodName = Util.escape(template.getName().toString()); int numParams = 0; if (template.isSimpleNamedTemplate()) { Vector parameters = template.getParameters(); numParams = parameters.size(); } // Initialize the types and names arrays for the NamedMethodGenerator. com.sun.org.apache.bcel.internal.generic.Type[] types = new com.sun.org.apache.bcel.internal.generic.Type[4 + numParams]; String[] names = new String[4 + numParams]; types[0] = Util.getJCRefType(DOM_INTF_SIG); types[1] = Util.getJCRefType(NODE_ITERATOR_SIG); types[2] = Util.getJCRefType(TRANSLET_OUTPUT_SIG); types[3] = com.sun.org.apache.bcel.internal.generic.Type.INT; names[0] = DOCUMENT_PNAME; names[1] = ITERATOR_PNAME; names[2] = TRANSLET_OUTPUT_PNAME; names[3] = NODE_PNAME; // For simple named templates, the signature of the generated method // is not fixed. It depends on the number of parameters declared in the // template. for (int i = 4; i < 4 + numParams; i++) { types[i] = Util.getJCRefType(OBJECT_SIG); names[i] = "param" + String.valueOf(i-4); } NamedMethodGenerator methodGen = new NamedMethodGenerator(ACC_PUBLIC, com.sun.org.apache.bcel.internal.generic.Type.VOID, types, names, methodName, getClassName(), il, cpg); il.append(template.compile(classGen, methodGen)); il.append(RETURN); classGen.addMethod(methodGen); }
Example 7
Source File: Whitespace.java From JDKSourceCode1.8 with MIT License | 4 votes |
/** * 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: Mode.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
private void compileNamedTemplate(Template template, ClassGenerator classGen) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = new InstructionList(); String methodName = Util.escape(template.getName().toString()); int numParams = 0; if (template.isSimpleNamedTemplate()) { Vector parameters = template.getParameters(); numParams = parameters.size(); } // Initialize the types and names arrays for the NamedMethodGenerator. com.sun.org.apache.bcel.internal.generic.Type[] types = new com.sun.org.apache.bcel.internal.generic.Type[4 + numParams]; String[] names = new String[4 + numParams]; types[0] = Util.getJCRefType(DOM_INTF_SIG); types[1] = Util.getJCRefType(NODE_ITERATOR_SIG); types[2] = Util.getJCRefType(TRANSLET_OUTPUT_SIG); types[3] = com.sun.org.apache.bcel.internal.generic.Type.INT; names[0] = DOCUMENT_PNAME; names[1] = ITERATOR_PNAME; names[2] = TRANSLET_OUTPUT_PNAME; names[3] = NODE_PNAME; // For simple named templates, the signature of the generated method // is not fixed. It depends on the number of parameters declared in the // template. for (int i = 4; i < 4 + numParams; i++) { types[i] = Util.getJCRefType(OBJECT_SIG); names[i] = "param" + String.valueOf(i-4); } NamedMethodGenerator methodGen = new NamedMethodGenerator(ACC_PUBLIC, com.sun.org.apache.bcel.internal.generic.Type.VOID, types, names, methodName, getClassName(), il, cpg); il.append(template.compile(classGen, methodGen)); il.append(RETURN); classGen.addMethod(methodGen); }
Example 9
Source File: Stylesheet.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
/** * Compile the translet's constructor */ private void compileConstructor(ClassGenerator classGen, Output output) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = new InstructionList(); final MethodGenerator constructor = new MethodGenerator(ACC_PUBLIC, com.sun.org.apache.bcel.internal.generic.Type.VOID, null, null, "<init>", _className, il, cpg); // Call the constructor in the AbstractTranslet superclass il.append(classGen.loadTranslet()); il.append(new INVOKESPECIAL(cpg.addMethodref(TRANSLET_CLASS, "<init>", "()V"))); constructor.markChunkStart(); il.append(classGen.loadTranslet()); il.append(new GETSTATIC(cpg.addFieldref(_className, STATIC_NAMES_ARRAY_FIELD, NAMES_INDEX_SIG))); il.append(new PUTFIELD(cpg.addFieldref(TRANSLET_CLASS, NAMES_INDEX, NAMES_INDEX_SIG))); il.append(classGen.loadTranslet()); il.append(new GETSTATIC(cpg.addFieldref(_className, STATIC_URIS_ARRAY_FIELD, URIS_INDEX_SIG))); il.append(new PUTFIELD(cpg.addFieldref(TRANSLET_CLASS, URIS_INDEX, URIS_INDEX_SIG))); constructor.markChunkEnd(); constructor.markChunkStart(); il.append(classGen.loadTranslet()); il.append(new GETSTATIC(cpg.addFieldref(_className, STATIC_TYPES_ARRAY_FIELD, TYPES_INDEX_SIG))); il.append(new PUTFIELD(cpg.addFieldref(TRANSLET_CLASS, TYPES_INDEX, TYPES_INDEX_SIG))); constructor.markChunkEnd(); constructor.markChunkStart(); il.append(classGen.loadTranslet()); il.append(new GETSTATIC(cpg.addFieldref(_className, STATIC_NAMESPACE_ARRAY_FIELD, NAMESPACE_INDEX_SIG))); il.append(new PUTFIELD(cpg.addFieldref(TRANSLET_CLASS, NAMESPACE_INDEX, NAMESPACE_INDEX_SIG))); constructor.markChunkEnd(); constructor.markChunkStart(); il.append(classGen.loadTranslet()); il.append(new PUSH(cpg, AbstractTranslet.CURRENT_TRANSLET_VERSION)); il.append(new PUTFIELD(cpg.addFieldref(TRANSLET_CLASS, TRANSLET_VERSION_INDEX, TRANSLET_VERSION_INDEX_SIG))); constructor.markChunkEnd(); if (_hasIdCall) { constructor.markChunkStart(); il.append(classGen.loadTranslet()); il.append(new PUSH(cpg, Boolean.TRUE)); il.append(new PUTFIELD(cpg.addFieldref(TRANSLET_CLASS, HASIDCALL_INDEX, HASIDCALL_INDEX_SIG))); constructor.markChunkEnd(); } // Compile in code to set the output configuration from <xsl:output> if (output != null) { // Set all the output settings files in the translet constructor.markChunkStart(); output.translate(classGen, constructor); constructor.markChunkEnd(); } // Compile default decimal formatting symbols. // This is an implicit, nameless xsl:decimal-format top-level element. if (_numberFormattingUsed) { constructor.markChunkStart(); DecimalFormatting.translateDefaultDFS(classGen, constructor); constructor.markChunkEnd(); } il.append(RETURN); classGen.addMethod(constructor); }
Example 10
Source File: Mode.java From JDKSourceCode1.8 with MIT License | 4 votes |
private void compileNamedTemplate(Template template, ClassGenerator classGen) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = new InstructionList(); String methodName = Util.escape(template.getName().toString()); int numParams = 0; if (template.isSimpleNamedTemplate()) { Vector parameters = template.getParameters(); numParams = parameters.size(); } // Initialize the types and names arrays for the NamedMethodGenerator. com.sun.org.apache.bcel.internal.generic.Type[] types = new com.sun.org.apache.bcel.internal.generic.Type[4 + numParams]; String[] names = new String[4 + numParams]; types[0] = Util.getJCRefType(DOM_INTF_SIG); types[1] = Util.getJCRefType(NODE_ITERATOR_SIG); types[2] = Util.getJCRefType(TRANSLET_OUTPUT_SIG); types[3] = com.sun.org.apache.bcel.internal.generic.Type.INT; names[0] = DOCUMENT_PNAME; names[1] = ITERATOR_PNAME; names[2] = TRANSLET_OUTPUT_PNAME; names[3] = NODE_PNAME; // For simple named templates, the signature of the generated method // is not fixed. It depends on the number of parameters declared in the // template. for (int i = 4; i < 4 + numParams; i++) { types[i] = Util.getJCRefType(OBJECT_SIG); names[i] = "param" + String.valueOf(i-4); } NamedMethodGenerator methodGen = new NamedMethodGenerator(ACC_PUBLIC, com.sun.org.apache.bcel.internal.generic.Type.VOID, types, names, methodName, getClassName(), il, cpg); il.append(template.compile(classGen, methodGen)); il.append(RETURN); classGen.addMethod(methodGen); }
Example 11
Source File: Whitespace.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
/** * 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: Stylesheet.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
/** * Compile a buildKeys() method into the output class. Note that keys * for the input document are created in topLevel(), not in this method. * However, we still need this method to create keys for documents loaded * via the XPath document() function. */ private String compileBuildKeys(ClassGenerator classGen) { final ConstantPoolGen cpg = classGen.getConstantPool(); final com.sun.org.apache.bcel.internal.generic.Type[] argTypes = { Util.getJCRefType(DOM_INTF_SIG), Util.getJCRefType(NODE_ITERATOR_SIG), Util.getJCRefType(TRANSLET_OUTPUT_SIG), com.sun.org.apache.bcel.internal.generic.Type.INT }; final String[] argNames = { DOCUMENT_PNAME, ITERATOR_PNAME, TRANSLET_OUTPUT_PNAME, "current" }; final InstructionList il = new InstructionList(); final MethodGenerator buildKeys = new MethodGenerator(ACC_PUBLIC, com.sun.org.apache.bcel.internal.generic.Type.VOID, argTypes, argNames, "buildKeys", _className, il, classGen.getConstantPool()); buildKeys.addException("com.sun.org.apache.xalan.internal.xsltc.TransletException"); final Iterator<SyntaxTreeNode> elements = elements(); while (elements.hasNext()) { // xsl:key final SyntaxTreeNode element = elements.next(); if (element instanceof Key) { final Key key = (Key)element; key.translate(classGen, buildKeys); _keys.put(key.getName(),key); } } il.append(RETURN); // Compute max locals + stack and add method to class buildKeys.stripAttributes(true); buildKeys.setMaxLocals(); buildKeys.setMaxStack(); buildKeys.removeNOPs(); classGen.addMethod(buildKeys.getMethod()); return("("+DOM_INTF_SIG+NODE_ITERATOR_SIG+TRANSLET_OUTPUT_SIG+"I)V"); }
Example 13
Source File: Stylesheet.java From Bytecoder with Apache License 2.0 | 4 votes |
/** * Compile the translet's constructor */ private void compileConstructor(ClassGenerator classGen, Output output) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = new InstructionList(); final MethodGenerator constructor = new MethodGenerator(ACC_PUBLIC, com.sun.org.apache.bcel.internal.generic.Type.VOID, null, null, "<init>", _className, il, cpg); // Call the constructor in the AbstractTranslet superclass il.append(classGen.loadTranslet()); il.append(new INVOKESPECIAL(cpg.addMethodref(TRANSLET_CLASS, "<init>", "()V"))); constructor.markChunkStart(); il.append(classGen.loadTranslet()); il.append(new GETSTATIC(cpg.addFieldref(_className, STATIC_NAMES_ARRAY_FIELD, NAMES_INDEX_SIG))); il.append(new PUTFIELD(cpg.addFieldref(TRANSLET_CLASS, NAMES_INDEX, NAMES_INDEX_SIG))); il.append(classGen.loadTranslet()); il.append(new GETSTATIC(cpg.addFieldref(_className, STATIC_URIS_ARRAY_FIELD, URIS_INDEX_SIG))); il.append(new PUTFIELD(cpg.addFieldref(TRANSLET_CLASS, URIS_INDEX, URIS_INDEX_SIG))); constructor.markChunkEnd(); constructor.markChunkStart(); il.append(classGen.loadTranslet()); il.append(new GETSTATIC(cpg.addFieldref(_className, STATIC_TYPES_ARRAY_FIELD, TYPES_INDEX_SIG))); il.append(new PUTFIELD(cpg.addFieldref(TRANSLET_CLASS, TYPES_INDEX, TYPES_INDEX_SIG))); constructor.markChunkEnd(); constructor.markChunkStart(); il.append(classGen.loadTranslet()); il.append(new GETSTATIC(cpg.addFieldref(_className, STATIC_NAMESPACE_ARRAY_FIELD, NAMESPACE_INDEX_SIG))); il.append(new PUTFIELD(cpg.addFieldref(TRANSLET_CLASS, NAMESPACE_INDEX, NAMESPACE_INDEX_SIG))); constructor.markChunkEnd(); constructor.markChunkStart(); il.append(classGen.loadTranslet()); il.append(new PUSH(cpg, AbstractTranslet.CURRENT_TRANSLET_VERSION)); il.append(new PUTFIELD(cpg.addFieldref(TRANSLET_CLASS, TRANSLET_VERSION_INDEX, TRANSLET_VERSION_INDEX_SIG))); constructor.markChunkEnd(); if (_hasIdCall) { constructor.markChunkStart(); il.append(classGen.loadTranslet()); il.append(new PUSH(cpg, Boolean.TRUE)); il.append(new PUTFIELD(cpg.addFieldref(TRANSLET_CLASS, HASIDCALL_INDEX, HASIDCALL_INDEX_SIG))); constructor.markChunkEnd(); } // Compile in code to set the output configuration from <xsl:output> if (output != null) { // Set all the output settings files in the translet constructor.markChunkStart(); output.translate(classGen, constructor); constructor.markChunkEnd(); } // Compile default decimal formatting symbols. // This is an implicit, nameless xsl:decimal-format top-level element. if (_numberFormattingUsed) { constructor.markChunkStart(); DecimalFormatting.translateDefaultDFS(classGen, constructor); constructor.markChunkEnd(); } il.append(RETURN); classGen.addMethod(constructor); }
Example 14
Source File: Whitespace.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
/** * 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 15
Source File: Stylesheet.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
/** * Compile the translet's constructor */ private void compileConstructor(ClassGenerator classGen, Output output) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = new InstructionList(); final MethodGenerator constructor = new MethodGenerator(ACC_PUBLIC, com.sun.org.apache.bcel.internal.generic.Type.VOID, null, null, "<init>", _className, il, cpg); // Call the constructor in the AbstractTranslet superclass il.append(classGen.loadTranslet()); il.append(new INVOKESPECIAL(cpg.addMethodref(TRANSLET_CLASS, "<init>", "()V"))); constructor.markChunkStart(); il.append(classGen.loadTranslet()); il.append(new GETSTATIC(cpg.addFieldref(_className, STATIC_NAMES_ARRAY_FIELD, NAMES_INDEX_SIG))); il.append(new PUTFIELD(cpg.addFieldref(TRANSLET_CLASS, NAMES_INDEX, NAMES_INDEX_SIG))); il.append(classGen.loadTranslet()); il.append(new GETSTATIC(cpg.addFieldref(_className, STATIC_URIS_ARRAY_FIELD, URIS_INDEX_SIG))); il.append(new PUTFIELD(cpg.addFieldref(TRANSLET_CLASS, URIS_INDEX, URIS_INDEX_SIG))); constructor.markChunkEnd(); constructor.markChunkStart(); il.append(classGen.loadTranslet()); il.append(new GETSTATIC(cpg.addFieldref(_className, STATIC_TYPES_ARRAY_FIELD, TYPES_INDEX_SIG))); il.append(new PUTFIELD(cpg.addFieldref(TRANSLET_CLASS, TYPES_INDEX, TYPES_INDEX_SIG))); constructor.markChunkEnd(); constructor.markChunkStart(); il.append(classGen.loadTranslet()); il.append(new GETSTATIC(cpg.addFieldref(_className, STATIC_NAMESPACE_ARRAY_FIELD, NAMESPACE_INDEX_SIG))); il.append(new PUTFIELD(cpg.addFieldref(TRANSLET_CLASS, NAMESPACE_INDEX, NAMESPACE_INDEX_SIG))); constructor.markChunkEnd(); constructor.markChunkStart(); il.append(classGen.loadTranslet()); il.append(new PUSH(cpg, AbstractTranslet.CURRENT_TRANSLET_VERSION)); il.append(new PUTFIELD(cpg.addFieldref(TRANSLET_CLASS, TRANSLET_VERSION_INDEX, TRANSLET_VERSION_INDEX_SIG))); constructor.markChunkEnd(); if (_hasIdCall) { constructor.markChunkStart(); il.append(classGen.loadTranslet()); il.append(new PUSH(cpg, Boolean.TRUE)); il.append(new PUTFIELD(cpg.addFieldref(TRANSLET_CLASS, HASIDCALL_INDEX, HASIDCALL_INDEX_SIG))); constructor.markChunkEnd(); } // Compile in code to set the output configuration from <xsl:output> if (output != null) { // Set all the output settings files in the translet constructor.markChunkStart(); output.translate(classGen, constructor); constructor.markChunkEnd(); } // Compile default decimal formatting symbols. // This is an implicit, nameless xsl:decimal-format top-level element. if (_numberFormattingUsed) { constructor.markChunkStart(); DecimalFormatting.translateDefaultDFS(classGen, constructor); constructor.markChunkEnd(); } il.append(RETURN); classGen.addMethod(constructor); }
Example 16
Source File: Mode.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
private void compileNamedTemplate(Template template, ClassGenerator classGen) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = new InstructionList(); String methodName = Util.escape(template.getName().toString()); int numParams = 0; if (template.isSimpleNamedTemplate()) { Vector parameters = template.getParameters(); numParams = parameters.size(); } // Initialize the types and names arrays for the NamedMethodGenerator. com.sun.org.apache.bcel.internal.generic.Type[] types = new com.sun.org.apache.bcel.internal.generic.Type[4 + numParams]; String[] names = new String[4 + numParams]; types[0] = Util.getJCRefType(DOM_INTF_SIG); types[1] = Util.getJCRefType(NODE_ITERATOR_SIG); types[2] = Util.getJCRefType(TRANSLET_OUTPUT_SIG); types[3] = com.sun.org.apache.bcel.internal.generic.Type.INT; names[0] = DOCUMENT_PNAME; names[1] = ITERATOR_PNAME; names[2] = TRANSLET_OUTPUT_PNAME; names[3] = NODE_PNAME; // For simple named templates, the signature of the generated method // is not fixed. It depends on the number of parameters declared in the // template. for (int i = 4; i < 4 + numParams; i++) { types[i] = Util.getJCRefType(OBJECT_SIG); names[i] = "param" + String.valueOf(i-4); } NamedMethodGenerator methodGen = new NamedMethodGenerator(ACC_PUBLIC, com.sun.org.apache.bcel.internal.generic.Type.VOID, types, names, methodName, getClassName(), il, cpg); il.append(template.compile(classGen, methodGen)); il.append(RETURN); classGen.addMethod(methodGen); }
Example 17
Source File: Stylesheet.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
/** * Compile a buildKeys() method into the output class. Note that keys * for the input document are created in topLevel(), not in this method. * However, we still need this method to create keys for documents loaded * via the XPath document() function. */ private String compileBuildKeys(ClassGenerator classGen) { final ConstantPoolGen cpg = classGen.getConstantPool(); final com.sun.org.apache.bcel.internal.generic.Type[] argTypes = { Util.getJCRefType(DOM_INTF_SIG), Util.getJCRefType(NODE_ITERATOR_SIG), Util.getJCRefType(TRANSLET_OUTPUT_SIG), com.sun.org.apache.bcel.internal.generic.Type.INT }; final String[] argNames = { DOCUMENT_PNAME, ITERATOR_PNAME, TRANSLET_OUTPUT_PNAME, "current" }; final InstructionList il = new InstructionList(); final MethodGenerator buildKeys = new MethodGenerator(ACC_PUBLIC, com.sun.org.apache.bcel.internal.generic.Type.VOID, argTypes, argNames, "buildKeys", _className, il, classGen.getConstantPool()); buildKeys.addException("com.sun.org.apache.xalan.internal.xsltc.TransletException"); final Iterator<SyntaxTreeNode> elements = elements(); while (elements.hasNext()) { // xsl:key final SyntaxTreeNode element = elements.next(); if (element instanceof Key) { final Key key = (Key)element; key.translate(classGen, buildKeys); _keys.put(key.getName(),key); } } il.append(RETURN); // Compute max locals + stack and add method to class buildKeys.stripAttributes(true); buildKeys.setMaxLocals(); buildKeys.setMaxStack(); buildKeys.removeNOPs(); classGen.addMethod(buildKeys.getMethod()); return("("+DOM_INTF_SIG+NODE_ITERATOR_SIG+TRANSLET_OUTPUT_SIG+"I)V"); }
Example 18
Source File: Mode.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
private void compileNamedTemplate(Template template, ClassGenerator classGen) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = new InstructionList(); String methodName = Util.escape(template.getName().toString()); int numParams = 0; if (template.isSimpleNamedTemplate()) { Vector parameters = template.getParameters(); numParams = parameters.size(); } // Initialize the types and names arrays for the NamedMethodGenerator. com.sun.org.apache.bcel.internal.generic.Type[] types = new com.sun.org.apache.bcel.internal.generic.Type[4 + numParams]; String[] names = new String[4 + numParams]; types[0] = Util.getJCRefType(DOM_INTF_SIG); types[1] = Util.getJCRefType(NODE_ITERATOR_SIG); types[2] = Util.getJCRefType(TRANSLET_OUTPUT_SIG); types[3] = com.sun.org.apache.bcel.internal.generic.Type.INT; names[0] = DOCUMENT_PNAME; names[1] = ITERATOR_PNAME; names[2] = TRANSLET_OUTPUT_PNAME; names[3] = NODE_PNAME; // For simple named templates, the signature of the generated method // is not fixed. It depends on the number of parameters declared in the // template. for (int i = 4; i < 4 + numParams; i++) { types[i] = Util.getJCRefType(OBJECT_SIG); names[i] = "param" + String.valueOf(i-4); } NamedMethodGenerator methodGen = new NamedMethodGenerator(ACC_PUBLIC, com.sun.org.apache.bcel.internal.generic.Type.VOID, types, names, methodName, getClassName(), il, cpg); il.append(template.compile(classGen, methodGen)); il.append(RETURN); classGen.addMethod(methodGen); }
Example 19
Source File: Whitespace.java From jdk1.8-source-analysis with Apache License 2.0 | 4 votes |
/** * Compiles the predicate method */ private static void compilePredicate(Vector rules, int defaultAction, ClassGenerator classGen) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = new InstructionList(); final XSLTC xsltc = classGen.getParser().getXSLTC(); // private boolean Translet.stripSpace(int type) - cannot be static final MethodGenerator stripSpace = new MethodGenerator(ACC_PUBLIC | ACC_FINAL , com.sun.org.apache.bcel.internal.generic.Type.BOOLEAN, new com.sun.org.apache.bcel.internal.generic.Type[] { Util.getJCRefType(DOM_INTF_SIG), com.sun.org.apache.bcel.internal.generic.Type.INT, com.sun.org.apache.bcel.internal.generic.Type.INT }, new String[] { "dom","node","type" }, "stripSpace",classGen.getClassName(),il,cpg); classGen.addInterface("com/sun/org/apache/xalan/internal/xsltc/StripFilter"); final int paramDom = stripSpace.getLocalIndex("dom"); final int paramCurrent = stripSpace.getLocalIndex("node"); final int paramType = stripSpace.getLocalIndex("type"); BranchHandle strip[] = new BranchHandle[rules.size()]; BranchHandle preserve[] = new BranchHandle[rules.size()]; int sCount = 0; int pCount = 0; // Traverse all strip/preserve rules for (int i = 0; i<rules.size(); i++) { // Get the next rule in the prioritised list WhitespaceRule rule = (WhitespaceRule)rules.elementAt(i); // Returns the namespace for a node in the DOM final int gns = cpg.addInterfaceMethodref(DOM_INTF, "getNamespaceName", "(I)Ljava/lang/String;"); final int strcmp = cpg.addMethodref("java/lang/String", "compareTo", "(Ljava/lang/String;)I"); // Handle elements="ns:*" type rule if (rule.getStrength() == RULE_NAMESPACE) { il.append(new ALOAD(paramDom)); il.append(new ILOAD(paramCurrent)); il.append(new INVOKEINTERFACE(gns,2)); il.append(new PUSH(cpg, rule.getNamespace())); il.append(new INVOKEVIRTUAL(strcmp)); il.append(ICONST_0); if (rule.getAction() == STRIP_SPACE) { strip[sCount++] = il.append(new IF_ICMPEQ(null)); } else { preserve[pCount++] = il.append(new IF_ICMPEQ(null)); } } // Handle elements="ns:el" type rule else if (rule.getStrength() == RULE_ELEMENT) { // Create the QName for the element final Parser parser = classGen.getParser(); QName qname; if (rule.getNamespace() != Constants.EMPTYSTRING ) qname = parser.getQName(rule.getNamespace(), null, rule.getElement()); else qname = parser.getQName(rule.getElement()); // Register the element. final int elementType = xsltc.registerElement(qname); il.append(new ILOAD(paramType)); il.append(new PUSH(cpg, elementType)); // Compare current node type with wanted element type if (rule.getAction() == STRIP_SPACE) strip[sCount++] = il.append(new IF_ICMPEQ(null)); else preserve[pCount++] = il.append(new IF_ICMPEQ(null)); } } if (defaultAction == STRIP_SPACE) { compileStripSpace(strip, sCount, il); compilePreserveSpace(preserve, pCount, il); } else { compilePreserveSpace(preserve, pCount, il); compileStripSpace(strip, sCount, il); } classGen.addMethod(stripSpace); }
Example 20
Source File: Stylesheet.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
/** * Compile a buildKeys() method into the output class. Note that keys * for the input document are created in topLevel(), not in this method. * However, we still need this method to create keys for documents loaded * via the XPath document() function. */ private String compileBuildKeys(ClassGenerator classGen) { final ConstantPoolGen cpg = classGen.getConstantPool(); final com.sun.org.apache.bcel.internal.generic.Type[] argTypes = { Util.getJCRefType(DOM_INTF_SIG), Util.getJCRefType(NODE_ITERATOR_SIG), Util.getJCRefType(TRANSLET_OUTPUT_SIG), com.sun.org.apache.bcel.internal.generic.Type.INT }; final String[] argNames = { DOCUMENT_PNAME, ITERATOR_PNAME, TRANSLET_OUTPUT_PNAME, "current" }; final InstructionList il = new InstructionList(); final MethodGenerator buildKeys = new MethodGenerator(ACC_PUBLIC, com.sun.org.apache.bcel.internal.generic.Type.VOID, argTypes, argNames, "buildKeys", _className, il, classGen.getConstantPool()); buildKeys.addException("com.sun.org.apache.xalan.internal.xsltc.TransletException"); final Enumeration elements = elements(); while (elements.hasMoreElements()) { // xsl:key final Object element = elements.nextElement(); if (element instanceof Key) { final Key key = (Key)element; key.translate(classGen, buildKeys); _keys.put(key.getName(),key); } } il.append(RETURN); // Compute max locals + stack and add method to class buildKeys.stripAttributes(true); buildKeys.setMaxLocals(); buildKeys.setMaxStack(); buildKeys.removeNOPs(); classGen.addMethod(buildKeys.getMethod()); return("("+DOM_INTF_SIG+NODE_ITERATOR_SIG+TRANSLET_OUTPUT_SIG+"I)V"); }