typegraph

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: 18 Imported by: 17

Documentation

Overview

typegraph package defines methods for creating and interacting with the Type Graph, which represents the definitions of all types (classes, interfaces, etc) in the Serulian type system defined by the parsed SRG.

Index

Constants

View Source
const (
	// Connects a node to its error node.
	NodePredicateError = "node-error"

	// Connects a node to the source node in the source graph (SRG, IRG, etc).
	NodePredicateSource = "source-node"

	// Decorates a type or type member node with the path of its source module.
	NodePredicateModulePath = "source-module"

	// Connects a type or type member with its documentation.
	NodePredicateDocumentation = "documentation"

	// The message for the parsing error.
	NodePredicateErrorMessage = "error-message"

	// Connects a type or module to a member (function, var, etc).
	NodePredicateMember = "node-member"

	//
	// NodeTypeModule
	//
	NodePredicateModuleName = "module-name"

	// Connects a type declaration to its parent module.
	NodePredicateTypeModule = "declaration-module"

	// Marks a type with its name.
	NodePredicateTypeName = "type-name"

	// Marks a type with its global ID.
	NodePredicateTypeGlobalId = "type-globalid"

	// Marks a type as being publicly exported from its package.
	NodePredicateTypeExported = "type-exported"

	// Connects a type declaration to an operator (function, var, etc).
	NodePredicateTypeOperator = "declaration-operator"

	// Connects a type declaration to a generic.
	NodePredicateTypeGeneric = "declaration-generic"

	// Marks a type with its global alias.
	NodePredicateTypeGlobalAlias = "type-alias"

	// Connects a type declaration to a custom attribute.
	NodePredicateTypeAttribute = "type-attribute"

	// Marks a type with a type reference to a parent type.
	NodePredicateParentType = "parent-type"

	// Marks a class or agent with a reference to an agent it composes.
	NodePredicateComposedAgent = "composed-agent"

	// Marks an agent with a type reference to its principal type.
	NodePredicatePrincipalType = "principal-type"

	// Connects a type alias to the type it is aliasing.
	NodePredicateAliasedType = "aliased-type"

	// Marks an agent reference with the type of the agent being composed.
	NodePredicateAgentType = "agent-type"

	// Decorates an agent reference with the name that will be used when composed into
	// the type.
	NodePredicateAgentCompositionName = "agent-composition-name"

	// Decorates a generic definition to its name.
	NodePredicateGenericName = "generic-name"

	// Connects a generic definition to its subtype reference (usually 'any').
	NodePredicateGenericSubtype = "generic-subtype"

	// Decorates a generic definition with its index.
	NodePredicateGenericIndex = "generic-index"

	// Decorates a generic definition with its kind (type generic or member generic)
	NodePredicateGenericKind = "generic-kind"

	// Marks a member with its name.
	NodePredicateMemberName = "member-name"

	// Marks a member as being read-only.
	NodePredicateMemberReadOnly = "member-readonly"

	// Marks a member as being "static", i.e. accessed under the type, rather than instances.
	NodePredicateMemberStatic = "member-static"

	// Marks a member with its resolved type.
	NodePredicateMemberType = "member-resolved-type"

	// Marks a member with a generic.
	NodePredicateMemberGeneric = "member-generic"

	// Marks a member with a parameter.
	NodePredicateMemberParameter = "member-parameter"

	// Marks a member with its signature.
	NodePredicateMemberSignature = "member-signature"

	// Marks a member with the fact that it is exported.
	NodePredicateMemberExported = "member-exported"

	// Connects a member to a returnable definition, itself connected to an SRG node.
	NodePredicateReturnable = "member-returnable"

	// Decorates a member as being a field holding data in the type.
	NodePredicateMemberField = "member-field"

	// Connects a member to the member in the parent type from which it was cloned.
	NodePredicateMemberBaseMember = "member-base-member"

	// Decorates a member with the type from which it was aliased.
	NodePredicateMemberBaseSource = "member-base-source"

	// Decorates a member as shadowing another member.
	NodePredicateMemberShadows = "member-shadows"

	// Decorates a member returning a promise of the member or return type.
	NodePredicateMemberPromising = "member-promising"

	// Decorates a member as being automatically initialized with a default value.
	NodePredicateMemberHasDefaultValue = "member-hasdefault"

	// Decorates a member as being implicitly called on access or assignment. Used for
	// properties that are backed by functions.
	NodePredicateMemberImplicitlyCalled = "member-implicitly-called"

	// Decorates a member as being executed under an asynchronously invoked worker.
	NodePredicateMemberInvokesAsync = "member-invokes-async"

	// Connects a member to a member tag.
	NodePredicateMemberTag = "member-tag"

	// Marks an operator with its searchable name.
	NodePredicateOperatorName = "operator-name"

	// Marks an operator as being a call to a native (ES) operator.
	NodePredicateOperatorNative = "operator-native"

	// Decorates a parameter with its name.
	NodePredicateParameterName = "parameter-name"

	// Decorates a parameter with its documentation.
	NodePredicateParameterDocumentation = "parameter-documentation"

	// Decorates a parameter with its type.
	NodePredicateParameterType = "parameter-type"

	// Decorates a member tag with its name.
	NodePredicateMemberTagName = "membertag-name"

	// Decorates a member tag with its value.
	NodePredicateMemberTagValue = "membertag-value"

	// Decorates an attribute with its name.
	NodePredicateAttributeName = "attribute-name"

	// Marks a returnable with its expected return type.
	NodePredicateReturnType = "return-type"
)
View Source
const ASSIGNABLE_OP_VALUE = "value"

Variables

Note: The list below does not contain NodeTypeAlias, which is a special handled case in LookupType.

Functions

This section is empty.

Types

type Annotator

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

Annotator defines a helper type for annotating various constraints in the type graph such as generic constraints, inheritance, etc.

func (Annotator) DefineAgencyComposition

func (an Annotator) DefineAgencyComposition(typeSourceNode compilergraph.GraphNode, agentType TypeReference, compositionName string)

DefineAgencyComposition defines that the type being constructed composes an agent of the given type, with the given name. Agency composition is a type-safe form of composition with automatic back reference to the composing type within the agent.

func (Annotator) DefineAliasedType

func (an Annotator) DefineAliasedType(typeSourceNode compilergraph.GraphNode, aliased TGTypeDecl)

DefineAliasedType defines that the given type aliases the other type. Only applies to aliases.

func (Annotator) DefineGenericConstraint

func (an Annotator) DefineGenericConstraint(genericSourceNode compilergraph.GraphNode, constraint TypeReference)

DefineGenericConstraint defines the constraint on a type or type member generic to be that specified.

func (Annotator) DefineParentType

func (an Annotator) DefineParentType(typeSourceNode compilergraph.GraphNode, inherits TypeReference)

DefineParentType defines that the given type inherits from the given parent type ref. For external interfaces, the parent is inherited and for nominal types, it describes conversion. Inheritance should only be used by legacy code and never for SRG-based types: Agency composition should be used instead.

func (Annotator) DefinePrincipalType

func (an Annotator) DefinePrincipalType(typeSourceNode compilergraph.GraphNode, principal TypeReference)

DefinePrincipalType defines the principal type that this agent accepts.

func (Annotator) ReportError

func (ir Annotator) ReportError(sourceNode compilergraph.GraphNode, message string, params ...interface{})

ReportError adds an error to the type graph, starting from the given source node.

type BuildOption added in v0.2.0

type BuildOption int

BuildOption is an option for building of the type graph.

const (
	// FullBuild indicates that basic types should be fully validated and that the type graph
	// should be frozen once complete.
	FullBuild BuildOption = iota

	// BuildForTesting will skip basic type validation and freezing. Should only be used for testing.
	BuildForTesting
)

type Entity added in v0.2.0

type Entity struct {
	// Kind is it the kind of the entity.
	Kind EntityKind

	// NameOrPath represents the name or path of the entity. If a module,
	// this is the module's path. If a type, this is the type's name.
	// If a member, this is the member's *child name*.
	NameOrPath string

	// SourceGraphId is the ID of the source graph for the type node. If none,
	// this will be `typegraph`.
	SourceGraphId string
}

Entity represents an entity: module, type, or member.

type EntityKind added in v0.2.0

type EntityKind string

EntityKind defines the various kinds of entities in which types or members can be found

const (
	// EntityKindModule indicates the entity is a module.
	EntityKindModule EntityKind = "module"

	// EntityKindType indicates the entity is a type.
	EntityKindType EntityKind = "type"

	// EntityKindMember indicates the entity is a member.
	EntityKindMember EntityKind = "member"
)

