Documentation ¶
Overview ¶
Package scopegraph defines methods for creating and interacting with the Scope Information Graph, which represents the determing scopes of all expressions and statements.
Index ¶
- Constants
- Variables
- type BuildTarget
- type Config
- type NodeType
- type PromisingAccessType
- type ReferencedName
- func (rn ReferencedName) Code() (compilercommon.CodeSummary, bool)
- func (rn ReferencedName) IsLocal() bool
- func (rn ReferencedName) IsParameter() bool
- func (rn ReferencedName) IsPromising() typegraph.MemberPromisingOption
- func (rn ReferencedName) IsProperty() bool
- func (rn ReferencedName) IsStatic() bool
- func (rn ReferencedName) Member() (typegraph.TGMember, bool)
- func (rn ReferencedName) Name() (string, bool)
- func (rn ReferencedName) NameOrPanic() string
- func (rn ReferencedName) ReferencedNode() compilergraph.GraphNode
- func (rn ReferencedName) SourceRange() (compilercommon.SourceRange, bool)
- func (rn ReferencedName) SourceRanges() []compilercommon.SourceRange
- func (rn ReferencedName) Type() (typegraph.TGTypeDecl, bool)
- type Result
- type ScopeFilter
- type ScopeGraph
- func (sg *ScopeGraph) BuildTransientScope(transientNode compilergraph.GraphNode, ...) (proto.ScopeInfo, bool)
- func (sg *ScopeGraph) GetLanguageIntegration(sourceGraphID string) (integration.LanguageIntegration, bool)
- func (sg *ScopeGraph) GetReferencedName(scope proto.ScopeInfo) (ReferencedName, bool)
- func (sg *ScopeGraph) GetReturnType(node compilergraph.GraphNode) (typegraph.TypeReference, bool)
- func (sg *ScopeGraph) GetScope(srgNode compilergraph.GraphNode) (proto.ScopeInfo, bool)
- func (sg *ScopeGraph) HasSecondaryLabel(srgNode compilergraph.GraphNode, label proto.ScopeLabel) bool
- func (sg *ScopeGraph) IsDynamicPromisingName(name string) bool
- func (sg *ScopeGraph) IsPromisingMember(member typegraph.TGMember, accessType PromisingAccessType) bool
- func (sg *ScopeGraph) MustGetLanguageIntegration(sourceGraphID string) integration.LanguageIntegration
- func (sg *ScopeGraph) PackageLoader() *packageloader.PackageLoader
- func (sg *ScopeGraph) ReferencedNameForNamedScope(namedScope srg.SRGNamedScope) ReferencedName
- func (sg *ScopeGraph) ReferencedNameForTypeOrMember(typeOrMember typegraph.TGTypeOrMember) ReferencedName
- func (sg *ScopeGraph) ResolveSRGTypeRef(srgTypeRef srg.SRGTypeRef) (typegraph.TypeReference, error)
- func (sg *ScopeGraph) RootSourceFilePath() string
- func (sg *ScopeGraph) SourceGraph() *srg.SRG
- func (sg *ScopeGraph) TypeGraph() *typegraph.TypeGraph
Constants ¶
const ( // Connects a scope node to its SRG source. NodePredicateSource = "scope-source" // Decorates a scope node with its scope info. NodePredicateScopeInfo = "scope-info" // Connects a secondary label to its SRG source. NodePredicateLabelSource = "secondary-label-source" // Decorates a secondary label node with its label value. NodePredicateSecondaryLabelValue = "secondary-label-value" // Connects an error or warning to its SRG source. NodePredicateNoticeSource = "scope-notice" // The error or warning message on a scope notice node. NodePredicateNoticeMessage = "notice-message" )
const ANONYMOUS_REFERENCE = "_"
Variables ¶
var ( // Compilation indicates the scope graph is being built for compilation of code // and therefore should not process the remaining phases if any errors occur. Compilation = BuildTarget{"compilation", false, false, false, true} // Tooling indicates the scope graph is being built for IDE or other forms of tooling, // and that a partially valid graph should be returned. Tooling = BuildTarget{"tooling", true, true, true, false} )
var ALLOWED_ANONYMOUS = []compilergraph.Predicate{sourceshape.NodeArrowStatementDestination, sourceshape.NodeArrowStatementRejection}
Functions ¶
This section is empty.
Types ¶
type BuildTarget ¶
type BuildTarget struct {
// contains filtered or unexported fields
}
BuildTarget defines the target of the scoping being performed.
type Config ¶
type Config struct { // Entrypoint is the entrypoint path from which to begin scoping. Entrypoint packageloader.Entrypoint // VCSDevelopmentDirectories are the paths to the development directories, if any, that // override VCS imports. VCSDevelopmentDirectories []string // Libraries defines the libraries, if any, to import along with the root source file. Libraries []packageloader.Library // Target defines the target of the scope building. Target BuildTarget // PathLoader defines the path loader to use when parsing. PathLoader packageloader.PathLoader // ScopeFilter defines the filter, if any, to use when scoping. If specified, only those entrypoints // for which the filter returns true, will be scoped. ScopeFilter ScopeFilter // LanguageIntegration defines the language integrations to be used when performing parsing and scoping. If not specified, // the integrations are loaded from the binary's directory. LanguageIntegrations []integration.LanguageIntegration // contains filtered or unexported fields }
Config defines the configuration for scoping.
func (Config) WithCancel ¶ added in v0.3.0
func (c Config) WithCancel() (Config, compilerutil.CancelFunction)
WithCancel returns the config with added support for cancelation.
type PromisingAccessType ¶
type PromisingAccessType int
PromisingAccessType defines an enumeration of access types for the IsPromisingMember check.
const ( // PromisingAccessFunctionCall indicates that the expression is being invoked as a function // call and the function itself should be checked if promising. PromisingAccessFunctionCall PromisingAccessType = iota // PromisingAccessImplicitGet indicates the expression is calling a property via an implicit // get and the property's getter should be checked. PromisingAccessImplicitGet // PromisingAccessImplicitSet indicates the expression is calling a property via an implicit // set and the property's setter should be checked. PromisingAccessImplicitSet // PromisingAccessInitializer indicates that the initializer of a variable is being accessed // and should be checked. PromisingAccessInitializer )
type ReferencedName ¶
type ReferencedName struct {
// contains filtered or unexported fields
}
func (ReferencedName) Code ¶
func (rn ReferencedName) Code() (compilercommon.CodeSummary, bool)
Code returns a code-like summarization of the referenced name, for human consumption.
func (ReferencedName) IsLocal ¶
func (rn ReferencedName) IsLocal() bool
IsLocal returns true if the referenced name is in the local scope.
func (ReferencedName) IsParameter ¶ added in v0.3.2
func (rn ReferencedName) IsParameter() bool
IsParameter returns true if the referenced name is a parameter.
func (ReferencedName) IsPromising ¶
func (rn ReferencedName) IsPromising() typegraph.MemberPromisingOption
IsPromising returns whether the referenced name is promising.
func (ReferencedName) IsProperty ¶
func (rn ReferencedName) IsProperty() bool
IsProperty returns true if the referenced name points to a property.
func (ReferencedName) IsStatic ¶
func (rn ReferencedName) IsStatic() bool
IsStatic returns true if the referenced name is static.
func (ReferencedName) Member ¶
func (rn ReferencedName) Member() (typegraph.TGMember, bool)
Member returns the type member referred to by this referenced, if any.
func (ReferencedName) Name ¶
func (rn ReferencedName) Name() (string, bool)
The name of the referenced node.
func (ReferencedName) NameOrPanic ¶
func (rn ReferencedName) NameOrPanic() string
The name of the referenced node.
func (ReferencedName) ReferencedNode ¶
func (rn ReferencedName) ReferencedNode() compilergraph.GraphNode
ReferencedNode returns the named node underlying this referenced name.
func (ReferencedName) SourceRange ¶
func (rn ReferencedName) SourceRange() (compilercommon.SourceRange, bool)
SourceRange returns the primary source range for the referenced node, if any.
func (ReferencedName) SourceRanges ¶
func (rn ReferencedName) SourceRanges() []compilercommon.SourceRange
SourceRanges returns the set of source ranges for the referenced node, if any.
func (ReferencedName) Type ¶
func (rn ReferencedName) Type() (typegraph.TGTypeDecl, bool)
Type returns the type referred to by this referenced, if any.
type Result ¶
type Result struct { Status bool // Whether the construction succeeded. Warnings []compilercommon.SourceWarning // Any warnings encountered during construction. Errors []compilercommon.SourceError // Any errors encountered during construction. Graph *ScopeGraph // The constructed scope graph. SourceTracker packageloader.SourceTracker // The source tracker. LanguageIntegrations []integration.LanguageIntegration // The language integrations used when scoping. }
Result represents the results of building a scope graph.
func ParseAndBuildScopeGraph ¶
func ParseAndBuildScopeGraph(rootSourceFilePath string, vcsDevelopmentDirectories []string, libraries ...packageloader.Library) (Result, error)
ParseAndBuildScopeGraph conducts full parsing, type graph construction and scoping for the project starting at the given root source file.
func ParseAndBuildScopeGraphWithConfig ¶
ParseAndBuildScopeGraphWithConfig conducts full parsing, type graph construction and scoping for the project starting at the root source file specified in configuration. If an *internal error* occurs, it is returned as the `err`. Parsing and scoping errors are returned in the Result.
type ScopeFilter ¶
type ScopeFilter func(inputSource compilercommon.InputSource) bool
ScopeFilter defines a filtering function for only scoping certain nodes in the SRG.
type ScopeGraph ¶
type ScopeGraph struct {
// contains filtered or unexported fields
}
ScopeGraph represents the ScopeGraph layer and all its associated helper methods.
func (*ScopeGraph) BuildTransientScope ¶
func (sg *ScopeGraph) BuildTransientScope(transientNode compilergraph.GraphNode, parentImplementable srg.SRGImplementable) (proto.ScopeInfo, bool)
BuildTransientScope builds the scope for the given transient node, as scoped under the given parent node. Note that this method should *only* be used for transient nodes (i.e. expressions in something like Grok), and that the scope created will not be saved anywhere once this method returns.
func (*ScopeGraph) GetLanguageIntegration ¶
func (sg *ScopeGraph) GetLanguageIntegration(sourceGraphID string) (integration.LanguageIntegration, bool)
GetLanguageIntegration returns the language integration with the given source graph ID, if any.
func (*ScopeGraph) GetReferencedName ¶
func (sg *ScopeGraph) GetReferencedName(scope proto.ScopeInfo) (ReferencedName, bool)
GetReferencedName returns the ReferencedName struct for the given scope, if it refers to a named scope.
func (*ScopeGraph) GetReturnType ¶ added in v0.3.0
func (sg *ScopeGraph) GetReturnType(node compilergraph.GraphNode) (typegraph.TypeReference, bool)
GetReturnType returns the return type defined for the given node, whether it be a member, a property getter or a lambda expression.
func (*ScopeGraph) GetScope ¶
func (sg *ScopeGraph) GetScope(srgNode compilergraph.GraphNode) (proto.ScopeInfo, bool)
GetScope returns the scope for the given SRG node, if any.
func (*ScopeGraph) HasSecondaryLabel ¶
func (sg *ScopeGraph) HasSecondaryLabel(srgNode compilergraph.GraphNode, label proto.ScopeLabel) bool
HasSecondaryLabel returns whether the given SRG node has a secondary scope label of the given kind.
func (*ScopeGraph) IsDynamicPromisingName ¶
func (sg *ScopeGraph) IsDynamicPromisingName(name string) bool
IsDynamicPromisingName returns true if the given name is considered dynamically promising in the graph. Such a name, when accessed dynamically, *may* return a promise.
func (*ScopeGraph) IsPromisingMember ¶
func (sg *ScopeGraph) IsPromisingMember(member typegraph.TGMember, accessType PromisingAccessType) bool
IsPromisingMember returns whether the member, when accessed via the given access type, returns a promise.
func (*ScopeGraph) MustGetLanguageIntegration ¶
func (sg *ScopeGraph) MustGetLanguageIntegration(sourceGraphID string) integration.LanguageIntegration
MustGetLanguageIntegration returns the language integration with the given source graph ID or panics.
func (*ScopeGraph) PackageLoader ¶
func (sg *ScopeGraph) PackageLoader() *packageloader.PackageLoader
PackageLoader returns the package loader behind this scope graph.
func (*ScopeGraph) ReferencedNameForNamedScope ¶
func (sg *ScopeGraph) ReferencedNameForNamedScope(namedScope srg.SRGNamedScope) ReferencedName
ReferencedNameForNamedScope returns a ReferencedName instance for the given named scope.
func (*ScopeGraph) ReferencedNameForTypeOrMember ¶
func (sg *ScopeGraph) ReferencedNameForTypeOrMember(typeOrMember typegraph.TGTypeOrMember) ReferencedName
ReferencedNameForTypeOrMember returns a ReferencedName instance for the given type or member.
func (*ScopeGraph) ResolveSRGTypeRef ¶
func (sg *ScopeGraph) ResolveSRGTypeRef(srgTypeRef srg.SRGTypeRef) (typegraph.TypeReference, error)
ResolveSRGTypeRef builds an SRG type reference into a resolved type reference.
func (*ScopeGraph) RootSourceFilePath ¶
func (sg *ScopeGraph) RootSourceFilePath() string
RootSourceFilePath returns the root source file for this scope graph.
func (*ScopeGraph) SourceGraph ¶
func (sg *ScopeGraph) SourceGraph() *srg.SRG
SourceGraph returns the SRG behind this scope graph.
func (*ScopeGraph) TypeGraph ¶
func (sg *ScopeGraph) TypeGraph() *typegraph.TypeGraph
TypeGraph returns the type graph behind this scope graph.
Source Files ¶
- builder.go
- builder_appliers.go
- config.go
- construction.go
- dynamicdependencycollector.go
- helpers.go
- namedscope.go
- nodetype_string.go
- promise_labeler.go
- referencedname.go
- scope_access_expr.go
- scope_arrow_expr.go
- scope_flow_expr.go
- scope_lambda_expr.go
- scope_literal_expr.go
- scope_members.go
- scope_name_expr.go
- scope_op_expr.go
- scope_sml_expr.go
- scope_statements.go
- scope_vars.go
- scopecontext.go
- scopegraph.go
- scopegraph_types.go
- scopeinfo.go
- statementlabelset.go
- staticdependencycollector.go
- util.go