mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-02-21 02:40:56 +00:00
Add specialized diagnostics for when predefined macros are used and ftepp predefined macros are not enabled.
This commit is contained in:
parent
ae09831227
commit
9bda8f61f4
4 changed files with 31 additions and 7 deletions
7
ftepp.c
7
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 },
|
||||
|
|
14
gmqcc.h
14
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 ========================*/
|
||||
/*===================================================================*/
|
||||
|
|
2
lexer.h
2
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;
|
||||
|
|
15
parser.c
15
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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue