parsing of vararg-counter

This commit is contained in:
Wolfgang Bumiller 2013-01-12 11:29:03 +01:00
parent 87ff481abf
commit c69ba2c734
3 changed files with 26 additions and 2 deletions

4
ast.c
View file

@ -348,6 +348,8 @@ ast_value* ast_value_new(lex_ctx ctx, const char *name, int t)
self->getter = NULL; self->getter = NULL;
self->desc = NULL; self->desc = NULL;
self->argcounter = NULL;
return self; return self;
} }
@ -355,6 +357,8 @@ void ast_value_delete(ast_value* self)
{ {
if (self->name) if (self->name)
mem_d((void*)self->name); mem_d((void*)self->name);
if (self->argcounter)
mem_d((void*)self->argcounter);
if (self->hasvalue) { if (self->hasvalue) {
switch (self->expression.vtype) switch (self->expression.vtype)
{ {

2
ast.h
View file

@ -167,6 +167,8 @@ struct ast_value_s
const char *name; const char *name;
const char *desc; const char *desc;
const char *argcounter;
/* /*
int vtype; int vtype;
ast_value *next; ast_value *next;

View file

@ -4292,6 +4292,7 @@ static ast_value *parse_parameter_list(parser_t *parser, ast_value *var)
bool first = true; bool first = true;
bool variadic = false; bool variadic = false;
ast_value *varparam = NULL; ast_value *varparam = NULL;
char *argcounter = NULL;
ctx = parser_ctx(parser); ctx = parser_ctx(parser);
@ -4321,10 +4322,17 @@ static ast_value *parse_parameter_list(parser_t *parser, ast_value *var)
if (parser->tok == TOKEN_DOTS) { if (parser->tok == TOKEN_DOTS) {
/* '...' indicates a varargs function */ /* '...' indicates a varargs function */
variadic = true; variadic = true;
if (!parser_next(parser) || parser->tok != ')') { if (!parser_next(parser) || (parser->tok != ')' && parser->tok != TOKEN_IDENT)) {
parseerror(parser, "`...` must be the last parameter of a variadic function declaration"); parseerror(parser, "`...` must be the last parameter of a variadic function declaration");
goto on_error; goto on_error;
} }
if (parser->tok == TOKEN_IDENT) {
argcounter = util_strdup(parser_tokval(parser));
if (!parser_next(parser) || parser->tok != ')') {
parseerror(parser, "`...` must be the last parameter of a variadic function declaration");
goto on_error;
}
}
} }
else else
{ {
@ -4344,10 +4352,17 @@ static ast_value *parse_parameter_list(parser_t *parser, ast_value *var)
variadic = true; variadic = true;
varparam = vec_last(params); varparam = vec_last(params);
vec_pop(params); vec_pop(params);
if (!parser_next(parser) || parser->tok != ')') { if (!parser_next(parser) || (parser->tok != ')' && parser->tok != TOKEN_IDENT)) {
parseerror(parser, "`...` must be the last parameter of a variadic function declaration"); parseerror(parser, "`...` must be the last parameter of a variadic function declaration");
goto on_error; goto on_error;
} }
if (parser->tok == TOKEN_IDENT) {
argcounter = util_strdup(parser_tokval(parser));
if (!parser_next(parser) || parser->tok != ')') {
parseerror(parser, "`...` must be the last parameter of a variadic function declaration");
goto on_error;
}
}
} }
} }
} }
@ -4374,11 +4389,14 @@ static ast_value *parse_parameter_list(parser_t *parser, ast_value *var)
var->expression.params = params; var->expression.params = params;
var->expression.varparam = (ast_expression*)varparam; var->expression.varparam = (ast_expression*)varparam;
var->argcounter = argcounter;
params = NULL; params = NULL;
return var; return var;
on_error: on_error:
if (argcounter)
mem_d(argcounter);
ast_delete(var); ast_delete(var);
for (i = 0; i < vec_size(params); ++i) for (i = 0; i < vec_size(params); ++i)
ast_delete(params[i]); ast_delete(params[i]);