Skip to content

Commit

Permalink
Reduce AST ambiguity in pointer comparison between e1 == e2 and `e1…
Browse files Browse the repository at this point in the history
… is e2`

By this additional translation, we can have only one semantic analysis result for the equivalent expression forms.
  • Loading branch information
9rnsr committed Aug 6, 2015
1 parent 3252ddc commit f802a93
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/expression.c
Expand Up @@ -13571,6 +13571,18 @@ Expression *EqualExp::semantic(Scope *sc)
return e;
}

if (t1->ty == Tpointer || t2->ty == Tpointer)
{
/* Rewrite:
* ptr1 == ptr2
* as:
* ptr1 is ptr2
*/
e = new IdentityExp(op == TOKequal ? TOKidentity : TOKnotidentity, loc, e1, e2);
e = e->semantic(sc);
return e;
}

if (t1->ty == Tstruct && t2->ty == Tstruct)
{
StructDeclaration *sd = ((TypeStruct *)t1)->sym;
Expand Down

0 comments on commit f802a93

Please sign in to comment.