mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-02-22 03:11:27 +00:00
Warn (via -Wextensions) when accessing a field-of-array's element without putting the indexed field name in parenthesis
This commit is contained in:
parent
b0326c66ed
commit
b1175eabfc
1 changed files with 14 additions and 5 deletions
19
parser.c
19
parser.c
|
@ -383,7 +383,7 @@ static sy_elem syparen(lex_ctx ctx, int p, size_t off) {
|
||||||
/* With regular precedence rules, ent.foo[n] is the same as (ent.foo)[n],
|
/* With regular precedence rules, ent.foo[n] is the same as (ent.foo)[n],
|
||||||
* so we need to rotate it to become ent.(foo[n]).
|
* so we need to rotate it to become ent.(foo[n]).
|
||||||
*/
|
*/
|
||||||
static void rotate_entfield_array_index_nodes(ast_expression **out)
|
static bool rotate_entfield_array_index_nodes(ast_expression **out)
|
||||||
{
|
{
|
||||||
ast_array_index *index;
|
ast_array_index *index;
|
||||||
ast_entfield *entfield;
|
ast_entfield *entfield;
|
||||||
|
@ -395,15 +395,15 @@ static void rotate_entfield_array_index_nodes(ast_expression **out)
|
||||||
lex_ctx ctx = ast_ctx(*out);
|
lex_ctx ctx = ast_ctx(*out);
|
||||||
|
|
||||||
if (!ast_istype(*out, ast_array_index))
|
if (!ast_istype(*out, ast_array_index))
|
||||||
return;
|
return false;
|
||||||
index = (ast_array_index*)*out;
|
index = (ast_array_index*)*out;
|
||||||
|
|
||||||
if (!ast_istype(index->array, ast_entfield))
|
if (!ast_istype(index->array, ast_entfield))
|
||||||
return;
|
return false;
|
||||||
entfield = (ast_entfield*)index->array;
|
entfield = (ast_entfield*)index->array;
|
||||||
|
|
||||||
if (!ast_istype(entfield->field, ast_value))
|
if (!ast_istype(entfield->field, ast_value))
|
||||||
return;
|
return false;
|
||||||
field = (ast_value*)entfield->field;
|
field = (ast_value*)entfield->field;
|
||||||
|
|
||||||
sub = index->index;
|
sub = index->index;
|
||||||
|
@ -414,6 +414,8 @@ static void rotate_entfield_array_index_nodes(ast_expression **out)
|
||||||
index = ast_array_index_new(ctx, (ast_expression*)field, sub);
|
index = ast_array_index_new(ctx, (ast_expression*)field, sub);
|
||||||
entfield = ast_entfield_new(ctx, entity, (ast_expression*)index);
|
entfield = ast_entfield_new(ctx, entity, (ast_expression*)index);
|
||||||
*out = (ast_expression*)entfield;
|
*out = (ast_expression*)entfield;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool parser_sy_pop(parser_t *parser, shunt *sy)
|
static bool parser_sy_pop(parser_t *parser, shunt *sy)
|
||||||
|
@ -514,7 +516,14 @@ static bool parser_sy_pop(parser_t *parser, shunt *sy)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
out = (ast_expression*)ast_array_index_new(ctx, exprs[0], exprs[1]);
|
out = (ast_expression*)ast_array_index_new(ctx, exprs[0], exprs[1]);
|
||||||
rotate_entfield_array_index_nodes(&out);
|
if (rotate_entfield_array_index_nodes(&out))
|
||||||
|
{
|
||||||
|
if (opts_standard != COMPILER_GMQCC) {
|
||||||
|
/* this error doesn't need to make us bail out */
|
||||||
|
(void)!parsewarning(parser, WARN_EXTENSIONS,
|
||||||
|
"accessing array-field members of an entity without parenthesis");
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case opid1(','):
|
case opid1(','):
|
||||||
|
|
Loading…
Reference in a new issue