decls

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2019 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package decls provides helpers for creating variable and function declarations.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Error type used to communicate issues during type-checking.
	Error = &exprpb.Type{
		TypeKind: &exprpb.Type_Error{
			Error: &emptypb.Empty{}}}

	// Dyn is a top-type used to represent any value.
	Dyn = &exprpb.Type{
		TypeKind: &exprpb.Type_Dyn{
			Dyn: &emptypb.Empty{}}}
)

Commonly used types.

Well-known types. TODO: Replace with an abstract type registry.

Functions

func NewAbstractType

func NewAbstractType(name string, paramTypes ...*exprpb.Type) *exprpb.Type

NewAbstractType creates an abstract type declaration which references a proto message name and may also include type parameters.

func NewFunction

func NewFunction(name string,
	overloads ...*exprpb.Decl_FunctionDecl_Overload) *exprpb.Decl

NewFunction creates a named function declaration with one or more overloads.

func NewFunctionType

func NewFunctionType(resultType *exprpb.Type,
	argTypes ...*exprpb.Type) *exprpb.Type

NewFunctionType creates a function invocation contract, typically only used by type-checking steps after overload resolution.

func NewIdent

func NewIdent(name string, t *exprpb.Type, v *exprpb.Constant) *exprpb.Decl

NewIdent creates a named identifier declaration with an optional literal value.

Literal values are typically only associated with enum identifiers.

func NewInstanceOverload

func NewInstanceOverload(id string, argTypes []*exprpb.Type,
	resultType *exprpb.Type) *exprpb.Decl_FunctionDecl_Overload

NewInstanceOverload creates a instance function overload contract. First element of argTypes is instance.

func NewListType

func NewListType(elem *exprpb.Type) *exprpb.Type

NewListType generates a new list with elements of a certain type.

func NewMapType

func NewMapType(key *exprpb.Type, value *exprpb.Type) *exprpb.Type

NewMapType generates a new map with typed keys and values.

func NewObjectType

func NewObjectType(typeName string) *exprpb.Type

NewObjectType creates an object type for a qualified type name.

func NewOverload

func NewOverload(id string, argTypes []*exprpb.Type,
	resultType *exprpb.Type) *exprpb.Decl_FunctionDecl_Overload

NewOverload creates a function overload declaration which contains a unique overload id as well as the expected argument and result types. Overloads must be aggregated within a Function declaration.

func NewParameterizedInstanceOverload

func NewParameterizedInstanceOverload(id string,
	argTypes []*exprpb.Type,
	resultType *exprpb.Type,
	typeParams []string) *exprpb.Decl_FunctionDecl_Overload

NewParameterizedInstanceOverload creates a parametric function instance overload type.

func NewParameterizedOverload

func NewParameterizedOverload(id string,
	argTypes []*exprpb.Type,
	resultType *exprpb.Type,
	typeParams []string) *exprpb.Decl_FunctionDecl_Overload

NewParameterizedOverload creates a parametric function overload type.

func NewPrimitiveType

func NewPrimitiveType(primitive exprpb.Type_PrimitiveType) *exprpb.Type

NewPrimitiveType creates a type for a primitive value. See the var declarations for Int, Uint, etc.

func NewTypeParamType

func NewTypeParamType(name string) *exprpb.Type

NewTypeParamType creates a type corresponding to a named, contextual parameter.

func NewTypeType

func NewTypeType(nested *exprpb.Type) *exprpb.Type

NewTypeType creates a new type designating a type.

func NewWellKnownType

func NewWellKnownType(wellKnown exprpb.Type_WellKnownType) *exprpb.Type

NewWellKnownType creates a type corresponding to a protobuf well-known type value.

func NewWrapperType

func NewWrapperType(wrapped *exprpb.Type) *exprpb.Type

NewWrapperType creates a wrapped primitive type instance. Wrapped types are roughly equivalent to a nullable, or optionally valued type.

Types

type Group

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

Group is a set of Decls that is pushed on or popped off a Scopes as a unit. Contains separate namespaces for idenifier and function Decls. (Should be named "Scope" perhaps?)

type Scopes

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

Scopes represents nested Decl sets where the Scopes value contains a Groups containing all identifiers in scope and an optional parent representing outer scopes. Each Groups value is a mapping of names to Decls in the ident and function namespaces. Lookups are performed such that bindings in inner scopes shadow those in outer scopes.

func NewScopes

func NewScopes() *Scopes

NewScopes creates a new, empty Scopes. Some operations can't be safely performed until a Group is added with Push.

func (*Scopes) AddFunction

func (s *Scopes) AddFunction(fn *exprpb.Decl)

AddFunction adds the function Decl to the current scope. Note: Any previous entry for a function in the current scope with the same name is overwritten.

func (*Scopes) AddIdent

func (s *Scopes) AddIdent(decl *exprpb.Decl)

AddIdent adds the ident Decl in the current scope. Note: If the name collides with an existing identifier in the scope, the Decl is overwritten.

func (*Scopes) FindFunction

func (s *Scopes) FindFunction(name string) *exprpb.Decl

FindFunction finds the first function Decl with a matching name in Scopes. The search is performed from innermost to outermost. Returns nil if no such function in Scopes.

func (*Scopes) FindIdent

func (s *Scopes) FindIdent(name string) *exprpb.Decl

FindIdent finds the first ident Decl with a matching name in Scopes, or nil if one cannot be found. Note: The search is performed from innermost to outermost.

func (*Scopes) FindIdentInScope

func (s *Scopes) FindIdentInScope(name string) *exprpb.Decl

FindIdentInScope finds the first ident Decl with a matching name in the current Scopes value, or nil if one does not exist. Note: The search is only performed on the current scope and does not search outer scopes.

func (*Scopes) Pop

func (s *Scopes) Pop() *Scopes

Pop returns the parent Scopes value for the current scope, or the current scope if the parent is nil.

func (*Scopes) Push

func (s *Scopes) Push() *Scopes

Push creates a new Scopes value which references the current Scope as its parent.

Jump to

Keyboard shortcuts

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