Package org.apache.bcel.generic

Examples of org.apache.bcel.generic.InstructionList


     * Stylesheet.compileConstructor() and not as the syntax tree is traversed.
     */
    public void translate(ClassGenerator classGen, MethodGenerator methodGen) {

  ConstantPoolGen cpg = classGen.getConstantPool();
  InstructionList il = methodGen.getInstructionList();
 
  // DecimalFormatSymbols.<init>();
  final int init = cpg.addMethodref(DFS_CLASS, "<init>", "()V");

  // Push the format name on the stack for call to addDecimalFormat()
  il.append(classGen.loadTranslet());
  il.append(new PUSH(cpg, _name.toString()));

  // Manufacture a DecimalFormatSymbols on the stack
  // for call to addDecimalFormat()
  il.append(new NEW(cpg.addClass(DFS_CLASS)));
  il.append(DUP);
  il.append(new INVOKESPECIAL(init));

  String tmp = getAttribute("NaN");
  if ((tmp == null) || (tmp.equals(EMPTYSTRING))) {
      int nan = cpg.addMethodref(DFS_CLASS,
               "setNaN", "(Ljava/lang/String;)V");
      il.append(DUP);
      il.append(new PUSH(cpg, "NaN"));
      il.append(new INVOKEVIRTUAL(nan));
  }

  tmp = getAttribute("infinity");
  if ((tmp == null) || (tmp.equals(EMPTYSTRING))) {
      int inf = cpg.addMethodref(DFS_CLASS,
               "setInfinity",
               "(Ljava/lang/String;)V");
      il.append(DUP);
      il.append(new PUSH(cpg, "Infinity"));
      il.append(new INVOKEVIRTUAL(inf));
  }
     
  final int nAttributes = _attributes.getLength();
  for (int i = 0; i < nAttributes; i++) {
      final String name = _attributes.getQName(i);
      final String value = _attributes.getValue(i);

      boolean valid = true;
      int method = 0;

      if (name.equals("decimal-separator")) {
    // DecimalFormatSymbols.setDecimalSeparator();
    method = cpg.addMethodref(DFS_CLASS,
            "setDecimalSeparator", "(C)V");
      }
      else if (name.equals("grouping-separator")) {
    method =  cpg.addMethodref(DFS_CLASS,
             "setGroupingSeparator", "(C)V");
      }
      else if (name.equals("minus-sign")) {
    method = cpg.addMethodref(DFS_CLASS,
            "setMinusSign", "(C)V");
      }
      else if (name.equals("percent")) {
    method = cpg.addMethodref(DFS_CLASS,
            "setPercent", "(C)V");
      }
      else if (name.equals("per-mille")) {
    method = cpg.addMethodref(DFS_CLASS,
            "setPerMill", "(C)V");
      }
      else if (name.equals("zero-digit")) {
    method = cpg.addMethodref(DFS_CLASS,
            "setZeroDigit", "(C)V");
      }
      else if (name.equals("digit")) {
    method = cpg.addMethodref(DFS_CLASS,
            "setDigit", "(C)V");
      }
      else if (name.equals("pattern-separator")) {
    method = cpg.addMethodref(DFS_CLASS,
            "setPatternSeparator", "(C)V");
      }
      else if (name.equals("NaN")) {
    method = cpg.addMethodref(DFS_CLASS,
            "setNaN", "(Ljava/lang/String;)V");
          il.append(DUP);
    il.append(new PUSH(cpg, value));
    il.append(new INVOKEVIRTUAL(method));
    valid = false;
      }
      else if (name.equals("infinity")) {
    method = cpg.addMethodref(DFS_CLASS,
            "setInfinity",
            "(Ljava/lang/String;)V");
          il.append(DUP);
    il.append(new PUSH(cpg, value));
    il.append(new INVOKEVIRTUAL(method));
    valid = false;
      }
      else {
    valid = false;
      }

      if (valid) {
    il.append(DUP);
    il.append(new PUSH(cpg, value.charAt(0)));
    il.append(new INVOKEVIRTUAL(method));
      }

  }

  final int put = cpg.addMethodref(TRANSLET_CLASS,
           "addDecimalFormat",
           "("+STRING_SIG+DFS_SIG+")V");
  il.append(new INVOKEVIRTUAL(put));
    }
