compilergraph

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2017 License: BSD-3-Clause Imports: 12 Imported by: 14

Documentation

Overview

compilergraph package defines methods for loading and populating the overall Serulian graph.

Index

Constants

View Source
const (
	WhereLTE clientQueryOperation = iota // Integer: Less than or equals
	WhereGTE                             // Integer: Greater than or equals
	WhereLT                              // Integer: Less than
	WhereGT                              // Integer: Greater than
)
View Source
const NodeIDLength = 36

The length of node IDs in characters.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientQuery

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

ClientQuery represents a query which does client-side processing of nodes returned by Cayley.

func (*ClientQuery) BuildNodeIterator

func (cq *ClientQuery) BuildNodeIterator(predicates ...Predicate) NodeIterator

BuildNodeIterator returns a NodeIterator over the query.

func (*ClientQuery) HasWhere

func (cq *ClientQuery) HasWhere(predicate Predicate, op clientQueryOperation, value interface{}) Query

HasWhere starts a new client-side query from the current query.

func (*ClientQuery) TryGetNode

func (cq *ClientQuery) TryGetNode() (GraphNode, bool)

TryGetNode attempts to return the node found.

type EmptyIterator

type EmptyIterator struct{}

An empty node iterator.

func (EmptyIterator) GetPredicate

func (ei EmptyIterator) GetPredicate(predicate Predicate) GraphValue

func (EmptyIterator) Next

func (ei EmptyIterator) Next() bool

func (EmptyIterator) Node

func (ei EmptyIterator) Node() GraphNode

func (EmptyIterator) TaggedValue

func (ei EmptyIterator) TaggedValue(predicate Predicate, example TaggedValue) interface{}

type FilteredQuery

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

FilteredQuery is a type which wraps a GraphQuery and executes additional filtering.

func (FilteredQuery) BuildNodeIterator

func (fq FilteredQuery) BuildNodeIterator(predicates ...Predicate) NodeIterator

BuildNodeIterator returns an iterator over the filtered query.

func (FilteredQuery) HasWhere

func (fq FilteredQuery) HasWhere(predicate Predicate, op clientQueryOperation, value interface{}) Query

HasWhere starts a new client query.

func (FilteredQuery) TryGetNode

func (fq FilteredQuery) TryGetNode() (GraphNode, bool)

TryGetNode executes the query and returns the single node found or false. If there is more than a single node as a result of the query, the first node is returned.

type GraphLayer

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

GraphLayer represents a single layer in the overall project graph.

func (*GraphLayer) FindNodesOfKind

func (gl *GraphLayer) FindNodesOfKind(kinds ...TaggedValue) GraphQuery

FindNodesOfKind returns a new query starting at the nodes who have the given kind in this layer.

func (*GraphLayer) FindNodesWithTaggedType

func (gl *GraphLayer) FindNodesWithTaggedType(predicate Predicate, values ...TaggedValue) GraphQuery

FindNodesWithTaggedType returns a new query starting at the nodes who are linked to tagged values (of the given name) by the given predicate.

For example:

`FindNodesWithTaggedType("parser-ast-node-type", NodeType.Class, NodeType.Interface)` would return all classes and interfaces.

func (*GraphLayer) Freeze added in v0.0.2

func (gl *GraphLayer) Freeze()

Freeze freezes the layer, preventing any further modification.

func (*GraphLayer) GetNode

func (gl *GraphLayer) GetNode(nodeID GraphNodeId) GraphNode

GetNode returns a node found in the graph layer.

func (*GraphLayer) NewModifier

func (gl *GraphLayer) NewModifier() GraphLayerModifier

NewModifier returns a new layer modifier for modifying the graph.

func (*GraphLayer) StartQuery

func (gl *GraphLayer) StartQuery(values ...interface{}) GraphQuery

StartQuery returns a new query starting at the nodes with the given values (either graph node IDs or arbitrary values).

func (*GraphLayer) StartQueryFromNode

func (gl *GraphLayer) StartQueryFromNode(nodeId GraphNodeId) GraphQuery

StartQueryFromNods returns a new query starting at the node with the given IDs.

func (*GraphLayer) StartQueryFromNodes

func (gl *GraphLayer) StartQueryFromNodes(nodeIds ...GraphNodeId) GraphQuery

StartQueryFromNodes returns a new query starting at the nodes with the given IDs.

func (*GraphLayer) TryGetNode

func (gl *GraphLayer) TryGetNode(nodeID GraphNodeId) (GraphNode, bool)

TryGetNode tries to return a node found in the graph layer.

func (*GraphLayer) Unfreeze added in v0.0.2

func (gl *GraphLayer) Unfreeze()

