srg

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2018 License: BSD-3-Clause Imports: 19 Imported by: 9

Documentation

Overview

srg package defines methods for interacting with the Source Representation Graph.

Index

Constants

View Source
const (
	// ContainingImplementedInclusive indicates that if the node itself is an implemented, it will be
	// returned.
	ContainingImplementedInclusive = "inclusive"

	// ContainingImplementedExclusive indicates that if the node itself is an implemented, its *containing
	// implemented will be returned (if any).
	ContainingImplementedExclusive = "excluse"
)
View Source
const ASYNC_SUFFIX = "Async"

Variables

View Source
var MEMBER_OR_TYPE_KINDS = append(TYPE_MEMBER_KINDS, TYPE_KINDS...)

Functions

func GetUniqueId

func GetUniqueId(srgNode compilergraph.GraphNode) string

GetUniqueId returns a unique hash ID for the SRG node that is stable across compilations.

func IdentifierPathString

func IdentifierPathString(node compilergraph.GraphNode) (string, bool)

IdentifierPathString returns the string form of the identifier path referenced by the given node. Will return false if the node is not an identifier path.

func InSamePackage

func InSamePackage(first compilercommon.InputSource, second compilercommon.InputSource) bool

InSamePackage returns true if the given input source paths are found *directly* under the same package (no subpackages).

func PackagePath added in v0.2.0

func PackagePath(modulePath compilercommon.InputSource) string

PackagePath returns the path of the package that holds the specified module path.

func ParseExpression added in v0.0.2

func ParseExpression(expressionString string, source compilercommon.InputSource, startRune int) (compilergraph.GraphNode, bool)

ParseExpression parses the given expression string and returns its node. Note that the expression will be added to *its own layer*, which means it will not be accessible from the normal SRG layer.

Types

type ContainingImplementedOption

type ContainingImplementedOption string

ContainingImplementedOption defines options for the TryGetContainingImplemented function.

type MemberKind

type MemberKind int

TypeMemberKind defines the various supported kinds of members in the SRG.

const (
	ConstructorMember MemberKind = iota
	VarMember
	FunctionMember
	PropertyMember
	OperatorMember
)

func (MemberKind) String

func (i MemberKind) String() string

type ModuleResolutionOption

type ModuleResolutionOption int
const (
	ModuleResolveExportedOnly ModuleResolutionOption = iota
	ModuleResolveAll          ModuleResolutionOption = iota
)

type NamedScopeKind

type NamedScopeKind int

NamedScopeKind defines the various kinds of named scope in the SRG.

const (
	NamedScopeType      NamedScopeKind = iota // The named scope refers to a type.
	NamedScopeMember                          // The named scope refers to a module member.
	NamedScopeImport                          // The named scope refers to an import.
	NamedScopeParameter                       // The named scope refers to a parameter.
	NamedScopeValue                           // The named scope refers to a read-only value exported by a statement.
	NamedScopeVariable                        // The named scope refers to a variable statement.
)

func (NamedScopeKind) String

func (i NamedScopeKind) String() string

type SRG

type SRG struct {
	Graph compilergraph.SerulianGraph // The root graph.
	// contains filtered or unexported fields
}

SRG represents the SRG layer and all its associated helper methods.

func NewSRG

func NewSRG(graph compilergraph.SerulianGraph) *SRG

NewSRG returns a new SRG for populating the graph with parsed source.

func (*SRG) AllComments

func (g *SRG) AllComments() compilergraph.NodeIterator

AllComments returns an iterator over all the comment nodes found in the SRG.

func (*SRG) AsImplementable

func (g *SRG) AsImplementable(node compilergraph.GraphNode) (SRGImplementable, bool)

AsImplementable returns the given node as an SRGImplementable (if applicable).

func (*SRG) EntrypointImplementations

func (g *SRG) EntrypointImplementations() SRGImplementableIterator

EntrypointImplementations returns an iterator of all SRG members/impls in the SRG with bodies.

func (*SRG) EntrypointVariables

func (g *SRG) EntrypointVariables() SRGMemberIterator

EntrypointVariables returns an iterator of all vars in the SRG that are entrypoints for scoping (currently variables and fields).

func (*SRG) FindComment

func (g *SRG) FindComment(commentValue string) (SRGComment, bool)

FindComment attempts to find the comment in the SRG with the given value.

func (*SRG) FindCommentedNode

func (g *SRG) FindCommentedNode(commentValue string) (compilergraph.GraphNode, bool)

FindCommentedNode attempts to find the node in the SRG with the given comment attached.

func (*SRG) FindModuleBySource

func (g *SRG) FindModuleBySource(source compilercommon.InputSource) (SRGModule, bool)

FindModuleBySource returns the module with the given input source, if any.

func (*SRG) FindNameInScope

func (g *SRG) FindNameInScope(name string, node compilergraph.GraphNode) (SRGScopeOrImport, bool)

FindNameInScope finds the given name accessible from the scope under which the given node exists, if any.

func (*SRG) FindNearbyNodeForPosition

func (g *SRG) FindNearbyNodeForPosition(sourcePosition compilercommon.SourcePosition) (compilergraph.GraphNode, bool)

