changeset 168:ceed63f310fb

stringtable, stringbuffer and freelist moved to Global
author korDen
date Thu, 30 Sep 2010 12:57:13 +0400
parents 50a6d232176c
children e7769d53e750
files dmd/Global.d dmd/Identifier.d dmd/Lexer.d
diffstat 3 files changed, 42 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/dmd/Global.d	Thu Sep 30 12:13:49 2010 +0400
+++ b/dmd/Global.d	Thu Sep 30 12:57:13 2010 +0400
@@ -5,6 +5,9 @@
 import dmd.Param;
 import dmd.ClassDeclaration;
 import dmd.DsymbolTable;
+import dmd.StringTable;
+import dmd.OutBuffer;
+import dmd.Token;
 
 class Global
 {
@@ -53,10 +56,23 @@
 	// Used in FuncDeclaration.genCfunc()
 	DsymbolTable st;
 	
+	// Used in Lexer.uniqueId()
+	int num;
+	
+	// Used in Identifier.generateId()
+	size_t i;
+	
+	// Used in Lexer
+	StringTable stringtable;
+    OutBuffer stringbuffer;
+    Token* freelist;
+	
 	this()
 	{
 		params.versionids = new Array();
 		st = new DsymbolTable();
+		stringtable = new StringTable();
+		stringbuffer = new OutBuffer();
 	}
 }
 
--- a/dmd/Identifier.d	Thu Sep 30 12:13:49 2010 +0400
+++ b/dmd/Identifier.d	Thu Sep 30 12:57:13 2010 +0400
@@ -4,10 +4,9 @@
 import dmd.TOK;
 import dmd.DYNCAST;
 import dmd.Lexer;
+import dmd.Global;
 import dmd.OutBuffer;
 
-import std.stdio : writef;
-
 class Identifier
 {
     TOK value;
@@ -21,7 +20,15 @@
 	
     bool equals(Object o)
 	{
-		return this is o || string_ == (cast(Identifier)o).toChars();		/// hack
+		if (this is o) {
+			return true;
+		}
+		
+		if (auto i = cast(Identifier)o) {
+			return string_ == i.string_;
+		}
+		
+		return false;
 	}
 	
     hash_t hashCode()
@@ -63,8 +70,7 @@
 	// BUG: these are redundant with Lexer::uniqueId()
     static Identifier generateId(string prefix)
 	{
-		static size_t i;
-		return generateId(prefix, ++i);
+		return generateId(prefix, ++global.i);
 	}
 	
     static Identifier generateId(string prefix, size_t i)
--- a/dmd/Lexer.d	Thu Sep 30 12:13:49 2010 +0400
+++ b/dmd/Lexer.d	Thu Sep 30 12:57:13 2010 +0400
@@ -37,7 +37,7 @@
 
 bool isUniAlpha(uint u)
 {
-	static ushort table[][2] =
+	enum ushort table[][2] =
     [
 		[ 0x00AA, 0x00AA ],
 		[ 0x00B5, 0x00B5 ],
@@ -344,10 +344,6 @@
 
 class Lexer
 {
-    static StringTable stringtable;
-    static OutBuffer stringbuffer;
-    static Token* freelist;
-
     Loc loc;			// for error messages
 
     ubyte* base;	// pointer to start of buffer
@@ -358,17 +354,6 @@
     int doDocComment;		// collect doc comment information
     int anyToken;		// !=0 means seen at least one token
     int commentToken;		// !=0 means comments are TOKcomment's
-	
-	static this()
-	{
-		stringtable = new StringTable();
-		stringbuffer = new OutBuffer();
-	}
-	
-	static ~this()
-	{
-		//delete stringtable;
-	}
 
     this(Module mod, ubyte* base, uint begoffset, uint endoffset, int doDocComment, int commentToken)
 	{
@@ -692,7 +677,17 @@
 				cmtable[c] |= CMidchar;
 		}
 	}
-
+	
+	static StringTable stringtable()
+	{
+		return global.stringtable;
+	}
+	
+	static OutBuffer stringbuffer()
+	{
+		return global.stringbuffer;
+	}
+	
     static void initKeywords()
 	{
 		uint nkeywords = keywords.length;
@@ -838,8 +833,7 @@
 
     static Identifier uniqueId(string s)
 	{
-		static int num;
-		return uniqueId(s, ++num);
+		return uniqueId(s, ++global.num);
 	}
 
 	/*********************************************
@@ -864,8 +858,8 @@
 		{
 			t = token.next;
 			memcpy(&token, t, Token.sizeof);
-			t.next = freelist;
-			freelist = t;
+			t.next = global.freelist;
+			global.freelist = t;
 		}
 		else
 		{