Java Code Examples for com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator#getLocalIndex()
The following examples show how to use
com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator#getLocalIndex() .
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 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 2
Source File: Key.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
/** * Gather all nodes that match the expression in the attribute "match" * and add one (or more) entries in this key's index. */ public void translate(ClassGenerator classGen, MethodGenerator methodGen) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); final int current = methodGen.getLocalIndex("current"); // AbstractTranslet.buildKeyIndex(name,node_id,value) => void final int key = cpg.addMethodref(TRANSLET_CLASS, "buildKeyIndex", "("+STRING_SIG+"I"+OBJECT_SIG+")V"); // AbstractTranslet.SetKeyIndexDom(name, Dom) => void final int keyDom = cpg.addMethodref(TRANSLET_CLASS, "setKeyIndexDom", "("+STRING_SIG+DOM_INTF_SIG+")V"); final int getNodeIdent = cpg.addInterfaceMethodref(DOM_INTF, "getNodeIdent", "(I)"+NODE_SIG); // DOM.getAxisIterator(root) => NodeIterator final int git = cpg.addInterfaceMethodref(DOM_INTF, "getAxisIterator", "(I)"+NODE_ITERATOR_SIG); il.append(methodGen.loadCurrentNode()); il.append(methodGen.loadIterator()); // Get an iterator for all nodes in the DOM il.append(methodGen.loadDOM()); il.append(new PUSH(cpg,Axis.DESCENDANT)); il.append(new INVOKEINTERFACE(git, 2)); // Reset the iterator to start with the root node il.append(methodGen.loadCurrentNode()); il.append(methodGen.setStartNode()); il.append(methodGen.storeIterator()); // Loop for traversing all nodes in the DOM final BranchHandle nextNode = il.append(new GOTO(null)); final InstructionHandle loop = il.append(NOP); // Check if the current node matches the pattern in "match" il.append(methodGen.loadCurrentNode()); _match.translate(classGen, methodGen); _match.synthesize(classGen, methodGen); // Leaves 0 or 1 on stack final BranchHandle skipNode = il.append(new IFEQ(null)); // If this is a node-set we must go through each node in the set if (_useType instanceof NodeSetType) { // Pass current node as parameter (we're indexing on that node) il.append(methodGen.loadCurrentNode()); traverseNodeSet(classGen, methodGen, key); } else { il.append(classGen.loadTranslet()); il.append(DUP); il.append(new PUSH(cpg, _name.toString())); il.append(DUP_X1); il.append(methodGen.loadCurrentNode()); _use.translate(classGen, methodGen); il.append(new INVOKEVIRTUAL(key)); il.append(methodGen.loadDOM()); il.append(new INVOKEVIRTUAL(keyDom)); } // Get the next node from the iterator and do loop again... final InstructionHandle skip = il.append(NOP); il.append(methodGen.loadIterator()); il.append(methodGen.nextNode()); il.append(DUP); il.append(methodGen.storeCurrentNode()); il.append(new IFGT(loop)); // Restore current node and current iterator from the stack il.append(methodGen.storeIterator()); il.append(methodGen.storeCurrentNode()); nextNode.setTarget(skip); skipNode.setTarget(skip); }
Example 3
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 4
Source File: Key.java From hottub with GNU General Public License v2.0 | 4 votes |
/** * Gather all nodes that match the expression in the attribute "match" * and add one (or more) entries in this key's index. */ public void translate(ClassGenerator classGen, MethodGenerator methodGen) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); final int current = methodGen.getLocalIndex("current"); // AbstractTranslet.buildKeyIndex(name,node_id,value) => void final int key = cpg.addMethodref(TRANSLET_CLASS, "buildKeyIndex", "("+STRING_SIG+"I"+STRING_SIG+")V"); // AbstractTranslet.SetKeyIndexDom(name, Dom) => void final int keyDom = cpg.addMethodref(TRANSLET_CLASS, "setKeyIndexDom", "("+STRING_SIG+DOM_INTF_SIG+")V"); final int getNodeIdent = cpg.addInterfaceMethodref(DOM_INTF, "getNodeIdent", "(I)"+NODE_SIG); // DOM.getAxisIterator(root) => NodeIterator final int git = cpg.addInterfaceMethodref(DOM_INTF, "getAxisIterator", "(I)"+NODE_ITERATOR_SIG); il.append(methodGen.loadCurrentNode()); il.append(methodGen.loadIterator()); // Get an iterator for all nodes in the DOM il.append(methodGen.loadDOM()); il.append(new PUSH(cpg,Axis.DESCENDANT)); il.append(new INVOKEINTERFACE(git, 2)); // Reset the iterator to start with the root node il.append(methodGen.loadCurrentNode()); il.append(methodGen.setStartNode()); il.append(methodGen.storeIterator()); // Loop for traversing all nodes in the DOM final BranchHandle nextNode = il.append(new GOTO(null)); final InstructionHandle loop = il.append(NOP); // Check if the current node matches the pattern in "match" il.append(methodGen.loadCurrentNode()); _match.translate(classGen, methodGen); _match.synthesize(classGen, methodGen); // Leaves 0 or 1 on stack final BranchHandle skipNode = il.append(new IFEQ(null)); // If this is a node-set we must go through each node in the set if (_useType instanceof NodeSetType) { // Pass current node as parameter (we're indexing on that node) il.append(methodGen.loadCurrentNode()); traverseNodeSet(classGen, methodGen, key); } else { il.append(classGen.loadTranslet()); il.append(DUP); il.append(new PUSH(cpg, _name.toString())); il.append(DUP_X1); il.append(methodGen.loadCurrentNode()); _use.translate(classGen, methodGen); il.append(new INVOKEVIRTUAL(key)); il.append(methodGen.loadDOM()); il.append(new INVOKEVIRTUAL(keyDom)); } // Get the next node from the iterator and do loop again... final InstructionHandle skip = il.append(NOP); il.append(methodGen.loadIterator()); il.append(methodGen.nextNode()); il.append(DUP); il.append(methodGen.storeCurrentNode()); il.append(new IFGT(loop)); // Restore current node and current iterator from the stack il.append(methodGen.storeIterator()); il.append(methodGen.storeCurrentNode()); nextNode.setTarget(skip); skipNode.setTarget(skip); }
Example 5
Source File: Whitespace.java From openjdk-jdk9 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: Whitespace.java From openjdk-8-source 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 7
Source File: Whitespace.java From Bytecoder with Apache License 2.0 | 4 votes |
/** * Compiles the predicate method */ private static void compilePredicate(List<WhitespaceRule> 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 = rules.get(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: Key.java From Bytecoder with Apache License 2.0 | 4 votes |
/** * Gather all nodes that match the expression in the attribute "match" * and add one (or more) entries in this key's index. */ public void translate(ClassGenerator classGen, MethodGenerator methodGen) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); final int current = methodGen.getLocalIndex("current"); // AbstractTranslet.buildKeyIndex(name,node_id,value) => void final int key = cpg.addMethodref(TRANSLET_CLASS, "buildKeyIndex", "("+STRING_SIG+"I"+STRING_SIG+")V"); // AbstractTranslet.SetKeyIndexDom(name, Dom) => void final int keyDom = cpg.addMethodref(TRANSLET_CLASS, "setKeyIndexDom", "("+STRING_SIG+DOM_INTF_SIG+")V"); final int getNodeIdent = cpg.addInterfaceMethodref(DOM_INTF, "getNodeIdent", "(I)"+NODE_SIG); // DOM.getAxisIterator(root) => NodeIterator final int git = cpg.addInterfaceMethodref(DOM_INTF, "getAxisIterator", "(I)"+NODE_ITERATOR_SIG); il.append(methodGen.loadCurrentNode()); il.append(methodGen.loadIterator()); // Get an iterator for all nodes in the DOM il.append(methodGen.loadDOM()); il.append(new PUSH(cpg,Axis.DESCENDANT)); il.append(new INVOKEINTERFACE(git, 2)); // Reset the iterator to start with the root node il.append(methodGen.loadCurrentNode()); il.append(methodGen.setStartNode()); il.append(methodGen.storeIterator()); // Loop for traversing all nodes in the DOM final BranchHandle nextNode = il.append(new GOTO(null)); final InstructionHandle loop = il.append(NOP); // Check if the current node matches the pattern in "match" il.append(methodGen.loadCurrentNode()); _match.translate(classGen, methodGen); _match.synthesize(classGen, methodGen); // Leaves 0 or 1 on stack final BranchHandle skipNode = il.append(new IFEQ(null)); // If this is a node-set we must go through each node in the set if (_useType instanceof NodeSetType) { // Pass current node as parameter (we're indexing on that node) il.append(methodGen.loadCurrentNode()); traverseNodeSet(classGen, methodGen, key); } else { il.append(classGen.loadTranslet()); il.append(DUP); il.append(new PUSH(cpg, _name.toString())); il.append(DUP_X1); il.append(methodGen.loadCurrentNode()); _use.translate(classGen, methodGen); il.append(new INVOKEVIRTUAL(key)); il.append(methodGen.loadDOM()); il.append(new INVOKEVIRTUAL(keyDom)); } // Get the next node from the iterator and do loop again... final InstructionHandle skip = il.append(NOP); il.append(methodGen.loadIterator()); il.append(methodGen.nextNode()); il.append(DUP); il.append(methodGen.storeCurrentNode()); il.append(new IFGT(loop)); // Restore current node and current iterator from the stack il.append(methodGen.storeIterator()); il.append(methodGen.storeCurrentNode()); nextNode.setTarget(skip); skipNode.setTarget(skip); }
Example 9
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 10
Source File: Key.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
/** * Gather all nodes that match the expression in the attribute "match" * and add one (or more) entries in this key's index. */ public void translate(ClassGenerator classGen, MethodGenerator methodGen) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); final int current = methodGen.getLocalIndex("current"); // AbstractTranslet.buildKeyIndex(name,node_id,value) => void final int key = cpg.addMethodref(TRANSLET_CLASS, "buildKeyIndex", "("+STRING_SIG+"I"+STRING_SIG+")V"); // AbstractTranslet.SetKeyIndexDom(name, Dom) => void final int keyDom = cpg.addMethodref(TRANSLET_CLASS, "setKeyIndexDom", "("+STRING_SIG+DOM_INTF_SIG+")V"); final int getNodeIdent = cpg.addInterfaceMethodref(DOM_INTF, "getNodeIdent", "(I)"+NODE_SIG); // DOM.getAxisIterator(root) => NodeIterator final int git = cpg.addInterfaceMethodref(DOM_INTF, "getAxisIterator", "(I)"+NODE_ITERATOR_SIG); il.append(methodGen.loadCurrentNode()); il.append(methodGen.loadIterator()); // Get an iterator for all nodes in the DOM il.append(methodGen.loadDOM()); il.append(new PUSH(cpg,Axis.DESCENDANT)); il.append(new INVOKEINTERFACE(git, 2)); // Reset the iterator to start with the root node il.append(methodGen.loadCurrentNode()); il.append(methodGen.setStartNode()); il.append(methodGen.storeIterator()); // Loop for traversing all nodes in the DOM final BranchHandle nextNode = il.append(new GOTO(null)); final InstructionHandle loop = il.append(NOP); // Check if the current node matches the pattern in "match" il.append(methodGen.loadCurrentNode()); _match.translate(classGen, methodGen); _match.synthesize(classGen, methodGen); // Leaves 0 or 1 on stack final BranchHandle skipNode = il.append(new IFEQ(null)); // If this is a node-set we must go through each node in the set if (_useType instanceof NodeSetType) { // Pass current node as parameter (we're indexing on that node) il.append(methodGen.loadCurrentNode()); traverseNodeSet(classGen, methodGen, key); } else { il.append(classGen.loadTranslet()); il.append(DUP); il.append(new PUSH(cpg, _name.toString())); il.append(DUP_X1); il.append(methodGen.loadCurrentNode()); _use.translate(classGen, methodGen); il.append(new INVOKEVIRTUAL(key)); il.append(methodGen.loadDOM()); il.append(new INVOKEVIRTUAL(keyDom)); } // Get the next node from the iterator and do loop again... final InstructionHandle skip = il.append(NOP); il.append(methodGen.loadIterator()); il.append(methodGen.nextNode()); il.append(DUP); il.append(methodGen.storeCurrentNode()); il.append(new IFGT(loop)); // Restore current node and current iterator from the stack il.append(methodGen.storeIterator()); il.append(methodGen.storeCurrentNode()); nextNode.setTarget(skip); skipNode.setTarget(skip); }
Example 11
Source File: Key.java From jdk1.8-source-analysis with Apache License 2.0 | 4 votes |
/** * Gather all nodes that match the expression in the attribute "match" * and add one (or more) entries in this key's index. */ public void translate(ClassGenerator classGen, MethodGenerator methodGen) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); final int current = methodGen.getLocalIndex("current"); // AbstractTranslet.buildKeyIndex(name,node_id,value) => void final int key = cpg.addMethodref(TRANSLET_CLASS, "buildKeyIndex", "("+STRING_SIG+"I"+STRING_SIG+")V"); // AbstractTranslet.SetKeyIndexDom(name, Dom) => void final int keyDom = cpg.addMethodref(TRANSLET_CLASS, "setKeyIndexDom", "("+STRING_SIG+DOM_INTF_SIG+")V"); final int getNodeIdent = cpg.addInterfaceMethodref(DOM_INTF, "getNodeIdent", "(I)"+NODE_SIG); // DOM.getAxisIterator(root) => NodeIterator final int git = cpg.addInterfaceMethodref(DOM_INTF, "getAxisIterator", "(I)"+NODE_ITERATOR_SIG); il.append(methodGen.loadCurrentNode()); il.append(methodGen.loadIterator()); // Get an iterator for all nodes in the DOM il.append(methodGen.loadDOM()); il.append(new PUSH(cpg,Axis.DESCENDANT)); il.append(new INVOKEINTERFACE(git, 2)); // Reset the iterator to start with the root node il.append(methodGen.loadCurrentNode()); il.append(methodGen.setStartNode()); il.append(methodGen.storeIterator()); // Loop for traversing all nodes in the DOM final BranchHandle nextNode = il.append(new GOTO(null)); final InstructionHandle loop = il.append(NOP); // Check if the current node matches the pattern in "match" il.append(methodGen.loadCurrentNode()); _match.translate(classGen, methodGen); _match.synthesize(classGen, methodGen); // Leaves 0 or 1 on stack final BranchHandle skipNode = il.append(new IFEQ(null)); // If this is a node-set we must go through each node in the set if (_useType instanceof NodeSetType) { // Pass current node as parameter (we're indexing on that node) il.append(methodGen.loadCurrentNode()); traverseNodeSet(classGen, methodGen, key); } else { il.append(classGen.loadTranslet()); il.append(DUP); il.append(new PUSH(cpg, _name.toString())); il.append(DUP_X1); il.append(methodGen.loadCurrentNode()); _use.translate(classGen, methodGen); il.append(new INVOKEVIRTUAL(key)); il.append(methodGen.loadDOM()); il.append(new INVOKEVIRTUAL(keyDom)); } // Get the next node from the iterator and do loop again... final InstructionHandle skip = il.append(NOP); il.append(methodGen.loadIterator()); il.append(methodGen.nextNode()); il.append(DUP); il.append(methodGen.storeCurrentNode()); il.append(new IFGT(loop)); // Restore current node and current iterator from the stack il.append(methodGen.storeIterator()); il.append(methodGen.storeCurrentNode()); nextNode.setTarget(skip); skipNode.setTarget(skip); }
Example 12
Source File: Key.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
/** * Gather all nodes that match the expression in the attribute "match" * and add one (or more) entries in this key's index. */ public void translate(ClassGenerator classGen, MethodGenerator methodGen) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); final int current = methodGen.getLocalIndex("current"); // AbstractTranslet.buildKeyIndex(name,node_id,value) => void final int key = cpg.addMethodref(TRANSLET_CLASS, "buildKeyIndex", "("+STRING_SIG+"I"+STRING_SIG+")V"); // AbstractTranslet.SetKeyIndexDom(name, Dom) => void final int keyDom = cpg.addMethodref(TRANSLET_CLASS, "setKeyIndexDom", "("+STRING_SIG+DOM_INTF_SIG+")V"); final int getNodeIdent = cpg.addInterfaceMethodref(DOM_INTF, "getNodeIdent", "(I)"+NODE_SIG); // DOM.getAxisIterator(root) => NodeIterator final int git = cpg.addInterfaceMethodref(DOM_INTF, "getAxisIterator", "(I)"+NODE_ITERATOR_SIG); il.append(methodGen.loadCurrentNode()); il.append(methodGen.loadIterator()); // Get an iterator for all nodes in the DOM il.append(methodGen.loadDOM()); il.append(new PUSH(cpg,Axis.DESCENDANT)); il.append(new INVOKEINTERFACE(git, 2)); // Reset the iterator to start with the root node il.append(methodGen.loadCurrentNode()); il.append(methodGen.setStartNode()); il.append(methodGen.storeIterator()); // Loop for traversing all nodes in the DOM final BranchHandle nextNode = il.append(new GOTO(null)); final InstructionHandle loop = il.append(NOP); // Check if the current node matches the pattern in "match" il.append(methodGen.loadCurrentNode()); _match.translate(classGen, methodGen); _match.synthesize(classGen, methodGen); // Leaves 0 or 1 on stack final BranchHandle skipNode = il.append(new IFEQ(null)); // If this is a node-set we must go through each node in the set if (_useType instanceof NodeSetType) { // Pass current node as parameter (we're indexing on that node) il.append(methodGen.loadCurrentNode()); traverseNodeSet(classGen, methodGen, key); } else { il.append(classGen.loadTranslet()); il.append(DUP); il.append(new PUSH(cpg, _name.toString())); il.append(DUP_X1); il.append(methodGen.loadCurrentNode()); _use.translate(classGen, methodGen); il.append(new INVOKEVIRTUAL(key)); il.append(methodGen.loadDOM()); il.append(new INVOKEVIRTUAL(keyDom)); } // Get the next node from the iterator and do loop again... final InstructionHandle skip = il.append(NOP); il.append(methodGen.loadIterator()); il.append(methodGen.nextNode()); il.append(DUP); il.append(methodGen.storeCurrentNode()); il.append(new IFGT(loop)); // Restore current node and current iterator from the stack il.append(methodGen.storeIterator()); il.append(methodGen.storeCurrentNode()); nextNode.setTarget(skip); skipNode.setTarget(skip); }
Example 13
Source File: Key.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
/** * Gather all nodes that match the expression in the attribute "match" * and add one (or more) entries in this key's index. */ public void translate(ClassGenerator classGen, MethodGenerator methodGen) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); final int current = methodGen.getLocalIndex("current"); // AbstractTranslet.buildKeyIndex(name,node_id,value) => void final int key = cpg.addMethodref(TRANSLET_CLASS, "buildKeyIndex", "("+STRING_SIG+"I"+OBJECT_SIG+")V"); // AbstractTranslet.SetKeyIndexDom(name, Dom) => void final int keyDom = cpg.addMethodref(TRANSLET_CLASS, "setKeyIndexDom", "("+STRING_SIG+DOM_INTF_SIG+")V"); final int getNodeIdent = cpg.addInterfaceMethodref(DOM_INTF, "getNodeIdent", "(I)"+NODE_SIG); // DOM.getAxisIterator(root) => NodeIterator final int git = cpg.addInterfaceMethodref(DOM_INTF, "getAxisIterator", "(I)"+NODE_ITERATOR_SIG); il.append(methodGen.loadCurrentNode()); il.append(methodGen.loadIterator()); // Get an iterator for all nodes in the DOM il.append(methodGen.loadDOM()); il.append(new PUSH(cpg,Axis.DESCENDANT)); il.append(new INVOKEINTERFACE(git, 2)); // Reset the iterator to start with the root node il.append(methodGen.loadCurrentNode()); il.append(methodGen.setStartNode()); il.append(methodGen.storeIterator()); // Loop for traversing all nodes in the DOM final BranchHandle nextNode = il.append(new GOTO(null)); final InstructionHandle loop = il.append(NOP); // Check if the current node matches the pattern in "match" il.append(methodGen.loadCurrentNode()); _match.translate(classGen, methodGen); _match.synthesize(classGen, methodGen); // Leaves 0 or 1 on stack final BranchHandle skipNode = il.append(new IFEQ(null)); // If this is a node-set we must go through each node in the set if (_useType instanceof NodeSetType) { // Pass current node as parameter (we're indexing on that node) il.append(methodGen.loadCurrentNode()); traverseNodeSet(classGen, methodGen, key); } else { il.append(classGen.loadTranslet()); il.append(DUP); il.append(new PUSH(cpg, _name.toString())); il.append(DUP_X1); il.append(methodGen.loadCurrentNode()); _use.translate(classGen, methodGen); il.append(new INVOKEVIRTUAL(key)); il.append(methodGen.loadDOM()); il.append(new INVOKEVIRTUAL(keyDom)); } // Get the next node from the iterator and do loop again... final InstructionHandle skip = il.append(NOP); il.append(methodGen.loadIterator()); il.append(methodGen.nextNode()); il.append(DUP); il.append(methodGen.storeCurrentNode()); il.append(new IFGT(loop)); // Restore current node and current iterator from the stack il.append(methodGen.storeIterator()); il.append(methodGen.storeCurrentNode()); nextNode.setTarget(skip); skipNode.setTarget(skip); }
Example 14
Source File: Key.java From JDKSourceCode1.8 with MIT License | 4 votes |
/** * Gather all nodes that match the expression in the attribute "match" * and add one (or more) entries in this key's index. */ public void translate(ClassGenerator classGen, MethodGenerator methodGen) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); final int current = methodGen.getLocalIndex("current"); // AbstractTranslet.buildKeyIndex(name,node_id,value) => void final int key = cpg.addMethodref(TRANSLET_CLASS, "buildKeyIndex", "("+STRING_SIG+"I"+STRING_SIG+")V"); // AbstractTranslet.SetKeyIndexDom(name, Dom) => void final int keyDom = cpg.addMethodref(TRANSLET_CLASS, "setKeyIndexDom", "("+STRING_SIG+DOM_INTF_SIG+")V"); final int getNodeIdent = cpg.addInterfaceMethodref(DOM_INTF, "getNodeIdent", "(I)"+NODE_SIG); // DOM.getAxisIterator(root) => NodeIterator final int git = cpg.addInterfaceMethodref(DOM_INTF, "getAxisIterator", "(I)"+NODE_ITERATOR_SIG); il.append(methodGen.loadCurrentNode()); il.append(methodGen.loadIterator()); // Get an iterator for all nodes in the DOM il.append(methodGen.loadDOM()); il.append(new PUSH(cpg,Axis.DESCENDANT)); il.append(new INVOKEINTERFACE(git, 2)); // Reset the iterator to start with the root node il.append(methodGen.loadCurrentNode()); il.append(methodGen.setStartNode()); il.append(methodGen.storeIterator()); // Loop for traversing all nodes in the DOM final BranchHandle nextNode = il.append(new GOTO(null)); final InstructionHandle loop = il.append(NOP); // Check if the current node matches the pattern in "match" il.append(methodGen.loadCurrentNode()); _match.translate(classGen, methodGen); _match.synthesize(classGen, methodGen); // Leaves 0 or 1 on stack final BranchHandle skipNode = il.append(new IFEQ(null)); // If this is a node-set we must go through each node in the set if (_useType instanceof NodeSetType) { // Pass current node as parameter (we're indexing on that node) il.append(methodGen.loadCurrentNode()); traverseNodeSet(classGen, methodGen, key); } else { il.append(classGen.loadTranslet()); il.append(DUP); il.append(new PUSH(cpg, _name.toString())); il.append(DUP_X1); il.append(methodGen.loadCurrentNode()); _use.translate(classGen, methodGen); il.append(new INVOKEVIRTUAL(key)); il.append(methodGen.loadDOM()); il.append(new INVOKEVIRTUAL(keyDom)); } // Get the next node from the iterator and do loop again... final InstructionHandle skip = il.append(NOP); il.append(methodGen.loadIterator()); il.append(methodGen.nextNode()); il.append(DUP); il.append(methodGen.storeCurrentNode()); il.append(new IFGT(loop)); // Restore current node and current iterator from the stack il.append(methodGen.storeIterator()); il.append(methodGen.storeCurrentNode()); nextNode.setTarget(skip); skipNode.setTarget(skip); }
Example 15
Source File: ApplyTemplates.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * Translate call-template. A parameter frame is pushed only if * some template in the stylesheet uses parameters. */ public void translate(ClassGenerator classGen, MethodGenerator methodGen) { boolean setStartNodeCalled = false; final Stylesheet stylesheet = classGen.getStylesheet(); final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); final int current = methodGen.getLocalIndex("current"); // check if sorting nodes is required final Vector sortObjects = new Vector(); final Enumeration children = elements(); while (children.hasMoreElements()) { final Object child = children.nextElement(); if (child instanceof Sort) { sortObjects.addElement(child); } } // Push a new parameter frame if (stylesheet.hasLocalParams() || hasContents()) { il.append(classGen.loadTranslet()); final int pushFrame = cpg.addMethodref(TRANSLET_CLASS, PUSH_PARAM_FRAME, PUSH_PARAM_FRAME_SIG); il.append(new INVOKEVIRTUAL(pushFrame)); // translate with-params translateContents(classGen, methodGen); } il.append(classGen.loadTranslet()); // The 'select' expression is a result-tree if ((_type != null) && (_type instanceof ResultTreeType)) { // <xsl:sort> cannot be applied to a result tree - issue warning if (sortObjects.size() > 0) { ErrorMsg err = new ErrorMsg(ErrorMsg.RESULT_TREE_SORT_ERR,this); getParser().reportError(WARNING, err); } // Put the result tree (a DOM adapter) on the stack _select.translate(classGen, methodGen); // Get back the DOM and iterator (not just iterator!!!) _type.translateTo(classGen, methodGen, Type.NodeSet); } else { il.append(methodGen.loadDOM()); // compute node iterator for applyTemplates if (sortObjects.size() > 0) { Sort.translateSortIterator(classGen, methodGen, _select, sortObjects); int setStartNode = cpg.addInterfaceMethodref(NODE_ITERATOR, SET_START_NODE, "(I)"+ NODE_ITERATOR_SIG); il.append(methodGen.loadCurrentNode()); il.append(new INVOKEINTERFACE(setStartNode,2)); setStartNodeCalled = true; } else { if (_select == null) Mode.compileGetChildren(classGen, methodGen, current); else _select.translate(classGen, methodGen); } } if (_select != null && !setStartNodeCalled) { _select.startIterator(classGen, methodGen); } //!!! need to instantiate all needed modes final String className = classGen.getStylesheet().getClassName(); il.append(methodGen.loadHandler()); final String applyTemplatesSig = classGen.getApplyTemplatesSig(); final int applyTemplates = cpg.addMethodref(className, _functionName, applyTemplatesSig); il.append(new INVOKEVIRTUAL(applyTemplates)); // Pop parameter frame if (stylesheet.hasLocalParams() || hasContents()) { il.append(classGen.loadTranslet()); final int popFrame = cpg.addMethodref(TRANSLET_CLASS, POP_PARAM_FRAME, POP_PARAM_FRAME_SIG); il.append(new INVOKEVIRTUAL(popFrame)); } }
Example 16
Source File: ApplyTemplates.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
/** * Translate call-template. A parameter frame is pushed only if * some template in the stylesheet uses parameters. */ public void translate(ClassGenerator classGen, MethodGenerator methodGen) { boolean setStartNodeCalled = false; final Stylesheet stylesheet = classGen.getStylesheet(); final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); final int current = methodGen.getLocalIndex("current"); // check if sorting nodes is required final Vector sortObjects = new Vector(); final Enumeration children = elements(); while (children.hasMoreElements()) { final Object child = children.nextElement(); if (child instanceof Sort) { sortObjects.addElement(child); } } // Push a new parameter frame if (stylesheet.hasLocalParams() || hasContents()) { il.append(classGen.loadTranslet()); final int pushFrame = cpg.addMethodref(TRANSLET_CLASS, PUSH_PARAM_FRAME, PUSH_PARAM_FRAME_SIG); il.append(new INVOKEVIRTUAL(pushFrame)); // translate with-params translateContents(classGen, methodGen); } il.append(classGen.loadTranslet()); // The 'select' expression is a result-tree if ((_type != null) && (_type instanceof ResultTreeType)) { // <xsl:sort> cannot be applied to a result tree - issue warning if (sortObjects.size() > 0) { ErrorMsg err = new ErrorMsg(ErrorMsg.RESULT_TREE_SORT_ERR,this); getParser().reportError(WARNING, err); } // Put the result tree (a DOM adapter) on the stack _select.translate(classGen, methodGen); // Get back the DOM and iterator (not just iterator!!!) _type.translateTo(classGen, methodGen, Type.NodeSet); } else { il.append(methodGen.loadDOM()); // compute node iterator for applyTemplates if (sortObjects.size() > 0) { Sort.translateSortIterator(classGen, methodGen, _select, sortObjects); int setStartNode = cpg.addInterfaceMethodref(NODE_ITERATOR, SET_START_NODE, "(I)"+ NODE_ITERATOR_SIG); il.append(methodGen.loadCurrentNode()); il.append(new INVOKEINTERFACE(setStartNode,2)); setStartNodeCalled = true; } else { if (_select == null) Mode.compileGetChildren(classGen, methodGen, current); else _select.translate(classGen, methodGen); } } if (_select != null && !setStartNodeCalled) { _select.startIterator(classGen, methodGen); } //!!! need to instantiate all needed modes final String className = classGen.getStylesheet().getClassName(); il.append(methodGen.loadHandler()); final String applyTemplatesSig = classGen.getApplyTemplatesSig(); final int applyTemplates = cpg.addMethodref(className, _functionName, applyTemplatesSig); il.append(new INVOKEVIRTUAL(applyTemplates)); // Pop parameter frame if (stylesheet.hasLocalParams() || hasContents()) { il.append(classGen.loadTranslet()); final int popFrame = cpg.addMethodref(TRANSLET_CLASS, POP_PARAM_FRAME, POP_PARAM_FRAME_SIG); il.append(new INVOKEVIRTUAL(popFrame)); } }
Example 17
Source File: Key.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * Gather all nodes that match the expression in the attribute "match" * and add one (or more) entries in this key's index. */ public void translate(ClassGenerator classGen, MethodGenerator methodGen) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); final int current = methodGen.getLocalIndex("current"); // AbstractTranslet.buildKeyIndex(name,node_id,value) => void final int key = cpg.addMethodref(TRANSLET_CLASS, "buildKeyIndex", "("+STRING_SIG+"I"+OBJECT_SIG+")V"); // AbstractTranslet.SetKeyIndexDom(name, Dom) => void final int keyDom = cpg.addMethodref(TRANSLET_CLASS, "setKeyIndexDom", "("+STRING_SIG+DOM_INTF_SIG+")V"); final int getNodeIdent = cpg.addInterfaceMethodref(DOM_INTF, "getNodeIdent", "(I)"+NODE_SIG); // DOM.getAxisIterator(root) => NodeIterator final int git = cpg.addInterfaceMethodref(DOM_INTF, "getAxisIterator", "(I)"+NODE_ITERATOR_SIG); il.append(methodGen.loadCurrentNode()); il.append(methodGen.loadIterator()); // Get an iterator for all nodes in the DOM il.append(methodGen.loadDOM()); il.append(new PUSH(cpg,Axis.DESCENDANT)); il.append(new INVOKEINTERFACE(git, 2)); // Reset the iterator to start with the root node il.append(methodGen.loadCurrentNode()); il.append(methodGen.setStartNode()); il.append(methodGen.storeIterator()); // Loop for traversing all nodes in the DOM final BranchHandle nextNode = il.append(new GOTO(null)); final InstructionHandle loop = il.append(NOP); // Check if the current node matches the pattern in "match" il.append(methodGen.loadCurrentNode()); _match.translate(classGen, methodGen); _match.synthesize(classGen, methodGen); // Leaves 0 or 1 on stack final BranchHandle skipNode = il.append(new IFEQ(null)); // If this is a node-set we must go through each node in the set if (_useType instanceof NodeSetType) { // Pass current node as parameter (we're indexing on that node) il.append(methodGen.loadCurrentNode()); traverseNodeSet(classGen, methodGen, key); } else { il.append(classGen.loadTranslet()); il.append(DUP); il.append(new PUSH(cpg, _name.toString())); il.append(DUP_X1); il.append(methodGen.loadCurrentNode()); _use.translate(classGen, methodGen); il.append(new INVOKEVIRTUAL(key)); il.append(methodGen.loadDOM()); il.append(new INVOKEVIRTUAL(keyDom)); } // Get the next node from the iterator and do loop again... final InstructionHandle skip = il.append(NOP); il.append(methodGen.loadIterator()); il.append(methodGen.nextNode()); il.append(DUP); il.append(methodGen.storeCurrentNode()); il.append(new IFGT(loop)); // Restore current node and current iterator from the stack il.append(methodGen.storeIterator()); il.append(methodGen.storeCurrentNode()); nextNode.setTarget(skip); skipNode.setTarget(skip); }
Example 18
Source File: Whitespace.java From TencentKona-8 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 19
Source File: Whitespace.java From openjdk-8 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 20
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); }