type EntityResolveOption added in v0.2.0

type EntityResolveOption int

EntityResolveOption defines the various options for ResolveEntityByPath.

const (
	// EntityResolveModulesExactly indicates that module entities will be resolved
	// as an exact match.
	EntityResolveModulesExactly EntityResolveOption = iota

	// EntityResolveModulesAsPackages indicates that module entities will be resolved
	// as *packages*, searching all modules with the matching package path.
	EntityResolveModulesAsPackages
)

type GetMemberBuilder

type GetMemberBuilder func(moduleOrTypeSourceNode compilergraph.GraphNode, isOperator bool) *MemberBuilder

type GetMemberDecorator

type GetMemberDecorator func(memberSourceNode compilergraph.GraphNode) *MemberDecorator

type GetModuleBuilder

type GetModuleBuilder func() *moduleBuilder

type GetTypeBuilder

type GetTypeBuilder func(moduleSourceNode compilergraph.GraphNode) *typeBuilder

type IssueReporter

type IssueReporter interface {
	ReportError(sourceNode compilergraph.GraphNode, message string, params ...interface{})
}

IssueReporter defines a helper type for reporting issues on source nodes translated into the type graph.

type MemberBuilder

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

MemberBuilder defines a helper type for easy construction of module and type members.

func (*MemberBuilder) Define

func (mb *MemberBuilder) Define() TGMember

Define defines the member under the type or module in the type graph.

func (*MemberBuilder) Documentation

func (mb *MemberBuilder) Documentation(documentation string) *MemberBuilder

Documentation sets the documentation of the member.

func (*MemberBuilder) Name

func (mb *MemberBuilder) Name(name string) *MemberBuilder

Name sets the name of the member.

func (*MemberBuilder) SourceNode

func (mb *MemberBuilder) SourceNode(sourceNode compilergraph.GraphNode) *MemberBuilder

SourceNode sets the source node for the member in the source graph.

func (*MemberBuilder) WithGeneric

func (mb *MemberBuilder) WithGeneric(name string, documentation string, sourceNode compilergraph.GraphNode) *MemberBuilder

WithGeneric adds a generic to this member.

func (*MemberBuilder) WithParameter

func (mb *MemberBuilder) WithParameter(name string, documentation string, sourceNode compilergraph.GraphNode) *MemberBuilder

WithParameter adds a parameter to this member.

type MemberDecorator

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

MemberDecorator defines a helper type for easy annotation of module and type members's dependent information.

func (*MemberDecorator) CreateReturnable

func (mb *MemberDecorator) CreateReturnable(sourceNode compilergraph.GraphNode, returnType TypeReference) *MemberDecorator

CreateReturnable adds a returnable definition to the type graph, indicating that the given source node returns a value of the given type.

func (*MemberDecorator) Decorate

func (mb *MemberDecorator) Decorate()

Decorate completes the decoration of the member.

func (*MemberDecorator) DefineGenericConstraint

func (mb *MemberDecorator) DefineGenericConstraint(genericSourceNode compilergraph.GraphNode, constraint TypeReference)

DefineGenericConstraint defines the constraint on the type member generic to be that specified.

func (*MemberDecorator) DefineParameterType

func (mb *MemberDecorator) DefineParameterType(parameterSourceNode compilergraph.GraphNode, parameterType TypeReference)

DefineParameterType defines the type of the parameter specified.

func (*MemberDecorator) Exported

func (mb *MemberDecorator) Exported(exported bool) *MemberDecorator

Exported sets whether the member is exported publicly.

func (*MemberDecorator) Field

func (mb *MemberDecorator) Field(field bool) *MemberDecorator

Field sets whether the member is a field.

func (*MemberDecorator) HasDefaultValue

func (mb *MemberDecorator) HasDefaultValue(hasdefault bool) *MemberDecorator

HasDefaultValue sets whether the member has a default value.

func (*MemberDecorator) ImplicitlyCalled

func (mb *MemberDecorator) ImplicitlyCalled(implicit bool) *MemberDecorator

ImplicitlyCalled sets whether the member is implicitly called on access or assignment.

func (*MemberDecorator) InvokesAsync

func (mb *MemberDecorator) InvokesAsync(invokesasync bool) *MemberDecorator

InvokesAsync sets whether the member invokes asynchronously.

func (*MemberDecorator) MemberKind

func (mb *MemberDecorator) MemberKind(memberKind MemberSignatureKind) *MemberDecorator

MemberKind sets the kind of the member. Used for signature calculation.

func (*MemberDecorator) MemberType

func (mb *MemberDecorator) MemberType(memberType TypeReference) *MemberDecorator

MemberType sets the type of the member, as well as the signature type. Call SignatureType to override.

func (*MemberDecorator) Native

func (mb *MemberDecorator) Native(native bool) *MemberDecorator

Native sets whether the member is native.

func (*MemberDecorator) Promising

func (mb *MemberDecorator) Promising(promising MemberPromisingOption) *MemberDecorator

Promising sets whether the member is promising.

func (*MemberDecorator) ReadOnly

func (mb *MemberDecorator) ReadOnly(readonly bool) *MemberDecorator

ReadOnly sets whether the member is read only.

func (*MemberDecorator) SignatureType

func (mb *MemberDecorator) SignatureType(signatureType TypeReference) *MemberDecorator

SignatureType sets the type of the member for interface signature calculation.

func (*MemberDecorator) SkipOperatorChecking

func (mb *MemberDecorator) SkipOperatorChecking(skip bool) *MemberDecorator

SkipOperatorChecking sets whether to skip operator checking for native operators.

func (*MemberDecorator) Static

func (mb *MemberDecorator) Static(static bool) *MemberDecorator

Static sets whether the member is static.

func (*MemberDecorator) WithTag

func (mb *MemberDecorator) WithTag(name string, value string) *MemberDecorator

WithTag adds a tag onto the member.

type MemberPromisingOption

type MemberPromisingOption int

MemberPromisingOption defines the various states of promising for a member.

const (
	// MemberNotPromising indicates the member does not return a promise.
	MemberNotPromising MemberPromisingOption = iota

	// MemberPromisingDynamic indicates that the member *may* return a promise, based
	// on its implementation. This will typically only apply to members generated from
	// source.
	MemberPromisingDynamic

	// MemberPromising indicates that the member always returns a promise.
	MemberPromising
)

type MemberResolutionKind

type MemberResolutionKind int
const (
	MemberResolutionOperator MemberResolutionKind = iota
	MemberResolutionStatic
	MemberResolutionInstance
	MemberResolutionInstanceOrStatic
)

func (MemberResolutionKind) Title

func (mrk MemberResolutionKind) Title() string

Title returns a human-readable title for the kind of resolution occurring.

type MemberSignatureKind

type MemberSignatureKind int

MemberSignatureKind defines the various kinds of members, for calculating signatures for interface comparisons.

const (
	CustomMemberSignature MemberSignatureKind = iota

	ConstructorMemberSignature
	FunctionMemberSignature
	PropertyMemberSignature
	OperatorMemberSignature
	FieldMemberSignature

	NativeConstructorMemberSignature
	NativeFunctionMemberSignature
	NativeOperatorMemberSignature
	NativePropertyMemberSignature
)

type NodeType

type NodeType int

NodeType identifies the type of type graph node.

const (
	// Top-level
	NodeTypeError             NodeType = iota // error occurred; value is text of error
	NodeTypeClass                             // A class
	NodeTypeInterface                         // An implicitly-defined interface
	NodeTypeExternalInterface                 // An externally defined interface
	NodeTypeNominalType                       // A nominal type
	NodeTypeStruct                            // A structural type
	NodeTypeAgent                             // An agent type
	NodeTypeModule                            // A module
	NodeTypeAlias                             // An alias pointing to a type

	// Member-level
	NodeTypeMember   // A member of a type or module.
	NodeTypeOperator // An operator defined on a type.

	// Member parameters.
	NodeTypeParameter // A parameter under a member.

	// Member tags.
	NodeTypeMemberTag

	// Body-level
	NodeTypeReturnable // A returnable member or property getter.

	// Generics.
	NodeTypeGeneric // A defined generic on a type or type member.

	// Agents.
	NodeTypeAgentReference // A reference to an agent composed into a class/agent.

	// Custom attribute.
	NodeTypeAttribute

	// An issue reported by a source graph.
	NodeTypeReportedIssue

	// 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 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    *TypeGraph                     // The constructed type graph.
}

Result represents the results of building a type graph.

