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

The following examples show how to use com.sun.org.apache.bcel.internal.generic.InstructionList. 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: FunctionCall.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Compile the function call and treat as an expression
 * Update true/false-lists.
 */
@Override
public void translateDesynthesized(ClassGenerator classGen,
                                   MethodGenerator methodGen)
{
    Type type = Type.Boolean;
    if (_chosenMethodType != null)
        type = _chosenMethodType.resultType();

    final InstructionList il = methodGen.getInstructionList();
    translate(classGen, methodGen);

    if ((type instanceof BooleanType) || (type instanceof IntType)) {
        _falseList.add(il.append(new IFEQ(null)));
    }
}
 
Example #2
Source File: PositionCall.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final InstructionList il = methodGen.getInstructionList();

    if (methodGen instanceof CompareGenerator) {
        il.append(((CompareGenerator)methodGen).loadCurrentNode());
    }
    else if (methodGen instanceof TestGenerator) {
        il.append(new ILOAD(POSITION_INDEX));
    }
    else {
        final ConstantPoolGen cpg = classGen.getConstantPool();
        final int index = cpg.addInterfaceMethodref(NODE_ITERATOR,
                                                   "getPosition",
                                                   "()I");

        il.append(methodGen.loadIterator());
        il.append(new INVOKEINTERFACE(index,1));
    }
}
 
Example #3
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 #4
Source File: PositionCall.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final InstructionList il = methodGen.getInstructionList();

    if (methodGen instanceof CompareGenerator) {
        il.append(((CompareGenerator)methodGen).loadCurrentNode());
    }
    else if (methodGen instanceof TestGenerator) {
        il.append(new ILOAD(POSITION_INDEX));
    }
    else {
        final ConstantPoolGen cpg = classGen.getConstantPool();
        final int index = cpg.addInterfaceMethodref(NODE_ITERATOR,
                                                   "getPosition",
                                                   "()I");

        il.append(methodGen.loadIterator());
        il.append(new INVOKEINTERFACE(index,1));
    }
}
 
Example #5
Source File: FlowList.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Redirect the handles from oldList to newList. "This" flow list
 * is assumed to be relative to oldList.
 */
public FlowList copyAndRedirect(InstructionList oldList,
    InstructionList newList)
{
    final FlowList result = new FlowList();
    if (_elements == null) {
        return result;
    }

    final int n = _elements.size();
    final Iterator<InstructionHandle> oldIter = oldList.iterator();
    final Iterator<InstructionHandle> newIter = newList.iterator();

    while (oldIter.hasNext()) {
        final InstructionHandle oldIh = oldIter.next();
        final InstructionHandle newIh = newIter.next();

        for (int i = 0; i < n; i++) {
            if (_elements.get(i) == oldIh) {
                result.add(newIh);
            }
        }
    }
    return result;
}
 
Example #6
Source File: PositionCall.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final InstructionList il = methodGen.getInstructionList();

    if (methodGen instanceof CompareGenerator) {
        il.append(((CompareGenerator)methodGen).loadCurrentNode());
    }
    else if (methodGen instanceof TestGenerator) {
        il.append(new ILOAD(POSITION_INDEX));
    }
    else {
        final ConstantPoolGen cpg = classGen.getConstantPool();
        final int index = cpg.addInterfaceMethodref(NODE_ITERATOR,
                                                   "getPosition",
                                                   "()I");

        il.append(methodGen.loadIterator());
        il.append(new INVOKEINTERFACE(index,1));
    }
}
 
Example #7
Source File: FunctionCall.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Compile the function call and treat as an expression
 * Update true/false-lists.
 */
@Override
public void translateDesynthesized(ClassGenerator classGen,
                                   MethodGenerator methodGen)
{
    Type type = Type.Boolean;
    if (_chosenMethodType != null)
        type = _chosenMethodType.resultType();

    final InstructionList il = methodGen.getInstructionList();
    translate(classGen, methodGen);

    if ((type instanceof BooleanType) || (type instanceof IntType)) {
        _falseList.add(il.append(new IFEQ(null)));
    }
}
 
Example #8
Source File: Mode.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Compiles the default action for DOM text nodes and attribute nodes:
 * output the node's text value
 */
private InstructionList compileDefaultText(ClassGenerator classGen,
                                           MethodGenerator methodGen,
                                           InstructionHandle next) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = new InstructionList();

    final int chars = cpg.addInterfaceMethodref(DOM_INTF,
                                                CHARACTERS,
                                                CHARACTERS_SIG);
    il.append(methodGen.loadDOM());
    il.append(new ILOAD(_currentIndex));
    il.append(methodGen.loadHandler());
    il.append(new INVOKEINTERFACE(chars, 3));
    il.append(new GOTO_W(next));
    return il;
}
 
