Movatterモバイル変換


[0]ホーム

URL:


decls

package
v0.26.1Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2025 License:Apache-2.0, BSD-3-ClauseImports:9Imported by:21

Details

Repository

github.com/google/cel-go

Links

Documentation

Overview

Package decls contains function and variable declaration structs and helper methods.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

funcFunctionDeclToExprDecl

func FunctionDeclToExprDecl(f *FunctionDecl) (*exprpb.Decl,error)

FunctionDeclToExprDecl converts a go-native function declaration into a protobuf-typed function declaration.

funcMaybeNoSuchOverload

func MaybeNoSuchOverload(funcNamestring, args ...ref.Val)ref.Val

MaybeNoSuchOverload determines whether to propagate an error if one is provided as an argument, orto return an unknown set, or to produce a new error for a missing function signature.

funcVariableDeclToExprDecl

func VariableDeclToExprDecl(v *VariableDecl) (*exprpb.Decl,error)

VariableDeclToExprDecl converts a go-native variable declaration into a protobuf-type variable declaration.

Types

typeFunctionDecl

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

FunctionDecl defines a function name, overload set, and optionally a singleton definition for alloverload instances.

funcNewFunction

func NewFunction(namestring, opts ...FunctionOpt) (*FunctionDecl,error)

NewFunction creates a new function declaration with a set of function options to configure overloadsand function definitions (implementations).

Functions are checked for name collisions and singleton redefinition.

func (*FunctionDecl)AddOverload

func (f *FunctionDecl) AddOverload(overload *OverloadDecl)error

AddOverload ensures that the new overload does not collide with an existing overload signature;however, if the function signatures are identical, the implementation may be rewritten as itsdifficult to compare functions by object identity.

func (*FunctionDecl)Bindings

func (f *FunctionDecl) Bindings() ([]*functions.Overload,error)

Bindings produces a set of function bindings, if any are defined.

func (*FunctionDecl)Descriptionadded inv0.25.0

func (f *FunctionDecl) Description()string

Description provides an overview of the function's purpose.

Usage examples should be included on specific overloads.

func (*FunctionDecl)Documentationadded inv0.25.0

func (f *FunctionDecl) Documentation() *common.Doc

Documentation generates documentation about the Function and its overloads as a common.Doc object.

func (*FunctionDecl)HasLateBindingadded inv0.25.0

func (f *FunctionDecl) HasLateBinding()bool

HasLateBinding returns true if the function has late bindings. A function cannot mix late bindings with other bindings.

func (*FunctionDecl)IsDeclarationDisabled

func (f *FunctionDecl) IsDeclarationDisabled()bool

IsDeclarationDisabled indicates that the function implementation should be added to the dispatcher, but thedeclaration should not be exposed for use in expressions.

func (*FunctionDecl)Merge

func (f *FunctionDecl) Merge(other *FunctionDecl) (*FunctionDecl,error)

Merge combines an existing function declaration with another.

If a function is extended, by say adding new overloads to an existing function, then it is merged with theprior definition of the function at which point its overloads must not collide with pre-existing overloadsand its bindings (singleton, or per-overload) must not conflict with previous definitions either.

func (*FunctionDecl)Name

func (f *FunctionDecl) Name()string

Name returns the function name in human-readable terms, e.g. 'contains' of 'math.least'

func (*FunctionDecl)OverloadDecls

func (f *FunctionDecl) OverloadDecls() []*OverloadDecl

OverloadDecls returns the overload declarations in the order in which they were declared.

func (*FunctionDecl)Subsetadded inv0.24.0

func (f *FunctionDecl) Subset(selectorOverloadSelector) *FunctionDecl

Subset returns a new function declaration which contains only the overloads with the specified IDs.If the subset function contains no overloads, then nil is returned to indicate the function is notfunctional.

typeFunctionOpt

type FunctionOpt func(*FunctionDecl) (*FunctionDecl,error)

FunctionOpt defines a functional option for mutating a function declaration.

funcDisableDeclaration

func DisableDeclaration(valuebool)FunctionOpt

DisableDeclaration indicates that the function declaration should be disabled, but the runtime functionbinding should be provided. Marking a function as runtime-only is a safe way to manage deprecationsof function declarations while still preserving the runtime behavior for previously compiled expressions.

funcDisableTypeGuards

func DisableTypeGuards(valuebool)FunctionOpt

DisableTypeGuards disables automatically generated function invocation guards on direct overload calls.Type guards remain on during dynamic dispatch for parsed-only expressions.