FindNearbyNodeForPosition finds a node near to matching the given position in the SRG. The exact location is tried first, followed by looking upwards and downwards by lines.

func (*SRG) FindNodeForPosition

func (g *SRG) FindNodeForPosition(sourcePosition compilercommon.SourcePosition) (compilergraph.GraphNode, bool)

FindNodeForPosition finds the node matching the given position in the SRG. As multiple nodes may *contain* the position, the node with the smallest range is returned (if any).

func (*SRG) FindReferencesInScope

func (g *SRG) FindReferencesInScope(name string, node compilergraph.GraphNode) compilergraph.NodeIterator

FindReferencesInScope finds all identifier expressions that refer to the given name, under the given scope.

func (*SRG) Freeze added in v0.0.2

func (g *SRG) Freeze()

Freeze freezes the source graph so that no additional changes can be applied to it.

func (*SRG) GetDefinedTypeReference

func (g *SRG) GetDefinedTypeReference(node compilergraph.GraphNode) SRGType

GetDefinedTypeReference returns an SRGType wrapper around the given SRG type node. Panics if the node is not a type node.

func (*SRG) GetGenericTypes

func (g *SRG) GetGenericTypes() []SRGType

GetGenericTypes returns all the generic types defined in the SRG.

func (*SRG) GetImport

func (g *SRG) GetImport(importNode compilergraph.GraphNode) SRGImport

GetImport returns an SRGImport wrapper around the given import node. Will panic if the node is not an import node.

func (*SRG) GetMemberReference

func (g *SRG) GetMemberReference(node compilergraph.GraphNode) SRGMember

GetMemberReference returns an SRGMember wrapper around the given SRG member node. Panics if the node is not a member node.

func (*SRG) GetModules

func (g *SRG) GetModules() []SRGModule

GetModules returns all the modules defined in the SRG.

func (*SRG) GetNamedScope

func (g *SRG) GetNamedScope(nodeId compilergraph.GraphNodeId) SRGNamedScope

GetNamedScope returns SRGNamedScope for the given SRG node. Panics on failure to lookup.

func (*SRG) GetNode

GetNode returns the node with the given ID in this layer or panics.

func (*SRG) GetPackageImport

func (g *SRG) GetPackageImport(packageNode compilergraph.GraphNode) SRGPackageImport

GetPackageImport returns an SRGPackageImport wrapper around the given import package node. Will panic if the node is not an import package node.

func (*SRG) GetParameterReference

func (g *SRG) GetParameterReference(node compilergraph.GraphNode) SRGParameter

GetParameterReference returns an SRGParameter wrapper around the given SRG parameter node. Panics if the node is not a member node.

func (*SRG) GetTypeGenerics

func (g *SRG) GetTypeGenerics() []SRGGeneric

GetTypeGenerics returns all the generics defined under types in the SRG.

func (*SRG) GetTypeRef

func (g *SRG) GetTypeRef(node compilergraph.GraphNode) SRGTypeRef

GetTypeRef returns an SRGTypeRef wrapper for the given type reference node.

func (*SRG) GetTypeReferences

func (g *SRG) GetTypeReferences() []SRGTypeRef

GetTypeReferences returns all the type references in the SRG.

func (*SRG) GetTypes

func (g *SRG) GetTypes() []SRGType

GetTypes returns all the types defined in the SRG.

func (*SRG) ImplicitLambdaExpressions

func (g *SRG) ImplicitLambdaExpressions() compilergraph.NodeIterator

ImplicitLambdaExpressions returns an iterator of all implicit lambda expressions defined in the SRG.

func (*SRG) NewSourceStructureFinder

func (g *SRG) NewSourceStructureFinder() *SourceStructureFinder

NewSourceStructureFinder returns a new source structural finder for the current SRG.

func (*SRG) ResolveAliasedType

func (g *SRG) ResolveAliasedType(name string) (SRGType, bool)

ResolveAliasedType returns the type with the global alias, if any.

func (*SRG) ScopeNameForNode added in v0.1.0

func (g *SRG) ScopeNameForNode(srgNode compilergraph.GraphNode) SRGNamedScope

ScopeNameForNode returns an SRGNamedScope for the given SRG node. Note that the node must be a named node in the SRG or this can cause a panic.

func (*SRG) SourceHandler

func (g *SRG) SourceHandler() packageloader.SourceHandler

SourceHandler returns a SourceHandler for populating the SRG via a package loader.

func (*SRG) SourceRangeOf

func (g *SRG) SourceRangeOf(node compilergraph.GraphNode) (compilercommon.SourceRange, bool)

SourceRangeOf returns a SourceRange for the given graph node.

func (*SRG) TryGetNode

func (g *SRG) TryGetNode(nodeId compilergraph.GraphNodeId) (compilergraph.GraphNode, bool)

TryGetNode attempts to return the node with the given ID in this layer, if any.

type SRGComment

type SRGComment struct {
	compilergraph.GraphNode
	// contains filtered or unexported fields
}

SRGComment wraps a comment node with helpers for accessing documentation.

