comparison lwcc/cpp.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
comparison
equal deleted inserted replaced
304:d85d173ba120 305:54f213c8fb81
52 memset(pp, 0, sizeof(struct preproc_info)); 52 memset(pp, 0, sizeof(struct preproc_info));
53 pp -> strpool = strpool_create(); 53 pp -> strpool = strpool_create();
54 pp -> fn = strpool_strdup(pp -> strpool, fn); 54 pp -> fn = strpool_strdup(pp -> strpool, fn);
55 pp -> fp = fp; 55 pp -> fp = fp;
56 pp -> ra = CPP_NOUNG; 56 pp -> ra = CPP_NOUNG;
57 pp -> unget = CPP_NOUNG;
57 pp -> ppeolseen = 1; 58 pp -> ppeolseen = 1;
59 pp -> lineno = 1;
60 pp -> n = NULL;
58 return pp; 61 return pp;
59 } 62 }
60 63
61 struct token *preproc_next_token(struct preproc_info *pp) 64 struct token *preproc_next_token(struct preproc_info *pp)
62 { 65 {
144 static void preproc_throw_warning_default(const char *m) 147 static void preproc_throw_warning_default(const char *m)
145 { 148 {
146 fprintf(stderr, "WARNING: %s\n", m); 149 fprintf(stderr, "WARNING: %s\n", m);
147 } 150 }
148 151
149 static void preproc_throw_message(void (*cb)(const char *), const char *m, va_list args) 152 static void preproc_throw_message(struct preproc_info *pp, void (*cb)(const char *), const char *m, va_list args)
150 { 153 {
151 int s; 154 int s, s2;
152 char *b; 155 char *b;
153 156
157 s2 = snprintf(NULL, 0, "(%s:%d:%d) ", pp -> fn, pp -> lineno, pp -> column);
154 s = vsnprintf(NULL, 0, m, args); 158 s = vsnprintf(NULL, 0, m, args);
155 b = lw_alloc(s + 1); 159 b = lw_alloc(s + s2 + 1);
156 vsnprintf(b, s + 1, m, args); 160 snprintf(b, s2 + 1, "(%s:%d:%d) ", pp -> fn, pp -> lineno, pp -> column);
161 vsnprintf(b + s2, s + 1, m, args);
157 (*cb)(b); 162 (*cb)(b);
158 lw_free(b); 163 lw_free(b);
159 } 164 }
160 165
161 void preproc_throw_error(struct preproc_info *pp, const char *m, ...) 166 void preproc_throw_error(struct preproc_info *pp, const char *m, ...)
162 { 167 {
163 va_list args; 168 va_list args;
164 va_start(args, m); 169 va_start(args, m);
165 preproc_throw_message(pp -> errorcb ? pp -> errorcb : preproc_throw_error_default, m, args); 170 preproc_throw_message(pp, pp -> errorcb ? pp -> errorcb : preproc_throw_error_default, m, args);
166 va_end(args); 171 va_end(args);
167 exit(1); 172 exit(1);
168 } 173 }
169 174
170 void preproc_throw_warning(struct preproc_info *pp, const char *m, ...) 175 void preproc_throw_warning(struct preproc_info *pp, const char *m, ...)
171 { 176 {
172 va_list args; 177 va_list args;
173 va_start(args, m); 178 va_start(args, m);
174 preproc_throw_message(pp -> warningcb ? pp -> warningcb : preproc_throw_warning_default, m, args); 179 preproc_throw_message(pp, pp -> warningcb ? pp -> warningcb : preproc_throw_warning_default, m, args);
175 va_end(args); 180 va_end(args);
176 } 181 }