Mercurial > projects > ddmd
annotate dmd/TypeEnum.d @ 168:ceed63f310fb
stringtable, stringbuffer and freelist moved to Global
author | korDen |
---|---|
date | Thu, 30 Sep 2010 12:57:13 +0400 |
parents | 0c8cc2a10f99 |
children | e3afd1303184 |
rev | line source |
---|---|
0 | 1 module dmd.TypeEnum; |
2 | |
114 | 3 import dmd.common; |
0 | 4 import dmd.Type; |
5 import dmd.EnumDeclaration; | |
6 import dmd.Scope; | |
7 import dmd.Loc; | |
8 import dmd.Id; | |
9 import dmd.ErrorExp; | |
10 import dmd.Dsymbol; | |
11 import dmd.EnumMember; | |
12 import dmd.OutBuffer; | |
13 import dmd.HdrGenState; | |
14 import dmd.Expression; | |
15 import dmd.Identifier; | |
16 import dmd.MATCH; | |
17 import dmd.OutBuffer; | |
18 import dmd.CppMangleState; | |
156 | 19 import dmd.StringExp; |
0 | 20 import dmd.TypeInfoDeclaration; |
21 import dmd.TypeInfoEnumDeclaration; | |
22 import dmd.ArrayTypes; | |
23 import dmd.TY; | |
68
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
0
diff
changeset
|
24 import dmd.MOD; |
0 | 25 import dmd.Util; |
26 | |
27 import dmd.backend.TYPE; | |
28 | |
29 class TypeEnum : Type | |
30 { | |
31 EnumDeclaration sym; | |
32 | |
33 this(EnumDeclaration sym) | |
34 { | |
35 super(TY.Tenum); | |
36 this.sym = sym; | |
37 } | |
38 | |
39 version (DumbClone) { | |
40 } else { | |
41 Type clone() | |
42 { | |
43 assert(false); | |
44 } | |
45 } | |
72 | 46 override Type syntaxCopy() |
0 | 47 { |
48 assert(false); | |
49 } | |
50 | |
72 | 51 override ulong size(Loc loc) |
0 | 52 { |
53 if (!sym.memtype) | |
54 { | |
55 error(loc, "enum %s is forward referenced", sym.toChars()); | |
56 return 4; | |
57 } | |
58 return sym.memtype.size(loc); | |
59 } | |
60 | |
156 | 61 override uint alignsize() |
0 | 62 { |
156 | 63 if (!sym.memtype) |
64 { | |
65 debug writef("1: "); | |
66 | |
67 error(Loc(0), "enum %s is forward referenced", sym.toChars()); | |
68 return 4; | |
69 } | |
70 return sym.memtype.alignsize(); | |
0 | 71 } |
156 | 72 |
73 override string toChars() | |
0 | 74 { |
156 | 75 if (mod) |
76 return super.toChars(); | |
77 return sym.toChars(); | |
0 | 78 } |
79 | |
72 | 80 override Type semantic(Loc loc, Scope sc) |
0 | 81 { |
82 //printf("TypeEnum::semantic() %s\n", toChars()); | |
83 //sym.semantic(sc); | |
84 return merge(); | |
85 } | |
86 | |
72 | 87 override Dsymbol toDsymbol(Scope sc) |
0 | 88 { |
89 return sym; | |
90 } | |
91 | |
72 | 92 override void toDecoBuffer(OutBuffer buf, int flag) |
0 | 93 { |
94 string name = sym.mangle(); | |
95 Type.toDecoBuffer(buf, flag); | |
96 buf.printf("%s", name); | |
97 } | |
98 | |
72 | 99 override void toCBuffer2(OutBuffer buf, HdrGenState* hgs, MOD mod) |
0 | 100 { |
68
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
0
diff
changeset
|
101 if (mod != this.mod) |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
0
diff
changeset
|
102 { |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
0
diff
changeset
|
103 toCBuffer3(buf, hgs, mod); |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
0
diff
changeset
|
104 return; |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
0
diff
changeset
|
105 } |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
0
diff
changeset
|
106 buf.writestring(sym.toChars()); |
0 | 107 } |
108 | |
72 | 109 override Expression dotExp(Scope sc, Expression e, Identifier ident) |
0 | 110 { |
111 version (LOGDOTEXP) { | |
112 printf("TypeEnum::dotExp(e = '%s', ident = '%s') '%s'\n", e.toChars(), ident.toChars(), toChars()); | |
113 } | |
114 Dsymbol s = sym.search(e.loc, ident, 0); | |
115 if (!s) | |
116 { | |
117 if (ident is Id.max || | |
118 ident is Id.min || | |
119 ident is Id.init_ || | |
120 ident is Id.stringof_ || | |
121 !sym.memtype | |
122 ) | |
123 { | |
124 return getProperty(e.loc, ident); | |
125 } | |
126 | |
127 return sym.memtype.dotExp(sc, e, ident); | |
128 } | |
129 | |
130 EnumMember m = s.isEnumMember(); | |
131 Expression em = m.value.copy(); | |
132 em.loc = e.loc; | |
133 return em; | |
134 } | |
135 | |
156 | 136 override Expression getProperty(Loc loc, Identifier ident) |
0 | 137 { |
156 | 138 Expression e; |
139 | |
140 if (ident is Id.max) | |
141 { | |
142 if (!sym.maxval) | |
143 goto Lfwd; | |
144 e = sym.maxval; | |
145 } | |
146 else if (ident is Id.min) | |
147 { | |
148 if (!sym.minval) | |
149 goto Lfwd; | |
150 e = sym.minval; | |
151 } | |
152 else if (ident is Id.init_) | |
153 { | |
154 e = defaultInitLiteral(loc); | |
155 } | |
156 else if (ident is Id.stringof_) | |
157 { | |
158 string s = toChars(); | |
159 e = new StringExp(loc, s, 'c'); | |
160 Scope sc; | |
161 e = e.semantic(sc); | |
162 } | |
163 else if (ident is Id.mangleof_) | |
164 { | |
165 e = Type.getProperty(loc, ident); | |
166 } | |
167 else | |
168 { | |
169 e = toBasetype().getProperty(loc, ident); | |
170 } | |
171 return e; | |
172 | |
173 Lfwd: | |
174 error(loc, "forward reference of %s.%s", toChars(), ident.toChars()); | |
175 return new ErrorExp(); | |
0 | 176 } |
177 | |
72 | 178 override bool isintegral() |
0 | 179 { |
73 | 180 return sym.memtype.isintegral(); |
0 | 181 } |
182 | |
72 | 183 override bool isfloating() |
0 | 184 { |
73 | 185 return sym.memtype.isfloating(); |
186 } | |
187 | |
79 | 188 override bool isreal() |
73 | 189 { |
190 return sym.memtype.isreal(); | |
191 } | |
192 | |
79 | 193 override bool isimaginary() |
73 | 194 { |
195 return sym.memtype.isimaginary(); | |
196 } | |
197 | |
79 | 198 override bool iscomplex() |
73 | 199 { |
200 return sym.memtype.iscomplex(); | |
201 } | |
202 | |
79 | 203 override bool checkBoolean() |
73 | 204 { |
205 return sym.memtype.checkBoolean(); | |
206 } | |
207 | |
79 | 208 override bool isAssignable() |
73 | 209 { |
210 return sym.memtype.isAssignable(); | |
0 | 211 } |
212 | |
72 | 213 override bool isscalar() |
0 | 214 { |
73 | 215 return sym.memtype.isscalar(); |
0 | 216 } |
217 | |
72 | 218 override bool isunsigned() |
0 | 219 { |
220 return sym.memtype.isunsigned(); | |
221 } | |
222 | |
72 | 223 override MATCH implicitConvTo(Type to) |
0 | 224 { |
225 MATCH m; | |
226 | |
227 //printf("TypeEnum::implicitConvTo()\n"); | |
228 if (ty == to.ty && sym == (cast(TypeEnum)to).sym) | |
229 m = (mod == to.mod) ? MATCHexact : MATCHconst; | |
230 else if (sym.memtype.implicitConvTo(to)) | |
231 m = MATCHconvert; // match with conversions | |
232 else | |
233 m = MATCHnomatch; // no match | |
234 return m; | |
235 } | |
236 | |
72 | 237 override MATCH constConv(Type to) |
0 | 238 { |
135 | 239 if (equals(to)) |
240 return MATCHexact; | |
241 if (ty == to.ty && sym == (cast(TypeEnum)to).sym && | |
242 MODimplicitConv(mod, to.mod)) | |
243 return MATCHconst; | |
244 return MATCHnomatch; | |
0 | 245 } |
246 | |
72 | 247 override Type toBasetype() |
0 | 248 { |
135 | 249 if (sym.scope_) |
250 { | |
251 sym.semantic(null); // attempt to resolve forward reference | |
252 } | |
0 | 253 if (!sym.memtype) |
254 { | |
255 debug writef("2: "); | |
256 error(sym.loc, "enum %s is forward referenced", sym.toChars()); | |
257 return tint32; | |
258 } | |
259 | |
260 return sym.memtype.toBasetype(); | |
261 } | |
262 | |
72 | 263 override Expression defaultInit(Loc loc) |
0 | 264 { |
265 version (LOGDEFAULTINIT) { | |
266 printf("TypeEnum::defaultInit() '%s'\n", toChars()); | |
267 } | |
268 // Initialize to first member of enum | |
269 //printf("%s\n", sym.defaultval.type.toChars()); | |
270 if (!sym.defaultval) | |
271 { | |
272 error(loc, "forward reference of %s.init", toChars()); | |
273 return new ErrorExp(); | |
274 } | |
275 return sym.defaultval; | |
276 } | |
277 | |
72 | 278 override bool isZeroInit(Loc loc) |
0 | 279 { |
280 if (!sym.defaultval) | |
281 { | |
282 debug writef("3: "); | |
283 error(loc, "enum %s is forward referenced", sym.toChars()); | |
284 return 0; | |
285 } | |
286 return sym.defaultval.isBool(false); | |
287 } | |
288 | |
93
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
79
diff
changeset
|
289 override MATCH deduceType(Scope sc, Type tparam, TemplateParameters parameters, Objects dedtypes) |
0 | 290 { |
93
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
79
diff
changeset
|
291 // Extra check |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
79
diff
changeset
|
292 if (tparam && tparam.ty == Tenum) |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
79
diff
changeset
|
293 { |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
79
diff
changeset
|
294 TypeEnum tp = cast(TypeEnum)tparam; |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
79
diff
changeset
|
295 |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
79
diff
changeset
|
296 if (sym != tp.sym) |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
79
diff
changeset
|
297 return MATCHnomatch; |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
79
diff
changeset
|
298 } |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
79
diff
changeset
|
299 return Type.deduceType(sc, tparam, parameters, dedtypes); |
0 | 300 } |
301 | |
72 | 302 override TypeInfoDeclaration getTypeInfoDeclaration() |
0 | 303 { |
304 return new TypeInfoEnumDeclaration(this); | |
305 } | |
306 | |
72 | 307 override bool hasPointers() |
0 | 308 { |
309 return toBasetype().hasPointers(); | |
310 } | |
311 | |
312 version (CPP_MANGLE) { | |
313 void toCppMangle(OutBuffer buf, CppMangleState* cms) | |
314 { | |
315 assert(false); | |
316 } | |
317 } | |
318 | |
72 | 319 override type* toCtype() |
0 | 320 { |
321 return sym.memtype.toCtype(); | |
322 } | |
72 | 323 } |