constructs

package
v0.0.0-...-bf3ae02 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BlankName

func BlankName(name string) bool

func CompareTo

func CompareTo[T Construct](a T, b Construct, cmp comp.Comparer[T]) int

func Comparer

func Comparer[T Construct]() comp.Comparer[T]

func ComparerPend

func ComparerPend[T Construct](a, b T) func() int

func SliceComparer

func SliceComparer[T Construct]() comp.Comparer[[]T]

func SliceComparerPend

func SliceComparerPend[T Construct](a, b []T) func() int

Types

type Abstract

type Abstract interface {
	Construct
	IsAbstract()

	Name() string
	Exported() bool
	Signature() Signature
}

Abstract is a named signature in an interface.

The order of the abstract doesn't matter.

type AbstractArgs

type AbstractArgs struct {
	Name      string
	Exported  bool
	Signature Signature
}

type AbstractFactory

type AbstractFactory interface {
	NewAbstract(args AbstractArgs) Abstract
	Abstracts() collections.ReadonlySortedSet[Abstract]
}

type Argument

type Argument interface {
	Construct
	TempReferenceContainer
	IsArgument()

	Name() string
	Type() TypeDesc
}

Argument is a parameter or result in a method signature.

The order of the arguments matters.

type ArgumentArgs

type ArgumentArgs struct {
	Name string
	Type TypeDesc
}

type ArgumentFactory

type ArgumentFactory interface {
	NewArgument(args ArgumentArgs) Argument
	Arguments() collections.ReadonlySortedSet[Argument]
}

type Basic

type Basic interface {
	TypeDesc
	IsBasic()
}

Basic is a base type (e.g. bool, int, string, float64).

This does not contain complex types, those are treated as an interface.

type BasicArgs

type BasicArgs struct {
	// RealType is the basic type underlying this type.
	RealType *types.Basic
}

type BasicFactory

type BasicFactory interface {
	NewBasic(args BasicArgs) Basic
	Basics() collections.ReadonlySortedSet[Basic]
}

type Construct

type Construct interface {
	comp.Comparable[Construct]

	// String gets a human readable string for this debugging this construct.
	String() string

	// Kind gets a string unique to each construct type.
	Kind() kind.Kind

	// Index gets the index of the construct, zero if unset.
	// The index will be set to the top level factory sorted set.
	Index() int

	// SetIndex sets the index of construct.
	SetIndex(index int)

	// Alive indicates that this construct is reachable
	// from any entry point in the compiled project.
	Alive() bool

	// SetAlive sets if the given construct is alive.
	SetAlive(alive bool)
}

Construct is part of the source code.

func ResolvedTempDeclRef

func ResolvedTempDeclRef(con Construct) Construct

type Declaration

type Declaration interface {
	Construct

	// IsDeclaration indicates that the type is a Declaration at compile time.
	// This prevents anything else from duck-typing into a Declaration.
	IsDeclaration()

	Package() Package
	Name() string
	Exported() bool
	Location() locs.Loc
	Type() TypeDesc
}

Declaration is a type, value, or method declaration with a name.

type Field

type Field interface {
	Construct
	TempReferenceContainer
	IsField()

	Name() string
	Exported() bool
	Type() TypeDesc
	Embedded() bool
}

Field is a variable inside of a struct or class.

For the abstraction, the order of the fields and the tags of the fields don't matter.

type FieldArgs

type FieldArgs struct {
	Name     string
	Exported bool
	Type     TypeDesc
	Embedded bool
}

type FieldFactory

type FieldFactory interface {
	NewField(args FieldArgs) Field
	Fields() collections.ReadonlySortedSet[Field]
}

type InterfaceDecl

type InterfaceDecl interface {
	TypeDecl
	IsInterface()

	Interface() InterfaceDesc
	IsNamed() bool
	IsGeneric() bool
	TypeParams() []TypeParam
	AddInstance(inst InterfaceInst) InterfaceInst
	Instances() collections.ReadonlySortedSet[InterfaceInst]
	FindInstance(instanceTypes []TypeDesc) (InterfaceInst, bool)
}

InterfaceDecl is a named interface typically explicitly defined at the given location in the source code. The underlying type description can be a class or interface with optional parameter types.

If type parameters are given then the interface is generic. Instances with realized versions of the interface, are added for each used instance in the source code. If there are no instances then the generic interface isn't used.

type InterfaceDeclArgs

type InterfaceDeclArgs struct {
	RealType types.Type
	Package  Package
	Name     string
	Exported bool
	Location locs.Loc

	TypeParams []TypeParam
	Interface  InterfaceDesc
}

type InterfaceDeclFactory

type InterfaceDeclFactory interface {
	NewInterfaceDecl(args InterfaceDeclArgs) InterfaceDecl
	InterfaceDecls() collections.ReadonlySortedSet[InterfaceDecl]
}

type InterfaceDesc

type InterfaceDesc interface {
	TypeDesc
	TempReferenceContainer
	IsInterfaceDesc()

	// Hint indicates if the interface is a placeholder for something that
	// isn't abstracted directly, such as maps and channels.
	Hint() hint.Hint

	// PinnedPackage is non-nil if the interface is tied to a specific
	// package. This only happens if any of the abstracts are unexported.
	// Unexported methods can only be implemented by something in the same
	// package as the interface is defined.
	PinnedPackage() Package

	// IsPinned indicates if this interface is pinned to a package.
	IsPinned() bool

	// Abstracts is the set of named signatures for this interface.
	// This does not contain any additional abstracts, only the original
	// that this interface was defined with.
	Abstracts() []Abstract

	// Exact types are like `string|int|bool` where the
	// data type must match exactly.
	Exact() []TypeDesc

	// Approx types are like `~string|~int` where the data type
	// may be exact or an extension of the base type.
	Approx() []TypeDesc

	// IsGeneral indicates if there is two or more exact or approximate types.
	IsGeneral() bool

	// Implements determines if this interface implements the other interface.
	Implements(other InterfaceDesc) bool

	// AdditionalAbstracts the set of additional named signatures for this
	// interface that were resolved from an underlying type.
	// The additional abstracts are not used in a comparison since they are
	// resolved from an underlying type they should match anyway once resolved.
	AdditionalAbstracts() []Abstract

	// SetAdditionalAbstracts overrides any prior additional abstracts with
	// the given set of abstracts.
	SetAdditionalAbstracts(abstracts []Abstract)

	AddInherits(it InterfaceDesc) InterfaceDesc

	Inherits() collections.SortedSet[InterfaceDesc]
}

InterfaceDesc is a named interface typically explicitly defined at the given location in the source code. The underlying type description can be a class or interface with optional parameter types.

If type parameters are given then the interface is generic. Instances with realized versions of the interface, are added for each used instance in the source code. If there are no instances then the generic interface isn't used.

type InterfaceDescArgs

type InterfaceDescArgs struct {
	Hint     hint.Hint
	RealType types.Type

	// PinnedPkg is non-nil when an abstract is unexported.
	// This is the package the interface is pinned to.
	PinnedPkg Package

	// Abstracts is the set of named signatures for this interface.
	Abstracts []Abstract

	// Exact types are like `string|int|bool` where the
	// data type must match exactly.
	Exact []TypeDesc

	// Approx types are like `~string|~int` where the data type
	// may be exact or an extension of the base type.
	Approx []TypeDesc

	// Package is needed when the real type isn't given.
	// The package is used to help create the real type.
	Package *packages.Package
}

type InterfaceDescFactory

type InterfaceDescFactory interface {
	NewInterfaceDesc(args InterfaceDescArgs) InterfaceDesc
	InterfaceDescs() collections.ReadonlySortedSet[InterfaceDesc]
}

type InterfaceInst

type InterfaceInst interface {
	TypeDesc
	TempReferenceContainer
	IsInterfaceInst()

	Generic() InterfaceDecl
	Resolved() InterfaceDesc
	InstanceTypes() []TypeDesc
}

InterfaceInst represents an instantiation of generic interface has been resolved to a specific interface with specific type parameters, e.g. List[T any] might be resolved to List<int>.

The instance parameter may be referencing a type parameter, e.g. List[T any] might be resolved to List<S int|string>, thus the instance is also generic. The type may be a non-type parameter on a generic type, e.g. List[List[T any]] where List[T any] is the instance type.

type InterfaceInstArgs

type InterfaceInstArgs struct {
	RealType      types.Type
	Generic       InterfaceDecl
	Resolved      InterfaceDesc
	InstanceTypes []TypeDesc
}

type InterfaceInstFactory

type InterfaceInstFactory interface {
	NewInterfaceInst(args InterfaceInstArgs) InterfaceInst
	InterfaceInsts() collections.ReadonlySortedSet[InterfaceInst]
}

type Method

type Method interface {
	Declaration
	IsMethod()

	Signature() Signature
	Metrics() Metrics
	ReceiverName() string
	SetReceiver(recv Object)
	NeedsReceiver() bool
	Receiver() Object
	PointerRecv() bool

	IsInit() bool
	IsMain() bool
	IsNamed() bool
	HasReceiver() bool
	IsGeneric() bool
	TypeParams() []TypeParam
	AddInstance(inst MethodInst) MethodInst
	Instances() collections.ReadonlySortedSet[MethodInst]
	FindInstance(instanceTypes []TypeDesc) (MethodInst, bool)
}

type MethodArgs

type MethodArgs struct {
	RealType *types.Signature
	Package  Package
	Name     string
	Exported bool
	Location locs.Loc

	TypeParams []TypeParam
	Signature  Signature
	Metrics    Metrics
	RecvName   string
	Receiver   Object

	// PointerRecv indicates the receiver is passed by pointer
	// and therefore should not be copied. This also changes how
	// the method is accessible via an interface.
	PointerRecv bool
}

type MethodFactory

type MethodFactory interface {
	NewMethod(args MethodArgs) Method
	Methods() collections.ReadonlySortedSet[Method]
}

type MethodInst

type MethodInst interface {
	Construct
	TempReferenceContainer
	IsMethodInst()

	Generic() Method
	Resolved() Signature
	InstanceTypes() []TypeDesc

	Receiver() ObjectInst
	SetReceiver(obj ObjectInst)
}

MethodInst represents an instantiation of generic method has been resolved to a specific method with specific type parameters, e.g. List[T any] might be resolved to List<int>.

The instance parameter may be referencing a type parameter, e.g. List[T any] might be resolved to List<S int|string>, thus the instance is also generic. The type may be a non-type parameter on a generic type, e.g. List[List[T any]] where List[T any] is the instance type.

type MethodInstArgs

type MethodInstArgs struct {
	Generic       Method
	Resolved      Signature
	InstanceTypes []TypeDesc
}

type MethodInstFactory

type MethodInstFactory interface {
	NewMethodInst(args MethodInstArgs) MethodInst
	MethodInsts() collections.ReadonlySortedSet[MethodInst]
}

type Metrics

type Metrics interface {
	Construct
	TempDeclRefContainer
	IsMetrics()

	Location() locs.Loc
	Complexity() int
	LineCount() int
	CodeCount() int
	Indents() int
	Getter() bool
	Setter() bool
	SideEffect() bool

	Reads() collections.ReadonlySortedSet[Construct]
	Writes() collections.ReadonlySortedSet[Construct]
	Invokes() collections.ReadonlySortedSet[Construct]
}

type MetricsArgs

type MetricsArgs struct {
	// Location is the unique location for the expression.
	// This is used as a key to determine different metrics.
	//
	// Metrics for values can be attached to zero or more values,
	// (`var _ = func() int { ⋯ }`) or (`var x, y = func()(int, int) { ⋯ }`).
	Location locs.Loc

	// Complexity is the McCabe's Cyclomatic Complexity value for the method.
	Complexity int

	// LineCount is the number of lines in a method
	// including function definition line and close bracket line.
	LineCount int

	// CodeCount is the number of lines that have code on it
	// including function definition line and close bracket line
	// but excluding blank lines and comment lines.
	CodeCount int

	// Indent is the indent complexity count using the amount of whitespace
	// to the left of the any line with code on it.
	Indents int

	// Getter indicates the expression only contains no parameters and a
	// single result that is set in a single return of a value.
	//
	// The expression must be a single function with or without a receiver,
	// have no parameter and a single result, and only a return with the
	// right hand side only identifiers (`f`), selectors (`f.x.a`), literals,
	// reference/dereference, or explicit/implicit casts.
	//
	// e.g. `func (f Foo) GetX() int { return f.x }`
	//
	// e.g. `func (f Foo) Kind() string { return "literal" }`
	//
	// This will not return true for modified result getters, such as
	// offsetting an index (`func (f Foo) GetX() int { return f.x + 1 }`),
	// reading a flag (`func (f Foo) GetX() int { return (f.x & 0xFF) >> 2 }`),
	// indexing (`func (f Foo) GetFirst() int { return f.list[0] }`),
	// or creating an instance of a type.
	Getter bool

	// Setter indicates the expression only contains an optional single parameter
	// and no results that is used in a single assignment of an external value.
	//
	// The expression must be a single function with or without a receiver,
	// with zero or one parameters, if the parameter is given it may only be
	// used on the right hand side of the assignment, a single assignment,
	// with only identifiers (`f`), selectors (`f.x.a`), literals,
	// reference/dereference, or explicit/implicit casts.
	//
	// e.g. `func (f *Foo) SetX(x int) { f.x = x }`
	//
	// e.g. `func (f *Foo) SetAsHidden() { f.state = "hidden" }`
	//
	// This will not return true for setters that modify the value in some way,
	// such as setting an offset index, setting an indexed value, etc.
	// This will not return true for reverse setters
	// (`func (f Foo) SetBar(b *Bar) { *b = f.x }`).
	Setter bool

	// Reads are the usages that reads a value or type.
	//
	// e.g. `return point.x + 4` has a read usage of `point.x`.
	Reads collections.SortedSet[Construct]

	// Writes are the usages that writes a value or type.
	// This includes creating a type internal to the function and
	// casting from one type to another.
	//
	// e.g. `point.x = 6` has a write usage of `point.x`.
	//
	// e.g. `return PointType(point)` has a write usage to `PointType`
	//      for the cast as if `point` was first written to a `PointType`
	//      instance prior ot other statements.
	//
	// e.g. `return point.(RealType)` has a write usage to `RealType`
	//      just like the cast in the above example.
	Writes collections.SortedSet[Construct]

	// Invokes are the usages that calls a method, function, or
	// function pointer.
	//
	// e.g. `point.getX()` has an invocation of `point.getX`.
	Invokes collections.SortedSet[Construct]

	// SideEffect indicates this metrics has something in it that
	// effects data outside the expression or method.
	SideEffect bool
}

MetricsArgs are measurements taken for a method body or expression.

type MetricsFactory

type MetricsFactory interface {
	NewMetrics(args MetricsArgs) Metrics
	Metrics() collections.ReadonlySortedSet[Metrics]
}

type Object

type Object interface {
	TypeDecl
	IsObject()

	Data() StructDesc
	Methods() collections.ReadonlySortedSet[Method]
	Interface() InterfaceDesc

	AddMethod(met Method) Method
	SetInterface(it InterfaceDesc)

	IsNamed() bool
	IsGeneric() bool
	TypeParams() []TypeParam
	AddInstance(inst ObjectInst) ObjectInst
	Instances() collections.ReadonlySortedSet[ObjectInst]
	FindInstance(instanceTypes []TypeDesc) (ObjectInst, bool)
}

Object is a named type typically explicitly defined at the given location in the source code. An object typically handles structs with optional parameter types. An object can handle any type that methods can use as a receiver.

If type parameters are given then the object is generic. Instances with realized versions of the object, are added for each used instance in the source code. If there are no instances then the generic object isn't used.

type ObjectArgs

type ObjectArgs struct {
	RealType types.Type
	Package  Package
	Name     string
	Exported bool
	Location locs.Loc

	TypeParams []TypeParam
	Data       StructDesc
}

type ObjectFactory

type ObjectFactory interface {
	NewObject(args ObjectArgs) Object
	Objects() collections.ReadonlySortedSet[Object]
}

type ObjectInst

type ObjectInst interface {
	TypeDesc
	TempReferenceContainer
	IsObjectInst()

	Generic() Object
	ResolvedData() StructDesc
	ResolvedInterface() InterfaceDesc
	InstanceTypes() []TypeDesc

	Methods() collections.ReadonlySortedSet[MethodInst]
	AddMethod(method MethodInst) MethodInst
	SetResolvedInterface(it InterfaceDesc)
}

ObjectInst represents an instantiation of generic object has been resolved to a specific object with specific type parameters, e.g. List[T any] might be resolved to List<int>.

The instance parameter may be referencing a type parameter, e.g. List[T any] might be resolved to List<S int|string>, thus the instance is also generic. The type may be a non-type parameter on a generic type, e.g. List[List[T any]] where List[T any] is the instance type.

type ObjectInstArgs

type ObjectInstArgs struct {
	RealType      types.Type
	Generic       Object
	ResolvedData  StructDesc
	InstanceTypes []TypeDesc
}

type ObjectInstFactory

type ObjectInstFactory interface {
	NewObjectInst(args ObjectInstArgs) ObjectInst
	ObjectInsts() collections.ReadonlySortedSet[ObjectInst]
}

type Package

type Package interface {
	Construct
	IsPackage()

	Source() *packages.Package
	Path() string
	Name() string
	EntryPoint() bool
	ImportPaths() []string
	InitCount() int

	AddImport(p Package) Package
	AddInterfaceDecl(it InterfaceDecl) InterfaceDecl
	AddMethod(m Method) Method
	AddObject(id Object) Object
	AddValue(v Value) Value

	Imports() collections.ReadonlySortedSet[Package]
	InterfaceDecls() collections.ReadonlySortedSet[InterfaceDecl]
	Methods() collections.ReadonlySortedSet[Method]
	Objects() collections.ReadonlySortedSet[Object]
	Values() collections.ReadonlySortedSet[Value]

	Empty() bool
	FindTypeDecl(name string) TypeDecl
	FindDecl(name string) Declaration
	ResolveReceivers()
}

type PackageArgs

type PackageArgs struct {
	RealPkg     *packages.Package
	Path        string
	Name        string
	ImportPaths []string
}

type PackageFactory

type PackageFactory interface {
	NewPackage(args PackageArgs) Package
	Packages() collections.ReadonlySortedSet[Package]
	FindPackageByPath(path string) Package
}

type Project

type Project interface {
	jsonify.Jsonable

	// Components
	AbstractFactory
	ArgumentFactory
	FieldFactory
	PackageFactory
	MetricsFactory
	SelectionFactory

	// Declarations
	InterfaceDeclFactory
	MethodFactory
	ObjectFactory
	ValueFactory
	TempDeclRefFactory

	// Type Descriptions
	BasicFactory
	InterfaceDescFactory
	InterfaceInstFactory
	MethodInstFactory
	ObjectInstFactory
	SignatureFactory
	StructDescFactory
	TempReferenceFactory
	TypeParamFactory

	Locs() locs.Set
	AllConstructs() collections.Enumerator[Construct]
	EntryPoint() Package
	FindType(pkgPath, name string, instTypes []TypeDesc, allowRef, panicOnNotFound bool) (TypeDesc, bool)
	FindDecl(pkgPath, name string, instTypes []TypeDesc, allowRef, panicOnNotFound bool) (Construct, bool)
	UpdateIndices()
}

type Selection

type Selection interface {
	Construct
	TempReferenceContainer
	IsSelection()

	Name() string
	Origin() Construct
}

Selection is a reference to a field, method, parameter, result, etc that is being selected from an origin construct.

type SelectionArgs

type SelectionArgs struct {
	// Name is the name of the field, method, parameter, result, etc
	// that is being selected in the origin.
	Name string

	// Origin is the construct that is being selected from.
	Origin Construct
}

type SelectionFactory

type SelectionFactory interface {
	NewSelection(args SelectionArgs) Selection
	Selections() collections.ReadonlySortedSet[Selection]
}

type Signature

type Signature interface {
	TypeDesc
	IsSignature()

	Variadic() bool
	Params() []Argument
	Results() []Argument

	// IsVacant indicates there are no parameters and no results,
	// i.e. `func()()`.
	IsVacant() bool
}

func FindSigByName

func FindSigByName(abs []Abstract, name string) Signature

type SignatureArgs

type SignatureArgs struct {
	RealType *types.Signature

	Variadic bool
	Params   []Argument
	Results  []Argument

	// Package is needed when the real type isn't given.
	// The package is used to help create the real type.
	Package *packages.Package
}

type SignatureFactory

type SignatureFactory interface {
	NewSignature(args SignatureArgs) Signature
	Signatures() collections.ReadonlySortedSet[Signature]
}

type StructDesc

type StructDesc interface {
	TypeDesc
	IsStructDesc()

	// Synthetic indicates this is a structure created around
	// a non-struct data for an object, e.g. `type Cat int`
	// has a synthetic `struct { $data int }`.
	Synthetic() bool

	Fields() []Field
}

type StructDescArgs

type StructDescArgs struct {
	RealType types.Type

	Fields []Field

	// Package is needed when the real type isn't given.
	// The package is used to help create the real type.
	Package *packages.Package
}

type StructDescFactory

type StructDescFactory interface {
	NewStructDesc(args StructDescArgs) StructDesc
	StructDescs() collections.ReadonlySortedSet[StructDesc]
}

type TempDeclRef

type TempDeclRef interface {
	Construct
	IsTempDeclRef()

	PackagePath() string
	Name() string
	InstanceTypes() []TypeDesc

	ResolvedType() Construct
	Resolved() bool
	SetResolution(con Construct)
}

TempDeclRef is a temporary reference used while abstracting a project to handle when a reference to a declaration is used prior to the declaration being defined. All references should be removed during resolving the since one thing that is resolved is all references.