func BuildTypeGraph

func BuildTypeGraph(graph compilergraph.SerulianGraph, constructors ...TypeGraphConstructor) (*Result, error)

BuildTypeGraph returns a new TypeGraph that is populated from the given constructors.

func BuildTypeGraphWithOption added in v0.0.2

func BuildTypeGraphWithOption(graph compilergraph.SerulianGraph, buildOption BuildOption, cancelationHandle compilerutil.CancelationHandle, constructors ...TypeGraphConstructor) (*Result, error)

BuildTypeGraphWithOption returns a new TypeGraph that is populated from the given constructors.

type SubTypingException

type SubTypingException int

SubTypingException defines the various exceptions allowed on CheckSubTypeOf

const (
	// NoSubTypingExceptions indicates that all the normal subtyping rules apply.
	NoSubTypingExceptions SubTypingException = iota

	// AllowNominalWrappedForData indicates that a nominally deriving type can be used
	// in place of its data type.
	AllowNominalWrappedForData
)

type TGAgentReference

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

TGAgentReference represents a reference to an agent composed into another type.

func (TGAgentReference) AgentType

func (tn TGAgentReference) AgentType() TypeReference

AgentType returns the type of agent being composed.

func (TGAgentReference) CompositionName

func (tn TGAgentReference) CompositionName() string

CompositionName returns the name of the agent when composed into the parent type.

type TGEntity added in v0.2.0

type TGEntity interface {
	Name() string
	Node() compilergraph.GraphNode
	IsType() bool
	AsType() (TGTypeDecl, bool)
	EntityPath() []Entity
}

TGEntity represents any form of entity: module, member or type.

type TGGeneric

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

TGGeneric represents a generic in the type graph.

func (TGGeneric) AsType

func (tn TGGeneric) AsType() TGTypeDecl

AsType returns the generic as a TGTypeDecl.

func (TGGeneric) Constraint

func (tn TGGeneric) Constraint() TypeReference

Constraint returns the type constraint on this generic.

func (TGGeneric) DescriptiveName

func (tn TGGeneric) DescriptiveName() string

DescriptiveName returns a nice human-readable name for the generic.

func (TGGeneric) GetTypeReference added in v0.2.0

func (tn TGGeneric) GetTypeReference() TypeReference

GetTypeReference returns a new type reference to this generic.

func (TGGeneric) Name

func (tn TGGeneric) Name() string

Name returns the name of the underlying generic.

func (TGGeneric) Node

func (tn TGGeneric) Node() compilergraph.GraphNode

Node returns the underlying node in this declaration.

func (TGGeneric) Title

func (tn TGGeneric) Title() string

Title returns a nice title for the generic.

type TGMember

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

TGMember represents a type or module member.

func (TGMember) AsType added in v0.2.0

func (tn TGMember) AsType() (TGTypeDecl, bool)

AsType returns whether this is a type (always false).

func (TGMember) AssignableType

func (tn TGMember) AssignableType() TypeReference

AssignableType returns the type of values that can be assigned to this member. Returns void for readonly members.

func (TGMember) BaseMember

func (tn TGMember) BaseMember() (TGMember, bool)

BaseMember returns the member in a parent type from which this member was cloned/inherited, if any.

func (TGMember) BaseMemberSource

func (tn TGMember) BaseMemberSource() (TypeReference, bool)

BaseMemberSource returns the type from which this member was cloned/inherited, if any.

func (TGMember) ChildName

func (tn TGMember) ChildName() string

ChildName returns the unique name of the underlying member. For operators, this will return the name prepended with the operator character.

func (TGMember) Code

func (tn TGMember) Code() (compilercommon.CodeSummary, bool)

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

func (TGMember) ConstructorType

func (tn TGMember) ConstructorType() (TypeReference, bool)

ConstructorType returns the type constructed by invoking this member, if it is a constructor.

func (TGMember) DeclaredType added in v0.2.0

func (tn TGMember) DeclaredType() TypeReference

DeclaredType returns the declared type for this member. If a function, returns the return type. Otherwise, returns the member type.

func (TGMember) Documentation

func (tn TGMember) Documentation() (string, bool)

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

func (TGMember) EntityPath added in v0.2.0

func (tn TGMember) EntityPath() []Entity

EntityPath returns the path of entities that chain to this member.

func (TGMember) Generics

func (tn TGMember) Generics() []TGGeneric

Generics returns the generics on this member.

func (TGMember) GetTag

func (tn TGMember) GetTag(tag TypeMemberTag) (string, bool)

GetTag returns the value of the given tag, if any.

func (TGMember) GetTagOrDefault

func (tn TGMember) GetTagOrDefault(tag TypeMemberTag, defaultValue string) string

GetTagOrDefault returns the value of the given tag or the default value if no such tag is defined.

func (TGMember) HasBaseMember

func (tn TGMember) HasBaseMember() bool

HasBaseMember returns true if this member was cloned/inherited.

func (TGMember) HasDefaultValue

func (tn TGMember) HasDefaultValue() bool

HasDefaultValue returns whether the member is automatically initialized with a default value.

func (TGMember) HasGenerics

func (tn TGMember) HasGenerics() bool

HasGenerics returns whether this member has generics defined.

func (TGMember) InvokesAsync

func (tn TGMember) InvokesAsync() bool

InvokesAsync returns whether the member invokes asynchronously.

func (TGMember) IsAccessibleTo

func (tn TGMember) IsAccessibleTo(modulePath compilercommon.InputSource) bool

IsAccessibleTo returns whether this member is accessible to the module with the given source path.

func (TGMember) IsExported

func (tn TGMember) IsExported() bool

IsExported returns whether the member is exported.

func (TGMember) IsField

func (tn TGMember) IsField() bool

IsField returns whether the member is a field.

func (TGMember) IsImplicitlyCalled

func (tn TGMember) IsImplicitlyCalled() bool

IsImplicitlyCalled returns whether the member is implicitly called on access or assignment.

func (TGMember) IsNative

func (tn TGMember) IsNative() bool

IsNative returns whether the member is a native operator.

func (TGMember) IsOperator

func (tn TGMember) IsOperator() bool

IsOperator returns whether this is an operator.

func (TGMember) IsPromising

func (tn TGMember) IsPromising() MemberPromisingOption

IsPromising returns whether the member is promising.

func (TGMember) IsReadOnly

func (tn TGMember) IsReadOnly() bool

IsReadOnly returns whether the member is read-only.

func (TGMember) IsRequired added in v0.2.0

func (tn TGMember) IsRequired() bool

IsRequired returns whether this member is "required" under the parent type, either by being a required field or by being the member of an interface that is implemented.

func (TGMember) IsRequiredField

func (tn TGMember) IsRequiredField() bool

IsRequiredField returns whether this member is a field requiring initialization on construction of an instance of the parent type.

func (TGMember) IsStatic

func (tn TGMember) IsStatic() bool

IsStatic returns whether the member is static.

func (TGMember) IsType

func (tn TGMember) IsType() bool

IsType returns whether this is a type (always false).

func (TGMember) LookupGeneric added in v0.2.0

func (tn TGMember) LookupGeneric(name string) (TGGeneric, bool)

LookupGeneric looks up the generic under this member with the given name and returns it, if any.

func (TGMember) MemberType

func (tn TGMember) MemberType() TypeReference

MemberType returns the type for this member.

func (TGMember) Name

func (tn TGMember) Name() string

Name returns the name of the underlying member.

func (TGMember) Node

func (tn TGMember) Node() compilergraph.GraphNode

Node returns the underlying node in this declaration.

func (TGMember) ParameterTypes

func (tn TGMember) ParameterTypes() []TypeReference

ParameterTypes returns the types of the parameters defined on this member, if any.

func (TGMember) Parameters

func (tn TGMember) Parameters() []TGParameter

Parameters returns the parameters on this member.

func (TGMember) Parent

func (tn TGMember) Parent() TGTypeOrModule

Parent returns the type or module containing this member.

func (TGMember) ParentType

func (tn TGMember) ParentType() (TGTypeDecl, bool)

ParentType returns the type containing this member, if any.

func (TGMember) ReturnType

func (tn TGMember) ReturnType() (TypeReference, bool)

ReturnType returns the return type for this member.

func (TGMember) SerializableName

func (tn TGMember) SerializableName() string

SerializableName returns the defined serializable name for this field.

func (TGMember) ShadowsMembers

func (tn TGMember) ShadowsMembers() []TGMember

ShadowsMembers returns the type members from any composed types that this member shadows.

func (TGMember) Signature

