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);
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;
}
};
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*);
else if (parser->tok == '.')
{
ast_value *var;
+ ast_value *typevar;
ast_value *fld;
ast_expression *oldex;
bool isfunc = false;
}
/* 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");
return false;
}
}
+ ast_delete(typevar);
/* skip the semicolon */
if (!parser_next(parser))