From 59dc25730bad088e44d67bfc1166171182b61c74 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Fri, 13 Nov 2015 16:00:46 -0800 Subject: [PATCH] cmd/compile: cleanup in parser (3) Factored out functionality of dotname (was inlined in 3 places). Change-Id: Ica782737c8decbb757465830b25ba87faa9115a4 Reviewed-on: https://go-review.googlesource.com/16897 Run-TryBot: Robert Griesemer TryBot-Result: Gobot Gobot Reviewed-by: Chris Manghane --- src/cmd/compile/internal/gc/parser.go | 54 +++++++++++++-------------- 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/src/cmd/compile/internal/gc/parser.go b/src/cmd/compile/internal/gc/parser.go index e42968677f..62063de87e 100644 --- a/src/cmd/compile/internal/gc/parser.go +++ b/src/cmd/compile/internal/gc/parser.go @@ -98,6 +98,10 @@ func (p *parser) want(tok int32) { // Syntax error handling func (p *parser) syntax_error(msg string) { + if trace && Debug['x'] != 0 { + defer p.trace("syntax_error (" + msg + ")")() + } + if p.tok == EOF && nerrors > 0 { return // avoid meaningless follow-up errors } @@ -1421,14 +1425,7 @@ loop: switch p.tok { case LNAME, '@', '?': // pexpr '.' sym - sel := p.sym() - if x.Op == OPACK { - s := restrictlookup(sel.Name, x.Name.Pkg) - x.Used = true - x = oldname(s) - break - } - x = Nod(OXDOT, x, newname(sel)) + x = p.new_dotname(x) case '(': p.next() @@ -1837,6 +1834,22 @@ func (p *parser) fnret_type() *Node { } } +// go.y:dotname (partial) +func (p *parser) new_dotname(pkg *Node) *Node { + if trace && Debug['x'] != 0 { + defer p.trace("new_dotname")() + } + + sel := p.sym() + if pkg.Op == OPACK { + s := restrictlookup(sel.Name, pkg.Name.Pkg) + pkg.Used = true + return oldname(s) + } + return Nod(OXDOT, pkg, newname(sel)) + +} + // go.y:dotname func (p *parser) dotname() *Node { if trace && Debug['x'] != 0 { @@ -1844,21 +1857,10 @@ func (p *parser) dotname() *Node { } name := p.name() - - switch p.tok { - default: - return name - - case '.': - p.next() - sel := p.sym() - if name.Op == OPACK { - s := restrictlookup(sel.Name, name.Name.Pkg) - name.Used = true - return oldname(s) - } - return Nod(OXDOT, name, newname(sel)) + if p.got('.') { + return p.new_dotname(name) } + return name } // go.y:structtype @@ -2443,13 +2445,7 @@ func (p *parser) arg_type() *Node { name := mkname(name) // from dotname if p.got('.') { - sel := p.sym() - if name.Op == OPACK { - s := restrictlookup(sel.Name, name.Name.Pkg) - name.Used = true - return oldname(s) - } - return Nod(OXDOT, name, newname(sel)) + return p.new_dotname(name) } return name }