diff options
| author | Linus Torvalds <torvalds@home.transmeta.com> | 2003-04-04 10:37:59 -0700 |
|---|---|---|
| committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-07 21:00:08 -0700 |
| commit | 112e133ea8c6ca654a44ae555741da9dca385499 (patch) | |
| tree | 3231c6147759379240493458ab6da0f876d5f62f | |
| parent | d80b9c793e275a44061f1f08b6d50bb313d4451a (diff) | |
| download | sparse-dev-112e133ea8c6ca654a44ae555741da9dca385499.tar.gz | |
Evaluating a symbol turns into a dereference of the address
of the symbol. This also means that '&' works correctly, ie
&c
really evaluates into &(*'symbol c') == 'symbol c', which is
really what we want. The backend will thus always consider
symbol expressions to be nothing but addresses.
| -rw-r--r-- | evaluate.c | 24 | ||||
| -rw-r--r-- | show-parse.c | 11 |
2 files changed, 15 insertions, 20 deletions
@@ -44,14 +44,21 @@ static struct symbol *evaluate_symbol_expression(struct expression *expr) } /* The type of a symbol is the symbol itself! */ - expr->ctype = sym; + expr->ctype = base_type; /* enum's can be turned into plain values */ - if (base_type->type == SYM_ENUM) { - expr->type = EXPR_VALUE; - expr->value = sym->value; + if (base_type->type != SYM_ENUM) { + struct expression *addr = alloc_expression(expr->pos, EXPR_SYMBOL); + addr->symbol = sym; + addr->ctype = sym; + expr->type = EXPR_PREOP; + expr->op = '*'; + expr->unop = addr; + return base_type; } - return sym; + expr->type = EXPR_VALUE; + expr->value = sym->value; + return base_type; } static struct symbol *evaluate_string(struct expression *expr) @@ -652,15 +659,10 @@ static struct symbol *evaluate_addressof(struct expression *expr) ctype = op->ctype; -#if 0 /* Simplify: &*(expr) => (expr) */ if (op->type == EXPR_PREOP && op->op == '*') { - ctype = ctype->ctype.base_type; *expr = *op->unop; - expr->ctype = ctype; - return ctype; } -#endif symbol = alloc_symbol(expr->pos, SYM_PTR); symbol->ctype.base_type = ctype; @@ -705,7 +707,7 @@ static struct symbol *evaluate_dereference(struct expression *expr) examine_symbol_type(ctype); -#if 0 +#if 1 /* Simplify: *&(expr) => (expr) */ if (op->type == EXPR_PREOP && op->op == '&') { *expr = *op->unop; diff --git a/show-parse.c b/show-parse.c index 8fc922ca..c0da6d26 100644 --- a/show-parse.c +++ b/show-parse.c @@ -195,7 +195,7 @@ static void do_show_type(struct symbol *sym, struct type_name *name) default: prepend(name, "unknown type %d", sym->type); - break; + return; } mod = modifier_string(sym->ctype.modifiers); @@ -481,14 +481,7 @@ void show_expression(struct expression *expr) printf(" %s ", show_special(expr->op)); break; case EXPR_SYMBOL: - if (!expr->symbol) { - warn(expr->pos, "undefined symbol '%s'", show_ident(expr->symbol_name)); - printf("<nosymbol>"); - break; - } - printf("<%s:", show_ident(expr->symbol_name)); - show_type(expr->symbol->ctype.base_type); - printf(">"); + show_type(expr->symbol); break; case EXPR_DEREF: show_expression(expr->deref); |
