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 Project: jdk1.8-source-analysis   Author: raysonfang   File: StringType.java    License: 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 #2
Source Project: TencentKona-8   Author: Tencent   File: StringType.java    License: 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 #3
Source Project: TencentKona-8   Author: Tencent   File: ObjectType.java    License: 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 #4
Source Project: JDKSourceCode1.8   Author: wupeixuan   File: StringType.java    License: 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 #5
Source Project: jdk8u60   Author: chenghanpeng   File: StringType.java    License: 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 #6
Source Project: JDKSourceCode1.8   Author: wupeixuan   File: ObjectType.java    License: 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 #7
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: FlowList.java    License: Apache License 2.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 #8
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: FlowList.java    License: 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 #9
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: NotCall.java    License: Apache License 2.0 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 #10
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: Whitespace.java    License: 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 #11
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: Whitespace.java    License: 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 #12
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: Whitespace.java    License: Apache License 2.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 #13
Source Project: JDKSourceCode1.8   Author: wupeixuan   File: IntType.java    License: 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 #14
Source Project: JDKSourceCode1.8   Author: wupeixuan   File: NodeSetType.java    License: MIT License 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 #15
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: RealType.java    License: Apache License 2.0 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));
}
 
Example #16
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: NotCall.java    License: GNU General Public License v2.0 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 #17
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: NodeType.java    License: Apache License 2.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 #18
Source Project: TencentKona-8   Author: Tencent   File: FlowList.java    License: 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 #19
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: NodeType.java    License: 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 #20
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: NodeSetType.java    License: 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 #21
Source Project: TencentKona-8   Author: Tencent   File: Expression.java    License: 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 Project: TencentKona-8   Author: Tencent   File: Whitespace.java    License: 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 Project: TencentKona-8   Author: Tencent   File: Whitespace.java    License: 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 Project: TencentKona-8   Author: Tencent   File: IntType.java    License: 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 #25
Source Project: TencentKona-8   Author: Tencent   File: BooleanType.java    License: 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 #26
Source Project: TencentKona-8   Author: Tencent   File: NodeSetType.java    License: 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 #27
Source Project: TencentKona-8   Author: Tencent   File: NodeSetType.java    License: 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 #28
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: Expression.java    License: 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 #29
Source Project: JDKSourceCode1.8   Author: wupeixuan   File: RealType.java    License: 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));
}
 
Example #30
Source Project: JDKSourceCode1.8   Author: wupeixuan   File: Whitespace.java    License: 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);
    }
}