func (tn TGMember) Signature() *proto.MemberSig

Signature returns the signature of this member.

func (TGMember) SourceGraphId

func (tn TGMember) SourceGraphId() string

SourceGraphId returns the ID of the source graph from which this member originated. If none, returns "typegraph".

func (TGMember) SourceNodeId

func (tn TGMember) SourceNodeId() (compilergraph.GraphNodeId, bool)

SourceNodeId returns the ID of the source node for this member, if any.

func (TGMember) SourceRange

func (tn TGMember) SourceRange() (compilercommon.SourceRange, bool)

SourceRange returns the source range for the source node for this member, if any.

func (TGMember) SourceRanges

func (tn TGMember) SourceRanges() []compilercommon.SourceRange

SourceRanges returns all the source ranges for the source node for this member, if any.

func (TGMember) Title

func (tn TGMember) Title() string

Title returns a nice title for the member.

func (TGMember) TypeGraph added in v0.2.0

func (tn TGMember) TypeGraph() *TypeGraph

TypeGraph returns the type graph that contains this member.

type TGModule

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

TGModule represents a module in the type graph.

func (TGModule) AsType

func (tn TGModule) AsType() (TGTypeDecl, bool)

AsType panics (since module is not a type).

func (TGModule) EntityPath added in v0.2.0

func (tn TGModule) EntityPath() []Entity

EntityPath returns the path of entities that chain to this module.

func (TGModule) GetMember added in v0.2.0

func (tn TGModule) GetMember(name string) (TGMember, bool)

GetMember finds the member under this module with the given name, if any.

func (TGModule) GetMemberOrOperator added in v0.2.0

func (tn TGModule) GetMemberOrOperator(name string) (TGMember, bool)

GetMemberOrOperator finds the member under this module with the given *child* name, if any.

func (TGModule) IsType

func (tn TGModule) IsType() bool

IsType returns whether this module is a type (always false).

func (TGModule) Members

func (tn TGModule) Members() []TGMember

Members returns the members defined in this module.

func (TGModule) MembersAndOperators added in v0.2.0

func (tn TGModule) MembersAndOperators() []TGMember

MembersAndOperators returns the members defined in this module.

func (TGModule) Name

func (tn TGModule) Name() string

Name returns the name of the underlying module.

func (TGModule) Node

func (tn TGModule) Node() compilergraph.GraphNode

Node returns the underlying node in this declaration.

func (TGModule) PackagePath added in v0.2.0

func (tn TGModule) PackagePath() string

PackagePath returns the path of the module's parent package.

func (TGModule) ParentModule

func (tn TGModule) ParentModule() TGModule

ParentModule returns the parent module (which, is this module).

func (TGModule) Path

Path returns the path of the underlying module.

func (TGModule) SourceGraphId

func (tn TGModule) SourceGraphId() string

SourceGraphId returns the ID of the source graph from which this module originated. If none, returns "typegraph".

func (TGModule) Title

func (tn TGModule) Title() string

Title returns the human readable name of this type ("Module")

func (TGModule) Types

func (tn TGModule) Types() []TGTypeDecl

Types returns the types defined in this module.

type TGParameter

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

TGParameter represents a parameter under a type member.

func (TGParameter) DeclaredType

func (tn TGParameter) DeclaredType() TypeReference

DeclaredType returns the type for this parameter.

func (TGParameter) Documentation

func (tn TGParameter) Documentation() (string, bool)

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

func (TGParameter) Name

func (tn TGParameter) Name() (string, bool)

Name returns the name of the underlying parameter.

type TGTypeDecl

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

TGTypeDeclaration represents a type declaration (class, interface or generic) in the type graph.

func (TGTypeDecl) AliasedType

func (tn TGTypeDecl) AliasedType() (TGTypeDecl, bool)

AliasedType returns the type aliased by this type alias.

func (TGTypeDecl) AsGeneric

func (tn TGTypeDecl) AsGeneric() (TGGeneric, bool)

AsGeneric returns this type as a generic.

func (TGTypeDecl) AsType

func (tn TGTypeDecl) AsType() (TGTypeDecl, bool)

AsType returns this type.

func (TGTypeDecl) Attributes added in v0.2.0

func (tn TGTypeDecl) Attributes() []TypeAttribute

Attributes returns the attributes of this type.

func (TGTypeDecl) Code

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

func (TGTypeDecl) ComposedAgents

func (tn TGTypeDecl) ComposedAgents() []TGAgentReference

ComposedAgents returns the types which this type composes (if any).

func (TGTypeDecl) ComposesAgent

func (tn TGTypeDecl) ComposesAgent(agentTypeRef TypeReference) bool

ComposesAgent returns true if the given agent type is composed by this type.

func (TGTypeDecl) ContainingMember added in v0.2.0

func (tn TGTypeDecl) ContainingMember() (TGMember, bool)

ContainingMember returns the *directly* containing member. Will only return a type for generics.

func (TGTypeDecl) ContainingType

func (tn TGTypeDecl) ContainingType() (TGTypeDecl, bool)

ContainingType returns the *directly* containing type. Will only return a type for generics.

func (TGTypeDecl) DescriptiveName

func (tn TGTypeDecl) DescriptiveName() string

DescriptiveName returns a nice human-readable name for the type.

func (TGTypeDecl) Documentation

func (tn TGTypeDecl) Documentation() (string, bool)

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

func (TGTypeDecl) EntityPath added in v0.2.0

func (tn TGTypeDecl) EntityPath() []Entity

EntityPath returns the path of entities that chain to this type.

func (TGTypeDecl) Fields

func (tn TGTypeDecl) Fields() []TGMember

Fields returns the fields under this type.

func (TGTypeDecl) FullName added in v0.2.0

func (tn TGTypeDecl) FullName() string

FullName returns the full name of this type, including its parent module's path.

func (TGTypeDecl) Generics

func (tn TGTypeDecl) Generics() []TGGeneric

Generics returns the generics on this type.

func (TGTypeDecl) GetMember

func (tn TGTypeDecl) GetMember(name string) (TGMember, bool)

GetMember returns the member (but not operator) with the given name under this type, if any.

func (TGTypeDecl) GetMemberOrOperator added in v0.2.0

func (tn TGTypeDecl) GetMemberOrOperator(name string) (TGMember, bool)

GetMemberOrOperator returns the member or operator with the given *child name* under this type, if any.

func (TGTypeDecl) GetOperator

func (tn TGTypeDecl) GetOperator(name string) (TGMember, bool)

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

func (TGTypeDecl) GetStaticMember

func (tn TGTypeDecl) GetStaticMember(name string) (TGMember, bool)

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

func (TGTypeDecl) GetTypeReference

func (tn TGTypeDecl) GetTypeReference() TypeReference

GetTypeReference returns a new type reference to this type.

func (TGTypeDecl) GlobalAlias

func (tn TGTypeDecl) GlobalAlias() (string, bool)

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

func (TGTypeDecl) GlobalUniqueId

func (tn TGTypeDecl) GlobalUniqueId() string

GlobalUniqueId returns a globally unique ID for this type, consistent across multiple compilations.

func (TGTypeDecl) HasAttribute

func (tn TGTypeDecl) HasAttribute(attribute TypeAttribute) bool

HasAttribute returns whether this type has the given attribute.

func (TGTypeDecl) HasGenerics

func (tn TGTypeDecl) HasGenerics() bool

HasGenerics returns whether this type has generics defined.

func (TGTypeDecl) IsAccessibleTo

func (tn TGTypeDecl) IsAccessibleTo(modulePath compilercommon.InputSource) bool

IsAccessibleTo returns whether this type is accessible to the module with the given source path.

func (TGTypeDecl) IsClass

func (tn TGTypeDecl) IsClass() bool

IsClass returns true if this type is a class.

func (TGTypeDecl) IsExported

func (tn TGTypeDecl) IsExported() bool

IsExported returns whether the type is exported.

func (TGTypeDecl) IsField

func (tn TGTypeDecl) IsField() bool

IsField returns whether this type is a field (always false).

func (TGTypeDecl) IsImplicitlyCalled

func (tn TGTypeDecl) IsImplicitlyCalled() bool

IsImplicitlyCalled returns whether this type is implicitly called (always false).

func (TGTypeDecl) IsPromising

func (tn TGTypeDecl) IsPromising() MemberPromisingOption

IsPromising returns whether this type is promising (always MemberNotPromising).

func (TGTypeDecl) IsReadOnly

func (tn TGTypeDecl) IsReadOnly() bool

IsReadOnly returns whether the type is read-only (which is always true)