Example #9
Source File: FlowList.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Redirect the handles from oldList to newList. "This" flow list
 * is assumed to be relative to oldList.
 */
public FlowList copyAndRedirect(InstructionList oldList,
    InstructionList newList)
{
    final FlowList result = new FlowList();
    if (_elements == null) {
        return result;
    }

    final int n = _elements.size();
    final Iterator oldIter = oldList.iterator();
    final Iterator newIter = newList.iterator();

    while (oldIter.hasNext()) {
        final InstructionHandle oldIh = (InstructionHandle) oldIter.next();
        final InstructionHandle newIh = (InstructionHandle) newIter.next();

        for (int i = 0; i < n; i++) {
            if (_elements.elementAt(i) == oldIh) {
                result.add(newIh);
            }
        }
    }
    return result;
}
 
Example #10
Source File: CeilingCall.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    argument(0).translate(classGen, methodGen);
    il.append(new INVOKESTATIC(cpg.addMethodref(MATH_CLASS,
                                                "ceil", "(D)D")));
}
 
Example #11
Source File: MatchGenerator.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
public MatchGenerator(int access_flags, Type return_type,
                      Type[] arg_types, String[] arg_names,
                      String method_name, String class_name,
                      InstructionList il, ConstantPoolGen cp) {
    super(access_flags, return_type, arg_types, arg_names, method_name,
          class_name, il, cp);

    _iloadCurrent = new ILOAD(CURRENT_INDEX);
    _istoreCurrent = new ISTORE(CURRENT_INDEX);
}
 
Example #12
Source File: NodeSetType.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Some type conversions require gettting the first node from the node-set.
 * This function is defined to avoid code repetition.
 */
private void getFirstNode(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    il.append(new INVOKEINTERFACE(cpg.addInterfaceMethodref(NODE_ITERATOR,
                                                            NEXT,
                                                            NEXT_SIG), 1));
}
 
Example #13
Source File: BinOpExpr.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final InstructionList il = methodGen.getInstructionList();

    _left.translate(classGen, methodGen);
    _right.translate(classGen, methodGen);

    switch (_op) {
    case PLUS:
        il.append(_type.ADD());
        break;
    case MINUS:
        il.append(_type.SUB());
        break;
    case TIMES:
        il.append(_type.MUL());
        break;
    case DIV:
        il.append(_type.DIV());
        break;
    case MOD:
        il.append(_type.REM());
        break;
    default:
        ErrorMsg msg = new ErrorMsg(ErrorMsg.ILLEGAL_BINARY_OP_ERR, this);
        getParser().reportError(Constants.ERROR, msg);
    }
}
 
Example #14
Source File: BinOpExpr.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final InstructionList il = methodGen.getInstructionList();

    _left.translate(classGen, methodGen);
    _right.translate(classGen, methodGen);

    switch (_op) {
    case PLUS:
        il.append(_type.ADD());
        break;
    case MINUS:
        il.append(_type.SUB());
        break;
    case TIMES:
        il.append(_type.MUL());
        break;
    case DIV:
        il.append(_type.DIV());
        break;
    case MOD:
        il.append(_type.REM());
        break;
    default:
        ErrorMsg msg = new ErrorMsg(ErrorMsg.ILLEGAL_BINARY_OP_ERR, this);
        getParser().reportError(Constants.ERROR, msg);
    }
}
 
Example #15
Source File: RealType.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Translates an object of this type to its unboxed representation.
 */
public void translateUnBox(ClassGenerator classGen,
                           MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    il.append(new CHECKCAST(cpg.addClass(DOUBLE_CLASS)));
    il.append(new INVOKEVIRTUAL(cpg.addMethodref(DOUBLE_CLASS,
                                                 DOUBLE_VALUE,
                                                 DOUBLE_VALUE_SIG)));
}
 
Example #16
Source File: NamespaceUriCall.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Translate code that leaves a node's namespace URI (as a String)
 * on the stack
 */
public void translate(ClassGenerator classGen,
                      MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    // Returns the string value for a node in the DOM
    final int getNamespace = cpg.addInterfaceMethodref(DOM_INTF,
                                                       "getNamespaceName",
                                                       "(I)"+STRING_SIG);
    super.translate(classGen, methodGen);
    il.append(new INVOKEINTERFACE(getNamespace, 2));
}
 
Example #17
Source File: GenerateIdCall.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final InstructionList il = methodGen.getInstructionList();
    if (argumentCount() == 0) {
       il.append(methodGen.loadContextNode());
    }
    else {                  // one argument
        argument().translate(classGen, methodGen);
    }
    final ConstantPoolGen cpg = classGen.getConstantPool();
    il.append(new INVOKESTATIC(cpg.addMethodref(BASIS_LIBRARY_CLASS,
                                                "generate_idF",
                                                // reuse signature
                                                GET_NODE_NAME_SIG)));
}
 
