Use a null pointer for marking the current position as unreachable again.
[cparser] / walk_statements.c
index 242b6f3..883a889 100644 (file)
@@ -1,3 +1,22 @@
+/*
+ * 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.
+ */
 #include <config.h>
 
 #include "adt/error.h"
 #include "walk_statements.h"
 
 
-static void walk_expression(expression_t const *const expr, statement_callback const callback, void *const env)
+static void walk_expression(expression_t const *const expr,
+                            statement_callback const callback, void *const env)
 {
        switch (expr->base.kind) {
-               case EXPR_STATEMENT:
-                       walk_statements(expr->statement.statement, callback, env);
-                       return;
+       case EXPR_STATEMENT:
+               walk_statements(expr->statement.statement, callback, env);
+               return;
 
-               EXPR_BINARY_CASES
-                       walk_expression(expr->binary.left,  callback, env);
-                       walk_expression(expr->binary.right, callback, env);
-                       return;
+       EXPR_BINARY_CASES
+               walk_expression(expr->binary.left,  callback, env);
+               walk_expression(expr->binary.right, callback, env);
+               return;
 
-               EXPR_UNARY_CASES_OPTIONAL
-                       if (expr->unary.value == NULL)
-                               return;
-                       /* FALLTHROUGH */
-               EXPR_UNARY_CASES_MANDATORY
-                       walk_expression(expr->unary.value, callback, env);
+       EXPR_UNARY_CASES_OPTIONAL
+               if (expr->unary.value == NULL)
                        return;
+               /* FALLTHROUGH */
+       EXPR_UNARY_CASES_MANDATORY
+               walk_expression(expr->unary.value, callback, env);
+               return;
 
-               case EXPR_CALL:
-                       for (call_argument_t *arg = expr->call.arguments; arg != NULL; arg = arg->next) {
-                               walk_expression(arg->expression, callback, env);
-                       }
-                       return;
+       case EXPR_CALL:
+               for (call_argument_t *arg = expr->call.arguments; arg != NULL;
+                    arg = arg->next) {
+                       walk_expression(arg->expression, callback, env);
+               }
+               return;
 
-               case EXPR_UNKNOWN:
-               case EXPR_INVALID:
-                       panic("unexpected expr kind");
+       case EXPR_UNKNOWN:
+               panic("unexpected expr kind");
 
-               case EXPR_COMPOUND_LITERAL:
-                       /* TODO... */
-                       break;
+       case EXPR_COMPOUND_LITERAL:
+               /* TODO... */
+               break;
 
-               case EXPR_CONDITIONAL:
-                       walk_expression(expr->conditional.condition,        callback, env);
+       case EXPR_CONDITIONAL:
+               walk_expression(expr->conditional.condition,        callback, env);
+               /* may be NULL because of gnu extension */
+               if (expr->conditional.true_expression != NULL)
                        walk_expression(expr->conditional.true_expression,  callback, env);
-                       walk_expression(expr->conditional.false_expression, callback, env);
-                       return;
-
-               case EXPR_BUILTIN_PREFETCH:
-                       walk_expression(expr->builtin_prefetch.adr,      callback, env);
-                       walk_expression(expr->builtin_prefetch.rw,       callback, env);
-                       walk_expression(expr->builtin_prefetch.locality, callback, env);
-                       return;
+               walk_expression(expr->conditional.false_expression, callback, env);
+               return;
 
-               case EXPR_BUILTIN_CONSTANT_P:
-                       walk_expression(expr->builtin_constant.value, callback, env);
-                       return;
+       case EXPR_BUILTIN_CONSTANT_P:
+               walk_expression(expr->builtin_constant.value, callback, env);
+               return;
 
-               case EXPR_SELECT:
-                       walk_expression(expr->select.compound, callback, env);
-                       return;
+       case EXPR_SELECT:
+               walk_expression(expr->select.compound, callback, env);
+               return;
 
-               case EXPR_ARRAY_ACCESS:
-                       walk_expression(expr->array_access.array_ref, callback, env);
-                       walk_expression(expr->array_access.index,     callback, env);
-                       return;
+       case EXPR_ARRAY_ACCESS:
+               walk_expression(expr->array_access.array_ref, callback, env);
+               walk_expression(expr->array_access.index,     callback, env);
+               return;
 
-               case EXPR_CLASSIFY_TYPE:
-                       walk_expression(expr->classify_type.type_expression, callback, env);
-                       return;
+       case EXPR_CLASSIFY_TYPE:
+               walk_expression(expr->classify_type.type_expression, callback, env);
+               return;
 
-               case EXPR_SIZEOF:
-               case EXPR_ALIGNOF: {
-                       expression_t *tp_expression = expr->typeprop.tp_expression;
-                       if (tp_expression != NULL) {
-                               walk_expression(tp_expression, callback, env);
-                       }
-                       return;
+       case EXPR_SIZEOF:
+       case EXPR_ALIGNOF: {
+               expression_t *tp_expression = expr->typeprop.tp_expression;
+               if (tp_expression != NULL) {
+                       walk_expression(tp_expression, callback, env);
                }
+               return;
+       }
+
+       case EXPR_VA_START:
+               walk_expression(expr->va_starte.ap, callback, env);
+               return;
+
+       case EXPR_VA_ARG:
+               walk_expression(expr->va_arge.ap, callback, env);
+               return;
+
+       case EXPR_VA_COPY:
+               walk_expression(expr->va_copye.src, callback, env);
+               walk_expression(expr->va_copye.dst, callback, env);
+               return;
 
-               case EXPR_OFFSETOF:
-               case EXPR_REFERENCE:
-               case EXPR_REFERENCE_ENUM_VALUE:
-               case EXPR_CONST:
-               case EXPR_CHARACTER_CONSTANT:
-               case EXPR_WIDE_CHARACTER_CONSTANT:
-               case EXPR_STRING_LITERAL:
-               case EXPR_WIDE_STRING_LITERAL:
-               case EXPR_FUNCNAME:
-               case EXPR_BUILTIN_SYMBOL:
-               case EXPR_VA_START:
-               case EXPR_VA_ARG:
-               case EXPR_LABEL_ADDRESS:
-                       break;
+       EXPR_LITERAL_CASES
+       case EXPR_INVALID:
+       case EXPR_OFFSETOF:
+       case EXPR_REFERENCE:
+       case EXPR_REFERENCE_ENUM_VALUE:
+       case EXPR_STRING_LITERAL:
+       case EXPR_WIDE_STRING_LITERAL:
+       case EXPR_FUNCNAME:
+       case EXPR_LABEL_ADDRESS:
+       case EXPR_BUILTIN_TYPES_COMPATIBLE_P:
+               break;
        }
 
        /* TODO FIXME: implement all the missing expressions here */
@@ -112,10 +138,11 @@ static void walk_initializer(const initializer_t  *initializer,
 }
 
 static void walk_declarations(const entity_t*            entity,
-                              const entity_t*      const end,
+                              const entity_t*      const last,
                               statement_callback   const callback,
                               void                *const env)
 {
+       entity_t const *const end = last != NULL ? last->base.next : NULL;
        for (; entity != end; entity = entity->base.next) {
                /* we only look at variables */
                if (entity->kind != ENTITY_VARIABLE)
@@ -193,8 +220,7 @@ void walk_statements(statement_t *const stmt, statement_callback const callback,
 
                case STATEMENT_DECLARATION:
                        walk_declarations(stmt->declaration.declarations_begin,
-                                         stmt->declaration.declarations_end->base.next,
-                                         callback, env);
+                                       stmt->declaration.declarations_end, callback, env);
                        return;
 
                case STATEMENT_MS_TRY:
@@ -202,7 +228,6 @@ void walk_statements(statement_t *const stmt, statement_callback const callback,
                        walk_statements(stmt->ms_try.final_statement, callback, env);
                        return;
 
-               case STATEMENT_LOCAL_LABEL:
                case STATEMENT_INVALID:
                case STATEMENT_EMPTY:
                case STATEMENT_CONTINUE: