]> git.rm.cloudns.org Git - xonotic/gmqcc.git/commitdiff
-Wlocal-shadows - note that -std=gmqcc is very different from the rest
authorWolfgang (Blub) Bumiller <blub@speed.at>
Sat, 18 Aug 2012 19:54:19 +0000 (21:54 +0200)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Sat, 18 Aug 2012 19:54:19 +0000 (21:54 +0200)
parser.c
warns.def

index dbe7fa78abe96d74da0c1d8e984c74996b3a9388..567a622f6a73197ee5cbd7ca6b319d51c1f88ed6 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -1792,6 +1792,7 @@ static bool parser_variable(parser_t *parser, ast_block *localblock)
         olddecl = NULL;
         isfunc  = false;
         func    = NULL;
+        isparam = false;
         ctx = parser_ctx(parser);
         var = parser_parse_type(parser, basetype, &isfunc);
 
@@ -1811,11 +1812,52 @@ static bool parser_variable(parser_t *parser, ast_block *localblock)
                 return false;
             }
 
-            if (localblock && (olddecl = parser_find_local(parser, parser_tokval(parser), parser->blocklocal, &isparam))) {
-                ast_value_delete(var);
-                parseerror(parser, "local `%s` already declared here: %s:%i",
-                           parser_tokval(parser), ast_ctx(olddecl).file, (int)ast_ctx(olddecl).line);
-                return false;
+            if (localblock) {
+                olddecl = parser_find_local(parser, parser_tokval(parser), parser->blocklocal, &isparam);
+                if (opts_standard == COMPILER_GMQCC)
+                {
+                    if (olddecl)
+                    {
+                        if (!isparam) {
+                            ast_value_delete(var);
+                            parseerror(parser, "local `%s` already declared here: %s:%i",
+                                       parser_tokval(parser), ast_ctx(olddecl).file, (int)ast_ctx(olddecl).line);
+                            return false;
+                        }
+                    }
+
+                    if( (!isparam && olddecl) || (olddecl = parser_find_local(parser, parser_tokval(parser), 0, &isparam)) )
+                    {
+                        if (parsewarning(parser, WARN_LOCAL_SHADOWS,
+                                         "local `%s` is shadowing a parameter", parser_tokval(parser)))
+                        {
+                            ast_value_delete(var);
+                            parseerror(parser, "local `%s` already declared here: %s:%i",
+                                       parser_tokval(parser), ast_ctx(olddecl).file, (int)ast_ctx(olddecl).line);
+                            return false;
+                        }
+                    }
+                }
+                else
+                {
+                    if (olddecl)
+                    {
+                        if (isparam &&
+                            parsewarning(parser, WARN_LOCAL_SHADOWS,
+                                         "a parameter is shadowing local `%s`", parser_tokval(parser)))
+                        {
+                            ast_value_delete(var);
+                            return false;
+                        }
+                        else if (!isparam)
+                        {
+                            ast_value_delete(var);
+                            parseerror(parser, "local `%s` already declared here: %s:%i",
+                                       parser_tokval(parser), ast_ctx(olddecl).file, (int)ast_ctx(olddecl).line);
+                            return false;
+                        }
+                    }
+                }
             }
         }
 
index 88b4cfccf9bf6925d21791d72f365f48fc62b80b..6958a9969b78f6cff558c30e2b81c5e6b306179d 100644 (file)
--- a/warns.def
+++ b/warns.def
@@ -9,3 +9,4 @@ GMQCC_DEFINE_FLAG(EXTENSIONS)
 GMQCC_DEFINE_FLAG(FIELD_REDECLARED)
 GMQCC_DEFINE_FLAG(MISSING_RETURN_VALUES)
 GMQCC_DEFINE_FLAG(TOO_FEW_PARAMETERS)
+GMQCC_DEFINE_FLAG(LOCAL_SHADOWS)