diff gen/toir.cpp @ 433:b5f55f471e0b

Move DeclarationExp code into a helper function so it can call itself for template mixin members.
author Christian Kamm <kamm incasoftware de>
date Wed, 30 Jul 2008 09:21:06 +0200
parents e763821ab244
children 74101be2a553
line wrap: on
line diff
--- a/gen/toir.cpp	Tue Jul 29 21:52:25 2008 +0200
+++ b/gen/toir.cpp	Wed Jul 30 09:21:06 2008 +0200
@@ -44,118 +44,7 @@
     Logger::print("DeclarationExp::toElem: %s | T=%s\n", toChars(), type->toChars());
     LOG_SCOPE;
 
-    // variable declaration
-    if (VarDeclaration* vd = declaration->isVarDeclaration())
-    {
-        Logger::println("VarDeclaration");
-
-        // static
-        if (vd->isDataseg())
-        {
-            vd->toObjFile(0); // TODO: multiobj
-        }
-        else
-        {
-            if (global.params.llvmAnnotate)
-                DtoAnnotation(toChars());
-
-            Logger::println("vdtype = %s", vd->type->toChars());
-
-            // referenced by nested delegate?
-            if (vd->nestedref) {
-                Logger::println("has nestedref set");
-                assert(vd->ir.irLocal);
-                vd->ir.irLocal->value = p->func()->decl->ir.irFunc->nestedVar;
-                assert(vd->ir.irLocal->value);
-                assert(vd->ir.irLocal->nestedIndex >= 0);
-            }
-            // normal stack variable, allocate storage on the stack if it has not already been done
-            else if(!vd->ir.irLocal) {
-                const LLType* lltype = DtoType(vd->type);
-
-                llvm::Value* allocainst;
-                if(gTargetData->getTypeSizeInBits(lltype) == 0) 
-                    allocainst = llvm::ConstantPointerNull::get(getPtrToType(lltype));
-                else
-                    allocainst = new llvm::AllocaInst(lltype, vd->toChars(), p->topallocapoint());
-
-                //allocainst->setAlignment(vd->type->alignsize()); // TODO
-                vd->ir.irLocal = new IrLocal(vd);
-                vd->ir.irLocal->value = allocainst;
-
-                if (global.params.symdebug)
-                {
-                    DtoDwarfLocalVariable(allocainst, vd);
-                }
-            }
-
-            Logger::cout() << "llvm value for decl: " << *vd->ir.irLocal->value << '\n';
-            DValue* ie = DtoInitializer(vd->init);
-        }
-
-        return new DVarValue(vd, vd->ir.getIrValue(), true);
-    }
-    // struct declaration
-    else if (StructDeclaration* s = declaration->isStructDeclaration())
-    {
-        Logger::println("StructDeclaration");
-        DtoForceConstInitDsymbol(s);
-    }
-    // function declaration
-    else if (FuncDeclaration* f = declaration->isFuncDeclaration())
-    {
-        Logger::println("FuncDeclaration");
-        DtoForceDeclareDsymbol(f);
-    }
-    // alias declaration
-    else if (AliasDeclaration* a = declaration->isAliasDeclaration())
-    {
-        Logger::println("AliasDeclaration - no work");
-        // do nothing
-    }
-    // enum
-    else if (EnumDeclaration* e = declaration->isEnumDeclaration())
-    {
-        Logger::println("EnumDeclaration - no work");
-        // do nothing
-    }
-    // class
-    else if (ClassDeclaration* e = declaration->isClassDeclaration())
-    {
-        Logger::println("ClassDeclaration");
-        DtoForceConstInitDsymbol(e);
-    }
-    // typedef
-    else if (TypedefDeclaration* tdef = declaration->isTypedefDeclaration())
-    {
-        Logger::println("TypedefDeclaration");
-        DtoTypeInfoOf(tdef->type, false);
-    }
-    // attribute declaration
-    else if (AttribDeclaration* a = declaration->isAttribDeclaration())
-    {
-        Logger::println("AttribDeclaration");
-        for (int i=0; i < a->decl->dim; ++i)
-        {
-            DtoForceDeclareDsymbol((Dsymbol*)a->decl->data[i]);
-        }
-    }
-    // mixin declaration
-    else if (TemplateMixin* m = declaration->isTemplateMixin())
-    {
-        Logger::println("TemplateMixin");
-        for (int i=0; i < m->members->dim; ++i)
-        {
-            DtoForceDeclareDsymbol((Dsymbol*)m->members->data[i]);
-        }
-    }
-    // unsupported declaration
-    else
-    {
-        error("Unimplemented DeclarationExp type. kind: %s", declaration->kind());
-        assert(0);
-    }
-    return 0;
+    return DtoDeclarationExp(declaration);
 }
 
 //////////////////////////////////////////////////////////////////////////////////////////