funcFunctionDocsadded inv0.25.0

func FunctionDocs(docs ...string)FunctionOpt

FunctionDocs configures documentation from a list of strings separated by newlines.

funcMemberOverload

func MemberOverload(overloadIDstring,args []*types.Type, resultType *types.Type,opts ...OverloadOpt)FunctionOpt

MemberOverload defines a new receiver-style overload (or member function) with an overload id, argument types,and result type. Through the use of OverloadOpt options, the overload may also be configured with a binding,an operand trait, and to be non-strict.

Note: function bindings should be commonly configured with Overload instances whereas operand traits andstrict-ness should be rare occurrences.

funcOverload

func Overload(overloadIDstring,args []*types.Type, resultType *types.Type,opts ...OverloadOpt)FunctionOpt

Overload defines a new global overload with an overload id, argument types, and result type. Through theuse of OverloadOpt options, the overload may also be configured with a binding, an operand trait, and tobe non-strict.

Note: function bindings should be commonly configured with Overload instances whereas operand traits andstrict-ness should be rare occurrences.

funcSingletonBinaryBinding

func SingletonBinaryBinding(fnfunctions.BinaryOp, traits ...int)FunctionOpt

SingletonBinaryBinding creates a singleton function definition to be used with all function overloads.

Note, this approach works well if operand is expected to have a specific trait which it implements,e.g. traits.ContainerType. Otherwise, prefer per-overload function bindings.

funcSingletonFunctionBinding

func SingletonFunctionBinding(fnfunctions.FunctionOp, traits ...int)FunctionOpt

SingletonFunctionBinding creates a singleton function definition to be used with all function overloads.

Note, this approach works well if operand is expected to have a specific trait which it implements,e.g. traits.ContainerType. Otherwise, prefer per-overload function bindings.

funcSingletonUnaryBinding

func SingletonUnaryBinding(fnfunctions.UnaryOp, traits ...int)FunctionOpt

SingletonUnaryBinding creates a singleton function definition to be used for all function overloads.

Note, this approach works well if operand is expected to have a specific trait which it implements,e.g. traits.ContainerType. Otherwise, prefer per-overload function bindings.

typeFunctionSubsetteradded inv0.24.0

type FunctionSubsetter func(fn *FunctionDecl) (*FunctionDecl,bool)

FunctionSubsetter subsets a function declaration or returns nil and false if the functionsubset was empty.

typeOverloadDecl

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

OverloadDecl contains the definition of a single overload id with a specific signature, and an optionalimplementation.

func (*OverloadDecl)ArgTypes

func (o *OverloadDecl) ArgTypes() []*types.Type

ArgTypes contains the set of argument types expected by the overload.

For member functions ArgTypes[0] represents the member operand type.

func (*OverloadDecl)Examplesadded inv0.25.0

func (o *OverloadDecl) Examples() []string

Examples returns a list of string examples for the overload.

func (*OverloadDecl)HasLateBindingadded inv0.25.0

func (o *OverloadDecl) HasLateBinding()bool

HasLateBinding returns whether the overload has a binding which is not known at compile time.

func (*OverloadDecl)ID

func (o *OverloadDecl) ID()string

ID mirrors the overload signature and provides a unique id which may be referenced within the type-checkerand interpreter to optimize performance.

The ID format is usually one of two styles:global: <functionName>_<argType>_<argTypeN>member: <memberType>_<functionName>_<argType>_<argTypeN>

func (*OverloadDecl)IsMemberFunction

func (o *OverloadDecl) IsMemberFunction()bool

IsMemberFunction indicates whether the overload is a member function

func (*OverloadDecl)IsNonStrict

func (o *OverloadDecl) IsNonStrict()bool

IsNonStrict returns whether the overload accepts errors and unknown values as arguments.

func (*OverloadDecl)OperandTrait

func (o *OverloadDecl) OperandTrait()int

OperandTrait returns the trait mask of the first operand to the overload call, e.g.`traits.Indexer`

func (*OverloadDecl)ResultType

func (o *OverloadDecl) ResultType() *types.Type

ResultType indicates the output type from calling the function.

func (*OverloadDecl)SignatureEquals

func (o *OverloadDecl) SignatureEquals(other *OverloadDecl)bool

SignatureEquals determines whether the incoming overload declaration signature is equal to the current signature.

Result type, operand trait, and strict-ness are not considered as part of signature equality.

func (*OverloadDecl)SignatureOverlaps

func (o *OverloadDecl) SignatureOverlaps(other *OverloadDecl)bool

