Documentation ¶
Overview ¶
Package golang implements the model to load and represent syntax and semantic information from source code in the .go files.
Specifically, this file defines SrcFile which provides interface to access the syntactic, type and semantic information from source code of one single file.
Package golang implements the model to load and represent syntax and semantic information from source code in the .go files.
Specifically, this file defines Package, which provides interfaces to load and access the type, syntax and semantic information of every source files under the package of being analyzed.
Package can be seen as the basic element taken into account for static analyzers in go-linters.
Package golang implements the model to load and represent syntax and semantic information from source code in the .go files.
Specifically, this file implements the top-level model Program that provides the packages and source files for static analyzers to consume.
Index ¶
- Constants
- func LoadAllPkg(srcDir string) ([]*packages.Package, error)
- func LoadOneFile(srcFile string) (*ast.File, *packages.Package, error)
- func LoadOnePkg(srcDir string) (*packages.Package, error)
- type LoadInfo
- type Module
- type Package
- func (pkg *Package) DirPath() string
- func (pkg *Package) FileSet() *token.FileSet
- func (pkg *Package) GoFiles() []string
- func (pkg *Package) Imports() []string
- func (pkg *Package) IsLoaded() bool
- func (pkg *Package) LoadInfo() *LoadInfo
- func (pkg *Package) PkgName() string
- func (pkg *Package) PkgPath() string
- func (pkg *Package) Program() *Program
- func (pkg *Package) SrcFile(path string) *SrcFile
- func (pkg *Package) TypeInfo() *types.Info
- func (pkg *Package) TypePkg() *types.Package
- func (pkg *Package) TypeSize() *types.Sizes
- type Program
- type SrcFile
Constants ¶
const ( GoFileSuffix = ".go" // GoFileSuffix defines the suffix of go source files PackagePrefix = "package" // PackagePrefix is the prefix of code line in package declaration GoModFileName = "go.mod" // GoModFileName is the name of `go.mod` file to find module name GoModIndirect = "indirect" // GoModIndirect is the 'indirect' flag to specify dependency one ModulePrefix = "module " // ModulePrefix is the prefix of code line in `go.mod` with module VersionPrefix = "go " // VersionPrefix is the prefix of code line in go.mod with version NewLine = "\n" // NewLine is the string used to split code into lines TabString = "\t" // TabString is the prefix of \t SpaceChar = " " // SpaceChar is a space ' ' )
Variables ¶
This section is empty.
Functions ¶
func LoadAllPkg ¶
LoadAllPkg will parse the AST of all source files under the directory and load the type & package information.
func LoadOneFile ¶
LoadOneFile parses the AST of source file and its corresponding package info.
Types ¶
type LoadInfo ¶
type LoadInfo struct { LoadTime time.Time // LoadTime is the time this loading is executed LoadedFiles []string // LoadedFiles are paths of source files loaded IgnoredFiles []string // IgnoredFiles are paths of those not be loaded IllTyped bool // IllTyped is true if any type error occurs in parsing FileErrors []error // FileErrors are a set of errors when parsing the file TypeErrors []error // TypeErrors are a set of errors in checking the types DepsErrors []error // DepsErrors are a set of errors in dependency imports }
LoadInfo records the information of the last loading a package, including the syntactic, types and the other error information that might be used for debugging and analyzing.
type Module ¶
type Module struct { RootPath string // RootPath is the absolute path of root directory of repository GoVersion string // GoVersion is the version of go language required in `go.mod` GoModFile string // GoModFile is the absolute path of go.mod file of the project ModuleName string // ModuleName is the name declared in go.mod file DirectDeps map[string]string // DirectDeps map from dependency packages to required versions IndirectDeps map[string]string // IndirectDeps model those indirectly dependency packages info }
Module gives the information in `go.mod` file that defines the module of project be analyzed.
type Package ¶
type Package struct {
// contains filtered or unexported fields
}
Package represents a package with its source files (modeled as SrcFile) being loaded from code.
Package is the basic element for static analyzer to taken as inputs (concurrently). The Package could be loaded with the syntactic, type's and semantic information of code at different levels.
func (*Package) IsLoaded ¶
IsLoaded check whether this package is loaded with any syntax, type and semantic information of its source files.
func (*Package) TypeInfo ¶
TypeInfo records the types and declarations of any variable and expression
type Program ¶
type Program struct {
// contains filtered or unexported fields
}
Program defines the top-level model of packages that will be taken as input by static analyzers.
func (*Program) AllPackages ¶
AllPackages return the set of all loaded packages in the program.
type SrcFile ¶
type SrcFile struct {
// contains filtered or unexported fields
}
SrcFile represents a source code file in go program (ending with '.go' suffix).
It is the smallest unit for analyzer, and implements interfaces to access code text, syntactic tree along with the static single assignment IR members loaded from this source during parsing.
The syntax and semantic info of SrcFile can be updated by invoking SrcFile.update, which is an internal method that will (only) be used by Package when loading its source files from outside.
func LoadBaseFile ¶
func (*SrcFile) Members ¶
Members return the static single assignment (SSA) members in the file or none if SSA form is not loaded.