diff options
| author | Linus Torvalds <torvalds@penguin.transmeta.com> | 2003-03-31 13:50:39 -0700 |
|---|---|---|
| committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-07 20:59:56 -0700 |
| commit | 9dfc1770c773dbfb1c8e4a853ca2eb534a0a8901 (patch) | |
| tree | fb585d52532286200fba0b73a1f458c8c8731d5c | |
| parent | 79ac96f9acb6805c95d362c642cddb1531c4be9e (diff) | |
| download | sparse-dev-9dfc1770c773dbfb1c8e4a853ca2eb534a0a8901.tar.gz | |
Parse array initializer index specifiers:
int test[] = {
[0...3] = 5,
[4...6] = 3
};
| -rw-r--r-- | parse.c | 24 |
1 files changed, 24 insertions, 0 deletions
@@ -726,6 +726,23 @@ static struct expression *identifier_expression(struct token *token) return expr; } +static struct expression *index_expression(struct expression *from, struct expression *to) +{ + int idx_from, idx_to; + struct expression *expr = alloc_expression(from->pos, EXPR_INDEX); + + idx_from = get_expression_value(from); + idx_to = idx_from; + if (to) { + idx_to = get_expression_value(to); + if (idx_to < idx_from) + warn(from->pos, "nonsense array initializer index range"); + } + expr->idx_from = idx_from; + expr->idx_to = idx_to; + return expr; +} + static struct token *initializer_list(struct expression_list **list, struct token *token) { for (;;) { @@ -738,6 +755,13 @@ static struct token *initializer_list(struct expression_list **list, struct toke } else if ((token_type(token) == TOKEN_IDENT) && match_op(next, ':')) { add_expression(list, identifier_expression(token)); token = next->next; + } else if (match_op(token, '[')) { + struct expression *from = NULL, *to = NULL; + token = constant_expression(token->next, &from); + if (match_op(token, SPECIAL_ELLIPSIS)) + token = constant_expression(token->next, &to); + add_expression(list, index_expression(from, to)); + token = expect(token, ']', "at end of initializer index"); } expr = NULL; |
