Package org.apache.bcel.generic

Examples of org.apache.bcel.generic.InstructionList


        clazz.addMethod(mg.getMethod());
    }

    static void generateSuperMethod(ClassGen clazz, MethodRef method) {
        ConstantPoolGen cp;
        InstructionList il;

        cp = clazz.getConstantPool();
        il = new InstructionList();

        InstructionFactory fac = new InstructionFactory(clazz, cp);

        Type methodReturnType = translate(method.getReturnType());
        Type[] methodArgTypes = translate(method.getParameterTypes());

        MethodGen mg = new MethodGen(
                Constants.ACC_FINAL | Constants.ACC_PUBLIC, methodReturnType,
                methodArgTypes, null, // arg names
                method.getName(), clazz.getClassName(), il, cp);

        mg.addAttribute(new Synthetic(cp.addUtf8("Synthetic"), 0, null, cp
                .getConstantPool()));

        Class[] throwsException = method.getExceptionTypes();
        for (int i = 0; i < throwsException.length; i++) {
            mg.addException(throwsException[i].getName());
        }

        // push this
        il.append(InstructionFactory.createThis());

        // push arguments
        int index = 1;
        for (int i = 0; i < methodArgTypes.length; i++) {
            emitLoad(il, index, methodArgTypes[i]);
            index += methodArgTypes[i].getSize();
        }

        // call method
        il.append(new INVOKESPECIAL(cp.addMethodref(method.getDeclaringClass()
                .getName(), method.getName(), method.getSignature())));

        emitReturn(il, methodReturnType);

        //
View Full Code Here


     */
    public void translateFrom(ClassGenerator classGen,
  MethodGenerator methodGen, Class clazz)
    {
   
    InstructionList il = methodGen.getInstructionList();
  ConstantPoolGen cpg = classGen.getConstantPool();
  if (clazz.getName().equals("org.w3c.dom.NodeList")) {
     // w3c NodeList is on the stack from the external Java function call.
     // call BasisFunction to consume NodeList and leave Iterator on
     //    the stack.
     il.append(classGen.loadTranslet());   // push translet onto stack
     il.append(methodGen.loadDOM());      // push DOM onto stack
     final int convert = cpg.addMethodref(BASIS_LIBRARY_CLASS,
          "nodeList2Iterator",
          "("   
           + "Lorg/w3c/dom/NodeList;"
           + TRANSLET_INTF_SIG
           + DOM_INTF_SIG
           + ")" + NODE_ITERATOR_SIG );
     il.append(new INVOKESTATIC(convert));
  }
  else if (clazz.getName().equals("org.w3c.dom.Node")) {
     // w3c Node is on the stack from the external Java function call.
     // call BasisLibrary.node2Iterator() to consume Node and leave
     // Iterator on the stack.
     il.append(classGen.loadTranslet());   // push translet onto stack
     il.append(methodGen.loadDOM());      // push DOM onto stack
     final int convert = cpg.addMethodref(BASIS_LIBRARY_CLASS,
          "node2Iterator",
          "("   
           + "Lorg/w3c/dom/Node;"
           + TRANSLET_INTF_SIG
           + DOM_INTF_SIG
           + ")" + NODE_ITERATOR_SIG );
     il.append(new INVOKESTATIC(convert));
  }
  else {
      ErrorMsg err = new ErrorMsg(ErrorMsg.DATA_CONVERSION_ERR,
    toString(), clazz.getName());
      classGen.getParser().reportError(Constants.FATAL, err);
View Full Code Here

     *
     * @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));
    }
View Full Code Here

     *
     * @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 IFEQ(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));
    }
View Full Code Here

     * @see  org.apache.xalan.xsltc.compiler.util.Type#translateToDesynthesized
     */
    public FlowList translateToDesynthesized(ClassGenerator classGen,
               MethodGenerator methodGen,
               BooleanType type) {
  final InstructionList il = methodGen.getInstructionList();
  getFirstNode(classGen, methodGen);
  return new FlowList(il.append(new IFEQ(null)));
    }
View Full Code Here

     * type after coercion.
     */
    public void translateTo(ClassGenerator classGen, MethodGenerator methodGen,
          Class clazz) {
  final ConstantPoolGen cpg = classGen.getConstantPool();
  final InstructionList il = methodGen.getInstructionList();
  final String className = clazz.getName();

  il.append(methodGen.loadDOM());
  il.append(SWAP);

  if (className.equals("org.w3c.dom.Node")) {
      int index = cpg.addInterfaceMethodref(DOM_INTF,
              MAKE_NODE,
              MAKE_NODE_SIG2);
      il.append(new INVOKEINTERFACE(index, 2));
  }
        else if (className.equals("org.w3c.dom.NodeList") ||
                 className.equals("java.lang.Object")) {
      int index = cpg.addInterfaceMethodref(DOM_INTF,
              MAKE_NODE_LIST,
              MAKE_NODE_LIST_SIG2);
      il.append(new INVOKEINTERFACE(index, 2));
  }
        else if (className.equals("java.lang.String")) {
            int next = cpg.addInterfaceMethodref(NODE_ITERATOR,
                                                 "next", "()I");
            int index = cpg.addInterfaceMethodref(DOM_INTF,
                                                 GET_NODE_VALUE,
                                                 "(I)"+STRING_SIG);

            // Get next node from the iterator
            il.append(new INVOKEINTERFACE(next, 1));
            // Get the node's string value (from the DOM)
            il.append(new INVOKEINTERFACE(index, 2));
                      
        }
  else if (className.equals("int")) {
      int next = cpg.addInterfaceMethodref(NODE_ITERATOR,
              "next", "()I");
      int index = cpg.addInterfaceMethodref(DOM_INTF,
              GET_NODE_VALUE,
              "(I)"+STRING_SIG);
      int str = cpg.addMethodref(BASIS_LIBRARY_CLASS,
          STRING_TO_INT,
          STRING_TO_INT_SIG);

      // Get next node from the iterator
      il.append(new INVOKEINTERFACE(next, 1));
      // Get the node's string value (from the DOM)
      il.append(new INVOKEINTERFACE(index, 2));
      // Create a new Integer object from the string value
      il.append(new INVOKESTATIC(str));
  }
  else {
      ErrorMsg err = new ErrorMsg(ErrorMsg.DATA_CONVERSION_ERR,
          toString(), className);
      classGen.getParser().reportError(Constants.FATAL, err);
View Full Code Here

     * 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));
    }
View Full Code Here

     *
     * @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));
    }
View Full Code Here

     * @see  org.apache.xalan.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)));
    }
View Full Code Here

     */
    public FlowList translateToDesynthesized(ClassGenerator classGen,
               MethodGenerator methodGen,
               BooleanType type) {
  final ConstantPoolGen cpg = classGen.getConstantPool();
  final InstructionList il = methodGen.getInstructionList();

  il.append(new INVOKEVIRTUAL(cpg.addMethodref(STRING_CLASS,
                 "length", "()I")));
  return new FlowList(il.append(new IFEQ(null)));
    }
View Full Code Here

TOP

Related Classes of org.apache.bcel.generic.InstructionList

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.