Package org.apache.bcel.generic

Examples of org.apache.bcel.generic.LocalVariableGen


        classGen.getConstantPool());

  toplevel.addException("org.apache.xalan.xsltc.TransletException");

  // Define and initialize 'current' variable with the root node
  final LocalVariableGen current =
      toplevel.addLocalVariable("current",
              org.apache.bcel.generic.Type.INT,
              null, null);

  final int setFilter = cpg.addInterfaceMethodref(DOM_INTF,
             "setFilter",
             "(Lorg/apache/xalan/xsltc/StripFilter;)V");

  final int gitr = cpg.addInterfaceMethodref(DOM_INTF,
              "getIterator",
              "()"+NODE_ITERATOR_SIG);
  il.append(toplevel.loadDOM());
  il.append(new INVOKEINTERFACE(gitr, 1));
        il.append(toplevel.nextNode());
  current.setStart(il.append(new ISTORE(current.getIndex())));

    // Create a new list containing variables/params + keys
    Vector varDepElements = new Vector(_globals);       
    Enumeration elements = elements();
    while (elements.hasMoreElements()) {
View Full Code Here


        il,
        classGen.getConstantPool());
  transf.addException("org.apache.xalan.xsltc.TransletException");

  // Define and initialize current with the root node
  final LocalVariableGen current =
      transf.addLocalVariable("current",
            org.apache.bcel.generic.Type.INT,
            null, null);
  final String applyTemplatesSig = classGen.getApplyTemplatesSig();
  final int applyTemplates = cpg.addMethodref(getClassName(),
                "applyTemplates",
                applyTemplatesSig);
  final int domField = cpg.addFieldref(getClassName(),
               DOM_FIELD,
               DOM_INTF_SIG);

  // push translet for PUTFIELD
  il.append(classGen.loadTranslet());
  // prepare appropriate DOM implementation
 
  if (isMultiDocument()) {
      il.append(new NEW(cpg.addClass(MULTI_DOM_CLASS)));
      il.append(DUP);
  }
 
  il.append(classGen.loadTranslet());
  il.append(transf.loadDOM());
  il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS,
                 "makeDOMAdapter",
                 "("+DOM_INTF_SIG+")"+
                 DOM_ADAPTER_SIG)));
  // DOMAdapter is on the stack

  if (isMultiDocument()) {
      final int init = cpg.addMethodref(MULTI_DOM_CLASS,
                "<init>",
                "("+DOM_INTF_SIG+")V");
      il.append(new INVOKESPECIAL(init));
      // MultiDOM is on the stack
  }
 
  //store to _dom variable
  il.append(new PUTFIELD(domField));

  // continue with globals initialization
  final int gitr = cpg.addInterfaceMethodref(DOM_INTF,
              "getIterator",
              "()"+NODE_ITERATOR_SIG);
  il.append(transf.loadDOM());
  il.append(new INVOKEINTERFACE(gitr, 1));
        il.append(transf.nextNode());
  current.setStart(il.append(new ISTORE(current.getIndex())));

  // Transfer the output settings to the output post-processor
  il.append(classGen.loadTranslet());
  il.append(transf.loadHandler());
  final int index = cpg.addMethodref(TRANSLET_CLASS,
View Full Code Here

                // Instead we calculate the values of the arguments to the
                // constructor first, store them in temporary variables, create
                // the object and reload the arguments from the temporaries to
                // avoid the problem.
                LocalVariableGen iteratorTemp
                        = methodGen.addLocalVariable("filter_expr_tmp1",
                                         Util.getJCRefType(NODE_ITERATOR_SIG),
                                         null, null);
                iteratorTemp.setStart(
                        il.append(new ASTORE(iteratorTemp.getIndex())));

                predicate.translate(classGen, methodGen);
                LocalVariableGen predicateValueTemp
                        = methodGen.addLocalVariable("filter_expr_tmp2",
                                         Util.getJCRefType("I"),
                                         null, null);
                predicateValueTemp.setStart(
                        il.append(new ISTORE(predicateValueTemp.getIndex())));

                il.append(new NEW(cpg.addClass(NTH_ITERATOR_CLASS)));
                il.append(DUP);
                iteratorTemp.setEnd(
                        il.append(new ALOAD(iteratorTemp.getIndex())));
                predicateValueTemp.setEnd(
                        il.append(new ILOAD(predicateValueTemp.getIndex())));
                il.append(new INVOKESPECIAL(nthIteratorIdx));
            } else {
                // Translate predicates from right to left
                final int initCNLI =
                                 cpg.addMethodref(CURRENT_NODE_LIST_ITERATOR,
                                                 "<init>",
                                                 "("+NODE_ITERATOR_SIG+"Z"+
                                                 CURRENT_NODE_LIST_FILTER_SIG +
                                                 NODE_SIG+TRANSLET_SIG+")V");

                // Backwards branches are prohibited if an uninitialized object
                // is on the stack by section 4.9.4 of the JVM Specification,
                // 2nd Ed.  We don't know whether this code might contain
                // backwards branches, so we mustn't create the new object
                // until after we've created the suspect arguments to its
                // constructor.  Instead we calculate the values of the
                // arguments to the constructor first, store them in temporary
                // variables, create the object and reload the arguments from
                // the temporaries to avoid the problem.


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

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

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

                // Instead we calculate the values of the arguments to the
                // constructor first, store them in temporary variables, create
                // the object and reload the arguments from the temporaries to
                // avoid the problem.
    translatePredicates(classGen, methodGen); // recursive call
                LocalVariableGen iteratorTemp
                        = methodGen.addLocalVariable("step_tmp1",
                                         Util.getJCRefType(NODE_ITERATOR_SIG),
                                         null, null);
                iteratorTemp.setStart(
                        il.append(new ASTORE(iteratorTemp.getIndex())));

    predicate.translate(classGen, methodGen);
                LocalVariableGen predicateValueTemp
                        = methodGen.addLocalVariable("step_tmp2",
                                         Util.getJCRefType("I"),
                                         null, null);
                predicateValueTemp.setStart(
                        il.append(new ISTORE(predicateValueTemp.getIndex())));

    il.append(new NEW(cpg.addClass(NTH_ITERATOR_CLASS)));
    il.append(DUP);
                iteratorTemp.setEnd(
                        il.append(new ALOAD(iteratorTemp.getIndex())));
                predicateValueTemp.setEnd(
                        il.append(new ILOAD(predicateValueTemp.getIndex())));
    il.append(new INVOKESPECIAL(idx));
      }
      else {
    idx = cpg.addMethodref(CURRENT_NODE_LIST_ITERATOR,
               "<init>",
               "("
               + NODE_ITERATOR_SIG
               + CURRENT_NODE_LIST_FILTER_SIG
               + NODE_SIG
               + TRANSLET_SIG
               + ")V");

                // Backwards branches are prohibited if an uninitialized object
                // is on the stack by section 4.9.4 of the JVM Specification,
                // 2nd Ed.  We don't know whether this code might contain
                // backwards branches, so we mustn't create the new object until
                // after we've created the suspect arguments to its constructor.
                // Instead we calculate the values of the arguments to the
                // constructor first, store them in temporary variables, create
                // the object and reload the arguments from the temporaries to
                // avoid the problem.
    translatePredicates(classGen, methodGen); // recursive call
                LocalVariableGen iteratorTemp
                        = methodGen.addLocalVariable("step_tmp1",
                                         Util.getJCRefType(NODE_ITERATOR_SIG),
                                         null, null);
                iteratorTemp.setStart(
                        il.append(new ASTORE(iteratorTemp.getIndex())));

    predicate.translateFilter(classGen, methodGen);
                LocalVariableGen filterTemp
                        = methodGen.addLocalVariable("step_tmp2",
                              Util.getJCRefType(CURRENT_NODE_LIST_FILTER_SIG),
                              null, null);
                filterTemp.setStart(
                        il.append(new ASTORE(filterTemp.getIndex())));

    // create new CurrentNodeListIterator
    il.append(new NEW(cpg.addClass(CURRENT_NODE_LIST_ITERATOR)));
    il.append(DUP);

                iteratorTemp.setEnd(
                        il.append(new ALOAD(iteratorTemp.getIndex())));
                filterTemp.setEnd(il.append(new ALOAD(filterTemp.getIndex())));
   
    il.append(methodGen.loadCurrentNode());
    il.append(classGen.loadTranslet());
    if (classGen.isExternal()) {
        final String className = classGen.getClassName();
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));
  local.setStart(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)));
  local.setStart(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!!!
  local.setStart(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

     * (iv) calls startElement() on the handler (v) looks up a uri in the XML
     * when the prefix is not known at compile time (vi) calls namespace()
     * on the handler (vii) evaluates the contents (viii) calls endElement().
     */
    public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
  LocalVariableGen local = null;
  final ConstantPoolGen cpg = classGen.getConstantPool();
  final InstructionList il = methodGen.getInstructionList();

  // Optimize translation if element name is a literal
  if (_isLiteralName) {
      translateLiteral(classGen, methodGen);
      return;
  }

  if (!_ignore) {
      
            // 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),
                                                null);
                   
            // store the name into a variable first so _name.translate only needs to be called once 
            _name.translate(classGen, methodGen);
            nameValue.setStart(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, "checkQName",
                            "("
                            +STRING_SIG
                            +")V");                
            il.append(new INVOKESTATIC(check));
           
            // Push handler for call to endElement()
            il.append(methodGen.loadHandler());        
           
            // load name value again
            nameValue.setEnd(il.append(new ALOAD(nameValue.getIndex())));
                   
      if (_namespace != null) {
    _namespace.translate(classGen, methodGen);
      }
      else {
View Full Code Here

     * @see  org.apache.xalan.xsltc.compiler.util.Type#translateToDesynthesized
     */
    public FlowList translateToDesynthesized(ClassGenerator classGen,
               MethodGenerator methodGen,
               BooleanType type) {
  LocalVariableGen local;
  final FlowList flowlist = new FlowList();
  final ConstantPoolGen cpg = classGen.getConstantPool();
  final InstructionList il = methodGen.getInstructionList();

  // Store real into a local variable
  il.append(DUP2);
  local = methodGen.addLocalVariable("real_to_boolean_tmp",
             org.apache.bcel.generic.Type.DOUBLE,
             null, null);
  local.setStart(il.append(new DSTORE(local.getIndex())));

  // Compare it to 0.0
  il.append(DCONST_0);
  il.append(DCMPG);
  flowlist.add(il.append(new IFEQ(null)));

  //!!! call isNaN
  // Compare it to itself to see if NaN
  il.append(new DLOAD(local.getIndex()));
  local.setEnd(il.append(new DLOAD(local.getIndex())));
  il.append(DCMPG);
  flowlist.add(il.append(new IFNE(null)))// NaN != NaN
  return flowlist;
    }
View Full Code Here

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

  // Recursively compile 2 iterators
  _filterExpr.translate(classGen, methodGen);
        LocalVariableGen filterTemp =
                methodGen.addLocalVariable("filter_parent_path_tmp1",
                                           Util.getJCRefType(NODE_ITERATOR_SIG),
                                           null, null);
        filterTemp.setStart(il.append(new ASTORE(filterTemp.getIndex())));

  _path.translate(classGen, methodGen);
        LocalVariableGen pathTemp =
                methodGen.addLocalVariable("filter_parent_path_tmp2",
                                           Util.getJCRefType(NODE_ITERATOR_SIG),
                                           null, null);
        pathTemp.setStart(il.append(new ASTORE(pathTemp.getIndex())));

  il.append(new NEW(cpg.addClass(STEP_ITERATOR_CLASS)));
  il.append(DUP);
        filterTemp.setEnd(il.append(new ALOAD(filterTemp.getIndex())));
        pathTemp.setEnd(il.append(new ALOAD(pathTemp.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

  final ConstantPoolGen cpg = classGen.getConstantPool();
  final InstructionList il = methodGen.getInstructionList();
   
        if (!_isLiteral) {
            // if the ncname is an AVT, then the ncname has to be checked at runtime if it is a valid ncname
            LocalVariableGen nameValue =
                    methodGen.addLocalVariable2("nameValue",
                                                Util.getJCRefType(STRING_SIG),
                                                null);
           
            // store the name into a variable first so _name.translate only needs to be called once 
            _name.translate(classGen, methodGen);
            nameValue.setStart(il.append(new ASTORE(nameValue.getIndex())));
            il.append(new ALOAD(nameValue.getIndex()));
           
            // call checkNCName if the name is an AVT
            final int check = cpg.addMethodref(BASIS_LIBRARY_CLASS, "checkNCName",
                                "("
                                +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   
            nameValue.setEnd(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

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.