func (SRGComment) Contents

func (c SRGComment) Contents() string

Contents returns the trimmed contents of the comment.

func (SRGComment) Documentation

func (c SRGComment) Documentation() (SRGDocumentation, bool)

Documentation returns the documentation found in this comment, if any.

func (SRGComment) IsDocComment

func (c SRGComment) IsDocComment() bool

IsDocComment returns true if the comment is a doc comment, instead of a normal comment.

func (SRGComment) ParentNode

func (c SRGComment) ParentNode() compilergraph.GraphNode

ParentNode returns the node that contains this comment.

type SRGComposedAgent

type SRGComposedAgent struct {
	compilergraph.GraphNode
	// contains filtered or unexported fields
}

SRGComposedAgent wraps an agent that is being composed under another type in the SRG.

func (SRGComposedAgent) AgentType

func (a SRGComposedAgent) AgentType() SRGTypeRef

AgentType returns the type of the agent being composed into the parent type.

func (SRGComposedAgent) CompositionAlias

func (a SRGComposedAgent) CompositionAlias() (string, bool)

CompositionAlias returns the alias used for composition of the agent under the parent type, if any.

func (SRGComposedAgent) CompositionName

func (a SRGComposedAgent) CompositionName() string

CompositionName returns the name used for composition of the agent under the parent type. If an alias is defined, the alias is used. Otherwise, the name of the type is used.

type SRGContextScopeName

type SRGContextScopeName struct {
	compilergraph.GraphNode
	// contains filtered or unexported fields
}

SRGContextScopeName represents a name found in the scope.

func (SRGContextScopeName) LocalName

func (cn SRGContextScopeName) LocalName() (string, bool)

LocalName returns the locally accessible name of the scope in context.

func (SRGContextScopeName) NamedScope

func (cn SRGContextScopeName) NamedScope() SRGNamedScope

NamedScope returns the named scope for this context name.

type SRGDocumentation

type SRGDocumentation struct {
	// contains filtered or unexported fields
}

SRGDocumentation represents documentation found on an SRG node. It is distinct from a comment in that it can be *part* of another comment.

func (SRGDocumentation) ForParameter

func (d SRGDocumentation) ForParameter(paramName string) (SRGDocumentation, bool)

ForParameter returns the documentation associated with the given parameter name, if any.

func (SRGDocumentation) IsDocComment

func (d SRGDocumentation) IsDocComment() bool

IsDocComment returns true if the documentation was found in a doc-comment style comment (instead of a standard comment).

func (SRGDocumentation) String

func (d SRGDocumentation) String() string

String returns the human-readable documentation string.

type SRGExternalPackageImport

type SRGExternalPackageImport struct {
	// contains filtered or unexported fields
}

SRGExternalPackageImport represents a reference to an imported name from another package within the SRG.

func (SRGExternalPackageImport) AsNamedScope

func (ns SRGExternalPackageImport) AsNamedScope() SRGNamedScope

func (SRGExternalPackageImport) AsPackageImport

func (SRGExternalPackageImport) ImportedName

func (ns SRGExternalPackageImport) ImportedName() string

ImportedName returns the name being accessed under the package.

func (SRGExternalPackageImport) IsNamedScope

func (ns SRGExternalPackageImport) IsNamedScope() bool

func (SRGExternalPackageImport) Name

func (ns SRGExternalPackageImport) Name() (string, bool)

Name returns the name of the imported member.

func (SRGExternalPackageImport) Package

Package returns the package under which the name is being imported.

type SRGGeneric

type SRGGeneric struct {
	compilergraph.GraphNode
	// contains filtered or unexported fields
}

SRGGeneric represents a generic declaration on a type or type member.

func (SRGGeneric) Code

Code returns a code-like summarization of the generic, for human consumption.

func (SRGGeneric) Documentation

func (t SRGGeneric) Documentation() (SRGDocumentation, bool)

Documentation returns the documentation associated with this generic, if any.

func (SRGGeneric) GetConstraint

func (t SRGGeneric) GetConstraint() (SRGTypeRef, bool)

GetConstraint returns the constraint for this generic, if any.

func (SRGGeneric) HasConstraint

func (t SRGGeneric) HasConstraint() bool

HasConstraint returns whether this generic has a type constraint.

func (SRGGeneric) Name

func (t SRGGeneric) Name() (string, bool)

Name returns the name of this generic. May not existing in the partial-parsing case for tooling.

func (SRGGeneric) Node

Node returns the underlying node.

func (SRGGeneric) SourceRange

func (t SRGGeneric) SourceRange() (compilercommon.SourceRange, bool)

SourceRange returns the source range for this generic.

type SRGImplementable

type SRGImplementable struct {
	compilergraph.GraphNode
	// contains filtered or unexported fields
}

SRGImplementable wraps a node that can have a body.

func (SRGImplementable) Body

Body returns the statement block forming the implementation body for this implementable, if any.

func (SRGImplementable) ContainingMember

func (m SRGImplementable) ContainingMember() SRGMember

ContainingMember returns the containing member of this implementable. If the node is, itself, a member, itself is returned.

