diff dmd/template.c @ 1367:8026319762be

Merged DMD 1.045 !!!
author Tomas Lindquist Olsen <tomas.l.olsen gmail com>
date Sat, 16 May 2009 22:21:31 +0200
parents e961851fb8be
children 4dca8ed9d8b7
line wrap: on
line diff
--- a/dmd/template.c	Sat May 16 18:37:16 2009 +0200
+++ b/dmd/template.c	Sat May 16 22:21:31 2009 +0200
@@ -1750,7 +1750,7 @@
 	    /* See if 'A' of the template parameter matches 'A'
 	     * of the type of the last function parameter.
 	     */
-	    Argument *fparam = (Argument *)tp->parameters->data[nfparams - 1];
+	    Argument *fparam = Argument::getNth(tp->parameters, nfparams - 1);
 	    if (fparam->type->ty != Tident)
 		goto L1;
 	    TypeIdentifier *tid = (TypeIdentifier *)fparam->type;
@@ -3059,6 +3059,7 @@
     this->tiargs = NULL;
     this->tempdecl = NULL;
     this->inst = NULL;
+    this->tinst = NULL;
     this->argsym = NULL;
     this->aliasdecl = NULL;
     this->semanticdone = 0;
@@ -3072,7 +3073,6 @@
 #if IN_LLVM
     // LDC
     this->emittedInModule = NULL;
-    this->tinst = NULL;
     this->tmodule = NULL;
 #endif
 }
@@ -3093,6 +3093,7 @@
     this->tiargs = tiargs;
     this->tempdecl = td;
     this->inst = NULL;
+    this->tinst = NULL;
     this->argsym = NULL;
     this->aliasdecl = NULL;
     this->semanticdone = 0;
@@ -3175,6 +3176,9 @@
 	return;
     }
 
+    // get the enclosing template instance from the scope tinst
+    tinst = sc->tinst;
+
     if (semanticdone != 0)
     {
 	error(loc, "recursive template expansion");
@@ -3420,6 +3424,14 @@
   __try
   {
 #endif
+    static int nest;
+    //printf("%d\n", nest);
+    if (++nest > 500)
+    {
+	global.gag = 0;			// ensure error message gets printed
+	error("recursive expansion");
+	fatal();
+    }
     for (int i = 0; i < members->dim; i++)
     {
 	Dsymbol *s = (Dsymbol *)members->data[i];
@@ -3432,6 +3444,7 @@
 	//printf("test4: isnested = %d, s->parent = %s\n", isnested, s->parent->toChars());
 	sc2->module->runDeferredSemantic();
     }
+    --nest;
 #if WINDOWS_SEH
   }
   __except (__ehfilter(GetExceptionInformation()))
@@ -3479,8 +3492,10 @@
     if (global.errors != errorsave)
     {
 	error("error instantiating");
-	if(tinst)
-	    tinst->printInstantiationTrace();
+	if (tinst && !global.gag)
+	{   tinst->printInstantiationTrace();
+	    fatal();
+	}
 	errors = 1;
 	if (global.gag)
 	    tempdecl->instances.remove(tempdecl_instance_idx);
@@ -3985,7 +4000,7 @@
 	  Lsa:
 	    buf.writeByte('S');
 	    Declaration *d = sa->isDeclaration();
-	    if (d && !d->type->deco)
+	    if (d && (!d->type || !d->type->deco))
 		error("forward reference of %s", d->toChars());
 	    else
 	    {
@@ -4089,6 +4104,12 @@
 
 #if IN_DMD
 
+void TemplateInstance::printInstantiationTrace()
+{
+    if (global.gag)
+	return;
+}
+
 void TemplateInstance::toObjFile(int multiobj)
 {
 #if LOG
@@ -4201,6 +4222,8 @@
     return s;
 }
 
+#if IN_LLVM
+
 void TemplateInstance::printInstantiationTrace()
 {
     if(global.gag)
@@ -4238,6 +4261,8 @@
     }
 }
 
+#endif
+
 /* ======================== TemplateMixin ================================ */
 
 TemplateMixin::TemplateMixin(Loc loc, Identifier *ident, Type *tqual,
@@ -4508,11 +4533,24 @@
     Scope *sc2;
     sc2 = scope->push(this);
     sc2->offset = sc->offset;
+
+    static int nest;
+    //printf("%d\n", nest);
+    if (++nest > 500)
+    {
+	global.gag = 0;			// ensure error message gets printed
+	error("recursive expansion");
+	fatal();
+    }
+
     for (int i = 0; i < members->dim; i++)
     {
 	Dsymbol *s = (Dsymbol *)members->data[i];
 	s->semantic(sc2);
     }
+
+    nest--;
+
     sc->offset = sc2->offset;
 
     /* The problem is when to parse the initializer for a variable.