com.sun.org.apache.bcel.internal.generic.PUSH Java Examples
The following examples show how to use
com.sun.org.apache.bcel.internal.generic.PUSH.
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: Predicate.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Translate a predicate expression. If non of the optimizations apply * then this translation pushes two references on the stack: a reference * to a newly created filter object and a reference to the predicate's * closure. See class <code>Step</code> for further details. */ public void translate(ClassGenerator classGen, MethodGenerator methodGen) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); if (_nthPositionFilter || _nthDescendant) { _exp.translate(classGen, methodGen); } else if (isNodeValueTest() && (getParent() instanceof Step)) { _value.translate(classGen, methodGen); il.append(new CHECKCAST(cpg.addClass(STRING_CLASS))); il.append(new PUSH(cpg, ((EqualityExpr)_exp).getOp())); } else { translateFilter(classGen, methodGen); } }
Example #2
Source File: UnsupportedElement.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Translate the fallback element (if any). */ public void translate(ClassGenerator classGen, MethodGenerator methodGen) { if (_fallbacks != null) { int count = _fallbacks.size(); for (int i = 0; i < count; i++) { Fallback fallback = (Fallback)_fallbacks.elementAt(i); fallback.translate(classGen, methodGen); } } // We only go into the else block in forward-compatibility mode, when // the unsupported element has no fallback. else { // If the unsupported element does not have any fallback child, then // at runtime, a runtime error should be raised when the unsupported // element is instantiated. Otherwise, no error is thrown. ConstantPoolGen cpg = classGen.getConstantPool(); InstructionList il = methodGen.getInstructionList(); final int unsupportedElem = cpg.addMethodref(BASIS_LIBRARY_CLASS, "unsupported_ElementF", "(" + STRING_SIG + "Z)V"); il.append(new PUSH(cpg, getQName().toString())); il.append(new PUSH(cpg, _isExtension)); il.append(new INVOKESTATIC(unsupportedElem)); } }
Example #3
Source File: Text.java From jdk1.8-source-analysis with Apache License 2.0 | 6 votes |
/** * Generates code that loads the array that will contain the character * data represented by this Text node, followed by the offset of the * data from the start of the array, and then the length of the data. * * The pre-condition to calling this method is that * canLoadAsArrayOffsetLength() returns true. * @see #canLoadArrayOffsetLength() */ public void loadAsArrayOffsetLength(ClassGenerator classGen, MethodGenerator methodGen) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); final XSLTC xsltc = classGen.getParser().getXSLTC(); // The XSLTC object keeps track of character data // that is to be stored in char arrays. final int offset = xsltc.addCharacterData(_text); final int length = _text.length(); String charDataFieldName = STATIC_CHAR_DATA_FIELD + (xsltc.getCharacterDataCount()-1); il.append(new GETSTATIC(cpg.addFieldref(xsltc.getClassName(), charDataFieldName, STATIC_CHAR_DATA_FIELD_SIG))); il.append(new PUSH(cpg, offset)); il.append(new PUSH(cpg, _text.length())); }
Example #4
Source File: Predicate.java From jdk1.8-source-analysis with Apache License 2.0 | 6 votes |
/** * Translate a predicate expression. If non of the optimizations apply * then this translation pushes two references on the stack: a reference * to a newly created filter object and a reference to the predicate's * closure. See class <code>Step</code> for further details. */ public void translate(ClassGenerator classGen, MethodGenerator methodGen) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); if (_nthPositionFilter || _nthDescendant) { _exp.translate(classGen, methodGen); } else if (isNodeValueTest() && (getParent() instanceof Step)) { _value.translate(classGen, methodGen); il.append(new CHECKCAST(cpg.addClass(STRING_CLASS))); il.append(new PUSH(cpg, ((EqualityExpr)_exp).getOp())); } else { translateFilter(classGen, methodGen); } }
Example #5
Source File: XslElement.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * This method is called when the name of the element is known at compile time. * In this case, there is no need to inspect the element name at runtime to * determine if a prefix exists, needs to be generated, etc. */ public void translateLiteral(ClassGenerator classGen, MethodGenerator methodGen) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); if (!_ignore) { il.append(methodGen.loadHandler()); _name.translate(classGen, methodGen); il.append(DUP2); il.append(methodGen.startElement()); if (_namespace != null) { il.append(methodGen.loadHandler()); il.append(new PUSH(cpg, _prefix)); _namespace.translate(classGen,methodGen); il.append(methodGen.namespace()); } } translateContents(classGen, methodGen); if (!_ignore) { il.append(methodGen.endElement()); } }
Example #6
Source File: StringType.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Translates an external (primitive) Java type into a string. * * @see com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateFrom */ public void translateFrom(ClassGenerator classGen, MethodGenerator methodGen, Class clazz) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); if (clazz.getName().equals("java.lang.String")) { // same internal representation, convert null to "" il.append(DUP); final BranchHandle ifNonNull = il.append(new IFNONNULL(null)); il.append(POP); il.append(new PUSH(cpg, "")); ifNonNull.setTarget(il.append(NOP)); } else { ErrorMsg err = new ErrorMsg(ErrorMsg.DATA_CONVERSION_ERR, toString(), clazz.getName()); classGen.getParser().reportError(Constants.FATAL, err); } }
Example #7
Source File: UnsupportedElement.java From jdk1.8-source-analysis with Apache License 2.0 | 6 votes |
/** * Translate the fallback element (if any). */ public void translate(ClassGenerator classGen, MethodGenerator methodGen) { if (_fallbacks != null) { int count = _fallbacks.size(); for (int i = 0; i < count; i++) { Fallback fallback = (Fallback)_fallbacks.elementAt(i); fallback.translate(classGen, methodGen); } } // We only go into the else block in forward-compatibility mode, when // the unsupported element has no fallback. else { // If the unsupported element does not have any fallback child, then // at runtime, a runtime error should be raised when the unsupported // element is instantiated. Otherwise, no error is thrown. ConstantPoolGen cpg = classGen.getConstantPool(); InstructionList il = methodGen.getInstructionList(); final int unsupportedElem = cpg.addMethodref(BASIS_LIBRARY_CLASS, "unsupported_ElementF", "(" + STRING_SIG + "Z)V"); il.append(new PUSH(cpg, getQName().toString())); il.append(new PUSH(cpg, _isExtension)); il.append(new INVOKESTATIC(unsupportedElem)); } }
Example #8
Source File: ObjectType.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Expects an integer on the stack and pushes its string value by calling * <code>Integer.toString(int i)</code>. * * @see com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo */ public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, StringType type) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); il.append(DUP); final BranchHandle ifNull = il.append(new IFNULL(null)); il.append(new INVOKEVIRTUAL(cpg.addMethodref(_javaClassName, "toString", "()" + STRING_SIG))); final BranchHandle gotobh = il.append(new GOTO(null)); ifNull.setTarget(il.append(POP)); il.append(new PUSH(cpg, "")); gotobh.setTarget(il.append(NOP)); }
Example #9
Source File: ReferenceType.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Translates reference into object of internal type <code>type</code>. * * @see com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo */ public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, StringType type) { final int current = methodGen.getLocalIndex("current"); ConstantPoolGen cpg = classGen.getConstantPool(); InstructionList il = methodGen.getInstructionList(); // If no current, conversion is a top-level if (current < 0) { il.append(new PUSH(cpg, DTM.ROOT_NODE)); // push root node } else { il.append(new ILOAD(current)); } il.append(methodGen.loadDOM()); final int stringF = cpg.addMethodref(BASIS_LIBRARY_CLASS, "stringF", "(" + OBJECT_SIG + NODE_SIG + DOM_INTF_SIG + ")" + STRING_SIG); il.append(new INVOKESTATIC(stringF)); }
Example #10
Source File: XslElement.java From jdk1.8-source-analysis with Apache License 2.0 | 6 votes |
/** * This method is called when the name of the element is known at compile time. * In this case, there is no need to inspect the element name at runtime to * determine if a prefix exists, needs to be generated, etc. */ public void translateLiteral(ClassGenerator classGen, MethodGenerator methodGen) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); if (!_ignore) { il.append(methodGen.loadHandler()); _name.translate(classGen, methodGen); il.append(DUP2); il.append(methodGen.startElement()); if (_namespace != null) { il.append(methodGen.loadHandler()); il.append(new PUSH(cpg, _prefix)); _namespace.translate(classGen,methodGen); il.append(methodGen.namespace()); } } translateContents(classGen, methodGen); if (!_ignore) { il.append(methodGen.endElement()); } }
Example #11
Source File: StringType.java From jdk1.8-source-analysis with Apache License 2.0 | 6 votes |
/** * Translates an external (primitive) Java type into a string. * * @see com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateFrom */ public void translateFrom(ClassGenerator classGen, MethodGenerator methodGen, Class clazz) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); if (clazz.getName().equals("java.lang.String")) { // same internal representation, convert null to "" il.append(DUP); final BranchHandle ifNonNull = il.append(new IFNONNULL(null)); il.append(POP); il.append(new PUSH(cpg, "")); ifNonNull.setTarget(il.append(NOP)); } else { ErrorMsg err = new ErrorMsg(ErrorMsg.DATA_CONVERSION_ERR, toString(), clazz.getName()); classGen.getParser().reportError(Constants.FATAL, err); } }
Example #12
Source File: Text.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Generates code that loads the array that will contain the character * data represented by this Text node, followed by the offset of the * data from the start of the array, and then the length of the data. * * The pre-condition to calling this method is that * canLoadAsArrayOffsetLength() returns true. * @see #canLoadArrayOffsetLength() */ public void loadAsArrayOffsetLength(ClassGenerator classGen, MethodGenerator methodGen) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); final XSLTC xsltc = classGen.getParser().getXSLTC(); // The XSLTC object keeps track of character data // that is to be stored in char arrays. final int offset = xsltc.addCharacterData(_text); final int length = _text.length(); String charDataFieldName = STATIC_CHAR_DATA_FIELD + (xsltc.getCharacterDataCount()-1); il.append(new GETSTATIC(cpg.addFieldref(xsltc.getClassName(), charDataFieldName, STATIC_CHAR_DATA_FIELD_SIG))); il.append(new PUSH(cpg, offset)); il.append(new PUSH(cpg, _text.length())); }
Example #13
Source File: ObjectType.java From jdk1.8-source-analysis with Apache License 2.0 | 6 votes |
/** * Expects an integer on the stack and pushes its string value by calling * <code>Integer.toString(int i)</code>. * * @see com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo */ public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, StringType type) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); il.append(DUP); final BranchHandle ifNull = il.append(new IFNULL(null)); il.append(new INVOKEVIRTUAL(cpg.addMethodref(_javaClassName, "toString", "()" + STRING_SIG))); final BranchHandle gotobh = il.append(new GOTO(null)); ifNull.setTarget(il.append(POP)); il.append(new PUSH(cpg, "")); gotobh.setTarget(il.append(NOP)); }
Example #14
Source File: ReferenceType.java From jdk1.8-source-analysis with Apache License 2.0 | 6 votes |
/** * Translates reference into object of internal type <code>type</code>. * * @see com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo */ public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, StringType type) { final int current = methodGen.getLocalIndex("current"); ConstantPoolGen cpg = classGen.getConstantPool(); InstructionList il = methodGen.getInstructionList(); // If no current, conversion is a top-level if (current < 0) { il.append(new PUSH(cpg, DTM.ROOT_NODE)); // push root node } else { il.append(new ILOAD(current)); } il.append(methodGen.loadDOM()); final int stringF = cpg.addMethodref(BASIS_LIBRARY_CLASS, "stringF", "(" + OBJECT_SIG + NODE_SIG + DOM_INTF_SIG + ")" + STRING_SIG); il.append(new INVOKESTATIC(stringF)); }
Example #15
Source File: NodeType.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
/** * Expects a node on the stack and pushes a boxed node. Boxed nodes * are represented by an instance of <code>com.sun.org.apache.xalan.internal.xsltc.dom.Node</code>. * * @see com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo */ public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, ReferenceType type) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); il.append(new NEW(cpg.addClass(RUNTIME_NODE_CLASS))); il.append(DUP_X1); il.append(SWAP); il.append(new PUSH(cpg, _type)); il.append(new INVOKESPECIAL(cpg.addMethodref(RUNTIME_NODE_CLASS, "<init>", "(II)V"))); }
Example #16
Source File: RelationalExpr.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public void translate(ClassGenerator classGen, MethodGenerator methodGen) { if (hasNodeSetArgs() || hasReferenceArgs()) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); // Call compare() from the BasisLibrary _left.translate(classGen, methodGen); _left.startIterator(classGen, methodGen); _right.translate(classGen, methodGen); _right.startIterator(classGen, methodGen); il.append(new PUSH(cpg, _op)); il.append(methodGen.loadDOM()); int index = cpg.addMethodref(BASIS_LIBRARY_CLASS, "compare", "(" + _left.getType().toSignature() + _right.getType().toSignature() + "I" + DOM_INTF_SIG + ")Z"); il.append(new INVOKESTATIC(index)); } else { translateDesynthesized(classGen, methodGen); synthesize(classGen, methodGen); } }
Example #17
Source File: FormatNumberCall.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public void translate(ClassGenerator classGen, MethodGenerator methodGen) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); _value.translate(classGen, methodGen); _format.translate(classGen, methodGen); final int fn3arg = cpg.addMethodref(BASIS_LIBRARY_CLASS, "formatNumber", "(DLjava/lang/String;"+ "Ljava/text/DecimalFormat;)"+ "Ljava/lang/String;"); final int get = cpg.addMethodref(TRANSLET_CLASS, "getDecimalFormat", "(Ljava/lang/String;)"+ "Ljava/text/DecimalFormat;"); il.append(classGen.loadTranslet()); if (_name == null) { il.append(new PUSH(cpg, EMPTYSTRING)); } else if (_resolvedQName != null) { il.append(new PUSH(cpg, _resolvedQName.toString())); } else { _name.translate(classGen, methodGen); } il.append(new INVOKEVIRTUAL(get)); il.append(new INVOKESTATIC(fn3arg)); }
Example #18
Source File: RelationalExpr.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
public void translate(ClassGenerator classGen, MethodGenerator methodGen) { if (hasNodeSetArgs() || hasReferenceArgs()) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); // Call compare() from the BasisLibrary _left.translate(classGen, methodGen); _left.startIterator(classGen, methodGen); _right.translate(classGen, methodGen); _right.startIterator(classGen, methodGen); il.append(new PUSH(cpg, _op)); il.append(methodGen.loadDOM()); int index = cpg.addMethodref(BASIS_LIBRARY_CLASS, "compare", "(" + _left.getType().toSignature() + _right.getType().toSignature() + "I" + DOM_INTF_SIG + ")Z"); il.append(new INVOKESTATIC(index)); } else { translateDesynthesized(classGen, methodGen); synthesize(classGen, methodGen); } }
Example #19
Source File: BooleanType.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Expects a boolean on the stack and pushes a string. If the value on the * stack is zero, then the string 'false' is pushed. Otherwise, the string * 'true' is pushed. * * @see com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo */ public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, StringType type) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); final BranchHandle falsec = il.append(new IFEQ(null)); il.append(new PUSH(cpg, "true")); final BranchHandle truec = il.append(new GOTO(null)); falsec.setTarget(il.append(new PUSH(cpg, "false"))); truec.setTarget(il.append(NOP)); }
Example #20
Source File: NodeSetType.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Translates a node-set into a string. The string value of a node-set is * value of its first element. * * @see com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo */ public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, StringType type) { final InstructionList il = methodGen.getInstructionList(); getFirstNode(classGen, methodGen); il.append(DUP); final BranchHandle falsec = il.append(new IFLT(null)); Type.Node.translateTo(classGen, methodGen, type); final BranchHandle truec = il.append(new GOTO(null)); falsec.setTarget(il.append(POP)); il.append(new PUSH(classGen.getConstantPool(), "")); truec.setTarget(il.append(NOP)); }
Example #21
Source File: FormatNumberCall.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
public void translate(ClassGenerator classGen, MethodGenerator methodGen) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); _value.translate(classGen, methodGen); _format.translate(classGen, methodGen); final int fn3arg = cpg.addMethodref(BASIS_LIBRARY_CLASS, "formatNumber", "(DLjava/lang/String;"+ "Ljava/text/DecimalFormat;)"+ "Ljava/lang/String;"); final int get = cpg.addMethodref(TRANSLET_CLASS, "getDecimalFormat", "(Ljava/lang/String;)"+ "Ljava/text/DecimalFormat;"); il.append(classGen.loadTranslet()); if (_name == null) { il.append(new PUSH(cpg, EMPTYSTRING)); } else if (_resolvedQName != null) { il.append(new PUSH(cpg, _resolvedQName.toString())); } else { _name.translate(classGen, methodGen); } il.append(new INVOKEVIRTUAL(get)); il.append(new INVOKESTATIC(fn3arg)); }
Example #22
Source File: WithParam.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
/** * This code generates a sequence of bytecodes that call the * addParameter() method in AbstractTranslet. The method call will add * (or update) the parameter frame with the new parameter value. */ public void translate(ClassGenerator classGen, MethodGenerator methodGen) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); // Translate the value and put it on the stack if (_doParameterOptimization) { translateValue(classGen, methodGen); return; } // Make name acceptable for use as field name in class String name = Util.escape(getEscapedName()); // Load reference to the translet (method is in AbstractTranslet) il.append(classGen.loadTranslet()); // Load the name of the parameter il.append(new PUSH(cpg, name)); // TODO: namespace ? // Generete the value of the parameter (use value in 'select' by def.) translateValue(classGen, methodGen); // Mark this parameter value is not being the default value il.append(new PUSH(cpg, false)); // Pass the parameter to the template il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS, ADD_PARAMETER, ADD_PARAMETER_SIG))); il.append(POP); // cleanup stack }
Example #23
Source File: BooleanType.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
/** * Expects a boolean on the stack and pushes a string. If the value on the * stack is zero, then the string 'false' is pushed. Otherwise, the string * 'true' is pushed. * * @see com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo */ public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, StringType type) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); final BranchHandle falsec = il.append(new IFEQ(null)); il.append(new PUSH(cpg, "true")); final BranchHandle truec = il.append(new GOTO(null)); falsec.setTarget(il.append(new PUSH(cpg, "false"))); truec.setTarget(il.append(NOP)); }
Example #24
Source File: FunctionCall.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
/** * Translate code to call the BasisLibrary.unallowed_extensionF(String) * method. */ private void translateUnallowedExtension(ConstantPoolGen cpg, InstructionList il) { int index = cpg.addMethodref(BASIS_LIBRARY_CLASS, "unallowed_extension_functionF", "(Ljava/lang/String;)V"); il.append(new PUSH(cpg, _fname.toString())); il.append(new INVOKESTATIC(index)); }
Example #25
Source File: FunctionCall.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Translate code to call the BasisLibrary.unallowed_extensionF(String) * method. */ private void translateUnallowedExtension(ConstantPoolGen cpg, InstructionList il) { int index = cpg.addMethodref(BASIS_LIBRARY_CLASS, "unallowed_extension_functionF", "(Ljava/lang/String;)V"); il.append(new PUSH(cpg, _fname.toString())); il.append(new INVOKESTATIC(index)); }
Example #26
Source File: NodeSetType.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
/** * Translates a node-set into a string. The string value of a node-set is * value of its first element. * * @see com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo */ public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, StringType type) { final InstructionList il = methodGen.getInstructionList(); getFirstNode(classGen, methodGen); il.append(DUP); final BranchHandle falsec = il.append(new IFLT(null)); Type.Node.translateTo(classGen, methodGen, type); final BranchHandle truec = il.append(new GOTO(null)); falsec.setTarget(il.append(POP)); il.append(new PUSH(classGen.getConstantPool(), "")); truec.setTarget(il.append(NOP)); }
Example #27
Source File: WithParam.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * This code generates a sequence of bytecodes that call the * addParameter() method in AbstractTranslet. The method call will add * (or update) the parameter frame with the new parameter value. */ public void translate(ClassGenerator classGen, MethodGenerator methodGen) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); // Translate the value and put it on the stack if (_doParameterOptimization) { translateValue(classGen, methodGen); return; } // Make name acceptable for use as field name in class String name = Util.escape(getEscapedName()); // Load reference to the translet (method is in AbstractTranslet) il.append(classGen.loadTranslet()); // Load the name of the parameter il.append(new PUSH(cpg, name)); // TODO: namespace ? // Generete the value of the parameter (use value in 'select' by def.) translateValue(classGen, methodGen); // Mark this parameter value is not being the default value il.append(new PUSH(cpg, false)); // Pass the parameter to the template il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS, ADD_PARAMETER, ADD_PARAMETER_SIG))); il.append(POP); // cleanup stack }
Example #28
Source File: IntExpr.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
public void translate(ClassGenerator classGen, MethodGenerator methodGen) { ConstantPoolGen cpg = classGen.getConstantPool(); InstructionList il = methodGen.getInstructionList(); il.append(new PUSH(cpg, _value)); }
Example #29
Source File: Sort.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
/** * Compiles a method that overloads NodeSortRecord.extractValueFromDOM() */ private static MethodGenerator compileExtract(Vector<Sort> sortObjects, NodeSortRecordGenerator sortRecord, ConstantPoolGen cpg, String className) { final InstructionList il = new InstructionList(); // String NodeSortRecord.extractValueFromDOM(dom,node,level); final CompareGenerator extractMethod = new CompareGenerator(ACC_PUBLIC | ACC_FINAL, com.sun.org.apache.bcel.internal.generic.Type.STRING, new com.sun.org.apache.bcel.internal.generic.Type[] { Util.getJCRefType(DOM_INTF_SIG), com.sun.org.apache.bcel.internal.generic.Type.INT, com.sun.org.apache.bcel.internal.generic.Type.INT, Util.getJCRefType(TRANSLET_SIG), com.sun.org.apache.bcel.internal.generic.Type.INT }, new String[] { "dom", "current", "level", "translet", "last" }, "extractValueFromDOM", className, il, cpg); // Values needed for the switch statement final int levels = sortObjects.size(); final int match[] = new int[levels]; final InstructionHandle target[] = new InstructionHandle[levels]; InstructionHandle tblswitch = null; // Compile switch statement only if the key has multiple levels if (levels > 1) { // Put the parameter to the swtich statement on the stack il.append(new ILOAD(extractMethod.getLocalIndex("level"))); // Append the switch statement here later on tblswitch = il.append(new NOP()); } // Append all the cases for the switch statment for (int level = 0; level < levels; level++) { match[level] = level; final Sort sort = sortObjects.elementAt(level); target[level] = il.append(NOP); sort.translateSelect(sortRecord, extractMethod); il.append(ARETURN); } // Compile def. target for switch statement if key has multiple levels if (levels > 1) { // Append the default target - it will _NEVER_ be reached InstructionHandle defaultTarget = il.append(new PUSH(cpg, EMPTYSTRING)); il.insert(tblswitch,new TABLESWITCH(match, target, defaultTarget)); il.append(ARETURN); } return extractMethod; }
Example #30
Source File: IdKeyPattern.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
/** * This method is called when the constructor is compiled in * Stylesheet.compileConstructor() and not as the syntax tree is traversed. */ public void translate(ClassGenerator classGen, MethodGenerator methodGen) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); // Returns the KeyIndex object of a given name final int getKeyIndex = cpg.addMethodref(TRANSLET_CLASS, "getKeyIndex", "(Ljava/lang/String;)"+ KEY_INDEX_SIG); // Initialises a KeyIndex to return nodes with specific values final int lookupId = cpg.addMethodref(KEY_INDEX_CLASS, "containsID", "(ILjava/lang/Object;)I"); final int lookupKey = cpg.addMethodref(KEY_INDEX_CLASS, "containsKey", "(ILjava/lang/Object;)I"); final int getNodeIdent = cpg.addInterfaceMethodref(DOM_INTF, "getNodeIdent", "(I)"+NODE_SIG); // Call getKeyIndex in AbstractTranslet with the name of the key // to get the index for this key (which is also a node iterator). il.append(classGen.loadTranslet()); il.append(new PUSH(cpg,_index)); il.append(new INVOKEVIRTUAL(getKeyIndex)); // Now use the value in the second argument to determine what nodes // the iterator should return. il.append(SWAP); il.append(new PUSH(cpg,_value)); if (this instanceof IdPattern) { il.append(new INVOKEVIRTUAL(lookupId)); } else { il.append(new INVOKEVIRTUAL(lookupKey)); } _trueList.add(il.append(new IFNE(null))); _falseList.add(il.append(new GOTO(null))); }