comparison 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
comparison
equal deleted inserted replaced
304:d85d173ba120 305:54f213c8fb81
72 } 72 }
73 73
74 void symtab_define(struct preproc_info *pp, char *name, struct token_list *def, int nargs, char **params, int vargs) 74 void symtab_define(struct preproc_info *pp, char *name, struct token_list *def, int nargs, char **params, int vargs)
75 { 75 {
76 struct symtab_e *s; 76 struct symtab_e *s;
77 77 int i;
78
78 s = lw_alloc(sizeof(struct symtab_e)); 79 s = lw_alloc(sizeof(struct symtab_e));
79 s -> name = lw_strdup(name); 80 s -> name = lw_strdup(name);
80 s -> tl = def; 81 s -> tl = def;
81 s -> nargs = nargs; 82 s -> nargs = nargs;
82 s -> params = params; 83 s -> params = NULL;
84 if (params)
85 {
86 s -> params = lw_alloc(sizeof(char *) * nargs);
87 for (i = 0; i < nargs; i++)
88 s -> params[i] = lw_strdup(params[i]);
89 }
83 s -> vargs = vargs; 90 s -> vargs = vargs;
84 s -> next = pp -> sh; 91 s -> next = pp -> sh;
85 pp -> sh = s; 92 pp -> sh = s;
86 } 93 }
94
95 void symtab_dump(struct preproc_info *pp)
96 {
97 struct symtab_e *s;
98 struct token *t;
99 int i;
100
101 for (s = pp -> sh; s; s = s -> next)
102 {
103 printf("%s", s -> name);
104 if (s -> nargs >= 0)
105 {
106 printf("(");
107 for (i = 0; i < s -> nargs; i++)
108 {
109 if (i)
110 printf(",");
111 printf("%s", s -> params[i]);
112 }
113 if (s -> vargs)
114 {
115 if (s -> nargs)
116 printf(",");
117 printf("...");
118 }
119 printf(")");
120 }
121 printf(" => ");
122 if (s -> tl)
123 {
124 for (t = s -> tl -> head; t; t = t -> next)
125 {
126 token_print(t, stdout);
127 }
128 }
129 printf("\n");
130 }
131 }