Mercurial > hg > index.cgi
diff 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 |
line wrap: on
line diff
--- a/lwcc/cpp.c Tue Sep 17 19:33:41 2013 -0600 +++ b/lwcc/cpp.c Wed Sep 18 19:17:52 2013 -0600 @@ -54,7 +54,10 @@ pp -> fn = strpool_strdup(pp -> strpool, fn); pp -> fp = fp; pp -> ra = CPP_NOUNG; + pp -> unget = CPP_NOUNG; pp -> ppeolseen = 1; + pp -> lineno = 1; + pp -> n = NULL; return pp; } @@ -146,14 +149,16 @@ fprintf(stderr, "WARNING: %s\n", m); } -static void preproc_throw_message(void (*cb)(const char *), const char *m, va_list args) +static void preproc_throw_message(struct preproc_info *pp, void (*cb)(const char *), const char *m, va_list args) { - int s; + int s, s2; char *b; + s2 = snprintf(NULL, 0, "(%s:%d:%d) ", pp -> fn, pp -> lineno, pp -> column); s = vsnprintf(NULL, 0, m, args); - b = lw_alloc(s + 1); - vsnprintf(b, s + 1, m, args); + b = lw_alloc(s + s2 + 1); + snprintf(b, s2 + 1, "(%s:%d:%d) ", pp -> fn, pp -> lineno, pp -> column); + vsnprintf(b + s2, s + 1, m, args); (*cb)(b); lw_free(b); } @@ -162,7 +167,7 @@ { va_list args; va_start(args, m); - preproc_throw_message(pp -> errorcb ? pp -> errorcb : preproc_throw_error_default, m, args); + preproc_throw_message(pp, pp -> errorcb ? pp -> errorcb : preproc_throw_error_default, m, args); va_end(args); exit(1); } @@ -171,6 +176,6 @@ { va_list args; va_start(args, m); - preproc_throw_message(pp -> warningcb ? pp -> warningcb : preproc_throw_warning_default, m, args); + preproc_throw_message(pp, pp -> warningcb ? pp -> warningcb : preproc_throw_warning_default, m, args); va_end(args); }