]> 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 c76855597a3d7cc7b0e248fe1677655e059a8b17..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;
@@ -2108,6 +2108,10 @@ nextvar:
 
         if (parser->tok == ',') {
             /* another var */
+            if (!parser_next(parser)) {
+                ast_delete(typevar);
+                return false;
+            }
             continue;
         }
 
@@ -2273,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 {
@@ -2303,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");
@@ -2463,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);
             }
         }
@@ -2681,12 +2670,17 @@ bool parser_compile(const char *filename)
                 if (parser->tok == TOKEN_EOF)
                     parseerror(parser, "unexpected eof");
                 else if (!parser->errors)
-                    parseerror(parser, "parse error\n");
+                    parseerror(parser, "parse error");
                 lex_close(parser->lex);
                 parser->lex = NULL;
                 return false;
             }
         }
+    } else {
+        parseerror(parser, "parse error");
+        lex_close(parser->lex);
+        parser->lex = NULL;
+        return false;
     }
 
     lex_close(parser->lex);