Package org.allspice.bytecode

Examples of org.allspice.bytecode.TypeName


import org.allspice.bytecode.instructions.Return;

public class TestRem extends MyTestCase {
  public ClassDef defadd(String ret,String type,int i1,int i2) {
    ClassDef cd = makeClassDef() ;
    Var x = new Var(i1,new TypeName(type)) ;
    Var y = new Var(i2,new TypeName(type)) ;
    MethodDef md = new MethodDef(new TypeName(ret),"meth",x,y) ;
    md = md.addInstructions(
        new Load(x),
        new Load(y),
        new Remainder(TypeCode.getType(type)),
        new Return(TypeCode.getType(ret))
View Full Code Here


import org.allspice.bytecode.instructions.Return;

public class TestMul extends MyTestCase {
  public ClassDef defadd(String ret,String type,int i1,int i2) {
    ClassDef cd = makeClassDef() ;
    Var x = new Var(i1,new TypeName(type)) ;
    Var y = new Var(i2,new TypeName(type)) ;
    MethodDef md = new MethodDef(new TypeName(ret),"meth",x,y) ;
    md = md.addInstructions(
        new Load(x),
        new Load(y),
        new Multiply(TypeCode.getType(type)),
        new Return(TypeCode.getType(ret))
View Full Code Here

   * Creates a ClassDef consisting of a constructor
   * and a single method add(int,int)
   * @return The ClassDef
   */
  public static ClassDef makeAddClass() {
    ClassDef cd = new ClassDef(ClassDefType.DEFAULT,null,new TypeName("TestClass"),TypeName.OBJECT) ;
    {
      // constructor called <init>
      // must call superclass's <init>
      // Returns nothing
      MethodDef md = new MethodDef(TypeName.VOID,"<init>").addInstructions(
          new Load(new Var(0,new TypeName("TestClass"))),
          new InvokeSpecial(new MethodRef(cd.superClass,TypeName.VOID,"<init>")),
          new Return(TypeCode.VOID)
      ) ;
      // Watch it!  ClassDef is immutable
      cd = cd.addMethod(md) ;
View Full Code Here

    myClasses = allClasses.clone();
    for(FileUnit fu: fileUnits) {
      final FileUnitInfo fuinfo = new FileUnitInfo(fu);
      this.units.put(fu,fuinfo) ;
      for(ClassDecl cd: fu.classDecl) {
        TypeName cname = getClassName(fu,cd);
        myClasses.add(cname.toString().replace(".","/")) ;
      }
    }
    for(FileUnit fu: fileUnits) {
      final FileUnitInfo fuinfo = units.get(fu) ;
      for(String imp: fuinfo.unit.imports) {
View Full Code Here

  }

  public ClassDecl getClassDecl(TypeName name) {
    for(FileUnit fu: units.keySet()) {
      for(ClassDecl cd: fu.classDecl) {
        TypeName cname = getClassName(fu,cd) ;
        if (cname.equals(name)) {
          return cd ;
        }
      }
    }
    return null ;
View Full Code Here

      classStubs.put(name,stub) ;
      return stub ;
    }
    for(FileUnit fu: units.keySet()) {
      for(ClassDecl cd: fu.classDecl) {
        TypeName cname = ClassPool.getClassName(fu,cd) ;
        if (cname.equals(name)) {
          ClassStub stub = makeClassDeclStub(units.get(fu),cd);
          classStubs.put(name,stub) ;
          return stub ;
        }
      }
View Full Code Here

  private ClassStub makeJavaClassStub(JavaClass realClass) {
    ClassStub stub;
    StubResolver superc ;
    if (realClass.getSuperclassName() != null && !realClass.getSuperclassName().equals(realClass.getClassName())) {
      superc = new SimpleResolver(new TypeName(realClass.getSuperclassName())) ;
    }
    else {
      superc = null ;
    }

    final TypeName cname = new TypeName(realClass.getClassName());
    stub = new ClassStub(cname,superc,realClass.isInterface()) ;
    StubResolver myStub = new SimpleResolver(cname) ;
   
    final com.sun.org.apache.bcel.internal.classfile.Method[] methods = realClass.getMethods();
    for(com.sun.org.apache.bcel.internal.classfile.Method meth: methods) {
      Type[] type = meth.getArgumentTypes();
      FIFO<StubResolver> types = new FIFO<StubResolver>() ;
      for(Type ptype: type) {
        types = types.insert(new SimpleResolver(new TypeName(ptype.toString()))) ;
      }
      boolean isStatic = false ;
      boolean isPrivate = false ;
      if ((meth.getModifiers() & Modifier.STATIC) != 0) {
        isStatic = true ;       
      }
      if ((meth.getModifiers() & Modifier.PRIVATE) != 0) {
        isPrivate = true ;       
      }
      final TypeName mname = new TypeName(meth.getReturnType().toString()) ;
      StubResolver retType = new SimpleResolver(mname) ;
      stub = stub.addMethod(new MethodStub(meth.getName(),myStub,retType,types,isStatic,isPrivate)) ;
    }
   
    com.sun.org.apache.bcel.internal.classfile.Field[] fields = realClass.getFields();
    for(com.sun.org.apache.bcel.internal.classfile.Field fld: fields) {
      final boolean isStatic = (fld.getModifiers() & Modifier.STATIC) != 0;
      final boolean isFinal = (fld.getModifiers() & Modifier.FINAL) != 0;
      StubResolver fldstub = new SimpleResolver(new TypeName(fld.getType().toString())) ;
      if (isStatic && isFinal) {
        ConstantValue cv = fld.getConstantValue();
        Object o ;
        if (cv != null) {
          Constant c = cv.getConstantPool().getConstant(cv.getConstantValueIndex());
          if (c instanceof ConstantObject) {
            o = ((ConstantObject)c).getConstantValue(cv.getConstantPool()) ;
            try {
              o = StdJavaExpressions.cast( this, fldstub, new ConstObj(o)) ;
            } catch (CompilerException e) {
              o = null ;
            }
          }
          else {
            o = null ;
          }
        }
        else {
          o = null ;
        }
        if (o != null) {
          final FieldStub fldDef = new FieldStub(fld.getName(),myStub,fldstub,isStatic,isFinal,new ConstExpr(o,null));
          stub = stub.addField(fldDef) ;
          continue ;
        }
      }
      stub = stub.addField(new FieldStub(fld.getName(),myStub,fldstub,isStatic,isFinal,null));

    }
   
    String[] ifaces = realClass.getInterfaceNames();
    for(String iface: ifaces) {
      stub = stub.addInterface(new SimpleResolver(new TypeName(iface))) ;
    }
    return stub;
  }
View Full Code Here

    return stub;
  }
 
  private ClassStub makeClassDeclStub(FileUnitInfo finfo,ClassDecl cd) {
    ClassStub stub;
    TypeName cname = getClassName(finfo.unit,cd) ;
    StubResolver enclosing = new SimpleResolver(cname) ;
    stub = new ClassStub(cname,new SimpleResolver(finfo.getFullQualified(cd.superClass)),cd.classType == ClassType.INTERFACE) ;
    classStubs.put(cname,stub) ;
    boolean foundInit = false ;
    for(FieldOrMethod fom: cd.decls) {
View Full Code Here

    }
    return true;
  }
 
  public static TypeName getClassName(FileUnit fu,ClassDecl cd) {
    return new TypeName((fu.packageName == null ? "" : (fu.packageName+"."))+cd.name);
  }
View Full Code Here

      super();
      this.unit = unit;
    }
    public TypeName getFullQualified(String type) {
      if (type.endsWith("[]")) {
        return new TypeName(getFullQualified(type.substring(0,type.length() - 2))+"[]") ;
      }
      TypeName fq = aliases.get(type) ;
      if (fq != null) {
        return fq ;
      }
      return new TypeName(type) ;
    }
View Full Code Here

TOP

Related Classes of org.allspice.bytecode.TypeName

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.