View Full Code Here


     */
    public static void translateDefaultDFS(ClassGenerator classGen,
             MethodGenerator methodGen) {

  ConstantPoolGen cpg = classGen.getConstantPool();
  InstructionList il = methodGen.getInstructionList();
  final int init = cpg.addMethodref(DFS_CLASS, "<init>", "()V");

  // Push the format name, which is empty, on the stack
  // for call to addDecimalFormat()
  il.append(classGen.loadTranslet());
  il.append(new PUSH(cpg, EMPTYSTRING));

  // Manufacture a DecimalFormatSymbols on the stack
  // for call to addDecimalFormat()
  il.append(new NEW(cpg.addClass(DFS_CLASS)));
  il.append(DUP);
  il.append(new INVOKESPECIAL(init));

  int nan = cpg.addMethodref(DFS_CLASS,
           "setNaN", "(Ljava/lang/String;)V");
  il.append(DUP);
  il.append(new PUSH(cpg, "NaN"));
  il.append(new INVOKEVIRTUAL(nan));

  int inf = cpg.addMethodref(DFS_CLASS,
           "setInfinity",
           "(Ljava/lang/String;)V");
  il.append(DUP);
  il.append(new PUSH(cpg, "Infinity"));
  il.append(new INVOKEVIRTUAL(inf));

  final int put = cpg.addMethodref(TRANSLET_CLASS,
           "addDecimalFormat",
           "("+STRING_SIG+DFS_SIG+")V");
  il.append(new INVOKEVIRTUAL(put));
    }
View Full Code Here

  return Type.Void;
    }

    public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
  final ConstantPoolGen cpg = classGen.getConstantPool();
  final InstructionList il = methodGen.getInstructionList();
  final int setEscaping = cpg.addInterfaceMethodref(OUTPUT_HANDLER,
                "setEscaping","(Z)Z");
  final int characters = cpg.addMethodref(TRANSLET_CLASS,
            CHARACTERSW,
            CHARACTERSW_SIG);

  // Turn off character escaping if so is wanted.
  if (!_escaping) {
      il.append(methodGen.loadHandler());
      il.append(new PUSH(cpg,false));
      il.append(new INVOKEINTERFACE(setEscaping,2));
  }

  // Translate the contents.
  il.append(classGen.loadTranslet());
  _select.translate(classGen, methodGen)
  il.append(methodGen.loadHandler());
  il.append(new INVOKEVIRTUAL(characters));

  // Restore character escaping setting to whatever it was.
  if (!_escaping) {
      il.append(methodGen.loadHandler());
      il.append(SWAP);
      il.append(new INVOKEINTERFACE(setEscaping,2));
      il.append(POP);
  }
    }
View Full Code Here

     * Translates the document() function call to a call to LoadDocument()'s
     * static method document().
     */
    public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
  final ConstantPoolGen cpg = classGen.getConstantPool();
  final InstructionList il = methodGen.getInstructionList();

  final int domField = cpg.addFieldref(classGen.getClassName(),
               DOM_FIELD,
               DOM_INTF_SIG);
  final String docParamList =
      "("+OBJECT_SIG+STRING_SIG+STRING_SIG+TRANSLET_SIG+DOM_INTF_SIG+")"+
      NODE_ITERATOR_SIG;
  final int docIdx = cpg.addMethodref(LOAD_DOCUMENT_CLASS,
              "document", docParamList);

  final int uriIdx = cpg.addInterfaceMethodref(DOM_INTF,
                 "getDocumentURI",
                 "(I)"+STRING_SIG);

  final int nextIdx = cpg.addInterfaceMethodref(NODE_ITERATOR,
                  NEXT, NEXT_SIG);

  // The URI can be either a node-set or something else cast to a string
  _uri.translate(classGen, methodGen);
  if (_uriType == Type.NodeSet)
      _uri.startResetIterator(classGen, methodGen);

  // The base of the URI may be given as a second argument (a node-set)
  il.append(methodGen.loadDOM());
  if (_base != null) {
      _base.translate(classGen, methodGen);
      il.append(new INVOKEINTERFACE(nextIdx, 1));
  }
  else {
       il.append(methodGen.loadContextNode());
  }
  il.append(new INVOKEINTERFACE(uriIdx, 2));
  il.append(new PUSH(cpg, getStylesheet().getSystemId()));

  // Feck the rest of the parameters on the stack
  il.append(classGen.loadTranslet());
  il.append(DUP);
  il.append(new GETFIELD(domField));
  il.append(new INVOKESTATIC(docIdx));
    }
View Full Code Here

  return typeCheckContents(stable);
    }

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

  if (_disabled) return;
  // bug fix #4433133, add a call to named template from applyTemplates
  String className = classGen.getClassName();

  if (_compiled && isNamed()){
      String methodName = Util.escape(_name.toString());
      il.append(classGen.loadTranslet());
      il.append(methodGen.loadDOM());
      il.append(methodGen.loadIterator());
      il.append(methodGen.loadHandler());
      il.append(methodGen.loadCurrentNode());
      il.append(new INVOKEVIRTUAL(cpg.addMethodref(className,
               methodName,
               "("
               + DOM_INTF_SIG
               + NODE_ITERATOR_SIG
               + TRANSLET_OUTPUT_SIG
               + "I)V")));
      return;
  }

  if (_compiled) return;
  _compiled = true;
 
  final InstructionHandle start = il.getEnd();
  translateContents(classGen, methodGen);
  final InstructionHandle end = il.getEnd();
  il.setPositions(true);
    }