SignatureOverlaps indicates whether two functions have non-equal, but overloapping function signatures.

For example, list(dyn) collides with list(string) since the 'dyn' type can contain a 'string' type.

func (*OverloadDecl)TypeParams

func (o *OverloadDecl) TypeParams() []string

TypeParams returns the type parameter names associated with the overload.

typeOverloadOpt

type OverloadOpt func(*OverloadDecl) (*OverloadDecl,error)

OverloadOpt is a functional option for configuring a function overload.

funcBinaryBinding

func BinaryBinding(bindingfunctions.BinaryOp)OverloadOpt

BinaryBinding provides the implementation of a binary overload. The provided function is protected by a runtimetype-guard which ensures runtime type agreement between the overload signature and runtime argument types.

funcFunctionBinding

func FunctionBinding(bindingfunctions.FunctionOp)OverloadOpt

FunctionBinding provides the implementation of a variadic overload. The provided function is protected by a runtimetype-guard which ensures runtime type agreement between the overload signature and runtime argument types.

funcLateFunctionBindingadded inv0.25.0

func LateFunctionBinding()OverloadOpt

LateFunctionBinding indicates that the function has a binding which is not known at compile time.This is useful for functions which have side-effects or are not deterministically computable.

funcOverloadExamplesadded inv0.25.0

func OverloadExamples(examples ...string)OverloadOpt

OverloadExamples configures example expressions for the overload.

funcOverloadIsNonStrict

func OverloadIsNonStrict()OverloadOpt

OverloadIsNonStrict enables the function to be called with error and unknown argument values.

Note: do not use this option unless absoluately necessary as it should be an uncommon feature.

funcOverloadOperandTrait

func OverloadOperandTrait(traitint)OverloadOpt

OverloadOperandTrait configures a set of traits which the first argument to the overload must implement in order to besuccessfully invoked.

funcUnaryBinding

func UnaryBinding(bindingfunctions.UnaryOp)OverloadOpt

UnaryBinding provides the implementation of a unary overload. The provided function is protected by a runtimetype-guard which ensures runtime type agreement between the overload signature and runtime argument types.

typeOverloadSelectoradded inv0.24.0

type OverloadSelector func(overload *OverloadDecl)bool

OverloadSelector selects an overload associated with a given function when it returns true.

Used in combination with the Subset method.

funcExcludeOverloadsadded inv0.24.0

func ExcludeOverloads(overloadIDs ...string)OverloadSelector

ExcludeOverloads defines an OverloadSelector which deny-lists a set of overloads by their ids.

funcIncludeOverloadsadded inv0.24.0

func IncludeOverloads(overloadIDs ...string)OverloadSelector

IncludeOverloads defines an OverloadSelector which allow-lists a set of overloads by their ids.

typeVariableDecl

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

VariableDecl defines a variable declaration which may optionally have a constant value.

funcNewConstant

func NewConstant(namestring, t *types.Type, vref.Val) *VariableDecl

NewConstant creates a new constant declaration.

funcNewVariable

func NewVariable(namestring, t *types.Type) *VariableDecl

NewVariable creates a new variable declaration.

funcNewVariableWithDocadded inv0.25.0

func NewVariableWithDoc(namestring, t *types.Type, docstring) *VariableDecl

NewVariableWithDoc creates a new variable declaration with usage documentation.

funcTypeVariable

func TypeVariable(t *types.Type) *VariableDecl

TypeVariable creates a new type identifier for use within a types.Provider

func (*VariableDecl)DeclarationIsEquivalent

func (v *VariableDecl) DeclarationIsEquivalent(other *VariableDecl)bool

DeclarationIsEquivalent returns true if one variable declaration has the same name and same type as the input.

func (*VariableDecl)Descriptionadded inv0.25.0

func (v *VariableDecl) Description()string

Description returns the usage documentation for the variable, if set.

Good usage instructions provide information about the valid formats, ranges, sizes for the variable type.

func (*VariableDecl)Documentationadded inv0.25.0

func (v *VariableDecl) Documentation() *common.Doc

Documentation returns name, type, and description for the variable.

func (*VariableDecl)Name

func (v *VariableDecl) Name()string

Name returns the fully-qualified variable name

func (*VariableDecl)Type

func (v *VariableDecl) Type() *types.Type

Type returns the types.Type value associated with the variable.

func (*VariableDecl)Value

func (v *VariableDecl) Value()ref.Val

Value returns the constant value associated with the declaration.

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp