Package com.sun.org.apache.bcel.internal.generic

Examples of com.sun.org.apache.bcel.internal.generic.LocalVariableGen


        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 (with RTF_INITIAL_SIZE nodes)
            il.append(methodGen.loadDOM());
            int index = cpg.addInterfaceMethodref(DOM_INTF,
                                 "getResultTreeFrag",
                                 "(IZ)" + DOM_INTF_SIG);
            il.append(new PUSH(cpg, RTF_INITIAL_SIZE));
            il.append(new PUSH(cpg, false));
            il.append(new INVOKEINTERFACE(index,3));
            il.append(DUP);

            // 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)));
            newDom.setStart(il.append(new ASTORE(newDom.getIndex())));

            // Overwrite old handler with DOM handler
            index = cpg.addInterfaceMethodref(DOM_INTF,
                                 "getOutputDomBuilder",
                                 "()" + TRANSLET_OUTPUT_SIG);

            il.append(new INVOKEINTERFACE(index,1));
            //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);
            domBuilder.setStart(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
            domBuilder.setEnd(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
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

            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);
            handler.setStart(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()
            handler.setEnd(il.append(new ALOAD(handler.getIndex())));
            index = cpg.addMethodref(STRING_VALUE_HANDLER,
                                     "getValue",
                                     "()" + STRING_SIG);
            il.append(new INVOKEVIRTUAL(index));
        }
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),
                                         il.getEnd(), null);
                il.append(new ASTORE(iteratorTemp.getIndex()));

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

    il.append(new NEW(cpg.addClass(NTH_ITERATOR_CLASS)));
    il.append(DUP);
                il.append(new ALOAD(iteratorTemp.getIndex()));
                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),
                                         il.getEnd(), null);
                il.append(new ASTORE(iteratorTemp.getIndex()));

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

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

                il.append(new ALOAD(iteratorTemp.getIndex()));
                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

                           

  // This variable holds the id of the node we found with the "match"
  // attribute of xsl:key. This is the id we store, with the value we
  // get from the nodes we find here, in the index for this key.
  final LocalVariableGen parentNode =
      methodGen.addLocalVariable("parentNode",
               Util.getJCRefType("I"),
               il.getEnd(), null);

  // Get the 'parameter' from the stack and store it in a local var.
  il.append(new ISTORE(parentNode.getIndex()))

  // Save current node and current iterator on the stack
  il.append(methodGen.loadCurrentNode());
  il.append(methodGen.loadIterator());

  // Overwrite current iterator with one that gives us only what we want
  _use.translate(classGen, methodGen);
  _use.startIterator(classGen, methodGen);
  il.append(methodGen.storeIterator());

  final BranchHandle nextNode = il.append(new GOTO(null));
  final InstructionHandle loop = il.append(NOP);

  // Prepare to call buildKeyIndex(String name, int node, String value);
  il.append(classGen.loadTranslet());
  il.append(new PUSH(cpg, _name.toString()));
  il.append(new ILOAD(parentNode.getIndex()));

  // Now get the node value and feck it on the parameter stack
  il.append(methodGen.loadDOM());
  il.append(methodGen.loadCurrentNode());
  il.append(new INVOKEINTERFACE(getNodeValue, 2));   
View Full Code Here

        classGen.getConstantPool());

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

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

  final int setFilter = cpg.addInterfaceMethodref(DOM_INTF,
             "setFilter",
             "(Lcom/sun/org/apache/xalan/internal/xsltc/StripFilter;)V");

  il.append(new PUSH(cpg, DTM.ROOT_NODE));
  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("com.sun.org.apache.xalan.internal.xsltc.TransletException");

  // Define and initialize current with the root node
  final LocalVariableGen current =
      transf.addLocalVariable("current",
            com.sun.org.apache.bcel.internal.generic.Type.INT,
            il.getEnd(), 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
  il.append(new PUSH(cpg, DTM.ROOT_NODE));
  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

 
    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

            // 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.

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

      // Create new Dup Filter Iterator
      il.append(new NEW(cpg.addClass(DUP_FILTERED_ITERATOR)));
      il.append(DUP);
            il.append(new ALOAD(pathTemp.getIndex()));

      // Initialize Dup Filter Iterator with iterator from the stack
      il.append(new INVOKESPECIAL(initDFI));
  }
  else {
View Full Code Here

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

TOP

Related Classes of com.sun.org.apache.bcel.internal.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.