diff options
| author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-07-31 01:06:09 +0200 |
|---|---|---|
| committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-07-31 01:06:09 +0200 |
| commit | 5fc204f2ec2d3ec038848db3f3bdb9fead782b4c (patch) | |
| tree | 129c519e457d389e7bf17407183d8e93a28d906a /parse.c | |
| parent | 9d3aa4b96b853c82da6940c1fed3a4e5801c5d90 (diff) | |
| parent | 7cdd65dd26cc523b3ff6d4acfc19488a47be8d7b (diff) | |
| download | sparse-dev-5fc204f2ec2d3ec038848db3f3bdb9fead782b4c.tar.gz | |
Merge branch 'array-decl'
Diffstat (limited to 'parse.c')
| -rw-r--r-- | parse.c | 53 |
1 files changed, 16 insertions, 37 deletions
@@ -171,7 +171,7 @@ static struct symbol_op register_op = { }; static struct symbol_op static_op = { - .type = KW_MODIFIER, + .type = KW_MODIFIER|KW_STATIC, .declarator = static_specifier, }; @@ -678,24 +678,6 @@ static void fn_local_symbol(struct symbol *sym) add_symbol(function_symbol_list, sym); } -static int SENTINEL_ATTR match_idents(struct token *token, ...) -{ - va_list args; - struct ident * next; - - if (token_type(token) != TOKEN_IDENT) - return 0; - - va_start(args, token); - do { - next = va_arg(args, struct ident *); - } while (next && token->ident != next); - va_end(args); - - return next && token->ident == next; -} - - struct statement *alloc_statement(struct position pos, int type) { struct statement *stmt = __alloc_statement(0); @@ -1711,29 +1693,26 @@ static struct token *declaration_specifiers(struct token *token, struct decl_sta return token; } -static struct token *abstract_array_static_declarator(struct token *token, int *has_static) -{ - while (token->ident == &static_ident) { - if (*has_static) - sparse_error(token->pos, "duplicate array static declarator"); - - *has_static = 1; - token = token->next; - } - return token; - -} - static struct token *abstract_array_declarator(struct token *token, struct symbol *sym) { struct expression *expr = NULL; int has_static = 0; - token = abstract_array_static_declarator(token, &has_static); - - if (match_idents(token, &restrict_ident, &__restrict_ident, &__restrict___ident, NULL)) - token = abstract_array_static_declarator(token->next, &has_static); - token = parse_expression(token, &expr); + while (token_type(token) == TOKEN_IDENT) { + struct symbol *sym = lookup_keyword(token->ident, NS_TYPEDEF); + if (!sym || !(sym->op->type & (KW_STATIC|KW_QUALIFIER))) + break; + if (has_static && (sym->op->type & KW_STATIC)) + sparse_error(token->pos, "duplicate array static declarator"); + has_static |= (sym->op->type & KW_STATIC); + token = token->next; + } + if (match_op(token, '*') && match_op(token->next, ']')) { + // FIXME: '[*]' is treated like '[]' + token = token->next; + } else { + token = assignment_expression(token, &expr); + } sym->array_size = expr; return token; } |
