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