Mercurial > projects > ldc
annotate gen/typinf.cpp @ 102:027b8d8b71ec trunk
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
Basically it tries to do the following in order: Resolve types, Declare symbols, Create constant initializers, Apply initializers, Generate functions bodies.
ClassInfo is now has the most useful(biased?) members working.
Probably other stuf...
author | lindquist |
---|---|
date | Sun, 18 Nov 2007 06:52:57 +0100 |
parents | 5071469303d4 |
children | 182b41f56b7f |
rev | line source |
---|---|
1 | 1 |
2 | |
3 // Copyright (c) 1999-2004 by Digital Mars | |
4 // All Rights Reserved | |
5 // written by Walter Bright | |
6 // www.digitalmars.com | |
7 // License for redistribution is by either the Artistic License | |
8 // in artistic.txt, or the GNU General Public License in gnu.txt. | |
9 // See the included readme.txt for details. | |
10 | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
11 // Modifications for LLVMDC: |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
12 // Copyright (c) 2007 by Tomas Lindquist Olsen |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
13 // tomas at famolsen dk |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
14 |
1 | 15 #include <cstdio> |
16 #include <cassert> | |
17 | |
52 | 18 #include "gen/llvm.h" |
19 | |
1 | 20 #include "mars.h" |
21 #include "module.h" | |
22 #include "mtype.h" | |
23 #include "scope.h" | |
24 #include "init.h" | |
25 #include "expression.h" | |
26 #include "attrib.h" | |
27 #include "declaration.h" | |
28 #include "template.h" | |
29 #include "id.h" | |
30 #include "enum.h" | |
31 #include "import.h" | |
32 #include "aggregate.h" | |
33 | |
52 | 34 #include "gen/irstate.h" |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
35 #include "gen/logger.h" |
52 | 36 #include "gen/runtime.h" |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
37 #include "gen/tollvm.h" |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
38 #include "gen/arrays.h" |
100 | 39 #include "gen/structs.h" |
1 | 40 |
41 /******************************************* | |
42 * Get a canonicalized form of the TypeInfo for use with the internal | |
43 * runtime library routines. Canonicalized in that static arrays are | |
44 * represented as dynamic arrays, enums are represented by their | |
45 * underlying type, etc. This reduces the number of TypeInfo's needed, | |
46 * so we can use the custom internal ones more. | |
47 */ | |
48 | |
49 Expression *Type::getInternalTypeInfo(Scope *sc) | |
50 { TypeInfoDeclaration *tid; | |
51 Expression *e; | |
52 Type *t; | |
53 static TypeInfoDeclaration *internalTI[TMAX]; | |
54 | |
55 //printf("Type::getInternalTypeInfo() %s\n", toChars()); | |
56 t = toBasetype(); | |
57 switch (t->ty) | |
58 { | |
59 case Tsarray: | |
60 t = t->next->arrayOf(); // convert to corresponding dynamic array type | |
61 break; | |
62 | |
63 case Tclass: | |
64 if (((TypeClass *)t)->sym->isInterfaceDeclaration()) | |
65 break; | |
66 goto Linternal; | |
67 | |
68 case Tarray: | |
69 if (t->next->ty != Tclass) | |
70 break; | |
71 goto Linternal; | |
72 | |
73 case Tfunction: | |
74 case Tdelegate: | |
75 case Tpointer: | |
76 Linternal: | |
77 tid = internalTI[t->ty]; | |
78 if (!tid) | |
79 { tid = new TypeInfoDeclaration(t, 1); | |
80 internalTI[t->ty] = tid; | |
81 } | |
82 e = new VarExp(0, tid); | |
52 | 83 //e = e->addressOf(sc); |
1 | 84 e->type = tid->type; // do this so we don't get redundant dereference |
85 return e; | |
86 | |
87 default: | |
88 break; | |
89 } | |
90 //printf("\tcalling getTypeInfo() %s\n", t->toChars()); | |
91 return t->getTypeInfo(sc); | |
92 } | |
93 | |
94 | |
95 /**************************************************** | |
96 * Get the exact TypeInfo. | |
97 */ | |
98 | |
99 Expression *Type::getTypeInfo(Scope *sc) | |
100 { | |
101 Expression *e; | |
102 Type *t; | |
103 | |
104 //printf("Type::getTypeInfo() %p, %s\n", this, toChars()); | |
105 t = merge(); // do this since not all Type's are merge'd | |
106 if (!t->vtinfo) | |
107 { t->vtinfo = t->getTypeInfoDeclaration(); | |
108 assert(t->vtinfo); | |
109 | |
110 /* If this has a custom implementation in std/typeinfo, then | |
111 * do not generate a COMDAT for it. | |
112 */ | |
113 if (!t->builtinTypeInfo()) | |
114 { // Generate COMDAT | |
115 if (sc) // if in semantic() pass | |
116 { // Find module that will go all the way to an object file | |
117 Module *m = sc->module->importedFrom; | |
118 m->members->push(t->vtinfo); | |
119 } | |
120 else // if in obj generation pass | |
121 { | |
122 t->vtinfo->toObjFile(); | |
123 } | |
124 } | |
125 } | |
126 e = new VarExp(0, t->vtinfo); | |
127 //e = e->addressOf(sc); | |
128 e->type = t->vtinfo->type; // do this so we don't get redundant dereference | |
129 return e; | |
130 } | |
131 | |
52 | 132 enum RET TypeFunction::retStyle() |
133 { | |
134 return RETstack; | |
135 } | |
1 | 136 |
137 TypeInfoDeclaration *Type::getTypeInfoDeclaration() | |
138 { | |
139 //printf("Type::getTypeInfoDeclaration() %s\n", toChars()); | |
140 return new TypeInfoDeclaration(this, 0); | |
141 } | |
142 | |
52 | 143 TypeInfoDeclaration *TypeTypedef::getTypeInfoDeclaration() |
1 | 144 { |
52 | 145 return new TypeInfoTypedefDeclaration(this); |
1 | 146 } |
147 | |
52 | 148 TypeInfoDeclaration *TypePointer::getTypeInfoDeclaration() |
149 { | |
150 return new TypeInfoPointerDeclaration(this); | |
151 } | |
1 | 152 |
153 TypeInfoDeclaration *TypeDArray::getTypeInfoDeclaration() | |
154 { | |
155 return new TypeInfoArrayDeclaration(this); | |
156 } | |
157 | |
158 TypeInfoDeclaration *TypeSArray::getTypeInfoDeclaration() | |
159 { | |
160 return new TypeInfoStaticArrayDeclaration(this); | |
161 } | |
162 | |
163 TypeInfoDeclaration *TypeAArray::getTypeInfoDeclaration() | |
164 { | |
165 return new TypeInfoAssociativeArrayDeclaration(this); | |
166 } | |
167 | |
52 | 168 TypeInfoDeclaration *TypeStruct::getTypeInfoDeclaration() |
169 { | |
170 return new TypeInfoStructDeclaration(this); | |
171 } | |
1 | 172 |
173 TypeInfoDeclaration *TypeClass::getTypeInfoDeclaration() | |
174 { | |
175 if (sym->isInterfaceDeclaration()) | |
176 return new TypeInfoInterfaceDeclaration(this); | |
177 else | |
178 return new TypeInfoClassDeclaration(this); | |
179 } | |
180 | |
181 TypeInfoDeclaration *TypeEnum::getTypeInfoDeclaration() | |
182 { | |
183 return new TypeInfoEnumDeclaration(this); | |
184 } | |
185 | |
186 TypeInfoDeclaration *TypeFunction::getTypeInfoDeclaration() | |
187 { | |
188 return new TypeInfoFunctionDeclaration(this); | |
189 } | |
190 | |
191 TypeInfoDeclaration *TypeDelegate::getTypeInfoDeclaration() | |
192 { | |
193 return new TypeInfoDelegateDeclaration(this); | |
194 } | |
195 | |
196 TypeInfoDeclaration *TypeTuple::getTypeInfoDeclaration() | |
197 { | |
198 return new TypeInfoTupleDeclaration(this); | |
199 } | |
200 | |
201 | |
202 /* ========================================================================= */ | |
203 | |
204 /* These decide if there's an instance for them already in std.typeinfo, | |
205 * because then the compiler doesn't need to build one. | |
206 */ | |
207 | |
208 int Type::builtinTypeInfo() | |
209 { | |
210 return 0; | |
211 } | |
212 | |
213 int TypeBasic::builtinTypeInfo() | |
214 { | |
215 return 1; | |
216 } | |
217 | |
218 int TypeDArray::builtinTypeInfo() | |
219 { | |
52 | 220 return next->isTypeBasic() != NULL; |
1 | 221 } |
222 | |
223 /* ========================================================================= */ | |
224 | |
225 /*************************************** | |
226 * Create a static array of TypeInfo references | |
227 * corresponding to an array of Expression's. | |
228 * Used to supply hidden _arguments[] value for variadic D functions. | |
229 */ | |
230 | |
57
a9d29e9f1fed
[svn r61] Added support for D-style variadic functions :)
lindquist
parents:
54
diff
changeset
|
231 Expression *createTypeInfoArray(Scope *sc, Expression *exps[], int dim) |
1 | 232 { |
233 assert(0); | |
57
a9d29e9f1fed
[svn r61] Added support for D-style variadic functions :)
lindquist
parents:
54
diff
changeset
|
234 return NULL; |
1 | 235 } |
236 | |
52 | 237 /* ========================================================================= */ |
238 | |
239 ////////////////////////////////////////////////////////////////////////////// | |
240 // MAGIC PLACE | |
241 ////////////////////////////////////////////////////////////////////////////// | |
242 | |
243 void TypeInfoDeclaration::toObjFile() | |
244 { | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
245 gIR->resolveList.push_back(this); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
246 } |
57
a9d29e9f1fed
[svn r61] Added support for D-style variadic functions :)
lindquist
parents:
54
diff
changeset
|
247 |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
248 void DtoResolveTypeInfo(TypeInfoDeclaration* tid) |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
249 { |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
250 if (tid->llvmResolved) return; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
251 tid->llvmResolved = true; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
252 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
253 Logger::println("* DtoResolveTypeInfo(%s)", tid->toChars()); |
52 | 254 LOG_SCOPE; |
65 | 255 |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
256 tid->llvmIRGlobal = new IRGlobal(tid); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
257 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
258 gIR->declareList.push_back(tid); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
259 } |
98
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
96
diff
changeset
|
260 |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
261 void DtoDeclareTypeInfo(TypeInfoDeclaration* tid) |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
262 { |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
263 if (tid->llvmDeclared) return; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
264 tid->llvmDeclared = true; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
265 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
266 Logger::println("* DtoDeclareTypeInfo(%s)", tid->toChars()); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
267 LOG_SCOPE; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
268 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
269 std::string mangled(tid->mangle()); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
270 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
271 Logger::println("type = '%s'", tid->tinfo->toChars()); |
98
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
96
diff
changeset
|
272 Logger::println("typeinfo mangle: %s", mangled.c_str()); |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
273 |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
274 // this is a declaration of a builtin __initZ var |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
275 if (tid->tinfo->builtinTypeInfo()) { |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
276 tid->llvmValue = LLVM_D_GetRuntimeGlobal(gIR->module, mangled.c_str()); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
277 assert(tid->llvmValue); |
98
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
96
diff
changeset
|
278 mangled.append("__TYPE"); |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
279 gIR->module->addTypeName(mangled, tid->llvmValue->getType()->getContainedType(0)); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
280 Logger::println("Got typeinfo var: %s", tid->llvmValue->getName().c_str()); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
281 tid->llvmInitialized = true; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
282 tid->llvmDefined = true; |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
283 } |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
284 // custom typedef |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
285 else { |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
286 gIR->constInitList.push_back(tid); |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
287 } |
52 | 288 } |
289 | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
290 void DtoConstInitTypeInfo(TypeInfoDeclaration* tid) |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
291 { |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
292 if (tid->llvmInitialized) return; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
293 tid->llvmInitialized = true; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
294 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
295 Logger::println("* DtoConstInitTypeInfo(%s)", tid->toChars()); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
296 LOG_SCOPE; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
297 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
298 tid->toDt(NULL); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
299 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
300 tid->llvmDefined = true; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
301 //gIR->defineList.push_back(tid); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
302 } |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
303 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
304 void DtoDefineTypeInfo(TypeInfoDeclaration* tid) |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
305 { |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
306 if (tid->llvmDefined) return; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
307 tid->llvmDefined = true; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
308 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
309 Logger::println("* DtoDefineTypeInfo(%s)", tid->toChars()); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
310 LOG_SCOPE; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
311 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
312 assert(0); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
313 } |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
314 |
52 | 315 /* ========================================================================= */ |
316 | |
317 void TypeInfoDeclaration::toDt(dt_t **pdt) | |
318 { | |
319 assert(0 && "TypeInfoDeclaration"); | |
320 } | |
321 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
322 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
323 |
52 | 324 void TypeInfoTypedefDeclaration::toDt(dt_t **pdt) |
325 { | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
326 Logger::println("TypeInfoTypedefDeclaration::toDt() %s", toChars()); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
327 LOG_SCOPE; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
328 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
329 ClassDeclaration* base = Type::typeinfotypedef; |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
330 DtoForceConstInitDsymbol(base); |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
331 |
100 | 332 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
333 Logger::cout() << "got stype: " << *stype << '\n'; |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
334 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
335 std::vector<llvm::Constant*> sinits; |
100 | 336 sinits.push_back(base->llvmVtbl); |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
337 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
338 assert(tinfo->ty == Ttypedef); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
339 TypeTypedef *tc = (TypeTypedef *)tinfo; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
340 TypedefDeclaration *sd = tc->sym; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
341 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
342 // TypeInfo base |
96 | 343 //const llvm::PointerType* basept = isaPointer(initZ->getOperand(1)->getType()); |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
344 //sinits.push_back(llvm::ConstantPointerNull::get(basept)); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
345 Logger::println("generating base typeinfo"); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
346 //sd->basetype = sd->basetype->merge(); |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
347 |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
348 sd->basetype->getTypeInfo(NULL); // generate vtinfo |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
349 assert(sd->basetype->vtinfo); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
350 if (!sd->basetype->vtinfo->llvmValue) |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
351 DtoForceConstInitDsymbol(sd->basetype->vtinfo); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
352 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
353 assert(sd->basetype->vtinfo->llvmValue); |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
354 assert(llvm::isa<llvm::Constant>(sd->basetype->vtinfo->llvmValue)); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
355 llvm::Constant* castbase = llvm::cast<llvm::Constant>(sd->basetype->vtinfo->llvmValue); |
100 | 356 castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(1)); |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
357 sinits.push_back(castbase); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
358 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
359 // char[] name |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
360 char *name = sd->toPrettyChars(); |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
73
diff
changeset
|
361 sinits.push_back(DtoConstString(name)); |
100 | 362 assert(sinits.back()->getType() == stype->getElementType(2)); |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
363 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
364 // void[] init |
69
2b5a2eaa88be
[svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents:
65
diff
changeset
|
365 const llvm::PointerType* initpt = llvm::PointerType::get(llvm::Type::Int8Ty); |
2b5a2eaa88be
[svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents:
65
diff
changeset
|
366 if (tinfo->isZeroInit() || !sd->init) // 0 initializer, or the same as the base type |
2b5a2eaa88be
[svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents:
65
diff
changeset
|
367 { |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
73
diff
changeset
|
368 sinits.push_back(DtoConstSlice(DtoConstSize_t(0), llvm::ConstantPointerNull::get(initpt))); |
69
2b5a2eaa88be
[svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents:
65
diff
changeset
|
369 } |
2b5a2eaa88be
[svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents:
65
diff
changeset
|
370 else |
2b5a2eaa88be
[svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents:
65
diff
changeset
|
371 { |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
73
diff
changeset
|
372 llvm::Constant* ci = DtoConstInitializer(sd->basetype, sd->init); |
69
2b5a2eaa88be
[svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents:
65
diff
changeset
|
373 std::string ciname(sd->mangle()); |
2b5a2eaa88be
[svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents:
65
diff
changeset
|
374 ciname.append("__init"); |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
73
diff
changeset
|
375 llvm::GlobalVariable* civar = new llvm::GlobalVariable(DtoType(sd->basetype),true,llvm::GlobalValue::InternalLinkage,ci,ciname,gIR->module); |
69
2b5a2eaa88be
[svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents:
65
diff
changeset
|
376 llvm::Constant* cicast = llvm::ConstantExpr::getBitCast(civar, initpt); |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
73
diff
changeset
|
377 size_t cisize = gTargetData->getTypeSize(DtoType(sd->basetype)); |
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
73
diff
changeset
|
378 sinits.push_back(DtoConstSlice(DtoConstSize_t(cisize), cicast)); |
69
2b5a2eaa88be
[svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents:
65
diff
changeset
|
379 } |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
380 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
381 // create the symbol |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
382 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
73 | 383 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,tiInit,toChars(),gIR->module); |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
384 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
385 llvmValue = gvar; |
52 | 386 } |
387 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
388 /* ========================================================================= */ |
52 | 389 |
390 void TypeInfoEnumDeclaration::toDt(dt_t **pdt) | |
391 { | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
392 Logger::println("TypeInfoTypedefDeclaration::toDt() %s", toChars()); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
393 LOG_SCOPE; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
394 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
395 ClassDeclaration* base = Type::typeinfoenum; |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
396 DtoForceConstInitDsymbol(base); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
397 |
100 | 398 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
399 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
400 std::vector<llvm::Constant*> sinits; |
100 | 401 sinits.push_back(base->llvmVtbl); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
402 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
403 assert(tinfo->ty == Tenum); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
404 TypeEnum *tc = (TypeEnum *)tinfo; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
405 EnumDeclaration *sd = tc->sym; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
406 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
407 // TypeInfo base |
96 | 408 //const llvm::PointerType* basept = isaPointer(initZ->getOperand(1)->getType()); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
409 //sinits.push_back(llvm::ConstantPointerNull::get(basept)); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
410 Logger::println("generating base typeinfo"); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
411 //sd->basetype = sd->basetype->merge(); |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
412 |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
413 sd->memtype->getTypeInfo(NULL); // generate vtinfo |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
414 assert(sd->memtype->vtinfo); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
415 if (!sd->memtype->vtinfo->llvmValue) |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
416 DtoForceConstInitDsymbol(sd->memtype->vtinfo); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
417 |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
418 assert(llvm::isa<llvm::Constant>(sd->memtype->vtinfo->llvmValue)); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
419 llvm::Constant* castbase = llvm::cast<llvm::Constant>(sd->memtype->vtinfo->llvmValue); |
100 | 420 castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(1)); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
421 sinits.push_back(castbase); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
422 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
423 // char[] name |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
424 char *name = sd->toPrettyChars(); |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
73
diff
changeset
|
425 sinits.push_back(DtoConstString(name)); |
100 | 426 assert(sinits.back()->getType() == stype->getElementType(2)); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
427 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
428 // void[] init |
71
53d3086b5ad3
[svn r75] Fixed the init member in custom enum typeinfo. I don't see any way this could actually need emmision though :/
lindquist
parents:
69
diff
changeset
|
429 const llvm::PointerType* initpt = llvm::PointerType::get(llvm::Type::Int8Ty); |
53d3086b5ad3
[svn r75] Fixed the init member in custom enum typeinfo. I don't see any way this could actually need emmision though :/
lindquist
parents:
69
diff
changeset
|
430 if (tinfo->isZeroInit() || !sd->defaultval) // 0 initializer, or the same as the base type |
53d3086b5ad3
[svn r75] Fixed the init member in custom enum typeinfo. I don't see any way this could actually need emmision though :/
lindquist
parents:
69
diff
changeset
|
431 { |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
73
diff
changeset
|
432 sinits.push_back(DtoConstSlice(DtoConstSize_t(0), llvm::ConstantPointerNull::get(initpt))); |
71
53d3086b5ad3
[svn r75] Fixed the init member in custom enum typeinfo. I don't see any way this could actually need emmision though :/
lindquist
parents:
69
diff
changeset
|
433 } |
53d3086b5ad3
[svn r75] Fixed the init member in custom enum typeinfo. I don't see any way this could actually need emmision though :/
lindquist
parents:
69
diff
changeset
|
434 else |
53d3086b5ad3
[svn r75] Fixed the init member in custom enum typeinfo. I don't see any way this could actually need emmision though :/
lindquist
parents:
69
diff
changeset
|
435 { |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
73
diff
changeset
|
436 const llvm::Type* memty = DtoType(sd->memtype); |
71
53d3086b5ad3
[svn r75] Fixed the init member in custom enum typeinfo. I don't see any way this could actually need emmision though :/
lindquist
parents:
69
diff
changeset
|
437 llvm::Constant* ci = llvm::ConstantInt::get(memty, sd->defaultval, !sd->memtype->isunsigned()); |
53d3086b5ad3
[svn r75] Fixed the init member in custom enum typeinfo. I don't see any way this could actually need emmision though :/
lindquist
parents:
69
diff
changeset
|
438 std::string ciname(sd->mangle()); |
53d3086b5ad3
[svn r75] Fixed the init member in custom enum typeinfo. I don't see any way this could actually need emmision though :/
lindquist
parents:
69
diff
changeset
|
439 ciname.append("__init"); |
53d3086b5ad3
[svn r75] Fixed the init member in custom enum typeinfo. I don't see any way this could actually need emmision though :/
lindquist
parents:
69
diff
changeset
|
440 llvm::GlobalVariable* civar = new llvm::GlobalVariable(memty,true,llvm::GlobalValue::InternalLinkage,ci,ciname,gIR->module); |
53d3086b5ad3
[svn r75] Fixed the init member in custom enum typeinfo. I don't see any way this could actually need emmision though :/
lindquist
parents:
69
diff
changeset
|
441 llvm::Constant* cicast = llvm::ConstantExpr::getBitCast(civar, initpt); |
53d3086b5ad3
[svn r75] Fixed the init member in custom enum typeinfo. I don't see any way this could actually need emmision though :/
lindquist
parents:
69
diff
changeset
|
442 size_t cisize = gTargetData->getTypeSize(memty); |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
73
diff
changeset
|
443 sinits.push_back(DtoConstSlice(DtoConstSize_t(cisize), cicast)); |
71
53d3086b5ad3
[svn r75] Fixed the init member in custom enum typeinfo. I don't see any way this could actually need emmision though :/
lindquist
parents:
69
diff
changeset
|
444 } |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
445 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
446 // create the symbol |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
447 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
73 | 448 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,tiInit,toChars(),gIR->module); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
449 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
450 llvmValue = gvar; |
52 | 451 } |
452 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
453 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
454 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
455 static llvm::Constant* LLVM_D_Create_TypeInfoBase(Type* basetype, TypeInfoDeclaration* tid, ClassDeclaration* cd) |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
456 { |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
457 ClassDeclaration* base = cd; |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
458 DtoForceConstInitDsymbol(base); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
459 |
100 | 460 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
461 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
462 std::vector<llvm::Constant*> sinits; |
100 | 463 sinits.push_back(base->llvmVtbl); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
464 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
465 // TypeInfo base |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
466 Logger::println("generating base typeinfo"); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
467 basetype->getTypeInfo(NULL); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
468 assert(basetype->vtinfo); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
469 if (!basetype->vtinfo->llvmValue) |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
470 DtoForceConstInitDsymbol(basetype->vtinfo); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
471 assert(llvm::isa<llvm::Constant>(basetype->vtinfo->llvmValue)); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
472 llvm::Constant* castbase = llvm::cast<llvm::Constant>(basetype->vtinfo->llvmValue); |
100 | 473 castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(1)); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
474 sinits.push_back(castbase); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
475 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
476 // create the symbol |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
477 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
73 | 478 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,tiInit,tid->toChars(),gIR->module); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
479 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
480 tid->llvmValue = gvar; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
481 } |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
482 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
483 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
484 |
52 | 485 void TypeInfoPointerDeclaration::toDt(dt_t **pdt) |
486 { | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
487 Logger::println("TypeInfoPointerDeclaration::toDt() %s", toChars()); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
488 LOG_SCOPE; |
52 | 489 |
490 assert(tinfo->ty == Tpointer); | |
491 TypePointer *tc = (TypePointer *)tinfo; | |
492 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
493 LLVM_D_Create_TypeInfoBase(tc->next, this, Type::typeinfopointer); |
52 | 494 } |
495 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
496 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
497 |
52 | 498 void TypeInfoArrayDeclaration::toDt(dt_t **pdt) |
499 { | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
500 Logger::println("TypeInfoArrayDeclaration::toDt() %s", toChars()); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
501 LOG_SCOPE; |
52 | 502 |
503 assert(tinfo->ty == Tarray); | |
504 TypeDArray *tc = (TypeDArray *)tinfo; | |
505 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
506 LLVM_D_Create_TypeInfoBase(tc->next, this, Type::typeinfoarray); |
52 | 507 } |
508 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
509 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
510 |
52 | 511 void TypeInfoStaticArrayDeclaration::toDt(dt_t **pdt) |
512 { | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
513 assert(0 && "TypeInfoStaticArrayDeclaration"); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
514 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
515 /* |
52 | 516 //printf("TypeInfoStaticArrayDeclaration::toDt()\n"); |
517 dtxoff(pdt, Type::typeinfostaticarray->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_StaticArray | |
518 dtdword(pdt, 0); // monitor | |
519 | |
520 assert(tinfo->ty == Tsarray); | |
521 | |
522 TypeSArray *tc = (TypeSArray *)tinfo; | |
523 | |
524 tc->next->getTypeInfo(NULL); | |
525 dtxoff(pdt, tc->next->vtinfo->toSymbol(), 0, TYnptr); // TypeInfo for array of type | |
526 | |
527 dtdword(pdt, tc->dim->toInteger()); // length | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
528 */ |
52 | 529 } |
530 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
531 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
532 |
52 | 533 void TypeInfoAssociativeArrayDeclaration::toDt(dt_t **pdt) |
534 { | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
535 assert(0 && "TypeInfoAssociativeArrayDeclaration"); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
536 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
537 /* |
52 | 538 //printf("TypeInfoAssociativeArrayDeclaration::toDt()\n"); |
539 dtxoff(pdt, Type::typeinfoassociativearray->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_AssociativeArray | |
540 dtdword(pdt, 0); // monitor | |
541 | |
542 assert(tinfo->ty == Taarray); | |
543 | |
544 TypeAArray *tc = (TypeAArray *)tinfo; | |
545 | |
546 tc->next->getTypeInfo(NULL); | |
547 dtxoff(pdt, tc->next->vtinfo->toSymbol(), 0, TYnptr); // TypeInfo for array of type | |
548 | |
549 tc->index->getTypeInfo(NULL); | |
550 dtxoff(pdt, tc->index->vtinfo->toSymbol(), 0, TYnptr); // TypeInfo for array of type | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
551 */ |
52 | 552 } |
553 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
554 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
555 |
52 | 556 void TypeInfoFunctionDeclaration::toDt(dt_t **pdt) |
557 { | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
558 Logger::println("TypeInfoFunctionDeclaration::toDt() %s", toChars()); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
559 LOG_SCOPE; |
52 | 560 |
561 assert(tinfo->ty == Tfunction); | |
562 TypeFunction *tc = (TypeFunction *)tinfo; | |
563 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
564 LLVM_D_Create_TypeInfoBase(tc->next, this, Type::typeinfofunction); |
52 | 565 } |
566 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
567 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
568 |
52 | 569 void TypeInfoDelegateDeclaration::toDt(dt_t **pdt) |
570 { | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
571 Logger::println("TypeInfoDelegateDeclaration::toDt() %s", toChars()); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
572 LOG_SCOPE; |
52 | 573 |
574 assert(tinfo->ty == Tdelegate); | |
575 TypeDelegate *tc = (TypeDelegate *)tinfo; | |
576 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
577 LLVM_D_Create_TypeInfoBase(tc->next->next, this, Type::typeinfodelegate); |
52 | 578 } |
579 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
580 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
581 |
52 | 582 void TypeInfoStructDeclaration::toDt(dt_t **pdt) |
583 { | |
72 | 584 Logger::println("TypeInfoStructDeclaration::toDt() %s", toChars()); |
585 LOG_SCOPE; | |
586 | |
587 assert(tinfo->ty == Tstruct); | |
588 TypeStruct *tc = (TypeStruct *)tinfo; | |
589 StructDeclaration *sd = tc->sym; | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
590 DtoForceConstInitDsymbol(sd); |
72 | 591 |
592 ClassDeclaration* base = Type::typeinfostruct; | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
593 DtoForceConstInitDsymbol(base); |
72 | 594 |
100 | 595 const llvm::StructType* stype = isaStruct(((TypeClass*)base->type)->llvmType->get()); |
72 | 596 |
597 std::vector<llvm::Constant*> sinits; | |
598 sinits.push_back(base->llvmVtbl); | |
599 | |
600 // char[] name | |
601 char *name = sd->toPrettyChars(); | |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
73
diff
changeset
|
602 sinits.push_back(DtoConstString(name)); |
73 | 603 Logger::println("************** A"); |
72 | 604 assert(sinits.back()->getType() == stype->getElementType(1)); |
605 | |
606 // void[] init | |
607 const llvm::PointerType* initpt = llvm::PointerType::get(llvm::Type::Int8Ty); | |
608 if (sd->zeroInit) // 0 initializer, or the same as the base type | |
609 { | |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
73
diff
changeset
|
610 sinits.push_back(DtoConstSlice(DtoConstSize_t(0), llvm::ConstantPointerNull::get(initpt))); |
72 | 611 } |
612 else | |
613 { | |
614 assert(sd->llvmInitZ); | |
100 | 615 size_t cisize = gTargetData->getTypeSize(tc->llvmType->get()); |
72 | 616 llvm::Constant* cicast = llvm::ConstantExpr::getBitCast(tc->llvmInit, initpt); |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
73
diff
changeset
|
617 sinits.push_back(DtoConstSlice(DtoConstSize_t(cisize), cicast)); |
72 | 618 } |
619 | |
620 // toX functions ground work | |
621 FuncDeclaration *fd; | |
622 FuncDeclaration *fdx; | |
623 TypeFunction *tf; | |
624 Type *ta; | |
625 Dsymbol *s; | |
626 | |
627 static TypeFunction *tftohash; | |
628 static TypeFunction *tftostring; | |
629 | |
630 if (!tftohash) | |
631 { | |
632 Scope sc; | |
633 | |
634 tftohash = new TypeFunction(NULL, Type::thash_t, 0, LINKd); | |
635 tftohash = (TypeFunction *)tftohash->semantic(0, &sc); | |
636 | |
637 tftostring = new TypeFunction(NULL, Type::tchar->arrayOf(), 0, LINKd); | |
638 tftostring = (TypeFunction *)tftostring->semantic(0, &sc); | |
639 } | |
640 | |
641 TypeFunction *tfeqptr; | |
642 { | |
643 Scope sc; | |
644 Arguments *arguments = new Arguments; | |
645 Argument *arg = new Argument(STCin, tc->pointerTo(), NULL, NULL); | |
646 | |
647 arguments->push(arg); | |
648 tfeqptr = new TypeFunction(arguments, Type::tint32, 0, LINKd); | |
649 tfeqptr = (TypeFunction *)tfeqptr->semantic(0, &sc); | |
650 } | |
651 | |
652 #if 0 | |
653 TypeFunction *tfeq; | |
654 { | |
655 Scope sc; | |
656 Array *arguments = new Array; | |
657 Argument *arg = new Argument(In, tc, NULL, NULL); | |
658 | |
659 arguments->push(arg); | |
660 tfeq = new TypeFunction(arguments, Type::tint32, 0, LINKd); | |
661 tfeq = (TypeFunction *)tfeq->semantic(0, &sc); | |
662 } | |
663 #endif | |
664 | |
73 | 665 Logger::println("************** B"); |
96 | 666 const llvm::PointerType* ptty = isaPointer(stype->getElementType(3)); |
72 | 667 |
668 s = search_function(sd, Id::tohash); | |
669 fdx = s ? s->isFuncDeclaration() : NULL; | |
670 if (fdx) | |
671 { | |
672 fd = fdx->overloadExactMatch(tftohash); | |
673 if (fd) { | |
674 assert(fd->llvmValue != 0); | |
675 llvm::Constant* c = llvm::cast_or_null<llvm::Constant>(fd->llvmValue); | |
676 assert(c); | |
677 c = llvm::ConstantExpr::getBitCast(c, ptty); | |
678 sinits.push_back(c); | |
679 } | |
680 else { | |
681 //fdx->error("must be declared as extern (D) uint toHash()"); | |
682 sinits.push_back(llvm::ConstantPointerNull::get(ptty)); | |
683 } | |
684 } | |
685 else { | |
686 sinits.push_back(llvm::ConstantPointerNull::get(ptty)); | |
687 } | |
688 | |
689 s = search_function(sd, Id::eq); | |
690 fdx = s ? s->isFuncDeclaration() : NULL; | |
691 for (int i = 0; i < 2; i++) | |
692 { | |
73 | 693 Logger::println("************** C %d", i); |
96 | 694 ptty = isaPointer(stype->getElementType(4+i)); |
72 | 695 if (fdx) |
696 { | |
697 fd = fdx->overloadExactMatch(tfeqptr); | |
698 if (fd) { | |
699 assert(fd->llvmValue != 0); | |
700 llvm::Constant* c = llvm::cast_or_null<llvm::Constant>(fd->llvmValue); | |
701 assert(c); | |
702 c = llvm::ConstantExpr::getBitCast(c, ptty); | |
703 sinits.push_back(c); | |
704 } | |
705 else { | |
706 //fdx->error("must be declared as extern (D) int %s(%s*)", fdx->toChars(), sd->toChars()); | |
707 sinits.push_back(llvm::ConstantPointerNull::get(ptty)); | |
708 } | |
709 } | |
710 else { | |
711 sinits.push_back(llvm::ConstantPointerNull::get(ptty)); | |
712 } | |
713 | |
714 s = search_function(sd, Id::cmp); | |
715 fdx = s ? s->isFuncDeclaration() : NULL; | |
716 } | |
717 | |
73 | 718 Logger::println("************** D"); |
96 | 719 ptty = isaPointer(stype->getElementType(6)); |
72 | 720 s = search_function(sd, Id::tostring); |
721 fdx = s ? s->isFuncDeclaration() : NULL; | |
722 if (fdx) | |
723 { | |
724 fd = fdx->overloadExactMatch(tftostring); | |
725 if (fd) { | |
726 assert(fd->llvmValue != 0); | |
727 llvm::Constant* c = llvm::cast_or_null<llvm::Constant>(fd->llvmValue); | |
728 assert(c); | |
729 c = llvm::ConstantExpr::getBitCast(c, ptty); | |
730 sinits.push_back(c); | |
731 } | |
732 else { | |
733 //fdx->error("must be declared as extern (D) char[] toString()"); | |
734 sinits.push_back(llvm::ConstantPointerNull::get(ptty)); | |
735 } | |
736 } | |
737 else { | |
738 sinits.push_back(llvm::ConstantPointerNull::get(ptty)); | |
739 } | |
740 | |
741 // uint m_flags; | |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
73
diff
changeset
|
742 sinits.push_back(DtoConstUint(tc->hasPointers())); |
72 | 743 |
744 // create the symbol | |
745 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); | |
73 | 746 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,tiInit,toChars(),gIR->module); |
72 | 747 |
748 llvmValue = gvar; | |
52 | 749 } |
750 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
751 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
752 |
52 | 753 void TypeInfoClassDeclaration::toDt(dt_t **pdt) |
754 { | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
755 assert(0 && "TypeInfoClassDeclaration"); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
756 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
757 /* |
52 | 758 //printf("TypeInfoClassDeclaration::toDt() %s\n", tinfo->toChars()); |
759 dtxoff(pdt, Type::typeinfoclass->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfoClass | |
760 dtdword(pdt, 0); // monitor | |
761 | |
762 assert(tinfo->ty == Tclass); | |
763 | |
764 TypeClass *tc = (TypeClass *)tinfo; | |
765 Symbol *s; | |
766 | |
767 if (!tc->sym->vclassinfo) | |
768 tc->sym->vclassinfo = new ClassInfoDeclaration(tc->sym); | |
769 s = tc->sym->vclassinfo->toSymbol(); | |
770 dtxoff(pdt, s, 0, TYnptr); // ClassInfo for tinfo | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
771 */ |
52 | 772 } |
773 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
774 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
775 |
52 | 776 void TypeInfoInterfaceDeclaration::toDt(dt_t **pdt) |
777 { | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
778 assert(0 && "TypeInfoInterfaceDeclaration"); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
779 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
780 /* |
52 | 781 //printf("TypeInfoInterfaceDeclaration::toDt() %s\n", tinfo->toChars()); |
782 dtxoff(pdt, Type::typeinfointerface->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfoInterface | |
783 dtdword(pdt, 0); // monitor | |
784 | |
785 assert(tinfo->ty == Tclass); | |
786 | |
787 TypeClass *tc = (TypeClass *)tinfo; | |
788 Symbol *s; | |
789 | |
790 if (!tc->sym->vclassinfo) | |
791 tc->sym->vclassinfo = new ClassInfoDeclaration(tc->sym); | |
792 s = tc->sym->vclassinfo->toSymbol(); | |
793 dtxoff(pdt, s, 0, TYnptr); // ClassInfo for tinfo | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
794 */ |
52 | 795 } |
796 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
797 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
798 |
52 | 799 void TypeInfoTupleDeclaration::toDt(dt_t **pdt) |
800 { | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
801 assert(0 && "TypeInfoTupleDeclaration"); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
802 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
803 /* |
52 | 804 //printf("TypeInfoTupleDeclaration::toDt() %s\n", tinfo->toChars()); |
805 dtxoff(pdt, Type::typeinfotypelist->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfoInterface | |
806 dtdword(pdt, 0); // monitor | |
807 | |
808 assert(tinfo->ty == Ttuple); | |
809 | |
810 TypeTuple *tu = (TypeTuple *)tinfo; | |
811 | |
812 size_t dim = tu->arguments->dim; | |
813 dtdword(pdt, dim); // elements.length | |
814 | |
815 dt_t *d = NULL; | |
816 for (size_t i = 0; i < dim; i++) | |
817 { Argument *arg = (Argument *)tu->arguments->data[i]; | |
818 Expression *e = arg->type->getTypeInfo(NULL); | |
819 e = e->optimize(WANTvalue); | |
820 e->toDt(&d); | |
821 } | |
822 | |
823 Symbol *s; | |
824 s = static_sym(); | |
825 s->Sdt = d; | |
826 outdata(s); | |
827 | |
828 dtxoff(pdt, s, 0, TYnptr); // elements.ptr | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
829 */ |
52 | 830 } |