semantic

package
v0.0.0-...-7a622f3 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package semantic holds the set of types used in the abstract semantic graph representation of the api language.

Index

Constants

View Source
const (
	// Resolved indicates that the order has been set.
	Resolved = LogicalOrder(1)
	// Pre represents a statement before a fence.
	Pre = LogicalOrder(2)
	// Post represents a statement after a fence.
	Post = LogicalOrder(4)
)

Variables

View Source
var (
	// BuiltinThreadGlobal represents the $Thread global variable.
	BuiltinThreadGlobal = &Global{
		Type:    Uint64Type,
		Named:   "$Thread",
		Default: Uint64Value(0),
	}

	// BuiltinGlobals is the list of all builtin globals.
	BuiltinGlobals = []*Global{
		BuiltinThreadGlobal,
	}
)
View Source
var (

	// Special types
	VoidType    = builtin("void")
	AnyType     = builtin("any")
	StringType  = builtin("string")
	MessageType = builtin("message")
	// Unsized primitives
	BoolType = builtin("bool")
	IntType  = builtin("int")
	UintType = builtin("uint")
	// Size is used to represent the size_t type in C/C++. It is transmitted
	// between various components as uint64. There's an up-conversion
	// on recording, and a down-conversion on replay.
	SizeType = builtin("size")
	// Char is supposed to be unsized type, but is treated by the APIC templates
	// as a synonym for u8 and the UI assumes ASCII in the memory view.
	CharType = builtin("char")
	// Fixed size integer forms
	Int8Type   = builtin("s8")
	Uint8Type  = builtin("u8")
	Int16Type  = builtin("s16")
	Uint16Type = builtin("u16")
	Int32Type  = builtin("s32")
	Uint32Type = builtin("u32")
	Int64Type  = builtin("s64")
	Uint64Type = builtin("u64")
	// Floating point forms
	Float32Type = builtin("f32")
	Float64Type = builtin("f64")
)
View Source
var BuiltinTypes []*Builtin
View Source
var InvalidType = builtin("<invalid>")

InvalidType is a placeholder for an invalid type. They are only generated by the resolver when the source has a syntatic error.

Functions

func Add

func Add(p Owner, c Owned)

Add connects an Owned to its Owner.

func AsUint64

func AsUint64(val Expression) (uint64, bool)

AsUint64 converts a sized integer value to a uint64.

func IntegerSizeInBits

func IntegerSizeInBits(ty Type) int

IntegerSizeInBits returns the size in bits of the given integer type. If ty is not an integer, then IntegerSizeInBits returns 0.

func IsInteger

func IsInteger(ty Type) bool

IsInteger returns true if ty is an integer type

func IsNumeric

func IsNumeric(ty Type) bool

IsNumeric returns true if t is one of the primitive numeric types.

func IsReference

func IsReference(ty Type) bool

IsReference returns true if ty is a reference type.

func IsStorageType

func IsStorageType(ty Type) bool

IsStorageType returns true if ty can be used as a storage type.

func IsUnsigned

func IsUnsigned(ty Type) bool

IsUnsigned returns true if ty is an unsigned integer type

func Replace

func Replace(node Node, visitor func(Node) Node)

Replace invokes visitor for all the children of the supplied node, replacing the node with the returned value.

func Visit

func Visit(node Node, visitor func(Node))

Visit invokes visitor for all the children of the supplied node.

Types

type API

type API struct {
	Named
	Enums        []*Enum        // the set of enums
	Definitions  []*Definition  // the set of definitions
	Classes      []*Class       // the set of classes
	Pseudonyms   []*Pseudonym   // the set of pseudo types
	Externs      []*Function    // the external function references
	Subroutines  []*Function    // the global subroutines
	Functions    []*Function    // the global functions
	Methods      []*Function    // the method functions
	Globals      []*Global      // the global variables
	StaticArrays []*StaticArray // the fixed size array types used
	Maps         []*Map         // the map types used
	Pointers     []*Pointer     // the pointer types used
	Slices       []*Slice       // the pointer types used
	References   []*Reference   // the reference types used
	Signatures   []*Signature   // the function signature types used
	Index        Uint8Value     // the index of this api
	// contains filtered or unexported fields
}

API is the root of the ASG, and holds a fully resolved api.

func (*API) ClassIndex

func (a *API) ClassIndex(class *Class) int

ClassIndex returns the index of the given class, or -1 if the class does not belong to the API.

func (*API) CommandIndex

func (a *API) CommandIndex(cmd *Function) int

CommandIndex returns the index of the given command, or -1 if the function is not a command of the API.

func (*API) EnumIndex

func (a *API) EnumIndex(enum *Enum) int

EnumIndex returns the index of the given enum, or -1 if the enum does not belong to the API.

func (*API) MapIndex

func (a *API) MapIndex(t *Map) int

MapIndex returns the index of the given map, or -1 if the map does not belong to the API.

func (*API) Member

func (m *API) Member(name string) Owned

func (*API) SliceIndex

func (a *API) SliceIndex(slice *Slice) int

SliceIndex returns the index of the given slice, or -1 if the slice does not belong to the API.

func (*API) SortMembers

func (m *API) SortMembers()

SortMembers sorts the members alphabetically.

func (*API) VisitMembers

func (m *API) VisitMembers(visitor func(Owned))

VisitMembers invokes the supplied function once for each member.

type ASTBacked

type ASTBacked interface {
	ASTNode() ast.Node
}

type Abort

type Abort struct {
	AST       *ast.Abort // the underlying syntax node this was built from
	Function  *Function  // the function this is aborting
	Statement Statement
}

Abort represents the abort statement, used to immediately terminate execution of a command, usually because of an error.

type Annotated