Example #18
Source File: ReferenceType.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Translates a reference into an 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,
                        RealType type) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    il.append(methodGen.loadDOM());
    int index = cpg.addMethodref(BASIS_LIBRARY_CLASS, "numberF",
                                 "("
                                 + OBJECT_SIG
                                 + DOM_INTF_SIG
                                 + ")D");
    il.append(new INVOKESTATIC(index));
}
 
Example #19
Source File: Expression.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Translate this node into a fresh instruction list.
 * The original instruction list is saved and restored.
 */
public final InstructionList compile(ClassGenerator classGen,
                                     MethodGenerator methodGen) {
    final InstructionList result, save = methodGen.getInstructionList();
    methodGen.setInstructionList(result = new InstructionList());
    translate(classGen, methodGen);
    methodGen.setInstructionList(save);
    return result;
}
 
Example #20
Source File: BooleanExpr.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void translateDesynthesized(ClassGenerator classGen,
                                   MethodGenerator methodGen) {
    final InstructionList il = methodGen.getInstructionList();
    if (_value) {
        il.append(NOP);     // true list falls through
    }
    else {
        _falseList.add(il.append(new GOTO(null)));
    }
}
 
Example #21
Source File: RelationalExpr.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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 #22
Source File: NodeType.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Expects a node on the stack and pushes a singleton node-set. Singleton
 * iterators are already started after construction.
 *
 * @see     com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo
 */
public void translateTo(ClassGenerator classGen, MethodGenerator methodGen,
                        NodeSetType type) {
    ConstantPoolGen cpg = classGen.getConstantPool();
    InstructionList il = methodGen.getInstructionList();

    // Create a new instance of SingletonIterator
    il.append(new NEW(cpg.addClass(SINGLETON_ITERATOR)));
    il.append(DUP_X1);
    il.append(SWAP);
    final int init = cpg.addMethodref(SINGLETON_ITERATOR, "<init>",
                                      "(" + NODE_SIG +")V");
    il.append(new INVOKESPECIAL(init));
}
 
Example #23
Source File: Fallback.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Translate contents only if this fallback element is put in place of
 * some unsupported element or non-XSLTC extension element
 */
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    if (_active) translateContents(classGen, methodGen);
}
 
Example #24
Source File: BooleanType.java    From openjdk-8-source 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 #25
Source File: ReferenceType.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Casts a reference into a ResultTree.
 *
 * @see     com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo
 */
public void translateTo(ClassGenerator classGen, MethodGenerator methodGen,
                        ResultTreeType type) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    int index = cpg.addMethodref(BASIS_LIBRARY_CLASS, "referenceToResultTree",
                                 "(" + OBJECT_SIG + ")" + DOM_INTF_SIG);
    il.append(new INVOKESTATIC(index));
}
 
Example #26
Source File: IntType.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Expects an integer on the stack and pushes a boxed integer.
 * Boxed integers are represented by an instance of
 * <code>java.lang.Integer</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(INTEGER_CLASS)));
    il.append(DUP_X1);
    il.append(SWAP);
    il.append(new INVOKESPECIAL(cpg.addMethodref(INTEGER_CLASS,
                                                 "<init>", "(I)V")));
}
 
Example #27
Source File: VariableBase.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Map this variable to a register
 */
public void mapRegister(MethodGenerator methodGen) {
    if (_local == null) {
        final InstructionList il = methodGen.getInstructionList();
        final String name = getEscapedName(); // TODO: namespace ?
        final com.sun.org.apache.bcel.internal.generic.Type varType = _type.toJCType();
        _local = methodGen.addLocalVariable2(name, varType, il.getEnd());
    }
}
 
Example #28
Source File: CeilingCall.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    argument(0).translate(classGen, methodGen);
    il.append(new INVOKESTATIC(cpg.addMethodref(MATH_CLASS,
                                                "ceil", "(D)D")));
}
 
Example #29
Source File: StringType.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Translates a string into a real by calling stringToReal() from the
 * basis library.
 *
 * @see     com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo
 */
public void translateTo(ClassGenerator classGen, MethodGenerator methodGen,
                        RealType type) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    il.append(new INVOKESTATIC(cpg.addMethodref(BASIS_LIBRARY_CLASS,
                                                STRING_TO_REAL,
                                                STRING_TO_REAL_SIG)));
}
 
Example #30
Source File: ReferenceType.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Casts a reference into a ResultTree.
 *
 * @see     com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#translateTo
 */
public void translateTo(ClassGenerator classGen, MethodGenerator methodGen,
                        ResultTreeType type) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    int index = cpg.addMethodref(BASIS_LIBRARY_CLASS, "referenceToResultTree",
                                 "(" + OBJECT_SIG + ")" + DOM_INTF_SIG);
    il.append(new INVOKESTATIC(index));
}