Package org.apache.bcel.generic

Examples of org.apache.bcel.generic.InstructionList


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


    public void translateTo(ClassGenerator classGen, MethodGenerator methodGen,
          BooleanType type) {
  // A result tree is always 'true' when converted to a boolean value,
  // since the tree always has at least one node (the root).
  final ConstantPoolGen cpg = classGen.getConstantPool();
  final InstructionList il = methodGen.getInstructionList();
  il.append(POP);      // don't need the DOM reference
  il.append(ICONST_1); // push 'true' on the stack
    }
View Full Code Here

     * @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();
 
  if (_methodName == null) {
      int index = cpg.addInterfaceMethodref(DOM_INTF,
              "getStringValue",
              "()"+STRING_SIG);
      il.append(new INVOKEINTERFACE(index, 1));
  }
  else {
      final String className = classGen.getClassName();
      final int current = methodGen.getLocalIndex("current");
     
      // Push required parameters
      il.append(classGen.loadTranslet());
      if (classGen.isExternal()) {
    il.append(new CHECKCAST(cpg.addClass(className)));
      }
      il.append(DUP);
      il.append(new GETFIELD(cpg.addFieldref(className, "_dom",
               DOM_INTF_SIG)));

      // Create a new instance of a StringValueHandler
      int index = cpg.addMethodref(STRING_VALUE_HANDLER, "<init>", "()V");
      il.append(new NEW(cpg.addClass(STRING_VALUE_HANDLER)));
      il.append(DUP);
      il.append(DUP);
      il.append(new INVOKESPECIAL(index));
     
      // Store new Handler into a local variable
      final LocalVariableGen handler =
    methodGen.addLocalVariable("rt_to_string_handler",
             Util.getJCRefType(STRING_VALUE_HANDLER_SIG),
             null, null);
      il.append(new ASTORE(handler.getIndex()));

      // Call the method that implements this result tree
      index = cpg.addMethodref(className, _methodName,
             "("+DOM_INTF_SIG+TRANSLET_OUTPUT_SIG+")V");
      il.append(new INVOKEVIRTUAL(index));
     
      // Restore new handler and call getValue()
      il.append(new ALOAD(handler.getIndex()));
      index = cpg.addMethodref(STRING_VALUE_HANDLER,
             "getValue",
             "()" + STRING_SIG);
      il.append(new INVOKEVIRTUAL(index));
  }
    }
View Full Code Here

     * @see org.apache.xalan.xsltc.compiler.util.Type#translateTo
     */
    public void translateTo(ClassGenerator classGen, MethodGenerator methodGen,
          ReferenceType type) {
  final ConstantPoolGen cpg = classGen.getConstantPool();
  final InstructionList il = methodGen.getInstructionList();

  if (_methodName == null) {
      il.append(NOP);
  }
  else {
      LocalVariableGen domBuilder, newDom;
      final String className = classGen.getClassName();
      final int current = methodGen.getLocalIndex("current");

      // Push required parameters
      il.append(classGen.loadTranslet());
      if (classGen.isExternal()) {
    il.append(new CHECKCAST(cpg.addClass(className)));
      }
      il.append(methodGen.loadDOM());

      // Create new instance of DOM class
      int index = cpg.addMethodref(DOM_IMPL, "<init>", "(I)V");
      il.append(new NEW(cpg.addClass(DOM_IMPL)));
      il.append(DUP);
      il.append(DUP);
      il.append(new PUSH(cpg, RTF_INITIAL_SIZE));
      il.append(new INVOKESPECIAL(index));
     
      // Store new DOM into a local variable
      newDom = methodGen.addLocalVariable("rt_to_reference_dom",
            Util.getJCRefType(DOM_INTF_SIG),
            null, null);
      il.append(new CHECKCAST(cpg.addClass(DOM_INTF_SIG)));
      il.append(new ASTORE(newDom.getIndex()));

      // Overwrite old handler with DOM handler
      index = cpg.addMethodref(DOM_IMPL,
             "getOutputDomBuilder",
             "()" + TRANSLET_OUTPUT_SIG);
      il.append(new INVOKEVIRTUAL(index));
      il.append(DUP);
      il.append(DUP);

      // Store DOM handler in a local in order to call endDocument()
      domBuilder =
    methodGen.addLocalVariable("rt_to_reference_handler",
             Util.getJCRefType(TRANSLET_OUTPUT_SIG),
             null, null);
      il.append(new ASTORE(domBuilder.getIndex()));

      // Call startDocument on the new handler
      index = cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE,
                "startDocument", "()V");
      il.append(new INVOKEINTERFACE(index, 1));

      // Call the method that implements this result tree
      index = cpg.addMethodref(className,
             _methodName,
             "("
             + DOM_INTF_SIG
             + TRANSLET_OUTPUT_SIG
             +")V");
      il.append(new INVOKEVIRTUAL(index));

      // Call endDocument on the DOM handler
      il.append(new ALOAD(domBuilder.getIndex()));
      index = cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE,
                "endDocument", "()V");
      il.append(new INVOKEINTERFACE(index, 1));

      // Push the new DOM on the stack
      il.append(new ALOAD(newDom.getIndex()));
  }
    }