type Annotated interface {
	// GetAnnotation returns the annotation with the matching name, if present.
	GetAnnotation(name string) *Annotation
}

Annotated is the common interface to objects that can carry annotations.

type Annotation

type Annotation struct {
	AST       *ast.Annotation // the underlying syntax node this was built from
	Named                     // the name of the annotation
	Arguments []Expression    // the arguments to the annotation
}

Annotation represents a single annotation on an Annotated.

type Annotations

type Annotations []*Annotation

Annotations is an array of Annotation objects that implements the Annotated interface. It is used as an anonymous field on objects that carry annotations.

func (Annotations) GetAnnotation

func (a Annotations) GetAnnotation(name string) *Annotation

GetAnnotation implements the Annotated interface for the Annotations type.

func (*Annotations) IsInternal

func (a *Annotations) IsInternal() bool

IsInternal returns true if the object is annotated with @internal. It is illegal to assign a non-external pointer or slice to an internal pointer or slice.

type ArrayAssign

type ArrayAssign struct {
	AST      *ast.Assign // the underlying syntax node this was built from
	To       *ArrayIndex // the array index to assign to
	Operator string      // the assignment operator being applied
	Value    Expression  // the value to set in the array
}

ArrayAssign represents assigning to a static-array index expression.

type ArrayIndex

type ArrayIndex struct {
	AST   *ast.Index   // the underlying syntax node this was built from
	Type  *StaticArray // the array type
	Array Expression   // the expression that returns the array to be indexed
	Index Expression   // the index to use on the array
}

ArrayIndex represents using the indexing operator on a static-array type.

func (*ArrayIndex) ExpressionType

func (i *ArrayIndex) ExpressionType() Type

ExpressionType implements Expression. It returns the element type of the array.

type ArrayInitializer

type ArrayInitializer struct {
	AST    *ast.Call    // the underlying syntax node this was built from
	Array  Type         // the array type to initialize (may be aliased)
	Values []Expression // the list of element values
}

ArrayInitializer represents an expression that creates a new StaticArray instance using a value list, of the form T(v0, v1, v2)

func (*ArrayInitializer) ExpressionType

func (c *ArrayInitializer) ExpressionType() Type

ExpressionType implements Expression returning the class type being initialized.

type Assert

type Assert struct {
	AST       *ast.Call  // the underlying syntax node this was built from
	Condition Expression // the condition is being asserted must be true
	Message   string
}

Assert represents a runtime assertion. Assertions are also used to infer required behavior from the expressions.

type Assign

type Assign struct {
	AST      *ast.Assign // the underlying syntax node this was built from
	LHS      Expression  // the expression that gives the location to store into
	Operator string      // the assignment operator being applied
	RHS      Expression  // the value to store
}

Assign is the only "mutating" construct. It assigns the value from the rhs into the slot described by the lhs, as defined by the operator.

type BinaryOp

type BinaryOp struct {
	AST      *ast.BinaryOp // the underlying syntax node this was built from
	Type     Type          // the resolved type of this binary expression
	LHS      Expression    // the expression that appears on the left of the operator
	Operator string        // the operator being applied
	RHS      Expression    // the expression that appears on the right of the operator
}

BinaryOp represents any operator applied to two arguments. The resolved type of the expression depends on the types of the two arguments and which operator it represents.

func (*BinaryOp) ExpressionType

func (b *BinaryOp) ExpressionType() Type

ExpressionType implements Expression

type BitTest

type BitTest struct {
	AST      *ast.BinaryOp // the underlying syntax node this was built from
	Bitfield Expression    // the bitfield being tested
	Bits     Expression    // the bits to test for
}

BitTest is the "in" operator applied to a bitfield.

func (*BitTest) ExpressionType

func (*BitTest) ExpressionType() Type

ExpressionType implements Expression

type Block

type Block struct {
	AST        *ast.Block // the underlying syntax node this was built from
	Statements Statements // the set of statements this block represents
}

Block represents a collection of statements, used as the body of other nodes.

type BoolValue

type BoolValue bool

BoolValue is a bool that implements Expression so it can be in the semantic graph

func (BoolValue) ExpressionType

func (v BoolValue) ExpressionType() Type

ExpressionType implements Expression with a type of BoolType

type Branch

type Branch struct {
	AST       *ast.Branch // the underlying syntax node this was built from
	Condition Expression  // the condition to select on
	True      *Block      // use if Condition is true
	False     *Block      // used if Condition is false
}

Branch represents the basic conditional execution statement. If Condition is true we use the True block, otherwise the False block.

type Builtin

type Builtin struct {
	Named // the primitive type name
	// contains filtered or unexported fields
}

Builtin represents one of the primitive types.

func (Builtin) Member

func (Builtin) Member(string) Owned

func (*Builtin) Owner

func (o *Builtin) Owner() Owner

func (Builtin) SortMembers

func (Builtin) SortMembers()

func (Builtin) String

func (b Builtin) String() string

func (Builtin) VisitMembers

func (Builtin) VisitMembers(func(Owned))

type Call

type Call struct {
	AST       *ast.Call    // the underlying syntax node this was built from
	Target    *Callable    // the function expression this invokes
	Arguments []Expression // the arguments to pass to the function
	Type      Type         // the return type of the call
}

Call represents a function call. It binds an Callable to the arguments it will be passed.

func (*Call) ExpressionType

func (c *Call) ExpressionType() Type

ExpressionType implements Expression returning the underlying function return type.

type Callable

type Callable struct {
	Object   Expression // the object to use as the this parameter for a method
	Function *Function  // the function this expression represents
}

Callable wraps a Function declaration into a function value expression, optionally binding to an object if its a method.

func (*Callable) ExpressionType

func (c *Callable) ExpressionType() Type

ExpressionType implements Expression returning the function type signature.

type Case

type Case struct {
	AST         *ast.Case    // the underlying syntax node this was built from
	Annotations              // the annotations applied to the case
	Conditions  []Expression // the set of expressions to match the switch value against
	Block       *Block       // the block to use if a condition matches
}

Case represents a possible choice in a switch.

type Cast

type Cast struct {
	AST    *ast.Call  // the underlying syntax node this was built from
	Object Expression // the expression to cast the result of
	Type   Type       // the type to cast to
}

Cast represents a type reinterpret expression.

func (*Cast) ExpressionType

func (c *Cast) ExpressionType() Type

ExpressionType implements Expression

type Choice

type Choice struct {
	AST         *ast.Case    // the underlying syntax node this was built from
	Annotations              // the annotations applied to the choice
	Conditions  []Expression // the set of expressions to match the select value against
	Expression  Expression   // the expression to use if a condition matches
}

Choice represents a possible choice in a select

type Class

type Class struct {
	AST         *ast.Class    // the underlying syntax node this was built from
	Annotations               // the annotations applied to this class
	Named                     // implement Child
	Docs        Documentation // the documentation for the class
	Fields      []*Field      // the set of fields the class declares
	Methods     []*Function   // the set of functions associated with the class
	// contains filtered or unexported fields
}

Class represents an api class construct.

func (*Class) ASTNode

func (t *Class) ASTNode() ast.Node

func (*Class) FieldByName

func (t *Class) FieldByName(n string) *Field

FieldByName returns the field of t with the name n, or nil.

func (*Class) Member

func (m *Class) Member(name string) Owned

func (*Class) Owner

func (o *Class) Owner() Owner

func (*Class) SortMembers

func (m *Class) SortMembers()

SortMembers sorts the members alphabetically.

func (Class) String

func (c Class) String() string

func (*Class) VisitMembers

func (m *Class) VisitMembers(visitor func(Owned))

VisitMembers invokes the supplied function once for each member.

type ClassInitializer

type ClassInitializer struct {
	AST    *ast.Call           // the underlying syntax node this was built from
	Class  *Class              // the class to initialize
	Fields []*FieldInitializer // the set of field assignments
}

ClassInitializer represents an expression that can assign values to multiple fields of a class.

func (*ClassInitializer) ExpressionType

func (c *ClassInitializer) ExpressionType() Type

ExpressionType implements Expression returning the class type being initialized.

func (*ClassInitializer) InitialValues

func (c *ClassInitializer) InitialValues() []Expression

InitialValues returns the full set of initial values for each field in the class. If there is not an initialized or default value for a field, then nil is returned for that field.

func (*ClassInitializer) IsCopyConstructor

func (c *ClassInitializer) IsCopyConstructor() bool

IsCopyConstructor returns whether this ClassInitializer represents the calling of the copy constructor.

type Clone

type Clone struct {
	AST   *ast.Call // the underlying syntax node this was built from
	Slice Expression
	Type  *Slice
}

Clone represents a call to clone.

func (*Clone) ExpressionType

func (m *Clone) ExpressionType() Type

ExpressionType implements Expression

type Copy

type Copy struct {
	AST *ast.Call // the underlying syntax node this was built from
	Src Expression
	Dst Expression
}

Copy represents a call to copy.

type Create

type Create struct {
	AST         *ast.Call // the underlying syntax node this was built from
	Type        *Reference
	Initializer *ClassInitializer
}

Create represents a call to new on a class type.

func (*Create) ExpressionType

func (n *Create) ExpressionType() Type

ExpressionType implements Expression

type DeclareLocal

type DeclareLocal struct {
	AST   *ast.DeclareLocal // the underlying syntax node this was built from
	Local *Local            // the local variable that was declared by this statement
}

DeclareLocal represents a local variable declaration statement. Variables cannot be modified after declaration.

type Definition

type Definition struct {
	Named
	AST         *ast.Definition // the underlying syntax node this was built from
	Annotations                 // the annotations applied to this definition
	Docs        Documentation   // the documentation for this definition
	Expression  Expression      // the value of this definition, type-inferred without context
	// contains filtered or unexported fields
}

Definition represents a named literal definition.

func (*Definition) ExpressionType

func (d *Definition) ExpressionType() Type

func (Definition) Member

func (Definition) Member(string) Owned

func (Definition) SortMembers

func (Definition) SortMembers()

func (Definition) VisitMembers

func (Definition) VisitMembers(func(Owned))

type DefinitionUsage

type DefinitionUsage struct {
	Definition *Definition // the definition of this definition usage
	Expression Expression  // the value of this definition, type-inferred by its usage context
	// contains filtered or unexported fields
}

DefinitionUsage represents a named literal usage.

func (*DefinitionUsage) ExpressionType

func (d *DefinitionUsage) ExpressionType() Type

func (DefinitionUsage) Member

func (DefinitionUsage) Member(string) Owned

func (DefinitionUsage) SortMembers

func (DefinitionUsage) SortMembers()

func (DefinitionUsage) VisitMembers

func (DefinitionUsage) VisitMembers(func(Owned))

type Documentation

type Documentation []string

Documentation represents the documentation strings for a type or function.

type Enum

type Enum struct {
	AST         *ast.Enum     // the underlying syntax node this was built from
	Annotations               // the annotations applied to this enum
	Named                     // the type name of the enum
	Docs        Documentation // the documentation for the enum
	IsBitfield  bool          // whether this enum is actually a bitfield
	NumberType  Type          // the numerical type of each entry
	Entries     []*EnumEntry  // the entries of this enum
	// contains filtered or unexported fields
}

Enum represents the api enum construct.

func (*Enum) ASTNode

