parser

package
v0.0.0-...-f61b284 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 15, 2024 License: BSD-3-Clause Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PackageTypeMap = map[string]PackageType{}
View Source
var StderrWriter io.Writer = os.Stderr

Functions

func CheckURL

func CheckURL(url string) (status int, err error)

func Close

func Close(c io.Closer, f func(err error))

func IsSelectorExpr

func IsSelectorExpr(expr ast.Expr) bool

func PackageName

func PackageName(pkgType PackageType) string

func WarnOnError

func WarnOnError(err error)

Types

type Codebase

type Codebase struct {
	Id         int64
	Project    string
	VersionTag string
}

func NewCodebase

func NewCodebase(project, tag string) *Codebase

type Field

type Field struct {
	Name   string
	Type   string
	GoFile *GoFile
	// contains filtered or unexported fields
}

func NewField

func NewField(name string, field *ast.Field, file *GoFile) *Field

type FieldMap

type FieldMap map[string]*Field

type Function

type Function struct {
	Name       string
	Receiver   *Variable
	Parameters Variables
	Results    Variables
}

func NewFunction

func NewFunction(name string, receiver *Variable, fd *ast.FuncDecl) *Function

type Functions

type Functions []*Function

type GoFile

type GoFile struct {
	scanner.File
	Package   *Package
	ImportMap ImportMap
	Functions Functions
	//Types      _archive.Types
	References map[string]struct{}
	// contains filtered or unexported fields
}

func NewGoFile

func NewGoFile(file scanner.File, pkgPath string) *GoFile

func (*GoFile) AST

func (gf *GoFile) AST() *ast.File

func (*GoFile) AddReference

func (gf *GoFile) AddReference(ref string)

func (*GoFile) HasFunctions

func (gf *GoFile) HasFunctions() bool

func (*GoFile) PackageImportPath

func (gf *GoFile) PackageImportPath() string

func (*GoFile) PackageName

func (gf *GoFile) PackageName() string

func (*GoFile) String

func (gf *GoFile) String() string

type GoFileParser

type GoFileParser struct {
	Files       scanner.Files
	ModuleGraph *ModuleGraph
	// contains filtered or unexported fields
}

func NewGoFileParser

func NewGoFileParser(mg *ModuleGraph, rootDir string) *GoFileParser

func (*GoFileParser) Parse

func (p *GoFileParser) Parse(ctx context.Context, files scanner.Files) (outFiles scanner.Files, err error)

func (*GoFileParser) ParseChan

func (p *GoFileParser) ParseChan(ctx context.Context, inFilesChan, outFilesChan chan scanner.File) (err error)

type GoMod

type GoMod struct {
	Version string
	Path    string
	Tag     string
}

type Import

type Import struct {
	Package *Package
	Alias   string
}

func NewImport

func NewImport(pkg *Package, alias string) *Import

type ImportMap

type ImportMap map[string]*Import

func (ImportMap) Sorted

func (ii ImportMap) Sorted() Imports

type Imports

type Imports []*Import

type Method

type Method struct {
	Name   string
	GoFile *GoFile
	// contains filtered or unexported fields
}

func NewMethod

func NewMethod(name string, field *ast.Field, file *GoFile) *Method

func (*Method) IsEmbed

func (m *Method) IsEmbed() bool

func (*Method) IsPrivate

func (m *Method) IsPrivate() (private bool)

type MethodMap

type MethodMap map[string]*Method

type ModFile

type ModFile struct {
	scanner.File
	Content []byte

	ModuleGraph *ModuleGraph
	// contains filtered or unexported fields
}

func NewModFile

func NewModFile(file scanner.File, content []byte, mg *ModuleGraph, rootDir string) *ModFile

func (ModFile) CodeFacet

func (ModFile) CodeFacet()

CodeFacet simply marks ModFile as implementing collector.CodeFacet

func (ModFile) GoVersion

func (mf ModFile) GoVersion() string

GoVersion returns the Go version set in this module

func (*ModFile) ImportPath

func (mf *ModFile) ImportPath() (s string)

func (*ModFile) ModFile

func (mf *ModFile) ModFile() *modfile.File

func (*ModFile) Modules

func (mf *ModFile) Modules() []*Module

Modules returns a slice of Mod where the first element is the module and the rest are its required dependencies. m.modFile, hence the name.

func (ModFile) Name

func (mf ModFile) Name() string

Name returns the module name as defined in go.mod by the `module` statement

func (ModFile) PathVersion

func (mf ModFile) PathVersion() module.Version

PathVersion returns the module.Version stored in mf.modFile.ModuleArgs.Mod, however, we replace the .Path value with mf.Fullpath().

func (ModFile) Require

func (mf ModFile) Require() []*modfile.Require

Require returns the version of the module as defined in go.mod by the `module` statement

func (*ModFile) SetModFile

