]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
Allow fieldpointer parameters in functions, allow function fields again
authorWolfgang (Blub) Bumiller <blub@speed.at>
Thu, 16 Aug 2012 13:27:06 +0000 (15:27 +0200)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Thu, 16 Aug 2012 13:27:06 +0000 (15:27 +0200)
lexer.c
parser.c

diff --git a/lexer.c b/lexer.c
index 6fc32b7c1456835bc059be907bba45468f6f980f..0c58a5da64f27d69b5648d9076a14b1aba863b6b 100644 (file)
--- 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"))
index 8bde63a2b99e9e7aa0917767f1c47f286e167d51..1f071a74a412e1dc8c70dee469f7e5099abebf2a 100644 (file)
--- 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(&params, 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;