type TempDeclRefArgs

type TempDeclRefArgs struct {
	PackagePath   string
	Name          string
	InstanceTypes []TypeDesc
}

type TempDeclRefContainer

type TempDeclRefContainer interface {
	Construct

	// RemoveTempDeclRefs should replace any found method reference with the
	// method that was referenced. References will already be looked up.
	RemoveTempDeclRefs()
}

TempDeclRefContainer is any construct that can contain a temporary method reference.

type TempDeclRefFactory

type TempDeclRefFactory interface {
	NewTempDeclRef(args TempDeclRefArgs) TempDeclRef
	TempDeclRefs() collections.ReadonlySortedSet[TempDeclRef]
	ClearAllTempDeclRefs()
}

type TempReference

type TempReference interface {
	TypeDesc
	IsTypeReference()

	PackagePath() string
	Name() string
	InstanceTypes() []TypeDesc

	ResolvedType() TypeDesc
	Resolved() bool
	SetResolution(typ TypeDesc)
}

TempReference is a temporary reference used while abstracting a project to handle when a reference to a type description is used prior to the type description being defined. All references should be removed during resolving the since one thing that is resolved is all references.

type TempReferenceArgs

type TempReferenceArgs struct {
	RealType      types.Type
	PackagePath   string
	Name          string
	InstanceTypes []TypeDesc

	// Package is needed when the real type isn't given.
	// The package is used to help create the real type.
	Package *packages.Package
}

type TempReferenceContainer

type TempReferenceContainer interface {
	Construct

	// RemoveTempReferences should replace any found reference with the type
	// description that was referenced. References will already be looked up.
	RemoveTempReferences()
}

TempReferenceContainer is any construct that can contain a temporary reference.

type TempReferenceFactory

type TempReferenceFactory interface {
	NewTempReference(args TempReferenceArgs) TempReference
	TempReferences() collections.ReadonlySortedSet[TempReference]
	ClearAllTempReferences()
}

type TypeDecl

type TypeDecl interface {
	Declaration
	TypeDesc
}

TypeDecl is both a type description and a type declaration, i.e. `type Foo struct{}; var X Foo`.

type TypeDesc

type TypeDesc interface {
	Construct

	// IsTypeDesc indicates that the type is a TypeDesc at compile time.
	// This prevents anything else from duck-typing into a TypeDecs.
	IsTypeDesc()

	// GoType gets the Go type associated with this type desc.
	GoType() types.Type
}

TypeDesc is a description of a type.

func ResolvedTempReference

func ResolvedTempReference(td TypeDesc) TypeDesc

type TypeParam

type TypeParam interface {
	TypeDesc
	TempReferenceContainer
	IsTypeParam()

	Name() string
	Type() TypeDesc
}

type TypeParamArgs

type TypeParamArgs struct {
	Name string
	Type TypeDesc
}

type TypeParamFactory

type TypeParamFactory interface {
	NewTypeParam(args TypeParamArgs) TypeParam
	TypeParams() collections.ReadonlySortedSet[TypeParam]
}

type Value

type Value interface {
	Declaration
	TempReferenceContainer
	IsValue()

	Const() bool
	Metrics() Metrics

	// HasSideEffect indicates that the value initialization expression
	// contains a usage that affects a variable outside of itself, arguments,
	// or receiver. Or that a function/method invoked in the expression
	// that these metrics are for, has a side effect.
	// If a variable is only read from it is not considered a side effect.
	//
	// For example:
	//    var callCount = 0
	//	  func foo() int {
	//       callCount++
	//       return 42
	//    }
	//
	//    // The below metrics for `bar` would show the invocation of `foo`
	//    // that has a side effect of changing `callCount`.
	//    // Therefore, even if `bar` isn't used, the initialization
	//    // of be is alive because it has side effects.
	//    var bar = foo()
	HasSideEffect() bool
}

type ValueArgs

type ValueArgs struct {
	Package  Package
	Name     string
	Exported bool
	Location locs.Loc
	Type     TypeDesc
	Const    bool

	// Metrics are optional and may be nil. These metrics are for
	// a variable initialized with an anonymous function.
	// (e.g. `var x = func() int { ⋯ }()`)
	Metrics Metrics
}

type ValueFactory

type ValueFactory interface {
	NewValue(args ValueArgs) Value
	Values() collections.ReadonlySortedSet[Value]
}

Jump to

Keyboard shortcuts

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