Package org.allspice.bytecode

Examples of org.allspice.bytecode.TypeName


    }
    l.add(new InvokeSpecial(mref)) ;
  }

  public static void createNewArray(EvaluationContext context, final Collection<? extends Expr> size, TypeName type, InstList l) throws CompilerException {
    TypeName baseType = type ;
    for(Expr e: size) {
      context.compile(null,e, l) ;
      if (!baseType.toString().endsWith("[]")) {
        throw new InvalidArray() ;
      }
      baseType = baseType.getArrayBase() ;
    }
    l.add(new New(baseType,size.size())) ;
  }
View Full Code Here


      return TypeName.FLOAT ;
    }
    if (cl == Double.class) {
      return TypeName.DOUBLE ;
    }
    return new TypeName(cl.getName()) ;
  }
View Full Code Here

    }
  }

  public static void createFieldVar(EvaluationContext context, Expr e,
      final String name, InstList l) throws CompilerException, UndefinedField {
    TypeName classname = getClassName(context,e) ;
    StubResolver type ;
    if (classname == null) {
      type = context.getType(e);
      if (type.getTypeCode() == TypeCode.ARRAY && name.equals("length")) {
        context.compile(null,e, l) ;
View Full Code Here

    }
    throw new UndefinedField(type.getTypeName().toString(),name) ;
  }
 
  public static StubResolver getClassReference(EvaluationContext context, Expr obj) throws CompilerException {
    TypeName type = getClassName(context,obj) ;
    if (type == null) {
      return context.getType(obj);
    }
    return context.makeTypeRef(type) ;
  }
View Full Code Here

  }

  public static StubResolver getFieldVarType(EvaluationContext context, Expr obj,
      final String name) throws CompilerException, UndefinedField {
    StubResolver type ;
    TypeName classname = getClassName(context,obj) ;
    if (classname == null) {
      type = context.getType(obj);
      if (type.getTypeCode() == TypeCode.ARRAY && name.equals("length")) {
        return context.makeTypeRef(TypeCode.INT) ;
      }
View Full Code Here

  }
 
  public static TypeName getClassName(EvaluationContext context,Expr e) throws CompilerException {
    if (e instanceof VarExpr) {
      String decl = ((VarExpr)e).var;
      final TypeName type = context.getType(decl);
      if (type != null) {
        return null ;
      }
      FieldStub fd = context.getField(context.classDef,decl) ;
      if (fd != null) {
        return null ;
      }
      if (context.classPool.isPackageOrClass(decl)) {
        return context.fullyQualified(decl) ;
      }
      return null ;
    }
    else if (e instanceof FieldVarExpr) {
      FieldVarExpr fve = (FieldVarExpr)e ;
      Expr obj = fve.object ;
      String name = fve.name ;
      TypeName type = getClassName(context,obj);
      if (type == null) {
        return null ;
      }
      String full = type+"."+name ;
      if (context.classPool.isPackageOrClass(full)) {
        return new TypeName(full) ;
      }
      return null ;

    }
    else {
View Full Code Here

      return null ;
    }
  }

  public static StubResolver getVarType(EvaluationContext context, String decl) throws CompilerException {
    final TypeName type = context.getType(decl);
    if (type != null) {
      return context.makeTypeRef(type) ;
    }
    FieldStub fd = context.getField(context.classDef,decl) ;
    if (fd != null) {
View Full Code Here

      return s1 ;
    }
    Set<TypeName> s1map = getSuperClassOrder(s1) ;
    Set<TypeName> s2map = getSuperClassOrder(s2) ;
    s1map.retainAll(s2map) ;
    final TypeName t ;
    if (!s1map.isEmpty()) {
      t = s1map.iterator().next();
    }
    else {
      t = TypeName.OBJECT ;
    }
    Set<StubResolver> ifaces1 = new HashSet<StubResolver>() ;
    Set<StubResolver> ifaces2 = new HashSet<StubResolver>() ;
    addInterfaces(classPool,s1,t,ifaces1) ;
    addInterfaces(classPool,s2,t,ifaces2) ;
    ifaces1.retainAll(ifaces2) ;
    int comb = s1.hashCode() ^ s2.hashCode();
    if (comb < 0) comb = -comb ;
    final TypeName cname = new TypeName("genclass"+comb);
    ClassStub stub = new ClassStub(cname,classPool.new SimpleResolver(t),false) ;
    for(StubResolver iface: ifaces1) {
      stub = stub.addInterface(iface) ;
    }
    final ClassStub cstub = stub ;
View Full Code Here

  public static StubResolver getCommon(final ClassPool pool,StubResolver td1,StubResolver td2) throws CompilerException {
    final StubResolver base1 = td1.getTypeCode() == TypeCode.ARRAY ? td1.getArrayBase() : null ;
    final StubResolver base2 = td2.getTypeCode() == TypeCode.ARRAY ? td2.getArrayBase() : null ;
    if (base1 != null && base2 != null) {
      final StubResolver arrayBase = getCommon(pool,base1,base2);
      final TypeName arrayType = arrayBase.getTypeName().makeArray();
      final ClassStub stub = new ClassStub(arrayType,pool.new SimpleResolver(TypeName.OBJECT),false) ;
      return new StubResolver() {

        @Override
        public StubResolver getArrayBase() {
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

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.