Generate warnings for useless declarations like "char data;"
authorepetrich <epetrich@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 12 Aug 2003 08:44:47 +0000 (08:44 +0000)
committerepetrich <epetrich@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 12 Aug 2003 08:44:47 +0000 (08:44 +0000)
that don't do what new users expect.

* src/SDCC.y
* support/Util/SDCCerr.h
* support/Util/SDCCerr.c

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2822 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
src/SDCC.y
support/Util/SDCCerr.c
support/Util/SDCCerr.h

index 7f65ec78ea39fbdb3193b8f4a5f4299e42e4de2e..b1fb8c309e3e03eff1db3d7c10634718208fb418 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2003-08-12  Erik Petrich <epetrich@ivorytower.norman.ok.us>
+
+       Generate warnings for useless declarations like "char data;"
+       that don't do what new users expect.
+
+       * src/SDCC.y
+       * support/Util/SDCCerr.h
+       * support/Util/SDCCerr.c
+
 2003-08-09  Bernhard Held <bernhard@bernhardheld.de>
 
        * src/SDCCval.c (valMult): fixex overflow detection of negativ int
index 4d4d5fa2f17c9d348737c2ee90208834429bd146..5847cbe78db16c5e367a4fdd63dc059e473b48dd 100644 (file)
@@ -57,6 +57,7 @@ STACK_DCL(swStk   ,ast   *,MAX_NEST_LEVEL)
 STACK_DCL(blockNum,int,MAX_NEST_LEVEL*3)
 
 value *cenum = NULL  ;  /* current enumeration  type chain*/
+bool uselessDecl = TRUE;
 
 %}
 %expect 6
@@ -459,7 +460,13 @@ constant_expr
    ;
 
 declaration
-   : declaration_specifiers ';'  { $$ = NULL ; }
+   : declaration_specifiers ';'
+      {
+         if (uselessDecl)
+           werror(W_USELESS_DECL);
+         uselessDecl = TRUE;
+         $$ = NULL ;
+      }
    | declaration_specifiers init_declarator_list ';'
       {
          /* add the specifier list to the id */
@@ -472,6 +479,7 @@ declaration
             addDecl (sym,0,lnk) ;
         }
         
+         uselessDecl = TRUE;
         $$ = sym1 ;
       }
    ;
@@ -629,9 +637,13 @@ type_specifier2
               SPEC_BSTR($$) = 0;
             }
 
-   | struct_or_union_specifier
+   | struct_or_union_specifier  {
+                                   uselessDecl = FALSE;
+                                   $$ = $1 ;
+                                }
    | enum_specifier     {                           
                            cenum = NULL ;
+                           uselessDecl = FALSE;
                            $$ = $1 ;                              
                         }
    | TYPE_NAME    
index 7e46d97ba0631197323b1cf95f6e4e77f614c9d7..3fdc279f59d774575e3130d3810ef941686f2090 100644 (file)
@@ -387,6 +387,8 @@ struct
     "'%s' internal stack %s" },
 { W_INT_OVL, ERROR_LEVEL_WARNING,
     "integer overflow in expression" },
+{ W_USELESS_DECL, ERROR_LEVEL_WARNING,
+    "useless declaration (possible use of keyword as variable name)" },
 };
 
 /*
index 70dade38beb4c94b6f6c2f5a922249bdc682e522..bb8510e42932729a9e96970df520fa3df3f75013 100644 (file)
@@ -181,6 +181,7 @@ SDCCERR - SDCC Standard error handler
 #define E_DUPLICATE_MEMBER 163
 #define E_STACK_VIOLATION 164       /* internal stack violation */
 #define W_INT_OVL 165               /* integer overflow in expression */
+#define W_USELESS_DECL 166         /* useless declaration */
 
 /** Describes the maximum error level that will be logged.  Any level
  *  includes all of the levels listed after it.