func (SRGImplementable) IsMember

func (m SRGImplementable) IsMember() bool

IsMember returns true if this implementable is an SRGMember.

func (SRGImplementable) IsPropertySetter

func (m SRGImplementable) IsPropertySetter() bool

IsPropertySetter returns true if this implementable is a property setter.

func (SRGImplementable) Name

func (m SRGImplementable) Name() (string, bool)

Name returns the name of the implementable, if any.

func (SRGImplementable) Node

Node returns the underlying node for this implementable in the SRG.

func (SRGImplementable) Parameters

func (m SRGImplementable) Parameters() []SRGParameter

Parameters returns the parameters defined on this implementable, if any.

type SRGImplementableIterator

type SRGImplementableIterator struct {
	// contains filtered or unexported fields
}

SRGImplementableIterator is an iterator of SRGImplementable's.

func (SRGImplementableIterator) Implementable

func (sii SRGImplementableIterator) Implementable() SRGImplementable

func (SRGImplementableIterator) Next

func (sii SRGImplementableIterator) Next() bool

type SRGImport

type SRGImport struct {
	compilergraph.GraphNode
	// contains filtered or unexported fields
}

SRGImport represents an import node.

func (SRGImport) Code

Code returns a code-like summarization of the import, for human consumption.

func (SRGImport) PackageImports

func (i SRGImport) PackageImports() []SRGPackageImport

PackageImports returns the package imports for this import statement, if any.

func (SRGImport) ParsedSource

func (i SRGImport) ParsedSource() (string, shared.ParsedImportType, error)

ParsedSource returns the source for this import, parsed.

func (SRGImport) Source

func (i SRGImport) Source() (string, bool)

Source returns the source of the import.

func (SRGImport) SourceRange

func (i SRGImport) SourceRange() (compilercommon.SourceRange, bool)

SourceRange returns the source range for this import.

type SRGMember

type SRGMember struct {
	compilergraph.GraphNode
	// contains filtered or unexported fields
}

SRGMember wraps a member declaration or definition in the SRG.

func (SRGMember) AsImplementable

func (m SRGMember) AsImplementable() SRGImplementable

func (SRGMember) AsNamedScope

func (m SRGMember) AsNamedScope() SRGNamedScope

AsNamedScope returns the member as a named scope reference.

func (SRGMember) Body

func (m SRGMember) Body() (compilergraph.GraphNode, bool)

Body returns the statement block forming the implementation body for this member, if any.

func (SRGMember) Code

Code returns a code-like summarization of the member, for human consumption.

func (SRGMember) ContainingType

func (m SRGMember) ContainingType() (SRGType, bool)

ContainingType returns the type containing this member, if any.

func (SRGMember) DeclaredType

func (m SRGMember) DeclaredType() (SRGTypeRef, bool)

DeclaredType returns a type reference to the declared type of this member, if any.

func (SRGMember) DefinedReturnType added in v0.2.0

func (m SRGMember) DefinedReturnType() (SRGTypeRef, bool)

DefinedReturnType returns a type reference to the defined return type of this member, if any.

func (SRGMember) Documentation

func (m SRGMember) Documentation() (SRGDocumentation, bool)

Documentation returns the documentation on the member, if any.

func (SRGMember) Generics

func (m SRGMember) Generics() []SRGGeneric

Generics returns the generics on this member.

func (SRGMember) Getter

func (m SRGMember) Getter() (SRGImplementable, bool)

Getter returns the defined getter for this property. Panics if this is not a property.

func (SRGMember) HasImplementation

func (m SRGMember) HasImplementation() bool

HasImplementation returns whether the given member has a defined implementation.

func (SRGMember) HasSetter

func (m SRGMember) HasSetter() bool

HasSetter returns true if the property has a setter defined. Will always return false for non-properties.

func (SRGMember) Initializer

func (m SRGMember) Initializer() (compilergraph.GraphNode, bool)

Initializer returns the expression forming the initializer for this variable or field, if any.

func (SRGMember) IsAsyncFunction

func (m SRGMember) IsAsyncFunction() bool

IsAsync returns whether the given member is an async function.

func (SRGMember) IsConstant added in v0.3.0

func (m SRGMember) IsConstant() bool

IsConstant returns whether the member is marked as explicitly constant. Only applies to variables under modules.

func (SRGMember) IsExported

func (m SRGMember) IsExported() bool

IsExported returns whether the given member is exported for use outside its package.

func (SRGMember) IsOperator

func (m SRGMember) IsOperator() bool

IsOperator returns whether the given member is an operator.

func (SRGMember) IsReadOnly

func (m SRGMember) IsReadOnly() bool

IsReadOnly returns whether the member is marked as explicitly read-only. Only applies to properties.

func (SRGMember) IsStatic

func (m SRGMember) IsStatic() bool

IsStatic returns whether the given member is static.

func (SRGMember) MemberKind

func (m SRGMember) MemberKind() MemberKind

MemberKind returns the kind matching the member definition/declaration node type.

func (SRGMember) Module

func (m SRGMember) Module() SRGModule

Module returns the module under which the member is defined.

