scopegraph

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: 0

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

View Source
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"
)
View Source
const ANONYMOUS_REFERENCE = "_"

Variables

View Source
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}
)

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 NodeType

type NodeType int

NodeType identifies the type of scope graph nodes.

const (
	// Top-level
	NodeTypeError          NodeType = iota // A scope error
	NodeTypeWarning                        // A scope warning
	NodeTypeResolvedScope                  // Resolved scope for an SRG node
	NodeTypeSecondaryLabel                 // A secondary label on an SRG node

	// NodeType is a tagged type.
	NodeTypeTagged
)

func (NodeType) Build

func (t NodeType) Build(value string) interface{}

func (NodeType) Name

func (t NodeType) Name() string

func (NodeType) String

func (i NodeType) String() string

func (NodeType) Value

func (t NodeType) Value() string

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

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

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

func ParseAndBuildScopeGraphWithConfig(config Config) (Result, error)

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.

Directories

Path Synopsis
Package proto is a generated protocol buffer package.
Package proto is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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