diff options
author | 2004-05-26 12:59:14 -0700 | |
---|---|---|
committer | 2005-04-07 21:01:47 -0700 | |
commit | 0bde264e56a04bec4f3f0895609c9ca6ba21c221 (patch) | |
tree | 7f3f66665f714d61e877ab86ab47e330ff2bbe3e /expression.c | |
parent | More "noderef" validation examples (diff) | |
download | sparse-0bde264e56a04bec4f3f0895609c9ca6ba21c221.tar.gz sparse-0bde264e56a04bec4f3f0895609c9ca6ba21c221.tar.bz2 sparse-0bde264e56a04bec4f3f0895609c9ca6ba21c221.zip |
"a->b" is just shorthand for "(*a).b".
So let's make that explicit in the parse tree, and avoid
carrying the special cases around further. This makes the
evaluation phase only have one case to worry about.
Diffstat (limited to 'expression.c')
-rw-r--r-- | expression.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/expression.c b/expression.c index d02452c..2133379 100644 --- a/expression.c +++ b/expression.c @@ -300,10 +300,17 @@ static struct token *postfix_expression(struct token *token, struct expression * token = token->next; continue; } - case '.': /* Structure member dereference */ case SPECIAL_DEREFERENCE: { /* Structure pointer member dereference */ + /* "x->y" is just shorthand for "(*x).y" */ + struct expression *inner = alloc_expression(token->pos, EXPR_PREOP); + inner->op = '*'; + inner->unop = expr; + expr = inner; + } + /* Fallthrough!! */ + case '.': { /* Structure member dereference */ struct expression *deref = alloc_expression(token->pos, EXPR_DEREF); - deref->op = token->special; + deref->op = '.'; deref->deref = expr; token = token->next; if (token_type(token) != TOKEN_IDENT) { |