コード例 #1
0
 public SearchResult run(RSClient data, HashMap<String, ClassGen> classes) {
   for (ClassGen c : classes.values()) {
     ConstantPoolGen cpg = c.getConstantPool();
     if (cpg.lookupFloat(16384.0000f) != -1) {
       for (Method m : c.getMethods()) {
         if (m.isStatic()) {
           MethodGen gen = new MethodGen(m, c.getClassName(), cpg);
           InstructionList il = gen.getInstructionList();
           if (il == null) continue;
           InstructionFinder f = new InstructionFinder(il);
           Iterator e = f.search("GETSTATIC LDC FSUB PUTSTATIC");
           if (e.hasNext()) {
             InstructionHandle[] handles = (InstructionHandle[]) e.next();
             data.addField(
                 "MapAngle",
                 ((GETSTATIC) handles[0].getInstruction()).getClassName(cpg)
                     + "."
                     + ((GETSTATIC) handles[0].getInstruction()).getFieldName(cpg));
             return SearchResult.Success;
           }
         }
       }
     }
   }
   return SearchResult.Failure;
 }
コード例 #2
0
 @Override
 public Constant createConstant(ConstantPoolGen cpg) {
   MethodRef method = getValue();
   int i = cpg.addClass(method.getClassName());
   int n = cpg.addNameAndType(method.getName(), method.getDescriptor().toString());
   return new ConstantMethodref(i, n);
 }
コード例 #3
0
ファイル: NameBase.java プロジェクト: srnsw/xena
  /**
   * Translate the code required for getting the node for which the QName, local-name or namespace
   * URI should be extracted.
   */
  public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    il.append(methodGen.loadDOM());

    // Function was called with no parameters
    if (argumentCount() == 0) {
      il.append(methodGen.loadContextNode());
    }
    // Function was called with node parameter
    else if (_paramType == Type.Node) {
      _param.translate(classGen, methodGen);
    } else if (_paramType == Type.Reference) {
      _param.translate(classGen, methodGen);
      il.append(
          new INVOKESTATIC(
              cpg.addMethodref(
                  BASIS_LIBRARY_CLASS,
                  "referenceToNodeSet",
                  "(" + OBJECT_SIG + ")" + NODE_ITERATOR_SIG)));
      il.append(methodGen.nextNode());
    }
    // Function was called with node-set parameter
    else {
      _param.translate(classGen, methodGen);
      _param.startIterator(classGen, methodGen);
      il.append(methodGen.nextNode());
    }
  }
コード例 #4
0
 @Override
 public int lookupConstant(ConstantPoolGen cpg) {
   MethodRef method = getValue();
   if (isInterfaceMethod()) {
     return cpg.lookupInterfaceMethodref(
         method.getClassName(), method.getName(), method.getDescriptor().toString());
   }
   return cpg.lookupMethodref(
       method.getClassName(), method.getName(), method.getDescriptor().toString());
 }
コード例 #5
0
ファイル: Variable.java プロジェクト: napile/napile.classpath
  public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    // Don't generate code for unreferenced variables
    if (_refs.isEmpty()) {
      _ignore = true;
    }

    // Make sure that a variable instance is only compiled once
    if (_ignore) return;
    _ignore = true;

    final String name = getEscapedName();

    if (isLocal()) {
      // Compile variable value computation
      translateValue(classGen, methodGen);

      // Add a new local variable and store value
      boolean createLocal = _local == null;
      if (createLocal) {
        mapRegister(methodGen);
      }
      InstructionHandle storeInst = il.append(_type.STORE(_local.getIndex()));

      // If the local is just being created, mark the store as the start
      // of its live range.  Note that it might have been created by
      // initializeVariables already, which would have set the start of
      // the live range already.
      if (createLocal) {
        _local.setStart(storeInst);
      }
    } else {
      String signature = _type.toSignature();

      // Global variables are store in class fields
      if (classGen.containsField(name) == null) {
        classGen.addField(
            new Field(
                ACC_PUBLIC,
                cpg.addUtf8(name),
                cpg.addUtf8(signature),
                null,
                cpg.getConstantPool()));

        // Push a reference to "this" for putfield
        il.append(classGen.loadTranslet());
        // Compile variable value computation
        translateValue(classGen, methodGen);
        // Store the variable in the allocated field
        il.append(new PUTFIELD(cpg.addFieldref(classGen.getClassName(), name, signature)));
      }
    }
  }
