Mercurial > projects > ldc
comparison gen/classes.cpp @ 835:3afe9f276db7
Added back a bunch of static's to gen/classes.cpp, it's not superfluous, it makes the functions internal to the compilation unit, and we don't call them anywhere else.
author | Tomas Lindquist Olsen <tomas.l.olsen@gmail.com> |
---|---|
date | Tue, 09 Dec 2008 02:07:24 +0100 |
parents | 482cd74d1c71 |
children | 331a176c1f4f |
comparison
equal
deleted
inserted
replaced
834:f466f475b654 | 835:3afe9f276db7 |
---|---|
20 #include "ir/irstruct.h" | 20 #include "ir/irstruct.h" |
21 | 21 |
22 ////////////////////////////////////////////////////////////////////////////////////////// | 22 ////////////////////////////////////////////////////////////////////////////////////////// |
23 | 23 |
24 // adds the base interfaces of b and the given iri to IrStruct's interfaceMap | 24 // adds the base interfaces of b and the given iri to IrStruct's interfaceMap |
25 void add_base_interfaces(IrStruct* to, IrInterface* iri, BaseClass* b) | 25 static void add_base_interfaces(IrStruct* to, IrInterface* iri, BaseClass* b) |
26 { | 26 { |
27 for (unsigned j = 0; j < b->baseInterfaces_dim; j++) | 27 for (unsigned j = 0; j < b->baseInterfaces_dim; j++) |
28 { | 28 { |
29 BaseClass *bc = &b->baseInterfaces[j]; | 29 BaseClass *bc = &b->baseInterfaces[j]; |
30 // add to map | 30 // add to map |
37 } | 37 } |
38 } | 38 } |
39 | 39 |
40 // adds interface b to target, if newinstance != 0, then target must provide all | 40 // adds interface b to target, if newinstance != 0, then target must provide all |
41 // functions required to implement b (it reimplements b) | 41 // functions required to implement b (it reimplements b) |
42 void add_interface(ClassDeclaration* target, BaseClass* b, int newinstance) | 42 static void add_interface(ClassDeclaration* target, BaseClass* b, int newinstance) |
43 { | 43 { |
44 Logger::println("adding interface: %s", b->base->toChars()); | 44 Logger::println("adding interface: %s", b->base->toChars()); |
45 LOG_SCOPE; | 45 LOG_SCOPE; |
46 | 46 |
47 InterfaceDeclaration* inter = b->base->isInterfaceDeclaration(); | 47 InterfaceDeclaration* inter = b->base->isInterfaceDeclaration(); |
88 iri->index = irstruct->index++; | 88 iri->index = irstruct->index++; |
89 } | 89 } |
90 | 90 |
91 ////////////////////////////////////////////////////////////////////////////////////////// | 91 ////////////////////////////////////////////////////////////////////////////////////////// |
92 | 92 |
93 void add_class_data(ClassDeclaration* target, ClassDeclaration* cd) | 93 static void add_class_data(ClassDeclaration* target, ClassDeclaration* cd) |
94 { | 94 { |
95 Logger::println("Adding data from class: %s", cd->toChars()); | 95 Logger::println("Adding data from class: %s", cd->toChars()); |
96 LOG_SCOPE; | 96 LOG_SCOPE; |
97 | 97 |
98 // recurse into baseClasses | 98 // recurse into baseClasses |
123 } | 123 } |
124 } | 124 } |
125 | 125 |
126 ////////////////////////////////////////////////////////////////////////////////////////// | 126 ////////////////////////////////////////////////////////////////////////////////////////// |
127 | 127 |
128 void DtoResolveInterface(InterfaceDeclaration* cd) | 128 static void DtoResolveInterface(InterfaceDeclaration* cd) |
129 { | 129 { |
130 if (cd->ir.resolved) return; | 130 if (cd->ir.resolved) return; |
131 cd->ir.resolved = true; | 131 cd->ir.resolved = true; |
132 | 132 |
133 Logger::println("DtoResolveInterface(%s): %s", cd->toPrettyChars(), cd->loc.toChars()); | 133 Logger::println("DtoResolveInterface(%s): %s", cd->toPrettyChars(), cd->loc.toChars()); |
273 gIR->declareList.push_back(cd); | 273 gIR->declareList.push_back(cd); |
274 } | 274 } |
275 | 275 |
276 ////////////////////////////////////////////////////////////////////////////////////////// | 276 ////////////////////////////////////////////////////////////////////////////////////////// |
277 | 277 |
278 void DtoDeclareInterface(InterfaceDeclaration* cd) | 278 static void DtoDeclareInterface(InterfaceDeclaration* cd) |
279 { | 279 { |
280 if (cd->ir.declared) return; | 280 if (cd->ir.declared) return; |
281 cd->ir.declared = true; | 281 cd->ir.declared = true; |
282 | 282 |
283 Logger::println("DtoDeclareInterface(%s): %s", cd->toPrettyChars(), cd->locToChars()); | 283 Logger::println("DtoDeclareInterface(%s): %s", cd->toPrettyChars(), cd->locToChars()); |
438 } | 438 } |
439 | 439 |
440 ////////////////////////////////////////////////////////////////////////////// | 440 ////////////////////////////////////////////////////////////////////////////// |
441 | 441 |
442 // adds data fields and interface vtables to the constant initializer of class cd | 442 // adds data fields and interface vtables to the constant initializer of class cd |
443 size_t init_class_initializer(std::vector<LLConstant*>& inits, ClassDeclaration* target, ClassDeclaration* cd, size_t offsetbegin) | 443 static size_t init_class_initializer(std::vector<LLConstant*>& inits, ClassDeclaration* target, ClassDeclaration* cd, size_t offsetbegin) |
444 { | 444 { |
445 // first do baseclasses | 445 // first do baseclasses |
446 if (cd->baseClass) | 446 if (cd->baseClass) |
447 { | 447 { |
448 offsetbegin = init_class_initializer(inits, target, cd->baseClass, offsetbegin); | 448 offsetbegin = init_class_initializer(inits, target, cd->baseClass, offsetbegin); |
541 } | 541 } |
542 | 542 |
543 ////////////////////////////////////////////////////////////////////////////// | 543 ////////////////////////////////////////////////////////////////////////////// |
544 | 544 |
545 // build the vtable initializer for class cd | 545 // build the vtable initializer for class cd |
546 void init_class_vtbl_initializer(ClassDeclaration* cd) | 546 static void init_class_vtbl_initializer(ClassDeclaration* cd) |
547 { | 547 { |
548 // generate vtable initializer | 548 // generate vtable initializer |
549 std::vector<LLConstant*> sinits(cd->vtbl.dim, NULL); | 549 std::vector<LLConstant*> sinits(cd->vtbl.dim, NULL); |
550 | 550 |
551 IrStruct* irstruct = cd->ir.irStruct; | 551 IrStruct* irstruct = cd->ir.irStruct; |
594 // Logger::cout() << "vtbl initializer: " << *irstruct->constVtbl << std::endl; | 594 // Logger::cout() << "vtbl initializer: " << *irstruct->constVtbl << std::endl; |
595 } | 595 } |
596 | 596 |
597 ////////////////////////////////////////////////////////////////////////////// | 597 ////////////////////////////////////////////////////////////////////////////// |
598 | 598 |
599 void init_class_interface_vtbl_initializers(ClassDeclaration* cd) | 599 static void init_class_interface_vtbl_initializers(ClassDeclaration* cd) |
600 { | 600 { |
601 IrStruct* irstruct = cd->ir.irStruct; | 601 IrStruct* irstruct = cd->ir.irStruct; |
602 | 602 |
603 // don't do anything if list is empty | 603 // don't do anything if list is empty |
604 if (irstruct->interfaceVec.empty()) | 604 if (irstruct->interfaceVec.empty()) |
695 } | 695 } |
696 } | 696 } |
697 | 697 |
698 ////////////////////////////////////////////////////////////////////////////// | 698 ////////////////////////////////////////////////////////////////////////////// |
699 | 699 |
700 void DtoConstInitInterface(InterfaceDeclaration* cd) | 700 static void DtoConstInitInterface(InterfaceDeclaration* cd) |
701 { | 701 { |
702 if (cd->ir.initialized) return; | 702 if (cd->ir.initialized) return; |
703 cd->ir.initialized = true; | 703 cd->ir.initialized = true; |
704 | 704 |
705 Logger::println("DtoConstInitClass(%s): %s", cd->toPrettyChars(), cd->loc.toChars()); | 705 Logger::println("DtoConstInitClass(%s): %s", cd->toPrettyChars(), cd->loc.toChars()); |
778 gIR->structs.pop_back(); | 778 gIR->structs.pop_back(); |
779 } | 779 } |
780 | 780 |
781 ////////////////////////////////////////////////////////////////////////////////////////// | 781 ////////////////////////////////////////////////////////////////////////////////////////// |
782 | 782 |
783 void DefineInterfaceInfos(IrStruct* irstruct) | 783 static void DefineInterfaceInfos(IrStruct* irstruct) |
784 { | 784 { |
785 // always do interface info array when possible | 785 // always do interface info array when possible |
786 std::vector<LLConstant*> infoInits; | 786 std::vector<LLConstant*> infoInits; |
787 | 787 |
788 size_t n = irstruct->interfaceVec.size(); | 788 size_t n = irstruct->interfaceVec.size(); |
808 } | 808 } |
809 } | 809 } |
810 | 810 |
811 ////////////////////////////////////////////////////////////////////////////////////////// | 811 ////////////////////////////////////////////////////////////////////////////////////////// |
812 | 812 |
813 void DtoDefineInterface(InterfaceDeclaration* cd) | 813 static void DtoDefineInterface(InterfaceDeclaration* cd) |
814 { | 814 { |
815 if (cd->ir.defined) return; | 815 if (cd->ir.defined) return; |
816 cd->ir.defined = true; | 816 cd->ir.defined = true; |
817 | 817 |
818 Logger::println("DtoDefineClass(%s): %s", cd->toPrettyChars(), cd->loc.toChars()); | 818 Logger::println("DtoDefineClass(%s): %s", cd->toPrettyChars(), cd->loc.toChars()); |
1321 ////////////////////////////////////////////////////////////////////////////////////////// | 1321 ////////////////////////////////////////////////////////////////////////////////////////// |
1322 | 1322 |
1323 #if GENERATE_OFFTI | 1323 #if GENERATE_OFFTI |
1324 | 1324 |
1325 // build a single element for the OffsetInfo[] of ClassInfo | 1325 // build a single element for the OffsetInfo[] of ClassInfo |
1326 LLConstant* build_offti_entry(ClassDeclaration* cd, VarDeclaration* vd) | 1326 static LLConstant* build_offti_entry(ClassDeclaration* cd, VarDeclaration* vd) |
1327 { | 1327 { |
1328 std::vector<LLConstant*> inits(2); | 1328 std::vector<LLConstant*> inits(2); |
1329 | 1329 |
1330 // size_t offset; | 1330 // size_t offset; |
1331 // | 1331 // |
1346 | 1346 |
1347 // done | 1347 // done |
1348 return llvm::ConstantStruct::get(inits); | 1348 return llvm::ConstantStruct::get(inits); |
1349 } | 1349 } |
1350 | 1350 |
1351 LLConstant* build_offti_array(ClassDeclaration* cd, const LLType* arrayT) | 1351 static LLConstant* build_offti_array(ClassDeclaration* cd, const LLType* arrayT) |
1352 { | 1352 { |
1353 IrStruct* irstruct = cd->ir.irStruct; | 1353 IrStruct* irstruct = cd->ir.irStruct; |
1354 | 1354 |
1355 size_t nvars = irstruct->varDecls.size(); | 1355 size_t nvars = irstruct->varDecls.size(); |
1356 std::vector<LLConstant*> arrayInits(nvars); | 1356 std::vector<LLConstant*> arrayInits(nvars); |
1381 return DtoConstSlice(size, ptr); | 1381 return DtoConstSlice(size, ptr); |
1382 } | 1382 } |
1383 | 1383 |
1384 #endif // GENERATE_OFFTI | 1384 #endif // GENERATE_OFFTI |
1385 | 1385 |
1386 LLConstant* build_class_dtor(ClassDeclaration* cd) | 1386 static LLConstant* build_class_dtor(ClassDeclaration* cd) |
1387 { | 1387 { |
1388 FuncDeclaration* dtor = cd->dtor; | 1388 FuncDeclaration* dtor = cd->dtor; |
1389 | 1389 |
1390 // if no destructor emit a null | 1390 // if no destructor emit a null |
1391 if (!dtor) | 1391 if (!dtor) |
1393 | 1393 |
1394 DtoForceDeclareDsymbol(dtor); | 1394 DtoForceDeclareDsymbol(dtor); |
1395 return llvm::ConstantExpr::getBitCast(dtor->ir.irFunc->func, getPtrToType(LLType::Int8Ty)); | 1395 return llvm::ConstantExpr::getBitCast(dtor->ir.irFunc->func, getPtrToType(LLType::Int8Ty)); |
1396 } | 1396 } |
1397 | 1397 |
1398 unsigned build_classinfo_flags(ClassDeclaration* cd) | 1398 static unsigned build_classinfo_flags(ClassDeclaration* cd) |
1399 { | 1399 { |
1400 // adapted from original dmd code | 1400 // adapted from original dmd code |
1401 unsigned flags = 0; | 1401 unsigned flags = 0; |
1402 //flags |= isCOMclass(); // IUnknown | 1402 //flags |= isCOMclass(); // IUnknown |
1403 bool hasOffTi = false; | 1403 bool hasOffTi = false; |