mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00: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:
parent
ec241db2fd
commit
b2a363b7ea
7 changed files with 29 additions and 29 deletions
|
|
@ -291,7 +291,7 @@ func (p *importer) pkg() *types.Pkg {
|
||||||
// add package to pkgList
|
// add package to pkgList
|
||||||
pkg := p.imp
|
pkg := p.imp
|
||||||
if path != "" {
|
if path != "" {
|
||||||
pkg = types.NewPkg(path)
|
pkg = types.NewPkg(path, "")
|
||||||
}
|
}
|
||||||
if pkg.Name == "" {
|
if pkg.Name == "" {
|
||||||
pkg.Name = name
|
pkg.Name = name
|
||||||
|
|
|
||||||
|
|
@ -556,7 +556,7 @@ func makepartialcall(fn *Node, t0 *types.Type, meth *types.Sym) *Node {
|
||||||
}
|
}
|
||||||
if spkg == nil {
|
if spkg == nil {
|
||||||
if makepartialcall_gopkg == nil {
|
if makepartialcall_gopkg == nil {
|
||||||
makepartialcall_gopkg = types.NewPkg("go")
|
makepartialcall_gopkg = types.NewPkg("go", "")
|
||||||
}
|
}
|
||||||
spkg = makepartialcall_gopkg
|
spkg = makepartialcall_gopkg
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -916,7 +916,7 @@ func methodsym(nsym *types.Sym, t0 *types.Type, iface bool) *types.Sym {
|
||||||
|
|
||||||
if spkg == nil {
|
if spkg == nil {
|
||||||
if methodsym_toppkg == nil {
|
if methodsym_toppkg == nil {
|
||||||
methodsym_toppkg = types.NewPkg("go")
|
methodsym_toppkg = types.NewPkg("go", "")
|
||||||
}
|
}
|
||||||
spkg = methodsym_toppkg
|
spkg = methodsym_toppkg
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -177,7 +177,7 @@ func dumpexport() {
|
||||||
savedPkgs := types.PkgList
|
savedPkgs := types.PkgList
|
||||||
types.PkgMap = make(map[string]*types.Pkg)
|
types.PkgMap = make(map[string]*types.Pkg)
|
||||||
types.PkgList = nil
|
types.PkgList = nil
|
||||||
Import(types.NewPkg(""), bufio.NewReader(©)) // must not die
|
Import(types.NewPkg("", ""), bufio.NewReader(©)) // must not die
|
||||||
types.PkgList = savedPkgs
|
types.PkgList = savedPkgs
|
||||||
types.PkgMap = savedPkgMap
|
types.PkgMap = savedPkgMap
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -122,45 +122,38 @@ func Main(archInit func(*Arch)) {
|
||||||
Ctxt.DiagFunc = yyerror
|
Ctxt.DiagFunc = yyerror
|
||||||
Ctxt.Bso = bufio.NewWriter(os.Stdout)
|
Ctxt.Bso = bufio.NewWriter(os.Stdout)
|
||||||
|
|
||||||
localpkg = types.NewPkg("")
|
localpkg = types.NewPkg("", "")
|
||||||
localpkg.Prefix = "\"\""
|
localpkg.Prefix = "\"\""
|
||||||
|
|
||||||
// pseudo-package, for scoping
|
// pseudo-package, for scoping
|
||||||
builtinpkg = types.NewPkg("go.builtin")
|
builtinpkg = types.NewPkg("go.builtin", "") // TODO(gri) name this package go.builtin?
|
||||||
builtinpkg.Prefix = "go.builtin" // not go%2ebuiltin
|
builtinpkg.Prefix = "go.builtin" // not go%2ebuiltin
|
||||||
|
|
||||||
// pseudo-package, accessed by import "unsafe"
|
// pseudo-package, accessed by import "unsafe"
|
||||||
unsafepkg = types.NewPkg("unsafe")
|
unsafepkg = types.NewPkg("unsafe", "unsafe")
|
||||||
unsafepkg.Name = "unsafe"
|
|
||||||
|
|
||||||
// Pseudo-package that contains the compiler's builtin
|
// Pseudo-package that contains the compiler's builtin
|
||||||
// declarations for package runtime. These are declared in a
|
// declarations for package runtime. These are declared in a
|
||||||
// separate package to avoid conflicts with package runtime's
|
// separate package to avoid conflicts with package runtime's
|
||||||
// actual declarations, which may differ intentionally but
|
// actual declarations, which may differ intentionally but
|
||||||
// insignificantly.
|
// insignificantly.
|
||||||
Runtimepkg = types.NewPkg("go.runtime")
|
Runtimepkg = types.NewPkg("go.runtime", "runtime")
|
||||||
Runtimepkg.Name = "runtime"
|
|
||||||
Runtimepkg.Prefix = "runtime"
|
Runtimepkg.Prefix = "runtime"
|
||||||
|
|
||||||
// pseudo-packages used in symbol tables
|
// pseudo-packages used in symbol tables
|
||||||
itabpkg = types.NewPkg("go.itab")
|
itabpkg = types.NewPkg("go.itab", "go.itab")
|
||||||
itabpkg.Name = "go.itab"
|
|
||||||
itabpkg.Prefix = "go.itab" // not go%2eitab
|
itabpkg.Prefix = "go.itab" // not go%2eitab
|
||||||
|
|
||||||
itablinkpkg = types.NewPkg("go.itablink")
|
itablinkpkg = types.NewPkg("go.itablink", "go.itablink")
|
||||||
itablinkpkg.Name = "go.itablink"
|
|
||||||
itablinkpkg.Prefix = "go.itablink" // not go%2eitablink
|
itablinkpkg.Prefix = "go.itablink" // not go%2eitablink
|
||||||
|
|
||||||
trackpkg = types.NewPkg("go.track")
|
trackpkg = types.NewPkg("go.track", "go.track")
|
||||||
trackpkg.Name = "go.track"
|
|
||||||
trackpkg.Prefix = "go.track" // not go%2etrack
|
trackpkg.Prefix = "go.track" // not go%2etrack
|
||||||
|
|
||||||
typepkg = types.NewPkg("type")
|
typepkg = types.NewPkg("type", "type")
|
||||||
typepkg.Name = "type"
|
|
||||||
|
|
||||||
// pseudo-package used for map zero values
|
// pseudo-package used for map zero values
|
||||||
mappkg = types.NewPkg("go.map")
|
mappkg = types.NewPkg("go.map", "go.map")
|
||||||
mappkg.Name = "go.map"
|
|
||||||
mappkg.Prefix = "go.map"
|
mappkg.Prefix = "go.map"
|
||||||
|
|
||||||
Nacl = objabi.GOOS == "nacl"
|
Nacl = objabi.GOOS == "nacl"
|
||||||
|
|
@ -261,12 +254,10 @@ func Main(archInit func(*Arch)) {
|
||||||
startProfile()
|
startProfile()
|
||||||
|
|
||||||
if flag_race {
|
if flag_race {
|
||||||
racepkg = types.NewPkg("runtime/race")
|
racepkg = types.NewPkg("runtime/race", "race")
|
||||||
racepkg.Name = "race"
|
|
||||||
}
|
}
|
||||||
if flag_msan {
|
if flag_msan {
|
||||||
msanpkg = types.NewPkg("runtime/msan")
|
msanpkg = types.NewPkg("runtime/msan", "msan")
|
||||||
msanpkg.Name = "msan"
|
|
||||||
}
|
}
|
||||||
if flag_race && flag_msan {
|
if flag_race && flag_msan {
|
||||||
log.Fatal("cannot use both -race and -msan")
|
log.Fatal("cannot use both -race and -msan")
|
||||||
|
|
@ -850,7 +841,7 @@ func importfile(f *Val) *types.Pkg {
|
||||||
errorexit()
|
errorexit()
|
||||||
}
|
}
|
||||||
|
|
||||||
importpkg := types.NewPkg(path_)
|
importpkg := types.NewPkg(path_, "")
|
||||||
if importpkg.Imported {
|
if importpkg.Imported {
|
||||||
return importpkg
|
return importpkg
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1535,7 +1535,7 @@ func dumptypestructs() {
|
||||||
if flag_msan {
|
if flag_msan {
|
||||||
dimportpath(msanpkg)
|
dimportpath(msanpkg)
|
||||||
}
|
}
|
||||||
dimportpath(types.NewPkg("main"))
|
dimportpath(types.NewPkg("main", ""))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,12 @@ package types
|
||||||
import (
|
import (
|
||||||
"cmd/internal/obj"
|
"cmd/internal/obj"
|
||||||
"cmd/internal/objabi"
|
"cmd/internal/objabi"
|
||||||
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Pkg struct {
|
type Pkg struct {
|
||||||
Name string // package name, e.g. "sys"
|
|
||||||
Path string // string literal used in import statement, e.g. "runtime/internal/sys"
|
Path string // string literal used in import statement, e.g. "runtime/internal/sys"
|
||||||
|
Name string // package name, e.g. "sys"
|
||||||
Pathsym *obj.LSym
|
Pathsym *obj.LSym
|
||||||
Prefix string // escaped path for use in symbol table
|
Prefix string // escaped path for use in symbol table
|
||||||
Imported bool // export data of this package was parsed
|
Imported bool // export data of this package was parsed
|
||||||
|
|
@ -22,17 +23,25 @@ type Pkg struct {
|
||||||
var PkgMap = make(map[string]*Pkg)
|
var PkgMap = make(map[string]*Pkg)
|
||||||
var PkgList []*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 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
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
p := new(Pkg)
|
p := new(Pkg)
|
||||||
p.Path = path
|
p.Path = path
|
||||||
|
p.Name = name
|
||||||
p.Prefix = objabi.PathToPrefix(path)
|
p.Prefix = objabi.PathToPrefix(path)
|
||||||
p.Syms = make(map[string]*Sym)
|
p.Syms = make(map[string]*Sym)
|
||||||
PkgMap[path] = p
|
PkgMap[path] = p
|
||||||
PkgList = append(PkgList, p)
|
PkgList = append(PkgList, p)
|
||||||
|
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue