1 package polyglot.ext.pao.types; 2 3 import java.util.Collections ; 4 import java.util.Iterator ; 5 import java.util.LinkedList ; 6 import java.util.List ; 7 8 import polyglot.ext.jl.types.TypeSystem_c; 9 import polyglot.frontend.Source; 10 import polyglot.types.*; 11 import polyglot.util.InternalCompilerError; 12 13 17 public class PaoTypeSystem_c extends TypeSystem_c implements PaoTypeSystem { 18 19 23 public PrimitiveType createPrimitive(PrimitiveType.Kind kind) { 24 return new PaoPrimitiveType_c(this, kind); 25 } 26 27 31 public ParsedClassType createClassType(LazyClassInitializer init, 32 Source fromSource) { 33 return new PaoParsedClassType_c(this, init, fromSource); 34 } 35 36 40 private static final String RUNTIME_PACKAGE = "polyglot.ext.pao.runtime"; 41 42 45 public MethodInstance primitiveEquals() { 46 String name = RUNTIME_PACKAGE + ".Primitive"; 49 50 try { 51 Type ct = (Type) systemResolver().find(name); 53 54 List args = new LinkedList (); 56 args.add(Object()); 57 args.add(Object()); 58 59 List l = ct.toClass().methods("equals", args); 61 if (!l.isEmpty()) { 62 return (MethodInstance)l.get(0); 63 } 64 } 65 catch (SemanticException e) { 66 throw new InternalCompilerError(e.getMessage()); 67 } 68 69 throw new InternalCompilerError("Could not find equals method."); 70 } 71 72 public MethodInstance getter(PrimitiveType t) { 73 76 String methodName = t.toString() + "Value"; 77 78 ReferenceType boxedType = boxedType(t); 80 81 List l = boxedType.methods(methodName, Collections.EMPTY_LIST); 84 if (!l.isEmpty()) { 85 return (MethodInstance)l.get(0); 86 } 87 88 throw new InternalCompilerError("Could not find getter for " + t); 89 } 90 91 public ClassType boxedType(PrimitiveType t) { 92 95 String name = RUNTIME_PACKAGE + "." 96 + wrapperTypeString(t).substring("java.lang.".length()); 97 98 try { 99 return ((Type)systemResolver().find(name)).toClass(); 100 101 } 102 catch (SemanticException e) { 103 throw new InternalCompilerError(e.getMessage()); 104 } 105 } 106 107 public ConstructorInstance wrapper(PrimitiveType t) { 108 111 ClassType ct = boxedType(t); 112 for (Iterator i = ct.constructors().iterator(); i.hasNext(); ) { 113 ConstructorInstance ci = (ConstructorInstance) i.next(); 114 if (ci.formalTypes().size() == 1) { 115 Type argType = (Type) ci.formalTypes().get(0); 116 if (equals(argType, t)) { 117 return ci; 119 } 120 } 121 } 122 123 throw new InternalCompilerError("Could not find constructor for " + t); 124 } 125 } 126 | Popular Tags |