diff dmd/attrib.c @ 336:aaade6ded589 trunk

[svn r357] Merged DMD 1.033
author lindquist
date Sat, 12 Jul 2008 19:38:31 +0200
parents 5acec6b2eef8
children 44f08170f4ef
line wrap: on
line diff
--- a/dmd/attrib.c	Sat Jul 12 17:04:36 2008 +0200
+++ b/dmd/attrib.c	Sat Jul 12 19:38:31 2008 +0200
@@ -1,6 +1,6 @@
 
 // Compiler implementation of the D programming language
-// Copyright (c) 1999-2007 by Digital Mars
+// Copyright (c) 1999-2008 by Digital Mars
 // All Rights Reserved
 // written by Walter Bright
 // http://www.digitalmars.com
@@ -35,6 +35,7 @@
 #include "../gen/logger.h"
 
 extern void obj_includelib(char *name);
+void obj_startaddress(Symbol *s);
 
 
 /********************************* AttribDeclaration ****************************/
@@ -52,16 +53,13 @@
 
 int AttribDeclaration::addMember(Scope *sc, ScopeDsymbol *sd, int memnum)
 {
-    unsigned i;
     int m = 0;
     Array *d = include(sc, sd);
 
     if (d)
     {
-	for (i = 0; i < d->dim; i++)
-	{   Dsymbol *s;
-
-	    s = (Dsymbol *)d->data[i];
+	for (unsigned i = 0; i < d->dim; i++)
+	{   Dsymbol *s = (Dsymbol *)d->data[i];
 	    m |= s->addMember(sc, sd, m | memnum);
 	}
     }
@@ -72,7 +70,7 @@
 {
     Array *d = include(sc, NULL);
 
-    //printf("\tAttribDeclaration::semantic '%s'\n",toChars());
+    //printf("\tAttribDeclaration::semantic '%s', d = %p\n",toChars(), d);
     if (d)
     {
 	for (unsigned i = 0; i < d->dim; i++)
@@ -86,15 +84,12 @@
 
 void AttribDeclaration::semantic2(Scope *sc)
 {
-    unsigned i;
     Array *d = include(sc, NULL);
 
     if (d)
     {
-	for (i = 0; i < d->dim; i++)
-	{   Dsymbol *s;
-
-	    s = (Dsymbol *)d->data[i];
+	for (unsigned i = 0; i < d->dim; i++)
+	{   Dsymbol *s = (Dsymbol *)d->data[i];
 	    s->semantic2(sc);
 	}
     }
@@ -102,15 +97,12 @@
 
 void AttribDeclaration::semantic3(Scope *sc)
 {
-    unsigned i;
     Array *d = include(sc, NULL);
 
     if (d)
     {
-	for (i = 0; i < d->dim; i++)
-	{   Dsymbol *s;
-
-	    s = (Dsymbol *)d->data[i];
+	for (unsigned i = 0; i < d->dim; i++)
+	{   Dsymbol *s = (Dsymbol *)d->data[i];
 	    s->semantic3(sc);
 	}
     }
@@ -118,15 +110,12 @@
 
 void AttribDeclaration::inlineScan()
 {
-    unsigned i;
     Array *d = include(NULL, NULL);
 
     if (d)
     {
-	for (i = 0; i < d->dim; i++)
-	{   Dsymbol *s;
-
-	    s = (Dsymbol *)d->data[i];
+	for (unsigned i = 0; i < d->dim; i++)
+	{   Dsymbol *s = (Dsymbol *)d->data[i];
 	    //printf("AttribDeclaration::inlineScan %s\n", s->toChars());
 	    s->inlineScan();
 	}
@@ -137,15 +126,12 @@
 {
     if (comment)
     {
-	unsigned i;
 	Array *d = include(NULL, NULL);
 
 	if (d)
 	{
-	    for (i = 0; i < d->dim; i++)
-	    {   Dsymbol *s;
-
-		s = (Dsymbol *)d->data[i];
+	    for (unsigned i = 0; i < d->dim; i++)
+	    {   Dsymbol *s = (Dsymbol *)d->data[i];
 		//printf("AttribDeclaration::addComment %s\n", s->toChars());
 		s->addComment(comment);
 	    }
@@ -163,50 +149,41 @@
 //    if (sc->docbuf)
 //	return;
 
-    unsigned i;
     Array *d = include(NULL, NULL);
 
     if (d)
     {
-	for (i = 0; i < d->dim; i++)
-	{   Dsymbol *s;
-
-	    s = (Dsymbol *)d->data[i];
+	for (unsigned i = 0; i < d->dim; i++)
+	{   Dsymbol *s = (Dsymbol *)d->data[i];
 	    //printf("AttribDeclaration::emitComment %s\n", s->toChars());
 	    s->emitComment(sc);
 	}
     }
 }
 
-void AttribDeclaration::toObjFile()
+void AttribDeclaration::toObjFile(int multiobj)
 {
-    unsigned i;
     Array *d = include(NULL, NULL);
 
     if (d)
     {
-	for (i = 0; i < d->dim; i++)
-	{   Dsymbol *s;
-
-	    s = (Dsymbol *)d->data[i];
-	    s->toObjFile();
+	for (unsigned i = 0; i < d->dim; i++)
+	{   Dsymbol *s = (Dsymbol *)d->data[i];
+	    s->toObjFile(multiobj);
 	}
     }
 }
 
 int AttribDeclaration::cvMember(unsigned char *p)
 {
-    unsigned i;
     int nwritten = 0;
     int n;
     Array *d = include(NULL, NULL);
 
     if (d)
     {
-	for (i = 0; i < d->dim; i++)
-	{   Dsymbol *s;
-
-	    s = (Dsymbol *)d->data[i];
+	for (unsigned i = 0; i < d->dim; i++)
+	{   Dsymbol *s = (Dsymbol *)d->data[i];
 	    n = s->cvMember(p);
 	    if (p)
 		p += n;
@@ -232,7 +209,7 @@
     return 0;
 }
 
-char *AttribDeclaration::kind()
+const char *AttribDeclaration::kind()
 {
     return "attribute";
 }
@@ -246,15 +223,12 @@
 
 void AttribDeclaration::checkCtorConstInit()
 {
-    unsigned i;
     Array *d = include(NULL, NULL);
 
     if (d)
     {
-	for (i = 0; i < d->dim; i++)
-	{   Dsymbol *s;
-
-	    s = (Dsymbol *)d->data[i];
+	for (unsigned i = 0; i < d->dim; i++)
+	{   Dsymbol *s = (Dsymbol *)d->data[i];
 	    s->checkCtorConstInit();
 	}
     }
@@ -264,15 +238,13 @@
  */
 
 void AttribDeclaration::addLocalClass(ClassDeclarations *aclasses)
-{   unsigned i;
+{
     Array *d = include(NULL, NULL);
 
     if (d)
     {
-	for (i = 0; i < d->dim; i++)
-	{   Dsymbol *s;
-
-	    s = (Dsymbol *)d->data[i];
+	for (unsigned i = 0; i < d->dim; i++)
+	{   Dsymbol *s = (Dsymbol *)d->data[i];
 	    s->addLocalClass(aclasses);
 	}
     }
@@ -723,7 +695,7 @@
     buf->writestring("}\n");
 }
 
-char *AnonDeclaration::kind()
+const char *AnonDeclaration::kind()
 {
     return (char *)(isunion ? "anonymous union" : "anonymous struct");
 }
@@ -1023,12 +995,12 @@
     return TRUE;
 }
 
-char *PragmaDeclaration::kind()
+const char *PragmaDeclaration::kind()
 {
     return "pragma";
 }
 
-void PragmaDeclaration::toObjFile()
+void PragmaDeclaration::toObjFile(int multiobj)
 {
     if (ident == Id::lib)
     {
@@ -1044,7 +1016,7 @@
 	name[se->len] = 0;
 	obj_includelib(name);
     }
-    AttribDeclaration::toObjFile();
+    AttribDeclaration::toObjFile(multiobj);
 }
 
 void PragmaDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
@@ -1214,6 +1186,7 @@
 
 int StaticIfDeclaration::addMember(Scope *sc, ScopeDsymbol *sd, int memnum)
 {
+    //printf("StaticIfDeclaration::addMember() '%s'\n",toChars());
     /* This is deferred until semantic(), so that
      * expressions in the condition can refer to declarations
      * in the same scope, such as:
@@ -1240,7 +1213,7 @@
 {
     Array *d = include(sc, sd);
 
-    //printf("\tStaticIfDeclaration::semantic '%s'\n",toChars());
+    //printf("\tStaticIfDeclaration::semantic '%s', d = %p\n",toChars(), d);
     if (d)
     {
 	if (!addisdone)
@@ -1257,7 +1230,7 @@
     }
 }
 
-char *StaticIfDeclaration::kind()
+const char *StaticIfDeclaration::kind()
 {
     return "static if";
 }
@@ -1268,8 +1241,10 @@
 CompileDeclaration::CompileDeclaration(Loc loc, Expression *exp)
     : AttribDeclaration(NULL)
 {
+    this->loc = loc;
     this->exp = exp;
     this->sd = NULL;
+    this->compiled = 0;
 }
 
 Dsymbol *CompileDeclaration::syntaxCopy(Dsymbol *s)
@@ -1281,32 +1256,50 @@
 
 int CompileDeclaration::addMember(Scope *sc, ScopeDsymbol *sd, int memnum)
 {
+    //printf("CompileDeclaration::addMember(sc = %p)\n", sc);
     this->sd = sd;
+    if (memnum == 0)
+    {	/* No members yet, so parse the mixin now
+	 */
+	compileIt(sc);
+	memnum |= AttribDeclaration::addMember(sc, sd, memnum);
+	compiled = 1;
+    }
     return memnum;
 }
 
+void CompileDeclaration::compileIt(Scope *sc)
+{
+    //printf("CompileDeclaration::compileIt()\n");
+    exp = exp->semantic(sc);
+    exp = resolveProperties(sc, exp);
+    exp = exp->optimize(WANTvalue | WANTinterpret);
+    if (exp->op != TOKstring)
+    {	exp->error("argument to mixin must be a string, not (%s)", exp->toChars());
+    }
+    else
+    {
+	StringExp *se = (StringExp *)exp;
+	se = se->toUTF8(sc);
+	Parser p(sc->module, (unsigned char *)se->string, se->len, 0);
+	p.loc = loc;
+	p.nextToken();
+	decl = p.parseDeclDefs(0);
+	if (p.token.value != TOKeof)
+	    exp->error("incomplete mixin declaration (%s)", se->toChars());
+    }
+}
+
 void CompileDeclaration::semantic(Scope *sc)
 {
     //printf("CompileDeclaration::semantic()\n");
-    exp = exp->semantic(sc);
-    exp = resolveProperties(sc, exp);
-    exp = exp->optimize(WANTvalue | WANTinterpret);
-    if (exp->op != TOKstring)
-    {	error("argument to mixin must be a string, not (%s)", exp->toChars());
-	return;
+
+    if (!compiled)
+    {
+	compileIt(sc);
+	AttribDeclaration::addMember(sc, sd, 0);
+	compiled = 1;
     }
-    StringExp *se = (StringExp *)exp;
-    se = se->toUTF8(sc);
-    Parser p(sc->module, (unsigned char *)se->string, se->len, 0);
-    p.loc = loc;
-    p.nextToken();
-    decl = p.parseDeclDefs(0);
-    if (p.token.value != TOKeof)
-    {
-	error("incomplete mixin declaration (%s)", se->toChars());
-    }
-
-    AttribDeclaration::addMember(sc, sd, 0);
     AttribDeclaration::semantic(sc);
 }