com.sun.org.apache.bcel.internal.generic.BranchHandle Java Examples

The following examples show how to use com.sun.org.apache.bcel.internal.generic.BranchHandle. 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: StringType.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 #2
Source File: ObjectType.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * 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 #3
Source File: StringType.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #4
Source File: StringType.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 #5
Source File: ObjectType.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 #6
Source File: StringType.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * 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: Whitespace.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example #8
Source File: NodeType.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * 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     com.sun.org.apache.xalan.internal.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));
}
 
Example #9
Source File: NodeSetType.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 #10
Source File: StringType.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Translates a string into a synthesized boolean.
 *
 * @see     com.sun.org.apache.xalan.internal.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));
}
 
Example #11
Source File: IntType.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Expects an integer on the stack and pushes a 0 if its value is 0 and
 * a 1 otherwise.
 *
 * @see     com.sun.org.apache.xalan.internal.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));
}
 
Example #12
Source File: BooleanType.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 #13
Source File: FlowList.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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
    }
}
 
Example #14
Source File: BooleanType.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 #15
Source File: Whitespace.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
}
 
Example #16
Source File: NodeType.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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     com.sun.org.apache.xalan.internal.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));
}
 
Example #17
Source File: NodeSetType.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 #18
Source File: Whitespace.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
}
 
Example #19
Source File: Expression.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * 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));
}
 
Example #20
Source File: NotCall.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
public void translateDesynthesized(ClassGenerator classGen,
                                   MethodGenerator methodGen) {
    final InstructionList il = methodGen.getInstructionList();
    final Expression exp = argument();
    exp.translateDesynthesized(classGen, methodGen);
    final BranchHandle gotoh = il.append(new GOTO(null));
    _trueList = exp._falseList;     // swap flow lists
    _falseList = exp._trueList;
    _falseList.add(gotoh);
}
 
Example #21
Source File: Expression.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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));
}
 
Example #22
Source File: Whitespace.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
}
 
Example #23
Source File: Whitespace.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
}
 
Example #24
Source File: Whitespace.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
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);
    }
}
 
Example #25
Source File: IntType.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Expects an integer on the stack and pushes a 0 if its value is 0 and
 * a 1 otherwise.
 *
 * @see     com.sun.org.apache.xalan.internal.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));
}
 
Example #26
Source File: BooleanType.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 #27
Source File: NodeSetType.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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     com.sun.org.apache.xalan.internal.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));
}
 
Example #28
Source File: NodeSetType.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 #29
Source File: Expression.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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));
}
 
Example #30
Source File: RealType.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Expects a real on the stack and pushes a 0 if that number is 0.0 and
 * a 1 otherwise.
 *
 * @see     com.sun.org.apache.xalan.internal.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));
}