func (mf *ModFile) SetModFile(f *modfile.File)

func (ModFile) String

func (mf ModFile) String() string

String returns a string representation of ModFile for debugging and error messages.

func (ModFile) UniqueID

func (mf ModFile) UniqueID() (uId string)

UniqueID returns a unique ID string that incorporates a version, if non-zero.

func (ModFile) Version

func (mf ModFile) Version() (v string)

Version returns the version of the module as defined in go.mod by the `module` statement

type Module

type Module struct {
	*Package
	*GoMod
	Parent      *Module
	Module      *Module
	ModuleGraph *ModuleGraph
	// contains filtered or unexported fields
}

func (*Module) GoModDir

func (m *Module) GoModDir() string

GoModDir returns the path to the go.mod file for the module, WITHOUT the suffix "/go.mod".

func (*Module) GoModPath

func (m *Module) GoModPath() string

GoModPath returns the path to the go.mod file for the module, WITH the suffix "/go.mod".

func (*Module) GoVersion

func (m *Module) GoVersion() (s string)

GoVersion returns Go version as a string

func (*Module) MaybeFixGoVersion

func (m *Module) MaybeFixGoVersion() (err error)

MaybeFixGoVersion checks to see if Go has a GitHub tag matching the version in the go.mod file, or if we need to embellish it. Embellishing it means either adding a ".0" to the end, or removing it. More embellishment may be needed in the future, if the Go team gets sloppier with their tagging.

func (*Module) Name

func (m *Module) Name() string

func (*Module) Version

func (m *Module) Version() *PackageVersion

func (*Module) VersionName

func (m *Module) VersionName() string

type ModuleArgs

type ModuleArgs struct {
	ModuleGraph *ModuleGraph
	Parent      *Module
	Module      *Module
	Name        string
	PackageDir  string
	Version     string
	Path        string
	GoVersion   string
	PackageType PackageType
}

type ModuleGraph

type ModuleGraph struct {
	ModuleMap
	// contains filtered or unexported fields
}

func NewModuleGraph

func NewModuleGraph() *ModuleGraph

func (*ModuleGraph) AddDependentModule

func (mg *ModuleGraph) AddDependentModule(pm *Module, args *ModuleArgs)

func (*ModuleGraph) AddProjectModule

func (mg *ModuleGraph) AddProjectModule(args *ModuleArgs) *Module

func (*ModuleGraph) DispenseGoModByImportPath

func (mg *ModuleGraph) DispenseGoModByImportPath(importPath string) (m *Module)

func (*ModuleGraph) DispenseGoModByPath

func (mg *ModuleGraph) DispenseGoModByPath(path string) (gm *Module)

DispenseGoModByPath returns a module for a go.mod based upon a path that has the go.mod's path as a string prefix, e.g.:

		For /foo/go.mod then /foo/bar/baz will return module for /foo/go.mod,
   Except if a /foo/bar/go.mod then it will return module for /foo/bar/go.mod,
   OTOH will return `nil` for path="github.com/example/project"

func (*ModuleGraph) DispenseLocalPackage

func (mg *ModuleGraph) DispenseLocalPackage(importPath, source string) (pkg *Package)

DispenseLocalPackage will return a newly instantiated Package of Local or GoMod type, or will return a pointer to one if previously instantiated and stored in mg.modulePackageMap.

func (*ModuleGraph) DispenseModule

func (mg *ModuleGraph) DispenseModule(name, path string) (m *Module)

DispenseModule returns a *Module given a module name and path to source file where imported

func (*ModuleGraph) DispenseModuleByImportPath

func (mg *ModuleGraph) DispenseModuleByImportPath(importPath string) (m *Module)

func (*ModuleGraph) DispenseModuleByPath

func (mg *ModuleGraph) DispenseModuleByPath(path string) (m *Module)

DispenseModuleByPath will return the applicable module for the given path.

func (*ModuleGraph) DispensePackage

func (mg *ModuleGraph) DispensePackage(importPath, source string) (pkg *Package)

dispensePackage returns a *Module given a package name (w/o alias) and source file where imported

func (*ModuleGraph) GetGoModByExactPath

func (mg *ModuleGraph) GetGoModByExactPath(path string) (gm *Module, found bool)

GetGoModByExactPath returns a module for a go.mod based upon an exact path

func (*ModuleGraph) GetPackageByImportPath

func (mg *ModuleGraph) GetPackageByImportPath(importPath string) (pkg *Package)

type ModuleMap

type ModuleMap map[string]*ModuleVersions

func (ModuleMap) GetPackageByImportPath

func (mm ModuleMap) GetPackageByImportPath(importPath string) (pkg *Package)

func (ModuleMap) ImportPaths

func (mm ModuleMap) ImportPaths() (ips []string)

type ModulePackage

