changeset 169:e7769d53e750

Moves static variables from Module to Global
author korDen
date Thu, 30 Sep 2010 13:29:54 +0400
parents ceed63f310fb
children 96c0fff6897d
files dmd/AnonDeclaration.d dmd/ClassDeclaration.d dmd/Global.d dmd/Import.d dmd/Lexer.d dmd/Library.d dmd/Lstring.d dmd/Module.d dmd/ModuleInfoDeclaration.d dmd/Package.d dmd/PowExp.d dmd/StructDeclaration.d dmd/TemplateInstance.d main.d
diffstat 14 files changed, 79 insertions(+), 68 deletions(-) [+]
line wrap: on
line diff
--- a/dmd/AnonDeclaration.d	Thu Sep 30 12:57:13 2010 +0400
+++ b/dmd/AnonDeclaration.d	Thu Sep 30 13:29:54 2010 +0400
@@ -13,6 +13,7 @@
 import dmd.STC;
 import dmd.Module;
 import dmd.VarDeclaration;
+import dmd.Global;
 
 class AnonDeclaration : AttribDeclaration
 {
@@ -110,7 +111,7 @@
 			}
 			if (sem == 0)
 			{   
-				Module.dprogress++;
+				global.dprogress++;
 				sem = 1;
 				//printf("\tcompleted %p\n", this);
 			}
--- a/dmd/ClassDeclaration.d	Thu Sep 30 12:57:13 2010 +0400
+++ b/dmd/ClassDeclaration.d	Thu Sep 30 13:29:54 2010 +0400
@@ -282,9 +282,9 @@
 
 			if (id is Id.ModuleInfo)
 			{   
-				if (Module.moduleinfo)
-					Module.moduleinfo.error("%s", msg);
-				Module.moduleinfo = this;
+				if (global.moduleinfo)
+					global.moduleinfo.error("%s", msg);
+				global.moduleinfo = this;
 			}
 		}
 
@@ -813,7 +813,7 @@
 		}
 		structsize = sc.offset;
 		sizeok = 1;
-		Module.dprogress++;
+		global.dprogress++;
 
 		dtor = buildDtor(sc);
 
@@ -1115,7 +1115,7 @@
 			ident is Id.TypeInfo_Tuple ||
 			this is global.object     ||
 			this is global.classinfo  ||
-			this is Module.moduleinfo ||
+			this is global.moduleinfo ||
 			ident.toChars().startsWith("TypeInfo_")
 		   )
 		{
--- a/dmd/Global.d	Thu Sep 30 12:57:13 2010 +0400
+++ b/dmd/Global.d	Thu Sep 30 13:29:54 2010 +0400
@@ -8,6 +8,10 @@
 import dmd.StringTable;
 import dmd.OutBuffer;
 import dmd.Token;
+import dmd.Module;
+
+import core.stdc.time;
+import core.stdc.stdio;
 
 class Global
 {
@@ -67,12 +71,44 @@
     OutBuffer stringbuffer;
     Token* freelist;
 	
+	char date[11+1];
+	char time[8+1];
+	char timestamp[24+1];
+	
+	// Used in Module
+	Module rootModule;
+    DsymbolTable modules;	// symbol table of all modules
+    Array amodules;		// array of all modules
+    Array deferred;	// deferred Dsymbol's needing semantic() run on them
+    uint dprogress;	// progress resolving the deferred list
+	
+	ClassDeclaration moduleinfo;
+	
 	this()
 	{
 		params.versionids = new Array();
 		st = new DsymbolTable();
 		stringtable = new StringTable();
 		stringbuffer = new OutBuffer();
+		
+		modules = new DsymbolTable();
+		amodules = new Array();
+		deferred = new Array();
+		
+		init_time();
+	}
+	
+	void init_time()
+	{
+		time_t tm;
+		char* p;
+
+		.time(&tm);
+		p = ctime(&tm);
+		assert(p);
+		sprintf(date.ptr, "%.6s %.4s", p + 4, p + 20);
+		sprintf(time.ptr, "%.8s", p + 11);
+		sprintf(timestamp.ptr, "%.24s", p);
 	}
 }
 
--- a/dmd/Import.d	Thu Sep 30 12:57:13 2010 +0400
+++ b/dmd/Import.d	Thu Sep 30 13:29:54 2010 +0400
@@ -130,7 +130,7 @@
 			dst.insert(id, mod);		// id may be different from mod.ident,
 							// if so then insert alias
 			if (!mod.importedFrom)
-				mod.importedFrom = sc ? sc.module_.importedFrom : Module.rootModule;
+				mod.importedFrom = sc ? sc.module_.importedFrom : global.rootModule;
 		}
 
 		if (!pkg)