Unfreeze unfreezes the layer, allowing for additional modification.

func (*GraphLayer) WalkOutward

func (gl *GraphLayer) WalkOutward(startingNodes []GraphNode, callback WalkCallback)

WalkOutward walks the graph layer outward, starting from the specified nodes, and hitting each node found from the outgoing predicates in the layer. Note that this method can be quite slow, so it should only be used for testing.

type GraphLayerModifier

type GraphLayerModifier interface {
	CreateNode(nodeKind TaggedValue) ModifiableGraphNode
	Modify(node GraphNode) ModifiableGraphNode
	Apply()
	Close()
}

GraphLayerModifier defines the interface for modifying a graph layer.

type GraphNode

type GraphNode struct {
	NodeId GraphNodeId // Unique ID for the node.
	// contains filtered or unexported fields
}

GraphNode represents a single node in a graph layer.

func (GraphNode) Clone

Clone returns a clone of this graph node, with all *outgoing* predicates copied.

func (GraphNode) CloneExcept

func (gn GraphNode) CloneExcept(modifier GraphLayerModifier, predicates ...Predicate) ModifiableGraphNode

CloneExcept returns a clone of this graph node, with all *outgoing* predicates copied except those specified.

func (GraphNode) Get

func (gn GraphNode) Get(predicate Predicate) string

Get returns the stringvalue of the given predicate found on this node and panics otherwise.

func (GraphNode) GetAllTagged

func (gn GraphNode) GetAllTagged(predicate Predicate, example TaggedValue) []interface{}

GetAllTagged returns the tagged values of the given predicate found on this node.

func (GraphNode) GetIncomingNode

func (gn GraphNode) GetIncomingNode(predicate Predicate) GraphNode

GetIncomingNode returns the node in this layer found off of the given predicate coming into this node and panics otherwise.

func (GraphNode) GetNode

func (gn GraphNode) GetNode(predicate Predicate) GraphNode

GetNode returns the node in this layer found off of the given predicate found on this node and panics otherwise.

func (GraphNode) GetNodeId

func (gn GraphNode) GetNodeId() GraphNodeId

GetNodeId returns the node's ID.

func (GraphNode) GetNodeInLayer

func (gn GraphNode) GetNodeInLayer(predicate Predicate, layer *GraphLayer) GraphNode

GetNodeInLayer returns the node in the specified layer found off of the given predicate found on this node and panics otherwise.

func (GraphNode) GetTagged

func (gn GraphNode) GetTagged(predicate Predicate, example TaggedValue) interface{}

GetTagged returns the value of the given predicate found on this node, "cast" to the type of the given tagged value.

func (GraphNode) GetValue

func (gn GraphNode) GetValue(predicate Predicate) GraphValue

GetValue returns the value of the given predicate found on this node and panics otherwise.

func (GraphNode) Kind

func (gn GraphNode) Kind() TaggedValue

Kind returns the kind of this node.

func (GraphNode) OutgoingNodeIterator

func (gn GraphNode) OutgoingNodeIterator() OutgoingNodeIterator

OutgoingNodeIterator returns an OutgoingNodeIterator instance for this graph node. The iterator provides an easy way of iterating over all the outgoing nodes accessible directly from this node *in this node's layer*.

func (GraphNode) StartQuery

func (gn GraphNode) StartQuery() GraphQuery

StartQuery starts a new query on the graph layer, with its origin being the current node.

func (GraphNode) StartQueryToLayer

func (gn GraphNode) StartQueryToLayer(layer *GraphLayer) GraphQuery

StartQueryToLayer starts a new query on the specified graph layer, with its origin being the current node.

func (GraphNode) TryGet

func (gn GraphNode) TryGet(predicate Predicate) (string, bool)

TryGet returns the string value of the given predicate found on this node (if any).

func (GraphNode) TryGetIncoming

func (gn GraphNode) TryGetIncoming(predicate Predicate) (string, bool)

TryGetIncoming returns the string value of the given predicate coming into this node (if any).

func (GraphNode) TryGetIncomingNode

func (gn GraphNode) TryGetIncomingNode(predicate Predicate) (GraphNode, bool)

TryGetIncomingNode returns the node in this layer found off of the given predicate coming into this node (if any).

func (GraphNode) TryGetIncomingValue

func (gn GraphNode) TryGetIncomingValue(predicate Predicate) (GraphValue, bool)

TryGetIncomingValue returns the value of the given predicate coming into this node (if any).

func (GraphNode) TryGetNode

func (gn GraphNode) TryGetNode(predicate Predicate) (GraphNode, bool)

TryGetNode returns the node in this layer found off of the given predicate found on this node (if any).

func (GraphNode) TryGetNodeInLayer