func (t *Enum) ASTNode() ast.Node

func (*Enum) Member

func (m *Enum) Member(name string) Owned

func (*Enum) Owner

func (o *Enum) Owner() Owner

func (*Enum) SortMembers

func (m *Enum) SortMembers()

SortMembers sorts the members alphabetically.

func (Enum) String

func (e Enum) String() string

func (*Enum) VisitMembers

func (m *Enum) VisitMembers(visitor func(Owned))

VisitMembers invokes the supplied function once for each member.

type EnumEntry

type EnumEntry struct {
	AST   *ast.EnumEntry // the underlying syntax node this was built from
	Named                // the name of this entry
	Docs  Documentation  // the documentation for the enum entry
	Value Expression     // the value this entry represents
	// contains filtered or unexported fields
}

EnumEntry represents a single entry in an Enum.

func (*EnumEntry) ExpressionType

func (e *EnumEntry) ExpressionType() Type

ExpressionType implements Expression returning the enum type.

func (*EnumEntry) Owner

func (o *EnumEntry) Owner() Owner

func (EnumEntry) String

func (e EnumEntry) String() string

type Expression

type Expression interface {
	Node
	ExpressionType() Type // returns the expression value type.
	// contains filtered or unexported methods
}

Expression represents anything that can act as an expression in the api language, it must be able to correctly report the type of value it would return if executed.

type Fence

type Fence struct {
	AST       *ast.Fence // the underlying syntax node this was built from
	Statement Statement
	Explicit  bool // If true, then the fence was explicitly declared in the API file.
}

Fence is a marker to indicate the point between all statements to be executed before (pre-fence) the call to the API function and all statements to be executed after (post-fence) the call to the API function.

The Statement member is the first statement that is classified as post-fence, but may be nil if the fence is being added at the end of a function that has no post operations.

Note that some statements are classified as both pre-fence and post-fence, and require logic to be executed either side of the API function call.

type Field

type Field struct {
	AST         *ast.Field    // the underlying syntax node this was built from
	Annotations               // the annotations applied to this field
	Type        Type          // the type the field stores
	Named                     // the name of the field
	Docs        Documentation // the documentation for the field
	Default     Expression    // the default value of the field
	// contains filtered or unexported fields
}

Field represents a field entry in a class.

func (*Field) ExpressionType

func (f *Field) ExpressionType() Type

ExpressionType implements Expression to return the type stored in the field.

func (*Field) Owner

func (o *Field) Owner() Owner

func (Field) String

func (f Field) String() string

type FieldInitializer

type FieldInitializer struct {
	AST   ast.Node   // the underlying syntax node this was built from
	Field *Field     // the field to assign to
	Value Expression // the value to assign
}

FieldInitializer represents the value initialization of a class field.

type Float32Value

type Float32Value float32

Float32Value is a float32 that implements Expression so it can be in the semantic graph

func (Float32Value) ExpressionType

func (v Float32Value) ExpressionType() Type

ExpressionType implements Expression with a type of Float32Type

type Float64Value

type Float64Value float64

Float64Value is a float64 that implements Expression so it can be in the semantic graph

func (Float64Value) ExpressionType

func (v Float64Value) ExpressionType() Type

ExpressionType implements Expression with a type of Float64Type

type Function

type Function struct {
	AST            *ast.Function // the underlying syntax node this was built from
	Annotations                  // the annotations applied to the function
	Named                        // the name of the function
	Docs           Documentation // the documentation for the function
	Return         *Parameter    // the return parameter
	This           *Parameter    // the this parameter, missing for non method functions
	FullParameters []*Parameter  // all the parameters, including This at the start if valid, and Return at the end if not void
	Block          *Block        // the body of the function, missing for externs
	Signature      *Signature    // the type signature of the function
	Extern         bool          // true if this was declared as an extern
	Subroutine     bool          // true if this was declared as a subroutine
	Recursive      bool          // true if this function is part of a recursive chain
	Order          LogicalOrder  // the logical order of the statements relative to the fence
	// contains filtered or unexported fields
}

Function represents function like objects in the semantic graph.

func (*Function) CallParameters

func (f *Function) CallParameters() []*Parameter

CallParameters returns the full set of parameters with the return value filtered out.

func (*Function) Owner

func (o *Function) Owner() Owner

type Global

type Global struct {
	AST         *ast.Field // the underlying syntax node this was built from
	Annotations            // the annotations applied to this global
	Type        Type       // the type the global stores
	Named                  // the name of the global
	Default     Expression // the initial value of the global
	// contains filtered or unexported fields
}

Global represents a global variable.

func (*Global) ExpressionType

func (g *Global) ExpressionType() Type

ExpressionType returns the type stored in the global.

func (*Global) Owner

func (o *Global) Owner() Owner

type Ignore

type Ignore struct {
	AST ast.Node // the underlying syntax node this was built from
}

Ignore represents an _ expression.

func (*Ignore) ExpressionType

func (i *Ignore) ExpressionType() Type

ExpressionType implements Expression.

type Import

type Import struct {
	Named      // the full type name
	API   *API // the API being imported
	// contains filtered or unexported fields
}

Import wraps an API with it's imported name.

func (Import) Member

func (i Import) Member(name string) Owned

Member implements the Owner interface delegating member lookup to the imported API

func (*Import) Owner

func (o *Import) Owner() Owner

func (Import) SortMembers

func (Import) SortMembers()

func (Import) VisitMembers

func (Import) VisitMembers(func(Owned))

type Int16Value

type Int16Value int16

Int16Value is an int16 that implements Expression so it can be in the semantic graph

func (Int16Value) ExpressionType

func (v Int16Value) ExpressionType() Type

ExpressionType implements Expression with a type of Int16Type

