diff dmd/Lexer.d @ 178:e3afd1303184

Many small bugs fixed Made all classes derive from TObject to detect memory leaks (functionality is disabled for now) Began work on overriding backend memory allocations (to avoid memory leaks)
author korDen
date Sun, 17 Oct 2010 07:42:00 +0400
parents 94b6033c07f3
children
line wrap: on
line diff
--- a/dmd/Lexer.d	Sun Oct 10 10:38:55 2010 +0400
+++ b/dmd/Lexer.d	Sun Oct 17 07:42:00 2010 +0400
@@ -340,7 +340,9 @@
 	return true;
 }
 
-class Lexer
+import dmd.TObject;
+
+class Lexer : TObject
 {
     Loc loc;			// for error messages
 
@@ -355,8 +357,9 @@
 
     this(Module mod, ubyte* base, uint begoffset, uint endoffset, int doDocComment, int commentToken)
 	{
+		register();
 		loc = Loc(mod, 1);
-		
+
 		memset(&token,0,token.sizeof);
 		this.base = base;
 		this.end  = base + endoffset;
@@ -374,7 +377,7 @@
 		{
 			p += 2;
 			while (1)
-			{  
+			{
 				ubyte c = *p;
 				switch (c)
 				{
@@ -658,7 +661,7 @@
 	enum CMoctal =	0x1;
 	enum  CMhex =	0x2;
 	enum  CMidchar =	0x4;
-	
+
 	ubyte isoctal (ubyte c) { return cmtable[c] & CMoctal; }
 	ubyte ishex   (ubyte c) { return cmtable[c] & CMhex; }
 	ubyte isidchar(ubyte c) { return cmtable[c] & CMidchar; }
@@ -675,17 +678,17 @@
 				cmtable[c] |= CMidchar;
 		}
 	}
-	
-	static StringTable stringtable()
+
+	static ref StringTable stringtable()
 	{
 		return global.stringtable;
 	}
-	
+
 	static OutBuffer stringbuffer()
 	{
 		return global.stringbuffer;
 	}
-	
+
     static void initKeywords()
 	{
 		uint nkeywords = keywords.length;
@@ -694,14 +697,14 @@
 			nkeywords -= 2;
 
 		cmtable_init();
-		
+
 		for (uint u = 0; u < nkeywords; u++)
 		{
 			//printf("keyword[%d] = '%.*s'\n",u, keywords[u].name);
 			string s = keywords[u].name;
 			TOK v = keywords[u].value;
-			StringValue* sv = stringtable.insert(s);
-			sv.ptrvalue = cast(void*) new Identifier(sv.lstring.string_, v);
+			Object* sv = stringtable.insert(s);
+			*sv = new Identifier(s, v);
 
 			//printf("tochars[%d] = '%s'\n",v, s);
 			Token.tochars[v] = s;
@@ -794,7 +797,7 @@
 		Token.tochars[TOK.TOKat]		= "@";
         Token.tochars[TOK.TOKpow]		= "^^";
         Token.tochars[TOK.TOKpowass]		= "^^=";
-        
+
 		 // For debugging
 		Token.tochars[TOKerror]		= "error";
 		Token.tochars[TOK.TOKdotexp]		= "dotexp";
@@ -818,12 +821,12 @@
 
     static Identifier idPool(string s)
 	{
-		StringValue* sv = stringtable.update(s);
-		Identifier id = cast(Identifier) sv.ptrvalue;
+		Object* sv = stringtable.update(s);
+		Identifier id = cast(Identifier) *sv;
 		if (id is null)
 		{
-			id = new Identifier(sv.lstring.string_, TOK.TOKidentifier);
-			sv.ptrvalue = cast(void*)id;
+			id = new Identifier(s, TOK.TOKidentifier);
+			*sv = id;
 		}
 
 		return id;
@@ -1068,12 +1071,14 @@
 		            break;
 		        }
 
-		        StringValue *sv = stringtable.update((cast(immutable(char)*)t.ptr)[0.. p - t.ptr]);
-		        Identifier id = cast(Identifier) sv.ptrvalue;
-                    
+                auto s = cast(string)(t.ptr[0.. p - t.ptr]);
+		        Object* sv = stringtable.update(s);
+		        Identifier id = cast(Identifier) *sv;
+
 				if (id is null)
-				{   id = new Identifier(sv.lstring.string_, TOK.TOKidentifier);
-					sv.ptrvalue = cast(void*)id;
+				{
+				    id = new Identifier(s, TOK.TOKidentifier);
+					*sv = id;
 				}
 				t.ident = id;
 				t.value = cast(TOK) id.value;
@@ -1340,7 +1345,7 @@
 						}
 						continue;
 					}
-					
+
 					default:
 						break;	///
 				}
@@ -1555,7 +1560,7 @@
 				else
 					t.value = TOK.TOKtilde;		// ~
 				return;
-                
+
 version(DMDV2) {
 	    case '^':
 		p++;
@@ -1636,7 +1641,7 @@
 						t.value = TOK.TOKmul;
 					}
 					return;
-					
+
 				case '%':
 					p++;
 					if (*p == '=') {
@@ -1795,7 +1800,7 @@
 				p++;
 				c = *p;
 				if (ishex(cast(ubyte)c))
-				{   
+				{
 					uint v;
 
 					n = 0;
@@ -1835,7 +1840,7 @@
 					case ';':
 						c = HtmlNamedEntity(idstart, p - idstart);
 						if (c == ~0)
-						{   
+						{
 							error("unnamed character entity &%s;", idstart[0..(p - idstart)]);
 							c = ' ';
 						}
@@ -1860,7 +1865,7 @@
 
 			default:
 				if (isoctal(cast(ubyte)c))
-				{   
+				{
 					uint v;
 
 					n = 0;
@@ -1940,7 +1945,7 @@
 			}
 			stringbuffer.writeByte(c);
 		}
-		
+
 		assert(false);
 	}
 
@@ -1986,7 +1991,7 @@
 
 				case '"':
 					if (n & 1)
-					{   
+					{
 						error("odd number (%d) of hex characters in hex string", n);
 						stringbuffer.writeByte(v);
 					}
@@ -2096,7 +2101,7 @@
 					break;
 			}
 			if (delimleft == 0)
-			{   
+			{
 				delimleft = c;
 				nest = 1;
 				nestcount = 1;
@@ -2109,18 +2114,18 @@
 				else if (c == '<')
 					delimright = '>';
 				else if (isalpha(c) || c == '_' || (c >= 0x80 && isUniAlpha(c)))
-				{	
+				{
 					// Start of identifier; must be a heredoc
 					Token t2;
 					p--;
 					scan(&t2);		// read in heredoc identifier
 					if (t2.value != TOKidentifier)
-					{   
+					{
 						error("identifier expected for heredoc, not %s", t2.toChars());
 						delimright = c;
 					}
 					else
-					{   
+					{
 						hereid = t2.ident;
 						//printf("hereid = '%s'\n", hereid.toChars());
 						blankrol = 1;
@@ -2128,7 +2133,7 @@
 					nest = 0;
 				}
 				else
-				{	
+				{
 					delimright = c;
 					nest = 0;
 					if (isspace(c))
@@ -2138,7 +2143,7 @@
 			else
 			{
 				if (blankrol)
-				{	
+				{
 					error("heredoc rest of line should be blank");
 					blankrol = 0;
 					continue;
@@ -2156,14 +2161,14 @@
 				else if (c == delimright)
 					goto Ldone;
 				if (startline && isalpha(c) && hereid)
-				{	
+				{
 					Token t2;
 					ubyte* psave = p;
 					p--;
 					scan(&t2);		// read in possible heredoc identifier
 					//printf("endid = '%s'\n", t2.ident.toChars());
 					if (t2.value == TOKidentifier && t2.ident.equals(hereid))
-					{   
+					{
 						/* should check that rest of line is blank
 						 */
 						goto Ldone;
@@ -2211,7 +2216,7 @@
 		ubyte* pstart = ++p;
 
 		while (true)
-		{	
+		{
 			Token tok;
 
 			scan(&tok);
@@ -2327,7 +2332,7 @@
 			}
 			stringbuffer.writeByte(c);
 		}
-		
+
 		assert(false);
 	}
 
@@ -2391,7 +2396,7 @@
 		}
 
 		if (*p != '\'')
-		{	
+		{
 			error("unterminated character constant");
 			return tk;
 		}
@@ -2423,7 +2428,7 @@
 	{
 		assert(false);
 	}
-	
+
 	/**************************************
 	 * Read in a number.
 	 * If it's an integer, store it in tok.TKutok.Vlong.
@@ -2450,7 +2455,7 @@
 			FLAGS_unsigned = 2,		// u or U suffix
 			FLAGS_long     = 4,		// l or L suffix
 		};
-		
+
 		FLAGS flags = FLAGS.FLAGS_decimal;
 
 		int i;
@@ -2889,7 +2894,7 @@
 					case 9:
 						dblstate = 1;
 						if (c == 'X' || c == 'x')
-						{	
+						{
 							hex++;
 							break;
 						}
@@ -2907,14 +2912,14 @@
 
 					case 2:			// no more digits to left of .
 						if (c == '.')
-						{   
+						{
 							dblstate++;
 							break;
 						}
 					case 4:			// no more digits to right of .
 						if ((c == 'E' || c == 'e') ||
 							hex && (c == 'P' || c == 'p'))
-						{   
+						{
 							dblstate = 5;
 							hex = 0;	// exponent is always decimal
 							break;
@@ -2996,7 +3001,7 @@
 				default:
 			}
 		}
-		
+
 	version (Windows) { ///&& __DMC__
 		__locale_decpoint = save;
 	}
@@ -3027,7 +3032,7 @@
 
 		global.errors++;
 	}
-	
+
 	/*********************************************
 	 * Do pragma.
 	 * Currently, the only pragma supported is:
@@ -3092,7 +3097,7 @@
 					stringbuffer.reset();
 					p++;
 					while (1)
-					{   
+					{
 						uint c;
 
 						c = *p;
@@ -3112,7 +3117,7 @@
 
 							default:
 								if (c & 0x80)
-								{   
+								{
 									uint u = decodeUTF();
 									if (u == PS || u == LS)
 										goto Lerr;
@@ -3127,7 +3132,7 @@
 
 				default:
 					if (*p & 0x80)
-					{   
+					{
 						uint u = decodeUTF();
 						if (u == PS || u == LS)
 							goto Lnewline;
@@ -3306,7 +3311,7 @@
 		//printf("Lexer::combineComments('%s', '%s')\n", c1, c2);
 
 		string c = c2;
-		
+
 		if (c1)
 		{
 			c = c1;
@@ -3357,7 +3362,7 @@
 		//writef("Lexer.combineComments('%s', '%s')\n", c1, c2);
 
 		char[] c = cast(char[]) c2;
-		
+
 		if (c1 !is null)
 		{
 			c = cast(char[]) c1;
@@ -3370,7 +3375,7 @@
 				c[len1 .. len1 + c2.length] = c2[];
 			}
 		}
-		
+
 		return cast(string)c;
 	}
-}
\ No newline at end of file
+}