Skip to content

Commit

Permalink
[Refactoring] Add findGotoTarget to share common code
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed Nov 27, 2014
1 parent c7c0ebf commit 7b6268a
Showing 1 changed file with 21 additions and 44 deletions.
65 changes: 21 additions & 44 deletions src/interpret.c
Expand Up @@ -1377,24 +1377,14 @@ class Interpreter : public Visitor
result = e;
}

void visit(BreakStatement *s)
static Statement *findGotoTarget(InterState *istate, Identifier *ident)
{
#if LOG
printf("%s BreakStatement::interpret()\n", s->loc.toChars());
#endif
if (istate->start)
{
if (istate->start != s)
return;
istate->start = NULL;
}

if (s->ident)
Statement *target = NULL;
if (ident)
{
LabelDsymbol *label = istate->fd->searchLabel(s->ident);
LabelDsymbol *label = istate->fd->searchLabel(ident);
assert(label && label->statement);
LabelStatement *ls = label->statement;
Statement *target;
if (ls->gotoTarget)
target = ls->gotoTarget;
else
Expand All @@ -1403,16 +1393,24 @@ class Interpreter : public Visitor
if (target->isScopeStatement())
target = target->isScopeStatement()->statement;
}
istate->gotoTarget = target;
result = CTFEExp::breakexp;
return;
}
else
return target;
}

void visit(BreakStatement *s)
{
#if LOG
printf("%s BreakStatement::interpret()\n", s->loc.toChars());
#endif
if (istate->start)
{
istate->gotoTarget = NULL;
result = CTFEExp::breakexp;
return;
if (istate->start != s)
return;
istate->start = NULL;
}

istate->gotoTarget = findGotoTarget(istate, s->ident);
result = CTFEExp::breakexp;
}

void visit(ContinueStatement *s)
Expand All @@ -1427,29 +1425,8 @@ class Interpreter : public Visitor
istate->start = NULL;
}

if (s->ident)
{
LabelDsymbol *label = istate->fd->searchLabel(s->ident);
assert(label && label->statement);
LabelStatement *ls = label->statement;
Statement *target;
if (ls->gotoTarget)
target = ls->gotoTarget;
else
{
target = ls->statement;
if (target->isScopeStatement())
target = target->isScopeStatement()->statement;
}
istate->gotoTarget = target;
result = CTFEExp::continueexp;
return;
}
else
{
result = CTFEExp::continueexp;
return;
}
istate->gotoTarget = findGotoTarget(istate, s->ident);
result = CTFEExp::continueexp;
}

void visit(WhileStatement *s)
Expand Down

0 comments on commit 7b6268a

Please sign in to comment.