func (gn GraphNode) TryGetNodeInLayer(predicate Predicate, layer *GraphLayer) (GraphNode, bool)

TryGetNodeInLayer returns the node found off of the given predicate found on this node (if any).

func (GraphNode) TryGetTagged

func (gn GraphNode) TryGetTagged(predicate Predicate, example TaggedValue) (interface{}, bool)

TryGetTagged returns the value of the given predicate found on this node, "cast" to the type of the given tagged value, if any.

func (GraphNode) TryGetValue

func (gn GraphNode) TryGetValue(predicate Predicate) (GraphValue, bool)

TryGetValue returns the value of the given predicate found on this node (if any).

type GraphNodeId

type GraphNodeId string

GraphNodeId represents an ID for a node in the graph.

type GraphNodeInterface

type GraphNodeInterface interface {
	GetNodeId() GraphNodeId
}

GraphNodeInterface defines the interface for a simple graph node, either already existing or being constructed by the modifier.

type GraphQuery

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

GraphQuery is a type which wraps a Cayley Path and provides nice accessors for querying the graph layer.

func (GraphQuery) BuildNodeIterator

func (gq GraphQuery) BuildNodeIterator(predicates ...Predicate) NodeIterator

BuildNodeIterator returns an iterator for retrieving the results of the query, with each result being a struct representing the node and the values found outgoing at the given predicates.

func (GraphQuery) FilterBy

func (gq GraphQuery) FilterBy(filter nodeFilter) FilteredQuery

FilterBy returns a query which further filters the current query, but leaves the virtual "cursor" at the current nodes.

func (GraphQuery) GetNode

func (gq GraphQuery) GetNode() GraphNode

GetNode executes the query and returns the single node found or panics.

func (GraphQuery) Has

func (gq GraphQuery) Has(via Predicate, values ...interface{}) GraphQuery

Has filters this Query to represent the nodes that have some linkage to some values.

func (GraphQuery) HasTagged

func (gq GraphQuery) HasTagged(via Predicate, values ...TaggedValue) GraphQuery

HasTagged filters this Query to represent the nodes that have some linkage to some values.

func (GraphQuery) HasWhere

func (gq GraphQuery) HasWhere(predicate Predicate, op clientQueryOperation, value interface{}) Query

HasWhere starts a new client query.

func (GraphQuery) In

func (gq GraphQuery) In(via ...Predicate) GraphQuery

In updates this Query to represent the nodes that are adjacent to the current nodes, via the given inbound predicate.

func (GraphQuery) InIfKind

func (gq GraphQuery) InIfKind(predicate Predicate, kind TaggedValue) GraphQuery

InIfKind returns a query that follows the given inbound predicate, but only if the current node has the given kind.

func (GraphQuery) IsKind

func (gq GraphQuery) IsKind(nodeKinds ...TaggedValue) GraphQuery

IsKind updates this Query to represent only those nodes that are of the given kind.

func (GraphQuery) Out

func (gq GraphQuery) Out(via ...Predicate) GraphQuery

Out updates this Query to represent the nodes that are adjacent to the current nodes, via the given outbound predicate.

func (GraphQuery) TryGetNode

func (gq GraphQuery) TryGetNode() (GraphNode, bool)

TryGetNode executes the query and returns the single node found or false. If there is more than a single node as a result of the query, the first node is returned.

func (GraphQuery) With

func (gq GraphQuery) With(predicate Predicate) GraphQuery

With updates this Query to represents the nodes that have the given predicate.

type GraphValue

type GraphValue struct {
	quad.Value
}

GraphValue defines the various values that can be found in the graph off of predicates.

func (GraphValue) Int

func (gv GraphValue) Int() int

Int returns the GraphValue as an int.

func (GraphValue) NodeId

func (gv GraphValue) NodeId() GraphNodeId

NodeId returns the GraphNodeId as a node ID.

func (GraphValue) String

func (gv GraphValue) String() string

String returns the GraphValue as a string.

func (GraphValue) Tagged

func (gv GraphValue) Tagged(graphLayer *GraphLayer, example TaggedValue) interface{}

Tagged returns the GraphValue as a TaggedValue.

type ModifiableGraphNode

type ModifiableGraphNode struct {
	NodeId GraphNodeId // Unique ID for the node.
	Kind   TaggedValue // The kind of the node.
	// contains filtered or unexported fields
}

ModifiableGraphNode represents a graph node that will be added to the graph once the modifier transaction is applied. If already in the graph, represents a node that can be changed.

func (ModifiableGraphNode) AsNode

func (gn ModifiableGraphNode) AsNode() GraphNode