View Full Code Here

     * @see org.apache.xalan.xsltc.compiler.util.Type#translateTo
     */
    public void translateTo(ClassGenerator classGen, MethodGenerator methodGen,
          NodeSetType type) {
  final ConstantPoolGen cpg = classGen.getConstantPool();
  final InstructionList il = methodGen.getInstructionList();

  // Put an extra copy of the result tree (DOM) on the stack
  il.append(DUP);

  // DOM adapters containing a result tree are not initialised with
  // translet-type to DOM-type mapping. This must be done now for
  // XPath expressions and patterns to work for the iterator we create.
  il.append(classGen.loadTranslet()); // get names array
  il.append(new GETFIELD(cpg.addFieldref(TRANSLET_CLASS,
                 NAMES_INDEX,
                 NAMES_INDEX_SIG)));
  il.append(classGen.loadTranslet()); // get namespaces array
  il.append(new GETFIELD(cpg.addFieldref(TRANSLET_CLASS,
                 NAMESPACE_INDEX,
                 NAMESPACE_INDEX_SIG)));
  // Pass the type mappings to the DOM adapter
  final int mapping = cpg.addInterfaceMethodref(DOM_INTF,
                  "setupMapping",
                  "(["+STRING_SIG+
                  "["+STRING_SIG+")V");
  il.append(new INVOKEINTERFACE(mapping, 3));
  il.append(DUP);

  // Create an iterator for the root node of the DOM adapter
  final int iter = cpg.addInterfaceMethodref(DOM_INTF,
               "getIterator",
               "()"+NODE_ITERATOR_SIG);
  il.append(new INVOKEINTERFACE(iter, 1))
    }
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();
  translateTo(classGen, methodGen, Type.Boolean);
  return new FlowList(il.append(new IFEQ(null)));
    }