コード例 #6
0
  /** Create a new auxillary class extending NodeSortRecord. */
  private static String compileSortRecord(
      Vector sortObjects, ClassGenerator classGen, MethodGenerator methodGen) {
    final XSLTC xsltc = ((Sort) sortObjects.firstElement()).getXSLTC();
    final String className = xsltc.getHelperClassName();

    // This generates a new class for handling this specific sort
    final NodeSortRecordGenerator sortRecord =
        new NodeSortRecordGenerator(
            className,
            NODE_SORT_RECORD,
            "sort$0.java",
            ACC_PUBLIC | ACC_SUPER | ACC_FINAL,
            new String[] {},
            classGen.getStylesheet());

    final ConstantPoolGen cpg = sortRecord.getConstantPool();

    // Add a new instance variable for each var in closure
    final int nsorts = sortObjects.size();
    final ArrayList dups = new ArrayList();

    for (int j = 0; j < nsorts; j++) {
      final Sort sort = (Sort) sortObjects.get(j);

      // Set the name of the inner class in this sort object
      sort.setInnerClassName(className);

      final int length = (sort._closureVars == null) ? 0 : sort._closureVars.size();
      for (int i = 0; i < length; i++) {
        final VariableRefBase varRef = (VariableRefBase) sort._closureVars.get(i);

        // Discard duplicate variable references
        if (dups.contains(varRef)) continue;

        final VariableBase var = varRef.getVariable();
        sortRecord.addField(
            new Field(
                ACC_PUBLIC,
                cpg.addUtf8(var.getEscapedName()),
                cpg.addUtf8(var.getType().toSignature()),
                null,
                cpg.getConstantPool()));
        dups.add(varRef);
      }
    }

    MethodGenerator init = compileInit(sortObjects, sortRecord, cpg, className);
    MethodGenerator extract = compileExtract(sortObjects, sortRecord, cpg, className);
    sortRecord.addMethod(init);
    sortRecord.addMethod(extract);

    xsltc.dumpClass(sortRecord.getJavaClass());
    return className;
  }
コード例 #7
0
  /**
   * Compiles code that instantiates a SortingIterator object. This object's constructor needs
   * referencdes to the current iterator and a node sort record producing objects as its parameters.
   */
  public static void translateSortIterator(
      ClassGenerator classGen, MethodGenerator methodGen, Expression nodeSet, Vector sortObjects) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    // SortingIterator.SortingIterator(NodeIterator,NodeSortRecordFactory);
    final int init =
        cpg.addMethodref(
            SORT_ITERATOR, "<init>", "(" + NODE_ITERATOR_SIG + NODE_SORT_FACTORY_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 nodesTemp =
        methodGen.addLocalVariable("sort_tmp1", Util.getJCRefType(NODE_ITERATOR_SIG), null, null);

    LocalVariableGen sortRecordFactoryTemp =
        methodGen.addLocalVariable(
            "sort_tmp2", Util.getJCRefType(NODE_SORT_FACTORY_SIG), null, null);

    // Get the current node iterator
    if (nodeSet == null) { // apply-templates default
      final int children =
          cpg.addInterfaceMethodref(DOM_INTF, "getAxisIterator", "(I)" + NODE_ITERATOR_SIG);
      il.append(methodGen.loadDOM());
      il.append(new PUSH(cpg, Axis.CHILD));
      il.append(new INVOKEINTERFACE(children, 2));
    } else {
      nodeSet.translate(classGen, methodGen);
    }

    nodesTemp.setStart(il.append(new ASTORE(nodesTemp.getIndex())));

    // Compile the code for the NodeSortRecord producing class and pass
    // that as the last argument to the SortingIterator constructor.
    compileSortRecordFactory(sortObjects, classGen, methodGen);
    sortRecordFactoryTemp.setStart(il.append(new ASTORE(sortRecordFactoryTemp.getIndex())));

    il.append(new NEW(cpg.addClass(SORT_ITERATOR)));
    il.append(DUP);
    nodesTemp.setEnd(il.append(new ALOAD(nodesTemp.getIndex())));
    sortRecordFactoryTemp.setEnd(il.append(new ALOAD(sortRecordFactoryTemp.getIndex())));
    il.append(new INVOKESPECIAL(init));
  }
コード例 #8
0
  public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final InstructionList il = methodGen.getInstructionList();

    if (methodGen instanceof CompareGenerator) {
      il.append(((CompareGenerator) methodGen).loadLastNode());
    } else if (methodGen instanceof TestGenerator) {
      il.append(new ILOAD(LAST_INDEX));
    } else {
      final ConstantPoolGen cpg = classGen.getConstantPool();
      final int getLast = cpg.addInterfaceMethodref(NODE_ITERATOR, "getLast", "()I");
      il.append(methodGen.loadIterator());
      il.append(new INVOKEINTERFACE(getLast, 1));
    }
  }
コード例 #9
0
 public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
   final ConstantPoolGen cpg = classGen.getConstantPool();
   final InstructionList il = methodGen.getInstructionList();
   // Push the this pointer on the stack...
   il.append(methodGen.loadDOM());
   // ...then the entity name...
   _entity.translate(classGen, methodGen);
   // ...to get the URI from the DOM object.
   il.append(
       new INVOKEINTERFACE(
           cpg.addInterfaceMethodref(
               DOM_INTF, GET_UNPARSED_ENTITY_URI, GET_UNPARSED_ENTITY_URI_SIG),
           2));
 }
