Java Code Examples for com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator#getStylesheet()
The following examples show how to use
com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator#getStylesheet() .
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: CallTemplate.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
public void translate(ClassGenerator classGen, MethodGenerator methodGen) { final Stylesheet stylesheet = classGen.getStylesheet(); final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); // If there are Params in the stylesheet or WithParams in this call? if (stylesheet.hasLocalParams() || hasContents()) { _calleeTemplate = getCalleeTemplate(); // Build the parameter list if the called template is simple named if (_calleeTemplate != null) { buildParameterList(); } // This is only needed when the called template is not // a simple named template. else { // Push parameter frame final int push = cpg.addMethodref(TRANSLET_CLASS, PUSH_PARAM_FRAME, PUSH_PARAM_FRAME_SIG); il.append(classGen.loadTranslet()); il.append(new INVOKEVIRTUAL(push)); translateContents(classGen, methodGen); } } // Generate a valid Java method name final String className = stylesheet.getClassName(); String methodName = Util.escape(_name.toString()); // Load standard arguments il.append(classGen.loadTranslet()); il.append(methodGen.loadDOM()); il.append(methodGen.loadIterator()); il.append(methodGen.loadHandler()); il.append(methodGen.loadCurrentNode()); // Initialize prefix of method signature StringBuffer methodSig = new StringBuffer("(" + DOM_INTF_SIG + NODE_ITERATOR_SIG + TRANSLET_OUTPUT_SIG + NODE_SIG); // If calling a simply named template, push actual arguments if (_calleeTemplate != null) { int numParams = _parameters.length; for (int i = 0; i < numParams; i++) { SyntaxTreeNode node = _parameters[i]; methodSig.append(OBJECT_SIG); // append Object to signature // Push 'null' if Param to indicate no actual parameter specified if (node instanceof Param) { il.append(ACONST_NULL); } else { // translate WithParam node.translate(classGen, methodGen); } } } // Complete signature and generate invokevirtual call methodSig.append(")V"); il.append(new INVOKEVIRTUAL(cpg.addMethodref(className, methodName, methodSig.toString()))); // release temporary result trees if (_parameters != null) { for (int i = 0; i < _parameters.length; i++) { if (_parameters[i] instanceof WithParam) { ((WithParam)_parameters[i]).releaseResultTree(classGen, methodGen); } } } // Do not need to call Translet.popParamFrame() if we are // calling a simple named template. if (_calleeTemplate == null && (stylesheet.hasLocalParams() || hasContents())) { // Pop parameter frame final int pop = cpg.addMethodref(TRANSLET_CLASS, POP_PARAM_FRAME, POP_PARAM_FRAME_SIG); il.append(classGen.loadTranslet()); il.append(new INVOKEVIRTUAL(pop)); } }
Example 2
Source File: Sort.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
/** * Create a new auxillary class extending NodeSortRecord. */ private static String compileSortRecord(Vector sortObjects, ClassGenerator classGen, MethodGenerator methodGen) { final XSLTC xsltc = ((Sort)sortObjects.firstElement()).getXSLTC(); final String className = xsltc.getHelperClassName(); // This generates a new class for handling this specific sort final NodeSortRecordGenerator sortRecord = new NodeSortRecordGenerator(className, NODE_SORT_RECORD, "sort$0.java", ACC_PUBLIC | ACC_SUPER | ACC_FINAL, new String[] {}, classGen.getStylesheet()); final ConstantPoolGen cpg = sortRecord.getConstantPool(); // Add a new instance variable for each var in closure final int nsorts = sortObjects.size(); final ArrayList dups = new ArrayList(); for (int j = 0; j < nsorts; j++) { final Sort sort = (Sort) sortObjects.get(j); // Set the name of the inner class in this sort object sort.setInnerClassName(className); final int length = (sort._closureVars == null) ? 0 : sort._closureVars.size(); for (int i = 0; i < length; i++) { final VariableRefBase varRef = (VariableRefBase) sort._closureVars.get(i); // Discard duplicate variable references if (dups.contains(varRef)) continue; final VariableBase var = varRef.getVariable(); sortRecord.addField(new Field(ACC_PUBLIC, cpg.addUtf8(var.getEscapedName()), cpg.addUtf8(var.getType().toSignature()), null, cpg.getConstantPool())); dups.add(varRef); } } MethodGenerator init = compileInit(sortObjects, sortRecord, cpg, className); MethodGenerator extract = compileExtract(sortObjects, sortRecord, cpg, className); sortRecord.addMethod(init); sortRecord.addMethod(extract); xsltc.dumpClass(sortRecord.getJavaClass()); return className; }
Example 3
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 4
Source File: Sort.java From hottub with GNU General Public License v2.0 | 4 votes |
/** * Create a new auxillary class extending NodeSortRecord. */ private static String compileSortRecord(Vector<Sort> sortObjects, ClassGenerator classGen, MethodGenerator methodGen) { final XSLTC xsltc = sortObjects.firstElement().getXSLTC(); final String className = xsltc.getHelperClassName(); // This generates a new class for handling this specific sort final NodeSortRecordGenerator sortRecord = new NodeSortRecordGenerator(className, NODE_SORT_RECORD, "sort$0.java", ACC_PUBLIC | ACC_SUPER | ACC_FINAL, new String[] {}, classGen.getStylesheet()); final ConstantPoolGen cpg = sortRecord.getConstantPool(); // Add a new instance variable for each var in closure final int nsorts = sortObjects.size(); final ArrayList<VariableRefBase> dups = new ArrayList<>(); for (int j = 0; j < nsorts; j++) { final Sort sort = sortObjects.get(j); // Set the name of the inner class in this sort object sort.setInnerClassName(className); final int length = (sort._closureVars == null) ? 0 : sort._closureVars.size(); for (int i = 0; i < length; i++) { final VariableRefBase varRef = (VariableRefBase) sort._closureVars.get(i); // Discard duplicate variable references if (dups.contains(varRef)) continue; final VariableBase var = varRef.getVariable(); sortRecord.addField(new Field(ACC_PUBLIC, cpg.addUtf8(var.getEscapedName()), cpg.addUtf8(var.getType().toSignature()), null, cpg.getConstantPool())); dups.add(varRef); } } MethodGenerator init = compileInit(sortRecord, cpg, className); MethodGenerator extract = compileExtract(sortObjects, sortRecord, cpg, className); sortRecord.addMethod(init); sortRecord.addMethod(extract); xsltc.dumpClass(sortRecord.getJavaClass()); return className; }
Example 5
Source File: CallTemplate.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public void translate(ClassGenerator classGen, MethodGenerator methodGen) { final Stylesheet stylesheet = classGen.getStylesheet(); final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); // If there are Params in the stylesheet or WithParams in this call? if (stylesheet.hasLocalParams() || hasContents()) { _calleeTemplate = getCalleeTemplate(); // Build the parameter list if the called template is simple named if (_calleeTemplate != null) { buildParameterList(); } // This is only needed when the called template is not // a simple named template. else { // Push parameter frame final int push = cpg.addMethodref(TRANSLET_CLASS, PUSH_PARAM_FRAME, PUSH_PARAM_FRAME_SIG); il.append(classGen.loadTranslet()); il.append(new INVOKEVIRTUAL(push)); translateContents(classGen, methodGen); } } // Generate a valid Java method name final String className = stylesheet.getClassName(); String methodName = Util.escape(_name.toString()); // Load standard arguments il.append(classGen.loadTranslet()); il.append(methodGen.loadDOM()); il.append(methodGen.loadIterator()); il.append(methodGen.loadHandler()); il.append(methodGen.loadCurrentNode()); // Initialize prefix of method signature StringBuffer methodSig = new StringBuffer("(" + DOM_INTF_SIG + NODE_ITERATOR_SIG + TRANSLET_OUTPUT_SIG + NODE_SIG); // If calling a simply named template, push actual arguments if (_calleeTemplate != null) { int numParams = _parameters.length; for (int i = 0; i < numParams; i++) { SyntaxTreeNode node = _parameters[i]; methodSig.append(OBJECT_SIG); // append Object to signature // Push 'null' if Param to indicate no actual parameter specified if (node instanceof Param) { il.append(ACONST_NULL); } else { // translate WithParam node.translate(classGen, methodGen); } } } // Complete signature and generate invokevirtual call methodSig.append(")V"); il.append(new INVOKEVIRTUAL(cpg.addMethodref(className, methodName, methodSig.toString()))); // release temporary result trees if (_parameters != null) { for (int i = 0; i < _parameters.length; i++) { if (_parameters[i] instanceof WithParam) { ((WithParam)_parameters[i]).releaseResultTree(classGen, methodGen); } } } // Do not need to call Translet.popParamFrame() if we are // calling a simple named template. if (_calleeTemplate == null && (stylesheet.hasLocalParams() || hasContents())) { // Pop parameter frame final int pop = cpg.addMethodref(TRANSLET_CLASS, POP_PARAM_FRAME, POP_PARAM_FRAME_SIG); il.append(classGen.loadTranslet()); il.append(new INVOKEVIRTUAL(pop)); } }
Example 6
Source File: Sort.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * Create a new auxillary class extending NodeSortRecord. */ private static String compileSortRecord(Vector<Sort> sortObjects, ClassGenerator classGen, MethodGenerator methodGen) { final XSLTC xsltc = sortObjects.firstElement().getXSLTC(); final String className = xsltc.getHelperClassName(); // This generates a new class for handling this specific sort final NodeSortRecordGenerator sortRecord = new NodeSortRecordGenerator(className, NODE_SORT_RECORD, "sort$0.java", ACC_PUBLIC | ACC_SUPER | ACC_FINAL, new String[] {}, classGen.getStylesheet()); final ConstantPoolGen cpg = sortRecord.getConstantPool(); // Add a new instance variable for each var in closure final int nsorts = sortObjects.size(); final ArrayList<VariableRefBase> dups = new ArrayList<>(); for (int j = 0; j < nsorts; j++) { final Sort sort = sortObjects.get(j); // Set the name of the inner class in this sort object sort.setInnerClassName(className); final int length = (sort._closureVars == null) ? 0 : sort._closureVars.size(); for (int i = 0; i < length; i++) { final VariableRefBase varRef = (VariableRefBase) sort._closureVars.get(i); // Discard duplicate variable references if (dups.contains(varRef)) continue; final VariableBase var = varRef.getVariable(); sortRecord.addField(new Field(ACC_PUBLIC, cpg.addUtf8(var.getEscapedName()), cpg.addUtf8(var.getType().toSignature()), null, cpg.getConstantPool())); dups.add(varRef); } } MethodGenerator init = compileInit(sortRecord, cpg, className); MethodGenerator extract = compileExtract(sortObjects, sortRecord, cpg, className); sortRecord.addMethod(init); sortRecord.addMethod(extract); xsltc.dumpClass(sortRecord.getJavaClass()); return className; }
Example 7
Source File: CallTemplate.java From Bytecoder with Apache License 2.0 | 4 votes |
public void translate(ClassGenerator classGen, MethodGenerator methodGen) { final Stylesheet stylesheet = classGen.getStylesheet(); final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); // If there are Params in the stylesheet or WithParams in this call? if (stylesheet.hasLocalParams() || hasContents()) { _calleeTemplate = getCalleeTemplate(); // Build the parameter list if the called template is simple named if (_calleeTemplate != null) { buildParameterList(); } // This is only needed when the called template is not // a simple named template. else { // Push parameter frame final int push = cpg.addMethodref(TRANSLET_CLASS, PUSH_PARAM_FRAME, PUSH_PARAM_FRAME_SIG); il.append(classGen.loadTranslet()); il.append(new INVOKEVIRTUAL(push)); translateContents(classGen, methodGen); } } // Generate a valid Java method name final String className = stylesheet.getClassName(); String methodName = Util.escape(_name.toString()); // Load standard arguments il.append(classGen.loadTranslet()); il.append(methodGen.loadDOM()); il.append(methodGen.loadIterator()); il.append(methodGen.loadHandler()); il.append(methodGen.loadCurrentNode()); // Initialize prefix of method signature StringBuffer methodSig = new StringBuffer("(" + DOM_INTF_SIG + NODE_ITERATOR_SIG + TRANSLET_OUTPUT_SIG + NODE_SIG); // If calling a simply named template, push actual arguments if (_calleeTemplate != null) { int numParams = _parameters.length; for (int i = 0; i < numParams; i++) { SyntaxTreeNode node = _parameters[i]; methodSig.append(OBJECT_SIG); // append Object to signature // Push 'null' if Param to indicate no actual parameter specified if (node instanceof Param) { il.append(ACONST_NULL); } else { // translate WithParam node.translate(classGen, methodGen); } } } // Complete signature and generate invokevirtual call methodSig.append(")V"); il.append(new INVOKEVIRTUAL(cpg.addMethodref(className, methodName, methodSig.toString()))); // release temporary result trees if (_parameters != null) { for (int i = 0; i < _parameters.length; i++) { if (_parameters[i] instanceof WithParam) { ((WithParam)_parameters[i]).releaseResultTree(classGen, methodGen); } } } // Do not need to call Translet.popParamFrame() if we are // calling a simple named template. if (_calleeTemplate == null && (stylesheet.hasLocalParams() || hasContents())) { // Pop parameter frame final int pop = cpg.addMethodref(TRANSLET_CLASS, POP_PARAM_FRAME, POP_PARAM_FRAME_SIG); il.append(classGen.loadTranslet()); il.append(new INVOKEVIRTUAL(pop)); } }
Example 8
Source File: Sort.java From Bytecoder with Apache License 2.0 | 4 votes |
/** * Create a new auxillary class extending NodeSortRecord. */ private static String compileSortRecord(List<Sort> sortObjects, ClassGenerator classGen, MethodGenerator methodGen) { final XSLTC xsltc = sortObjects.get(0).getXSLTC(); final String className = xsltc.getHelperClassName(); // This generates a new class for handling this specific sort final NodeSortRecordGenerator sortRecord = new NodeSortRecordGenerator(className, NODE_SORT_RECORD, "sort$0.java", ACC_PUBLIC | ACC_SUPER | ACC_FINAL, new String[] {}, classGen.getStylesheet()); final ConstantPoolGen cpg = sortRecord.getConstantPool(); // Add a new instance variable for each var in closure final int nsorts = sortObjects.size(); final List<VariableRefBase> dups = new ArrayList<>(); for (int j = 0; j < nsorts; j++) { final Sort sort = sortObjects.get(j); // Set the name of the inner class in this sort object sort.setInnerClassName(className); final int length = (sort._closureVars == null) ? 0 : sort._closureVars.size(); for (int i = 0; i < length; i++) { final VariableRefBase varRef = sort._closureVars.get(i); // Discard duplicate variable references if (dups.contains(varRef)) continue; final VariableBase var = varRef.getVariable(); sortRecord.addField(new Field(ACC_PUBLIC, cpg.addUtf8(var.getEscapedName()), cpg.addUtf8(var.getType().toSignature()), null, cpg.getConstantPool())); dups.add(varRef); } } MethodGenerator init = compileInit(sortRecord, cpg, className); MethodGenerator extract = compileExtract(sortObjects, sortRecord, cpg, className); sortRecord.addMethod(init); sortRecord.addMethod(extract); xsltc.dumpClass(sortRecord.getJavaClass()); return className; }
Example 9
Source File: CallTemplate.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
public void translate(ClassGenerator classGen, MethodGenerator methodGen) { final Stylesheet stylesheet = classGen.getStylesheet(); final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); // If there are Params in the stylesheet or WithParams in this call? if (stylesheet.hasLocalParams() || hasContents()) { _calleeTemplate = getCalleeTemplate(); // Build the parameter list if the called template is simple named if (_calleeTemplate != null) { buildParameterList(); } // This is only needed when the called template is not // a simple named template. else { // Push parameter frame final int push = cpg.addMethodref(TRANSLET_CLASS, PUSH_PARAM_FRAME, PUSH_PARAM_FRAME_SIG); il.append(classGen.loadTranslet()); il.append(new INVOKEVIRTUAL(push)); translateContents(classGen, methodGen); } } // Generate a valid Java method name final String className = stylesheet.getClassName(); String methodName = Util.escape(_name.toString()); // Load standard arguments il.append(classGen.loadTranslet()); il.append(methodGen.loadDOM()); il.append(methodGen.loadIterator()); il.append(methodGen.loadHandler()); il.append(methodGen.loadCurrentNode()); // Initialize prefix of method signature StringBuffer methodSig = new StringBuffer("(" + DOM_INTF_SIG + NODE_ITERATOR_SIG + TRANSLET_OUTPUT_SIG + NODE_SIG); // If calling a simply named template, push actual arguments if (_calleeTemplate != null) { int numParams = _parameters.length; for (int i = 0; i < numParams; i++) { SyntaxTreeNode node = _parameters[i]; methodSig.append(OBJECT_SIG); // append Object to signature // Push 'null' if Param to indicate no actual parameter specified if (node instanceof Param) { il.append(ACONST_NULL); } else { // translate WithParam node.translate(classGen, methodGen); } } } // Complete signature and generate invokevirtual call methodSig.append(")V"); il.append(new INVOKEVIRTUAL(cpg.addMethodref(className, methodName, methodSig.toString()))); // release temporary result trees if (_parameters != null) { for (int i = 0; i < _parameters.length; i++) { if (_parameters[i] instanceof WithParam) { ((WithParam)_parameters[i]).releaseResultTree(classGen, methodGen); } } } // Do not need to call Translet.popParamFrame() if we are // calling a simple named template. if (_calleeTemplate == null && (stylesheet.hasLocalParams() || hasContents())) { // Pop parameter frame final int pop = cpg.addMethodref(TRANSLET_CLASS, POP_PARAM_FRAME, POP_PARAM_FRAME_SIG); il.append(classGen.loadTranslet()); il.append(new INVOKEVIRTUAL(pop)); } }
Example 10
Source File: Sort.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
/** * Create a new auxillary class extending NodeSortRecord. */ private static String compileSortRecord(Vector<Sort> sortObjects, ClassGenerator classGen, MethodGenerator methodGen) { final XSLTC xsltc = sortObjects.firstElement().getXSLTC(); final String className = xsltc.getHelperClassName(); // This generates a new class for handling this specific sort final NodeSortRecordGenerator sortRecord = new NodeSortRecordGenerator(className, NODE_SORT_RECORD, "sort$0.java", ACC_PUBLIC | ACC_SUPER | ACC_FINAL, new String[] {}, classGen.getStylesheet()); final ConstantPoolGen cpg = sortRecord.getConstantPool(); // Add a new instance variable for each var in closure final int nsorts = sortObjects.size(); final ArrayList<VariableRefBase> dups = new ArrayList<>(); for (int j = 0; j < nsorts; j++) { final Sort sort = sortObjects.get(j); // Set the name of the inner class in this sort object sort.setInnerClassName(className); final int length = (sort._closureVars == null) ? 0 : sort._closureVars.size(); for (int i = 0; i < length; i++) { final VariableRefBase varRef = (VariableRefBase) sort._closureVars.get(i); // Discard duplicate variable references if (dups.contains(varRef)) continue; final VariableBase var = varRef.getVariable(); sortRecord.addField(new Field(ACC_PUBLIC, cpg.addUtf8(var.getEscapedName()), cpg.addUtf8(var.getType().toSignature()), null, cpg.getConstantPool())); dups.add(varRef); } } MethodGenerator init = compileInit(sortRecord, cpg, className); MethodGenerator extract = compileExtract(sortObjects, sortRecord, cpg, className); sortRecord.addMethod(init); sortRecord.addMethod(extract); xsltc.dumpClass(sortRecord.getJavaClass()); return className; }
Example 11
Source File: CallTemplate.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
public void translate(ClassGenerator classGen, MethodGenerator methodGen) { final Stylesheet stylesheet = classGen.getStylesheet(); final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); // If there are Params in the stylesheet or WithParams in this call? if (stylesheet.hasLocalParams() || hasContents()) { _calleeTemplate = getCalleeTemplate(); // Build the parameter list if the called template is simple named if (_calleeTemplate != null) { buildParameterList(); } // This is only needed when the called template is not // a simple named template. else { // Push parameter frame final int push = cpg.addMethodref(TRANSLET_CLASS, PUSH_PARAM_FRAME, PUSH_PARAM_FRAME_SIG); il.append(classGen.loadTranslet()); il.append(new INVOKEVIRTUAL(push)); translateContents(classGen, methodGen); } } // Generate a valid Java method name final String className = stylesheet.getClassName(); String methodName = Util.escape(_name.toString()); // Load standard arguments il.append(classGen.loadTranslet()); il.append(methodGen.loadDOM()); il.append(methodGen.loadIterator()); il.append(methodGen.loadHandler()); il.append(methodGen.loadCurrentNode()); // Initialize prefix of method signature StringBuffer methodSig = new StringBuffer("(" + DOM_INTF_SIG + NODE_ITERATOR_SIG + TRANSLET_OUTPUT_SIG + NODE_SIG); // If calling a simply named template, push actual arguments if (_calleeTemplate != null) { Vector calleeParams = _calleeTemplate.getParameters(); int numParams = _parameters.length; for (int i = 0; i < numParams; i++) { SyntaxTreeNode node = (SyntaxTreeNode)_parameters[i]; methodSig.append(OBJECT_SIG); // append Object to signature // Push 'null' if Param to indicate no actual parameter specified if (node instanceof Param) { il.append(ACONST_NULL); } else { // translate WithParam node.translate(classGen, methodGen); } } } // Complete signature and generate invokevirtual call methodSig.append(")V"); il.append(new INVOKEVIRTUAL(cpg.addMethodref(className, methodName, methodSig.toString()))); // Do not need to call Translet.popParamFrame() if we are // calling a simple named template. if (_calleeTemplate == null && (stylesheet.hasLocalParams() || hasContents())) { // Pop parameter frame final int pop = cpg.addMethodref(TRANSLET_CLASS, POP_PARAM_FRAME, POP_PARAM_FRAME_SIG); il.append(classGen.loadTranslet()); il.append(new INVOKEVIRTUAL(pop)); } }
Example 12
Source File: Sort.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
/** * Create a new auxillary class extending NodeSortRecord. */ private static String compileSortRecord(Vector<Sort> sortObjects, ClassGenerator classGen, MethodGenerator methodGen) { final XSLTC xsltc = sortObjects.firstElement().getXSLTC(); final String className = xsltc.getHelperClassName(); // This generates a new class for handling this specific sort final NodeSortRecordGenerator sortRecord = new NodeSortRecordGenerator(className, NODE_SORT_RECORD, "sort$0.java", ACC_PUBLIC | ACC_SUPER | ACC_FINAL, new String[] {}, classGen.getStylesheet()); final ConstantPoolGen cpg = sortRecord.getConstantPool(); // Add a new instance variable for each var in closure final int nsorts = sortObjects.size(); final ArrayList<VariableRefBase> dups = new ArrayList<>(); for (int j = 0; j < nsorts; j++) { final Sort sort = sortObjects.get(j); // Set the name of the inner class in this sort object sort.setInnerClassName(className); final int length = (sort._closureVars == null) ? 0 : sort._closureVars.size(); for (int i = 0; i < length; i++) { final VariableRefBase varRef = (VariableRefBase) sort._closureVars.get(i); // Discard duplicate variable references if (dups.contains(varRef)) continue; final VariableBase var = varRef.getVariable(); sortRecord.addField(new Field(ACC_PUBLIC, cpg.addUtf8(var.getEscapedName()), cpg.addUtf8(var.getType().toSignature()), null, cpg.getConstantPool())); dups.add(varRef); } } MethodGenerator init = compileInit(sortRecord, cpg, className); MethodGenerator extract = compileExtract(sortObjects, sortRecord, cpg, className); sortRecord.addMethod(init); sortRecord.addMethod(extract); xsltc.dumpClass(sortRecord.getJavaClass()); return className; }
Example 13
Source File: CallTemplate.java From JDKSourceCode1.8 with MIT License | 4 votes |
public void translate(ClassGenerator classGen, MethodGenerator methodGen) { final Stylesheet stylesheet = classGen.getStylesheet(); final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); // If there are Params in the stylesheet or WithParams in this call? if (stylesheet.hasLocalParams() || hasContents()) { _calleeTemplate = getCalleeTemplate(); // Build the parameter list if the called template is simple named if (_calleeTemplate != null) { buildParameterList(); } // This is only needed when the called template is not // a simple named template. else { // Push parameter frame final int push = cpg.addMethodref(TRANSLET_CLASS, PUSH_PARAM_FRAME, PUSH_PARAM_FRAME_SIG); il.append(classGen.loadTranslet()); il.append(new INVOKEVIRTUAL(push)); translateContents(classGen, methodGen); } } // Generate a valid Java method name final String className = stylesheet.getClassName(); String methodName = Util.escape(_name.toString()); // Load standard arguments il.append(classGen.loadTranslet()); il.append(methodGen.loadDOM()); il.append(methodGen.loadIterator()); il.append(methodGen.loadHandler()); il.append(methodGen.loadCurrentNode()); // Initialize prefix of method signature StringBuffer methodSig = new StringBuffer("(" + DOM_INTF_SIG + NODE_ITERATOR_SIG + TRANSLET_OUTPUT_SIG + NODE_SIG); // If calling a simply named template, push actual arguments if (_calleeTemplate != null) { int numParams = _parameters.length; for (int i = 0; i < numParams; i++) { SyntaxTreeNode node = _parameters[i]; methodSig.append(OBJECT_SIG); // append Object to signature // Push 'null' if Param to indicate no actual parameter specified if (node instanceof Param) { il.append(ACONST_NULL); } else { // translate WithParam node.translate(classGen, methodGen); } } } // Complete signature and generate invokevirtual call methodSig.append(")V"); il.append(new INVOKEVIRTUAL(cpg.addMethodref(className, methodName, methodSig.toString()))); // release temporary result trees if (_parameters != null) { for (int i = 0; i < _parameters.length; i++) { if (_parameters[i] instanceof WithParam) { ((WithParam)_parameters[i]).releaseResultTree(classGen, methodGen); } } } // Do not need to call Translet.popParamFrame() if we are // calling a simple named template. if (_calleeTemplate == null && (stylesheet.hasLocalParams() || hasContents())) { // Pop parameter frame final int pop = cpg.addMethodref(TRANSLET_CLASS, POP_PARAM_FRAME, POP_PARAM_FRAME_SIG); il.append(classGen.loadTranslet()); il.append(new INVOKEVIRTUAL(pop)); } }
Example 14
Source File: Sort.java From JDKSourceCode1.8 with MIT License | 4 votes |
/** * Create a new auxillary class extending NodeSortRecord. */ private static String compileSortRecord(Vector<Sort> sortObjects, ClassGenerator classGen, MethodGenerator methodGen) { final XSLTC xsltc = sortObjects.firstElement().getXSLTC(); final String className = xsltc.getHelperClassName(); // This generates a new class for handling this specific sort final NodeSortRecordGenerator sortRecord = new NodeSortRecordGenerator(className, NODE_SORT_RECORD, "sort$0.java", ACC_PUBLIC | ACC_SUPER | ACC_FINAL, new String[] {}, classGen.getStylesheet()); final ConstantPoolGen cpg = sortRecord.getConstantPool(); // Add a new instance variable for each var in closure final int nsorts = sortObjects.size(); final ArrayList<VariableRefBase> dups = new ArrayList<>(); for (int j = 0; j < nsorts; j++) { final Sort sort = sortObjects.get(j); // Set the name of the inner class in this sort object sort.setInnerClassName(className); final int length = (sort._closureVars == null) ? 0 : sort._closureVars.size(); for (int i = 0; i < length; i++) { final VariableRefBase varRef = (VariableRefBase) sort._closureVars.get(i); // Discard duplicate variable references if (dups.contains(varRef)) continue; final VariableBase var = varRef.getVariable(); sortRecord.addField(new Field(ACC_PUBLIC, cpg.addUtf8(var.getEscapedName()), cpg.addUtf8(var.getType().toSignature()), null, cpg.getConstantPool())); dups.add(varRef); } } MethodGenerator init = compileInit(sortRecord, cpg, className); MethodGenerator extract = compileExtract(sortObjects, sortRecord, cpg, className); sortRecord.addMethod(init); sortRecord.addMethod(extract); xsltc.dumpClass(sortRecord.getJavaClass()); return className; }
Example 15
Source File: CallTemplate.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
public void translate(ClassGenerator classGen, MethodGenerator methodGen) { final Stylesheet stylesheet = classGen.getStylesheet(); final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); // If there are Params in the stylesheet or WithParams in this call? if (stylesheet.hasLocalParams() || hasContents()) { _calleeTemplate = getCalleeTemplate(); // Build the parameter list if the called template is simple named if (_calleeTemplate != null) { buildParameterList(); } // This is only needed when the called template is not // a simple named template. else { // Push parameter frame final int push = cpg.addMethodref(TRANSLET_CLASS, PUSH_PARAM_FRAME, PUSH_PARAM_FRAME_SIG); il.append(classGen.loadTranslet()); il.append(new INVOKEVIRTUAL(push)); translateContents(classGen, methodGen); } } // Generate a valid Java method name final String className = stylesheet.getClassName(); String methodName = Util.escape(_name.toString()); // Load standard arguments il.append(classGen.loadTranslet()); il.append(methodGen.loadDOM()); il.append(methodGen.loadIterator()); il.append(methodGen.loadHandler()); il.append(methodGen.loadCurrentNode()); // Initialize prefix of method signature StringBuffer methodSig = new StringBuffer("(" + DOM_INTF_SIG + NODE_ITERATOR_SIG + TRANSLET_OUTPUT_SIG + NODE_SIG); // If calling a simply named template, push actual arguments if (_calleeTemplate != null) { Vector calleeParams = _calleeTemplate.getParameters(); int numParams = _parameters.length; for (int i = 0; i < numParams; i++) { SyntaxTreeNode node = (SyntaxTreeNode)_parameters[i]; methodSig.append(OBJECT_SIG); // append Object to signature // Push 'null' if Param to indicate no actual parameter specified if (node instanceof Param) { il.append(ACONST_NULL); } else { // translate WithParam node.translate(classGen, methodGen); } } } // Complete signature and generate invokevirtual call methodSig.append(")V"); il.append(new INVOKEVIRTUAL(cpg.addMethodref(className, methodName, methodSig.toString()))); // Do not need to call Translet.popParamFrame() if we are // calling a simple named template. if (_calleeTemplate == null && (stylesheet.hasLocalParams() || hasContents())) { // Pop parameter frame final int pop = cpg.addMethodref(TRANSLET_CLASS, POP_PARAM_FRAME, POP_PARAM_FRAME_SIG); il.append(classGen.loadTranslet()); il.append(new INVOKEVIRTUAL(pop)); } }
Example 16
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 17
Source File: Sort.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * Create a new auxillary class extending NodeSortRecord. */ private static String compileSortRecord(Vector sortObjects, ClassGenerator classGen, MethodGenerator methodGen) { final XSLTC xsltc = ((Sort)sortObjects.firstElement()).getXSLTC(); final String className = xsltc.getHelperClassName(); // This generates a new class for handling this specific sort final NodeSortRecordGenerator sortRecord = new NodeSortRecordGenerator(className, NODE_SORT_RECORD, "sort$0.java", ACC_PUBLIC | ACC_SUPER | ACC_FINAL, new String[] {}, classGen.getStylesheet()); final ConstantPoolGen cpg = sortRecord.getConstantPool(); // Add a new instance variable for each var in closure final int nsorts = sortObjects.size(); final ArrayList dups = new ArrayList(); for (int j = 0; j < nsorts; j++) { final Sort sort = (Sort) sortObjects.get(j); // Set the name of the inner class in this sort object sort.setInnerClassName(className); final int length = (sort._closureVars == null) ? 0 : sort._closureVars.size(); for (int i = 0; i < length; i++) { final VariableRefBase varRef = (VariableRefBase) sort._closureVars.get(i); // Discard duplicate variable references if (dups.contains(varRef)) continue; final VariableBase var = varRef.getVariable(); sortRecord.addField(new Field(ACC_PUBLIC, cpg.addUtf8(var.getEscapedName()), cpg.addUtf8(var.getType().toSignature()), null, cpg.getConstantPool())); dups.add(varRef); } } MethodGenerator init = compileInit(sortObjects, sortRecord, cpg, className); MethodGenerator extract = compileExtract(sortObjects, sortRecord, cpg, className); sortRecord.addMethod(init); sortRecord.addMethod(extract); xsltc.dumpClass(sortRecord.getJavaClass()); return className; }
Example 18
Source File: CallTemplate.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
public void translate(ClassGenerator classGen, MethodGenerator methodGen) { final Stylesheet stylesheet = classGen.getStylesheet(); final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); // If there are Params in the stylesheet or WithParams in this call? if (stylesheet.hasLocalParams() || hasContents()) { _calleeTemplate = getCalleeTemplate(); // Build the parameter list if the called template is simple named if (_calleeTemplate != null) { buildParameterList(); } // This is only needed when the called template is not // a simple named template. else { // Push parameter frame final int push = cpg.addMethodref(TRANSLET_CLASS, PUSH_PARAM_FRAME, PUSH_PARAM_FRAME_SIG); il.append(classGen.loadTranslet()); il.append(new INVOKEVIRTUAL(push)); translateContents(classGen, methodGen); } } // Generate a valid Java method name final String className = stylesheet.getClassName(); String methodName = Util.escape(_name.toString()); // Load standard arguments il.append(classGen.loadTranslet()); il.append(methodGen.loadDOM()); il.append(methodGen.loadIterator()); il.append(methodGen.loadHandler()); il.append(methodGen.loadCurrentNode()); // Initialize prefix of method signature StringBuffer methodSig = new StringBuffer("(" + DOM_INTF_SIG + NODE_ITERATOR_SIG + TRANSLET_OUTPUT_SIG + NODE_SIG); // If calling a simply named template, push actual arguments if (_calleeTemplate != null) { int numParams = _parameters.length; for (int i = 0; i < numParams; i++) { SyntaxTreeNode node = _parameters[i]; methodSig.append(OBJECT_SIG); // append Object to signature // Push 'null' if Param to indicate no actual parameter specified if (node instanceof Param) { il.append(ACONST_NULL); } else { // translate WithParam node.translate(classGen, methodGen); } } } // Complete signature and generate invokevirtual call methodSig.append(")V"); il.append(new INVOKEVIRTUAL(cpg.addMethodref(className, methodName, methodSig.toString()))); // release temporary result trees if (_parameters != null) { for (int i = 0; i < _parameters.length; i++) { if (_parameters[i] instanceof WithParam) { ((WithParam)_parameters[i]).releaseResultTree(classGen, methodGen); } } } // Do not need to call Translet.popParamFrame() if we are // calling a simple named template. if (_calleeTemplate == null && (stylesheet.hasLocalParams() || hasContents())) { // Pop parameter frame final int pop = cpg.addMethodref(TRANSLET_CLASS, POP_PARAM_FRAME, POP_PARAM_FRAME_SIG); il.append(classGen.loadTranslet()); il.append(new INVOKEVIRTUAL(pop)); } }
Example 19
Source File: Sort.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
/** * Create a new auxillary class extending NodeSortRecord. */ private static String compileSortRecord(Vector<Sort> sortObjects, ClassGenerator classGen, MethodGenerator methodGen) { final XSLTC xsltc = sortObjects.firstElement().getXSLTC(); final String className = xsltc.getHelperClassName(); // This generates a new class for handling this specific sort final NodeSortRecordGenerator sortRecord = new NodeSortRecordGenerator(className, NODE_SORT_RECORD, "sort$0.java", ACC_PUBLIC | ACC_SUPER | ACC_FINAL, new String[] {}, classGen.getStylesheet()); final ConstantPoolGen cpg = sortRecord.getConstantPool(); // Add a new instance variable for each var in closure final int nsorts = sortObjects.size(); final ArrayList<VariableRefBase> dups = new ArrayList<>(); for (int j = 0; j < nsorts; j++) { final Sort sort = sortObjects.get(j); // Set the name of the inner class in this sort object sort.setInnerClassName(className); final int length = (sort._closureVars == null) ? 0 : sort._closureVars.size(); for (int i = 0; i < length; i++) { final VariableRefBase varRef = (VariableRefBase) sort._closureVars.get(i); // Discard duplicate variable references if (dups.contains(varRef)) continue; final VariableBase var = varRef.getVariable(); sortRecord.addField(new Field(ACC_PUBLIC, cpg.addUtf8(var.getEscapedName()), cpg.addUtf8(var.getType().toSignature()), null, cpg.getConstantPool())); dups.add(varRef); } } MethodGenerator init = compileInit(sortRecord, cpg, className); MethodGenerator extract = compileExtract(sortObjects, sortRecord, cpg, className); sortRecord.addMethod(init); sortRecord.addMethod(extract); xsltc.dumpClass(sortRecord.getJavaClass()); return className; }
Example 20
Source File: CallTemplate.java From jdk1.8-source-analysis with Apache License 2.0 | 4 votes |
public void translate(ClassGenerator classGen, MethodGenerator methodGen) { final Stylesheet stylesheet = classGen.getStylesheet(); final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); // If there are Params in the stylesheet or WithParams in this call? if (stylesheet.hasLocalParams() || hasContents()) { _calleeTemplate = getCalleeTemplate(); // Build the parameter list if the called template is simple named if (_calleeTemplate != null) { buildParameterList(); } // This is only needed when the called template is not // a simple named template. else { // Push parameter frame final int push = cpg.addMethodref(TRANSLET_CLASS, PUSH_PARAM_FRAME, PUSH_PARAM_FRAME_SIG); il.append(classGen.loadTranslet()); il.append(new INVOKEVIRTUAL(push)); translateContents(classGen, methodGen); } } // Generate a valid Java method name final String className = stylesheet.getClassName(); String methodName = Util.escape(_name.toString()); // Load standard arguments il.append(classGen.loadTranslet()); il.append(methodGen.loadDOM()); il.append(methodGen.loadIterator()); il.append(methodGen.loadHandler()); il.append(methodGen.loadCurrentNode()); // Initialize prefix of method signature StringBuffer methodSig = new StringBuffer("(" + DOM_INTF_SIG + NODE_ITERATOR_SIG + TRANSLET_OUTPUT_SIG + NODE_SIG); // If calling a simply named template, push actual arguments if (_calleeTemplate != null) { int numParams = _parameters.length; for (int i = 0; i < numParams; i++) { SyntaxTreeNode node = _parameters[i]; methodSig.append(OBJECT_SIG); // append Object to signature // Push 'null' if Param to indicate no actual parameter specified if (node instanceof Param) { il.append(ACONST_NULL); } else { // translate WithParam node.translate(classGen, methodGen); } } } // Complete signature and generate invokevirtual call methodSig.append(")V"); il.append(new INVOKEVIRTUAL(cpg.addMethodref(className, methodName, methodSig.toString()))); // release temporary result trees if (_parameters != null) { for (int i = 0; i < _parameters.length; i++) { if (_parameters[i] instanceof WithParam) { ((WithParam)_parameters[i]).releaseResultTree(classGen, methodGen); } } } // Do not need to call Translet.popParamFrame() if we are // calling a simple named template. if (_calleeTemplate == null && (stylesheet.hasLocalParams() || hasContents())) { // Pop parameter frame final int pop = cpg.addMethodref(TRANSLET_CLASS, POP_PARAM_FRAME, POP_PARAM_FRAME_SIG); il.append(classGen.loadTranslet()); il.append(new INVOKEVIRTUAL(pop)); } }