diff options
| -rw-r--r-- | ast-inspect.c | 1 | ||||
| -rw-r--r-- | ctags.c | 1 | ||||
| -rw-r--r-- | dissect.c | 1 | ||||
| -rw-r--r-- | evaluate.c | 3 | ||||
| -rw-r--r-- | parse.c | 24 | ||||
| -rw-r--r-- | show-parse.c | 1 | ||||
| -rw-r--r-- | symbol.c | 17 | ||||
| -rw-r--r-- | symbol.h | 1 |
8 files changed, 44 insertions, 5 deletions
diff --git a/ast-inspect.c b/ast-inspect.c index b510cd9b..e940a93a 100644 --- a/ast-inspect.c +++ b/ast-inspect.c @@ -110,6 +110,7 @@ static const char *symbol_type_name(enum type type) [SYM_UNION] = "SYM_UNION", [SYM_ENUM] = "SYM_ENUM", [SYM_TYPEOF] = "SYM_TYPEOF", + [SYM_TYPEOF_UNQUAL] = "SYM_TYPEOF_UNQUAL", [SYM_BITFIELD] = "SYM_BITFIELD", [SYM_LABEL] = "SYM_LABEL", [SYM_RESTRICT] = "SYM_RESTRICT", @@ -151,6 +151,7 @@ static void examine_symbol(struct symbol *sym) sym->kind = 'e'; case SYM_PTR: case SYM_TYPEOF: + case SYM_TYPEOF_UNQUAL: case SYM_BITFIELD: case SYM_FN: case SYM_ARRAY: @@ -212,6 +212,7 @@ static void examine_sym_node(struct symbol *node, struct symbol *parent) while ((base = node->ctype.base_type) != NULL) switch (base->type) { case SYM_TYPEOF: + case SYM_TYPEOF_UNQUAL: node->ctype.base_type = do_expression(U_VOID, base->initializer); break; @@ -358,7 +358,8 @@ static inline int classify_type(struct symbol *type, struct symbol **base) }; if (type->type == SYM_NODE) type = type->ctype.base_type; - if (type->type == SYM_TYPEOF) { + if (type->type == SYM_TYPEOF || + type->type == SYM_TYPEOF_UNQUAL) { type = examine_symbol_type(type); if (type->type == SYM_NODE) type = type->ctype.base_type; @@ -54,7 +54,7 @@ static struct token *handle_attributes(struct token *token, struct decl_state *c typedef struct token *declarator_t(struct token *, struct symbol *, struct decl_state *); static declarator_t struct_specifier, union_specifier, enum_specifier, - attribute_specifier, typeof_specifier, + attribute_specifier, typeof_specifier, typeof_unqual_specifier, storage_specifier, thread_specifier; static declarator_t generic_qualifier; static declarator_t autotype_specifier; @@ -196,6 +196,13 @@ static struct symbol_op typeof_op = { .set = Set_S|Set_T, }; +static struct symbol_op typeof_unqual_op = { + .type = KW_SPECIFIER, + .declarator = typeof_unqual_specifier, + .test = Set_Any, + .set = Set_S|Set_T, +}; + static struct symbol_op autotype_op = { .type = KW_SPECIFIER, .declarator = autotype_specifier, @@ -480,6 +487,7 @@ static struct init_keyword { /* Typedef ... */ N("typedef", &typedef_op, .mods = MOD_USERTYPE), A("typeof", &typeof_op), + A("typeof_unqual", &typeof_unqual_op), N("__auto_type", &autotype_op), /* Type qualifiers */ @@ -1052,7 +1060,7 @@ static struct token *enum_specifier(struct token *token, struct symbol *sym, str return ret; } -static struct token *typeof_specifier(struct token *token, struct symbol *sym, struct decl_state *ctx) +static struct token *typeof_specifier_helper(struct token *token, struct symbol *sym, struct decl_state *ctx, bool qual) { if (!match_op(token, '(')) { @@ -1065,7 +1073,7 @@ static struct token *typeof_specifier(struct token *token, struct symbol *sym, s ctx->ctype.base_type = sym->ctype.base_type; apply_ctype(token->pos, &ctx->ctype, &sym->ctype); } else { - struct symbol *typeof_sym = alloc_symbol(token->pos, SYM_TYPEOF); + struct symbol *typeof_sym = alloc_symbol(token->pos, qual? SYM_TYPEOF : SYM_TYPEOF_UNQUAL); token = parse_expression(token->next, &typeof_sym->initializer); typeof_sym->endpos = token->pos; @@ -1078,6 +1086,16 @@ static struct token *typeof_specifier(struct token *token, struct symbol *sym, s return expect(token, ')', "after typeof"); } +static struct token *typeof_specifier(struct token *token, struct symbol *sym, struct decl_state *ctx) +{ + return typeof_specifier_helper(token, sym, ctx, true); +} + +static struct token *typeof_unqual_specifier(struct token *token, struct symbol *sym, struct decl_state *ctx) +{ + return typeof_specifier_helper(token, sym, ctx, false); +} + static struct token *autotype_specifier(struct token *token, struct symbol *sym, struct decl_state *ctx) { ctx->ctype.base_type = &autotype_ctype; diff --git a/show-parse.c b/show-parse.c index e2fc18bb..ceb6b3cb 100644 --- a/show-parse.c +++ b/show-parse.c @@ -59,6 +59,7 @@ static void do_debug_symbol(struct symbol *sym, int indent) [SYM_UNION] = "unin", [SYM_ENUM] = "enum", [SYM_TYPEOF] = "tpof", + [SYM_TYPEOF_UNQUAL] = "tpof_unqual", [SYM_BITFIELD] = "bitf", [SYM_LABEL] = "labl", [SYM_RESTRICT] = "rstr", @@ -541,7 +541,7 @@ static struct symbol *examine_pointer_type(struct symbol *sym) return sym; } -static struct symbol *examine_typeof(struct symbol *sym) +static struct symbol *examine_typeof_helper(struct symbol *sym, bool qual) { struct symbol *base = evaluate_expression(sym->initializer); unsigned long mod = 0; @@ -550,6 +550,8 @@ static struct symbol *examine_typeof(struct symbol *sym) base = &bad_ctype; if (base->type == SYM_NODE) { mod |= base->ctype.modifiers & MOD_TYPEOF; + if (!qual) + mod &= ~MOD_QUALIFIER; base = base->ctype.base_type; } if (base->type == SYM_BITFIELD) @@ -560,6 +562,16 @@ static struct symbol *examine_typeof(struct symbol *sym) return examine_node_type(sym); } +static struct symbol *examine_typeof(struct symbol *sym) +{ + return examine_typeof_helper(sym, true); +} + +static struct symbol *examine_typeof_unqual(struct symbol *sym) +{ + return examine_typeof_helper(sym, false); +} + /* * Fill in type size and alignment information for * regular SYM_TYPE things. @@ -595,6 +607,8 @@ struct symbol *examine_symbol_type(struct symbol * sym) return sym; case SYM_TYPEOF: return examine_typeof(sym); + case SYM_TYPEOF_UNQUAL: + return examine_typeof_unqual(sym); case SYM_PREPROCESSOR: sparse_error(sym->pos, "ctype on preprocessor command? (%s)", show_ident(sym->ident)); return NULL; @@ -628,6 +642,7 @@ const char* get_type_name(enum type type) [SYM_UNION] = "union", [SYM_ENUM] = "enum", [SYM_TYPEOF] = "typeof", + [SYM_TYPEOF_UNQUAL] = "typeof_unqual", [SYM_BITFIELD] = "bitfield", [SYM_LABEL] = "label", [SYM_RESTRICT] = "restrict", @@ -65,6 +65,7 @@ enum type { SYM_UNION, SYM_ENUM, SYM_TYPEOF, + SYM_TYPEOF_UNQUAL, SYM_BITFIELD, SYM_LABEL, SYM_RESTRICT, |
