type: Make an assert()ion independent of the last entry of an enum.
[cparser] / walk.c
diff --git a/walk.c b/walk.c
index 62a46a2..647a814 100644 (file)
--- a/walk.c
+++ b/walk.c
@@ -1,21 +1,6 @@
 /*
  * This file is part of cparser.
- * Copyright (C) 2007-2009 Matthias Braun <matze@braunis.de>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
+ * Copyright (C) 2012 Matthias Braun <matze@braunis.de>
  */
 #include <config.h>
 
@@ -83,7 +68,7 @@ static void walk_type(type_t *const type, const walk_env_t *const env)
                walk_entity((entity_t*)type->enumt.enume, env);
                return;
        }
-       panic("invalid type found");
+       panic("invalid type");
 }
 
 static void walk_expression(expression_t *const expr,
@@ -177,10 +162,10 @@ static void walk_expression(expression_t *const expr,
                return;
 
        case EXPR_LITERAL_CASES:
+       case EXPR_LITERAL_CHARACTER:
        case EXPR_REFERENCE:
-       case EXPR_REFERENCE_ENUM_VALUE:
+       case EXPR_ENUM_CONSTANT:
        case EXPR_STRING_LITERAL:
-       case EXPR_WIDE_STRING_LITERAL:
        case EXPR_FUNCNAME:
        case EXPR_LABEL_ADDRESS:
        case EXPR_ERROR:
@@ -201,7 +186,7 @@ static void walk_designator(const designator_t *designator,
 static void walk_initializer(const initializer_t  *initializer,
                              const walk_env_t *const env)
 {
-       switch(initializer->kind) {
+       switch (initializer->kind) {
        case INITIALIZER_VALUE:
                walk_expression(initializer->value.value, env);
                return;
@@ -214,8 +199,8 @@ static void walk_initializer(const initializer_t  *initializer,
        case INITIALIZER_DESIGNATOR:
                walk_designator(initializer->designator.designator, env);
                return;
+
        case INITIALIZER_STRING:
-       case INITIALIZER_WIDE_STRING:
                return;
        }
 }
@@ -243,8 +228,8 @@ static void walk_entity(entity_t *entity, const walk_env_t *const env)
                return;
        case ENTITY_FUNCTION:
                walk_type(entity->declaration.type, env);
-               if (entity->function.statement != NULL)
-                       walk_statement(entity->function.statement, env);
+               if (entity->function.body != NULL)
+                       walk_statement(entity->function.body, env);
                return;
        case ENTITY_COMPOUND_MEMBER:
        case ENTITY_PARAMETER:
@@ -269,7 +254,7 @@ static void walk_entity(entity_t *entity, const walk_env_t *const env)
        case ENTITY_LOCAL_LABEL:
                return;
        }
-       panic("invalid entity found");
+       panic("invalid entity");
 }
 
 static void walk_declarations(entity_t*            entity,
@@ -327,14 +312,14 @@ static void walk_statement(statement_t *const stmt, const walk_env_t *const env)
                return;
 
        case STATEMENT_CASE_LABEL:
+               if (stmt->case_label.expression) {
+                       walk_expression(stmt->case_label.expression, env);
+                       if (stmt->case_label.end_range)
+                               walk_expression(stmt->case_label.end_range, env);
+               }
                walk_statement(stmt->case_label.statement, env);
                return;
 
-       case STATEMENT_WHILE:
-               walk_expression(stmt->whiles.condition, env);
-               walk_statement(stmt->whiles.body, env);
-               return;
-
        case STATEMENT_DO_WHILE:
                walk_statement(stmt->do_while.body, env);
                walk_expression(stmt->do_while.condition, env);