]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: minor cleanup to import loading
authorMatthew Dempsky <mdempsky@google.com>
Mon, 4 Apr 2016 22:41:56 +0000 (15:41 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Mon, 4 Apr 2016 23:47:25 +0000 (23:47 +0000)
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>

src/cmd/compile/internal/gc/bimport.go
src/cmd/compile/internal/gc/export.go
src/cmd/compile/internal/gc/parser.go

index 103a0b354b6426341f4d23ca9f906c7ca0aadd9b..8c53372b8020826157f1d48ed28a6952e0252dc0 100644 (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
index 17681d0700927fed41f4faff26dd55626fdcbe14..9fc6e5627508a8458f40545b5143524266ff6986 100644 (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 {
index aecd0361be85317dbafe931c1b6f6133308a63c8..6538877e68756cbd61b454cc9ea3fc5ded43af8c 100644 (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())
 }
 
 // ----------------------------------------------------------------------------