AsNode returns the ModifiableGraphNode as a GraphNode. Note that the node will not yet be in the layer unless Apply has been called, and therefore calling operations on it are undefined.

func (ModifiableGraphNode) CloneExcept

func (gn ModifiableGraphNode) CloneExcept(predicates ...Predicate) ModifiableGraphNode

CloneExcept returns a clone of this graph node, with all *outgoing* predicates copied except those specified.

func (ModifiableGraphNode) Connect

func (gn ModifiableGraphNode) Connect(predicate Predicate, target GraphNodeInterface)

Connect decorates the given graph node with a predicate pointing at the given target node.

func (ModifiableGraphNode) Decorate

func (gn ModifiableGraphNode) Decorate(predicate Predicate, value string)

Decorate decorates the given graph node with a predicate with the given string value.

func (ModifiableGraphNode) DecorateWith

func (gn ModifiableGraphNode) DecorateWith(predicate Predicate, value interface{})

DecorateWith decorates the given graph node with a predicate with the given Go value.

func (ModifiableGraphNode) DecorateWithTagged

func (gn ModifiableGraphNode) DecorateWithTagged(predicate Predicate, value TaggedValue)

DecorateWithTagged decorates the given graph node with a predicate pointing to a tagged value. Tagged values are typically used for values that would otherwise not be unique (such as enums).

func (ModifiableGraphNode) DecorateWithValue

func (gn ModifiableGraphNode) DecorateWithValue(predicate Predicate, value GraphValue)

DecorateWithValue decorates the given graph node with a predicate with the given value.

func (ModifiableGraphNode) GetNodeId

func (gn ModifiableGraphNode) GetNodeId() GraphNodeId

GetNodeId returns the node's ID.

func (ModifiableGraphNode) Modifier

Modifier returns the modifier used to create this node.

type NodeIterator

type NodeIterator interface {
	// Next move the iterator forward to the next node and returns whether a node is available.
	Next() bool

	// Node returns the current node.
	Node() GraphNode

	// TaggedValue returns the tagged value at the predicate in the Values list.
	TaggedValue(predicate Predicate, example TaggedValue) interface{}

	// Get returns the GraphValue for the given predicate on the current node. Note
	// that the predicate must have been requested in the call to BuildNodeIterator
	// or this call will panic.
	GetPredicate(predicate Predicate) GraphValue
	// contains filtered or unexported methods
}

NodeIterator represents an iterator over a query's found nodes.

type OutgoingNodeIterator

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

func (OutgoingNodeIterator) Next

func (oni OutgoingNodeIterator) Next() bool

func (OutgoingNodeIterator) Node

func (oni OutgoingNodeIterator) Node() GraphNode

type Predicate

type Predicate string

Predicate represents a predicate on a node in the graph.

type Query

type Query interface {
	// HasWhere starts a new client-side query from the current query.
	HasWhere(predicate Predicate, op clientQueryOperation, value interface{}) Query

	// BuildNodeIterator returns a NodeIterator over the query.
	BuildNodeIterator(predicates ...Predicate) NodeIterator

	// TryGetNode attempts to return the node found.
	TryGetNode() (GraphNode, bool)
}

Query represents all the different types of queries supported.

type SerulianGraph

type SerulianGraph struct {
	RootSourceFilePath string // The root source file path.
	// contains filtered or unexported fields
}

SerulianGraph represents a full Serulian graph, including its AST (SRG), type system (TG) and other various graphs used by the compiler.

func NewGraph

func NewGraph(rootSourceFilePath string) (*SerulianGraph, error)

NewGraph creates and returns a SerulianGraph rooted at the specified root source file.

func (*SerulianGraph) NewGraphLayer

func (sg *SerulianGraph) NewGraphLayer(uniqueID string, nodeKindEnum TaggedValue) *GraphLayer

NewGraphLayer returns a new graph layer of the given kind.

type TaggedValue

type TaggedValue interface {
	Name() string                   // The unique name for this kind of value.
	Value() string                  // The string value.
	Build(value string) interface{} // Builds a new tagged value from the given value string.
}

taggedValue defines an interface for storing uniquely tagged string data in the graph.

type WalkCallback

type WalkCallback func(result *WalkResult) bool

WalkCallback is a callback invoked for each step of a walk. If the callback returns false, the walk is terminated immediately.

type WalkResult

type WalkResult struct {
	ParentNode        *GraphNode        // The parent node that led to this node in the walk. May be nil.
	IncomingPredicate string            // The predicate followed from the parent node to this node.
	Node              GraphNode         // The current node.
	Predicates        map[string]string // The list of outgoing predicates on this node.
}

WalkResult is a result for each step of a walk.

Jump to

Keyboard shortcuts

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