コード例 #10
0
ファイル: Predicate.java プロジェクト: srnsw/xena
  /**
   * Translate a predicate expression. If non of the optimizations apply then this translation
   * pushes two references on the stack: a reference to a newly created filter object and a
   * reference to the predicate's closure. See class <code>Step</code> for further details.
   */
  public void translate(ClassGenerator classGen, MethodGenerator methodGen) {

    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    if (_nthPositionFilter || _nthDescendant) {
      _exp.translate(classGen, methodGen);
    } else if (isNodeValueTest() && (getParent() instanceof Step)) {
      _value.translate(classGen, methodGen);
      il.append(new CHECKCAST(cpg.addClass(STRING_CLASS)));
      il.append(new PUSH(cpg, ((EqualityExpr) _exp).getOp()));
    } else {
      translateFilter(classGen, methodGen);
    }
  }
コード例 #11
0
ファイル: Predicate.java プロジェクト: srnsw/xena
  /**
   * Translate a predicate expression. This translation pushes two references on the stack: a
   * reference to a newly created filter object and a reference to the predicate's closure.
   */
  public void translateFilter(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    // Compile auxiliary class for filter
    compileFilter(classGen, methodGen);

    // Create new instance of filter
    il.append(new NEW(cpg.addClass(_className)));
    il.append(DUP);
    il.append(new INVOKESPECIAL(cpg.addMethodref(_className, "<init>", "()V")));

    // Initialize closure variables
    final int length = (_closureVars == null) ? 0 : _closureVars.size();

    for (int i = 0; i < length; i++) {
      VariableRefBase varRef = (VariableRefBase) _closureVars.get(i);
      VariableBase var = varRef.getVariable();
      Type varType = var.getType();

      il.append(DUP);

      // Find nearest closure implemented as an inner class
      Closure variableClosure = _parentClosure;
      while (variableClosure != null) {
        if (variableClosure.inInnerClass()) break;
        variableClosure = variableClosure.getParentClosure();
      }

      // Use getfield if in an inner class
      if (variableClosure != null) {
        il.append(ALOAD_0);
        il.append(
            new GETFIELD(
                cpg.addFieldref(
                    variableClosure.getInnerClassName(),
                    var.getEscapedName(),
                    varType.toSignature())));
      } else {
        // Use a load of instruction if in translet class
        il.append(var.loadInstruction());
      }

      // Store variable in new closure
      il.append(
          new PUTFIELD(cpg.addFieldref(_className, var.getEscapedName(), varType.toSignature())));
    }
  }
コード例 #12
0
  /** Returns the attribute name for the specified attribute */
  public static String get_attribute_name(Attribute a, ConstantPoolGen pool) {

    int con_index = a.getNameIndex();
    Constant c = pool.getConstant(con_index);
    String att_name = ((ConstantUtf8) c).getBytes();
    return (att_name);
  }
コード例 #13
0
 /** Translate code to call the BasisLibrary.unallowed_extensionF(String) method. */
 private void translateUnallowedExtension(ConstantPoolGen cpg, InstructionList il) {
   int index =
       cpg.addMethodref(
           BASIS_LIBRARY_CLASS, "unallowed_extension_functionF", "(Ljava/lang/String;)V");
   il.append(new PUSH(cpg, _fname.toString()));
   il.append(new INVOKESTATIC(index));
 }
コード例 #14
0
  /** Returns the attribute name for the specified attribute */
  public String get_attribute_name(Attribute a) {

    int con_index = a.getNameIndex();
    Constant c = pgen.getConstant(con_index);
    String att_name = ((ConstantUtf8) c).getBytes();
    return (att_name);
  }
コード例 #15
0
  /**
   * Create a constructor for the new class. Updates the reference to the collator in the super
   * calls only when the stylesheet specifies a new language in xsl:sort.
   */
  private static MethodGenerator compileInit(
      Vector sortObjects,
      NodeSortRecordGenerator sortRecord,
      ConstantPoolGen cpg,
      String className) {
    final InstructionList il = new InstructionList();
    final MethodGenerator init =
        new MethodGenerator(
            ACC_PUBLIC,
            org.apache.bcel.generic.Type.VOID,
            null,
            null,
            "<init>",
            className,
            il,
            cpg);

    // Call the constructor in the NodeSortRecord superclass
    il.append(ALOAD_0);
    il.append(new INVOKESPECIAL(cpg.addMethodref(NODE_SORT_RECORD, "<init>", "()V")));

    il.append(RETURN);

    return init;
  }