--- a/dmd/Lexer.d	Thu Sep 30 12:57:13 2010 +0400
+++ b/dmd/Lexer.d	Thu Sep 30 13:29:54 2010 +0400
@@ -23,8 +23,6 @@
 import core.stdc.ctype;
 import core.stdc.stdlib;
 import core.stdc.string;
-import core.stdc.stdio;
-import core.stdc.time;
 import core.stdc.errno;
 
 enum LS = 0x2028;	// UTF line separator
@@ -411,7 +409,7 @@
 	}
 
 version (DMDV2) {
-	static Keyword[] keywords =
+	enum Keyword[] keywords =
 	[
 	//    {	"",		TOK	},
 
@@ -538,7 +536,7 @@
 		{	"immutable",	TOK.TOKimmutable	},
 	];
 } else {
-	static Keyword[] keywords =
+	enum Keyword[] keywords =
 	[
 	//    {	"",		TOK	},
 
@@ -1082,22 +1080,6 @@
 				anyToken = 1;
 				if (*t.ptr == '_')	// if special identifier token
 				{
-					static char date[11+1];
-					static char time[8+1];
-					static char timestamp[24+1];
-
-					if (!date[0])	// lazy evaluation
-					{   time_t tm;
-					char *p;
-
-					.time(&tm);
-					p = ctime(&tm);
-					assert(p);
-					sprintf(date.ptr, "%.6s %.4s", p + 4, p + 20);
-					sprintf(time.ptr, "%.8s", p + 11);
-					sprintf(timestamp.ptr, "%.24s", p);
-					}
-
 ///version (DMDV1) {
 ///					if (mod && id == Id.FILE)
 ///					{
@@ -1113,12 +1095,12 @@
 ///}
 					if (id == Id.DATE)
 					{
-					t.ustring = date.ptr;
+					t.ustring = global.date.ptr;
 					goto Lstr;
 					}
 					else if (id == Id.TIME)
 					{
-					t.ustring = time.ptr;
+					t.ustring = global.time.ptr;
 					goto Lstr;
 					}
 					else if (id == Id.VENDOR)
@@ -1128,7 +1110,7 @@
 					}
 					else if (id == Id.TIMESTAMP)
 					{
-					t.ustring = timestamp.ptr;
+					t.ustring = global.timestamp.ptr;
 					 Lstr:
 					t.value = TOK.TOKstring;
 					 Llen:
--- a/dmd/Library.d	Thu Sep 30 12:57:13 2010 +0400
+++ b/dmd/Library.d	Thu Sep 30 13:29:54 2010 +0400
@@ -606,7 +606,7 @@
 				case COMENT:
 					// Recognize Phar Lap EASY-OMF format
 					{   
-						static ubyte[7] omfstr = [0x80,0xAA,'8','0','3','8','6'];
+						enum ubyte[7] omfstr = [0x80,0xAA,'8','0','3','8','6'];
 
 						if (recLen == omfstr.sizeof)
 						{
@@ -620,7 +620,7 @@
 					}
 					// Recognize .IMPDEF Import Definition Records
 					{   
-						static ubyte[3] omfstr = [0, 0xA0, 1];
+						enum ubyte[3] omfstr = [0, 0xA0, 1];
 
 						if (recLen >= 7)
 						{
@@ -684,7 +684,7 @@
 		//printf("ndicpages = %u\n",ndicpages);
 
 		// Find prime number greater than ndicpages
-		static uint[] primes =
+		enum uint[] primes =
 		[ 1,2,3,5,7,11,13,17,19,23,29,31,37,41,43,
 		  47,53,59,61,67,71,73,79,83,89,97,101,103,
 		  107,109,113,127,131,137,139,149,151,157,
--- a/dmd/Lstring.d	Thu Sep 30 12:57:13 2010 +0400
+++ b/dmd/Lstring.d	Thu Sep 30 13:29:54 2010 +0400
@@ -7,7 +7,7 @@
 {
     immutable(dchar_t)[] string_;
 
-    static Lstring zero;	// 0 length string
+    __gshared static const(Lstring) zero;	// 0 length string
 
     // No constructors because we want to be able to statically
     // initialize Lstring's, and Lstrings are of variable size.
--- a/dmd/Module.d	Thu Sep 30 12:57:13 2010 +0400
+++ b/dmd/Module.d	Thu Sep 30 13:29:54 2010 +0400
@@ -164,22 +164,6 @@
 
 class Module : Package
 {
-    static Module rootModule;
-    static DsymbolTable modules;	// symbol table of all modules
-    static Array amodules;		// array of all modules
-    static Array deferred;	// deferred Dsymbol's needing semantic() run on them
-    static uint dprogress;	// progress resolving the deferred list
-
-    static void init()
-	{
-		modules = new DsymbolTable();
-		amodules = new Array();
-		deferred = new Array();
-	}
-
-    static ClassDeclaration moduleinfo;
-
-
     string arg;	// original argument name
     ModuleDeclaration md; // if !null, the contents of the ModuleDeclaration declaration
     File srcfile;	// input source file
@@ -687,7 +671,7 @@
 		}
 		else
 		{
-			dst = modules;
+			dst = global.modules;
 
 			/* Check to see if module name is a valid identifier
 			 */
@@ -705,7 +689,7 @@
 			}
 			else
 			{
-				amodules.push(cast(void*)this);
+				global.amodules.push(cast(void*)this);
 			}
 		}
 	}
@@ -823,6 +807,7 @@
 	
     void semantic2()	// pass 2 semantic analysis
 	{
+		auto deferred = global.deferred;
 		if (deferred.dim)
 		{
 			for (int i = 0; i < deferred.dim; i++)
@@ -1282,6 +1267,7 @@
 	 */
 	void addDeferredSemantic(Dsymbol s)
 	{
+		auto deferred = global.deferred;
 	    // Don't add it if it is already there
 	    for (int i = 0; i < deferred.dim; i++)
 	    {
@@ -1309,9 +1295,11 @@
 		//if (deferred.dim) printf("+Module.runDeferredSemantic('%s'), len = %d\n", toChars(), deferred.dim);
 		nested++;
 
+		auto deferred = global.deferred;
+		
 		do
 		{
-			dprogress = 0;
+			global.dprogress = 0;
 			len = deferred.dim;
 			if (!len)
 				break;
@@ -1341,7 +1329,7 @@
 				//printf("deferred: %s, parent = %s\n", s.toChars(), s.parent.toChars());
 			}
 			//printf("\tdeferred.dim = %d, len = %d, dprogress = %d\n", deferred.dim, len, dprogress);
-		} while (deferred.dim < len || dprogress);	// while making progress
+		} while (deferred.dim < len || global.dprogress);	// while making progress
 		nested--;
 		//printf("-Module.runDeferredSemantic('%s'), len = %d\n", toChars(), deferred.dim);
 	}
@@ -1566,8 +1554,8 @@
 		 */
 		dt_t* dt = null;
 
-		if (moduleinfo)
-			dtxoff(&dt, moduleinfo.toVtblSymbol(), 0, TYM.TYnptr); // vtbl for ModuleInfo
+		if (global.moduleinfo)
+			dtxoff(&dt, global.moduleinfo.toVtblSymbol(), 0, TYM.TYnptr); // vtbl for ModuleInfo
 		else
 		{	
 			//printf("moduleinfo is null\n");
--- a/dmd/ModuleInfoDeclaration.d	Thu Sep 30 12:57:13 2010 +0400
+++ b/dmd/ModuleInfoDeclaration.d	Thu Sep 30 13:29:54 2010 +0400
@@ -3,6 +3,7 @@
 import dmd.common;
 import dmd.VarDeclaration;
 import dmd.Module;
+import dmd.Global;
 import dmd.OutBuffer;
 import dmd.Dsymbol;
 import dmd.Scope;
@@ -16,7 +17,7 @@
 
 	this(Module mod)
 	{
-		super(Loc(0), Module.moduleinfo.type, mod.ident, null);
+		super(Loc(0), global.moduleinfo.type, mod.ident, null);
 	}
 	
 	override Dsymbol syntaxCopy(Dsymbol)
--- a/dmd/Package.d	Thu Sep 30 12:57:13 2010 +0400
+++ b/dmd/Package.d	Thu Sep 30 13:29:54 2010 +0400
@@ -8,6 +8,7 @@
 import dmd.Scope;
 import dmd.Dsymbol;
 import dmd.Module;
+import dmd.Global;
 import dmd.Util;
 
 class Package : ScopeDsymbol
@@ -24,7 +25,7 @@
 
     static DsymbolTable resolve(Identifiers packages, Dsymbol* pparent, Package* ppkg)
 	{
-		DsymbolTable dst = Module.modules;
+		DsymbolTable dst = global.modules;
 		Dsymbol parent = null;
 
 		//printf("Package::resolve()\n");
--- a/dmd/PowExp.d	Thu Sep 30 12:57:13 2010 +0400
+++ b/dmd/PowExp.d	Thu Sep 30 13:29:54 2010 +0400
@@ -15,6 +15,7 @@
 import dmd.CommaExp;
 import dmd.AndExp;
 import dmd.CondExp;
+import dmd.Global;
 import dmd.IntegerExp;
 import dmd.Type;
 import dmd.Lexer;
@@ -112,9 +113,10 @@
 	        if (!importMathChecked)
 	        {
 	            importMathChecked = 1;
-	            for (int i = 0; i < Module.amodules.dim; i++)
+				auto amodules = global.amodules;
+	            for (int i = 0; i < amodules.dim; i++)
 	            {
-                    auto mi = cast(Module)Module.amodules.data[i];
+                    auto mi = cast(Module)amodules.data[i];
 		            //printf("\t[%d] %s\n", i, mi->toChars());
 		            if (mi.ident == Id.math &&
 		                mi.parent.ident == Id.std &&
--- a/dmd/StructDeclaration.d	Thu Sep 30 12:57:13 2010 +0400
+++ b/dmd/StructDeclaration.d	Thu Sep 30 13:29:54 2010 +0400
@@ -389,7 +389,7 @@
 		structsize = (structsize + alignsize - 1) & ~(alignsize - 1);
 
 		sizeok = 1;
-		Module.dprogress++;
+		global.dprogress++;
 
 		//printf("-StructDeclaration.semantic(this=%p, '%s')\n", this, toChars());
 
--- a/dmd/TemplateInstance.d	Thu Sep 30 12:57:13 2010 +0400
+++ b/dmd/TemplateInstance.d	Thu Sep 30 13:29:54 2010 +0400
@@ -609,9 +609,10 @@
 		 * on them due to forward references, we cannot run semantic2()
 		 * or semantic3() yet.
 		 */
-		for (size_t i = 0; i < Module.deferred.dim; i++)
+		auto deferred = global.deferred;
+		for (size_t i = 0; i < deferred.dim; i++)
 		{	
-			Dsymbol sd = cast(Dsymbol)Module.deferred.data[i];
+			Dsymbol sd = cast(Dsymbol)deferred.data[i];
 
 			if (sd.parent is this)
 				goto Laftersemantic;
--- a/main.d	Thu Sep 30 12:57:13 2010 +0400
+++ b/main.d	Thu Sep 30 13:29:54 2010 +0400
@@ -775,7 +775,6 @@
     // Initialization
     Type.init();
     Id.initialize();
-    Module.init();
     initPrecedence();
 
     backend_init();
@@ -965,8 +964,8 @@
         m = cast(Module)modules.data[i];
         if (global.params.verbose)
             writef("parse     %s\n", m.toChars());
-        if (!Module.rootModule)
-            Module.rootModule = m;
+        if (!global.rootModule)
+            global.rootModule = m;
         m.importedFrom = m;
         if (!global.params.oneobj || i == 0 || m.isDocFile)
             m.deleteObjFile();
@@ -1101,9 +1100,9 @@
         {
             // Do pass 3 semantic analysis on all imported modules,
             // since otherwise functions in them cannot be inlined
-            for (int i = 0; i < Module.amodules.dim; i++)
+            for (int i = 0; i < global.amodules.dim; i++)
             {
-                m = cast(Module)Module.amodules.data[i];
+                m = cast(Module)global.amodules.data[i];
                 if (global.params.verbose)
                     writef("semantic3 %s\n", m.toChars());
                 m.semantic3();