type Int32Value

type Int32Value int32

Int32Value is an int32 that implements Expression so it can be in the semantic graph

func (Int32Value) ExpressionType

func (v Int32Value) ExpressionType() Type

ExpressionType implements Expression with a type of Int32Type

type Int64Value

type Int64Value int64

Int64Value is an int64 that implements Expression so it can be in the semantic graph

func (Int64Value) ExpressionType

func (v Int64Value) ExpressionType() Type

ExpressionType implements Expression with a type of Int64Type

type Int8Value

type Int8Value int8

Int8Value is an int8 that implements Expression so it can be in the semantic graph

func (Int8Value) ExpressionType

func (v Int8Value) ExpressionType() Type

ExpressionType implements Expression with a type of Int8Type

type Invalid

type Invalid struct {
	// If part of the code could be parsed, then this is the partially parsed
	// node. For example Partial would hold a parsed expression if an incomplete
	// statement was formed.
	Partial Node
}

Invalid is a placeholder for an invalid expression or statement. They are only generated by the resolver when the source has a syntatic error.

func (Invalid) ExpressionType

func (Invalid) ExpressionType() Type

type Iteration

type Iteration struct {
	AST      *ast.Iteration // the underlying syntax node this was built from
	Iterator *Local         // the iteration control variable
	From     Expression     // the expression to iterate from
	To       Expression     // the expression to iterate to
	Block    *Block         // the block to run for each entry from Iterable
}

Iteration is the basic looping construct. It will set Iterator to each value from Iterable in turn, and run Block for each one.

type Length

type Length struct {
	AST    *ast.Call  // the underlying syntax node this was built from
	Object Expression // the object go get the length of
	Type   Type       // the resolved type of the length operation
}

Length represents a length of object expression. Object must be of either pointer, slice, map or string type. The length expression is allowed to be of any numeric type

func (*Length) ExpressionType

func (l *Length) ExpressionType() Type

ExpressionType implements Expression

type Local

type Local struct {
	Declaration *DeclareLocal // the statement that created the local
	Type        Type          // the type of the storage
	Named                     // the identifier that will resolve to this local
	Value       Expression    // the expression the local was assigned on creation
}

Local represents an immutable local storage slot, created by a DeclareLocal, and referred to by identifiers that resolve to that slot.

func (*Local) ExpressionType

func (l *Local) ExpressionType() Type

ExpressionType implements Expression

type LogicalOrder

type LogicalOrder int

LogicalOrder is a bitfield describing whether a statement, block or subroutine belongs before (pre) or after (post) the command's fence. Some statements and blocks straddle the fence, in which case both the pre and post bits will be set.

func (LogicalOrder) Post

func (o LogicalOrder) Post() bool

Post returns true if the logical order has the Post bit set.

func (LogicalOrder) Pre

func (o LogicalOrder) Pre() bool

Pre returns true if the logical order has the Pre bit set.

func (LogicalOrder) Resolved

func (o LogicalOrder) Resolved() bool

Resolved returns true if the logical order has the Resolved bit set.

func (LogicalOrder) String

func (o LogicalOrder) String() string

type Make

type Make struct {
	AST  *ast.Call // the underlying syntax node this was built from
	Type *Slice
	Size Expression
}

Make represents a call to make.

func (*Make) ExpressionType

func (m *Make) ExpressionType() Type

ExpressionType implements Expression

type Map

type Map struct {
	Named          // the full type name
	KeyType   Type // the type used as an indexing key
	ValueType Type // the type stored in the map
	Dense     bool // Is this a dense map
	// contains filtered or unexported fields
}

Map represents an api map type declaration, of the form map!(KeyType, ValueType)

func (*Map) Member

func (m *Map) Member(name string) Owned

func (*Map) Owner

func (o *Map) Owner() Owner

func (*Map) SortMembers

func (m *Map) SortMembers()

SortMembers sorts the members alphabetically.

func (Map) String

func (m Map) String() string

func (*Map) VisitMembers

func (m *Map) VisitMembers(visitor func(Owned))

VisitMembers invokes the supplied function once for each member.

type MapAssign

type MapAssign struct {
	AST      *ast.Assign // the underlying syntax node this was built from
	To       *MapIndex   // the map index to assign to
	Operator string      // the assignment operator being applied
	Value    Expression  // the value to set in the map
}

MapAssign represents assigning to a map index expression.

type MapClear

type MapClear struct {
	AST  *ast.Clear // the underlying syntax node this was built from
	Type *Map       // the value type of the map
	Map  Expression // the expression that returns the map holding the key
}

MapClear represents clearing a map

type MapContains

type MapContains struct {
	AST  *ast.BinaryOp // the underlying syntax node this was built from
	Type *Map          // the value type of the map being indexed
	Map  Expression    // the map being tested
	Key  Expression    // the key to test for
}

MapContains is the "in" operator applied to a map.

func (*MapContains) ExpressionType

func (*MapContains) ExpressionType() Type

ExpressionType implements Expression

type MapIndex

type MapIndex struct {
	AST   *ast.Index // the underlying syntax node this was built from
	Type  *Map       // the value type of the map being indexed
	Map   Expression // the expression that returns the map to be indexed
	Index Expression // the index to use on the map
}

MapIndex represents using the indexing operator on a map type.

func (*MapIndex) ExpressionType

func (i *MapIndex) ExpressionType() Type

ExpressionType implements Expression returning the value type of the map.

type MapIteration

type MapIteration struct {
	AST           *ast.MapIteration // the underlying syntax node this was built from
	IndexIterator *Local            // the iteration index control variable
	KeyIterator   *Local            // the iteration key control variable
	ValueIterator *Local            // the iteration value control variable
	Map           Expression        // the map to iterate over
	Block         *Block            // the block to run for each k-v mapping
}

