Mercurial > projects > ddmd
annotate dmd/TypeTypedef.d @ 187:b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
author | Abscissa |
---|---|
date | Tue, 07 Jun 2011 23:37:34 -0400 |
parents | e3afd1303184 |
children |
rev | line source |
---|---|
0 | 1 module dmd.TypeTypedef; |
2 | |
114 | 3 import dmd.common; |
0 | 4 import dmd.Type; |
5 import dmd.TypedefDeclaration; | |
6 import dmd.MOD; | |
7 import dmd.Loc; | |
8 import dmd.Id; | |
9 import dmd.Dsymbol; | |
10 import dmd.Scope; | |
11 import dmd.OutBuffer; | |
12 import dmd.HdrGenState; | |
13 import dmd.Expression; | |
14 import dmd.Identifier; | |
15 import dmd.ArrayTypes; | |
16 import dmd.MATCH; | |
17 import dmd.TypeSArray; | |
18 import dmd.CppMangleState; | |
19 import dmd.TypeInfoDeclaration; | |
20 import dmd.TypeInfoTypedefDeclaration; | |
21 import dmd.TY; | |
22 | |
23 import dmd.backend.TYPE; | |
24 import dmd.backend.dt_t; | |
25 | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
26 import dmd.DDMDExtensions; |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
27 |
0 | 28 class TypeTypedef : Type |
29 { | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
30 mixin insertMemberExtension!(typeof(this)); |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
31 |
0 | 32 TypedefDeclaration sym; |
33 | |
34 this(TypedefDeclaration sym) | |
35 { | |
178 | 36 register(); |
0 | 37 super(Ttypedef); |
38 this.sym = sym; | |
39 } | |
40 | |
72 | 41 override Type syntaxCopy() |
0 | 42 { |
43 assert(false); | |
44 } | |
45 | |
72 | 46 override ulong size(Loc loc) |
0 | 47 { |
48 return sym.basetype.size(loc); | |
49 } | |
50 | |
72 | 51 override uint alignsize() |
0 | 52 { |
53 assert(false); | |
54 } | |
55 | |
72 | 56 override string toChars() |
0 | 57 { |
58 assert(false); | |
59 } | |
60 | |
72 | 61 override Type semantic(Loc loc, Scope sc) |
0 | 62 { |
63 //printf("TypeTypedef::semantic(%s), sem = %d\n", toChars(), sym->sem); | |
64 sym.semantic(sc); | |
65 return merge(); | |
66 } | |
67 | |
72 | 68 override Dsymbol toDsymbol(Scope sc) |
0 | 69 { |
70 return sym; | |
71 } | |
72 | |
72 | 73 override void toDecoBuffer(OutBuffer buf, int flag) |
0 | 74 { |
75 Type.toDecoBuffer(buf, flag); | |
76 string name = sym.mangle(); | |
77 buf.printf("%s", name); | |
78 } | |
79 | |
72 | 80 override void toCBuffer2(OutBuffer buf, HdrGenState* hgs, MOD mod) |
0 | 81 { |
67 | 82 //printf("TypeTypedef.toCBuffer2() '%s'\n", sym.toChars()); |
83 if (mod != this.mod) | |
84 { | |
85 toCBuffer3(buf, hgs, mod); | |
86 return; | |
87 } | |
88 | |
89 buf.writestring(sym.toChars()); | |
0 | 90 } |
91 | |
72 | 92 override Expression dotExp(Scope sc, Expression e, Identifier ident) |
0 | 93 { |
94 version (LOGDOTEXP) { | |
95 printf("TypeTypedef.dotExp(e = '%s', ident = '%s') '%s'\n", e.toChars(), ident.toChars(), toChars()); | |
96 } | |
97 if (ident is Id.init_) | |
98 { | |
99 return Type.dotExp(sc, e, ident); | |
100 } | |
101 return sym.basetype.dotExp(sc, e, ident); | |
102 } | |
103 | |
72 | 104 override Expression getProperty(Loc loc, Identifier ident) |
0 | 105 { |
64 | 106 version (LOGDOTEXP) { |
107 printf("TypeTypedef.getProperty(ident = '%s') '%s'\n", ident.toChars(), toChars()); | |
108 } | |
109 if (ident == Id.init_) | |
110 { | |
111 return Type.getProperty(loc, ident); | |
112 } | |
113 return sym.basetype.getProperty(loc, ident); | |
0 | 114 } |
115 | |
116 bool isbit() | |
117 { | |
118 assert(false); | |
119 } | |
120 | |
72 | 121 override bool isintegral() |
0 | 122 { |
123 //printf("TypeTypedef::isintegral()\n"); | |
124 //printf("sym = '%s'\n", sym->toChars()); | |
125 //printf("basetype = '%s'\n", sym->basetype->toChars()); | |
126 return sym.basetype.isintegral(); | |
127 } | |
128 | |
72 | 129 override bool isfloating() |
0 | 130 { |
131 return sym.basetype.isfloating(); | |
132 } | |
133 | |
72 | 134 override bool isreal() |
0 | 135 { |
136 return sym.basetype.isreal(); | |
137 } | |
138 | |
72 | 139 override bool isimaginary() |
0 | 140 { |
141 return sym.basetype.isimaginary(); | |
142 } | |
143 | |
72 | 144 override bool iscomplex() |
0 | 145 { |
146 return sym.basetype.iscomplex(); | |
147 } | |
148 | |
72 | 149 override bool isscalar() |
0 | 150 { |
151 return sym.basetype.isscalar(); | |
152 } | |
153 | |
72 | 154 override bool isunsigned() |
0 | 155 { |
156 return sym.basetype.isunsigned(); | |
157 } | |
158 | |
72 | 159 override bool checkBoolean() |
0 | 160 { |
64 | 161 return sym.basetype.checkBoolean(); |
0 | 162 } |
163 | |
73 | 164 override bool isAssignable() |
0 | 165 { |
166 return sym.basetype.isAssignable(); | |
167 } | |
168 | |
72 | 169 override Type toBasetype() |
0 | 170 { |
171 if (sym.inuse) | |
172 { | |
173 sym.error("circular definition"); | |
174 sym.basetype = Type.terror; | |
175 return Type.terror; | |
176 } | |
177 sym.inuse = 1; | |
178 Type t = sym.basetype.toBasetype(); | |
179 sym.inuse = 0; | |
180 t = t.addMod(mod); | |
181 return t; | |
182 } | |
183 | |
72 | 184 override MATCH implicitConvTo(Type to) |
0 | 185 { |
186 MATCH m; | |
187 | |
188 //printf("TypeTypedef::implicitConvTo(to = %s) %s\n", to->toChars(), toChars()); | |
189 if (equals(to)) | |
190 m = MATCHexact; // exact match | |
191 else if (sym.basetype.implicitConvTo(to)) | |
192 m = MATCHconvert; // match with conversions | |
193 else if (ty == to.ty && sym == (cast(TypeTypedef)to).sym) | |
194 { | |
195 m = constConv(to); | |
196 } | |
197 else | |
198 m = MATCHnomatch; // no match | |
199 return m; | |
200 } | |
201 | |
72 | 202 override MATCH constConv(Type to) |
0 | 203 { |
53 | 204 if (equals(to)) |
205 return MATCHexact; | |
206 if (ty == to.ty && sym == (cast(TypeTypedef)to).sym) | |
207 return sym.basetype.implicitConvTo((cast(TypeTypedef)to).sym.basetype); | |
208 return MATCHnomatch; | |
0 | 209 } |
210 | |
72 | 211 override Expression defaultInit(Loc loc) |
0 | 212 { |
213 version (LOGDEFAULTINIT) { | |
214 printf("TypeTypedef::defaultInit() '%s'\n", toChars()); | |
215 } | |
216 if (sym.init) | |
217 { | |
218 //sym->init->toExpression()->print(); | |
219 return sym.init.toExpression(); | |
220 } | |
135 | 221 Type bt = sym.basetype; |
222 Expression e = bt.defaultInit(loc); | |
0 | 223 e.type = this; |
224 while (bt.ty == Tsarray) | |
225 { | |
226 TypeSArray tsa = cast(TypeSArray)bt; | |
227 e.type = tsa.next; | |
228 bt = tsa.next.toBasetype(); | |
229 } | |
230 return e; | |
231 } | |
232 | |
72 | 233 override bool isZeroInit(Loc loc) |
0 | 234 { |
235 if (sym.init) | |
236 { | |
237 if (sym.init.isVoidInitializer()) | |
238 return true; // initialize voids to 0 | |
239 Expression e = sym.init.toExpression(); | |
240 if (e && e.isBool(false)) | |
241 return true; | |
242 | |
243 return false; // assume not | |
244 } | |
245 if (sym.inuse) | |
246 { | |
247 sym.error("circular definition"); | |
248 sym.basetype = Type.terror; | |
249 } | |
250 sym.inuse = 1; | |
251 bool result = sym.basetype.isZeroInit(loc); | |
252 sym.inuse = 0; | |
253 | |
254 return result; | |
255 } | |
256 | |
72 | 257 override dt_t** toDt(dt_t** pdt) |
0 | 258 { |
259 if (sym.init) | |
260 { | |
261 dt_t* dt = sym.init.toDt(); | |
262 | |
263 while (*pdt) | |
264 pdt = &((*pdt).DTnext); | |
265 *pdt = dt; | |
266 return pdt; | |
267 } | |
268 | |
269 sym.basetype.toDt(pdt); | |
270 return pdt; | |
271 } | |
272 | |
72 | 273 override MATCH deduceType(Scope sc, Type tparam, TemplateParameters parameters, Objects dedtypes) |
0 | 274 { |
63 | 275 // Extra check |
276 if (tparam && tparam.ty == Ttypedef) | |
277 { | |
278 TypeTypedef tp = cast(TypeTypedef)tparam; | |
279 | |
280 if (sym != tp.sym) | |
281 return MATCHnomatch; | |
282 } | |
283 return Type.deduceType(sc, tparam, parameters, dedtypes); | |
0 | 284 } |
285 | |
72 | 286 override TypeInfoDeclaration getTypeInfoDeclaration() |
0 | 287 { |
288 return new TypeInfoTypedefDeclaration(this); | |
289 } | |
290 | |
72 | 291 override bool hasPointers() |
0 | 292 { |
293 return toBasetype().hasPointers(); | |
294 } | |
295 | |
135 | 296 override int hasWild() |
297 { | |
298 return mod & MOD.MODwild || toBasetype().hasWild(); | |
299 } | |
300 | |
72 | 301 override Type toHeadMutable() |
0 | 302 { |
303 assert(false); | |
304 } | |
305 | |
306 version (CPP_MANGLE) { | |
307 void toCppMangle(OutBuffer buf, CppMangleState* cms) | |
308 { | |
309 assert(false); | |
310 } | |
311 } | |
312 | |
72 | 313 override type* toCtype() |
0 | 314 { |
315 return sym.basetype.toCtype(); | |
316 } | |
317 | |
72 | 318 override type* toCParamtype() |
0 | 319 { |
320 return sym.basetype.toCParamtype(); | |
321 } | |
72 | 322 } |