mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-01-31 12:00:38 +00:00
parsing of vararg-counter
This commit is contained in:
parent
87ff481abf
commit
c69ba2c734
3 changed files with 26 additions and 2 deletions
4
ast.c
4
ast.c
|
@ -348,6 +348,8 @@ ast_value* ast_value_new(lex_ctx ctx, const char *name, int t)
|
|||
self->getter = NULL;
|
||||
self->desc = NULL;
|
||||
|
||||
self->argcounter = NULL;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
@ -355,6 +357,8 @@ void ast_value_delete(ast_value* self)
|
|||
{
|
||||
if (self->name)
|
||||
mem_d((void*)self->name);
|
||||
if (self->argcounter)
|
||||
mem_d((void*)self->argcounter);
|
||||
if (self->hasvalue) {
|
||||
switch (self->expression.vtype)
|
||||
{
|
||||
|
|
2
ast.h
2
ast.h
|
@ -167,6 +167,8 @@ struct ast_value_s
|
|||
const char *name;
|
||||
const char *desc;
|
||||
|
||||
const char *argcounter;
|
||||
|
||||
/*
|
||||
int vtype;
|
||||
ast_value *next;
|
||||
|
|
22
parser.c
22
parser.c
|
@ -4292,6 +4292,7 @@ static ast_value *parse_parameter_list(parser_t *parser, ast_value *var)
|
|||
bool first = true;
|
||||
bool variadic = false;
|
||||
ast_value *varparam = NULL;
|
||||
char *argcounter = NULL;
|
||||
|
||||
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) {
|
||||
/* '...' indicates a varargs function */
|
||||
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");
|
||||
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
|
||||
{
|
||||
|
@ -4344,10 +4352,17 @@ static ast_value *parse_parameter_list(parser_t *parser, ast_value *var)
|
|||
variadic = true;
|
||||
varparam = vec_last(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");
|
||||
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.varparam = (ast_expression*)varparam;
|
||||
var->argcounter = argcounter;
|
||||
params = NULL;
|
||||
|
||||
return var;
|
||||
|
||||
on_error:
|
||||
if (argcounter)
|
||||
mem_d(argcounter);
|
||||
ast_delete(var);
|
||||
for (i = 0; i < vec_size(params); ++i)
|
||||
ast_delete(params[i]);
|
||||
|
|
Loading…
Reference in a new issue