コード例 #16
0
ファイル: DecimalFormatting.java プロジェクト: srnsw/xena
  /**
   * Creates the default, nameless, DecimalFormat object in AbstractTranslet's format_symbols
   * hashtable. This should be called for every stylesheet, and the entry may be overridden by later
   * nameless xsl:decimal-format instructions.
   */
  public static void translateDefaultDFS(ClassGenerator classGen, MethodGenerator methodGen) {

    ConstantPoolGen cpg = classGen.getConstantPool();
    InstructionList il = methodGen.getInstructionList();
    final int init = cpg.addMethodref(DFS_CLASS, "<init>", "(" + LOCALE_SIG + ")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().  Use the US Locale as the
    // default, as most of its settings are equivalent to
    // the default settings required of xsl:decimal-format -
    // except for the NaN and infinity attributes.
    il.append(new NEW(cpg.addClass(DFS_CLASS)));
    il.append(DUP);
    il.append(new GETSTATIC(cpg.addFieldref(LOCALE_CLASS, "US", LOCALE_SIG)));
    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));
  }
コード例 #17
0
ファイル: ExecutionVisitor.java プロジェクト: ubiopen/JMD
 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
 public void visitLDC2_W(LDC2_W o) {
   Constant c = cpg.getConstant(o.getIndex());
   if (c instanceof ConstantLong) {
     stack().push(Type.LONG);
   }
   if (c instanceof ConstantDouble) {
     stack().push(Type.DOUBLE);
   }
 }
コード例 #18
0
  // TODO: write Javadoc
  public static String instruction_descr(InstructionList il, ConstantPoolGen pool) {

    String out = "";
    // not generic because BCEL is not generic
    for (Iterator i = il.iterator(); i.hasNext(); ) {
      InstructionHandle handle = (InstructionHandle) i.next();
      out += handle.getInstruction().toString(pool.getConstantPool()) + "\n";
    }
    return (out);
  }
コード例 #19
0
ファイル: LangCall.java プロジェクト: enenuki/phd
 /* 43:   */
 /* 44:   */ public void translate(ClassGenerator classGen, MethodGenerator methodGen)
       /* 45:   */ {
   /* 46:77 */ ConstantPoolGen cpg = classGen.getConstantPool();
   /* 47:78 */ InstructionList il = methodGen.getInstructionList();
   /* 48:   */
   /* 49:80 */ int tst =
       cpg.addMethodref(
           "org.apache.xalan.xsltc.runtime.BasisLibrary",
           "testLanguage",
           "(Ljava/lang/String;Lorg/apache/xalan/xsltc/DOM;I)Z");
   /* 50:   */
   /* 51:   */
   /* 52:83 */ this._lang.translate(classGen, methodGen);
   /* 53:84 */ il.append(methodGen.loadDOM());
   /* 54:85 */ if ((classGen instanceof FilterGenerator)) {
     /* 55:86 */ il.append(new ILOAD(1));
     /* 56:   */ } else {
     /* 57:88 */ il.append(methodGen.loadContextNode());
     /* 58:   */ }
   /* 59:89 */ il.append(new INVOKESTATIC(tst));
   /* 60:   */ }
コード例 #20
0
ファイル: ExecutionVisitor.java プロジェクト: ubiopen/JMD
 /** Symbolically executes the corresponding Java Virtual Machine instruction. */
 public void visitLDC_W(LDC_W o) {
   Constant c = cpg.getConstant(o.getIndex());
   if (c instanceof ConstantInteger) {
     stack().push(Type.INT);
   }
   if (c instanceof ConstantFloat) {
     stack().push(Type.FLOAT);
   }
   if (c instanceof ConstantString) {
     stack().push(Type.STRING);
   }
 }
コード例 #21
0
ファイル: EventMethod.java プロジェクト: RPI-WCL/overview
  public void insertPart(
      InstructionList patch, MethodGen methodGen, ConstantPoolGen constantPoolGen) {
    for (int i = 0; i < eventArguments.length; i++) {
      eventArguments[i].insertArgument(patch, methodGen, constantPoolGen);
    }

    try {
      if (Class.forName(methodClassType).isInterface()) {
        // nargs must be eventArgs+1 to account for the class being invoked upon
        int method =
            constantPoolGen.addInterfaceMethodref(methodClassType, methodName, methodSignature);
        patch.append(new INVOKEINTERFACE(method, (eventArguments.length + 1)));
      } else {
        int method = constantPoolGen.addMethodref(methodClassType, methodName, methodSignature);
        patch.append(new INVOKEVIRTUAL(method));
      }
    } catch (Exception e) {
      System.err.println("Could not load class: " + methodClassType);
      System.err.println("Exception: e");
      e.printStackTrace();
    }
  }
