001 /* Copyright 2000, 2001, Compaq Computer Corporation */ 002 003 package escjava.tc; 004 005 import javafe.ast.*; 006 import escjava.ast.TagConstants; 007 008 import javafe.tc.*; 009 010 import javafe.util.*; 011 012 public class Types extends javafe.tc.Types 013 { 014 static { 015 inst = new Types(); 016 } 017 018 public static void init() { 019 } 020 021 protected javafe.tc.TypeSig makeTypeSigInstance(String simpleName, 022 /*@ non_null */ Env enclosingEnv, 023 /*@ non_null */ TypeDecl decl) { 024 return new escjava.tc.TypeSig(simpleName, 025 enclosingEnv, 026 decl); 027 } 028 029 protected javafe.tc.TypeSig makeTypeSigInstance(String[] packageName, 030 /*@ non_null */ String simpleName, 031 javafe.tc.TypeSig enclosingType, 032 TypeDecl decl, 033 CompilationUnit cu) { 034 return new escjava.tc.TypeSig(packageName, simpleName, 035 enclosingType, decl, cu); 036 } 037 038 039 public static PrimitiveType 040 anyType = PrimitiveType.make(TagConstants.ANY, Location.NULL); 041 042 public static PrimitiveType 043 typecodeType = PrimitiveType.make(TagConstants.TYPECODE, Location.NULL); 044 //public static Type typecodeType = javaLangClass(); 045 046 public static PrimitiveType 047 locksetType = PrimitiveType.make(TagConstants.LOCKSET, Location.NULL); 048 049 public static PrimitiveType 050 objectsetType = PrimitiveType.make(TagConstants.OBJECTSET, Location.NULL); 051 052 public static PrimitiveType 053 rangeType = PrimitiveType.make(TagConstants.DOTDOT, Location.NULL); 054 055 //@ invariant bigintType != null; 056 public static PrimitiveType 057 bigintType = PrimitiveType.make( TagConstants.BIGINTTYPE, Location.NULL ); 058 059 //@ invariant realType != null; 060 public static PrimitiveType 061 realType = PrimitiveType.make( TagConstants.REALTYPE, Location.NULL ); 062 063 064 public static boolean isTypeType(Type t) { 065 //return t.getTag() == TagConstants.TYPECODE; 066 return t.getTag() == TagConstants.TYPECODE || t.equals(javaLangClass()); 067 } 068 069 070 public boolean isSameTypeInstance(Type t, Type tt) { 071 if (isTypeType(t) && isTypeType(tt)) return true; 072 return super.isSameTypeInstance(t,tt); 073 } 074 075 public boolean isCastableInstance(Type t, Type tt) { 076 boolean b = super.isCastableInstance(t,tt); 077 if (b) return b; 078 if (t.getTag() == TagConstants.BYTETYPE && 079 tt.getTag() == TagConstants.BIGINTTYPE) return true; 080 if (t.getTag() == TagConstants.SHORTTYPE && 081 tt.getTag() == TagConstants.BIGINTTYPE) return true; 082 if (t.getTag() == TagConstants.INTTYPE && 083 tt.getTag() == TagConstants.BIGINTTYPE) return true; 084 if (t.getTag() == TagConstants.LONGTYPE && 085 tt.getTag() == TagConstants.BIGINTTYPE) return true; 086 if (t.getTag() == TagConstants.TYPECODE) 087 return super.isCastableInstance(javaLangClass(),tt); 088 if (tt.getTag() == TagConstants.TYPECODE) 089 return super.isCastableInstance(t,javaLangClass()); 090 return b; 091 } 092 093 public boolean isIntegralTypeInstance(Type t){ 094 if ((t instanceof PrimitiveType) && 095 ((PrimitiveType)t).getTag() == TagConstants.BIGINTTYPE) return true; 096 return super.isIntegralTypeInstance(t); 097 } 098 099 public boolean isNumericTypeInstance(Type t){ 100 if( t instanceof PrimitiveType ) { 101 PrimitiveType p = (PrimitiveType)t; 102 if (p.getTag() == TagConstants.BIGINTTYPE) return true; 103 if (p.getTag() == TagConstants.REALTYPE) return true; 104 } 105 return super.isNumericTypeInstance(t); 106 } 107 108 public boolean isFloatingPointTypeInstance(Type t){ 109 if( t instanceof PrimitiveType ) { 110 if (((PrimitiveType)t).tag == TagConstants.REALTYPE) return true; 111 } 112 return super.isFloatingPointTypeInstance(t); 113 } 114 115 protected boolean isWideningPrimitiveConvertableInstance( Type x, Type y ) { 116 117 switch( x.getTag() ) { 118 case TagConstants.BYTETYPE: 119 case TagConstants.SHORTTYPE: 120 case TagConstants.INTTYPE: 121 case TagConstants.LONGTYPE: 122 switch( y.getTag() ) { 123 case TagConstants.BIGINTTYPE: 124 case TagConstants.REALTYPE: 125 return true; 126 default: 127 break; 128 } 129 130 case TagConstants.BIGINTTYPE: 131 switch( y.getTag() ) { 132 case TagConstants.REALTYPE: 133 return true; 134 default: 135 break; 136 } 137 138 case TagConstants.FLOATTYPE: 139 case TagConstants.DOUBLETYPE: 140 switch( y.getTag() ) { 141 case TagConstants.REALTYPE: 142 return true; 143 default: 144 break; 145 } 146 default: 147 break; 148 } 149 150 return super.isWideningPrimitiveConvertableInstance(x,y); 151 } 152 153 154 155 /** 156 * This routine overrides {@link javafe.tc.Types#lookupField}. Unlike that 157 * routine, it knows about ghost fields and spec_public. 158 * 159 * <p> This routine assumes we are in an annotation so ghost fields are visible 160 * and spec_public is equivalent to public. </a> 161 */ 162 /* 163 //@ requires t != null 164 public FieldDecl lookupFieldInstance(Type t, Identifier id, javafe.tc.TypeSig caller) 165 throws LookupException { 166 Assert.notNull(t); 167 if (t instanceof TypeName) 168 t = TypeSig.getSig((TypeName) t); 169 Assert.notNull(t); 170 171 / * 172 * Looking up a field in an arraytype is equivalent to looking 173 * up that field in java.lang.Object unless the field name is 174 * "length": 175 * / 176 if (t instanceof ArrayType && id != javafe.tc.Types.lenId) 177 t = javaLangObject(); 178 179 // Our functionality is different only for TypeSigs: 180 if (!(t instanceof TypeSig)) 181 return javafe.tc.Types.lookupField(t, id, caller); 182 TypeSig sig = (TypeSig)t; 183 184 // /* 185 // * Extend caller to handle spec_public: 186 // * / 187 // caller = new ExtendedTypeSig(caller); 188 189 // Search for a normal field first; propogate any errors other 190 // than NOTFOUND: 191 try { 192 return sig.lookupField(id, caller); 193 } catch (LookupException E) { 194 if (E.reason != LookupException.NOTFOUND) 195 throw E; 196 } 197 198 // If not found, search for a ghost field: 199 GhostEnv G = new GhostEnv(sig.getEnclosingEnv(), sig, false); 200 FieldDecl decl = G.getGhostField(id.toString(), null); 201 if (decl==null) 202 throw new LookupException(LookupException.NOTFOUND); 203 204 // Make sure the ghost field is not ambiguous: 205 if (G.getGhostField(id.toString(), decl) != null) 206 throw new LookupException(LookupException.AMBIGUOUS); 207 208 // Ghost fields are always public, so no access checking required... 209 // FIXME - no longer true 210 211 return decl; 212 } 213 */ 214 } // end of class Types 215 216 /* 217 * Local Variables: 218 * Mode: Java 219 * fill-column: 85 220 * End: 221 */