parser: Parse and reject GCC range initializers "[0 ... 9]".
authorChristoph Mallon <christoph.mallon@gmx.de>
Wed, 12 Dec 2012 13:07:48 +0000 (14:07 +0100)
committerChristoph Mallon <christoph.mallon@gmx.de>
Wed, 12 Dec 2012 15:57:19 +0000 (16:57 +0100)
ast.c
ast_t.h
parser.c

diff --git a/ast.c b/ast.c
index 84367c8..adb0b73 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -599,6 +599,10 @@ static void print_designator(const designator_t *designator)
                if (designator->symbol == NULL) {
                        print_char('[');
                        print_expression(designator->array_index);
+                       if (designator->range_last) {
+                               print_string(" ... ");
+                               print_expression(designator->range_last);
+                       }
                        print_char(']');
                } else {
                        print_char('.');
diff --git a/ast_t.h b/ast_t.h
index b980f90..e0371e7 100644 (file)
--- a/ast_t.h
+++ b/ast_t.h
@@ -348,6 +348,7 @@ struct designator_t {
        position_t    pos;
        symbol_t     *symbol;      /**< the symbol if any */
        expression_t *array_index; /**< the array index if any */
+       expression_t *range_last;  /**< last index of a range initializer, if any */
        designator_t *next;
 };
 
index a0df559..5fec2af 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -1535,7 +1535,13 @@ static designator_t *parse_designation(void)
                        designator->pos = *HERE;
                        eat('[');
                        add_anchor_token(']');
+                       add_anchor_token(T_DOTDOTDOT);
                        designator->array_index = parse_constant_expression();
+                       if (accept(T_DOTDOTDOT)) {
+                               designator->range_last = parse_constant_expression();
+                               errorf(&designator->pos, "range initializer not supported");
+                       }
+                       rem_anchor_token(T_DOTDOTDOT);
                        rem_anchor_token(']');
                        expect(']');
                        break;