MapIteration is a loop over a map's key-value pairs. It will set KeyIterator and ValueIterator to each pair from Map in turn, set IndexIterator to 0 and increment on each loop, and run Block for each.

type MapRemove

type MapRemove struct {
	AST  *ast.Delete // the underlying syntax node this was built from
	Type *Map        // the value type of the map
	Map  Expression  // the expression that returns the map holding the key
	Key  Expression  // the map key to remove
}

MapRemove represents removing an element from a map.

type Mappings

type Mappings struct {
	AST           ast.Mappings
	ASTToSemantic map[ast.Node][]Node
	SemanticToAST map[Node][]ast.Node
}

Mappings is a two-way map of AST nodes to semantic nodes.

func (*Mappings) Add

func (m *Mappings) Add(a ast.Node, s Node)

Add creates an association between the AST and semantic nodes.

func (*Mappings) CST

func (m *Mappings) CST(sem Node) cst.Node

CST returns the primary CST for the semantic node. If the semantic node has no associated CST then nil is returned.

func (*Mappings) MergeIn

func (m *Mappings) MergeIn(other *Mappings)

MergeIn merges the mappings in other into m.

func (*Mappings) Remove

func (m *Mappings) Remove(s Node)

Remove removes the semantic node from the mappings.

type Member

type Member struct {
	AST    *ast.Member // the underlying syntax node this was built from
	Object Expression  // the object to look up a field of
	Field  *Field      // the field to look up
}

Member is an expression that looks up a field by name from an object.

func (*Member) ExpressionType

func (m *Member) ExpressionType() Type

ExpressionType implements Expression returning the type of the field.

func (*Member) GetAnnotation

func (m *Member) GetAnnotation(name string) *Annotation

GetAnnotation returns the annotation with the matching name, if present.

type MessageValue

type MessageValue struct {
	AST       *ast.Class          // the underlying syntax node this was built from
	Arguments []*FieldInitializer // the list of message arguments
}

MessageValue is an expression that produces a localized message

func (*MessageValue) ExpressionType

func (*MessageValue) ExpressionType() Type

ExpressionType implements Expression with a type of MessageType

type Named

type Named string

Named is mixed in to implement the Name method of NamedNode.

func (Named) Name

func (n Named) Name() string

type NamedNode

type NamedNode interface {
	Node
	Name() string // Returns the partial name of the object.
}

NamedNode represents any semantic-tree node that carries a name.

type New

type New struct {
	AST  *ast.Call // the underlying syntax node this was built from
	Type *Reference
}

New represents a call to new.

func (*New) ExpressionType

func (n *New) ExpressionType() Type

ExpressionType implements Expression

type Node

type Node interface {
	// contains filtered or unexported methods
}

Node represents any semantic-tree node type.

type Null

type Null struct {
	AST  *ast.Null // the underlying syntax node this was built from
	Type Type      // the resolved type of this null
}

Null represents a default value.

func (Null) ExpressionType

func (n Null) ExpressionType() Type

ExpressionType implements Expression with the inferred type of the null.

type Observed

type Observed struct {
	Parameter *Parameter // the output parameter to infer from
}

Observed represents the final observed value of an output parameter. It is never produced directly from the ast, but is inserted when inferring the value of an unknown from observed outputs.

func (*Observed) ExpressionType

func (e *Observed) ExpressionType() Type

ExpressionType implements Expression for observed parameter lookup.

type Owned

type Owned interface {
	NamedNode
	// Owner returns the owner of this node.
	Owner() Owner
	// contains filtered or unexported methods
}

Owned is the interface to an object with a unique name and an owner.

type Owner

type Owner interface {
	NamedNode
	// Member looks up a member by name from an owner.
	Member(string) Owned
	// VisitMembers invokes the supplied function once for each member.
	VisitMembers(func(Owned))
	// SortMembers sorts the members alphabetically.
	SortMembers()
	// contains filtered or unexported methods
}

Owner is the interface for an object that has named Members.

type Parameter

type Parameter struct {
	AST         *ast.Parameter // the underlying syntax node this was built from
	Annotations                // the annotations applied to the parameter
	Function    *Function      // the function this parameter belongs to
	Named                      // the name of the parameter
	Docs        Documentation  // the documentation for the parameter
	Type        Type           // the type of the parameter
}

Parameter represents a single parameter declaration for a function.

func (*Parameter) ExpressionType

func (p *Parameter) ExpressionType() Type

ExpressionType implements Expression for parameter lookup.

func (*Parameter) IsReturn

func (p *Parameter) IsReturn() bool

IsReturn returns true if this parameter is the Return parameter of it's function.

func (*Parameter) IsThis

func (p *Parameter) IsThis() bool

IsThis returns true if this parameter is the This parameter of it's function.

type Pointer

type Pointer struct {
	Named        // the full type name
	To    Type   // the type this is a pointer to
	Const bool   // whether the pointer was declared with the const attribute
	Slice *Slice // The complementary slice type for this pointer.
	// contains filtered or unexported fields
}

Pointer represents an api pointer type declaration, of the form To*

func (*Pointer) Member

func (t *Pointer) Member(name string) Owned

func (*Pointer) Owner

func (o *Pointer) Owner() Owner

func (*Pointer) SortMembers

func (t *Pointer) SortMembers()

func (Pointer) String

func (p Pointer) String() string

func (*Pointer) VisitMembers

func (t *Pointer) VisitMembers(visitor func(Owned))

type PointerRange

type PointerRange struct {
	AST     *ast.Index // the underlying syntax node this was built from
	Type    *Slice     // the slice type returned.
	Pointer Expression // the expression that returns the pointer to be indexed
	Range   *BinaryOp  // the range to use on the slice
}

