diff options
author | 2004-09-23 14:25:24 -0700 | |
---|---|---|
committer | 2005-04-07 21:03:17 -0700 | |
commit | 3c83edc32120201e1b35970be88ea1711cf30093 (patch) | |
tree | 2085aeed9c880c2b35397a8f839032783a0bfd4e /show-parse.c | |
parent | Print out the proper filename on open failure. (diff) | |
download | sparse-3c83edc32120201e1b35970be88ea1711cf30093.tar.gz sparse-3c83edc32120201e1b35970be88ea1711cf30093.tar.bz2 sparse-3c83edc32120201e1b35970be88ea1711cf30093.zip |
Totally re-do how we build up the initializer tree: make the
positional markers be hierarchical rather than a flat list.
This makes the data structure a bit more complex, but it simplifies
some of the code, and makes it possible to evaluate complex initializers
without going insane.
In particular, we how support
struct xxxx var = {
.a.b[10] = 1;
};
which we couldn't handle at all before (it had to
be written as
struct xxxx var = {
.a = {
.b = { [10] = 1; }
}
}
or similar.
The new code changes all array indexes and structure members
to EXPR_POS expressions offset from the "outer" scope (either
start of the symbol, or an outer EXPR_POS).
Diffstat (limited to 'show-parse.c')
-rw-r--r-- | show-parse.c | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/show-parse.c b/show-parse.c index 3856289..ae45354 100644 --- a/show-parse.c +++ b/show-parse.c @@ -914,7 +914,7 @@ static int show_statement_expr(struct expression *expr) static int show_position_expr(struct expression *expr, struct symbol *base) { int new = show_expression(expr->init_expr); - struct symbol *ctype = expr->init_sym; + struct symbol *ctype = expr->init_expr->ctype; printf("\tinsert v%d at [%d:%d] of %s\n", new, expr->init_offset, ctype->bit_offset, @@ -927,6 +927,8 @@ static int show_initializer_expr(struct expression *expr, struct symbol *ctype) struct expression *entry; FOR_EACH_PTR(expr->expr_list, entry) { + +again: // Nested initializers have their positions already // recursively calculated - just output them too if (entry->type == EXPR_INITIALIZER) { @@ -934,10 +936,19 @@ static int show_initializer_expr(struct expression *expr, struct symbol *ctype) continue; } - // Ignore initializer indexes and identifiers - the - // evaluator has taken them into account - if (entry->type == EXPR_IDENTIFIER || entry->type == EXPR_INDEX) - continue; + // Initializer indexes and identifiers should + // have been evaluated to EXPR_POS + if (entry->type == EXPR_IDENTIFIER) { + printf(" AT '%s':\n", show_ident(entry->expr_ident)); + entry = entry->ident_expression; + goto again; + } + + if (entry->type == EXPR_INDEX) { + printf(" AT '%d..%d:\n", entry->idx_from, entry->idx_to); + entry = entry->idx_expression; + goto again; + } if (entry->type == EXPR_POS) { show_position_expr(entry, ctype); continue; |