lex_ctx ctx = parser_ctx(parser);
int vtype = basetype;
int temptype;
+ size_t i;
MEM_VECTOR_INIT(¶ms, p);
ast_value *param;
bool dummy;
- if (!parser_next(parser)) {
- MEM_VECTOR_CLEAR(¶ms, p);
- return NULL;
- }
+ if (!parser_next(parser))
+ goto on_error;
if (parser->tok == ')')
break;
temptype = parser_token(parser)->constval.t;
- if (!parser_next(parser)) {
- MEM_VECTOR_CLEAR(¶ms, p);
- return NULL;
- }
+ if (!parser_next(parser))
+ goto on_error;
+
param = parser_parse_type(parser, temptype, &dummy);
(void)dummy;
- if (!param) {
- MEM_VECTOR_CLEAR(¶ms, p);
- return NULL;
+ if (!param)
+ goto on_error;
+
+ if (parser->tok == TOKEN_IDENT) {
+ /* named parameter */
+ if (!ast_value_set_name(param, parser_tokval(parser)))
+ goto on_error;
+ if (!parser_next(parser))
+ goto on_error;
}
if (!paramlist_t_p_add(¶ms, param)) {
- MEM_VECTOR_CLEAR(¶ms, p);
parseerror(parser, "Out of memory while parsing typename");
- return NULL;
+ goto on_error;
}
if (parser->tok == ',')
continue;
if (parser->tok == ')')
break;
- MEM_VECTOR_CLEAR(¶ms, p);
parseerror(parser, "Unexpected token");
- return NULL;
- }
- if (!parser_next(parser)) {
- MEM_VECTOR_CLEAR(¶ms, p);
- return NULL;
+ goto on_error;
}
+ if (!parser_next(parser))
+ goto on_error;
}
var = ast_value_new(ctx, "<unnamed>", vtype);
- if (!var) {
- MEM_VECTOR_CLEAR(¶ms, p);
- return NULL;
- }
+ if (!var)
+ goto on_error;
MEM_VECTOR_MOVE(¶ms, p, var, params);
return var;
+on_error:
+ for (i = 0; i < params.p_count; ++i)
+ ast_value_delete(params.p[i]);
+ MEM_VECTOR_CLEAR(¶ms, p);
+ return NULL;
}
typedef struct