]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: move and rename mkpkg to types.NewPkg
authorRobert Griesemer <gri@golang.org>
Wed, 19 Apr 2017 17:03:35 +0000 (10:03 -0700)
committerRobert Griesemer <gri@golang.org>
Wed, 19 Apr 2017 21:18:42 +0000 (21:18 +0000)
That's where it belongs. Also, moved pkgMap and pkgs globals.

Change-Id: I531727fe5ce162c403efefec82f4cc90afa326d7
Reviewed-on: https://go-review.googlesource.com/41071
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/gc/bimport.go
src/cmd/compile/internal/gc/closure.go
src/cmd/compile/internal/gc/dcl.go
src/cmd/compile/internal/gc/export.go
src/cmd/compile/internal/gc/main.go
src/cmd/compile/internal/gc/reflect.go
src/cmd/compile/internal/gc/subr.go
src/cmd/compile/internal/types/pkg.go

index 245f4217316cb2661ae4bd7f1da72aa6b8327aaa..45d5ffdc776b3f8979ddfff8167dc9118652f9ac 100644 (file)
@@ -291,7 +291,7 @@ func (p *importer) pkg() *types.Pkg {
        // add package to pkgList
        pkg := p.imp
        if path != "" {
-               pkg = mkpkg(path)
+               pkg = types.NewPkg(path)
        }
        if pkg.Name == "" {
                pkg.Name = name
index cc6f8eb6a6fa89690b2559021b99b840ae59474c..67a9d17ee3924cf3d3e8ab4ef762d2b1cc508017 100644 (file)
@@ -556,7 +556,7 @@ func makepartialcall(fn *Node, t0 *types.Type, meth *types.Sym) *Node {
        }
        if spkg == nil {
                if makepartialcall_gopkg == nil {
-                       makepartialcall_gopkg = mkpkg("go")
+                       makepartialcall_gopkg = types.NewPkg("go")
                }
                spkg = makepartialcall_gopkg
        }
index 7dadc6224dc405407d6c0428a6c2b328f838363b..7a44d93bef7ccab88c61d10acc1fce831da44204 100644 (file)
@@ -916,7 +916,7 @@ func methodsym(nsym *types.Sym, t0 *types.Type, iface bool) *types.Sym {
 
        if spkg == nil {
                if methodsym_toppkg == nil {
-                       methodsym_toppkg = mkpkg("go")
+                       methodsym_toppkg = types.NewPkg("go")
                }
                spkg = methodsym_toppkg
        }
index 1c6b90905fed0d0e92241701e1d800ad8d95af7d..676d29744f2793929f4796778ae0202756459143 100644 (file)
@@ -173,13 +173,13 @@ func dumpexport() {
 
                // verify that we can read the copied export data back in
                // (use empty package map to avoid collisions)
-               savedPkgMap := pkgMap
-               savedPkgs := pkgs
-               pkgMap = make(map[string]*types.Pkg)
-               pkgs = nil
-               Import(mkpkg(""), bufio.NewReader(&copy)) // must not die
-               pkgs = savedPkgs
-               pkgMap = savedPkgMap
+               savedPkgMap := types.PkgMap
+               savedPkgs := types.PkgList
+               types.PkgMap = make(map[string]*types.Pkg)
+               types.PkgList = nil
+               Import(types.NewPkg(""), bufio.NewReader(&copy)) // must not die
+               types.PkgList = savedPkgs
+               types.PkgMap = savedPkgMap
        } else {
                size = export(bout.Writer, Debug_export != 0)
        }
index c4b43fc53be545ed99b35c88bb219f55c8e8846b..0da2e94f4ebc5278eb375c881721358e8be712ed 100644 (file)
@@ -122,15 +122,15 @@ func Main(archInit func(*Arch)) {
        Ctxt.DiagFunc = yyerror
        Ctxt.Bso = bufio.NewWriter(os.Stdout)
 
-       localpkg = mkpkg("")
+       localpkg = types.NewPkg("")
        localpkg.Prefix = "\"\""
 
        // pseudo-package, for scoping
-       builtinpkg = mkpkg("go.builtin")
+       builtinpkg = types.NewPkg("go.builtin")
        builtinpkg.Prefix = "go.builtin" // not go%2ebuiltin
 
        // pseudo-package, accessed by import "unsafe"
-       unsafepkg = mkpkg("unsafe")
+       unsafepkg = types.NewPkg("unsafe")
        unsafepkg.Name = "unsafe"
 
        // Pseudo-package that contains the compiler's builtin
@@ -138,28 +138,28 @@ func Main(archInit func(*Arch)) {
        // separate package to avoid conflicts with package runtime's
        // actual declarations, which may differ intentionally but
        // insignificantly.
-       Runtimepkg = mkpkg("go.runtime")
+       Runtimepkg = types.NewPkg("go.runtime")
        Runtimepkg.Name = "runtime"
        Runtimepkg.Prefix = "runtime"
 
        // pseudo-packages used in symbol tables
-       itabpkg = mkpkg("go.itab")
+       itabpkg = types.NewPkg("go.itab")
        itabpkg.Name = "go.itab"
        itabpkg.Prefix = "go.itab" // not go%2eitab
 
-       itablinkpkg = mkpkg("go.itablink")
+       itablinkpkg = types.NewPkg("go.itablink")
        itablinkpkg.Name = "go.itablink"
        itablinkpkg.Prefix = "go.itablink" // not go%2eitablink
 
-       trackpkg = mkpkg("go.track")
+       trackpkg = types.NewPkg("go.track")
        trackpkg.Name = "go.track"
        trackpkg.Prefix = "go.track" // not go%2etrack
 
-       typepkg = mkpkg("type")
+       typepkg = types.NewPkg("type")
        typepkg.Name = "type"
 
        // pseudo-package used for map zero values
-       mappkg = mkpkg("go.map")
+       mappkg = types.NewPkg("go.map")
        mappkg.Name = "go.map"
        mappkg.Prefix = "go.map"
 
@@ -261,11 +261,11 @@ func Main(archInit func(*Arch)) {
        startProfile()
 
        if flag_race {
-               racepkg = mkpkg("runtime/race")
+               racepkg = types.NewPkg("runtime/race")
                racepkg.Name = "race"
        }
        if flag_msan {
-               msanpkg = mkpkg("runtime/msan")
+               msanpkg = types.NewPkg("runtime/msan")
                msanpkg.Name = "msan"
        }
        if flag_race && flag_msan {
@@ -850,7 +850,7 @@ func importfile(f *Val) *types.Pkg {
                errorexit()
        }
 
-       importpkg := mkpkg(path_)
+       importpkg := types.NewPkg(path_)
        if importpkg.Imported {
                return importpkg
        }
index aa2146c5fbb0bc3623216c7c8246aab16387465c..c56ca3f4a8c84602f60cc29739aa6b3425dda231 100644 (file)
@@ -1501,7 +1501,7 @@ func dumptypestructs() {
        }
 
        // generate import strings for imported packages
-       for _, p := range pkgs {
+       for _, p := range types.PkgList {
                if p.Direct {
                        dimportpath(p)
                }
@@ -1535,7 +1535,7 @@ func dumptypestructs() {
                if flag_msan {
                        dimportpath(msanpkg)
                }
-               dimportpath(mkpkg("main"))
+               dimportpath(types.NewPkg("main"))
        }
 }
 
index f840c470fb741ea4f7f705231dc14f093b2c34b5..ff2d88614b1e61e74936d52e3a8085d875ed77a2 100644 (file)
@@ -1957,23 +1957,6 @@ func ngotype(n *Node) *types.Sym {
        return nil
 }
 
-var pkgMap = make(map[string]*types.Pkg)
-var pkgs []*types.Pkg
-
-func mkpkg(path string) *types.Pkg {
-       if p := pkgMap[path]; p != nil {
-               return p
-       }
-
-       p := new(types.Pkg)
-       p.Path = path
-       p.Prefix = objabi.PathToPrefix(path)
-       p.Syms = make(map[string]*types.Sym)
-       pkgMap[path] = p
-       pkgs = append(pkgs, p)
-       return p
-}
-
 // The result of addinit MUST be assigned back to n, e.g.
 //     n.Left = addinit(n.Left, init)
 func addinit(n *Node, init []*Node) *Node {
index 9885734bc2067388af0de5194c5487a51a2102fc..947dc12caeb01e0fc9e7f679ff2e0634a309b856 100644 (file)
@@ -4,7 +4,10 @@
 
 package types
 
-import "cmd/internal/obj"
+import (
+       "cmd/internal/obj"
+       "cmd/internal/objabi"
+)
 
 type Pkg struct {
        Name     string // package name, e.g. "sys"
@@ -16,6 +19,23 @@ type Pkg struct {
        Syms     map[string]*Sym
 }
 
+var PkgMap = make(map[string]*Pkg)
+var PkgList []*Pkg
+
+func NewPkg(path string) *Pkg {
+       if p := PkgMap[path]; p != nil {
+               return p
+       }
+
+       p := new(Pkg)
+       p.Path = path
+       p.Prefix = objabi.PathToPrefix(path)
+       p.Syms = make(map[string]*Sym)
+       PkgMap[path] = p
+       PkgList = append(PkgList, p)
+       return p
+}
+
 var Nopkg = &Pkg{
        Syms: make(map[string]*Sym),
 }