From 24a21d08167dae7657d1785ec5db7c1727c7d238 Mon Sep 17 00:00:00 2001 From: "Wolfgang (Blub) Bumiller" Date: Sat, 18 Aug 2012 17:16:20 +0200 Subject: [PATCH] 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 --- ast.c | 14 +++++++++++++- ast.h | 1 + parser.c | 5 ++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/ast.c b/ast.c index bca493e..52023ff 100644 --- a/ast.c +++ b/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; } diff --git a/ast.h b/ast.h index 9951216..d118adb 100644 --- a/ast.h +++ b/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*); diff --git a/parser.c b/parser.c index a084e2f..b193566 100644 --- a/parser.c +++ b/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)) -- 2.39.2