func (SRGMember) Name

func (m SRGMember) Name() (string, bool)

Name returns the name of this member. Can not exist in the partial-parsing case for tooling.

func (SRGMember) Node

Node returns the underlying member node for this member.

func (SRGMember) Parameters

func (m SRGMember) Parameters() []SRGParameter

Parameters returns the parameters on this member.

func (SRGMember) Setter

func (m SRGMember) Setter() (SRGImplementable, bool)

Setter returns the defined setter for this property. Panics if this is not a property.

func (SRGMember) SourceRange

func (m SRGMember) SourceRange() (compilercommon.SourceRange, bool)

SourceRange returns the source range for this member.

func (SRGMember) Tags

func (m SRGMember) Tags() map[string]string

Tags returns the tags defined on this member, if any.

func (SRGMember) UniqueId

func (m SRGMember) UniqueId() string

UniqueId returns a unique hash ID for the node that is stable across compilations.

type SRGMemberIterator

type SRGMemberIterator struct {
	// contains filtered or unexported fields
}

SRGMemberIterator is an iterator of SRGMembers's.

func (SRGMemberIterator) Member

func (smi SRGMemberIterator) Member() SRGMember

func (SRGMemberIterator) Next

func (smi SRGMemberIterator) Next() bool

type SRGModule

type SRGModule struct {
	compilergraph.GraphNode
	// contains filtered or unexported fields
}

SRGModule wraps a module defined in the SRG.

func (SRGModule) FindTypeByName

func (m SRGModule) FindTypeByName(typeName string, option ModuleResolutionOption) (SRGType, bool)

FindTypeByName searches for the type definition or declaration with the given name under this module and returns it (if found).

func (SRGModule) FindTypeOrMemberByName

func (m SRGModule) FindTypeOrMemberByName(name string, option ModuleResolutionOption) (SRGTypeOrMember, bool)

FindTypeOrMemberByName searches for the type definition, declaration or module member with the given name under this module and returns it (if found). Note that this method does not handle imports.

func (SRGModule) GetImports

func (m SRGModule) GetImports() []SRGImport

GetImports returns the imports declared under the module.

func (SRGModule) GetMembers

func (m SRGModule) GetMembers() []SRGMember

GetMembers returns the members declared directly under the module.

func (SRGModule) GetTypes

func (m SRGModule) GetTypes() []SRGType

GetTypes returns the types declared directly under the module.

func (SRGModule) InputSource

func (m SRGModule) InputSource() compilercommon.InputSource

InputSource returns the input source for this module.

func (SRGModule) Name

func (m SRGModule) Name() string

Name returns the name of the module.

func (SRGModule) Node

Node returns the underlying node.

func (SRGModule) ResolveImportedPackage

func (m SRGModule) ResolveImportedPackage(packageName string) (importedPackage, bool)

ResolveImportedPackage attempts to find a package imported by this module under the given packageName.

func (SRGModule) ResolveType

func (m SRGModule) ResolveType(path string, option ModuleResolutionOption) (TypeResolutionResult, bool)

ResolveType attempts to resolve the type with the given name, under this module.

func (SRGModule) ResolveTypePath

func (m SRGModule) ResolveTypePath(path string) (TypeResolutionResult, bool)

ResolveTypePath attempts to resolve the type at the given path under this module and its imports.

type SRGNamedScope

type SRGNamedScope struct {
	compilergraph.GraphNode
	// contains filtered or unexported fields
}

SRGNamedScope represents a reference to a named scope in the SRG (import, variable, etc).

func (SRGNamedScope) AccessIsUsage

func (ns SRGNamedScope) AccessIsUsage() bool

AccessIsUsage returns true if the named scope refers to a member or variable that is used immediately via the access. For example, a variable or property access will "use" that member, while a function or constructor is not used until invoked.

func (SRGNamedScope) AsNamedScope

func (ns SRGNamedScope) AsNamedScope() SRGNamedScope

AsNamedScope returns the named scope as a named scope object.

func (SRGNamedScope) AsPackageImport

func (ns SRGNamedScope) AsPackageImport() SRGExternalPackageImport

AsPackageImport returns the named scope as a package import (always panics).

func (SRGNamedScope) Code

Code returns a code-like summarization of the referenced scope, for human consumption.

func (SRGNamedScope) DeclaredType

func (ns SRGNamedScope) DeclaredType() (SRGTypeRef, bool)

DeclaredType returns the declared type of the scoped node, if any.

func (SRGNamedScope) DefinedReturnType added in v0.2.0

func (ns SRGNamedScope) DefinedReturnType() (SRGTypeRef, bool)

DefinedReturnType returns the defined return type of the scoped node, if any.

func (SRGNamedScope) Documentation

func (ns SRGNamedScope) Documentation() (SRGDocumentation, bool)

Documentation returns the documentation comment found on the scoped node, if any.

func (SRGNamedScope) GetMember

func (ns SRGNamedScope) GetMember() (SRGMember, bool)

GetMember returns the member pointed to by this scope, if any.

func (SRGNamedScope) GetParameter

func (ns SRGNamedScope) GetParameter() (SRGParameter, bool)

