Mercurial > projects > ddmd
comparison dmd/TypeTypedef.d @ 0:10317f0c89a5
Initial commit
author | korDen |
---|---|
date | Sat, 24 Oct 2009 08:42:06 +0400 |
parents | |
children | a8b50ff7f201 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:10317f0c89a5 |
---|---|
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 { | |
192 assert(false); | |
193 } | |
194 | |
195 Expression defaultInit(Loc loc) | |
196 { | |
197 Expression e; | |
198 Type bt; | |
199 | |
200 version (LOGDEFAULTINIT) { | |
201 printf("TypeTypedef::defaultInit() '%s'\n", toChars()); | |
202 } | |
203 if (sym.init) | |
204 { | |
205 //sym->init->toExpression()->print(); | |
206 return sym.init.toExpression(); | |
207 } | |
208 bt = sym.basetype; | |
209 e = bt.defaultInit(loc); | |
210 e.type = this; | |
211 while (bt.ty == Tsarray) | |
212 { | |
213 TypeSArray tsa = cast(TypeSArray)bt; | |
214 e.type = tsa.next; | |
215 bt = tsa.next.toBasetype(); | |
216 } | |
217 return e; | |
218 } | |
219 | |
220 bool isZeroInit(Loc loc) | |
221 { | |
222 if (sym.init) | |
223 { | |
224 if (sym.init.isVoidInitializer()) | |
225 return true; // initialize voids to 0 | |
226 Expression e = sym.init.toExpression(); | |
227 if (e && e.isBool(false)) | |
228 return true; | |
229 | |
230 return false; // assume not | |
231 } | |
232 if (sym.inuse) | |
233 { | |
234 sym.error("circular definition"); | |
235 sym.basetype = Type.terror; | |
236 } | |
237 sym.inuse = 1; | |
238 bool result = sym.basetype.isZeroInit(loc); | |
239 sym.inuse = 0; | |
240 | |
241 return result; | |
242 } | |
243 | |
244 dt_t** toDt(dt_t** pdt) | |
245 { | |
246 if (sym.init) | |
247 { | |
248 dt_t* dt = sym.init.toDt(); | |
249 | |
250 while (*pdt) | |
251 pdt = &((*pdt).DTnext); | |
252 *pdt = dt; | |
253 return pdt; | |
254 } | |
255 | |
256 sym.basetype.toDt(pdt); | |
257 return pdt; | |
258 } | |
259 | |
260 MATCH deduceType(Scope sc, Type tparam, TemplateParameters parameters, Objects dedtypes) | |
261 { | |
262 assert(false); | |
263 } | |
264 | |
265 TypeInfoDeclaration getTypeInfoDeclaration() | |
266 { | |
267 return new TypeInfoTypedefDeclaration(this); | |
268 } | |
269 | |
270 bool hasPointers() | |
271 { | |
272 return toBasetype().hasPointers(); | |
273 } | |
274 | |
275 Type toHeadMutable() | |
276 { | |
277 assert(false); | |
278 } | |
279 | |
280 version (CPP_MANGLE) { | |
281 void toCppMangle(OutBuffer buf, CppMangleState* cms) | |
282 { | |
283 assert(false); | |
284 } | |
285 } | |
286 | |
287 type* toCtype() | |
288 { | |
289 return sym.basetype.toCtype(); | |
290 } | |
291 | |
292 type* toCParamtype() | |
293 { | |
294 return sym.basetype.toCParamtype(); | |
295 } | |
296 } |