cmd/compile: minor cleanup to import loading

Briefly document what the importfoo functions do.

Get rid of importsym's unused result parameter.

Get rid of the redundant calls to importsym(s, OTYPE)
after we've already called pkgtype(s).

Passes toolstash -cmp.

Change-Id: I4c057358144044f5356e4dec68907ec85f1fe806
Reviewed-on: https://go-review.googlesource.com/21498
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Matthew Dempsky 2016-04-04 15:41:56 -07:00
parent 86e7a5b92a
commit 0c71e293b5
3 changed files with 7 additions and 14 deletions

View file

@ -290,7 +290,6 @@ func (p *importer) typ() *Type {
// parser.go:hidden_pkgtype
t = pkgtype(tsym)
importsym(tsym, OTYPE)
p.typList = append(p.typList, t)
// read underlying type

View file

@ -445,10 +445,8 @@ func dumpexport() {
}
}
// import
// return the sym for ss, which should match lexical
func importsym(s *Sym, op Op) *Sym {
// importsym declares symbol s as an imported object representable by op.
func importsym(s *Sym, op Op) {
if s.Def != nil && s.Def.Op != op {
pkgstr := fmt.Sprintf("during import %q", importpkg.Path)
redeclare(s, pkgstr)
@ -462,11 +460,10 @@ func importsym(s *Sym, op Op) *Sym {
s.Flags |= SymPackage // package scope
}
}
return s
}
// return the type pkg.name, forward declaring if needed
// pkgtype returns the named type declared by symbol s.
// If no such type has been declared yet, a forward declaration is returned.
func pkgtype(s *Sym) *Type {
importsym(s, OTYPE)
if s.Def == nil || s.Def.Op != OTYPE {
@ -506,6 +503,7 @@ func importimport(s *Sym, path string) {
}
}
// importconst declares symbol s as an imported constant with type t and value n.
func importconst(s *Sym, t *Type, n *Node) {
importsym(s, OLITERAL)
n = convlit(n, t)
@ -533,6 +531,7 @@ func importconst(s *Sym, t *Type, n *Node) {
}
}
// importvar declares symbol s as an imported variable with type t.
func importvar(s *Sym, t *Type) {
importsym(s, ONAME)
if s.Def != nil && s.Def.Op == ONAME {

View file

@ -2931,12 +2931,7 @@ func (p *parser) hidden_pkgtype() *Type {
defer p.trace("hidden_pkgtype")()
}
s1 := p.hidden_pkg_importsym()
ss := pkgtype(s1)
importsym(s1, OTYPE)
return ss
return pkgtype(p.hidden_pkg_importsym())
}
// ----------------------------------------------------------------------------