GetParameter returns the parameter pointed to by this scope, if any.

func (SRGNamedScope) IsAssignable

func (ns SRGNamedScope) IsAssignable() bool

IsAssignable returns whether the scoped node is assignable.

func (SRGNamedScope) IsFunction added in v0.2.0

func (ns SRGNamedScope) IsFunction() bool

IsFunction returns whether the named scope refers to a function.

func (SRGNamedScope) IsNamedScope

func (ns SRGNamedScope) IsNamedScope() bool

IsNamedScope returns true if this is a named scope (always returns true).

func (SRGNamedScope) IsStatic

func (ns SRGNamedScope) IsStatic() bool

IsStatic returns whether the scoped node is static.

func (SRGNamedScope) Name

func (ns SRGNamedScope) Name() (string, bool)

Name returns the name of the scoped node.

func (SRGNamedScope) Node

Node returns the underlying node.

func (SRGNamedScope) ResolveNameUnderScope

func (ns SRGNamedScope) ResolveNameUnderScope(name string) (SRGScopeOrImport, bool)

ResolveNameUnderScope attempts to resolve the given name under this scope. Only applies to imports.

func (SRGNamedScope) ScopeKind

func (ns SRGNamedScope) ScopeKind() NamedScopeKind

ScopeKind returns the kind of the scoped node.

func (SRGNamedScope) SourceRange

func (ns SRGNamedScope) SourceRange() (compilercommon.SourceRange, bool)

SourceRange returns the range of the named scope in source, if any.

func (SRGNamedScope) Title

func (ns SRGNamedScope) Title() string

Title returns a nice title for the given named scope.

type SRGPackageImport

type SRGPackageImport struct {
	compilergraph.GraphNode
	// contains filtered or unexported fields
}

SRGPackageImport represents the package under an import.

func (SRGPackageImport) Alias

func (i SRGPackageImport) Alias() (string, bool)

Alias returns the local alias for this package import, if any.

func (SRGPackageImport) Code

Code returns a code-like summarization of the import, for human consumption.

func (SRGPackageImport) ResolveType added in v0.3.2

func (i SRGPackageImport) ResolveType() (TypeResolutionResult, bool)

ResolveType returns the resolved type of this import, if any.

func (SRGPackageImport) ResolvedTypeOrMember

func (i SRGPackageImport) ResolvedTypeOrMember() (SRGTypeOrMember, bool)

ResolvedTypeOrMember returns the SRG type or member referenced by this import, if any.

func (SRGPackageImport) SourceRange

func (i SRGPackageImport) SourceRange() (compilercommon.SourceRange, bool)

SourceRange returns the source range for this import.

func (SRGPackageImport) Subsource

func (i SRGPackageImport) Subsource() (string, bool)

Subsource returns the subsource for this package import, if any.

type SRGParameter

type SRGParameter struct {
	compilergraph.GraphNode
	// contains filtered or unexported fields
}

SRGParameter represents a parameter on a function, constructor or operator.

func (SRGParameter) AsNamedScope

func (p SRGParameter) AsNamedScope() SRGNamedScope

AsNamedScope returns the parameter as a named scope reference.

func (SRGParameter) Code

Code returns a code-like summarization of the parameter, for human consumption.

func (SRGParameter) DeclaredType

func (p SRGParameter) DeclaredType() (SRGTypeRef, bool)

DeclaredType returns the declared type for this parameter, if any.

func (SRGParameter) Documentation

func (p SRGParameter) Documentation() (SRGDocumentation, bool)

Documentation returns the documentation associated with this parameter, if any.

func (SRGParameter) Name

func (p SRGParameter) Name() (string, bool)

Name returns the name of this parameter. May not exist in the partial-parsing case for tooling.

func (SRGParameter) Node

Node returns the underlying node.

func (SRGParameter) SourceRange

func (p SRGParameter) SourceRange() (compilercommon.SourceRange, bool)

SourceRange returns the source range for this parameter.

type SRGScopeOrImport

type SRGScopeOrImport interface {
	Name() (string, bool)
	IsNamedScope() bool // Whether this is a named scope.
	AsNamedScope() SRGNamedScope
	AsPackageImport() SRGExternalPackageImport
}

SRGScopeOrImport represents a named scope or an external package import.

type SRGType

type SRGType struct {
	compilergraph.GraphNode
	// contains filtered or unexported fields
}

SRGType wraps a type declaration or definition in the SRG.

func (SRGType) Alias

func (t SRGType) Alias() (string, bool)

Alias returns the global alias for this type, if any.

func (SRGType) AsNamedScope

func (t SRGType) AsNamedScope() SRGNamedScope

AsNamedScope returns the type as a named scope reference.

func (SRGType) Code

func (t SRGType) Code() (compilercommon.CodeSummary, bool)

Code returns a code-like summarization of the type, for human consumption.

func (SRGType) ComposedAgents

func (t SRGType) ComposedAgents() []SRGComposedAgent

ComposedAgents returns references to the agents composed by this type, if any.

func (SRGType) Documentation

func (t SRGType) Documentation() (SRGDocumentation, bool)