コード例 #22
0
ファイル: BCEL.java プロジェクト: tempbottle/ASM
 byte[] counterAdaptClass(final InputStream is, final String name) throws Exception {
   JavaClass jc = new ClassParser(is, name + ".class").parse();
   ClassGen cg = new ClassGen(jc);
   String cName = cg.getClassName();
   ConstantPoolGen cp = cg.getConstantPool();
   if (!cg.isInterface()) {
     FieldGen fg = new FieldGen(ACC_PUBLIC, Type.getType("I"), "_counter", cp);
     cg.addField(fg.getField());
   }
   Method[] ms = cg.getMethods();
   for (int j = 0; j < ms.length; ++j) {
     MethodGen mg = new MethodGen(ms[j], cg.getClassName(), cp);
     if (!mg.getName().equals("<init>") && !mg.isStatic() && !mg.isAbstract() && !mg.isNative()) {
       if (mg.getInstructionList() != null) {
         InstructionList il = new InstructionList();
         il.append(new ALOAD(0));
         il.append(new ALOAD(0));
         il.append(new GETFIELD(cp.addFieldref(name, "_counter", "I")));
         il.append(new ICONST(1));
         il.append(new IADD());
         il.append(new PUTFIELD(cp.addFieldref(name, "_counter", "I")));
         mg.getInstructionList().insert(il);
         mg.setMaxStack(Math.max(mg.getMaxStack(), 2));
         boolean lv = ms[j].getLocalVariableTable() == null;
         boolean ln = ms[j].getLineNumberTable() == null;
         if (lv) {
           mg.removeLocalVariables();
         }
         if (ln) {
           mg.removeLineNumbers();
         }
         cg.replaceMethod(ms[j], mg.getMethod());
       }
     }
   }
   return cg.getJavaClass().getBytes();
 }
コード例 #23
0
  /**
   * Translate a function call. The compiled code will leave the function's return value on the
   * JVM's stack.
   */
  public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final int n = argumentCount();
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();
    final boolean isSecureProcessing = classGen.getParser().getXSLTC().isSecureProcessing();
    int index;

    // Translate calls to methods in the BasisLibrary
    if (isStandard() || isExtension()) {
      for (int i = 0; i < n; i++) {
        final Expression exp = argument(i);
        exp.translate(classGen, methodGen);
        exp.startIterator(classGen, methodGen);
      }

      // append "F" to the function's name
      final String name = _fname.toString().replace('-', '_') + "F";
      String args = Constants.EMPTYSTRING;

      // Special precautions for some method calls
      if (name.equals("sumF")) {
        args = DOM_INTF_SIG;
        il.append(methodGen.loadDOM());
      } else if (name.equals("normalize_spaceF")) {
        if (_chosenMethodType.toSignature(args).equals("()Ljava/lang/String;")) {
          args = "I" + DOM_INTF_SIG;
          il.append(methodGen.loadContextNode());
          il.append(methodGen.loadDOM());
        }
      }

      // Invoke the method in the basis library
      index = cpg.addMethodref(BASIS_LIBRARY_CLASS, name, _chosenMethodType.toSignature(args));
      il.append(new INVOKESTATIC(index));
    }
    // Add call to BasisLibrary.unresolved_externalF() to generate
    // run-time error message for unsupported external functions
    else if (unresolvedExternal) {
      index =
          cpg.addMethodref(BASIS_LIBRARY_CLASS, "unresolved_externalF", "(Ljava/lang/String;)V");
      il.append(new PUSH(cpg, _fname.toString()));
      il.append(new INVOKESTATIC(index));
    } else if (_isExtConstructor) {
      if (isSecureProcessing) translateUnallowedExtension(cpg, il);

      final String clazz = _chosenConstructor.getDeclaringClass().getName();
      Class[] paramTypes = _chosenConstructor.getParameterTypes();
      LocalVariableGen[] paramTemp = new LocalVariableGen[n];

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

      for (int i = 0; i < n; i++) {
        final Expression exp = argument(i);
        Type expType = exp.getType();
        exp.translate(classGen, methodGen);
        // Convert the argument to its Java type
        exp.startIterator(classGen, methodGen);
        expType.translateTo(classGen, methodGen, paramTypes[i]);
        paramTemp[i] =
            methodGen.addLocalVariable(
                "function_call_tmp" + i, expType.toJCType(), il.getEnd(), null);
        il.append(expType.STORE(paramTemp[i].getIndex()));
      }

      il.append(new NEW(cpg.addClass(_className)));
      il.append(InstructionConstants.DUP);

      for (int i = 0; i < n; i++) {
        final Expression arg = argument(i);
        il.append(arg.getType().LOAD(paramTemp[i].getIndex()));
      }

      final StringBuffer buffer = new StringBuffer();
      buffer.append('(');
      for (int i = 0; i < paramTypes.length; i++) {
        buffer.append(getSignature(paramTypes[i]));
      }
      buffer.append(')');
      buffer.append("V");

      index = cpg.addMethodref(clazz, "<init>", buffer.toString());
      il.append(new INVOKESPECIAL(index));

      // Convert the return type back to our internal type
      (Type.Object).translateFrom(classGen, methodGen, _chosenConstructor.getDeclaringClass());

    }
    // Invoke function calls that are handled in separate classes
    else {
      if (isSecureProcessing) translateUnallowedExtension(cpg, il);

      final String clazz = _chosenMethod.getDeclaringClass().getName();
      Class[] paramTypes = _chosenMethod.getParameterTypes();

      // Push "this" if it is an instance method
      if (_thisArgument != null) {
        _thisArgument.translate(classGen, methodGen);
      }

      for (int i = 0; i < n; i++) {
        final Expression exp = argument(i);
        exp.translate(classGen, methodGen);
        // Convert the argument to its Java type
        exp.startIterator(classGen, methodGen);
        exp.getType().translateTo(classGen, methodGen, paramTypes[i]);
      }

      final StringBuffer buffer = new StringBuffer();
      buffer.append('(');
      for (int i = 0; i < paramTypes.length; i++) {
        buffer.append(getSignature(paramTypes[i]));
      }
      buffer.append(')');
      buffer.append(getSignature(_chosenMethod.getReturnType()));

      if (_thisArgument != null && _clazz.isInterface()) {
        index = cpg.addInterfaceMethodref(clazz, _fname.getLocalPart(), buffer.toString());
        il.append(new INVOKEINTERFACE(index, n + 1));
      } else {
        index = cpg.addMethodref(clazz, _fname.getLocalPart(), buffer.toString());
        il.append(
            _thisArgument != null
                ? (InvokeInstruction) new INVOKEVIRTUAL(index)
                : (InvokeInstruction) new INVOKESTATIC(index));
      }

      // Convert the return type back to our internal type
      _type.translateFrom(classGen, methodGen, _chosenMethod.getReturnType());
    }
  }
