]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - parser.c
don't _move_ values out of immediates, it causes NULL strings to be code-generated
[xonotic/gmqcc.git] / parser.c
index 21a944bdf36c6c8e6d098bcf999bcaf3048a9aae..9d461597f0aecca2d95cd6e3d91980fb3f74124a 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -129,7 +129,7 @@ bool parser_next(parser_t *parser)
     /* lex_do kills the previous token */
     parser->tok = lex_do(parser->lex);
     if (parser->tok == TOKEN_EOF)
-        return false;
+        return true;
     if (parser->tok >= TOKEN_ERROR) {
         parseerror(parser, "lex error");
         return false;
@@ -2277,24 +2277,7 @@ nextvar:
 
                     varent.var = (ast_expression*)thinkfunc;
                     varent.name = util_strdup(thinkfunc->name);
-                    if (thinkfunc->expression.vtype == TYPE_FUNCTION)
-                    {
-                        ast_function *func;
-
-                        func = ast_function_new(parser_ctx(parser), thinkfunc->name, thinkfunc);
-                        if (!func) {
-                            ast_delete(thinkfunc);
-                            ast_unref(framenum);
-                            parseerror(parser, "failed to create function for implicit prototype for `%s`",
-                                       thinkfunc->name);
-                            ast_value_delete(typevar);
-                            return false;
-                        }
-                        (void)!parser_t_functions_add(parser, func);
-                        (void)!parser_t_globals_add(parser, varent);
-                    }
-                    else
-                        (void)!parser_t_globals_add(parser, varent);
+                    (void)!parser_t_globals_add(parser, varent);
                     nextthink = (ast_expression*)thinkfunc;
 
                 } else {
@@ -2307,7 +2290,7 @@ nextvar:
                     }
                 }
 
-                if (!ast_istype(nextthink, ast_value) || !( (ast_value*)nextthink )->isconst) {
+                if (!ast_istype(nextthink, ast_value)) {
                     ast_unref(nextthink);
                     ast_unref(framenum);
                     parseerror(parser, "think-function in [frame,think] notation must be a constant");
@@ -2467,8 +2450,10 @@ nextvar:
             else
             {
                 var->isconst = true;
-                memcpy(&var->constval, &cval->constval, sizeof(var->constval));
-                memset(&cval->constval, 0, sizeof(cval->constval));
+                if (cval->expression.vtype == TYPE_STRING)
+                    var->constval.vstring = parser_strdup(cval->constval.vstring);
+                else
+                    memcpy(&var->constval, &cval->constval, sizeof(var->constval));
                 ast_unref(cval);
             }
         }