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