コード例 #24
0
ファイル: Predicate.java プロジェクト: srnsw/xena
  /**
   * Create a new "Filter" class implementing <code>CurrentNodeListFilter</code>. Allocate registers
   * for local variables and local parameters passed in the closure to test(). 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)));
    local.setStart(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);

    filterGen.addEmptyConstructor(ACC_PUBLIC);
    filterGen.addMethod(testGen);

    getXSLTC().dumpClass(filterGen.getJavaClass());
  }
コード例 #25
0
ファイル: DecimalFormatting.java プロジェクト: srnsw/xena
  /**
   * This method is called when the constructor is compiled in 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>(Locale);
    // xsl:decimal-format - except for the NaN and infinity attributes.
    final int init = cpg.addMethodref(DFS_CLASS, "<init>", "(" + LOCALE_SIG + ")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()
    // Use the US Locale as the default, as most of its settings
    // are equivalent to the default settings required of
    il.append(new NEW(cpg.addClass(DFS_CLASS)));
    il.append(DUP);
    il.append(new GETSTATIC(cpg.addFieldref(LOCALE_CLASS, "US", LOCALE_SIG)));
    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));
  }
コード例 #26
0
ファイル: GenJava.java プロジェクト: deepakworld07/xmlvm.svn
 public Instruction createInstructionAnewarray(Element inst) {
   String classType = inst.getAttributeValue("elementType");
   return new ANEWARRAY(_cp.addClass(classType));
 }
コード例 #27
0
ファイル: GenJava.java プロジェクト: deepakworld07/xmlvm.svn
 public Instruction createInstructionCheckcast(Element inst) throws IllegalXMLVMException {
   String classType = inst.getAttributeValue("type");
   return new CHECKCAST(_cp.addClass(classType));
 }
コード例 #28
0
  /**
   * Compiles code that instantiates a NodeSortRecordFactory object which will produce
   * NodeSortRecord objects of a specific type.
   */
  public static void compileSortRecordFactory(
      Vector sortObjects, ClassGenerator classGen, MethodGenerator methodGen) {
    String sortRecordClass = compileSortRecord(sortObjects, classGen, methodGen);

    boolean needsSortRecordFactory = false;
    final int nsorts = sortObjects.size();
    for (int i = 0; i < nsorts; i++) {
      final Sort sort = (Sort) sortObjects.elementAt(i);
      needsSortRecordFactory |= sort._needsSortRecordFactory;
    }

    String sortRecordFactoryClass = NODE_SORT_FACTORY;
    if (needsSortRecordFactory) {
      sortRecordFactoryClass =
          compileSortRecordFactory(sortObjects, classGen, methodGen, sortRecordClass);
    }

    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

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

    // Compile code that initializes the static _sortOrder
    LocalVariableGen sortOrderTemp =
        methodGen.addLocalVariable(
            "sort_order_tmp", Util.getJCRefType("[" + STRING_SIG), null, null);
    il.append(new PUSH(cpg, nsorts));
    il.append(new ANEWARRAY(cpg.addClass(STRING)));
    for (int level = 0; level < nsorts; level++) {
      final Sort sort = (Sort) sortObjects.elementAt(level);
      il.append(DUP);
      il.append(new PUSH(cpg, level));
      sort.translateSortOrder(classGen, methodGen);
      il.append(AASTORE);
    }
    sortOrderTemp.setStart(il.append(new ASTORE(sortOrderTemp.getIndex())));

    LocalVariableGen sortTypeTemp =
        methodGen.addLocalVariable(
            "sort_type_tmp", Util.getJCRefType("[" + STRING_SIG), null, null);
    il.append(new PUSH(cpg, nsorts));
    il.append(new ANEWARRAY(cpg.addClass(STRING)));
    for (int level = 0; level < nsorts; level++) {
      final Sort sort = (Sort) sortObjects.elementAt(level);
      il.append(DUP);
      il.append(new PUSH(cpg, level));
      sort.translateSortType(classGen, methodGen);
      il.append(AASTORE);
    }
    sortTypeTemp.setStart(il.append(new ASTORE(sortTypeTemp.getIndex())));

    LocalVariableGen sortLangTemp =
        methodGen.addLocalVariable(
            "sort_lang_tmp", Util.getJCRefType("[" + STRING_SIG), null, null);
    il.append(new PUSH(cpg, nsorts));
    il.append(new ANEWARRAY(cpg.addClass(STRING)));
    for (int level = 0; level < nsorts; level++) {
      final Sort sort = (Sort) sortObjects.elementAt(level);
      il.append(DUP);
      il.append(new PUSH(cpg, level));
      sort.translateLang(classGen, methodGen);
      il.append(AASTORE);
    }
    sortLangTemp.setStart(il.append(new ASTORE(sortLangTemp.getIndex())));

    LocalVariableGen sortCaseOrderTemp =
        methodGen.addLocalVariable(
            "sort_case_order_tmp", Util.getJCRefType("[" + STRING_SIG), null, null);
    il.append(new PUSH(cpg, nsorts));
    il.append(new ANEWARRAY(cpg.addClass(STRING)));
    for (int level = 0; level < nsorts; level++) {
      final Sort sort = (Sort) sortObjects.elementAt(level);
      il.append(DUP);
      il.append(new PUSH(cpg, level));
      sort.translateCaseOrder(classGen, methodGen);
      il.append(AASTORE);
    }
    sortCaseOrderTemp.setStart(il.append(new ASTORE(sortCaseOrderTemp.getIndex())));

    il.append(new NEW(cpg.addClass(sortRecordFactoryClass)));
    il.append(DUP);
    il.append(methodGen.loadDOM());
    il.append(new PUSH(cpg, sortRecordClass));
    il.append(classGen.loadTranslet());

    sortOrderTemp.setEnd(il.append(new ALOAD(sortOrderTemp.getIndex())));
    sortTypeTemp.setEnd(il.append(new ALOAD(sortTypeTemp.getIndex())));
    sortLangTemp.setEnd(il.append(new ALOAD(sortLangTemp.getIndex())));
    sortCaseOrderTemp.setEnd(il.append(new ALOAD(sortCaseOrderTemp.getIndex())));

    il.append(
        new INVOKESPECIAL(
            cpg.addMethodref(
                sortRecordFactoryClass,
                "<init>",
                "("
                    + DOM_INTF_SIG
                    + STRING_SIG
                    + TRANSLET_INTF_SIG
                    + "["
                    + STRING_SIG
                    + "["
                    + STRING_SIG
                    + "["
                    + STRING_SIG
                    + "["
                    + STRING_SIG
                    + ")V")));

    // Initialize closure variables in sortRecordFactory
    final ArrayList dups = new ArrayList();

    for (int j = 0; j < nsorts; j++) {
      final Sort sort = (Sort) sortObjects.get(j);
      final int length = (sort._closureVars == null) ? 0 : sort._closureVars.size();

      for (int i = 0; i < length; i++) {
        VariableRefBase varRef = (VariableRefBase) sort._closureVars.get(i);

        // Discard duplicate variable references
        if (dups.contains(varRef)) continue;

        final VariableBase var = varRef.getVariable();

        // Store variable in new closure
        il.append(DUP);
        il.append(var.loadInstruction());
        il.append(
            new PUTFIELD(
                cpg.addFieldref(
                    sortRecordFactoryClass, var.getEscapedName(), var.getType().toSignature())));
        dups.add(varRef);
      }
    }
  }