func (TGTypeDecl) IsStatic

func (tn TGTypeDecl) IsStatic() bool

IsStatic returns whether this type is static (always true).

func (TGTypeDecl) IsType

func (tn TGTypeDecl) IsType() bool

IsType returns whether this is a type (always true).

func (TGTypeDecl) LookupGeneric

func (tn TGTypeDecl) LookupGeneric(name string) (TGGeneric, bool)

LookupGeneric looks up the generic under this type with the given name and returns it, if any.

func (TGTypeDecl) Members

func (tn TGTypeDecl) Members() []TGMember

Members returns the type graph members (but not operartors) for this type node.

func (TGTypeDecl) MembersAndOperators added in v0.2.0

func (tn TGTypeDecl) MembersAndOperators() []TGMember

MembersAndOperators returns the type graph members and operators for this type node.

func (TGTypeDecl) Name

func (tn TGTypeDecl) Name() string

Name returns the name of the underlying type.

func (TGTypeDecl) Node

Node returns the underlying node in this declaration.

func (TGTypeDecl) NonFieldMembers

func (tn TGTypeDecl) NonFieldMembers() []TGMember

NonFieldMembers returns the type graph members for this type node that are not fields.

func (TGTypeDecl) OverallContainerType added in v0.2.0

func (tn TGTypeDecl) OverallContainerType() (TGTypeDecl, bool)

OverallContainerType returns the type containing this type, even if this type is defined on a member. Will only return a type for generics.

func (TGTypeDecl) PackagedName added in v0.2.0

func (tn TGTypeDecl) PackagedName() string

PackagedName returns the packaged name of this type, including its parent package's path.

func (TGTypeDecl) Parent

func (tn TGTypeDecl) Parent() TGTypeOrModule

Parent returns the module containing this type.

func (TGTypeDecl) ParentModule

func (tn TGTypeDecl) ParentModule() TGModule

ParentModule returns the module containing this type.

func (TGTypeDecl) ParentTypes

func (tn TGTypeDecl) ParentTypes() []TypeReference

ParentTypes returns the types from which this type derives (if any).

func (TGTypeDecl) PrincipalType

func (tn TGTypeDecl) PrincipalType() (TypeReference, bool)

PrincipalType returns the type of the principal for this agent.

func (TGTypeDecl) RequiredFields

func (tn TGTypeDecl) RequiredFields() []TGMember

RequiredFields returns the fields under this type that must be specified when constructing an instance of the type, as they are non-nullable and do not have a specified default value.

func (TGTypeDecl) SourceGraphId

func (tn TGTypeDecl) SourceGraphId() string

SourceGraphId returns the ID of the source graph from which this type originated. If none, returns "typegraph".

func (TGTypeDecl) SourceNodeId

func (tn TGTypeDecl) SourceNodeId() (compilergraph.GraphNodeId, bool)

SourceNodeId returns the ID of the source node for this tyoe, if any.

func (TGTypeDecl) SourceRange

func (tn TGTypeDecl) SourceRange() (compilercommon.SourceRange, bool)

SourceRange returns the source range for the source node for this type, if any.

func (TGTypeDecl) SourceRanges

func (tn TGTypeDecl) SourceRanges() []compilercommon.SourceRange

SourceRanges returns all the source ranges for the source node for this type, if any.

func (TGTypeDecl) Title

func (tn TGTypeDecl) Title() string

Title returns a nice title for the type.

func (TGTypeDecl) TypeKind

func (tn TGTypeDecl) TypeKind() TypeKind

TypeKind returns the kind of the type node.

type TGTypeOrMember

type TGTypeOrMember interface {
	Name() string
	Title() string
	Node() compilergraph.GraphNode
	Generics() []TGGeneric
	HasGenerics() bool
	LookupGeneric(name string) (TGGeneric, bool)
	IsReadOnly() bool
	IsType() bool
	IsStatic() bool
	IsExported() bool
	IsPromising() MemberPromisingOption
	Parent() TGTypeOrModule
	IsImplicitlyCalled() bool
	IsField() bool
	SourceNodeId() (compilergraph.GraphNodeId, bool)
	SourceGraphId() string
	SourceRange() (compilercommon.SourceRange, bool)
	SourceRanges() []compilercommon.SourceRange
	IsAccessibleTo(modulePath compilercommon.InputSource) bool
	AsType() (TGTypeDecl, bool)
	Code() (compilercommon.CodeSummary, bool)
	EntityPath() []Entity
}

TGTypeOrMember represents an interface shared by types and members.

type TGTypeOrModule

type TGTypeOrModule interface {
	Name() string
	Node() compilergraph.GraphNode
	Members() []TGMember
	MembersAndOperators() []TGMember
	Title() string
	IsType() bool
	ParentModule() TGModule
	GetMember(name string) (TGMember, bool)
	GetMemberOrOperator(name string) (TGMember, bool)
	AsType() (TGTypeDecl, bool)
	SourceGraphId() string
	EntityPath() []Entity
}

TGTypeOrModule represents an interface shared by types and modules.

type TestGeneric added in v0.2.0

type TestGeneric struct {
	Name       string
	Constraint string
}

TestGeneric defines a new generic to be created on a TestType or TestMember.

type TestMember added in v0.2.0

type TestMember struct {
	Kind       MemberSignatureKind
	Name       string
	ReturnType string
	Generics   []TestGeneric
	Parameters []TestParam
}

TestMember defines a new member to be created on a TestType or under a test module.

type TestModule added in v0.2.0

type TestModule struct {
	ModuleName string
	Types      []TestType
	Members    []TestMember
}

TestModule defines a new mdoule to be created in the test type graph.

func (TestModule) ResolveTypeString added in v0.2.0

func (module TestModule) ResolveTypeString(humanString string, graph *TypeGraph) TypeReference

ResolveTypeString resolves the given type string via the given constructed module.

type TestParam added in v0.2.0

type TestParam struct {
	Name      string
	ParamType string
}

TestParam defines a new parameter to be created on a TestMember.

type TestType added in v0.2.0

type TestType struct {
	Kind       string
	Name       string
	ParentType string
	Generics   []TestGeneric
	Members    []TestMember
}

TestType defines a new type to be created in the test type graph.

type TypeAttribute

type TypeAttribute string

TypeAttribute defines the set of custom attributes allowed on type declarations.

const (
	// SERIALIZABLE_ATTRIBUTE marks a type as being serializable in the native
	// runtime.
	SERIALIZABLE_ATTRIBUTE TypeAttribute = "serializable"
)

type TypeGraph

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

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

func ConstructTypeGraphWithBasicTypes added in v0.2.0

func ConstructTypeGraphWithBasicTypes(modules ...TestModule) *TypeGraph

ConstructTypeGraphWithBasicTypes constructs a type graph populated with the given testing modules and all the "basic" types necessary for implicit operators. Will panic if construction fails.

func (*TypeGraph) AnyTypeReference

func (t *TypeGraph) AnyTypeReference() TypeReference

AnyTypeReference returns a reference to the special 'any' type.

func (*TypeGraph) AsyncMembers

func (g *TypeGraph) AsyncMembers() []TGMember

AsyncMembers returns all defined async members.

func (*TypeGraph) AwaitableType

func (t *TypeGraph) AwaitableType() TGTypeDecl

AwaitableType returns the awaitable type.

func (*TypeGraph) AwaitableTypeReference

func (t *TypeGraph) AwaitableTypeReference(generic TypeReference) TypeReference

AwaitableTypeReference returns a new reference to the awaitable type, with the given generic.

func (*TypeGraph) BoolType

func (t *TypeGraph) BoolType() TGTypeDecl

BoolType returns the boolean type.

func (*TypeGraph) BoolTypeReference

func (t *TypeGraph) BoolTypeReference() TypeReference

BoolTypeReference returns a reference to the bool type.

func (*TypeGraph) DeserializieTypeRef

func (t *TypeGraph) DeserializieTypeRef(value string) TypeReference

Deserializes a type reference string value into a TypeReference.

func (*TypeGraph) ErrorType

func (t *TypeGraph) ErrorType() TGTypeDecl

ErrorType returns the error type.

func (*TypeGraph) ErrorTypeReference

func (t *TypeGraph) ErrorTypeReference() TypeReference

ErrorTypeReference returns a reference to the error type.

func (*TypeGraph) FloatType

func (t *TypeGraph) FloatType() TGTypeDecl

FloatType returns the float type.

func (*TypeGraph) ForEachModule

func (g *TypeGraph) ForEachModule(handler moduleHandler)

