From: Wolfgang (Blub) Bumiller Date: Thu, 16 Aug 2012 13:27:06 +0000 (+0200) Subject: Allow fieldpointer parameters in functions, allow function fields again X-Git-Tag: 0.1-rc1~252 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=ec439d788086e95450c9331ea9d43e9299ce1ffc;p=xonotic%2Fgmqcc.git Allow fieldpointer parameters in functions, allow function fields again --- diff --git a/lexer.c b/lexer.c index 6fc32b7..0c58a5d 100644 --- a/lexer.c +++ b/lexer.c @@ -635,7 +635,6 @@ int lex_do(lex_file *lex) !strcmp(v, "do") || !strcmp(v, "if") || !strcmp(v, "else") || - !strcmp(v, "var") || !strcmp(v, "local") || !strcmp(v, "return") || !strcmp(v, "const")) diff --git a/parser.c b/parser.c index 8bde63a..1f071a7 100644 --- a/parser.c +++ b/parser.c @@ -292,6 +292,8 @@ static ast_value *parser_parse_type(parser_t *parser, int basetype, bool *isfunc *isfunc = true; while (true) { ast_value *param; + ast_value *fld; + bool isfield = false; bool dummy; if (!parser_next(parser)) @@ -300,6 +302,14 @@ static ast_value *parser_parse_type(parser_t *parser, int basetype, bool *isfunc if (parser->tok == ')') break; + if (parser->tok == '.') { + isfield = true; + if (!parser_next(parser)) { + parseerror(parser, "expected field parameter type"); + goto on_error; + } + } + temptype = parser_token(parser)->constval.t; if (!parser_next(parser)) goto on_error; @@ -318,6 +328,12 @@ static ast_value *parser_parse_type(parser_t *parser, int basetype, bool *isfunc goto on_error; } + if (isfield) { + fld = ast_value_new(ctx, param->name, TYPE_FIELD); + fld->expression.next = (ast_expression*)param; + param = fld; + } + if (!paramlist_t_p_add(¶ms, param)) { parseerror(parser, "Out of memory while parsing typename"); goto on_error; @@ -2007,6 +2023,18 @@ static bool parser_do(parser_t *parser) } } + if (isfunc) { + ast_value *fval; + fval = ast_value_new(ctx, var->name, TYPE_FUNCTION); + if (!fval) { + ast_value_delete(var); + return false; + } + fval->expression.next = (ast_expression*)var; + MEM_VECTOR_MOVE(&var->expression, params, &fval->expression, params); + var = fval; + } + /* turn it into a field */ fld = ast_value_new(ctx, parser_tokval(parser), TYPE_FIELD); fld->expression.next = (ast_expression*)var;