aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2019-12-17 01:13:38 +0100
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2019-12-17 01:13:38 +0100
commit3f90fa99393dd2b16eea3eaabe48e3e644890728 (patch)
tree7dd71f7737d48f5eba84b3ba1efde187b8429884
parent0f49afdec53446e7af20271519ae422d8d183360 (diff)
parente0d40e809a6ffd7630ab058df7b0ad08a8d355e2 (diff)
downloadsparse-3f90fa99393dd2b16eea3eaabe48e3e644890728.tar.gz
Merge branch 'eval-typeof' into next
* tidy-up of typeof expansion
-rw-r--r--evaluate.c10
-rw-r--r--symbol.c41
2 files changed, 27 insertions, 24 deletions
diff --git a/evaluate.c b/evaluate.c
index 4096566e..91547bc6 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -110,6 +110,8 @@ static struct symbol *evaluate_string(struct expression *expr)
sym->ctype.modifiers = MOD_STATIC;
sym->ctype.base_type = array;
sym->initializer = initstr;
+ sym->examined = 1;
+ sym->evaluated = 1;
initstr->ctype = sym;
initstr->string = expr->string;
@@ -119,6 +121,8 @@ static struct symbol *evaluate_string(struct expression *expr)
array->ctype.alignment = 1;
array->ctype.modifiers = MOD_STATIC;
array->ctype.base_type = &char_ctype;
+ array->examined = 1;
+ array->evaluated = 1;
addr->symbol = sym;
addr->ctype = &lazy_ptr_ctype;
@@ -379,10 +383,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) {
- type = evaluate_expression(type->initializer);
- if (!type)
- type = &bad_ctype;
- else if (type->type == SYM_NODE)
+ type = examine_symbol_type(type);
+ if (type->type == SYM_NODE)
type = type->ctype.base_type;
}
if (type->type == SYM_ENUM)
diff --git a/symbol.c b/symbol.c
index 3655cbb7..ab6e9841 100644
--- a/symbol.c
+++ b/symbol.c
@@ -453,6 +453,25 @@ static struct symbol *examine_pointer_type(struct symbol *sym)
return sym;
}
+static struct symbol *examine_typeof(struct symbol *sym)
+{
+ struct symbol *base = evaluate_expression(sym->initializer);
+ unsigned long mod = 0;
+
+ if (!base)
+ base = &bad_ctype;
+ if (base->type == SYM_NODE) {
+ mod |= base->ctype.modifiers & MOD_TYPEOF;
+ base = base->ctype.base_type;
+ }
+ if (base->type == SYM_BITFIELD)
+ warning(base->pos, "typeof applied to bitfield type");
+ sym->type = SYM_NODE;
+ sym->ctype.modifiers = mod;
+ sym->ctype.base_type = base;
+ return examine_node_type(sym);
+}
+
/*
* Fill in type size and alignment information for
* regular SYM_TYPE things.
@@ -486,26 +505,8 @@ struct symbol *examine_symbol_type(struct symbol * sym)
case SYM_BASETYPE:
/* Size and alignment had better already be set up */
return sym;
- case SYM_TYPEOF: {
- struct symbol *base = evaluate_expression(sym->initializer);
- if (base) {
- unsigned long mod = 0;
-
- if (is_bitfield_type(base))
- warning(base->pos, "typeof applied to bitfield type");
- if (base->type == SYM_NODE) {
- mod |= base->ctype.modifiers & MOD_TYPEOF;
- base = base->ctype.base_type;
- }
- sym->type = SYM_NODE;
- sym->ctype.modifiers = mod;
- sym->ctype.base_type = base;
- return examine_node_type(sym);
- }
- sym->type = SYM_NODE;
- sym->ctype.base_type = &bad_ctype;
- return sym;
- }
+ case SYM_TYPEOF:
+ return examine_typeof(sym);
case SYM_PREPROCESSOR:
sparse_error(sym->pos, "ctype on preprocessor command? (%s)", show_ident(sym->ident));
return NULL;