From 93a632c7c2f9082b268a44039b1dbf69e48c96b7 Mon Sep 17 00:00:00 2001 From: Tomas Lindquist Olsen Date: Tue, 6 May 2008 03:07:21 +0200 Subject: [PATCH] [svn r185] Fixed broken nested classes with data members, did DMD change the class layout? tango.text.Regex now compiles. Commented some of the *very* verbose logging for -vv option. --- gen/classes.cpp | 18 +++++++++--------- gen/structs.cpp | 2 +- gen/toir.cpp | 9 ++++++--- llvmdc.kdevelop.filelist | 1 + tangotests/classes1.d | 37 +++++++++++++++++++++++++++++++++++++ 5 files changed, 54 insertions(+), 13 deletions(-) create mode 100644 tangotests/classes1.d diff --git a/gen/classes.cpp b/gen/classes.cpp index e43e62f1..b612a359 100644 --- a/gen/classes.cpp +++ b/gen/classes.cpp @@ -769,12 +769,11 @@ DValue* DtoNewClass(TypeClass* tc, NewExp* newexp) Logger::println("Resolving outer class"); LOG_SCOPE; DValue* thisval = newexp->thisexp->toElem(gIR); - size_t idx = 2; - //idx += gIR->irDsymbol[tc->sym].irStruct->interfaces.size(); - llvm::Value* dst = thisval->getRVal(); - llvm::Value* src = DtoGEPi(mem,0,idx,"tmp"); + size_t idx = 2 + gIR->irDsymbol[tc->sym->vthis].irField->index; + llvm::Value* src = thisval->getRVal(); + llvm::Value* dst = DtoGEPi(mem,0,idx,"tmp"); Logger::cout() << "dst: " << *dst << "\nsrc: " << *src << '\n'; - DtoStore(dst, src); + DtoStore(src, dst); } // set the context for nested classes else if (tc->sym->isNested()) @@ -1110,18 +1109,19 @@ llvm::Value* DtoIndexClass(llvm::Value* ptr, ClassDeclaration* cd, Type* t, unsi VarDeclaration* vd = i->second.var; assert(vd); Type* vdtype = DtoDType(vd->type); - Logger::println("found %u type %s", vd->offset, vdtype->toChars()); + //Logger::println("found %u type %s", vd->offset, vdtype->toChars()); assert(gIR->irDsymbol[vd].irField->index >= 0); if (os == vd->offset && vdtype == t) { + Logger::println("found %s %s", vdtype->toChars(), vd->toChars()); idxs.push_back(gIR->irDsymbol[vd].irField->index + dataoffset); - Logger::cout() << "indexing: " << *ptr << '\n'; + //Logger::cout() << "indexing: " << *ptr << '\n'; ptr = DtoGEP(ptr, idxs, "tmp"); if (ptr->getType() != llt) ptr = gIR->ir->CreateBitCast(ptr, llt, "tmp"); - Logger::cout() << "indexing: " << *ptr << '\n'; + //Logger::cout() << "indexing: " << *ptr << '\n'; if (gIR->irDsymbol[vd].irField->indexOffset) ptr = new llvm::GetElementPtrInst(ptr, DtoConstUint(gIR->irDsymbol[vd].irField->indexOffset), "tmp", gIR->scopebb()); - Logger::cout() << "indexing: " << *ptr << '\n'; + //Logger::cout() << "indexing: " << *ptr << '\n'; return ptr; } else if (vdtype->ty == Tstruct && (vd->offset + vdtype->size()) > os) { diff --git a/gen/structs.cpp b/gen/structs.cpp index b31336a1..25cd5c08 100644 --- a/gen/structs.cpp +++ b/gen/structs.cpp @@ -122,7 +122,7 @@ llvm::Value* DtoIndexStruct(llvm::Value* ptr, StructDeclaration* sd, Type* t, un for (unsigned i=0; ifields.dim; ++i) { VarDeclaration* vd = (VarDeclaration*)sd->fields.data[i]; Type* vdtype = DtoDType(vd->type); - Logger::println("found %u type %s", vd->offset, vdtype->toChars()); + //Logger::println("found %u type %s", vd->offset, vdtype->toChars()); assert(gIR->irDsymbol[vd].irField->index >= 0); if (os == vd->offset && vdtype == t) { idxs.push_back(gIR->irDsymbol[vd].irField->index); diff --git a/gen/toir.cpp b/gen/toir.cpp index 1a894f6b..cdd659e0 100644 --- a/gen/toir.cpp +++ b/gen/toir.cpp @@ -541,6 +541,8 @@ DValue* AssignExp::toElem(IRState* p) p->exps.pop_back(); + Logger::println("performing assignment"); + DImValue* im = r->isIm(); if (!im || !im->inPlace()) { Logger::println("assignment not inplace"); @@ -1007,7 +1009,7 @@ DValue* CallExp::toElem(IRState* p) // this arguments if (dfn && dfn->vthis) { - Logger::cout() << "This Call func val:" << *funcval << '\n'; + Logger::cout() << "This Call" << '\n';// func val:" << *funcval << '\n'; if (dfn->vthis->getType() != argiter->get()) { //Logger::cout() << "value: " << *dfn->vthis << " totype: " << *argiter->get() << '\n'; llargs[j] = DtoBitCast(dfn->vthis, argiter->get()); @@ -1155,7 +1157,7 @@ DValue* CallExp::toElem(IRState* p) } } - #if 1 + #if 0 Logger::println("%d params passed", n); for (int i=0; igetReturnType() != llvm::Type::VoidTy) varname = "tmp"; - Logger::cout() << "Calling: " << *funcval << '\n'; + //Logger::cout() << "Calling: " << *funcval << '\n'; // call the function llvm::CallInst* call = new llvm::CallInst(funcval, llargs.begin(), llargs.end(), varname, p->scopebb()); @@ -1894,6 +1896,7 @@ DValue* NewExp::toElem(IRState* p) Type* ntype = DtoDType(newtype); if (ntype->ty == Tclass) { + Logger::println("new class"); return DtoNewClass((TypeClass*)ntype, this); } diff --git a/llvmdc.kdevelop.filelist b/llvmdc.kdevelop.filelist index c9c42e8d..3de01023 100644 --- a/llvmdc.kdevelop.filelist +++ b/llvmdc.kdevelop.filelist @@ -750,6 +750,7 @@ tangotests/a.d tangotests/aa1.d tangotests/b.d tangotests/c.d +tangotests/classes1.d tangotests/constructors.d tangotests/d.d tangotests/e.d diff --git a/tangotests/classes1.d b/tangotests/classes1.d new file mode 100644 index 00000000..2bc66149 --- /dev/null +++ b/tangotests/classes1.d @@ -0,0 +1,37 @@ +module tangotests.classes1; + +class Outer +{ + int data; + + class Inner + { + long data; + + this(long d) + { + data = d*2; + } + } + + void func() + { + auto i = new Inner(data); + data += (i.data/4); + } + + this(int d) + { + data = d; + } +} + +void main() +{ + scope c = new Outer(100); + c.func(); + int d = c.data; + printf("150 = %d\n", d); +} + +extern(C) int printf(char*, ...);