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