1
0
mirror of https://github.com/golang/go synced 2024-11-05 16:06:10 -07:00

cmd/compile: pass package name to types.NewPkg

Change-Id: I08b43b08a8d2e9851f41401feee4b72287ced774
Reviewed-on: https://go-review.googlesource.com/41072
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Robert Griesemer 2017-04-19 10:27:19 -07:00
parent ec241db2fd
commit b2a363b7ea
7 changed files with 29 additions and 29 deletions

View File

@ -291,7 +291,7 @@ func (p *importer) pkg() *types.Pkg {
// add package to pkgList
pkg := p.imp
if path != "" {
pkg = types.NewPkg(path)
pkg = types.NewPkg(path, "")
}
if pkg.Name == "" {
pkg.Name = name

View 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 = types.NewPkg("go")
makepartialcall_gopkg = types.NewPkg("go", "")
}
spkg = makepartialcall_gopkg
}

View 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 = types.NewPkg("go")
methodsym_toppkg = types.NewPkg("go", "")
}
spkg = methodsym_toppkg
}

View File

@ -177,7 +177,7 @@ func dumpexport() {
savedPkgs := types.PkgList
types.PkgMap = make(map[string]*types.Pkg)
types.PkgList = nil
Import(types.NewPkg(""), bufio.NewReader(&copy)) // must not die
Import(types.NewPkg("", ""), bufio.NewReader(&copy)) // must not die
types.PkgList = savedPkgs
types.PkgMap = savedPkgMap
} else {

View File

@ -122,45 +122,38 @@ func Main(archInit func(*Arch)) {
Ctxt.DiagFunc = yyerror
Ctxt.Bso = bufio.NewWriter(os.Stdout)
localpkg = types.NewPkg("")
localpkg = types.NewPkg("", "")
localpkg.Prefix = "\"\""
// pseudo-package, for scoping
builtinpkg = types.NewPkg("go.builtin")
builtinpkg.Prefix = "go.builtin" // not go%2ebuiltin
builtinpkg = types.NewPkg("go.builtin", "") // TODO(gri) name this package go.builtin?
builtinpkg.Prefix = "go.builtin" // not go%2ebuiltin
// pseudo-package, accessed by import "unsafe"
unsafepkg = types.NewPkg("unsafe")
unsafepkg.Name = "unsafe"
unsafepkg = types.NewPkg("unsafe", "unsafe")
// Pseudo-package that contains the compiler's builtin
// declarations for package runtime. These are declared in a
// separate package to avoid conflicts with package runtime's
// actual declarations, which may differ intentionally but
// insignificantly.
Runtimepkg = types.NewPkg("go.runtime")
Runtimepkg.Name = "runtime"
Runtimepkg = types.NewPkg("go.runtime", "runtime")
Runtimepkg.Prefix = "runtime"
// pseudo-packages used in symbol tables
itabpkg = types.NewPkg("go.itab")
itabpkg.Name = "go.itab"
itabpkg = types.NewPkg("go.itab", "go.itab")
itabpkg.Prefix = "go.itab" // not go%2eitab
itablinkpkg = types.NewPkg("go.itablink")
itablinkpkg.Name = "go.itablink"
itablinkpkg = types.NewPkg("go.itablink", "go.itablink")
itablinkpkg.Prefix = "go.itablink" // not go%2eitablink
trackpkg = types.NewPkg("go.track")
trackpkg.Name = "go.track"
trackpkg = types.NewPkg("go.track", "go.track")
trackpkg.Prefix = "go.track" // not go%2etrack
typepkg = types.NewPkg("type")
typepkg.Name = "type"
typepkg = types.NewPkg("type", "type")
// pseudo-package used for map zero values
mappkg = types.NewPkg("go.map")
mappkg.Name = "go.map"
mappkg = types.NewPkg("go.map", "go.map")
mappkg.Prefix = "go.map"
Nacl = objabi.GOOS == "nacl"
@ -261,12 +254,10 @@ func Main(archInit func(*Arch)) {
startProfile()
if flag_race {
racepkg = types.NewPkg("runtime/race")
racepkg.Name = "race"
racepkg = types.NewPkg("runtime/race", "race")
}
if flag_msan {
msanpkg = types.NewPkg("runtime/msan")
msanpkg.Name = "msan"
msanpkg = types.NewPkg("runtime/msan", "msan")
}
if flag_race && flag_msan {
log.Fatal("cannot use both -race and -msan")
@ -850,7 +841,7 @@ func importfile(f *Val) *types.Pkg {
errorexit()
}
importpkg := types.NewPkg(path_)
importpkg := types.NewPkg(path_, "")
if importpkg.Imported {
return importpkg
}

View File

@ -1535,7 +1535,7 @@ func dumptypestructs() {
if flag_msan {
dimportpath(msanpkg)
}
dimportpath(types.NewPkg("main"))
dimportpath(types.NewPkg("main", ""))
}
}

View File

@ -7,11 +7,12 @@ package types
import (
"cmd/internal/obj"
"cmd/internal/objabi"
"fmt"
)
type Pkg struct {
Name string // package name, e.g. "sys"
Path string // string literal used in import statement, e.g. "runtime/internal/sys"
Name string // package name, e.g. "sys"
Pathsym *obj.LSym
Prefix string // escaped path for use in symbol table
Imported bool // export data of this package was parsed
@ -22,17 +23,25 @@ type Pkg struct {
var PkgMap = make(map[string]*Pkg)
var PkgList []*Pkg
func NewPkg(path string) *Pkg {
// NewPkg returns a new Pkg for the given package path and name.
// Unless name is the empty string, if the package exists already,
// the existing package name and the provided name must match.
func NewPkg(path, name string) *Pkg {
if p := PkgMap[path]; p != nil {
if name != "" && p.Name != name {
panic(fmt.Sprintf("conflicting package names %s and %s for path %q", p.Name, name, path))
}
return p
}
p := new(Pkg)
p.Path = path
p.Name = name
p.Prefix = objabi.PathToPrefix(path)
p.Syms = make(map[string]*Sym)
PkgMap[path] = p
PkgList = append(PkgList, p)
return p
}