compilergraph

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: 11 Imported by: 14

Documentation

Overview

Package compilergraph 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

NodeIDLength is 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 interface {
	// NewModifier returns a new layer modifier for modifying the graph.
	NewModifier() GraphLayerModifier

	// Freeze freezes the layer, preventing any further modification. Any attempt to apply a modifier
	// to a frozen layer will panic.
	Freeze()

	// Unfreeze unfreezes the layer, allowing for additional modification.
	Unfreeze()

	// GetNode returns a node found in the graph layer.
	GetNode(nodeID GraphNodeId) GraphNode

	// TryGetNode tries to return a node found in the graph layer.
	TryGetNode(nodeID GraphNodeId) (GraphNode, bool)

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

	// StartQueryFromNods returns a new query starting at the node with the given IDs.
	StartQueryFromNode(nodeID GraphNodeId) GraphQuery

	// StartQueryFromNodes returns a new query starting at the nodes with the given IDs.
	StartQueryFromNodes(nodeIds ...GraphNodeId) GraphQuery

	// FindNodesOfKind returns a new query starting at the nodes who have the given kind in this layer.
	FindNodesOfKind(kinds ...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.
	FindNodesWithTaggedType(predicate Predicate, values ...TaggedValue) GraphQuery

	// 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.
	WalkOutward(startingNodes []GraphNode, callback WalkCallback)
	// contains filtered or unexported methods
}

GraphLayer defines a single layer within a graph. A graph layer can be thought of as its own sub-graph, with clearly defined edges connecting between different layers.

type GraphLayerModifier

type GraphLayerModifier interface {
	// CreateNode enqueues the creation of a new node of the given kind.
	CreateNode(nodeKind TaggedValue) ModifiableGraphNode

	// Modify returns a ModifiableGraphNode for decorating or connecting an existing
	// node in the layer.
	Modify(node GraphNode) ModifiableGraphNode

	// Apply applies all queued changes to the underlying graph layer.
	Apply()

	// Close closes the modifier, discarding any enqueued changes.
	Close()

	// ApplyOrClose applies the modifier if the given apply bool is true.
	ApplyOrClose(apply bool)
}

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) 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 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 interface {
	// NewGraphLayer returns a new graph layer, with the given unique ID and a TaggedValue representing
	// the enumeration of all kinds of nodes found in the layer. Note that the unique ID should be
	// human-readable.
	NewGraphLayer(uniqueID string, nodeKindEnum TaggedValue) GraphLayer

	// RootSourceFilePath returns the path of the root source file (or directory, if under tooling) for
	// which this graph is being built.
	RootSourceFilePath() string
}

SerulianGraph represents a full graph being processed by the Serulian toolkit. Each step or phase of the compilation or other operation will add one or more graph layers, each representing a unique set of information.

func NewGraph

func NewGraph(rootSourceFilePath string) (SerulianGraph, error)

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

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