Java Code Examples for com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator#getConstantPool()
The following examples show how to use
com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator#getConstantPool() .
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: LastCall.java From Bytecoder with Apache License 2.0 | 6 votes |
public void translate(ClassGenerator classGen, MethodGenerator methodGen) { final InstructionList il = methodGen.getInstructionList(); if (methodGen instanceof CompareGenerator) { il.append(((CompareGenerator)methodGen).loadLastNode()); } else if (methodGen instanceof TestGenerator) { il.append(new ILOAD(LAST_INDEX)); } else { final ConstantPoolGen cpg = classGen.getConstantPool(); final int getLast = cpg.addInterfaceMethodref(NODE_ITERATOR, "getLast", "()I"); il.append(methodGen.loadIterator()); il.append(new INVOKEINTERFACE(getLast, 1)); } }
Example 2
Source File: Mode.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * Compiles the default handling for DOM elements: traverse all children */ private InstructionList compileDefaultRecursion(ClassGenerator classGen, MethodGenerator methodGen, InstructionHandle next) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = new InstructionList(); final String applyTemplatesSig = classGen.getApplyTemplatesSig(); final int git = cpg.addInterfaceMethodref(DOM_INTF, GET_CHILDREN, GET_CHILDREN_SIG); final int applyTemplates = cpg.addMethodref(getClassName(), functionName(), applyTemplatesSig); il.append(classGen.loadTranslet()); il.append(methodGen.loadDOM()); il.append(methodGen.loadDOM()); il.append(new ILOAD(_currentIndex)); il.append(new INVOKEINTERFACE(git, 2)); il.append(methodGen.loadHandler()); il.append(new INVOKEVIRTUAL(applyTemplates)); il.append(new GOTO_W(next)); return il; }
Example 3
Source File: WithParam.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
/** * Compile the value of the parameter, which is either in an expression in * a 'select' attribute, or in the with-param element's body */ public void translateValue(ClassGenerator classGen, MethodGenerator methodGen) { // Compile expression is 'select' attribute if present if (_select != null) { _select.translate(classGen, methodGen); _select.startIterator(classGen, methodGen); } // If not, compile result tree from parameter body if present. else if (hasContents()) { compileResultTree(classGen, methodGen); } // If neither are present then store empty string in parameter slot else { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); il.append(new PUSH(cpg, Constants.EMPTYSTRING)); } }
Example 4
Source File: StepPattern.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
public void translate(ClassGenerator classGen, MethodGenerator methodGen) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); if (hasPredicates()) { switch (_contextCase) { case NO_CONTEXT: translateNoContext(classGen, methodGen); break; case SIMPLE_CONTEXT: translateSimpleContext(classGen, methodGen); break; default: translateGeneralContext(classGen, methodGen); break; } } else if (isWildcard()) { il.append(POP); // true list falls through } else { translateKernel(classGen, methodGen); } }
Example 5
Source File: Stylesheet.java From hottub with GNU General Public License v2.0 | 5 votes |
private void addDOMField(ClassGenerator classGen) { final FieldGen fgen = new FieldGen(ACC_PUBLIC, Util.getJCRefType(DOM_INTF_SIG), DOM_FIELD, classGen.getConstantPool()); classGen.addField(fgen.getField()); }
Example 6
Source File: CastExpr.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public void translateDesynthesized(ClassGenerator classGen, MethodGenerator methodGen) { FlowList fl; final Type ltype = _left.getType(); // This is a special case for the self:: axis. Instead of letting // the Step object create and iterator that we cast back to a single // node, we simply ask the DOM for the node type. if (_typeTest) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); final int idx = cpg.addInterfaceMethodref(DOM_INTF, "getExpandedTypeID", "(I)I"); il.append(new SIPUSH((short)((Step)_left).getNodeType())); il.append(methodGen.loadDOM()); il.append(methodGen.loadContextNode()); il.append(new INVOKEINTERFACE(idx, 2)); _falseList.add(il.append(new IF_ICMPNE(null))); } else { _left.translate(classGen, methodGen); if (_type != ltype) { _left.startIterator(classGen, methodGen); if (_type instanceof BooleanType) { fl = ltype.translateToDesynthesized(classGen, methodGen, _type); if (fl != null) { _falseList.append(fl); } } else { ltype.translateTo(classGen, methodGen, _type); } } } }
Example 7
Source File: ContainsCall.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
/** * Compile expression and update true/false-lists */ public void translateDesynthesized(ClassGenerator classGen, MethodGenerator methodGen) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); _base.translate(classGen, methodGen); _token.translate(classGen, methodGen); il.append(new INVOKEVIRTUAL(cpg.addMethodref(STRING_CLASS, "indexOf", "("+STRING_SIG+")I"))); _falseList.add(il.append(new IFLT(null))); }
Example 8
Source File: CastExpr.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
public void translateDesynthesized(ClassGenerator classGen, MethodGenerator methodGen) { FlowList fl; final Type ltype = _left.getType(); // This is a special case for the self:: axis. Instead of letting // the Step object create and iterator that we cast back to a single // node, we simply ask the DOM for the node type. if (_typeTest) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); final int idx = cpg.addInterfaceMethodref(DOM_INTF, "getExpandedTypeID", "(I)I"); il.append(new SIPUSH((short)((Step)_left).getNodeType())); il.append(methodGen.loadDOM()); il.append(methodGen.loadContextNode()); il.append(new INVOKEINTERFACE(idx, 2)); _falseList.add(il.append(new IF_ICMPNE(null))); } else { _left.translate(classGen, methodGen); if (_type != ltype) { _left.startIterator(classGen, methodGen); if (_type instanceof BooleanType) { fl = ltype.translateToDesynthesized(classGen, methodGen, _type); if (fl != null) { _falseList.append(fl); } } else { ltype.translateTo(classGen, methodGen, _type); } } } }
Example 9
Source File: NameBase.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Translate the code required for getting the node for which the * QName, local-name or namespace URI should be extracted. */ public void translate(ClassGenerator classGen, MethodGenerator methodGen) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); il.append(methodGen.loadDOM()); // Function was called with no parameters if (argumentCount() == 0) { il.append(methodGen.loadContextNode()); } // Function was called with node parameter else if (_paramType == Type.Node) { _param.translate(classGen, methodGen); } else if (_paramType == Type.Reference) { _param.translate(classGen, methodGen); il.append(new INVOKESTATIC(cpg.addMethodref (BASIS_LIBRARY_CLASS, "referenceToNodeSet", "(" + OBJECT_SIG + ")" + NODE_ITERATOR_SIG))); il.append(methodGen.nextNode()); } // Function was called with node-set parameter else { _param.translate(classGen, methodGen); _param.startIterator(classGen, methodGen); il.append(methodGen.nextNode()); } }
Example 10
Source File: Predicate.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
/** * Translate a predicate expression. This translation pushes * two references on the stack: a reference to a newly created * filter object and a reference to the predicate's closure. */ public void translateFilter(ClassGenerator classGen, MethodGenerator methodGen) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); // Compile auxiliary class for filter compileFilter(classGen, methodGen); // Create new instance of filter il.append(new NEW(cpg.addClass(_className))); il.append(DUP); il.append(new INVOKESPECIAL(cpg.addMethodref(_className, "<init>", "()V"))); // Initialize closure variables final int length = (_closureVars == null) ? 0 : _closureVars.size(); for (int i = 0; i < length; i++) { VariableRefBase varRef = (VariableRefBase) _closureVars.get(i); VariableBase var = varRef.getVariable(); Type varType = var.getType(); il.append(DUP); // Find nearest closure implemented as an inner class Closure variableClosure = _parentClosure; while (variableClosure != null) { if (variableClosure.inInnerClass()) break; variableClosure = variableClosure.getParentClosure(); } // Use getfield if in an inner class if (variableClosure != null) { il.append(ALOAD_0); il.append(new GETFIELD( cpg.addFieldref(variableClosure.getInnerClassName(), var.getEscapedName(), varType.toSignature()))); } else { // Use a load of instruction if in translet class il.append(var.loadInstruction()); } // Store variable in new closure il.append(new PUTFIELD( cpg.addFieldref(_className, var.getEscapedName(), varType.toSignature()))); } }
Example 11
Source File: AbsolutePathPattern.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public void translate(ClassGenerator classGen, MethodGenerator methodGen) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); if (_left != null) { if (_left instanceof StepPattern) { final LocalVariableGen local = // absolute path pattern temporary methodGen.addLocalVariable2("apptmp", Util.getJCRefType(NODE_SIG), null); il.append(DUP); local.setStart(il.append(new ISTORE(local.getIndex()))); _left.translate(classGen, methodGen); il.append(methodGen.loadDOM()); local.setEnd(il.append(new ILOAD(local.getIndex()))); methodGen.removeLocalVariable(local); } else { _left.translate(classGen, methodGen); } } final int getParent = cpg.addInterfaceMethodref(DOM_INTF, GET_PARENT, GET_PARENT_SIG); final int getType = cpg.addInterfaceMethodref(DOM_INTF, "getExpandedTypeID", "(I)I"); InstructionHandle begin = il.append(methodGen.loadDOM()); il.append(SWAP); il.append(new INVOKEINTERFACE(getParent, 2)); if (_left instanceof AncestorPattern) { il.append(methodGen.loadDOM()); il.append(SWAP); } il.append(new INVOKEINTERFACE(getType, 2)); il.append(new PUSH(cpg, DTM.DOCUMENT_NODE)); final BranchHandle skip = il.append(new IF_ICMPEQ(null)); _falseList.add(il.append(new GOTO_W(null))); skip.setTarget(il.append(NOP)); if (_left != null) { _left.backPatchTrueList(begin); /* * If _left is an ancestor pattern, backpatch this pattern's false * list to the loop that searches for more ancestors. */ if (_left instanceof AncestorPattern) { final AncestorPattern ancestor = (AncestorPattern) _left; _falseList.backPatch(ancestor.getLoopHandle()); // clears list } _falseList.append(_left._falseList); } }
Example 12
Source File: LiteralExpr.java From Bytecoder with Apache License 2.0 | 4 votes |
public void translate(ClassGenerator classGen, MethodGenerator methodGen) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); il.append(new PUSH(cpg, _value)); }
Example 13
Source File: Copy.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
public void translate(ClassGenerator classGen, MethodGenerator methodGen) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); final LocalVariableGen name = methodGen.addLocalVariable2("name", Util.getJCRefType(STRING_SIG), null); final LocalVariableGen length = methodGen.addLocalVariable2("length", Util.getJCRefType("I"), null); // Get the name of the node to copy and save for later il.append(methodGen.loadDOM()); il.append(methodGen.loadCurrentNode()); il.append(methodGen.loadHandler()); final int cpy = cpg.addInterfaceMethodref(DOM_INTF, "shallowCopy", "(" + NODE_SIG + TRANSLET_OUTPUT_SIG + ")" + STRING_SIG); il.append(new INVOKEINTERFACE(cpy, 3)); il.append(DUP); name.setStart(il.append(new ASTORE(name.getIndex()))); final BranchHandle ifBlock1 = il.append(new IFNULL(null)); // Get the length of the node name and save for later il.append(new ALOAD(name.getIndex())); final int lengthMethod = cpg.addMethodref(STRING_CLASS,"length","()I"); il.append(new INVOKEVIRTUAL(lengthMethod)); il.append(DUP); length.setStart(il.append(new ISTORE(length.getIndex()))); // Ignore attribute sets if current node is ROOT. DOM.shallowCopy() // returns "" for ROOT, so skip attribute sets if length == 0 final BranchHandle ifBlock4 = il.append(new IFEQ(null)); // Copy in attribute sets if specified if (_useSets != null) { // If the parent of this element will result in an element being // output then we know that it is safe to copy out the attributes final SyntaxTreeNode parent = getParent(); if ((parent instanceof LiteralElement) || (parent instanceof LiteralElement)) { _useSets.translate(classGen, methodGen); } // If not we have to check to see if the copy will result in an // element being output. else { // check if element; if not skip to translate body il.append(new ILOAD(length.getIndex())); final BranchHandle ifBlock2 = il.append(new IFEQ(null)); // length != 0 -> element -> do attribute sets _useSets.translate(classGen, methodGen); // not an element; root ifBlock2.setTarget(il.append(NOP)); } } // Instantiate body of xsl:copy ifBlock4.setTarget(il.append(NOP)); translateContents(classGen, methodGen); // Call the output handler's endElement() if we copied an element // (The DOM.shallowCopy() method calls startElement().) length.setEnd(il.append(new ILOAD(length.getIndex()))); final BranchHandle ifBlock3 = il.append(new IFEQ(null)); il.append(methodGen.loadHandler()); name.setEnd(il.append(new ALOAD(name.getIndex()))); il.append(methodGen.endElement()); final InstructionHandle end = il.append(NOP); ifBlock1.setTarget(end); ifBlock3.setTarget(end); methodGen.removeLocalVariable(name); methodGen.removeLocalVariable(length); }
Example 14
Source File: IdKeyPattern.java From jdk8u60 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))); }
Example 15
Source File: KeyCall.java From hottub 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. * <p>This method will generate byte code that produces an iterator * for the nodes in the node set for the key or id function call. * @param classGen The Java class generator * @param methodGen The method generator */ 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); // KeyIndex.setDom(Dom, node) => void final int keyDom = cpg.addMethodref(KEY_INDEX_CLASS, "setDom", "(" + DOM_INTF_SIG + "I)V"); // Initialises a KeyIndex to return nodes with specific values final int getKeyIterator = cpg.addMethodref(KEY_INDEX_CLASS, "getKeyIndexIterator", "(" + _valueType.toSignature() + "Z)" + KEY_INDEX_ITERATOR_SIG); // Initialise the index specified in the first parameter of key() il.append(classGen.loadTranslet()); if (_name == null) { il.append(new PUSH(cpg,"##id")); } else if (_resolvedQName != null) { il.append(new PUSH(cpg, _resolvedQName.toString())); } else { _name.translate(classGen, methodGen); } // Generate following byte code: // // KeyIndex ki = translet.getKeyIndex(_name) // ki.setDom(translet.dom); // ki.getKeyIndexIterator(_value, true) - for key() // OR // ki.getKeyIndexIterator(_value, false) - for id() il.append(new INVOKEVIRTUAL(getKeyIndex)); il.append(DUP); il.append(methodGen.loadDOM()); il.append(methodGen.loadCurrentNode()); il.append(new INVOKEVIRTUAL(keyDom)); _value.translate(classGen, methodGen); il.append((_name != null) ? ICONST_1: ICONST_0); il.append(new INVOKEVIRTUAL(getKeyIterator)); }
Example 16
Source File: AbsolutePathPattern.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
public void translate(ClassGenerator classGen, MethodGenerator methodGen) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); if (_left != null) { if (_left instanceof StepPattern) { final LocalVariableGen local = // absolute path pattern temporary methodGen.addLocalVariable2("apptmp", Util.getJCRefType(NODE_SIG), null); il.append(DUP); local.setStart(il.append(new ISTORE(local.getIndex()))); _left.translate(classGen, methodGen); il.append(methodGen.loadDOM()); local.setEnd(il.append(new ILOAD(local.getIndex()))); methodGen.removeLocalVariable(local); } else { _left.translate(classGen, methodGen); } } final int getParent = cpg.addInterfaceMethodref(DOM_INTF, GET_PARENT, GET_PARENT_SIG); final int getType = cpg.addInterfaceMethodref(DOM_INTF, "getExpandedTypeID", "(I)I"); InstructionHandle begin = il.append(methodGen.loadDOM()); il.append(SWAP); il.append(new INVOKEINTERFACE(getParent, 2)); if (_left instanceof AncestorPattern) { il.append(methodGen.loadDOM()); il.append(SWAP); } il.append(new INVOKEINTERFACE(getType, 2)); il.append(new PUSH(cpg, DTM.DOCUMENT_NODE)); final BranchHandle skip = il.append(new IF_ICMPEQ(null)); _falseList.add(il.append(new GOTO_W(null))); skip.setTarget(il.append(NOP)); if (_left != null) { _left.backPatchTrueList(begin); /* * If _left is an ancestor pattern, backpatch this pattern's false * list to the loop that searches for more ancestors. */ if (_left instanceof AncestorPattern) { final AncestorPattern ancestor = (AncestorPattern) _left; _falseList.backPatch(ancestor.getLoopHandle()); // clears list } _falseList.append(_left._falseList); } }
Example 17
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 18
Source File: StepPattern.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
private void translateSimpleContext(ClassGenerator classGen, MethodGenerator methodGen) { int index; final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); // Store matching node into a local variable LocalVariableGen match; match = methodGen.addLocalVariable("step_pattern_tmp1", Util.getJCRefType(NODE_SIG), null, null); match.setStart(il.append(new ISTORE(match.getIndex()))); // If pattern not reduced then check kernel if (!_isEpsilon) { il.append(new ILOAD(match.getIndex())); translateKernel(classGen, methodGen); } // Push current iterator and current node on the stack il.append(methodGen.loadCurrentNode()); il.append(methodGen.loadIterator()); // Create a new matching iterator using the matching node index = cpg.addMethodref(MATCHING_ITERATOR, "<init>", "(I" + NODE_ITERATOR_SIG + ")V"); // Backwards branches are prohibited if an uninitialized object is // on the stack by section 4.9.4 of the JVM Specification, 2nd Ed. // We don't know whether this code might contain backwards branches, // so we mustn't create the new object until after we've created // the suspect arguments to its constructor. Instead we calculate // the values of the arguments to the constructor first, store them // in temporary variables, create the object and reload the // arguments from the temporaries to avoid the problem. _step.translate(classGen, methodGen); LocalVariableGen stepIteratorTemp = methodGen.addLocalVariable("step_pattern_tmp2", Util.getJCRefType(NODE_ITERATOR_SIG), null, null); stepIteratorTemp.setStart( il.append(new ASTORE(stepIteratorTemp.getIndex()))); il.append(new NEW(cpg.addClass(MATCHING_ITERATOR))); il.append(DUP); il.append(new ILOAD(match.getIndex())); stepIteratorTemp.setEnd( il.append(new ALOAD(stepIteratorTemp.getIndex()))); il.append(new INVOKESPECIAL(index)); // Get the parent of the matching node il.append(methodGen.loadDOM()); il.append(new ILOAD(match.getIndex())); index = cpg.addInterfaceMethodref(DOM_INTF, GET_PARENT, GET_PARENT_SIG); il.append(new INVOKEINTERFACE(index, 2)); // Start the iterator with the parent il.append(methodGen.setStartNode()); // Overwrite current iterator and current node il.append(methodGen.storeIterator()); match.setEnd(il.append(new ILOAD(match.getIndex()))); il.append(methodGen.storeCurrentNode()); // Translate the expression of the predicate Predicate pred = (Predicate) _predicates.elementAt(0); Expression exp = pred.getExpr(); exp.translateDesynthesized(classGen, methodGen); // Backpatch true list and restore current iterator/node InstructionHandle restore = il.append(methodGen.storeIterator()); il.append(methodGen.storeCurrentNode()); exp.backPatchTrueList(restore); BranchHandle skipFalse = il.append(new GOTO(null)); // Backpatch false list and restore current iterator/node restore = il.append(methodGen.storeIterator()); il.append(methodGen.storeCurrentNode()); exp.backPatchFalseList(restore); _falseList.add(il.append(new GOTO(null))); // True list falls through skipFalse.setTarget(il.append(NOP)); }
Example 19
Source File: AbsoluteLocationPath.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
public void translate(ClassGenerator classGen, MethodGenerator methodGen) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); if (_path != null) { final int initAI = cpg.addMethodref(ABSOLUTE_ITERATOR, "<init>", "(" + NODE_ITERATOR_SIG + ")V"); // Compile relative path iterator(s) // // Backwards branches are prohibited if an uninitialized object is // on the stack by section 4.9.4 of the JVM Specification, 2nd Ed. // We don't know whether this code might contain backwards branches, // so we mustn't create the new object until after we've created // this argument to its constructor. Instead we calculate the // value of the argument to the constructor first, store it in // a temporary variable, create the object and reload the argument // from the temporary to avoid the problem. _path.translate(classGen, methodGen); LocalVariableGen relPathIterator = methodGen.addLocalVariable("abs_location_path_tmp", Util.getJCRefType(NODE_ITERATOR_SIG), null, null); relPathIterator.setStart( il.append(new ASTORE(relPathIterator.getIndex()))); // Create new AbsoluteIterator il.append(new NEW(cpg.addClass(ABSOLUTE_ITERATOR))); il.append(DUP); relPathIterator.setEnd( il.append(new ALOAD(relPathIterator.getIndex()))); // Initialize AbsoluteIterator with iterator from the stack il.append(new INVOKESPECIAL(initAI)); } else { final int gitr = cpg.addInterfaceMethodref(DOM_INTF, "getIterator", "()"+NODE_ITERATOR_SIG); il.append(methodGen.loadDOM()); il.append(new INVOKEINTERFACE(gitr, 1)); } }
Example 20
Source File: LiteralExpr.java From hottub with GNU General Public License v2.0 | 4 votes |
public void translate(ClassGenerator classGen, MethodGenerator methodGen) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); il.append(new PUSH(cpg, _value)); }