prelimiraries for -Wunused-parameter and -Wunused-variable:
authorMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Sat, 15 Dec 2007 03:22:36 +0000 (03:22 +0000)
committerMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Sat, 15 Dec 2007 03:22:36 +0000 (03:22 +0000)
- mark used declarations
- add field to link declarations
- recognize options (no warnings yet)

[r18761]

ast_t.h
parser.c
warning.c
warning.h

diff --git a/ast_t.h b/ast_t.h
index 7efa194..cb8b674 100644 (file)
--- a/ast_t.h
+++ b/ast_t.h
@@ -414,6 +414,8 @@ struct declaration_t {
        declaration_t      *next;
        /** next declaration with same symbol */
        declaration_t      *symbol_next;
+       /** next variable/parameter in function scope/global scope */
+       declaration_t      *next_var;
 
        /* the following fields are used in ast2firm module */
        unsigned char       declaration_kind;
index 10fd845..da48d6b 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -3217,6 +3217,9 @@ static expression_t *parse_reference(void)
        ref->declaration         = declaration;
        ref->expression.datatype = type;
 
+       /* this declaration is used */
+       declaration->used = true;
+
        return expression;
 }
 
index c1c076c..0453c65 100644 (file)
--- a/warning.c
+++ b/warning.c
@@ -37,6 +37,8 @@ void set_warning_opt(const char *const opt)
        OPT("switch-default",                switch_default)
        OPT("unknown-pragmas",               unknown_pragmas)
        OPT("unused-label",                  unused_label)
+       OPT("unused-parameter",              unused_parameter)
+       OPT("unused-variable",               unused_variable)
 #if 0
        OPTX("unused") {
                SET(unused_function)
@@ -72,5 +74,7 @@ warning_t warning = {
        .switch_default                = false,
        .unknown_pragmas               = true,
        .unused_label                  = false,
+       .unused_parameter              = false,
+       .unused_variable               = false,
        .unused_value                  = true
 };
index c251a70..87fc35a 100644 (file)
--- a/warning.h
+++ b/warning.h
@@ -75,10 +75,8 @@ typedef struct warning_t {
        bool unused_function:1;               /**< Warn whenever a static function is declared but not defined or a non-inline static function is unused */
 #endif
        bool unused_label:1;                  /**< Warn whenever a label is declared but not used */
-#if 0 // TODO
        bool unused_parameter:1;              /**< Warn whenever a function parameter is unused aside from its declaration */
        bool unused_variable:1;               /**< Warn whenever a local variable or non-constant static variable is unused aside from its declaration */
-#endif
        bool unused_value:1;                  /**< Warn whenever a statement computes a result that is explicitly not used */
 #if 0 // TODO
        bool write_strings:1;                 /**< Give string constants the type 'const char[LENGTH]' so that copying the address of one into a 'char *' pointer will get a warning */