ForEachModule executes the given function for each defined module in the graph. Note that the functions will be executed in *parallel*, so care must be taken to ensure there aren't any inconsistent accesses or writes.

func (*TypeGraph) ForEachTypeDecl

func (g *TypeGraph) ForEachTypeDecl(typeKinds []NodeType, handler typeDeclHandler)

ForEachTypeDecl executes the given function for each defined type matching the type kinds. Note that the functions will be executed in *parallel*, so care must be taken to ensure there aren't any inconsistent accesses or writes.

func (*TypeGraph) FunctionType

func (t *TypeGraph) FunctionType() TGTypeDecl

FunctionType returns the function type.

func (*TypeGraph) FunctionTypeReference

func (t *TypeGraph) FunctionTypeReference(generic TypeReference) TypeReference

FunctionTypeReference returns a new reference to the function type, with the given generic.

func (*TypeGraph) GetFilteredJSONForm

func (tg *TypeGraph) GetFilteredJSONForm(pathFilters []string, skipNodeKinds []compilergraph.TaggedValue) string

GetFilteredJSONForm returns the filtered type graph serialized to JSON. *For testing purposes only*.

func (*TypeGraph) GetJSONForm

func (tg *TypeGraph) GetJSONForm() string

GetJSONForm returns this type graph serialized to JSON. *For testing purposes only*.

func (*TypeGraph) GetMemberForSourceNode

func (g *TypeGraph) GetMemberForSourceNode(node compilergraph.GraphNode) (TGMember, bool)

GetMemberForSRGNode returns the TypeGraph member for the given source member node, if any.

func (*TypeGraph) GetNode

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

func (*TypeGraph) GetOperatorDefinition

func (g *TypeGraph) GetOperatorDefinition(operatorName string) (operatorDefinition, bool)

GetOperatorDefinition returns the operator definition for the operator with the given name (if any)

func (*TypeGraph) GetTypeDecls

func (g *TypeGraph) GetTypeDecls(typeKinds ...NodeType) []TGTypeDecl

GetTypeDecls returns all types defined in the type graph of the given types.

func (*TypeGraph) GetTypeForSourceNode

func (g *TypeGraph) GetTypeForSourceNode(node compilergraph.GraphNode) (TGTypeDecl, bool)

GetTypeForSourceNode returns the TypeGraph type decl for the given source type node, if any.

func (*TypeGraph) GetTypeOrMember

func (g *TypeGraph) GetTypeOrMember(nodeId compilergraph.GraphNodeId) TGTypeOrMember

GetTypeOrMember returns the type or member matching the given node ID.

func (*TypeGraph) GetTypeOrMemberForNode

func (g *TypeGraph) GetTypeOrMemberForNode(node compilergraph.GraphNode) (TGTypeOrMember, bool)

GetTypeOrMemberForNode returns a type or member wrapper around the given node, if applicable.

func (*TypeGraph) GetTypeOrMemberForSourceNode

func (g *TypeGraph) GetTypeOrMemberForSourceNode(node compilergraph.GraphNode) (TGTypeOrMember, bool)

GetTypeOrMemberForSourceNode returns the TypeGraph type or member for the given source node, if any.

func (*TypeGraph) GetTypeOrModuleForSourceNode

func (g *TypeGraph) GetTypeOrModuleForSourceNode(sourceNode compilergraph.GraphNode) (TGTypeOrModule, bool)

GetTypeOrModuleForSourceNode returns the type or module for the given source node, if any.

func (*TypeGraph) IntStreamType

func (t *TypeGraph) IntStreamType() TGTypeDecl

IntStreamType returns the $intstream type.

func (*TypeGraph) IntType

func (t *TypeGraph) IntType() TGTypeDecl

IntType returns the integer type.

func (*TypeGraph) IntTypeReference

func (t *TypeGraph) IntTypeReference() TypeReference

IntTypeReference returns a reference to the int type.

func (*TypeGraph) IntersectTypes

func (g *TypeGraph) IntersectTypes(first []TypeReference, second []TypeReference) []TypeReference

IntersectTypes performs type reference intersection on both slices, returning a new slices.

func (*TypeGraph) LookupGlobalAliasedType

func (g *TypeGraph) LookupGlobalAliasedType(alias string) (TGTypeDecl, bool)

LookupGlobalAliasedType looks up the type with the given global alias and returns it, if any.

func (*TypeGraph) LookupModule

func (g *TypeGraph) LookupModule(source compilercommon.InputSource) (TGModule, bool)

LookupModule looks up the module with the given source and returns it, if any.

func (*TypeGraph) LookupModuleMember

func (g *TypeGraph) LookupModuleMember(memberName string, module compilercommon.InputSource) (TGMember, bool)

LookupModuleMember looks up the member with the given name directly under the given module and returns it (if any).

func (*TypeGraph) LookupReturnType

func (g *TypeGraph) LookupReturnType(sourceNode compilergraph.GraphNode) (TypeReference, bool)

LookupReturnType looks up the return type for an source member or property getter.

func (*TypeGraph) LookupType

func (g *TypeGraph) LookupType(typeName string, module compilercommon.InputSource) (TGTypeDecl, bool)

LookupType looks up the type declaration with the given name in the given module and returns it (if any).

func (*TypeGraph) LookupTypeOrMember

func (g *TypeGraph) LookupTypeOrMember(name string, module compilercommon.InputSource) (TGTypeOrMember, bool)

LookupTypeOrMember looks up the type or member with the given name in the given module and returns it (if any).

func (*TypeGraph) MappingType

func (t *TypeGraph) MappingType() TGTypeDecl

MappingType returns the mapping type.

func (*TypeGraph) MappingTypeReference

func (t *TypeGraph) MappingTypeReference(value TypeReference) TypeReference

MappingTypeReference returns a new reference to the mapoing type, with the given generic.

func (*TypeGraph) Members

func (g *TypeGraph) Members() []TGMember

Members returns all members defined in the type graph.

func (*TypeGraph) Modules

func (g *TypeGraph) Modules() []TGModule

Modules returns all modules defined in the type graph.

func (*TypeGraph) ModulesWithMembers

func (g *TypeGraph) ModulesWithMembers() []TGModule

ModulesWithMembers returns all modules containing members defined in the type graph.

func (*TypeGraph) NativeBoolTypeReference

func (t *TypeGraph) NativeBoolTypeReference() TypeReference

NativeBoolTypeReference returns a reference to the native boolean type.

func (*TypeGraph) NewInstanceTypeReference

func (t *TypeGraph) NewInstanceTypeReference(typeDecl TGTypeDecl) TypeReference

NewInstanceTypeReference returns a new type reference pointing to a type and its generics (if any).

func (*TypeGraph) NewTypeReference

func (t *TypeGraph) NewTypeReference(typeDecl TGTypeDecl, generics ...TypeReference) TypeReference

NewTypeReference returns a new type reference pointing to the given type node and some (optional) generics.

func (*TypeGraph) NullTypeReference

func (t *TypeGraph) NullTypeReference() TypeReference

NullTypeReference returns a reference to the special 'null' type.

func (*TypeGraph) ReleasableType

func (t *TypeGraph) ReleasableType() TGTypeDecl

ReleasableType returns the releasable type.

func (*TypeGraph) ReleasableTypeReference

func (t *TypeGraph) ReleasableTypeReference() TypeReference

ReleasableTypeReference returns a reference to the releasable type.

func (*TypeGraph) ResolveEntityByPath added in v0.2.0

func (g *TypeGraph) ResolveEntityByPath(entityPath []Entity, option EntityResolveOption) (TGEntity, bool)

ResolveEntityByPath finds the entity with the matching set of entries in this type graph, if any.

func (*TypeGraph) ResolveTypeOrMemberUnderPackage

func (g *TypeGraph) ResolveTypeOrMemberUnderPackage(name string, packageInfo packageloader.PackageInfo) (TGTypeOrMember, bool)

ResolveTypeOrMemberUnderPackage searches the type graph for a type or member with the given name, located in any modules found in the given package.

func (*TypeGraph) ResolveTypeUnderPackage

func (g *TypeGraph) ResolveTypeUnderPackage(name string, packageInfo packageloader.PackageInfo) (TGTypeDecl, bool)

ResolveTypeUnderPackage searches the type graph for a type with the given name, located in any modules found in the given package.

func (*TypeGraph) SerializationJSONType

func (t *TypeGraph) SerializationJSONType() TGTypeDecl

SerializationJSONType returns the $json type.

func (*TypeGraph) SerializationParserType

func (t *TypeGraph) SerializationParserType() TGTypeDecl

