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