type ModulePackage struct {
	Module     *Module
	PackageMap PackageMap
}

type ModulePackageMap

type ModulePackageMap map[string]*ModulePackage

type ModuleVersions

type ModuleVersions struct {
	VersionMap VersionMap
	Module     *Module
	ModPath    string
	GoMod      bool
}

func NewModuleVersions

func NewModuleVersions() *ModuleVersions

type Package

type Package struct {
	*PackageDetails
	ImportPath string
	// contains filtered or unexported fields
}

Package holds the name used early in the pipeline; during parsing

func NewFlyweightPackage

func NewFlyweightPackage(importPath string) *Package

func (Package) ExternalURL

func (p Package) ExternalURL() (url string)

ExternalURL returns a URL for an external package. Panics if the package is not external.

func (Package) GoModPath

func (p Package) GoModPath() (s string)

func (Package) LocalSourceDir

func (p Package) LocalSourceDir() (dir string)

func (Package) Name

func (p Package) Name() (s string)

Name returns the last segemnt of the name, e.g. `baz` for `foo/bar/baz`.

func (Package) PartialClone

func (p Package) PartialClone() (pkg *Package)

PartialClone returns a cloned version of Package completely disconnected from any pointers, EXCEPT for maintaining Module and ModuleGraph as pointers.

func (Package) SetVersion

func (p Package) SetVersion(ver string)

func (Package) Source

func (p Package) Source() (src string)

Source returns a string of its source

func (Package) StdLibSourceURL

func (p Package) StdLibSourceURL() (url string)

StdLibSourceURL returns the source URL for a Go package. Adds a fragment #invalid-version if URL resolution failed.

func (Package) String

func (p Package) String() (s string)

String returns a textual representation of Package for error messages and database fields.

func (Package) VersionName

func (p Package) VersionName() (s string)

type PackageArgs

type PackageArgs struct {
	ModuleGraph *ModuleGraph
	Module      *Module
	ImportPath  string
	Directory   string
	Type        PackageType
	Version     string
}

type PackageDetails

type PackageDetails struct {
	PackageVersion *PackageVersion
	Module         *Module
	ModuleGraph    *ModuleGraph

	// Directory contains the full path to the package's directory
	// TODO: Change this to relative path when all paths are changed to relative
	Directory *string
	Type      PackageType
}

PackageDetails holds values used later in the pipeline

type PackageMap

type PackageMap map[string]*Package

func (PackageMap) HasPackage

func (pm PackageMap) HasPackage(name string) bool

type PackageType

type PackageType int
const (
	InvalidPackage  PackageType = 0
	StdLibPackage   PackageType = 1
	GoModPackage    PackageType = 2
	LocalPackage    PackageType = 3
	ExternalPackage PackageType = 4
)

func (PackageType) ID

func (pt PackageType) ID() int

func (PackageType) Name

func (pt PackageType) Name() string

type PackageVersion

type PackageVersion struct {
	Package *Package
	Name    string
}

func NewPackageVersion

func NewPackageVersion(args *VersionArgs) *PackageVersion

func (PackageVersion) ExternalURL

func (v PackageVersion) ExternalURL() (url string)

ExternalURL returns a URL for an external package at the given version. Panics if the package is not external.

func (PackageVersion) Source

func (v PackageVersion) Source() (src string)

Source returns a string of its source, complete with a version where applicable

func (PackageVersion) StdLibSourceURL

func (v PackageVersion) StdLibSourceURL() (url string)

StdLibSourceURL returns the source URL for a package for the Go version. Adds a fragment #invalid-version if URL resolution failed.

type PathMap

type PathMap map[string]string

type Project

type Project struct {
	Id      int64
	Name    string
	RepoURL string
}

func NewProject

func NewProject(name, repoURL string) *Project

type SafeMap

type SafeMap[K comparable, V any] struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

SafeMap is a generic map that uses sync.RWMutex for concurrency-safe access

func NewSafeMap

func NewSafeMap[K comparable, V any]() *SafeMap[K, V]

NewSafeMap instantiates a new instance of for SafeMap{KeyType,ValueType], e.g.

myMap := NewSafeMap[int,string]()

func (*SafeMap[K, V]) Has

func (m *SafeMap[K, V]) Has(k K) (ok bool)

func (*SafeMap[K, V]) Load

func (m *SafeMap[K, V]) Load(k K) (v V, ok bool)

func (*SafeMap[K, V]) Save

func (m *SafeMap[K, V]) Save(k K, v V)

type StringModuleMap

type StringModuleMap map[string]*Module

type Variable

type Variable struct {
	Name string
	Type string
}

func NewVariable

func NewVariable(t string, name string) *Variable

type Variables

type Variables []*Variable

type VersionArgs

type VersionArgs struct {
	Package *Package
	Name    string
}

type VersionMap

type VersionMap map[string]*Module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL