github.com/bir3/gocompiler@v0.9.2202/src/go/types/package.go (about) 1 // Code generated by "go test -run=Generate -write=all"; DO NOT EDIT. 2 3 // Copyright 2013 The Go Authors. All rights reserved. 4 // Use of this source code is governed by a BSD-style 5 // license that can be found in the LICENSE file. 6 7 package types 8 9 import ( 10 "fmt" 11 ) 12 13 // A Package describes a Go package. 14 type Package struct { 15 path string 16 name string 17 scope *Scope 18 imports []*Package 19 complete bool 20 fake bool // scope lookup errors are silently dropped if package is fake (internal use only) 21 cgo bool // uses of this package will be rewritten into uses of declarations from _cgo_gotypes.go 22 goVersion string // minimum Go version required for package (by Config.GoVersion, typically from go.mod) 23 } 24 25 // NewPackage returns a new Package for the given package path and name. 26 // The package is not complete and contains no explicit imports. 27 func NewPackage(path, name string) *Package { 28 scope := NewScope(Universe, nopos, nopos, fmt.Sprintf("package %q", path)) 29 return &Package{path: path, name: name, scope: scope} 30 } 31 32 // Path returns the package path. 33 func (pkg *Package) Path() string { return pkg.path } 34 35 // Name returns the package name. 36 func (pkg *Package) Name() string { return pkg.name } 37 38 // SetName sets the package name. 39 func (pkg *Package) SetName(name string) { pkg.name = name } 40 41 // GoVersion returns the minimum Go version required by this package. 42 // If the minimum version is unknown, GoVersion returns the empty string. 43 // Individual source files may specify a different minimum Go version, 44 // as reported in the [go/ast.File.GoVersion] field. 45 func (pkg *Package) GoVersion() string { return pkg.goVersion } 46 47 // Scope returns the (complete or incomplete) package scope 48 // holding the objects declared at package level (TypeNames, 49 // Consts, Vars, and Funcs). 50 // For a nil pkg receiver, Scope returns the Universe scope. 51 func (pkg *Package) Scope() *Scope { 52 if pkg != nil { 53 return pkg.scope 54 } 55 return Universe 56 } 57 58 // A package is complete if its scope contains (at least) all 59 // exported objects; otherwise it is incomplete. 60 func (pkg *Package) Complete() bool { return pkg.complete } 61 62 // MarkComplete marks a package as complete. 63 func (pkg *Package) MarkComplete() { pkg.complete = true } 64 65 // Imports returns the list of packages directly imported by 66 // pkg; the list is in source order. 67 // 68 // If pkg was loaded from export data, Imports includes packages that 69 // provide package-level objects referenced by pkg. This may be more or 70 // less than the set of packages directly imported by pkg's source code. 71 // 72 // If pkg uses cgo and the FakeImportC configuration option 73 // was enabled, the imports list may contain a fake "C" package. 74 func (pkg *Package) Imports() []*Package { return pkg.imports } 75 76 // SetImports sets the list of explicitly imported packages to list. 77 // It is the caller's responsibility to make sure list elements are unique. 78 func (pkg *Package) SetImports(list []*Package) { pkg.imports = list } 79 80 func (pkg *Package) String() string { 81 return fmt.Sprintf("package %s (%q)", pkg.name, pkg.path) 82 }