]> de.git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - parser.c
new warning: -Wlocal-constants
[xonotic/gmqcc.git] / parser.c
index 4f5b7be4e9594c40b07f63d13954caedab82d552..4874f49deae08885c900e29d8019b69253e64322 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;
@@ -2115,6 +2115,16 @@ nextvar:
             continue;
         }
 
+        if (localblock && opts_standard == COMPILER_QCC) {
+            if (parsewarning(parser, WARN_LOCAL_CONSTANTS,
+                             "initializing expression turns variable `%s` into a constant in this standard",
+                             var->name) )
+            {
+                ast_value_delete(typevar);
+                return false;
+            }
+        }
+
         if (parser->tok != '=') {
             ast_value_delete(typevar);
             parseerror(parser, "expected '=' or ';'");
@@ -2277,24 +2287,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 +2300,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 +2460,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);
             }
         }
@@ -2685,12 +2680,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);