aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/syntax/parser.go
diff options
context:
space:
mode:
authorgriesemer <gri@golang.org>2017-10-10 16:12:52 -0700
committerRobert Griesemer <gri@golang.org>2017-10-11 00:29:46 +0000
commit39edffb6b1632e6d22d8e1b399e57cbba7456b9d (patch)
treef234cd3439c3ec684f06b6634d445a576c4ca2be /src/cmd/compile/internal/syntax/parser.go
parentc87fb208c5162e2067138dd8fcea2e5ab8c1d6de (diff)
downloadgo-39edffb6b1632e6d22d8e1b399e57cbba7456b9d.tar.xz
cmd/compile/internal/syntax: factor out parsing of func bodies (cleanup)
Change-Id: If6481a5401940a923fc9a104981dfb90eed0d1ac Reviewed-on: https://go-review.googlesource.com/69750 Run-TryBot: Robert Griesemer <gri@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/syntax/parser.go')
-rw-r--r--src/cmd/compile/internal/syntax/parser.go31
1 files changed, 18 insertions, 13 deletions
diff --git a/src/cmd/compile/internal/syntax/parser.go b/src/cmd/compile/internal/syntax/parser.go
index 845e3f0eb7..c04322890c 100644
--- a/src/cmd/compile/internal/syntax/parser.go
+++ b/src/cmd/compile/internal/syntax/parser.go
@@ -487,16 +487,28 @@ func (p *parser) funcDeclOrNil() *FuncDecl {
f.Name = p.name()
f.Type = p.funcType()
if p.tok == _Lbrace {
- f.Body = p.blockStmt("")
- if p.mode&CheckBranches != 0 {
- checkBranches(f.Body, p.errh)
- }
+ f.Body = p.funcBody()
}
f.Pragma = p.pragma
return f
}
+func (p *parser) funcBody() *BlockStmt {
+ // TODO(gri) If we are in a function we should update p.fnest
+ // accordingly. Currently p.fnest is always zero and thus not
+ // used in error recovery.
+ // Not enabled because it performs worse for some code without
+ // more fine tuning (see example in #22164).
+ // p.fnest++
+ body := p.blockStmt("")
+ // p.fnest--
+ if p.mode&CheckBranches != 0 {
+ checkBranches(body, p.errh)
+ }
+ return body
+}
+
// ----------------------------------------------------------------------------
// Expressions
@@ -712,10 +724,7 @@ func (p *parser) operand(keep_parens bool) Expr {
f := new(FuncLit)
f.pos = pos
f.Type = t
- f.Body = p.blockStmt("")
- if p.mode&CheckBranches != 0 {
- checkBranches(f.Body, p.errh)
- }
+ f.Body = p.funcBody()
p.xnest--
return f
@@ -1635,16 +1644,12 @@ func (p *parser) labeledStmtOrNil(label *Name) Stmt {
return nil // avoids follow-on errors (see e.g., fixedbugs/bug274.go)
}
+// context must be a non-empty string unless we know that p.tok == _Lbrace.
func (p *parser) blockStmt(context string) *BlockStmt {
if trace {
defer p.trace("blockStmt")()
}
- // TODO(gri) If we are in a function we should update p.fnest
- // accordingly. Currently p.fnest is always zero and thus not
- // used in error recovery.
- // Not enabled for for because it performs worse for some code
- // without more fine tuning (see example in #22164).
s := new(BlockStmt)
s.pos = p.pos()