コード例 #29
0
  public static String compileSortRecordFactory(
      Vector sortObjects,
      ClassGenerator classGen,
      MethodGenerator methodGen,
      String sortRecordClass) {
    final XSLTC xsltc = ((Sort) sortObjects.firstElement()).getXSLTC();
    final String className = xsltc.getHelperClassName();

    final NodeSortRecordFactGenerator sortRecordFactory =
        new NodeSortRecordFactGenerator(
            className,
            NODE_SORT_FACTORY,
            className + ".java",
            ACC_PUBLIC | ACC_SUPER | ACC_FINAL,
            new String[] {},
            classGen.getStylesheet());

    ConstantPoolGen cpg = sortRecordFactory.getConstantPool();

    // Add a new instance variable for each var in closure
    final int nsorts = sortObjects.size();
    final ArrayList dups = new ArrayList();

    for (int j = 0; j < nsorts; j++) {
      final Sort sort = (Sort) sortObjects.get(j);
      final int length = (sort._closureVars == null) ? 0 : sort._closureVars.size();

      for (int i = 0; i < length; i++) {
        final VariableRefBase varRef = (VariableRefBase) sort._closureVars.get(i);

        // Discard duplicate variable references
        if (dups.contains(varRef)) continue;

        final VariableBase var = varRef.getVariable();
        sortRecordFactory.addField(
            new Field(
                ACC_PUBLIC,
                cpg.addUtf8(var.getEscapedName()),
                cpg.addUtf8(var.getType().toSignature()),
                null,
                cpg.getConstantPool()));
        dups.add(varRef);
      }
    }

    // Define a constructor for this class
    final org.apache.bcel.generic.Type[] argTypes = new org.apache.bcel.generic.Type[7];
    argTypes[0] = Util.getJCRefType(DOM_INTF_SIG);
    argTypes[1] = Util.getJCRefType(STRING_SIG);
    argTypes[2] = Util.getJCRefType(TRANSLET_INTF_SIG);
    argTypes[3] = Util.getJCRefType("[" + STRING_SIG);
    argTypes[4] = Util.getJCRefType("[" + STRING_SIG);
    argTypes[5] = Util.getJCRefType("[" + STRING_SIG);
    argTypes[6] = Util.getJCRefType("[" + STRING_SIG);

    final String[] argNames = new String[7];
    argNames[0] = DOCUMENT_PNAME;
    argNames[1] = "className";
    argNames[2] = TRANSLET_PNAME;
    argNames[3] = "order";
    argNames[4] = "type";
    argNames[5] = "lang";
    argNames[6] = "case_order";

    InstructionList il = new InstructionList();
    final MethodGenerator constructor =
        new MethodGenerator(
            ACC_PUBLIC,
            org.apache.bcel.generic.Type.VOID,
            argTypes,
            argNames,
            "<init>",
            className,
            il,
            cpg);

    // Push all parameters onto the stack and called super.<init>()
    il.append(ALOAD_0);
    il.append(ALOAD_1);
    il.append(ALOAD_2);
    il.append(new ALOAD(3));
    il.append(new ALOAD(4));
    il.append(new ALOAD(5));
    il.append(new ALOAD(6));
    il.append(new ALOAD(7));
    il.append(
        new INVOKESPECIAL(
            cpg.addMethodref(
                NODE_SORT_FACTORY,
                "<init>",
                "("
                    + DOM_INTF_SIG
                    + STRING_SIG
                    + TRANSLET_INTF_SIG
                    + "["
                    + STRING_SIG
                    + "["
                    + STRING_SIG
                    + "["
                    + STRING_SIG
                    + "["
                    + STRING_SIG
                    + ")V")));
    il.append(RETURN);

    // Override the definition of makeNodeSortRecord()
    il = new InstructionList();
    final MethodGenerator makeNodeSortRecord =
        new MethodGenerator(
            ACC_PUBLIC,
            Util.getJCRefType(NODE_SORT_RECORD_SIG),
            new org.apache.bcel.generic.Type[] {
              org.apache.bcel.generic.Type.INT, org.apache.bcel.generic.Type.INT
            },
            new String[] {"node", "last"},
            "makeNodeSortRecord",
            className,
            il,
            cpg);

    il.append(ALOAD_0);
    il.append(ILOAD_1);
    il.append(ILOAD_2);
    il.append(
        new INVOKESPECIAL(
            cpg.addMethodref(
                NODE_SORT_FACTORY, "makeNodeSortRecord", "(II)" + NODE_SORT_RECORD_SIG)));
    il.append(DUP);
    il.append(new CHECKCAST(cpg.addClass(sortRecordClass)));

    // Initialize closure in record class
    final int ndups = dups.size();
    for (int i = 0; i < ndups; i++) {
      final VariableRefBase varRef = (VariableRefBase) dups.get(i);
      final VariableBase var = varRef.getVariable();
      final Type varType = var.getType();

      il.append(DUP);

      // Get field from factory class
      il.append(ALOAD_0);
      il.append(
          new GETFIELD(cpg.addFieldref(className, var.getEscapedName(), varType.toSignature())));

      // Put field in record class
      il.append(
          new PUTFIELD(
              cpg.addFieldref(sortRecordClass, var.getEscapedName(), varType.toSignature())));
    }
    il.append(POP);
    il.append(ARETURN);

    constructor.setMaxLocals();
    constructor.setMaxStack();
    sortRecordFactory.addMethod(constructor);
    makeNodeSortRecord.setMaxLocals();
    makeNodeSortRecord.setMaxStack();
    sortRecordFactory.addMethod(makeNodeSortRecord);
    xsltc.dumpClass(sortRecordFactory.getJavaClass());

    return className;
  }