Mercurial > projects > ldc
comparison gen/classes.cpp @ 800:d14e4594c7d7
Changed aggregate field initializers to be created lazily, fixes problem with static void arrays in aggregates.
author | Tomas Lindquist Olsen <tomas.l.olsen@gmail.com> |
---|---|
date | Sat, 29 Nov 2008 18:28:17 +0100 |
parents | 340acf1535d0 |
children | c8d9b30a0dc2 |
comparison
equal
deleted
inserted
replaced
797:340acf1535d0 | 800:d14e4594c7d7 |
---|---|
422 } | 422 } |
423 | 423 |
424 ////////////////////////////////////////////////////////////////////////////////////////// | 424 ////////////////////////////////////////////////////////////////////////////////////////// |
425 | 425 |
426 void addZeros(std::vector<llvm::Constant*>& inits, size_t pos, size_t offset); // irstruct.cpp | 426 void addZeros(std::vector<llvm::Constant*>& inits, size_t pos, size_t offset); // irstruct.cpp |
427 | |
428 ////////////////////////////////////////////////////////////////////////////// | |
429 | |
430 // assigns constant initializers to fields introduced by cd | |
431 static void init_field_inits(ClassDeclaration* cd) | |
432 { | |
433 size_t n = cd->fields.dim; | |
434 for (size_t i=0; i<n; i++) | |
435 { | |
436 VarDeclaration* v = (VarDeclaration*)cd->fields.data[i]; | |
437 IrField* f = v->ir.irField; | |
438 assert(!f->constInit); | |
439 f->constInit = DtoConstFieldInitializer(v->loc, v->type, v->init); | |
440 } | |
441 } | |
442 | 427 |
443 ////////////////////////////////////////////////////////////////////////////// | 428 ////////////////////////////////////////////////////////////////////////////// |
444 | 429 |
445 // adds data fields and interface vtables to the constant initializer of class cd | 430 // adds data fields and interface vtables to the constant initializer of class cd |
446 static size_t init_class_initializer(std::vector<LLConstant*>& inits, ClassDeclaration* target, ClassDeclaration* cd, size_t offsetbegin) | 431 static size_t init_class_initializer(std::vector<LLConstant*>& inits, ClassDeclaration* target, ClassDeclaration* cd, size_t offsetbegin) |
500 size_t pos = lastoffset + lastsize; | 485 size_t pos = lastoffset + lastsize; |
501 addZeros(inits, pos, offset); | 486 addZeros(inits, pos, offset); |
502 } | 487 } |
503 | 488 |
504 // add the field | 489 // add the field |
505 assert(var->ir.irField->constInit); | 490 // and build its constant initializer lazily |
491 if (!var->ir.irField->constInit) | |
492 var->ir.irField->constInit = DtoConstFieldInitializer(var->loc, var->type, var->init); | |
506 inits.push_back(var->ir.irField->constInit); | 493 inits.push_back(var->ir.irField->constInit); |
507 | 494 |
508 lastoffset = offset; | 495 lastoffset = offset; |
509 lastsize = var->type->size(); | 496 lastsize = var->type->size(); |
510 } | 497 } |
728 TypeClass* tc = (TypeClass*)cd->type; | 715 TypeClass* tc = (TypeClass*)cd->type; |
729 const llvm::StructType* structtype = isaStruct(tc->ir.type->get()); | 716 const llvm::StructType* structtype = isaStruct(tc->ir.type->get()); |
730 assert(structtype); | 717 assert(structtype); |
731 const llvm::ArrayType* vtbltype = isaArray(irstruct->vtblTy.get()); | 718 const llvm::ArrayType* vtbltype = isaArray(irstruct->vtblTy.get()); |
732 assert(vtbltype); | 719 assert(vtbltype); |
733 | |
734 // make sure each field knows its default initializer | |
735 init_field_inits(cd); | |
736 | 720 |
737 // build initializer list | 721 // build initializer list |
738 std::vector<LLConstant*> inits; | 722 std::vector<LLConstant*> inits; |
739 inits.reserve(irstruct->varDecls.size()); | 723 inits.reserve(irstruct->varDecls.size()); |
740 | 724 |