diff lwcc/lex.c @ 299:856caf91ffaa ccdev

Added token list structure and switched some stuff to use it Swithced to using a token list structure instead of manually fiddling pointers throughout the macro expansion code. Also fixed up some problematic things related to stringification and concatenation.
author William Astle <lost@l-w.ca>
date Sun, 15 Sep 2013 13:06:00 -0600
parents 6112c67728ba
children 8d6c47395653
line wrap: on
line diff
--- a/lwcc/lex.c	Sat Sep 14 22:42:53 2013 -0600
+++ b/lwcc/lex.c	Sun Sep 15 13:06:00 2013 -0600
@@ -596,7 +596,9 @@
 				{
 					if (!pp -> lexstr)
 						preproc_throw_error(pp, "Invalid character constant");
-					break;
+					ttype = TOK_ERROR;
+					strval = strbuf_end(strbuf);
+					goto out;
 				}
 				cl++;
 				strbuf_add(strbuf, c);
@@ -604,10 +606,15 @@
 			}
 			strbuf_add(strbuf, c);
 		}
-		if (cl == 0 && !pp -> lexstr)
-			preproc_throw_error(pp, "Invalid character constant");
 		strval = strbuf_end(strbuf);
-		ttype = TOK_CHR_LIT;
+		if (cl == 0)
+		{
+			ttype = TOK_ERROR;
+			if (!pp -> lexstr)
+				preproc_throw_error(pp, "Invalid character constant");
+		}
+		else
+			ttype = TOK_CHR_LIT;
 		goto out;
 
 	case '"':
@@ -617,7 +624,15 @@
 		for (;;)
 		{
 			c = preproc_lex_fetch_byte(pp);
-			if (c == CPP_EOF || c == CPP_EOL || c == '"')
+			if (c == CPP_EOF || c == CPP_EOL)
+			{
+				ttype = TOK_ERROR;
+				strval = strbuf_end(strbuf);
+				if (!pp -> lexstr)
+					preproc_throw_error(pp, "Invalid string constant");
+				goto out;
+			}
+			if (c == '"')
 				break;
 			if (c == '\\')
 			{
@@ -625,9 +640,11 @@
 				c = preproc_lex_fetch_byte(pp);
 				if (c == CPP_EOF || c == CPP_EOL)
 				{
+					ttype = TOK_ERROR;
 					if (!pp -> lexstr)
 						preproc_throw_error(pp, "Invalid string constant");
-					break;
+					strval = strbuf_end(strbuf);
+					goto out;
 				}
 				cl++;
 				strbuf_add(strbuf, c);