Mercurial > projects > ddmd
annotate dmd/TypeEnum.d @ 114:e28b18c23469
added a module dmd.common for commonly used stuff
it currently holds code for consistency checking of predefined versions
also added a VisualD project file
author | Trass3r |
---|---|
date | Wed, 01 Sep 2010 18:21:58 +0200 |
parents | df6d0f967680 |
children | af1bebfd96a4 |
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; | |
19 import dmd.TypeInfoDeclaration; | |
20 import dmd.TypeInfoEnumDeclaration; | |
21 import dmd.ArrayTypes; | |
22 import dmd.TY; | |
68
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
0
diff
changeset
|
23 import dmd.MOD; |
0 | 24 import dmd.Util; |
25 | |
26 import dmd.backend.TYPE; | |
27 | |
28 class TypeEnum : Type | |
29 { | |
30 EnumDeclaration sym; | |
31 | |
32 this(EnumDeclaration sym) | |
33 { | |
34 super(TY.Tenum); | |
35 this.sym = sym; | |
36 } | |
37 | |
38 version (DumbClone) { | |
39 } else { | |
40 Type clone() | |
41 { | |
42 assert(false); | |
43 } | |
44 } | |
72 | 45 override Type syntaxCopy() |
0 | 46 { |
47 assert(false); | |
48 } | |
49 | |
72 | 50 override ulong size(Loc loc) |
0 | 51 { |
52 if (!sym.memtype) | |
53 { | |
54 error(loc, "enum %s is forward referenced", sym.toChars()); | |
55 return 4; | |
56 } | |
57 return sym.memtype.size(loc); | |
58 } | |
59 | |
72 | 60 override uint alignsize() |
0 | 61 { |
62 assert(false); | |
63 } | |
64 | |
72 | 65 override string toChars() |
0 | 66 { |
67 assert(false); | |
68 } | |
69 | |
72 | 70 override Type semantic(Loc loc, Scope sc) |
0 | 71 { |
72 //printf("TypeEnum::semantic() %s\n", toChars()); | |
73 //sym.semantic(sc); | |
74 return merge(); | |
75 } | |
76 | |
72 | 77 override Dsymbol toDsymbol(Scope sc) |
0 | 78 { |
79 return sym; | |
80 } | |
81 | |
72 | 82 override void toDecoBuffer(OutBuffer buf, int flag) |
0 | 83 { |
84 string name = sym.mangle(); | |
85 Type.toDecoBuffer(buf, flag); | |
86 buf.printf("%s", name); | |
87 } | |
88 | |
72 | 89 override void toCBuffer2(OutBuffer buf, HdrGenState* hgs, MOD mod) |
0 | 90 { |
68
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
0
diff
changeset
|
91 if (mod != this.mod) |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
0
diff
changeset
|
92 { |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
0
diff
changeset
|
93 toCBuffer3(buf, hgs, mod); |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
0
diff
changeset
|
94 return; |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
0
diff
changeset
|
95 } |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
0
diff
changeset
|
96 buf.writestring(sym.toChars()); |
0 | 97 } |
98 | |
72 | 99 override Expression dotExp(Scope sc, Expression e, Identifier ident) |
0 | 100 { |
101 version (LOGDOTEXP) { | |
102 printf("TypeEnum::dotExp(e = '%s', ident = '%s') '%s'\n", e.toChars(), ident.toChars(), toChars()); | |
103 } | |
104 Dsymbol s = sym.search(e.loc, ident, 0); | |
105 if (!s) | |
106 { | |
107 if (ident is Id.max || | |
108 ident is Id.min || | |
109 ident is Id.init_ || | |
110 ident is Id.stringof_ || | |
111 !sym.memtype | |
112 ) | |
113 { | |
114 return getProperty(e.loc, ident); | |
115 } | |
116 | |
117 return sym.memtype.dotExp(sc, e, ident); | |
118 } | |
119 | |
120 EnumMember m = s.isEnumMember(); | |
121 Expression em = m.value.copy(); | |
122 em.loc = e.loc; | |
123 return em; | |
124 } | |
125 | |
72 | 126 override Expression getProperty(Loc loc, Identifier ident) |
0 | 127 { |
128 assert(false); | |
129 } | |
130 | |
72 | 131 override bool isintegral() |
0 | 132 { |
73 | 133 return sym.memtype.isintegral(); |
0 | 134 } |
135 | |
72 | 136 override bool isfloating() |
0 | 137 { |
73 | 138 return sym.memtype.isfloating(); |
139 } | |
140 | |
79 | 141 override bool isreal() |
73 | 142 { |
143 return sym.memtype.isreal(); | |
144 } | |
145 | |
79 | 146 override bool isimaginary() |
73 | 147 { |
148 return sym.memtype.isimaginary(); | |
149 } | |
150 | |
79 | 151 override bool iscomplex() |
73 | 152 { |
153 return sym.memtype.iscomplex(); | |
154 } | |
155 | |
79 | 156 override bool checkBoolean() |
73 | 157 { |
158 return sym.memtype.checkBoolean(); | |
159 } | |
160 | |
79 | 161 override bool isAssignable() |
73 | 162 { |
163 return sym.memtype.isAssignable(); | |
0 | 164 } |
165 | |
72 | 166 override bool isscalar() |
0 | 167 { |
73 | 168 return sym.memtype.isscalar(); |
0 | 169 } |
170 | |
72 | 171 override bool isunsigned() |
0 | 172 { |
173 return sym.memtype.isunsigned(); | |
174 } | |
175 | |
72 | 176 override MATCH implicitConvTo(Type to) |
0 | 177 { |
178 MATCH m; | |
179 | |
180 //printf("TypeEnum::implicitConvTo()\n"); | |
181 if (ty == to.ty && sym == (cast(TypeEnum)to).sym) | |
182 m = (mod == to.mod) ? MATCHexact : MATCHconst; | |
183 else if (sym.memtype.implicitConvTo(to)) | |
184 m = MATCHconvert; // match with conversions | |
185 else | |
186 m = MATCHnomatch; // no match | |
187 return m; | |
188 } | |
189 | |
72 | 190 override MATCH constConv(Type to) |
0 | 191 { |
192 assert(false); | |
193 } | |
194 | |
72 | 195 override Type toBasetype() |
0 | 196 { |
197 if (!sym.memtype) | |
198 { | |
199 debug writef("2: "); | |
200 error(sym.loc, "enum %s is forward referenced", sym.toChars()); | |
201 return tint32; | |
202 } | |
203 | |
204 return sym.memtype.toBasetype(); | |
205 } | |
206 | |
72 | 207 override Expression defaultInit(Loc loc) |
0 | 208 { |
209 version (LOGDEFAULTINIT) { | |
210 printf("TypeEnum::defaultInit() '%s'\n", toChars()); | |
211 } | |
212 // Initialize to first member of enum | |
213 //printf("%s\n", sym.defaultval.type.toChars()); | |
214 if (!sym.defaultval) | |
215 { | |
216 error(loc, "forward reference of %s.init", toChars()); | |
217 return new ErrorExp(); | |
218 } | |
219 return sym.defaultval; | |
220 } | |
221 | |
72 | 222 override bool isZeroInit(Loc loc) |
0 | 223 { |
224 if (!sym.defaultval) | |
225 { | |
226 debug writef("3: "); | |
227 error(loc, "enum %s is forward referenced", sym.toChars()); | |
228 return 0; | |
229 } | |
230 return sym.defaultval.isBool(false); | |
231 } | |
232 | |
93
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
79
diff
changeset
|
233 override MATCH deduceType(Scope sc, Type tparam, TemplateParameters parameters, Objects dedtypes) |
0 | 234 { |
93
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
79
diff
changeset
|
235 // Extra check |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
79
diff
changeset
|
236 if (tparam && tparam.ty == Tenum) |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
79
diff
changeset
|
237 { |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
79
diff
changeset
|
238 TypeEnum tp = cast(TypeEnum)tparam; |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
79
diff
changeset
|
239 |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
79
diff
changeset
|
240 if (sym != tp.sym) |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
79
diff
changeset
|
241 return MATCHnomatch; |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
79
diff
changeset
|
242 } |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
79
diff
changeset
|
243 return Type.deduceType(sc, tparam, parameters, dedtypes); |
0 | 244 } |
245 | |
72 | 246 override TypeInfoDeclaration getTypeInfoDeclaration() |
0 | 247 { |
248 return new TypeInfoEnumDeclaration(this); | |
249 } | |
250 | |
72 | 251 override bool hasPointers() |
0 | 252 { |
253 return toBasetype().hasPointers(); | |
254 } | |
255 | |
256 version (CPP_MANGLE) { | |
257 void toCppMangle(OutBuffer buf, CppMangleState* cms) | |
258 { | |
259 assert(false); | |
260 } | |
261 } | |
262 | |
72 | 263 override type* toCtype() |
0 | 264 { |
265 return sym.memtype.toCtype(); | |
266 } | |
72 | 267 } |