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