mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-01-18 22:31:36 +00:00
Print a warning if end_sys_fields was declared as a field rather than a global
This commit is contained in:
parent
4742ee9123
commit
9d70c3a56e
3 changed files with 19 additions and 0 deletions
1
main.c
1
main.c
|
@ -416,6 +416,7 @@ int main(int argc, char **argv) {
|
|||
options_set(opts_warn, WARN_FRAME_MACROS, true);
|
||||
options_set(opts_warn, WARN_UNUSED_VARIABLE, true);
|
||||
options_set(opts_warn, WARN_EFFECTLESS_STATEMENT, true);
|
||||
options_set(opts_warn, WARN_END_SYS_FIELDS, true);
|
||||
|
||||
if (!options_parse(argc, argv)) {
|
||||
return usage();
|
||||
|
|
17
parser.c
17
parser.c
|
@ -23,6 +23,9 @@ typedef struct {
|
|||
ast_value *imm_float_zero;
|
||||
ast_value *imm_vector_zero;
|
||||
|
||||
size_t crc_globals;
|
||||
size_t crc_fields;
|
||||
|
||||
ast_function *function;
|
||||
MEM_VECTOR_MAKE(varentry_t, locals);
|
||||
size_t blocklocal;
|
||||
|
@ -2284,6 +2287,13 @@ static bool parse_variable(parser_t *parser, ast_block *localblock)
|
|||
goto cleanup;
|
||||
}
|
||||
|
||||
if (!localblock) {
|
||||
if (!strcmp(parser_tokval(parser), "end_sys_globals"))
|
||||
parser->crc_globals = parser->globals_count;
|
||||
else if (!strcmp(parser_tokval(parser), "end_sys_fields"))
|
||||
parser->crc_fields = parser->fields_count;
|
||||
}
|
||||
|
||||
if (!isfunc) {
|
||||
if (!localblock && (olddecl = parser_find_global(parser, parser_tokval(parser)))) {
|
||||
parseerror(parser, "global `%s` already declared here: %s:%i",
|
||||
|
@ -2710,6 +2720,13 @@ static bool parser_global_statement(parser_t *parser)
|
|||
var = fval;
|
||||
}
|
||||
|
||||
if (!strcmp(parser_tokval(parser), "end_sys_fields")) {
|
||||
if (parsewarning(parser, WARN_END_SYS_FIELDS, "by convention end_sys_fields should be declared as global, rather than a field")) {
|
||||
ast_value_delete(var);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* turn it into a field */
|
||||
fld = ast_value_new(ctx, parser_tokval(parser), TYPE_FIELD);
|
||||
fld->expression.next = (ast_expression*)var;
|
||||
|
|
|
@ -17,3 +17,4 @@ GMQCC_DEFINE_FLAG(IMPLICIT_FUNCTION_POINTER)
|
|||
GMQCC_DEFINE_FLAG(VARIADIC_FUNCTION)
|
||||
GMQCC_DEFINE_FLAG(FRAME_MACROS)
|
||||
GMQCC_DEFINE_FLAG(EFFECTLESS_STATEMENT)
|
||||
GMQCC_DEFINE_FLAG(END_SYS_FIELDS)
|
||||
|
|
Loading…
Reference in a new issue