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