PointerRange represents using the indexing operator on a pointer type with a range expression.

func (*PointerRange) ExpressionType

func (i *PointerRange) ExpressionType() Type

ExpressionType implements Expression. It returns the same slice type being sliced.

type Print

type Print struct {
	AST       *ast.Call    // the underlying syntax node this was built from
	Arguments []Expression // The parameters to print
}

Print represents a call to print.

type Pseudonym

type Pseudonym struct {
	AST         *ast.Pseudonym // the underlying syntax node this was built from
	Annotations                // the annotations applied to this pseudonym
	Named                      // the type name
	Docs        Documentation  // the documentation for the pseudonym
	To          Type           // the underlying type
	Methods     []*Function    // the methods added directly to the pseudonym
	// contains filtered or unexported fields
}

Pseudonym represents the type construct. It acts as a type in it's own right that can carry methods, but is defined in terms of another type.

func (*Pseudonym) ASTNode

func (t *Pseudonym) ASTNode() ast.Node

func (*Pseudonym) Member

func (t *Pseudonym) Member(name string) Owned

Member implements Type returning the direct member if it has it, otherwise delegating the lookup to the underlying type.

func (*Pseudonym) Owner

func (o *Pseudonym) Owner() Owner

func (*Pseudonym) SortMembers

func (t *Pseudonym) SortMembers()

func (Pseudonym) String

func (p Pseudonym) String() string

func (*Pseudonym) VisitMembers

func (t *Pseudonym) VisitMembers(visitor func(Owned))

type Read

type Read struct {
	AST   *ast.Call // the underlying syntax node this was built from
	Slice Expression
}

Read represents a call to read.

type Reference

type Reference struct {
	Named      // the full type name
	To    Type // the type this is a reference to
	// contains filtered or unexported fields
}

Reference represents an api reference type declaration, of the form ref!To

func (*Reference) Member

func (t *Reference) Member(name string) Owned

func (*Reference) Owner

func (o *Reference) Owner() Owner

func (*Reference) SortMembers

func (t *Reference) SortMembers()

func (Reference) String

func (r Reference) String() string

func (*Reference) VisitMembers

func (t *Reference) VisitMembers(visitor func(Owned))

type Return

type Return struct {
	AST      *ast.Return // the underlying syntax node this was built from
	Function *Function   // the function this statement returns from
	Value    Expression  // the value to be returned
}

Return represents return statement for a function.

type Select

type Select struct {
	AST     *ast.Switch // the underlying syntax node this was built from
	Type    Type        // the return type of the select if valid
	Value   Expression  // the value to match the cases against
	Choices []*Choice   // The set of possible choices to match
	Default Expression  // the expression to use if no condition matches
}

Select is the expression form of a switch.

func (*Select) ExpressionType

func (s *Select) ExpressionType() Type

ExpressionType implements Expression with the unified type of the choices

type Signature

type Signature struct {
	Named            // the full type name
	Return    Type   // the return type of the callable
	Arguments []Type // the required callable arguments
	// contains filtered or unexported fields
}

Signature represents a callable type signature

func (Signature) Member

func (Signature) Member(string) Owned

func (*Signature) Owner

func (o *Signature) Owner() Owner

func (Signature) SortMembers

func (Signature) SortMembers()

func (Signature) VisitMembers

func (Signature) VisitMembers(func(Owned))

type Slice

type Slice struct {
	Named            // the full type name
	To      Type     // The type this is a slice of
	Pointer *Pointer // The complementary pointer type for this slice.
	// contains filtered or unexported fields
}

Slice represents an api slice type declaration, of the form To[]

func (Slice) Member

func (Slice) Member(string) Owned

func (*Slice) Owner

func (o *Slice) Owner() Owner

func (Slice) SortMembers

func (Slice) SortMembers()

func (Slice) String

func (s Slice) String() string

func (Slice) VisitMembers

func (Slice) VisitMembers(func(Owned))

type SliceAssign

type SliceAssign struct {
	AST      *ast.Assign // the underlying syntax node this was built from
	To       *SliceIndex // the slice index to assign to
	Operator string      // the assignment operator being applied
	Value    Expression  // the value to set in the slice
}

SliceAssign represents assigning to a slice index expression.

type SliceContains

type SliceContains struct {
	AST   *ast.BinaryOp // the underlying syntax node this was built from
	Type  *Slice        // the value type of the map being sliced
	Slice Expression    // the slice being tested
	Value Expression    // the value to test for
}

SliceContains is the "in" operator applied to a slice.

func (*SliceContains) ExpressionType

func (*SliceContains) ExpressionType() Type

ExpressionType implements Expression

type SliceIndex

type SliceIndex struct {
	AST   *ast.Index // the underlying syntax node this was built from
	Type  *Slice     // the slice type
	Slice Expression // the expression that returns the slice to be indexed
	Index Expression // the index to use on the slice
}

SliceIndex represents using the indexing operator on a slice type.

func (*SliceIndex) ExpressionType

func (i *SliceIndex) ExpressionType() Type

ExpressionType implements Expression. It returns the value type of the slice.

type SliceRange

type SliceRange struct {
	AST   *ast.Index // the underlying syntax node this was built from
	Type  *Slice     // the slice type
	Slice Expression // the expression that returns the slice to be indexed
	Range *BinaryOp  // the range to use on the slice
}

SliceRange represents using the indexing operator on a slice type with a range expression.

func (*SliceRange) ExpressionType

func (i *SliceRange) ExpressionType() Type

ExpressionType implements Expression. It returns the same slice type being sliced.

type Statement

type Statement interface {
	Node
	// contains filtered or unexported methods
}