SerializationParserType returns the $parser type.

func (*TypeGraph) SerializationStringifier

func (t *TypeGraph) SerializationStringifier() TGTypeDecl

SerializationStringifier returns the $stringifier type.

func (*TypeGraph) SliceType

func (t *TypeGraph) SliceType() TGTypeDecl

SliceType returns the slice type.

func (*TypeGraph) SliceTypeReference

func (t *TypeGraph) SliceTypeReference(generic TypeReference) TypeReference

SliceTypeReference returns a new reference to the slice type, with the given generic.

func (*TypeGraph) SourceRangeOf

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

SourceRangeOf returns the source range of the given node in its *source* graph, if any.

func (*TypeGraph) SourceRangesOf

func (g *TypeGraph) SourceRangesOf(node compilergraph.GraphNode) []compilercommon.SourceRange

SourceRangesOf returns the source ranges of the given in its *source* graph, if any.

func (*TypeGraph) StreamType

func (t *TypeGraph) StreamType() TGTypeDecl

StreamType returns the stream type.

func (*TypeGraph) StreamTypeReference

func (t *TypeGraph) StreamTypeReference(generic TypeReference) TypeReference

StreamTypeReference returns a new reference to the stream type, with the given generic.

func (*TypeGraph) StreamableType

func (t *TypeGraph) StreamableType() TGTypeDecl

StreamableType returns the streamable type.

func (*TypeGraph) StringType

func (t *TypeGraph) StringType() TGTypeDecl

StringType returns the string type.

func (*TypeGraph) StringTypeReference

func (t *TypeGraph) StringTypeReference() TypeReference

StringTypeReference returns a reference to the string type.

func (*TypeGraph) StringableType

func (t *TypeGraph) StringableType() TGTypeDecl

StringableType returns the string type.

func (*TypeGraph) StringableTypeReference

func (t *TypeGraph) StringableTypeReference() TypeReference

StringableTypeReference returns a reference to the stringable type.

func (*TypeGraph) StructTypeReference

func (t *TypeGraph) StructTypeReference() TypeReference

StructTypeReference returns a reference to the special 'struct' type.

func (*TypeGraph) TypeAliases

func (g *TypeGraph) TypeAliases() []TGTypeDecl

TypeAliases returns all type aliases in the type graph.

func (*TypeGraph) TypeDecls

func (g *TypeGraph) TypeDecls() []TGTypeDecl

TypeDecls returns all types defined in the type graph.

func (*TypeGraph) TypeOrMembersUnderPackage

func (g *TypeGraph) TypeOrMembersUnderPackage(packageInfo packageloader.PackageInfo) []TGTypeOrMember

TypeOrMembersUnderPackage returns all types or members defined under the given package.

func (*TypeGraph) VoidTypeReference

func (t *TypeGraph) VoidTypeReference() TypeReference

VoidTypeReference returns a reference to the special 'void' type.

type TypeGraphConstructor

type TypeGraphConstructor interface {
	// Defines the modules exported by the source graph.
	DefineModules(builder GetModuleBuilder)

	// Defines the types exported by the source graph (including generics).
	DefineTypes(builder GetTypeBuilder)

	// Defines the constraints on generics, inheritance, and other type-dependent info.
	DefineDependencies(annotator Annotator, graph *TypeGraph)

	// Defines the members under the modules and types.
	DefineMembers(builder GetMemberBuilder, reporter IssueReporter, graph *TypeGraph)

	// Decorates all members with their generics and other attributes. Occurs as a second step after
	// DefineMembers to ensure member-level generics are available for resolution.
	DecorateMembers(decorator GetMemberDecorator, reporter IssueReporter, graph *TypeGraph)

	// Performs final validation of the type graph after full definition.
	Validate(reporter IssueReporter, graph *TypeGraph)

	// GetRanges returns the range information for the given source node in the source graph,
	// if any.
	GetRanges(sourceNodeID compilergraph.GraphNodeId) []compilercommon.SourceRange
}

TypeGraphConstructor defines an interface that is implemented by various source graphs (SRG, IRG) for translating their parsed form into type graph information.

func NewBasicTypesConstructorForTesting added in v0.2.0

func NewBasicTypesConstructorForTesting(graph compilergraph.SerulianGraph) TypeGraphConstructor

NewBasicTypesConstructorForTesting returns a new TypeGraphConstructor which adds the basic types for testing.

type TypeKind

type TypeKind int

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

const (
	ClassType TypeKind = iota
	ImplicitInterfaceType
	ExternalInternalType
	NominalType
	StructType
	AgentType
	GenericType
	AliasType
)

type TypeLookup added in v0.2.0

type TypeLookup func(existingType TGTypeDecl) (TGTypeDecl, bool)

TypeLookup is a function for finding the equivalent type for a type declaration in another type graph.

type TypeMemberTag

type TypeMemberTag string

TypeMemberTag defines the set of custom tags on type members.

const (
	// STRUCT_SERIALIZED_NAME_TAG marks a type member under a struct with its name when
	// serialized.
	STRUCT_SERIALIZED_NAME_TAG TypeMemberTag = "name"
)

type TypeReference

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

TypeReference represents a saved type reference in the graph.

func (TypeReference) AdoptReferenceInto added in v0.2.0

func (tr TypeReference) AdoptReferenceInto(graph *TypeGraph, lookup TypeLookup) (TypeReference, error)

AdoptReferenceInto attempts to turn the current type reference into a reference to the *equivalent* type found in the specified type graph. Type equivalency matching is done via the lookup method. This method is used in libraries that operate on multiple type graphs and need to perform comparison between them.

func (TypeReference) AsNonNullable

func (tr TypeReference) AsNonNullable() TypeReference

AsNonNullable returns a copy of this type reference that is non-nullable.

func (TypeReference) AsNullable

func (tr TypeReference) AsNullable() TypeReference

AsNullable returns a copy of this type reference that is nullable.

func (TypeReference) AsValueOfStream

func (tr TypeReference) AsValueOfStream() TypeReference

AsValueOfStream returns a type reference to a Stream, with this type reference as the value.

func (TypeReference) Build

func (tr TypeReference) Build(value string) interface{}

func (TypeReference) CheckCastableFrom

func (tr TypeReference) CheckCastableFrom(source TypeReference) error

CheckCastableFrom returns whether the type pointed to by this type reference is castable from the source type reference.

Rules:

  • All types can be cast to 'any'
  • Void is never allowed.
  • A null type cannot be casted.
  • `struct` can only be cast to a structural type.
  • Nullability must match.
  • If the destination is an interface, any interface type can be cast to it, as it'll be checked at runtime.
  • Otherwise, subtyping rules are in effect

func (TypeReference) CheckConcreteSubtypeOf

func (tr TypeReference) CheckConcreteSubtypeOf(otherType TGTypeDecl) ([]TypeReference, error)

CheckConcreteSubtypeOf checks that the current type reference refers to a type that is a concrete subtype of the specified *generic* interface.

func (TypeReference) CheckNominalConvertable

func (tr TypeReference) CheckNominalConvertable(other TypeReference) error

CheckNominalConvertable checks that the current type reference refers to a type that is nominally deriving from the given type reference's type or vice versa.

func (TypeReference) CheckStructuralSubtypeOf

func (tr TypeReference) CheckStructuralSubtypeOf(other TypeReference) bool

CheckStructuralSubtypeOf checks that the current type reference refers to a type that is structurally deriving from the given type reference's type.

func (TypeReference) CheckSubTypeOf

func (tr TypeReference) CheckSubTypeOf(other TypeReference) error

CheckSubTypeOf returns whether the type pointed to by this type reference is a subtype of the other type reference: tr <: other

Subtyping rules in Serulian are as follows:

  • All types are subtypes of 'any'.
  • Only structural types are subtypes of 'struct'.
  • The special "null" type is a subtype of any *nullable* type.
  • A non-nullable type is a subtype of a nullable type (but not vice versa).
  • A class is a subtype of itself (and no other class) and only if generics and parameters match.
  • A class (or interface) is a subtype of an interface if it defines that interface's full signature.
  • A generic is checked by its constraint.
  • An external interface is a subtype of another external interface if explicitly declared so.

func (TypeReference) CheckSubTypeOfWithExceptions

func (tr TypeReference) CheckSubTypeOfWithExceptions(other TypeReference, exception SubTypingException) (error, SubTypingException)

CheckSubTypeOfWithExceptions returns whether the type pointed to by this type reference is a subtype of the other type reference: tr <: other

func (TypeReference) ContainsType

