/** * Back patch a flow list. All instruction handles must be branch handles. */ public void backPatch(InstructionHandle target) { if (_elements != null) { final int n = _elements.size(); for (int i = 0; i < n; i++) { BranchHandle bh = (BranchHandle)_elements.elementAt(i); bh.setTarget(target); } _elements.clear(); // avoid backpatching more than once } }
public static void compilePreserveSpace(BranchHandle preserve[], int pCount, InstructionList il) { final InstructionHandle target = il.append(ICONST_0); il.append(IRETURN); for (int i = 0; i < pCount; i++) { preserve[i].setTarget(target); } }
public static void compileStripSpace(BranchHandle strip[], int sCount, InstructionList il) { final InstructionHandle target = il.append(ICONST_1); il.append(IRETURN); for (int i = 0; i < sCount; i++) { strip[i].setTarget(target); } }
/** * Expects an integer on the stack and pushes a 0 if its value is 0 and * a 1 otherwise. * * @see org.apache.xalan.xsltc.compiler.util.Type#translateTo */ public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, BooleanType type) { final InstructionList il = methodGen.getInstructionList(); final BranchHandle falsec = il.append(new IFEQ(null)); il.append(ICONST_1); final BranchHandle truec = il.append(new GOTO(null)); falsec.setTarget(il.append(ICONST_0)); truec.setTarget(il.append(NOP)); }
/** * 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 org.apache.xalan.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)); }
/** * Translates a node-set into a string. The string value of a node-set is * value of its first element. * * @see org.apache.xalan.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)); }
/** * Translates an external (primitive) Java type into a string. * * @see org.apache.xalan.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); } }
/** * Translates a string into a synthesized boolean. * * @see org.apache.xalan.xsltc.compiler.util.Type#translateTo */ public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, BooleanType type) { final InstructionList il = methodGen.getInstructionList(); FlowList falsel = translateToDesynthesized(classGen, methodGen, type); il.append(ICONST_1); final BranchHandle truec = il.append(new GOTO(null)); falsel.backPatch(il.append(ICONST_0)); truec.setTarget(il.append(NOP)); }
/** * Expects a real on the stack and pushes a 0 if that number is 0.0 and * a 1 otherwise. * * @see org.apache.xalan.xsltc.compiler.util.Type#translateTo */ public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, BooleanType type) { final InstructionList il = methodGen.getInstructionList(); FlowList falsel = translateToDesynthesized(classGen, methodGen, type); il.append(ICONST_1); final BranchHandle truec = il.append(new GOTO(null)); falsel.backPatch(il.append(ICONST_0)); truec.setTarget(il.append(NOP)); }
/** * Expects an integer on the stack and pushes its string value by calling * <code>Integer.toString(int i)</code>. * * @see org.apache.xalan.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)); }
/** * Translates a node-set into a synthesized boolean. * The boolean value of a node-set is "true" if non-empty * and "false" otherwise. Notice that the * function getFirstNode() is called in translateToDesynthesized(). * * @see org.apache.xalan.xsltc.compiler.util.Type#translateTo */ public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, BooleanType type) { final InstructionList il = methodGen.getInstructionList(); FlowList falsel = translateToDesynthesized(classGen, methodGen, type); il.append(ICONST_1); final BranchHandle truec = il.append(new GOTO(null)); falsel.backPatch(il.append(ICONST_0)); truec.setTarget(il.append(NOP)); }
/** * Translates a node into a synthesized boolean. * If the expression is "@attr", * then "true" is pushed iff "attr" is an attribute of the current node. * If the expression is ".", the result is always "true". * * @see org.apache.xalan.xsltc.compiler.util.Type#translateTo */ public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, BooleanType type) { final InstructionList il = methodGen.getInstructionList(); FlowList falsel = translateToDesynthesized(classGen, methodGen, type); il.append(ICONST_1); final BranchHandle truec = il.append(new GOTO(null)); falsel.backPatch(il.append(ICONST_0)); truec.setTarget(il.append(NOP)); }
/** * Synthesize a boolean expression, i.e., either push a 0 or 1 onto the * operand stack for the next statement to succeed. Returns the handle * of the instruction to be backpatched. */ public void synthesize(ClassGenerator classGen, MethodGenerator methodGen) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); _trueList.backPatch(il.append(ICONST_1)); final BranchHandle truec = il.append(new GOTO_W(null)); _falseList.backPatch(il.append(ICONST_0)); truec.setTarget(il.append(NOP)); }
skipFalse.setTarget(il.append(NOP));
nextNode.setTarget(il.append(methodGen.loadIterator())); il.append(methodGen.nextNode()); il.append(DUP);
skipFalse.setTarget(il.append(NOP));
skip.setTarget(il.append(NOP));
il.append(new INVOKEVIRTUAL(keyDom)); nextNode.setTarget(il.append(methodGen.loadIterator())); il.append(methodGen.nextNode());