diff gen/classes.cpp @ 486:a34078905d01

Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in. Reimplemented support for nested functions/class using a new approach. Added error on taking address of intrinsic. Fixed problems with the ->syntaxCopy of TypeFunction delegate exp. Removed DtoDType and replaced all uses with ->toBasetype() instead. Removed unused inplace stuff. Fixed a bunch of issues in the runtime unittests, not complete yet. Added mini tests.
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Sun, 10 Aug 2008 08:37:38 +0200
parents 672eb4893b55
children 577211114d6d
line wrap: on
line diff
--- a/gen/classes.cpp	Sat Aug 09 09:03:52 2008 +0200
+++ b/gen/classes.cpp	Sun Aug 10 08:37:38 2008 +0200
@@ -786,7 +786,7 @@
 
 //////////////////////////////////////////////////////////////////////////////////////////
 
-DValue* DtoNewClass(TypeClass* tc, NewExp* newexp)
+DValue* DtoNewClass(Loc loc, TypeClass* tc, NewExp* newexp)
 {
     // resolve type
     DtoForceDeclareDsymbol(tc->sym);
@@ -829,25 +829,18 @@
         DtoStore(src, dst);
     }
     // set the context for nested classes
-    else if (tc->sym->isNested())
+    else if (tc->sym->isNested() && tc->sym->vthis)
     {
         Logger::println("Resolving nested context");
         LOG_SCOPE;
 
+        // get context
+        LLValue* nest = DtoNestedContext(loc, tc->sym);
+
+        // store into right location
         size_t idx = 2 + tc->sym->vthis->ir.irField->index;
         LLValue* gep = DtoGEPi(mem,0,idx,"tmp");
-
-        // this value might be zero if it was not necessary to generate it ...
-        LLValue* nest = gIR->func()->nestedVar;
-        // ... then revert to the this ptr if there is one
-        if (!nest)
-            nest = gIR->func()->thisVar;
-        // ... or just use zero, since it must be unused.
-        if (!nest)
-            nest = llvm::Constant::getNullValue(gep->getType()->getContainedType(0));
-        else
-            nest = DtoBitCast(nest, gep->getType()->getContainedType(0));
-        DtoStore(nest, gep);
+        DtoStore(DtoBitCast(nest, gep->getType()->getContainedType(0)), gep);
     }
 
     // call constructor
@@ -860,7 +853,7 @@
     }
 
     // return default constructed class
-    return new DImValue(tc, mem, false);
+    return new DImValue(tc, mem);
 }
 
 //////////////////////////////////////////////////////////////////////////////////////////
@@ -912,7 +905,7 @@
     Logger::println("DtoCastClass(%s, %s)", val->getType()->toChars(), _to->toChars());
     LOG_SCOPE;
 
-    Type* to = DtoDType(_to);
+    Type* to = _to->toBasetype();
     if (to->ty == Tpointer) {
         const LLType* tolltype = DtoType(_to);
         LLValue* rval = DtoBitCast(val->getRVal(), tolltype);
@@ -922,7 +915,7 @@
     assert(to->ty == Tclass);
     TypeClass* tc = (TypeClass*)to;
 
-    Type* from = DtoDType(val->getType());
+    Type* from = val->getType()->toBasetype();
     TypeClass* fc = (TypeClass*)from;
 
     if (tc->sym->isInterfaceDeclaration()) {
@@ -977,7 +970,7 @@
     assert(funcTy->getParamType(0) == obj->getType());
 
     // ClassInfo c
-    TypeClass* to = (TypeClass*)DtoDType(_to);
+    TypeClass* to = (TypeClass*)_to->toBasetype();
     DtoForceDeclareDsymbol(to->sym);
     assert(to->sym->ir.irStruct->classInfo);
     LLValue* cinfo = to->sym->ir.irStruct->classInfo;
@@ -1041,7 +1034,7 @@
     ptr = DtoBitCast(ptr, funcTy->getParamType(0));
 
     // ClassInfo c
-    TypeClass* to = (TypeClass*)DtoDType(_to);
+    TypeClass* to = (TypeClass*)_to->toBasetype();
     DtoForceDeclareDsymbol(to->sym);
     assert(to->sym->ir.irStruct->classInfo);
     LLValue* cinfo = to->sym->ir.irStruct->classInfo;
@@ -1116,7 +1109,7 @@
     for (IrStruct::OffsetMap::iterator i=irstruct->offsets.begin(); i!=irstruct->offsets.end(); ++i) {
         VarDeclaration* vd = i->second.var;
         assert(vd);
-        Type* vdtype = DtoDType(vd->type);
+        Type* vdtype = vd->type->toBasetype();
         //Logger::println("found %u type %s", vd->offset, vdtype->toChars());
         assert(vd->ir.irField->index >= 0);
         if (os == vd->offset && vdtype->toBasetype() == t->toBasetype()) {
@@ -1173,7 +1166,7 @@
 {
     assert(fdecl->isVirtual());//fdecl->isAbstract() || (!fdecl->isFinal() && fdecl->isVirtual()));
     assert(fdecl->vtblIndex > 0);
-    assert(DtoDType(inst->getType())->ty == Tclass);
+    assert(inst->getType()->toBasetype()->ty == Tclass);
 
     LLValue* vthis = inst->getRVal();
     Logger::cout() << "vthis: " << *vthis << '\n';