@@ -670,18 +670,17 @@ struct statement *alloc_statement(struct position pos, int type)
static struct token *struct_declaration_list(struct token *token, struct symbol_list **list);
-static void apply_modifiers(struct position pos, struct decl_state *ctx)
+static void apply_modifiers(struct decl_state *ctx)
{
struct symbol *ctype;
if (!ctx->mode)
return;
ctype = ctx->mode->to_mode(ctx->ctype.base_type);
if (!ctype)
- sparse_error(pos, "don't know how to apply mode to %s",
+ sparse_error(ctx->mode_pos, "don't know how to apply mode to %s",
show_typename(ctx->ctype.base_type));
else
ctx->ctype.base_type = ctype;
-
}
static struct symbol * alloc_indirect_symbol(struct position pos, struct ctype *ctype, int type)
@@ -1233,10 +1232,12 @@ static struct token *attribute_mode(struct token *token, struct symbol *attr, st
token = expect(token, '(', "after mode attribute");
if (token_type(token) == TOKEN_IDENT) {
struct symbol *mode = lookup_keyword(token->ident, NS_KEYWORD);
- if (mode && mode->op->type == KW_MODE)
+ if (mode && mode->op->type == KW_MODE) {
ctx->mode = mode->op;
- else
+ ctx->mode_pos = token->pos;
+ } else {
sparse_error(token->pos, "unknown mode attribute %s", show_ident(token->ident));
+ }
token = token->next;
} else
sparse_error(token->pos, "expect attribute mode symbol\n");
@@ -1969,7 +1970,7 @@ static struct token *declaration_list(struct token *token, struct symbol_list **
token = handle_bitfield(token, &ctx);
token = handle_attributes(token, &ctx, KW_ATTRIBUTE);
- apply_modifiers(token->pos, &ctx);
+ apply_modifiers(&ctx);
decl->ctype = ctx.ctype;
decl->ctype.modifiers |= mod;
@@ -2009,7 +2010,7 @@ static struct token *parameter_declaration(struct token *token, struct symbol *s
ctx.ident = &sym->ident;
token = declarator(token, &ctx);
token = handle_attributes(token, &ctx, KW_ATTRIBUTE);
- apply_modifiers(token->pos, &ctx);
+ apply_modifiers(&ctx);
sym->ctype = ctx.ctype;
sym->ctype.modifiers |= storage_modifiers(&ctx);
sym->endpos = token->pos;
@@ -2025,7 +2026,7 @@ struct token *typename(struct token *token, struct symbol **p, int *forced)
*p = sym;
token = declaration_specifiers(token, &ctx);
token = declarator(token, &ctx);
- apply_modifiers(token->pos, &ctx);
+ apply_modifiers(&ctx);
sym->ctype = ctx.ctype;
sym->endpos = token->pos;
class = ctx.storage_class;
@@ -2918,14 +2919,14 @@ struct token *external_declaration(struct token *token, struct symbol_list **lis
decl = alloc_symbol(token->pos, SYM_NODE);
/* Just a type declaration? */
if (match_op(token, ';')) {
- apply_modifiers(token->pos, &ctx);
+ apply_modifiers(&ctx);
return token->next;
}
saved = ctx.ctype;
token = declarator(token, &ctx);
token = handle_attributes(token, &ctx, KW_ATTRIBUTE | KW_ASM);
- apply_modifiers(token->pos, &ctx);
+ apply_modifiers(&ctx);
decl->ctype = ctx.ctype;
decl->ctype.modifiers |= mod;
@@ -3021,7 +3022,7 @@ struct token *external_declaration(struct token *token, struct symbol_list **lis
token = handle_attributes(token, &ctx, KW_ATTRIBUTE);
token = declarator(token, &ctx);
token = handle_attributes(token, &ctx, KW_ATTRIBUTE | KW_ASM);
- apply_modifiers(token->pos, &ctx);
+ apply_modifiers(&ctx);
decl->ctype = ctx.ctype;
decl->ctype.modifiers |= mod;
decl->endpos = token->pos;
@@ -109,6 +109,7 @@ struct decl_state {
struct ctype ctype;
struct ident **ident;
struct symbol_op *mode;
+ struct position mode_pos;
unsigned char prefer_abstract, is_inline, storage_class, is_tls;
unsigned char is_ext_visible;
};
apply_modifiers() is given a position for a warning that can possibly be issued but: * this position is the one of the token following the attributes * the warning is about a mode that can't be applied. Fix this by storing the position with the mode in the decl_state. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com> --- parse.c | 23 ++++++++++++----------- symbol.h | 1 + 2 files changed, 13 insertions(+), 11 deletions(-)