Documentation returns the documentation on the type, if any.

func (SRGType) FindMember

func (t SRGType) FindMember(name string) (SRGMember, bool)

FindMember returns the type member with the given name under this type, if any.

func (SRGType) FindOperator

func (t SRGType) FindOperator(name string) (SRGMember, bool)

FindOperator returns the operator with the given name under this type, if any.

func (SRGType) Generics

func (t SRGType) Generics() []SRGGeneric

Generics returns the generics on this type.

func (SRGType) GetMembers

func (t SRGType) GetMembers() []SRGMember

GetMembers returns the members on this type.

func (SRGType) HasComposedAgents

func (t SRGType) HasComposedAgents() bool

HasComposedAgents returns true if this SRG type composes any agents.

func (SRGType) IsExported added in v0.2.0

func (t SRGType) IsExported() bool

IsExported returns whether the given type is exported for use outside its package.

func (SRGType) Module

func (t SRGType) Module() SRGModule

Module returns the module under which the type is defined.

func (SRGType) Name

func (t SRGType) Name() (string, bool)

Name returns the name of this type. Can not exist in the partial-parsing case in tooling.

func (SRGType) Node

func (t SRGType) Node() compilergraph.GraphNode

Node returns the underlying type node for this type.

func (SRGType) PrincipalType

func (t SRGType) PrincipalType() (SRGTypeRef, bool)

PrincipalType returns a type reference to the principal type for this agent. Will only return a valid reference for AgentTypes.

func (SRGType) SourceRange

func (t SRGType) SourceRange() (compilercommon.SourceRange, bool)

SourceRange returns the source range for this type.

func (SRGType) TypeKind

func (t SRGType) TypeKind() TypeKind

GetTypeKind returns the kind matching the type definition/declaration node type.

func (SRGType) UniqueId

func (m SRGType) UniqueId() string

UniqueId returns a unique hash ID for the node that is stable across compilations.

func (SRGType) WrappedType

func (t SRGType) WrappedType() (SRGTypeRef, bool)

WrappedType returns a type reference to the wrapped type, if any. Will only return a valid reference for NominalTypes.

type SRGTypeOrGeneric

type SRGTypeOrGeneric struct {
	compilergraph.GraphNode
	// contains filtered or unexported fields
}

SRGTypeOrGeneric represents a resolved reference to a type or generic.

func (SRGTypeOrGeneric) AsType

func (t SRGTypeOrGeneric) AsType() SRGType

AsType returns this type or generic as a type. Panics if not a type.

func (SRGTypeOrGeneric) IsGeneric

func (t SRGTypeOrGeneric) IsGeneric() bool

IsGeneric returns whether this represents a reference to a generic.

func (SRGTypeOrGeneric) Name

func (t SRGTypeOrGeneric) Name() (string, bool)

Name returns the name of the referenced type or generic.

func (SRGTypeOrGeneric) Node

Node returns the underlying node.

func (SRGTypeOrGeneric) SourceRange

func (t SRGTypeOrGeneric) SourceRange() (compilercommon.SourceRange, bool)

SourceRange returns the source range for this resolved type or generic.

type SRGTypeOrMember

type SRGTypeOrMember struct {
	compilergraph.GraphNode
	// contains filtered or unexported fields
}

SRGTypeOrMember represents a resolved reference to a type or module member.

func (SRGTypeOrMember) AsMember

func (t SRGTypeOrMember) AsMember() (SRGMember, bool)

AsMember returns the type or member as a member, if applicable.

func (SRGTypeOrMember) AsType

func (t SRGTypeOrMember) AsType() (SRGType, bool)

AsType returns the type or member as a type, if applicable.

func (SRGTypeOrMember) ContainingModule

func (t SRGTypeOrMember) ContainingModule() SRGModule

ContainingModule returns the module containing this type or member.

func (SRGTypeOrMember) Generics

func (t SRGTypeOrMember) Generics() []SRGGeneric

Generics returns the generics of this type or member.

func (SRGTypeOrMember) IsType

func (t SRGTypeOrMember) IsType() bool

IsType returns whether this represents a reference to a type.

func (SRGTypeOrMember) Name

func (t SRGTypeOrMember) Name() (string, bool)

Name returns the name of the referenced type or member.

func (SRGTypeOrMember) Node

Node returns the underlying node.

func (SRGTypeOrMember) SourceRange

func (t SRGTypeOrMember) SourceRange() (compilercommon.SourceRange, bool)

SourceRange returns the source range for this resolved type or member.

type SRGTypeRef

type SRGTypeRef struct {
	compilergraph.GraphNode
	// contains filtered or unexported fields
}

SRGTypeRef represents a type reference defined in the SRG.

func (SRGTypeRef) Generics

func (t SRGTypeRef) Generics() []SRGTypeRef

Generics returns the generics defined on this type ref. Panics if this is not a RefKind of TypeRefPath.

func (SRGTypeRef) HasGenerics

func (t SRGTypeRef) HasGenerics() bool

HasGenerics returns whether this type reference has generics.

func (SRGTypeRef) HasParameters

