From: Dale Weiler Date: Thu, 3 Jan 2013 12:04:32 +0000 (+0000) Subject: Add specialized diagnostics for when predefined macros are used and ftepp predefined... X-Git-Tag: before-library~377 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=9bda8f61f403620c4e39e3b7e175ba3d1d09d8c9;p=xonotic%2Fgmqcc.git Add specialized diagnostics for when predefined macros are used and ftepp predefined macros are not enabled. --- diff --git a/ftepp.c b/ftepp.c index 436b05b..ea68661 100644 --- a/ftepp.c +++ b/ftepp.c @@ -70,11 +70,6 @@ typedef struct { char *includename; } ftepp_t; -typedef struct { - const char *name; - char *(*func)(lex_file *); -} predef_t; - /* * Implement the predef subsystem now. We can do this safely with the * help of lexer contexts. @@ -168,7 +163,7 @@ char *ftepp_predef_randomlast(lex_file *context) { return value; } -static const predef_t ftepp_predefs[] = { +const ftepp_predef_t ftepp_predefs[FTEPP_PREDEF_COUNT] = { { "__LINE__", &ftepp_predef_line }, { "__FILE__", &ftepp_predef_file }, { "__COUNTER__", &ftepp_predef_counter }, diff --git a/gmqcc.h b/gmqcc.h index 0bfe7ce..36a67fd 100644 --- a/gmqcc.h +++ b/gmqcc.h @@ -963,6 +963,18 @@ void parser_cleanup (); /*===================================================================*/ /*====================== ftepp.c commandline ========================*/ /*===================================================================*/ +struct lex_file_s; +typedef struct { + const char *name; + char *(*func)(struct lex_file_s *); +} ftepp_predef_t; + +/* + * line, file, counter, counter_last, random, random_last, date, time + * increment when items are added + */ +#define FTEPP_PREDEF_COUNT 8 + bool ftepp_init (); bool ftepp_preprocess_file (const char *filename); bool ftepp_preprocess_string(const char *name, const char *str); @@ -972,6 +984,8 @@ void ftepp_flush (); void ftepp_add_define (const char *source, const char *name); void ftepp_add_macro (const char *name, const char *value); +extern const ftepp_predef_t ftepp_predefs[FTEPP_PREDEF_COUNT]; + /*===================================================================*/ /*======================= main.c commandline ========================*/ /*===================================================================*/ diff --git a/lexer.h b/lexer.h index 919dbec..5d7b7f6 100644 --- a/lexer.h +++ b/lexer.h @@ -99,7 +99,7 @@ typedef struct { int value; } frame_macro; -typedef struct { +typedef struct lex_file_s { FILE *file; const char *open_string; size_t open_string_length; diff --git a/parser.c b/parser.c index 14b4c81..c0ca8b5 100644 --- a/parser.c +++ b/parser.c @@ -1604,6 +1604,21 @@ static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma } else { + /* + * sometimes people use preprocessing predefs without enabling them + * i've done this thousands of times already myself. Lets check for + * it in the predef table. And diagnose it better :) + */ + if (!OPTS_FLAG(FTEPP_PREDEFS)) { + size_t i; + for (i = 0; i < sizeof(ftepp_predefs)/sizeof(*ftepp_predefs); i++) { + if (!strcmp(ftepp_predefs[i].name, parser_tokval(parser))) { + parseerror(parser, "unexpected ident: %s (use -fftepp-predef to enable pre-defined macros)", parser_tokval(parser)); + goto onerr; + } + } + } + parseerror(parser, "unexpected ident: %s", parser_tokval(parser)); goto onerr; }