From 3e17a21e0bf35242db520b31a03d46d7f57655e0 Mon Sep 17 00:00:00 2001 From: Tomas Lindquist Olsen Date: Fri, 13 Feb 2009 22:20:30 +0100 Subject: [PATCH] Merged a bunch recent dmd v1 frontend changes into the dmd v2 tree. --- dmd2/dsymbol.c | 28 ++++++++++++++++++++++++++++ dmd2/dsymbol.h | 1 + dmd2/mtype.c | 5 +++-- dmd2/mtype.h | 6 +++++- dmd2/statement.c | 13 +++++++------ dmd2/template.c | 13 +++++++++++++ dmd2/template.h | 1 + 7 files changed, 58 insertions(+), 9 deletions(-) diff --git a/dmd2/dsymbol.c b/dmd2/dsymbol.c index 2cf2cb4d..893610c2 100644 --- a/dmd2/dsymbol.c +++ b/dmd2/dsymbol.c @@ -560,6 +560,34 @@ Module *Dsymbol::getModule() return NULL; } + +/********************************** + * Determine which Module a Dsymbol will be compiled in. + * This may be different from getModule for templates. + */ + +Module *Dsymbol::getCompilationModule() +{ + Module *m; + TemplateInstance *ti; + Dsymbol *s; + + //printf("Dsymbol::getModule()\n"); + s = this; + while (s) + { + //printf("\ts = '%s'\n", s->toChars()); + m = s->isModule(); + if (m) + return m; + ti = s->isTemplateInstance(); + if (ti && ti->tmodule) + return ti->tmodule; + s = s->parent; + } + return NULL; +} + /************************************* */ diff --git a/dmd2/dsymbol.h b/dmd2/dsymbol.h index 96d8fd7a..61842ff9 100644 --- a/dmd2/dsymbol.h +++ b/dmd2/dsymbol.h @@ -121,6 +121,7 @@ struct Dsymbol : Object void error(const char *format, ...); void checkDeprecated(Loc loc, Scope *sc); Module *getModule(); + Module *getCompilationModule(); // possibly different for templates Dsymbol *pastMixin(); Dsymbol *toParent(); Dsymbol *toParent2(); diff --git a/dmd2/mtype.c b/dmd2/mtype.c index fb5f7bf1..53bb68f6 100644 --- a/dmd2/mtype.c +++ b/dmd2/mtype.c @@ -3074,10 +3074,11 @@ TypeFunction::TypeFunction(Arguments *parameters, Type *treturn, int varargs, en this->retInPtr = false; this->usesThis = false; this->usesNest = false; + this->structInregArg = NULL; this->retAttrs = 0; this->thisAttrs = 0; this->reverseParams = false; - this->reverseIndex = 0; + this->firstRealArg = 0; } Type *TypeFunction::syntaxCopy() @@ -3095,7 +3096,7 @@ Type *TypeFunction::syntaxCopy() t->retAttrs = retAttrs; t->thisAttrs = thisAttrs; t->reverseParams = reverseParams; - t->reverseIndex = reverseIndex; + t->firstRealArg = firstRealArg; return t; } diff --git a/dmd2/mtype.h b/dmd2/mtype.h index 4e0c8196..f75b1c7f 100644 --- a/dmd2/mtype.h +++ b/dmd2/mtype.h @@ -23,6 +23,7 @@ // llvm #include "../ir/irtype.h" +namespace llvm { class Type; } struct Scope; struct Identifier; @@ -504,11 +505,14 @@ struct TypeFunction : TypeNext bool retInPtr; bool usesThis; bool usesNest; + // when the last arg is a struct and passed in EAX, this holds its real type + const llvm::Type* structInregArg; unsigned retAttrs; unsigned thisAttrs; // also used for nest + // parameter index in the llvm function that contains the first not-implicit arg + size_t firstRealArg; bool reverseParams; - size_t reverseIndex; }; struct TypeDelegate : TypeNext diff --git a/dmd2/statement.c b/dmd2/statement.c index 38f06677..fa3e74ed 100644 --- a/dmd2/statement.c +++ b/dmd2/statement.c @@ -2198,12 +2198,6 @@ Statement *IfStatement::semantic(Scope *sc) condition = condition->semantic(scd); } - // LDC - else if (ident == Id::allow_inline) - { - sc->func->allowInlining = true; - } - else scd = sc->push(); ifbody = ifbody->semantic(scd); @@ -2478,6 +2472,13 @@ Statement *PragmaStatement::semantic(Scope *sc) return this; } } + + // LDC + else if (ident == Id::allow_inline) + { + sc->func->allowInlining = true; + } + else error("unrecognized pragma(%s)", ident->toChars()); diff --git a/dmd2/template.c b/dmd2/template.c index 17b21cf9..ec53eff6 100644 --- a/dmd2/template.c +++ b/dmd2/template.c @@ -3013,7 +3013,10 @@ TemplateInstance::TemplateInstance(Loc loc, Identifier *ident) this->havetempdecl = 0; this->isnested = NULL; this->errors = 0; + + // LDC this->tinst = NULL; + this->tmodule = NULL; } /***************** @@ -3041,7 +3044,10 @@ TemplateInstance::TemplateInstance(Loc loc, TemplateDeclaration *td, Objects *ti this->havetempdecl = 1; this->isnested = NULL; this->errors = 0; + + // LDC this->tinst = NULL; + this->tmodule = NULL; assert((size_t)tempdecl->scope > 0x10000); } @@ -3112,6 +3118,13 @@ void TemplateInstance::semantic(Scope *sc) // get the enclosing template instance from the scope tinst tinst = sc->tinst; + // get the module of the outermost enclosing instantiation + if (tinst) + tmodule = tinst->tmodule; + else + tmodule = sc->module; + //printf("%s in %s\n", toChars(), tmodule->toChars()); + #if LOG printf("\tdo semantic\n"); #endif diff --git a/dmd2/template.h b/dmd2/template.h index 34136b03..c0877cff 100644 --- a/dmd2/template.h +++ b/dmd2/template.h @@ -322,6 +322,7 @@ struct TemplateInstance : ScopeDsymbol // LDC TemplateInstance *tinst; // enclosing template instance + Module* tmodule; // module from outermost enclosing template instantiation void printInstantiationTrace(); };