]> de.git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - parser.c
Just allow variable declarations in for-loop initializers in any standard...
[xonotic/gmqcc.git] / parser.c
index 8fe2c31ffb36518247f6718240194e45c5996230..97a4dffc5c40fbd071d7f0bc9c4903ffde0527b0 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -983,14 +983,14 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
                 return false;
             }
             vec_pop(parser->pot);
-            if (exprs[1]->expression.vtype != exprs[2]->expression.vtype) {
+            if (!ast_compare_type(exprs[1], exprs[2])) {
                 ast_type_to_string(exprs[1], ty1, sizeof(ty1));
                 ast_type_to_string(exprs[2], ty2, sizeof(ty2));
                 parseerror(parser, "operands of ternary expression must have the same type, got %s and %s", ty1, ty2);
                 return false;
             }
             if (CanConstFold1(exprs[0]))
-                out = (ConstF(0) ? exprs[1] : exprs[2]);
+                out = (immediate_is_true(ctx, asvalue[0]) ? exprs[1] : exprs[2]);
             else
                 out = (ast_expression*)ast_ternary_new(ctx, exprs[0], exprs[1], exprs[2]);
             break;
@@ -1403,35 +1403,18 @@ static bool parser_close_call(parser_t *parser, shunt *sy)
               vec_size(fun->expression.params) < paramcount))
         {
             const char *fewmany = (vec_size(fun->expression.params) > paramcount) ? "few" : "many";
-            if (opts.standard == COMPILER_GMQCC)
-            {
-                if (fval)
-                    parseerror(parser, "too %s parameters for call to %s: expected %i, got %i\n"
-                               " -> `%s` has been declared here: %s:%i",
-                               fewmany, fval->name, (int)vec_size(fun->expression.params), (int)paramcount,
-                               fval->name, ast_ctx(fun).file, (int)ast_ctx(fun).line);
-                else
-                    parseerror(parser, "too %s parameters for function call: expected %i, got %i\n"
-                               " -> it has been declared here: %s:%i",
-                               fewmany, (int)vec_size(fun->expression.params), (int)paramcount,
-                               ast_ctx(fun).file, (int)ast_ctx(fun).line);
-                return false;
-            }
+            if (fval)
+                return !parsewarning(parser, WARN_INVALID_PARAMETER_COUNT,
+                                     "too %s parameters for call to %s: expected %i, got %i\n"
+                                     " -> `%s` has been declared here: %s:%i",
+                                     fewmany, fval->name, (int)vec_size(fun->expression.params), (int)paramcount,
+                                     fval->name, ast_ctx(fun).file, (int)ast_ctx(fun).line);
             else
-            {
-                if (fval)
-                    return !parsewarning(parser, WARN_TOO_FEW_PARAMETERS,
-                                         "too %s parameters for call to %s: expected %i, got %i\n"
-                                         " -> `%s` has been declared here: %s:%i",
-                                         fewmany, fval->name, (int)vec_size(fun->expression.params), (int)paramcount,
-                                         fval->name, ast_ctx(fun).file, (int)ast_ctx(fun).line);
-                else
-                    return !parsewarning(parser, WARN_TOO_FEW_PARAMETERS,
-                                         "too %s parameters for function call: expected %i, got %i\n"
-                                         " -> it has been declared here: %s:%i",
-                                         fewmany, (int)vec_size(fun->expression.params), (int)paramcount,
-                                         ast_ctx(fun).file, (int)ast_ctx(fun).line);
-            }
+                return !parsewarning(parser, WARN_INVALID_PARAMETER_COUNT,
+                                     "too %s parameters for function call: expected %i, got %i\n"
+                                     " -> it has been declared here: %s:%i",
+                                     fewmany, (int)vec_size(fun->expression.params), (int)paramcount,
+                                     ast_ctx(fun).file, (int)ast_ctx(fun).line);
         }
     }
 
@@ -2429,11 +2412,13 @@ static bool parse_for_go(parser_t *parser, ast_block *block, ast_expression **ou
         typevar = parser_find_typedef(parser, parser_tokval(parser), 0);
 
     if (typevar || parser->tok == TOKEN_TYPENAME) {
+#if 0
         if (opts.standard != COMPILER_GMQCC) {
             if (parsewarning(parser, WARN_EXTENSIONS,
                              "current standard does not allow variable declarations in for-loop initializers"))
                 goto onerr;
         }
+#endif
         if (!parse_variable(parser, block, true, CV_VAR, typevar, false, false, 0, NULL))
             goto onerr;
     }