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