From 72af804b313e53bbfd6741cfa56701fd5331c811 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sat, 31 Mar 2007 15:27:36 +0000 Subject: [PATCH] nested include reporting --- tools/qfcc/include/expr.h | 4 +-- tools/qfcc/include/qfcc.h | 8 +++++ tools/qfcc/source/expr.c | 16 ++++++++-- tools/qfcc/source/qc-lex.l | 61 +++++++++++++++++++++++++++++++++----- 4 files changed, 77 insertions(+), 12 deletions(-) diff --git a/tools/qfcc/include/expr.h b/tools/qfcc/include/expr.h index b757500f0..73a5fde58 100644 --- a/tools/qfcc/include/expr.h +++ b/tools/qfcc/include/expr.h @@ -227,8 +227,8 @@ expr_t *cast_expr (struct type_s *t, expr_t *e); void init_elements (struct def_s *def, expr_t *eles); expr_t *error (expr_t *e, const char *fmt, ...) __attribute__((format(printf, 2,3))); -void warning (expr_t *e, const char *fmt, ...) __attribute__((format(printf, 2,3))); -void notice (expr_t *e, const char *fmt, ...) __attribute__((format(printf, 2,3))); +expr_t *warning (expr_t *e, const char *fmt, ...) __attribute__((format(printf, 2,3))); +expr_t * notice (expr_t *e, const char *fmt, ...) __attribute__((format(printf, 2,3))); const char *get_op_string (int op); diff --git a/tools/qfcc/include/qfcc.h b/tools/qfcc/include/qfcc.h index 036232e14..849eb5a86 100644 --- a/tools/qfcc/include/qfcc.h +++ b/tools/qfcc/include/qfcc.h @@ -40,6 +40,13 @@ //============================================================================= +typedef struct srcline_s srcline_t; +struct srcline_s { + srcline_t *next; + string_t source_file; + int source_line; +}; + // // output generated by prog parsing // @@ -61,6 +68,7 @@ typedef struct pr_info_s { struct defspace_s *entity_data; struct scope_s *scope; + srcline_t *srcline_stack; string_t source_file; int source_line; int error_count; diff --git a/tools/qfcc/source/expr.c b/tools/qfcc/source/expr.c index 4ae2feca4..eaf48d9ae 100644 --- a/tools/qfcc/source/expr.c +++ b/tools/qfcc/source/expr.c @@ -2766,11 +2766,19 @@ static void report_function (expr_t *e) { static function_t *last_func = (function_t *)-1L; + static string_t last_file; string_t file = pr.source_file; + srcline_t *srcline; if (e) file = e->file; + if (file != last_file) { + for (srcline = pr.srcline_stack; srcline; srcline = srcline->next) + fprintf (stderr, "In file included from %s:%d:\n", + G_GETSTR (srcline->source_file), srcline->source_line); + } + last_file = file; if (current_func != last_func) { if (current_func) { fprintf (stderr, "%s: In function `%s':\n", G_GETSTR (file), @@ -2804,13 +2812,13 @@ _warning (expr_t *e, const char *fmt, va_list args) fputs ("\n", stderr); } -void +expr_t * notice (expr_t *e, const char *fmt, ...) { va_list args; if (options.notices.silent) - return; + return e; va_start (args, fmt); if (options.notices.promote) { @@ -2829,9 +2837,10 @@ notice (expr_t *e, const char *fmt, ...) fputs ("\n", stderr); } va_end (args); + return e; } -void +expr_t * warning (expr_t *e, const char *fmt, ...) { va_list args; @@ -2839,6 +2848,7 @@ warning (expr_t *e, const char *fmt, ...) va_start (args, fmt); _warning (e, fmt, args); va_end (args); + return e; } expr_t * diff --git a/tools/qfcc/source/qc-lex.l b/tools/qfcc/source/qc-lex.l index 576e22a1d..503149b07 100644 --- a/tools/qfcc/source/qc-lex.l +++ b/tools/qfcc/source/qc-lex.l @@ -85,7 +85,10 @@ int do_grab (char *token); void add_frame_macro (char *token); -const char *make_string (char *token); +const char *make_string (char *token, char **end); + +void push_source_file (void); +void pop_source_file (void); extern YYSTYPE yylval; @@ -148,7 +151,7 @@ m ([\-+]?) @ return '@'; \"(\\.|[^"\\])*\" { - yylval.string_val = make_string (yytext); + yylval.string_val = make_string (yytext, 0); return STRING_VAL; } @@ -169,7 +172,7 @@ m ([\-+]?) } '(\\[^xX0-7\r\n]|[^'\r\n]|\\[xX][0-9A-Fa-f]+|\\[0-7]+)*' { - const char *str = make_string (yytext); + const char *str = make_string (yytext, 0); if (str[1]) warning (0, "multibyte char constant"); @@ -184,7 +187,8 @@ m ([\-+]?) char *s; const char *str; int line; - + int flags; + p = yytext + 1; line = strtol (p, &s, 10); p = s; @@ -192,8 +196,20 @@ m ([\-+]?) p++; if (!*p) error (0, "Unexpected end of file"); - str = make_string (p); // grab the filename - while (*p && *p != '\n') // ignore flags + str = make_string (p, &s); // grab the filename + p = s; + while (isspace ((unsigned char)*p)) + p++; + flags = strtol (p, &s, 10); + switch (flags) { + case 1: + push_source_file (); + break; + case 2: + pop_source_file (); + break; + } + while (*p && *p != '\n') // ignore rest p++; pr.source_line = line - 1; pr.source_file = ReuseString (strip_path (str)); @@ -475,7 +491,7 @@ clear_frame_macros (void) } const char * -make_string (char *token) +make_string (char *token, char **end) { char s[2]; int c; @@ -637,9 +653,40 @@ make_string (char *token) dstring_appendstr (str, s); } while (1); + if (end) + *end = token; + return save_string (str->str); } +static srcline_t *free_srclines; + +void +push_source_file (void) +{ + srcline_t *srcline; + ALLOC (16, srcline_t, srclines, srcline); + srcline->source_file = pr.source_file; + srcline->source_line = pr.source_line; + srcline->next = pr.srcline_stack; + pr.srcline_stack = srcline; +} + +void +pop_source_file (void) +{ + srcline_t *tmp; + + if (!pr.srcline_stack) { + notice (0, "unbalanced #includes. bug in preprocessor?"); + return; + } + tmp = pr.srcline_stack; + pr.srcline_stack = tmp->next; + tmp->next = free_srclines; + free_srclines = tmp; +} + #ifdef YY_FLEX_REALLOC_HACK static __attribute__ ((unused)) void *(*const yy_flex_realloc_hack)(void *,yy_size_t) = yy_flex_realloc; #else