1 // Copyright 2017 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
13 Name string // package name, e.g. "sys"
14 Path string // string literal used in import statement, e.g. "runtime/internal/sys"
16 Prefix string // escaped path for use in symbol table
17 Imported bool // export data of this package was parsed
18 Direct bool // imported directly
22 var PkgMap = make(map[string]*Pkg)
25 func NewPkg(path string) *Pkg {
26 if p := PkgMap[path]; p != nil {
32 p.Prefix = objabi.PathToPrefix(path)
33 p.Syms = make(map[string]*Sym)
35 PkgList = append(PkgList, p)
40 Syms: make(map[string]*Sym),
43 func (pkg *Pkg) Lookup(name string) *Sym {
44 s, _ := pkg.LookupOK(name)
50 // LookupOK looks up name in pkg and reports whether it previously existed.
51 func (pkg *Pkg) LookupOK(name string) (s *Sym, existed bool) {
55 if s := pkg.Syms[name]; s != nil {
64 InitSyms = append(InitSyms, s)
70 func (pkg *Pkg) LookupBytes(name []byte) *Sym {
74 if s := pkg.Syms[string(name)]; s != nil {
77 str := InternString(name)
78 return pkg.Lookup(str)
81 var internedStrings = map[string]string{}
83 func InternString(b []byte) string {
84 s, ok := internedStrings[string(b)] // string(b) here doesn't allocate
87 internedStrings[s] = s