mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-02-17 09:02:25 +00:00
ast_value_copy should copy the expression substructure as well - exposing ast_value_copy to the outside since the parser needs to copy complete types when multiple variables are declared with commas
This commit is contained in:
parent
3effcd2342
commit
24a21d0816
3 changed files with 18 additions and 2 deletions
14
ast.c
14
ast.c
|
@ -92,8 +92,11 @@ static void ast_expression_delete_full(ast_expression *self)
|
|||
MEM_VEC_FUNCTIONS(ast_expression_common, ast_value*, params)
|
||||
|
||||
static ast_expression* ast_type_copy(lex_ctx ctx, const ast_expression *ex);
|
||||
static ast_value* ast_value_copy(const ast_value *self)
|
||||
ast_value* ast_value_copy(const ast_value *self)
|
||||
{
|
||||
size_t i;
|
||||
const ast_expression_common *fromex;
|
||||
ast_expression_common *selfex;
|
||||
ast_value *cp = ast_value_new(self->expression.node.context, self->name, self->expression.vtype);
|
||||
if (self->expression.next) {
|
||||
cp->expression.next = ast_type_copy(self->expression.node.context, self->expression.next);
|
||||
|
@ -102,6 +105,15 @@ static ast_value* ast_value_copy(const ast_value *self)
|
|||
return NULL;
|
||||
}
|
||||
}
|
||||
fromex = &self->expression;
|
||||
selfex = &cp->expression;
|
||||
for (i = 0; i < fromex->params_count; ++i) {
|
||||
ast_value *v = ast_value_copy(fromex->params[i]);
|
||||
if (!v || !ast_expression_common_params_add(selfex, v)) {
|
||||
ast_value_delete(cp);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return cp;
|
||||
}
|
||||
|
||||
|
|
1
ast.h
1
ast.h
|
@ -149,6 +149,7 @@ struct ast_value_s
|
|||
};
|
||||
|
||||
ast_value* ast_value_new(lex_ctx ctx, const char *name, int qctype);
|
||||
ast_value* ast_value_copy(const ast_value *self);
|
||||
/* This will NOT delete an underlying ast_function */
|
||||
void ast_value_delete(ast_value*);
|
||||
|
||||
|
|
5
parser.c
5
parser.c
|
@ -2042,6 +2042,7 @@ static bool parser_do(parser_t *parser)
|
|||
else if (parser->tok == '.')
|
||||
{
|
||||
ast_value *var;
|
||||
ast_value *typevar;
|
||||
ast_value *fld;
|
||||
ast_expression *oldex;
|
||||
bool isfunc = false;
|
||||
|
@ -2065,11 +2066,12 @@ static bool parser_do(parser_t *parser)
|
|||
}
|
||||
|
||||
/* parse the field type fully */
|
||||
var = parser_parse_type(parser, basetype, &isfunc);
|
||||
typevar = var = parser_parse_type(parser, basetype, &isfunc);
|
||||
if (!var)
|
||||
return false;
|
||||
|
||||
while (true) {
|
||||
var = ast_value_copy(typevar);
|
||||
/* now the field name */
|
||||
if (parser->tok != TOKEN_IDENT) {
|
||||
parseerror(parser, "expected field name");
|
||||
|
@ -2179,6 +2181,7 @@ nextfield:
|
|||
return false;
|
||||
}
|
||||
}
|
||||
ast_delete(typevar);
|
||||
|
||||
/* skip the semicolon */
|
||||
if (!parser_next(parser))
|
||||
|
|
Loading…
Reference in a new issue