Package org.apache.bcel.generic

Examples of org.apache.bcel.generic.LocalVariableGen


        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();

    mainIL.append(new ILOAD(methodGen.getLocalIndex(NODE_PNAME)));
    mainIL.append(new ISTORE(_currentIndex));
   
  // Create the "body" instruction list that will eventually hold the
View Full Code Here

     * Notice that local variables need to be "unboxed".
     */
    private void compileFilter(ClassGenerator classGen,
             MethodGenerator methodGen) {
  TestGenerator testGen;
  LocalVariableGen local;
  FilterGenerator filterGen;

  _className = getXSLTC().getHelperClassName();
  filterGen = new FilterGenerator(_className,
          "java.lang.Object",
          toString(),
          ACC_PUBLIC | ACC_SUPER,
          new String[] {
              CURRENT_NODE_LIST_FILTER
          },
          classGen.getStylesheet())

  final ConstantPoolGen cpg = filterGen.getConstantPool();
  final int length = (_closureVars == null) ? 0 : _closureVars.size();

  // Add a new instance variable for each var in closure
  for (int i = 0; i < length; i++) {
      VariableBase var = ((VariableRefBase) _closureVars.get(i)).getVariable();

      filterGen.addField(new Field(ACC_PUBLIC,
          cpg.addUtf8(var.getEscapedName()),
          cpg.addUtf8(var.getType().toSignature()),
          null, cpg.getConstantPool()));
  }

  final InstructionList il = new InstructionList();
  testGen = new TestGenerator(ACC_PUBLIC | ACC_FINAL,
            org.apache.bcel.generic.Type.BOOLEAN,
            new org.apache.bcel.generic.Type[] {
          org.apache.bcel.generic.Type.INT,
          org.apache.bcel.generic.Type.INT,
          org.apache.bcel.generic.Type.INT,
          org.apache.bcel.generic.Type.INT,
          Util.getJCRefType(TRANSLET_SIG),
          Util.getJCRefType(NODE_ITERATOR_SIG)
            },
            new String[] {
          "node",
          "position",
          "last",
          "current",
          "translet",
          "iterator"
            },
            "test", _className, il, cpg);
   
  // Store the dom in a local variable
  local = testGen.addLocalVariable("document",
           Util.getJCRefType(DOM_INTF_SIG),
           null, null);
  final String className = classGen.getClassName();
  il.append(filterGen.loadTranslet());
  il.append(new CHECKCAST(cpg.addClass(className)));
  il.append(new GETFIELD(cpg.addFieldref(className,
                 DOM_FIELD, DOM_INTF_SIG)));
  il.append(new ASTORE(local.getIndex()));

  // Store the dom index in the test generator
  testGen.setDomIndex(local.getIndex());

  _exp.translate(filterGen, testGen);
  il.append(IRETURN);
 
  testGen.stripAttributes(true);
View Full Code Here

    }

    public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
  final ConstantPoolGen cpg = classGen.getConstantPool();
  final InstructionList il = methodGen.getInstructionList();
  final LocalVariableGen local =
      methodGen.addLocalVariable2("ppt",
          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.isWildcard()) {
      il.append(methodGen.loadDOM());
      il.append(SWAP);
  }
  else if (_right instanceof StepPattern) {
      il.append(DUP);
      il.append(storeLocal);
     
      _right.translate(classGen, methodGen);
     
      il.append(methodGen.loadDOM());
      local.setEnd(il.append(loadLocal));
  }
  else {
      _right.translate(classGen, methodGen);

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

  final int getParent = cpg.addInterfaceMethodref(DOM_INTF,
              GET_PARENT,
              GET_PARENT_SIG);
  il.append(new INVOKEINTERFACE(getParent, 2));

  final SyntaxTreeNode p = getParent();
  if (p == null || p instanceof Instruction ||
      p instanceof TopLevelElement)
  {
      _left.translate(classGen, methodGen);
  }
  else {
      il.append(DUP);
      il.append(storeLocal);
     
      _left.translate(classGen, methodGen);

      il.append(methodGen.loadDOM());
      local.setEnd(il.append(loadLocal));
  }

  methodGen.removeLocalVariable(local);
 
  /*
 
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),
                    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, "checkQName",
                            "("
                            +STRING_SIG
                            +")V");                
            il.append(new INVOKESTATIC(check));
           
            // Push handler for call to endElement()
            il.append(methodGen.loadHandler());        
           
            // load name value again   
            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,
             il.getEnd(), null);
  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()));
  il.append(new DLOAD(local.getIndex()));
  il.append(DCMPG);
  flowlist.add(il.append(new IFNE(null)))// NaN != NaN
  return flowlist;
    }
View Full Code Here

    if(name.equals("TRUE")) {
        il.append(new PUSH(cp, 1));
    } else if(name.equals("FALSE")) {
        il.append(new PUSH(cp, 0));
    } else {
      LocalVariableGen local_var = reference.getLocalVariable();
      il.append(new ILOAD(local_var.getIndex()));
    }
    ASTFunDecl.push();
  }
View Full Code Here

           new Type[] { new ObjectType("java.io.Reader") },
           Constants.INVOKESPECIAL));

    /* Create local variable `in'
     */
    LocalVariableGen lg = mg.addLocalVariable("in",
                new ObjectType("java.io.BufferedReader"),
                null, null);
    int in = lg.getIndex();
    lg.setStart(il.append(new ASTORE(in))); // `i' valid from here

    /* Create local variable `name'
     */
    lg = mg.addLocalVariable("name", Type.STRING, null, null);
    int name = lg.getIndex();
    il.append(InstructionConstants.ACONST_NULL);
    lg.setStart(il.append(new ASTORE(name))); // `name' valid from here

    /* try { ...
     */
    InstructionHandle try_start =
      il.append(factory.createFieldAccess("java.lang.System", "out", p_stream,
View Full Code Here

    for(int i=0; i < size; i++) {
      String           ident = idents[i].getName();
      Variable         entry = (Variable)env.get(ident);
      Type             t     = BasicType.getType((byte)idents[i].getType());
      LocalVariableGen lg    = method.addLocalVariable(ident, t, null, null);
      int              slot  = lg.getIndex();

      entry.setLocalVariable(lg);
      InstructionHandle start = il.getEnd();
      exprs[i].byte_code(il, method, cp);
      start = (start == null)? il.getStart() : start.getNext();
      lg.setStart(start);
      il.append(new ISTORE(slot));     ASTFunDecl.pop();
      l[i] = lg;
    }

    body.byte_code(il, method, cp);
View Full Code Here

    }
    /* Pass 2: Output code.
     */
    for(int i=0; i < lvs.length; i++) {
      LocalVariableGen l = lvs[i];
      out.println(".var " + l.getIndex() + " is " + l.getName() + " " +
      l.getType().getSignature() +
      " from " + get(l.getStart()) +
      " to " + get(l.getEnd()));
    }

    out.print("\n");
   
    for(int i=0; i < ihs.length; i++) {
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.