diff lwcc/symbol.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 856caf91ffaa
children
line wrap: on
line diff
--- a/lwcc/symbol.c	Tue Sep 17 19:33:41 2013 -0600
+++ b/lwcc/symbol.c	Wed Sep 18 19:17:52 2013 -0600
@@ -74,13 +74,58 @@
 void symtab_define(struct preproc_info *pp, char *name, struct token_list *def, int nargs, char **params, int vargs)
 {
 	struct symtab_e *s;
-	
+	int i;
+		
 	s = lw_alloc(sizeof(struct symtab_e));
 	s -> name = lw_strdup(name);
 	s -> tl = def;
 	s -> nargs = nargs;
-	s -> params = params;
+	s -> params = NULL;
+	if (params)
+	{
+		s -> params = lw_alloc(sizeof(char *) * nargs);
+		for (i = 0; i < nargs; i++)
+			s -> params[i] = lw_strdup(params[i]);
+	}
 	s -> vargs = vargs;
 	s -> next = pp -> sh;
 	pp -> sh = s;
 }
+
+void symtab_dump(struct preproc_info *pp)
+{
+	struct symtab_e *s;
+	struct token *t;
+	int i;
+		
+	for (s = pp -> sh; s; s = s -> next)
+	{
+		printf("%s", s -> name);
+		if (s -> nargs >= 0)
+		{
+			printf("(");
+			for (i = 0; i < s -> nargs; i++)
+			{
+				if (i)
+					printf(",");
+				printf("%s", s -> params[i]);
+			}
+			if (s -> vargs)
+			{
+				if (s -> nargs)
+					printf(",");
+				printf("...");
+			}
+			printf(")");
+		}
+		printf(" => ");
+		if (s -> tl)
+		{
+			for (t = s -> tl -> head; t; t = t -> next)
+			{
+				token_print(t, stdout);
+			}
+		}
+		printf("\n");
+	}
+}