Mercurial > projects > ddmd
annotate dmd/TypeEnum.d @ 68:ee3a9f34dc48
final bits of codegen implementation to compile Phobos
author | korDen |
---|---|
date | Tue, 24 Aug 2010 16:44:34 +0400 |
parents | 10317f0c89a5 |
children | 2e2a5c3f943a |
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 } | |
44 Type syntaxCopy() | |
45 { | |
46 assert(false); | |
47 } | |
48 | |
49 ulong size(Loc loc) | |
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 | |
59 uint alignsize() | |
60 { | |
61 assert(false); | |
62 } | |
63 | |
64 string toChars() | |
65 { | |
66 assert(false); | |
67 } | |
68 | |
69 Type semantic(Loc loc, Scope sc) | |
70 { | |
71 //printf("TypeEnum::semantic() %s\n", toChars()); | |
72 //sym.semantic(sc); | |
73 return merge(); | |
74 } | |
75 | |
76 Dsymbol toDsymbol(Scope sc) | |
77 { | |
78 return sym; | |
79 } | |
80 | |
81 void toDecoBuffer(OutBuffer buf, int flag) | |
82 { | |
83 string name = sym.mangle(); | |
84 Type.toDecoBuffer(buf, flag); | |
85 buf.printf("%s", name); | |
86 } | |
87 | |
68
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
0
diff
changeset
|
88 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 | |
98 Expression dotExp(Scope sc, Expression e, Identifier ident) | |
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 | |
125 Expression getProperty(Loc loc, Identifier ident) | |
126 { | |
127 assert(false); | |
128 } | |
129 | |
130 bool isintegral() | |
131 { | |
132 return true; | |
133 } | |
134 | |
135 bool isfloating() | |
136 { | |
137 return false; | |
138 } | |
139 | |
140 bool isscalar() | |
141 { | |
142 return true; | |
143 //return sym.memtype.isscalar(); | |
144 } | |
145 | |
146 bool isunsigned() | |
147 { | |
148 return sym.memtype.isunsigned(); | |
149 } | |
150 | |
151 MATCH implicitConvTo(Type to) | |
152 { | |
153 MATCH m; | |
154 | |
155 //printf("TypeEnum::implicitConvTo()\n"); | |
156 if (ty == to.ty && sym == (cast(TypeEnum)to).sym) | |
157 m = (mod == to.mod) ? MATCHexact : MATCHconst; | |
158 else if (sym.memtype.implicitConvTo(to)) | |
159 m = MATCHconvert; // match with conversions | |
160 else | |
161 m = MATCHnomatch; // no match | |
162 return m; | |
163 } | |
164 | |
165 MATCH constConv(Type to) | |
166 { | |
167 assert(false); | |
168 } | |
169 | |
170 Type toBasetype() | |
171 { | |
172 if (!sym.memtype) | |
173 { | |
174 debug writef("2: "); | |
175 error(sym.loc, "enum %s is forward referenced", sym.toChars()); | |
176 return tint32; | |
177 } | |
178 | |
179 return sym.memtype.toBasetype(); | |
180 } | |
181 | |
182 Expression defaultInit(Loc loc) | |
183 { | |
184 version (LOGDEFAULTINIT) { | |
185 printf("TypeEnum::defaultInit() '%s'\n", toChars()); | |
186 } | |
187 // Initialize to first member of enum | |
188 //printf("%s\n", sym.defaultval.type.toChars()); | |
189 if (!sym.defaultval) | |
190 { | |
191 error(loc, "forward reference of %s.init", toChars()); | |
192 return new ErrorExp(); | |
193 } | |
194 return sym.defaultval; | |
195 } | |
196 | |
197 bool isZeroInit(Loc loc) | |
198 { | |
199 if (!sym.defaultval) | |
200 { | |
201 debug writef("3: "); | |
202 error(loc, "enum %s is forward referenced", sym.toChars()); | |
203 return 0; | |
204 } | |
205 return sym.defaultval.isBool(false); | |
206 } | |
207 | |
208 MATCH deduceType(Scope sc, Type tparam, TemplateParameters parameters, Objects dedtypes) | |
209 { | |
210 assert(false); | |
211 } | |
212 | |
213 TypeInfoDeclaration getTypeInfoDeclaration() | |
214 { | |
215 return new TypeInfoEnumDeclaration(this); | |
216 } | |
217 | |
218 bool hasPointers() | |
219 { | |
220 return toBasetype().hasPointers(); | |
221 } | |
222 | |
223 version (CPP_MANGLE) { | |
224 void toCppMangle(OutBuffer buf, CppMangleState* cms) | |
225 { | |
226 assert(false); | |
227 } | |
228 } | |
229 | |
230 type* toCtype() | |
231 { | |
232 return sym.memtype.toCtype(); | |
233 } | |
234 } |