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 {
|
|
101 assert(false);
|
|
102 }
|
|
103
|
|
104 bool isbit()
|
|
105 {
|
|
106 assert(false);
|
|
107 }
|
|
108
|
|
109 bool isintegral()
|
|
110 {
|
|
111 //printf("TypeTypedef::isintegral()\n");
|
|
112 //printf("sym = '%s'\n", sym->toChars());
|
|
113 //printf("basetype = '%s'\n", sym->basetype->toChars());
|
|
114 return sym.basetype.isintegral();
|
|
115 }
|
|
116
|
|
117 bool isfloating()
|
|
118 {
|
|
119 return sym.basetype.isfloating();
|
|
120 }
|
|
121
|
|
122 bool isreal()
|
|
123 {
|
|
124 return sym.basetype.isreal();
|
|
125 }
|
|
126
|
|
127 bool isimaginary()
|
|
128 {
|
|
129 return sym.basetype.isimaginary();
|
|
130 }
|
|
131
|
|
132 bool iscomplex()
|
|
133 {
|
|
134 return sym.basetype.iscomplex();
|
|
135 }
|
|
136
|
|
137 bool isscalar()
|
|
138 {
|
|
139 return sym.basetype.isscalar();
|
|
140 }
|
|
141
|
|
142 bool isunsigned()
|
|
143 {
|
|
144 return sym.basetype.isunsigned();
|
|
145 }
|
|
146
|
|
147 bool checkBoolean()
|
|
148 {
|
|
149 assert(false);
|
|
150 }
|
|
151
|
|
152 int isAssignable()
|
|
153 {
|
|
154 return sym.basetype.isAssignable();
|
|
155 }
|
|
156
|
|
157 Type toBasetype()
|
|
158 {
|
|
159 if (sym.inuse)
|
|
160 {
|
|
161 sym.error("circular definition");
|
|
162 sym.basetype = Type.terror;
|
|
163 return Type.terror;
|
|
164 }
|
|
165 sym.inuse = 1;
|
|
166 Type t = sym.basetype.toBasetype();
|
|
167 sym.inuse = 0;
|
|
168 t = t.addMod(mod);
|
|
169 return t;
|
|
170 }
|
|
171
|
|
172 MATCH implicitConvTo(Type to)
|
|
173 {
|
|
174 MATCH m;
|
|
175
|
|
176 //printf("TypeTypedef::implicitConvTo(to = %s) %s\n", to->toChars(), toChars());
|
|
177 if (equals(to))
|
|
178 m = MATCHexact; // exact match
|
|
179 else if (sym.basetype.implicitConvTo(to))
|
|
180 m = MATCHconvert; // match with conversions
|
|
181 else if (ty == to.ty && sym == (cast(TypeTypedef)to).sym)
|
|
182 {
|
|
183 m = constConv(to);
|
|
184 }
|
|
185 else
|
|
186 m = MATCHnomatch; // no match
|
|
187 return m;
|
|
188 }
|
|
189
|
|
190 MATCH constConv(Type to)
|
|
191 {
|
53
|
192 if (equals(to))
|
|
193 return MATCHexact;
|
|
194 if (ty == to.ty && sym == (cast(TypeTypedef)to).sym)
|
|
195 return sym.basetype.implicitConvTo((cast(TypeTypedef)to).sym.basetype);
|
|
196 return MATCHnomatch;
|
0
|
197 }
|
|
198
|
|
199 Expression defaultInit(Loc loc)
|
|
200 {
|
|
201 Expression e;
|
|
202 Type bt;
|
|
203
|
|
204 version (LOGDEFAULTINIT) {
|
|
205 printf("TypeTypedef::defaultInit() '%s'\n", toChars());
|
|
206 }
|
|
207 if (sym.init)
|
|
208 {
|
|
209 //sym->init->toExpression()->print();
|
|
210 return sym.init.toExpression();
|
|
211 }
|
|
212 bt = sym.basetype;
|
|
213 e = bt.defaultInit(loc);
|
|
214 e.type = this;
|
|
215 while (bt.ty == Tsarray)
|
|
216 {
|
|
217 TypeSArray tsa = cast(TypeSArray)bt;
|
|
218 e.type = tsa.next;
|
|
219 bt = tsa.next.toBasetype();
|
|
220 }
|
|
221 return e;
|
|
222 }
|
|
223
|
|
224 bool isZeroInit(Loc loc)
|
|
225 {
|
|
226 if (sym.init)
|
|
227 {
|
|
228 if (sym.init.isVoidInitializer())
|
|
229 return true; // initialize voids to 0
|
|
230 Expression e = sym.init.toExpression();
|
|
231 if (e && e.isBool(false))
|
|
232 return true;
|
|
233
|
|
234 return false; // assume not
|
|
235 }
|
|
236 if (sym.inuse)
|
|
237 {
|
|
238 sym.error("circular definition");
|
|
239 sym.basetype = Type.terror;
|
|
240 }
|
|
241 sym.inuse = 1;
|
|
242 bool result = sym.basetype.isZeroInit(loc);
|
|
243 sym.inuse = 0;
|
|
244
|
|
245 return result;
|
|
246 }
|
|
247
|
|
248 dt_t** toDt(dt_t** pdt)
|
|
249 {
|
|
250 if (sym.init)
|
|
251 {
|
|
252 dt_t* dt = sym.init.toDt();
|
|
253
|
|
254 while (*pdt)
|
|
255 pdt = &((*pdt).DTnext);
|
|
256 *pdt = dt;
|
|
257 return pdt;
|
|
258 }
|
|
259
|
|
260 sym.basetype.toDt(pdt);
|
|
261 return pdt;
|
|
262 }
|
|
263
|
|
264 MATCH deduceType(Scope sc, Type tparam, TemplateParameters parameters, Objects dedtypes)
|
|
265 {
|
|
266 assert(false);
|
|
267 }
|
|
268
|
|
269 TypeInfoDeclaration getTypeInfoDeclaration()
|
|
270 {
|
|
271 return new TypeInfoTypedefDeclaration(this);
|
|
272 }
|
|
273
|
|
274 bool hasPointers()
|
|
275 {
|
|
276 return toBasetype().hasPointers();
|
|
277 }
|
|
278
|
|
279 Type toHeadMutable()
|
|
280 {
|
|
281 assert(false);
|
|
282 }
|
|
283
|
|
284 version (CPP_MANGLE) {
|
|
285 void toCppMangle(OutBuffer buf, CppMangleState* cms)
|
|
286 {
|
|
287 assert(false);
|
|
288 }
|
|
289 }
|
|
290
|
|
291 type* toCtype()
|
|
292 {
|
|
293 return sym.basetype.toCtype();
|
|
294 }
|
|
295
|
|
296 type* toCParamtype()
|
|
297 {
|
|
298 return sym.basetype.toCParamtype();
|
|
299 }
|
|
300 } |