Statement is the interface implemented by all statement types.

type Statements

type Statements []Statement

Statements is a list of statements.

func (*Statements) Append

func (l *Statements) Append(s Statement)

Append adds the statement s at the end of the list.

func (*Statements) InsertBefore

func (l *Statements) InsertBefore(s Statement, i int)

InsertBefore inserts the statement s before the i'th statement.

func (Statements) Last

func (l Statements) Last() Statement

Last returns the last statement in the list.

func (*Statements) Remove

func (l *Statements) Remove(s Statement)

Remove removes all occurances of s from the list of statements.

func (*Statements) Replace

func (l *Statements) Replace(first, count int, s ...Statement)

Replace replaces count statements starting from first with s.

type StaticArray

type StaticArray struct {
	Named                // the full type name
	ValueType Type       // the storage type of the elements
	Size      uint32     // the array size
	SizeExpr  Expression // the expression representing the array size
	// contains filtered or unexported fields
}

StaticArray represents a one-dimension fixed size array type, of the form T[8]

func (StaticArray) Member

func (StaticArray) Member(string) Owned

func (*StaticArray) Owner

func (o *StaticArray) Owner() Owner

func (StaticArray) SortMembers

func (StaticArray) SortMembers()

func (StaticArray) String

func (a StaticArray) String() string

func (StaticArray) VisitMembers

func (StaticArray) VisitMembers(func(Owned))

type StringValue

type StringValue string

StringValue is a string that implements Expression so it can be in the semantic graph

func (StringValue) ExpressionType

func (v StringValue) ExpressionType() Type

ExpressionType implements Expression with a type of StringType

type Switch

type Switch struct {
	AST     *ast.Switch // the underlying syntax node this was built from
	Value   Expression  // the value to match the cases against
	Cases   []*Case     // the set of case statements to choose from
	Default *Block      // the block to use if no condition matches
}

Switch represents a resolved ast.Switch statement.

type Symbols

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

Symbols is an object with named members and no other functionality.

func (*Symbols) Add

func (s *Symbols) Add(name string, entry Node)

Add inserts a node into the symbol space with the specified name.

func (*Symbols) AddNamed

func (s *Symbols) AddNamed(entry NamedNode)

AddNamed inserts a named node into the symbol space.

func (*Symbols) Find

func (s *Symbols) Find(name string) (Node, error)

func (*Symbols) FindAll

func (s *Symbols) FindAll(name string) []Node

func (*Symbols) Visit

func (s *Symbols) Visit(visitor func(string, Node))

type Type

type Type interface {
	Owner
	// contains filtered or unexported methods
}

Type is the interface to any object that can act as a type to the api language.

func Integer

func Integer(size int32) Type

Integer returns a signed integer type of the given size in bytes. size must be 1, 2, 4 or 8.

func TypeOf

func TypeOf(v Node) (Type, error)

TypeOf returns the resolved semantic type of the Type, Field or Expression.

func Underlying

func Underlying(ty Type) Type

Underlying returns the underlying type for ty by recursively traversing the pseudonym chain until reaching and returning the first non-pseudoym type. If ty is not a pseudonym then it is simply returned.

func UnsignedInteger

func UnsignedInteger(size int32) Type

UnsignedInteger returns an unsigned integer type of the given size in bytes. size must be 1, 2, 4 or 8.

type Uint16Value

type Uint16Value uint16

Uint16Value is a uint16 that implements Expression so it can be in the semantic graph

func (Uint16Value) ExpressionType

func (v Uint16Value) ExpressionType() Type

ExpressionType implements Expression with a type of Uint16Type

type Uint32Value

type Uint32Value uint32

Uint32Value is a uint32 that implements Expression so it can be in the semantic graph

func (Uint32Value) ExpressionType

func (v Uint32Value) ExpressionType() Type

ExpressionType implements Expression with a type of Uint32Type

type Uint64Value

type Uint64Value uint64

Uint64Value is a uint64 that implements Expression so it can be in the semantic graph

func (Uint64Value) ExpressionType

func (v Uint64Value) ExpressionType() Type

ExpressionType implements Expression with a type of Uint64Type

type Uint8Value

type Uint8Value uint8

Uint8Value is a uint8 that implements Expression so it can be in the semantic graph

func (Uint8Value) ExpressionType

func (v Uint8Value) ExpressionType() Type

ExpressionType implements Expression with a type of Uint8Type

type UnaryOp

type UnaryOp struct {
	AST        *ast.UnaryOp // the underlying syntax node this was built from
	Type       Type         // the resolved type of the operation
	Operator   string       // the operator being applied
	Expression Expression   // the expression to apply the operator to
}

UnaryOp represents an operator applied to a single expression. It's type depends on the operator and the type of the expression it is being applied to.

func (*UnaryOp) ExpressionType

func (b *UnaryOp) ExpressionType() Type

ExpressionType implements Expression

type Unknown

type Unknown struct {
	AST      *ast.Unknown // the underlying syntax node this was built from
	Inferred Expression   // the inferred expression to derive the unknown from the outputs
}

Unknown represents a value that cannot be predicted. These values are non-deterministic with regard to the API specification and may vary between implementations of the API.

func (*Unknown) ExpressionType

func (u *Unknown) ExpressionType() Type

ExpressionType implements Expression with the inferred type of the unknown. If the unknown could not be inferred, it will be of type "any" so allow expressions using it to resolve anyway.

type Write

type Write struct {
	AST   *ast.Call // the underlying syntax node this was built from
	Slice Expression
}

Write represents a call to write.

Directories

Path Synopsis
Package printer provides a human-readable printer for the semantic tree nodes.
Package printer provides a human-readable printer for the semantic tree nodes.

Jump to

Keyboard shortcuts

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