View Full Code Here

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

  if (className.equals("org.w3c.dom.Node")) {
      translateTo(classGen, methodGen, Type.NodeSet);
      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")) {
      translateTo(classGen, methodGen, Type.NodeSet);
      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.Object")) {
      il.append(NOP);
  }
        else if (className.equals("java.lang.String")) {
            translateTo(classGen, methodGen, Type.String);
        }
        else if (clazz == Double.TYPE) {
View Full Code Here

     * @param instructionFactory
     */
    private static void createGetDefaultStaticMethod(ClassGen classGen,
            ConstantPoolGen constantPoolGen, InstructionFactory instructionFactory)
    {
        InstructionList il = new InstructionList();

        String methodName = "getDefault";
        MethodGen mg = new MethodGen(ACC_STATIC | ACC_PUBLIC, // access flags
                            Type.getType(SSLSocketFactory.class)// return type
                            new Type[0],   // argument types - no args
                            new String[0], // arg names - no args
                            methodName,
                            classGen.getClassName(),    // method, class
                            il,
                            constantPoolGen);

        il.append(instructionFactory.createNew(classGen.getClassName()));
        il.append(InstructionConstants.DUP);

        il.append(instructionFactory.createInvoke(classGen.getClassName(), "<init>", Type.VOID,
                                       new Type[] {},
                                       Constants.INVOKESPECIAL));

        il.append(InstructionConstants.ARETURN);

        mg.setMaxStack();
        classGen.addMethod(mg.getMethod());
        il.dispose();
    }
View Full Code Here

  _left.reduceKernelPattern();
    }
 
    public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
  final ConstantPoolGen cpg = classGen.getConstantPool();
  final InstructionList il = methodGen.getInstructionList();

  if (_left != null) {
      if (_left instanceof StepPattern) {
    final LocalVariableGen local =
        // absolute path pattern temporary
        methodGen.addLocalVariable2("apptmp",
            Util.getJCRefType(NODE_SIG),
            il.getEnd());
    il.append(DUP);
    il.append(new ISTORE(local.getIndex()));
    _left.translate(classGen, methodGen);
    il.append(methodGen.loadDOM());
    local.setEnd(il.append(new ILOAD(local.getIndex())));
    methodGen.removeLocalVariable(local);
      }
      else {
    _left.translate(classGen, methodGen);
      }
  }

  final int getParent = cpg.addInterfaceMethodref(DOM_INTF,
              GET_PARENT,
              GET_PARENT_SIG);
  final int getType = cpg.addInterfaceMethodref(DOM_INTF,
                  "getType", "(I)I");

  InstructionHandle begin = il.append(methodGen.loadDOM());
  il.append(SWAP);
  il.append(new INVOKEINTERFACE(getParent, 2));
  if (_left instanceof AncestorPattern) { 
      il.append(methodGen.loadDOM());
      il.append(SWAP);
  }
  il.append(new INVOKEINTERFACE(getType, 2));
  il.append(new PUSH(cpg, DOM.ROOT));
 
  final BranchHandle skip = il.append(new IF_ICMPEQ(null));
  _falseList.add(il.append(new GOTO_W(null)));
  skip.setTarget(il.append(NOP));

  if (_left != null) {
      _left.backPatchTrueList(begin);
     
      /*
 
View Full Code Here

    }

    public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
  InstructionHandle parent;
  final ConstantPoolGen cpg = classGen.getConstantPool();
  final InstructionList il = methodGen.getInstructionList();

  /*
   * The scope of this local var must be the entire method since
   * a another pattern may decide to jump back into the loop
   */
  final LocalVariableGen local =
      methodGen.addLocalVariable2("app", Util.getJCRefType(NODE_SIG),
          il.getEnd());

  final org.apache.bcel.generic.Instruction loadLocal =
      new ILOAD(local.getIndex());
  final org.apache.bcel.generic.Instruction storeLocal =
      new ISTORE(local.getIndex());

  if (_right instanceof StepPattern) {
      il.append(DUP);
      il.append(storeLocal);
      _right.translate(classGen, methodGen);
      il.append(methodGen.loadDOM());
      il.append(loadLocal);
  }
  else {
      _right.translate(classGen, methodGen);

      if (_right instanceof AncestorPattern) {
    il.append(methodGen.loadDOM());
    il.append(SWAP);
      }
  }

  if (_left != null) {
      final int getParent = cpg.addInterfaceMethodref(DOM_INTF,
                  GET_PARENT,
                  GET_PARENT_SIG);
      parent = il.append(new INVOKEINTERFACE(getParent, 2));
     
      il.append(DUP);
      il.append(storeLocal);
      _falseList.add(il.append(new IFEQ(null)));
      il.append(loadLocal);

      _left.translate(classGen, methodGen);

      final SyntaxTreeNode p = getParent();
      if (p == null || p instanceof Instruction ||
    p instanceof TopLevelElement)
      {
    // do nothing
      }
      else {
    il.append(loadLocal);
      }

      final BranchHandle exit = il.append(new GOTO(null));
      _loop = il.append(methodGen.loadDOM());
      il.append(loadLocal);
      local.setEnd(_loop);
      il.append(new GOTO(parent));
      exit.setTarget(il.append(NOP));
      _left.backPatchFalseList(_loop);

      _trueList.append(_left._trueList)
  }
  else {
      il.append(POP2);
  }
 
  /*
   * If _right is an ancestor pattern, backpatch this pattern's false
   * list to the loop that searches for more ancestors.
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.