View Full Code Here

     * TODO: optimize by checking if the callee has parameters.
     */
    public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
  final Stylesheet stylesheet = classGen.getStylesheet();
  final ConstantPoolGen cpg = classGen.getConstantPool();
  final InstructionList il = methodGen.getInstructionList();


  if (stylesheet.hasLocalParams() || hasContents()) {
      // Push parameter frame
      final int push = cpg.addMethodref(TRANSLET_CLASS,
                PUSH_PARAM_FRAME,
                PUSH_PARAM_FRAME_SIG);
      il.append(classGen.loadTranslet());
      il.append(new INVOKEVIRTUAL(push));
      // Translate with-params
      translateContents(classGen, methodGen);
  }

  final String className = stylesheet.getClassName();
  // Generate a valid Java method name
  String methodName = Util.escape(_name.toString());

  il.append(classGen.loadTranslet());
  il.append(methodGen.loadDOM());
  il.append(methodGen.loadIterator());
  il.append(methodGen.loadHandler());
  il.append(methodGen.loadCurrentNode());
  il.append(new INVOKEVIRTUAL(cpg.addMethodref(className,
                 methodName,
                 "("
                 + DOM_INTF_SIG
                 + NODE_ITERATOR_SIG
                 + TRANSLET_OUTPUT_SIG
                 + NODE_SIG
                 +")V")));
 

  if (stylesheet.hasLocalParams() || hasContents()) {
      // Pop parameter frame
      final int pop = cpg.addMethodref(TRANSLET_CLASS,
               POP_PARAM_FRAME,
               POP_PARAM_FRAME_SIG);
      il.append(classGen.loadTranslet());
      il.append(new INVOKEVIRTUAL(pop));
  }
    }
View Full Code Here

    }

    private void compileNamedTemplate(Template template,
              ClassGenerator classGen) {
  final ConstantPoolGen cpg = classGen.getConstantPool();
  final InstructionList il = new InstructionList();
  String methodName = Util.escape(template.getName().toString());

  final NamedMethodGenerator methodGen =
      new NamedMethodGenerator(ACC_PUBLIC,
             org.apache.bcel.generic.Type.VOID,
             new org.apache.bcel.generic.Type[] {
           Util.getJCRefType(DOM_INTF_SIG),
           Util.getJCRefType(NODE_ITERATOR_SIG),
           Util.getJCRefType(TRANSLET_OUTPUT_SIG),
           org.apache.bcel.generic.Type.INT
             },
             new String[] {
           DOCUMENT_PNAME,
           ITERATOR_PNAME,
           TRANSLET_OUTPUT_PNAME,
           NODE_PNAME
             },
             methodName,
             getClassName(),
             il, cpg);
 
  il.append(template.compile(classGen, methodGen));
  il.append(RETURN);
 
  methodGen.stripAttributes(true);
  methodGen.setMaxLocals();
  methodGen.setMaxStack();
  methodGen.removeNOPs();
View Full Code Here

  templates = _neededTemplates.keys();
  while (templates.hasMoreElements()) {
      final Template template = (Template)templates.nextElement();
      if (template.hasContents()) {
    // !!! TODO templates both named and matched
    InstructionList til = template.compile(classGen, methodGen);
    til.append(new GOTO_W(next));
    _templateILs.put(template, til);
    _templateIHs.put(template, til.getStart());
      }
      else {
    // empty template
    _templateIHs.put(template, next);
      }
View Full Code Here

    private void appendTestSequences(InstructionList body) {
  final int n = _testSeq.length;
  for (int i = 0; i < n; i++) {
      final TestSeq testSeq = _testSeq[i];
      if (testSeq != null) {
    InstructionList il = testSeq.getInstructionList();
    if (il != null)
        body.append(il);
    // else trivial TestSeq
      }
  }
View Full Code Here

    public static void compileGetChildren(ClassGenerator classGen,
            MethodGenerator methodGen,
            int node) {
  final ConstantPoolGen cpg = classGen.getConstantPool();
  final InstructionList il = methodGen.getInstructionList();
  final int git = cpg.addInterfaceMethodref(DOM_INTF,
              GET_CHILDREN,
              GET_CHILDREN_SIG);
  il.append(methodGen.loadDOM());
  il.append(new ILOAD(node));
  il.append(new INVOKEINTERFACE(git, 2));
    }
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.