aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/parse.c
diff options
Diffstat (limited to 'parse.c')
-rw-r--r--parse.c53
1 files changed, 16 insertions, 37 deletions
diff --git a/parse.c b/parse.c
index b07237ee..5f587ce6 100644
--- a/parse.c
+++ b/parse.c
@@ -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;
}