Skip to content

Commit

Permalink
Merge pull request #4663 from 9rnsr/refactor_parse
Browse files Browse the repository at this point in the history
[refactor] simplify parsing for function literal
  • Loading branch information
yebblies committed May 17, 2015
2 parents c6edba1 + 24fe884 commit 5ef0338
Show file tree
Hide file tree
Showing 4 changed files with 235 additions and 237 deletions.
35 changes: 13 additions & 22 deletions src/expression.c
Original file line number Diff line number Diff line change
Expand Up @@ -5508,11 +5508,17 @@ Expression *TupleExp::semantic(Scope *sc)

/******************************** FuncExp *********************************/

FuncExp::FuncExp(Loc loc, FuncLiteralDeclaration *fd, TemplateDeclaration *td)
FuncExp::FuncExp(Loc loc, Dsymbol *s)
: Expression(loc, TOKfunction, sizeof(FuncExp))
{
this->fd = fd;
this->td = td;
this->td = s->isTemplateDeclaration();
this->fd = s->isFuncLiteralDeclaration();
if (td)
{
assert(td->literal);
assert(td->members && td->members->dim == 1);
fd = (*td->members)[0]->isFuncLiteralDeclaration();
}
tok = fd->tok; // save original kind of function/delegate/(infer)
assert(fd->fbody);
}
Expand Down Expand Up @@ -5561,27 +5567,12 @@ void FuncExp::genIdent(Scope *sc)

Expression *FuncExp::syntaxCopy()
{
TemplateDeclaration *td2;
FuncLiteralDeclaration *fd2;
if (td)
{
td2 = (TemplateDeclaration *)td->syntaxCopy(NULL);
assert(td2->members->dim == 1);
fd2 = (*td2->members)[0]->isFuncLiteralDeclaration();
assert(fd2);
}
return new FuncExp(loc, td->syntaxCopy(NULL));
else if (fd->semanticRun == PASSinit)
{
td2 = NULL;
fd2 = (FuncLiteralDeclaration *)fd->syntaxCopy(NULL);
}
else
{
// Bugzilla 13481: Prevent multiple semantic analysis of lambda body.
td2 = NULL;
fd2 = fd;
}
return new FuncExp(loc, fd2, td2);
return new FuncExp(loc, fd->syntaxCopy(NULL));
else // Bugzilla 13481: Prevent multiple semantic analysis of lambda body.
return new FuncExp(loc, fd);
}

Expression *FuncExp::semantic(Scope *sc)
Expand Down
2 changes: 1 addition & 1 deletion src/expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ class FuncExp : public Expression
TemplateDeclaration *td;
TOK tok;

FuncExp(Loc loc, FuncLiteralDeclaration *fd, TemplateDeclaration *td = NULL);
FuncExp(Loc loc, Dsymbol *s);
void genIdent(Scope *sc);
Expression *syntaxCopy();
Expression *semantic(Scope *sc);
Expand Down
Loading

0 comments on commit 5ef0338

Please sign in to comment.