diff lwcc/lex.c @ 305:54f213c8fb81 ccdev

Various bugfixes and output tuning Tuned output of preprocessor to include line markers similar to the ones added by the gcc preprocessor. Also, many fixes for various bits of dumbosity leading to misbehaviour and crashing.
author William Astle <lost@l-w.ca>
date Wed, 18 Sep 2013 19:17:52 -0600
parents d85d173ba120
children b08787e5b9f3
line wrap: on
line diff
--- a/lwcc/lex.c	Tue Sep 17 19:33:41 2013 -0600
+++ b/lwcc/lex.c	Wed Sep 18 19:17:52 2013 -0600
@@ -191,7 +191,7 @@
    by fetch_byte(). Theoretically, an unlimited number of characters can
    be unfetched. Line and column counting may be incorrect if unfetched
    characters cross a token boundary. */
-static void preproc_lex_unfetch_byte(struct preproc_info *pp, int c)
+void preproc_lex_unfetch_byte(struct preproc_info *pp, int c)
 {
 	if (pp -> ungetbufl >= pp -> ungetbufs)
 	{
@@ -275,7 +275,7 @@
 */
 
 
-static int preproc_lex_fetch_byte(struct preproc_info *pp)
+int preproc_lex_fetch_byte(struct preproc_info *pp)
 {
 	int c;
 	c = fetch_byte(pp);
@@ -318,7 +318,7 @@
 			for (;;)
 			{
 				c2 = fetch_byte(pp);
-				if (c2 == CPP_EOL || c2 == CPP_EOF)
+				if (c2 == CPP_EOF)
 				{
 					preproc_lex_unfetch_byte(pp, c);
 					break;
@@ -362,6 +362,12 @@
 			c = CPP_EOL;
 		}
 	}
+
+	if (pp -> lineno != sline)
+	{
+		sline = pp -> lineno;
+		scol = pp -> column;
+	}
 	
 	if (c == CPP_EOF)
 	{
@@ -639,6 +645,7 @@
 strlit:
 		/* string literal */
 		strbuf = strbuf_new();
+		strbuf_add(strbuf, '"');
 		for (;;)
 		{
 			c = preproc_lex_fetch_byte(pp);
@@ -670,6 +677,7 @@
 			}
 			strbuf_add(strbuf, c);
 		}
+		strbuf_add(strbuf, '"');
 		strval = strbuf_end(strbuf);
 		ttype = TOK_STR_LIT;
 		goto out;