func (tr TypeReference) ContainsType(typeDecl TGTypeDecl) bool

ContainsType returns true if the current type reference has a reference to the given type.

func (TypeReference) EnsureStructural

func (tr TypeReference) EnsureStructural() error

EnsureStructural ensures that the type reference and all sub-references are structural in nature. A "structural" type, as allowed by this pass, must meet the following rules:

1) The type is marked with a 'serializable' annotation OR 2) The type is a `struct` OR 3) The type refers to a generic OR 4) The type is a nominal type around #1, #2 or #3 AND 5) All subreferences (generics and parameters) must meet the above rules.

func (TypeReference) EqualsOrAny

func (tr TypeReference) EqualsOrAny(other TypeReference) bool

EqualsOrAny returns true if this type reference is equal to the other given, OR if it is 'any'.

func (TypeReference) ExtractTypeDiff

func (tr TypeReference) ExtractTypeDiff(otherRef TypeReference, diffType TGTypeDecl) (TypeReference, bool)

ExtractTypeDiff attempts to extract the child type reference from this type reference used in place of a reference to the given type in the other reference. For example, if this is a reference to SomeClass<int> and the other reference is SomeClass<T>, passing in 'T' will return 'int'.

func (TypeReference) GenericCount

func (tr TypeReference) GenericCount() int

GenericCount returns the number of generics on this type reference.

func (TypeReference) Generics

func (tr TypeReference) Generics() []TypeReference

Generics returns the generics defined on this type reference, if any.

func (TypeReference) HasGenerics

func (tr TypeReference) HasGenerics() bool

HasGenerics returns whether the type reference has generics.

func (TypeReference) HasParameters

func (tr TypeReference) HasParameters() bool

HasParameters returns whether the type reference has parameters.

func (TypeReference) HasReferredType

func (tr TypeReference) HasReferredType(typeDecl TGTypeDecl) bool

HasReferredType returns whether this type references refers to the given type. Note that the type reference can be nullable.

func (TypeReference) Intersect

func (tr TypeReference) Intersect(other TypeReference) TypeReference

Intersect returns the type common to both type references or any if they are uncommon.

func (TypeReference) IsAny

func (tr TypeReference) IsAny() bool

IsAny returns whether this type reference refers to the special 'any' type.

func (TypeReference) IsDirectReferenceTo

func (tr TypeReference) IsDirectReferenceTo(typeDecl TGTypeDecl) bool

IsDirectReferenceTo returns whether this type references refers to the given type. Note that the type reference cannot be nullable.

func (TypeReference) IsLocalRef

func (tr TypeReference) IsLocalRef() bool

IsLocalRef returns whether this type reference is a localized reference.

func (TypeReference) IsNominal

func (tr TypeReference) IsNominal() bool

IsNominal returns whether the referenced type is a nominal type.

func (TypeReference) IsNominalOrStruct

func (tr TypeReference) IsNominalOrStruct() bool

IsNominalOrStruct returns whether the referenced type is a struct or nominal type.

func (TypeReference) IsNominalWrapOf

func (tr TypeReference) IsNominalWrapOf(other TypeReference) bool

IsNominalWrapOf returns whether the type referenced is a nominal wrapping of the other type.

func (TypeReference) IsNormal

func (tr TypeReference) IsNormal() bool

IsNormal returns whether this type reference refers to a normal type, such as a class, struct, agent or interface.

func (TypeReference) IsNull

func (tr TypeReference) IsNull() bool

IsNull returns whether this type reference refers to the special 'null' type (which is distinct from a nullable type).

func (TypeReference) IsNullable

func (tr TypeReference) IsNullable() bool

IsNullable returns whether the type reference refers to a nullable type.

func (TypeReference) IsRefToAgent

func (tr TypeReference) IsRefToAgent() bool

IsRefToAgent returns whether the referenced type is an agent.

func (TypeReference) IsRefToClass

func (tr TypeReference) IsRefToClass() bool

IsRefToClass returns whether the referenced type is a class.

func (TypeReference) IsRefToImplicitInterface

func (tr TypeReference) IsRefToImplicitInterface() bool

IsRefToImplicitInterface returns whether the referenced type is an interface.

func (TypeReference) IsRefToStruct

func (tr TypeReference) IsRefToStruct() bool

IsRefToStruct returns whether the referenced type is a struct.

func (TypeReference) IsStruct

func (tr TypeReference) IsStruct() bool

IsStruct returns whether this type reference refers to the special 'struct' type.

func (TypeReference) IsStructurual

func (tr TypeReference) IsStructurual() bool

IsStructurual returns whether the reference type is *directly* structural.

func (TypeReference) IsVoid

func (tr TypeReference) IsVoid() bool

IsVoid returns whether this type reference refers to the special 'void' type.

func (TypeReference) Localize

func (tr TypeReference) Localize(generics ...TGGeneric) TypeReference

Localize returns a copy of this type reference with any references to the specified generics replaced with a string that does not reference a specific type node ID, but rather a localized ID instead. This allows type references that reference different type and type member generics to be compared.

func (TypeReference) Name

func (tr TypeReference) Name() string

func (TypeReference) NominalDataType

func (tr TypeReference) NominalDataType() TypeReference

NominalDataType returns the root data type of the nominal type, or the type itself if not nominal.

func (TypeReference) NominalRootType

func (tr TypeReference) NominalRootType() TypeReference

NominalRootType returns the root nominal type of the nominal type, or the type itself if not nominal.

func (TypeReference) NullValueAllowed

func (tr TypeReference) NullValueAllowed() bool

NullValueAllowed returns whether a null value can be assigned to a field of this type.

func (TypeReference) PackageQualifiedString added in v0.2.0

func (tr TypeReference) PackageQualifiedString() string

PackageQualifiedString returns a string representation of the type, qualified by package path for all types, including generics.

func (TypeReference) ParameterCount

func (tr TypeReference) ParameterCount() int

ParameterCount returns the number of parameters on this type reference.

func (TypeReference) Parameters

func (tr TypeReference) Parameters() []TypeReference

Parameters returns the parameters defined on this type reference, if any.

func (TypeReference) ReferredType

func (tr TypeReference) ReferredType() TGTypeDecl

ReferredType returns the type decl to which the type reference refers.

func (TypeReference) ReplaceType

func (tr TypeReference) ReplaceType(typeDecl TGTypeDecl, replacement TypeReference) TypeReference

ReplaceType returns a copy of this type reference, with the given type node replaced with the given type reference.

func (TypeReference) ResolveAccessibleMember

func (tr TypeReference) ResolveAccessibleMember(memberName string, modulePath compilercommon.InputSource, kind MemberResolutionKind) (TGMember, error)

ResolveAccessibleMember looks for an member with the given name under the referred type and returns it (if any).

func (TypeReference) ResolveMember

func (tr TypeReference) ResolveMember(memberName string, kind MemberResolutionKind) (TGMember, bool)

ResolveMember looks for an member with the given name under the referred type and returns it (if any).

func (TypeReference) StreamYieldType added in v0.3.0

func (tr TypeReference) StreamYieldType() (TypeReference, error)

StreamYieldType returns the type of items yielded by this stream or an error if this type is not a concrete subtype of Stream<T>.

func (TypeReference) StreamYieldTypeOrAny added in v0.3.0

func (tr TypeReference) StreamYieldTypeOrAny() TypeReference

StreamYieldTypeOrAny returns the type of the items yielded by this stream, or `any` if none.

func (TypeReference) String

func (tr TypeReference) String() string

String returns a human-friendly string.

func (TypeReference) TitledString

func (tr TypeReference) TitledString() string

TitledString returns a human-friendly string which includes the title of the type referenced.

func (TypeReference) TransformUnder

func (tr TypeReference) TransformUnder(other TypeReference) TypeReference

TransformUnder replaces any generic references in this type reference with the references found in the other type reference.

For example, if this type reference is function<T> and the other is SomeClass<int>, where T is the generic of 'SomeClass', this method will return function<int>.

func (TypeReference) Value

func (tr TypeReference) Value() string

func (TypeReference) Verify

func (tr TypeReference) Verify() error

Verify returns an error if the type reference is invalid in some way. Returns nil if it is valid.

func (TypeReference) WithGeneric

func (tr TypeReference) WithGeneric(generic TypeReference) TypeReference

WithGeneric returns a copy of this type reference with the given generic added.

func (TypeReference) WithParameter

func (tr TypeReference) WithParameter(parameter TypeReference) TypeReference

WithParameter returns a copy of this type reference with the given parameter added.

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