Documentation ¶
Index ¶
- func BlankName(name string) bool
- func CompareTo[T Construct](a T, b Construct, cmp comp.Comparer[T]) int
- func Comparer[T Construct]() comp.Comparer[T]
- func ComparerPend[T Construct](a, b T) func() int
- func SliceComparer[T Construct]() comp.Comparer[[]T]
- func SliceComparerPend[T Construct](a, b []T) func() int
- type Abstract
- type AbstractArgs
- type AbstractFactory
- type Argument
- type ArgumentArgs
- type ArgumentFactory
- type Basic
- type BasicArgs
- type BasicFactory
- type Construct
- type Declaration
- type Field
- type FieldArgs
- type FieldFactory
- type InterfaceDecl
- type InterfaceDeclArgs
- type InterfaceDeclFactory
- type InterfaceDesc
- type InterfaceDescArgs
- type InterfaceDescFactory
- type InterfaceInst
- type InterfaceInstArgs
- type InterfaceInstFactory
- type Method
- type MethodArgs
- type MethodFactory
- type MethodInst
- type MethodInstArgs
- type MethodInstFactory
- type Metrics
- type MetricsArgs
- type MetricsFactory
- type Object
- type ObjectArgs
- type ObjectFactory
- type ObjectInst
- type ObjectInstArgs
- type ObjectInstFactory
- type Package
- type PackageArgs
- type PackageFactory
- type Project
- type Selection
- type SelectionArgs
- type SelectionFactory
- type Signature
- type SignatureArgs
- type SignatureFactory
- type StructDesc
- type StructDescArgs
- type StructDescFactory
- type TempDeclRef
- type TempDeclRefArgs
- type TempDeclRefContainer
- type TempDeclRefFactory
- type TempReference
- type TempReferenceArgs
- type TempReferenceContainer
- type TempReferenceFactory
- type TypeDecl
- type TypeDesc
- type TypeParam
- type TypeParamArgs
- type TypeParamFactory
- type Value
- type ValueArgs
- type ValueFactory
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ComparerPend ¶
func SliceComparer ¶
func SliceComparerPend ¶
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 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 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 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 ¶
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 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 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 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 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 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 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 ¶
type SignatureArgs ¶
type SignatureFactory ¶
type SignatureFactory interface { NewSignature(args SignatureArgs) Signature Signatures() collections.ReadonlySortedSet[Signature] }
type StructDesc ¶
type StructDescArgs ¶
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 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 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 ¶
type TypeParam ¶
type TypeParam interface { TypeDesc TempReferenceContainer IsTypeParam() Name() string Type() TypeDesc }
type TypeParamArgs ¶
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 ValueFactory ¶
type ValueFactory interface { NewValue(args ValueArgs) Value Values() collections.ReadonlySortedSet[Value] }
Source Files ¶
- abstract.go
- argument.go
- basic.go
- constructs.go
- declaration.go
- field.go
- interfaceDecl.go
- interfaceDesc.go
- interfaceInst.go
- method.go
- methodInst.go
- metrics.go
- object.go
- objectInst.go
- package.go
- project.go
- selection.go
- signature.go
- structDesc.go
- tempDeclRef.go
- tempReference.go
- typeDesc.go
- typeParam.go
- value.go