func (t SRGTypeRef) HasParameters() bool

HasParameters returns whether this type reference has parameters.

func (SRGTypeRef) InnerReference

func (t SRGTypeRef) InnerReference() (SRGTypeRef, bool)

InnerReference returns the inner type reference, if this is a nullable or stream.

func (SRGTypeRef) Parameters

func (t SRGTypeRef) Parameters() []SRGTypeRef

Parameters returns the parameters defined on this type ref. Panics if this is not a RefKind of TypeRefPath.

func (SRGTypeRef) RefKind

func (t SRGTypeRef) RefKind() TypeRefKind

RefKind returns the kind of this type reference.

func (SRGTypeRef) ResolutionName

func (t SRGTypeRef) ResolutionName() string

ResolutionName returns the last piece of the ResolutionPath. Panics if this is not a RefKind of TypeRefPath.

func (SRGTypeRef) ResolutionPath

func (t SRGTypeRef) ResolutionPath() string

ResolutionPath returns the full resolution path for this type reference. Panics if this is not a RefKind of TypeRefPath.

func (SRGTypeRef) ResolveType

func (t SRGTypeRef) ResolveType() (TypeResolutionResult, bool)

ResolveType attempts to resolve the type path referenced by this type ref. Panics if this is not a RefKind of TypeRefPath.

func (SRGTypeRef) SourceRange

func (t SRGTypeRef) SourceRange() (compilercommon.SourceRange, bool)

SourceRange returns the source range for this type ref.

func (SRGTypeRef) String

func (t SRGTypeRef) String() string

String returns the human-readable string form of this type reference.

type SourceStructureFinder

type SourceStructureFinder struct {
	// contains filtered or unexported fields
}

SourceStructureFinder defines a helper type for looking up various structure within the source represented by an SRG.

func (*SourceStructureFinder) ScopeInContext

ScopeInContext returns all the named scope thats available in the context as defined by the given SRG node.

func (*SourceStructureFinder) TryGetContainingImplemented

func (f *SourceStructureFinder) TryGetContainingImplemented(node compilergraph.GraphNode) (SRGImplementable, bool)

TryGetContainingImplemented returns the member, property or function lambda node that contains the given node, if any.

func (*SourceStructureFinder) TryGetContainingImplementedWithOption

func (f *SourceStructureFinder) TryGetContainingImplementedWithOption(node compilergraph.GraphNode, option ContainingImplementedOption) (SRGImplementable, bool)

TryGetContainingImplementedWithOption returns the containing implemented of the given node with the given option, if any.

func (*SourceStructureFinder) TryGetContainingMemberOrType

func (f *SourceStructureFinder) TryGetContainingMemberOrType(node compilergraph.GraphNode) (SRGTypeOrMember, bool)

TryGetContainingMemberOrType returns the member or type that contains the given node, if any.

func (*SourceStructureFinder) TryGetContainingModule

func (f *SourceStructureFinder) TryGetContainingModule(node compilergraph.GraphNode) (SRGModule, bool)

TryGetContainingModule returns the containing module of the given SRG node, if any.

func (*SourceStructureFinder) TryGetContainingNode

func (f *SourceStructureFinder) TryGetContainingNode(node compilergraph.GraphNode, nodeTypes ...sourceshape.NodeType) (compilergraph.GraphNode, bool)

TryGetContainingNode returns the containing node of the given node that is one of the given types, if any.

func (*SourceStructureFinder) TryGetContainingType

func (f *SourceStructureFinder) TryGetContainingType(node compilergraph.GraphNode) (SRGType, bool)

TryGetContainingType returns the type that contains the given node, if any.

func (*SourceStructureFinder) TryGetNearestContainingNode

func (f *SourceStructureFinder) TryGetNearestContainingNode(node compilergraph.GraphNode, nodeTypes ...sourceshape.NodeType) (compilergraph.GraphNode, bool)

TryGetNearestContainingNode returns the containing node of the given node that is one of the given types, if any. If there are multiple such nodes, the node which is closest (by rune position) is returned.

type TypeKind

type TypeKind int

TypeKind defines the various supported kinds of types in the SRG.

const (
	ClassType TypeKind = iota
	InterfaceType
	NominalType
	StructType
	AgentType
)

func (TypeKind) String

func (i TypeKind) String() string

type TypeRefKind

type TypeRefKind int
const (
	TypeRefNullable TypeRefKind // A nullable type.
	TypeRefStream               // A stream type.
	TypeRefSlice                // A slice type.
	TypeRefMapping              // A mapping type.
	TypeRefPath                 // A normal path type. May have generics.
	TypeRefVoid                 // A void type reference.
	TypeRefStruct               // A struct type reference.
	TypeRefAny                  // An any type reference.
)

type TypeResolutionResult

type TypeResolutionResult struct {
	// IsExternalPackage returns whether the resolved type is, in fact, an external package.
	IsExternalPackage       bool
	ResolvedType            SRGTypeOrGeneric
	ExternalPackage         packageloader.PackageInfo
	ExternalPackageTypePath string
}

TypeResolutionResult defines the result of resolving a type or package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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