diff lwcc/preproc.c @ 297:310df72c641d ccdev

Handle () surrounding macro args on invocation
author William Astle <lost@l-w.ca>
date Sat, 14 Sep 2013 21:27:03 -0600
parents 83fcc1ed6ad6
children 6112c67728ba
line wrap: on
line diff
--- a/lwcc/preproc.c	Sat Sep 14 20:04:38 2013 -0600
+++ b/lwcc/preproc.c	Sat Sep 14 21:27:03 2013 -0600
@@ -774,7 +774,8 @@
 	struct expand_e *e;
 	struct token **exparglist = NULL;
 	int i;
-	
+	int pcount;
+		
 	s = symtab_find(pp, mname);
 	if (!s)
 		return 0;
@@ -827,6 +828,7 @@
 	
 	while (t -> ttype != TOK_CPAREN)
 	{
+		pcount = 0;
 		if (t -> ttype == TOK_EOF)
 		{
 			preproc_throw_error(pp, "Unexpected EOF in macro call");
@@ -834,7 +836,11 @@
 		}
 		if (t -> ttype == TOK_EOL)
 			continue;
-		if (t -> ttype == TOK_COMMA)
+		if (t -> ttype == TOK_OPAREN)
+			pcount++;
+		else if (t -> ttype == TOK_CPAREN && pcount)
+			pcount--;
+		if (t -> ttype == TOK_COMMA && pcount == 0)
 		{
 			if (!(s -> vargs) || (nargs > s -> nargs))
 			{