diff options
author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-08-15 00:32:29 +0200 |
---|---|---|
committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-08-15 17:08:07 +0200 |
commit | 8b5d92da3b1919f574decb542d93fde82693fe71 (patch) | |
tree | 4b448a81a938686152139a9d1bc73fe5f8f98f66 | |
parent | c73a5a4bbcb30f176be5b82969b5d681b8481bc5 (diff) | |
download | sparse-8b5d92da3b1919f574decb542d93fde82693fe71.tar.gz |
union-cast: extract evaluate_compound_literal()
extract evaluate_compound_literal() from evaluate_cast,
in preparation for supporting union casts.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r-- | evaluate.c | 41 |
1 files changed, 22 insertions, 19 deletions
@@ -2948,6 +2948,26 @@ static int cast_flags(struct expression *expr, struct expression *old) return flags; } +static struct symbol *evaluate_compound_literal(struct expression *expr, struct expression *source) +{ + struct expression *addr = alloc_expression(expr->pos, EXPR_SYMBOL); + struct symbol *sym = expr->cast_type; + + sym->initializer = source; + evaluate_symbol(sym); + + addr->ctype = &lazy_ptr_ctype; /* Lazy eval */ + addr->symbol = sym; + if (sym->ctype.modifiers & MOD_TOPLEVEL) + addr->flags |= CEF_ADDR; + + expr->type = EXPR_PREOP; + expr->op = '*'; + expr->deref = addr; + expr->ctype = sym; + return sym; +} + static struct symbol *evaluate_cast(struct expression *expr) { struct expression *source = expr->cast_expression; @@ -2970,25 +2990,8 @@ static struct symbol *evaluate_cast(struct expression *expr) * dereferenced as part of a post-fix expression. * We need to produce an expression that can be dereferenced. */ - if (source->type == EXPR_INITIALIZER) { - struct symbol *sym = expr->cast_type; - struct expression *addr = alloc_expression(expr->pos, EXPR_SYMBOL); - - sym->initializer = source; - evaluate_symbol(sym); - - addr->ctype = &lazy_ptr_ctype; /* Lazy eval */ - addr->symbol = sym; - if (sym->ctype.modifiers & MOD_TOPLEVEL) - addr->flags |= CEF_ADDR; - - expr->type = EXPR_PREOP; - expr->op = '*'; - expr->unop = addr; - expr->ctype = sym; - - return sym; - } + if (source->type == EXPR_INITIALIZER) + return evaluate_compound_literal(expr, source); ctype = examine_symbol_type(expr->cast_type); expr->ctype = ctype; |