Package org.apache.bcel.generic

Examples of org.apache.bcel.generic.LocalVariableGen


      body.byte_code(il, method, cp);

      if(main) {
  ObjectType e_type = new ObjectType("java.lang.Exception");
  InstructionHandle start = il.getStart(), end, handler, end_handler;
  LocalVariableGen exc = method.addLocalVariable("$e",
                   e_type,
                   null, null);
  int slot = exc.getIndex();

  il.append(InstructionConstants.POP); pop(); // Remove last element on stack
  end = il.append(InstructionConstants.RETURN); // Use instruction constants, if possible

  // catch
  handler = il.append(new ASTORE(slot)); // save exception object
  il.append(new GETSTATIC(cp.addFieldref("java.lang.System", "err",
                 "Ljava/io/PrintStream;")));
  il.append(new ALOAD(slot)); push(2);
  il.append(new INVOKEVIRTUAL(cp.addMethodref("java.io.PrintStream",
            "println",
            "(Ljava/lang/Object;)V")));
  pop(2);
  end_handler = il.append(InstructionConstants.RETURN);
  method.addExceptionHandler(start, end, handler, e_type);
  exc.setStart(handler); exc.setEnd(end_handler);
      } else {
        il.append(InstructionConstants.IRETURN); // Reuse object to save memory
    }

      method.removeNOPs(); // First optimization pass, provided by MethodGen
View Full Code Here


        // in temporary variables, create the object and reload the
        // arguments from the temporaries to avoid the problem.

  // Compile path iterator
  _path.translate(classGen, methodGen); // iterator on stack....
        LocalVariableGen pathTemp
                = methodGen.addLocalVariable("parent_location_path_tmp1",
                                         Util.getJCRefType(NODE_ITERATOR_SIG),
                                         il.getEnd(), null);
        il.append(new ASTORE(pathTemp.getIndex()));

  _step.translate(classGen, methodGen);
        LocalVariableGen stepTemp
                = methodGen.addLocalVariable("parent_location_path_tmp2",
                                         Util.getJCRefType(NODE_ITERATOR_SIG),
                                         il.getEnd(), null);
        il.append(new ASTORE(stepTemp.getIndex()));

  // Create new StepIterator
  final int initSI = cpg.addMethodref(STEP_ITERATOR_CLASS,
              "<init>",
              "("
              +NODE_ITERATOR_SIG
              +NODE_ITERATOR_SIG
              +")V");
  il.append(new NEW(cpg.addClass(STEP_ITERATOR_CLASS)));
  il.append(DUP);

        il.append(new ALOAD(pathTemp.getIndex()));
        il.append(new ALOAD(stepTemp.getIndex()));

  // Initialize StepIterator with iterators from the stack
  il.append(new INVOKESPECIAL(initSI));

  // This is a special case for the //* path with or without predicates
