Mercurial > projects > ddmd
annotate dmd/TypeEnum.d @ 146:af7e5ebef6ad
redundant extern(C)
author | Eldar Insafutdinov <e.insafutdinov@gmail.com> |
---|---|
date | Tue, 14 Sep 2010 23:34:50 +0100 |
parents | af1bebfd96a4 |
children | 0c8cc2a10f99 |
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 { |
135 | 192 if (equals(to)) |
193 return MATCHexact; | |
194 if (ty == to.ty && sym == (cast(TypeEnum)to).sym && | |
195 MODimplicitConv(mod, to.mod)) | |
196 return MATCHconst; | |
197 return MATCHnomatch; | |
0 | 198 } |
199 | |
72 | 200 override Type toBasetype() |
0 | 201 { |
135 | 202 if (sym.scope_) |
203 { | |
204 sym.semantic(null); // attempt to resolve forward reference | |
205 } | |
0 | 206 if (!sym.memtype) |
207 { | |
208 debug writef("2: "); | |
209 error(sym.loc, "enum %s is forward referenced", sym.toChars()); | |
210 return tint32; | |
211 } | |
212 | |
213 return sym.memtype.toBasetype(); | |
214 } | |
215 | |
72 | 216 override Expression defaultInit(Loc loc) |
0 | 217 { |
218 version (LOGDEFAULTINIT) { | |
219 printf("TypeEnum::defaultInit() '%s'\n", toChars()); | |
220 } | |
221 // Initialize to first member of enum | |
222 //printf("%s\n", sym.defaultval.type.toChars()); | |
223 if (!sym.defaultval) | |
224 { | |
225 error(loc, "forward reference of %s.init", toChars()); | |
226 return new ErrorExp(); | |
227 } | |
228 return sym.defaultval; | |
229 } | |
230 | |
72 | 231 override bool isZeroInit(Loc loc) |
0 | 232 { |
233 if (!sym.defaultval) | |
234 { | |
235 debug writef("3: "); | |
236 error(loc, "enum %s is forward referenced", sym.toChars()); | |
237 return 0; | |
238 } | |
239 return sym.defaultval.isBool(false); | |
240 } | |
241 | |
93
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
79
diff
changeset
|
242 override MATCH deduceType(Scope sc, Type tparam, TemplateParameters parameters, Objects dedtypes) |
0 | 243 { |
93
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
79
diff
changeset
|
244 // Extra check |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
79
diff
changeset
|
245 if (tparam && tparam.ty == Tenum) |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
79
diff
changeset
|
246 { |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
79
diff
changeset
|
247 TypeEnum tp = cast(TypeEnum)tparam; |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
79
diff
changeset
|
248 |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
79
diff
changeset
|
249 if (sym != tp.sym) |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
79
diff
changeset
|
250 return MATCHnomatch; |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
79
diff
changeset
|
251 } |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
79
diff
changeset
|
252 return Type.deduceType(sc, tparam, parameters, dedtypes); |
0 | 253 } |
254 | |
72 | 255 override TypeInfoDeclaration getTypeInfoDeclaration() |
0 | 256 { |
257 return new TypeInfoEnumDeclaration(this); | |
258 } | |
259 | |
72 | 260 override bool hasPointers() |
0 | 261 { |
262 return toBasetype().hasPointers(); | |
263 } | |
264 | |
265 version (CPP_MANGLE) { | |
266 void toCppMangle(OutBuffer buf, CppMangleState* cms) | |
267 { | |
268 assert(false); | |
269 } | |
270 } | |
271 | |
72 | 272 override type* toCtype() |
0 | 273 { |
274 return sym.memtype.toCtype(); | |
275 } | |
72 | 276 } |