Skip to content

Commit

Permalink
fix CTFE interpreter
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed May 16, 2014
1 parent 8c3580d commit 240fcae
Showing 1 changed file with 7 additions and 25 deletions.
32 changes: 7 additions & 25 deletions src/interpret.c
Expand Up @@ -6166,11 +6166,13 @@ class Interpreter : public Visitor
result->type = e->type;
return;
}

// It's possible we have an array bounds error. We need to make sure it
// errors with this line number, not the one where the pointer was set.
result = e->e1->interpret(istate);
if (exceptionOrCantInterpret(result))
return;

if (!(result->op == TOKvar || result->op == TOKdotvar || result->op == TOKindex
|| result->op == TOKslice || result->op == TOKaddress))
{
Expand Down Expand Up @@ -6237,40 +6239,20 @@ class Interpreter : public Visitor
}
if (result->op == TOKstructliteral)
return;
result = e->e1->interpret(istate, goal);

if (result->op == TOKaddress)
{
result = ((AddrExp*)result)->e1;
// We're changing *&e to e.
// We needed the AddrExp to deal with type painting expressions
// we couldn't otherwise express. Now that the type painting is
// undone, we must simplify them. This applies to references
// (which will be a DotVarExp or IndexExp) and to local structs
// (which will be a VarExp).

// We sometimes use DotVarExp and IndexExp to represent pointers,
// so in that case, they shouldn't be simplified.

bool isCtfePtr = (result->op == TOKdotvar || result->op == TOKindex)
&& isPointer(result->type);

// We also must not simplify if it is already a struct Literal
// or array literal, because it has already been interpreted.
if ( !isCtfePtr && result->op != TOKstructliteral &&
result->op != TOKassocarrayliteral && result->op != TOKarrayliteral)
{
result = result->interpret(istate, goal);
}
}
else if (result->op == TOKvar)
{
result = result->interpret(istate, goal);
result = ((AddrExp *)result)->e1;
}
result = result->interpret(istate, goal);
if (exceptionOrCantInterpret(result))
return;
}
else if (result->op == TOKaddress)
{
result = ((AddrExp*)result)->e1; // *(&x) ==> x
}
else if (result->op == TOKnull)
{
e->error("dereference of null pointer '%s'", e->e1->toChars());
Expand Down

0 comments on commit 240fcae

Please sign in to comment.