View Full Code Here

      il.append(methodGen.namespace());
  }
   
        if (!_isLiteral) {
            // if the qname is an AVT, then the qname has to be checked at runtime if it is a valid qname
            LocalVariableGen nameValue = methodGen.addLocalVariable2("nameValue",
                    Util.getJCRefType(STRING_SIG),
                    il.getEnd());
                   
            // store the name into a variable first so _name.translate only needs to be called once 
            _name.translate(classGen, methodGen);
            il.append(new ASTORE(nameValue.getIndex()));
            il.append(new ALOAD(nameValue.getIndex()));
           
            // call checkQName if the name is an AVT
            final int check = cpg.addMethodref(BASIS_LIBRARY_CLASS, "checkAttribQName",
                            "("
                            +STRING_SIG
                            +")V");                
            il.append(new INVOKESTATIC(check));
           
            // Save the current handler base on the stack
            il.append(methodGen.loadHandler());
            il.append(DUP);     // first arg to "attributes" call           
           
            // load name value again   
            il.append(new ALOAD(nameValue.getIndex()));           
        } else {   
            // Save the current handler base on the stack
            il.append(methodGen.loadHandler());
            il.append(DUP);     // first arg to "attributes" call
           
View Full Code Here

    private void compileLocals(NodeCounterGenerator nodeCounterGen,
             MatchGenerator matchGen,
             InstructionList il)
    {
  int field;
  LocalVariableGen local;
  ConstantPoolGen cpg = nodeCounterGen.getConstantPool();

  // Get NodeCounter._iterator and store locally
  local = matchGen.addLocalVariable("iterator",
            Util.getJCRefType(NODE_ITERATOR_SIG),
            null, null);
  field = cpg.addFieldref(NODE_COUNTER, "_iterator",
        ITERATOR_FIELD_SIG);
  il.append(ALOAD_0); // 'this' pointer on stack
  il.append(new GETFIELD(field));
  il.append(new ASTORE(local.getIndex()));
  matchGen.setIteratorIndex(local.getIndex());
 
  // Get NodeCounter._translet and store locally
  local = matchGen.addLocalVariable("translet",
          Util.getJCRefType(TRANSLET_SIG),
          null, null);
  field = cpg.addFieldref(NODE_COUNTER, "_translet",
        "Lorg/apache/xalan/xsltc/Translet;");
  il.append(ALOAD_0); // 'this' pointer on stack
  il.append(new GETFIELD(field));
  il.append(new CHECKCAST(cpg.addClass(TRANSLET_CLASS)));
  il.append(new ASTORE(local.getIndex()));
  nodeCounterGen.setTransletIndex(local.getIndex());

  // Get NodeCounter._document and store locally
  local = matchGen.addLocalVariable("document",
            Util.getJCRefType(DOM_INTF_SIG),
            null, null);
  field = cpg.addFieldref(_className, "_document", DOM_INTF_SIG);
  il.append(ALOAD_0); // 'this' pointer on stack
  il.append(new GETFIELD(field));
  // Make sure we have the correct DOM type on the stack!!!
  il.append(new ASTORE(local.getIndex()));
  matchGen.setDomIndex(local.getIndex());
    }
View Full Code Here

    private void compilePatterns(ClassGenerator classGen,
         MethodGenerator methodGen)
    {
  int current;
  int field;
  LocalVariableGen local;
  MatchGenerator matchGen;
  NodeCounterGenerator nodeCounterGen;

  _className = getXSLTC().getHelperClassName();
  nodeCounterGen = new NodeCounterGenerator(_className,
View Full Code Here

            _predicates.remove(predicate);

            // Translate the rest of the predicates from right to left
            translatePredicates(classGen, methodGen);

            LocalVariableGen nodeIteratorTemp =
                methodGen.addLocalVariable("filter_expr_tmp1",
                                           Util.getJCRefType(NODE_ITERATOR_SIG),
                                           il.getEnd(), null);
            il.append(new ASTORE(nodeIteratorTemp.getIndex()));

            predicate.translate(classGen, methodGen);
            LocalVariableGen filterTemp =
                methodGen.addLocalVariable("filter_expr_tmp2",
                              Util.getJCRefType(CURRENT_NODE_LIST_FILTER_SIG),
                              il.getEnd(), null);
            il.append(new ASTORE(filterTemp.getIndex()));

            // Create a CurrentNodeListIterator
            il.append(new NEW(cpg.addClass(CURRENT_NODE_LIST_ITERATOR)));
            il.append(DUP);
           
            // Initialize CurrentNodeListIterator
            il.append(new ALOAD(nodeIteratorTemp.getIndex()));
            il.append(ICONST_1);
            il.append(new ALOAD(filterTemp.getIndex()));
            il.append(methodGen.loadCurrentNode());
            il.append(classGen.loadTranslet());
            il.append(new INVOKESPECIAL(initCNLI));
  }
    }
View Full Code Here

            // this argument to its constructor.  Instead we calculate the
            // value of the argument to the constructor first, store it in
            // a temporary variable, create the object and reload the argument
            // from the temporary to avoid the problem.
      _path.translate(classGen, methodGen);
            LocalVariableGen relPathIterator
                    = methodGen.addLocalVariable("abs_location_path_tmp",
                                       Util.getJCRefType(NODE_ITERATOR_SIG),
                                       il.getEnd(), null);
            il.append(new ASTORE(relPathIterator.getIndex()));

      // Create new AbsoluteIterator
      il.append(new NEW(cpg.addClass(ABSOLUTE_ITERATOR)));
      il.append(DUP);
            il.append(new ALOAD(relPathIterator.getIndex()));

      // Initialize AbsoluteIterator with iterator from the stack
      il.append(new INVOKESPECIAL(initAI));
  }
  else {
View Full Code Here

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

  final LocalVariableGen name =
      methodGen.addLocalVariable2("name",
          Util.getJCRefType(STRING_SIG),
          il.getEnd());
  final LocalVariableGen length =
      methodGen.addLocalVariable2("length",
          Util.getJCRefType("I"),
          il.getEnd());

  // Get the name of the node to copy and save for later
  il.append(methodGen.loadDOM());
  il.append(methodGen.loadCurrentNode());
  il.append(methodGen.loadHandler());
  final int cpy = cpg.addInterfaceMethodref(DOM_INTF,
              "shallowCopy",
              "("
              + NODE_SIG
              + TRANSLET_OUTPUT_SIG
              + ")" + STRING_SIG);
  il.append(new INVOKEINTERFACE(cpy, 3));
  il.append(DUP);
  il.append(new ASTORE(name.getIndex()));
  final BranchHandle ifBlock1 = il.append(new IFNULL(null));

  // Get the length of the node name and save for later
  il.append(new ALOAD(name.getIndex()));
  final int lengthMethod = cpg.addMethodref(STRING_CLASS,"length","()I");
  il.append(new INVOKEVIRTUAL(lengthMethod));
  il.append(new ISTORE(length.getIndex()));

  // Copy in attribute sets if specified
  if (_useSets != null) {
      // If the parent of this element will result in an element being
      // output then we know that it is safe to copy out the attributes
      final SyntaxTreeNode parent = getParent();
      if ((parent instanceof LiteralElement) ||
    (parent instanceof LiteralElement)) {
    _useSets.translate(classGen, methodGen);
      }
      // If not we have to check to see if the copy will result in an
      // element being output.
      else {
    // check if element; if not skip to translate body
    il.append(new ILOAD(length.getIndex()));
    final BranchHandle ifBlock2 = il.append(new IFEQ(null));
    // length != 0 -> element -> do attribute sets
    _useSets.translate(classGen, methodGen);
    // not an element; root
    ifBlock2.setTarget(il.append(NOP));
      }
  }

  // Instantiate body of xsl:copy
  translateContents(classGen, methodGen);

  // Call the output handler's endElement() if we copied an element
  // (The DOM.shallowCopy() method calls startElement().)
  il.append(new ILOAD(length.getIndex()));
  final BranchHandle ifBlock3 = il.append(new IFEQ(null));
  il.append(methodGen.loadHandler());
  il.append(new ALOAD(name.getIndex()));
  il.append(methodGen.endElement());
 
View Full Code Here

        getClassName(), mainIL,
        classGen.getConstantPool());
  methodGen.addException("org.apache.xalan.xsltc.TransletException");

  // Create a local variable to hold the current node
  final LocalVariableGen current;
  current = methodGen.addLocalVariable2("current",
                org.apache.bcel.generic.Type.INT,
                mainIL.getEnd());
  _currentIndex = current.getIndex();

  // Create the "body" instruction list that will eventually hold the
  // code for the entire method (other ILs will be appended).
  final InstructionList body = new InstructionList();
  body.append(NOP);
View Full Code Here

        getClassName(), mainIL,
        classGen.getConstantPool());
  methodGen.addException("org.apache.xalan.xsltc.TransletException");

  // Create the local variable to hold the current node
  final LocalVariableGen current;
  current = methodGen.addLocalVariable2("current",
                org.apache.bcel.generic.Type.INT,
                mainIL.getEnd());
  _currentIndex = current.getIndex();

  // Create the "body" instruction list that will eventually hold the
  // code for the entire method (other ILs will be appended).
  final InstructionList body = new InstructionList();
  body.append(NOP);
View Full Code Here

TOP

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

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.