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