checker
packageThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
Documentation¶
Overview¶
Package checker defines functions to type-checked a parsed expressionagainst a set of identifier and function declarations.
Index¶
- func Check(parsed *ast.AST, source common.Source, env *Env) (*ast.AST, *common.Errors)
- func FormatCELType(t any) string
- func FormatCheckedType(t *exprpb.Type) string
- func Print(e ast.Expr, checked *ast.AST) string
- type AstNode
- type CallEstimate
- type CostEstimate
- type CostEstimator
- type CostOption
- type Env
- type FunctionEstimator
- type Group
- type Option
- type Scopes
- func (s *Scopes) AddIdent(decl *decls.VariableDecl)
- func (s *Scopes) Copy() *Scopes
- func (s *Scopes) FindFunction(name string) *decls.FunctionDecl
- func (s *Scopes) FindIdent(name string) *decls.VariableDecl
- func (s *Scopes) FindIdentInScope(name string) *decls.VariableDecl
- func (s *Scopes) Pop() *Scopes
- func (s *Scopes) Push() *Scopes
- func (s *Scopes) SetFunction(fn *decls.FunctionDecl)
- type SizeEstimate
- func (se SizeEstimate) Add(sizeEstimate SizeEstimate) SizeEstimate
- func (se SizeEstimate) Multiply(sizeEstimate SizeEstimate) SizeEstimate
- func (se SizeEstimate) MultiplyByCost(cost CostEstimate) CostEstimate
- func (se SizeEstimate) MultiplyByCostFactor(costPerUnit float64) CostEstimate
- func (se SizeEstimate) Union(size SizeEstimate) SizeEstimate
Constants¶
This section is empty.
Variables¶
This section is empty.
Functions¶
funcCheck¶
Check performs type checking, giving a typed AST.
The input is a parsed AST and an env which encapsulates type binding of variables,declarations of built-in functions, descriptions of protocol buffers, and a registry forerrors.
Returns a type-checked AST, which might not be usable if there are errors in the errorregistry.
funcFormatCELType¶added inv0.17.0
FormatCELType formats a types.Type value to a string representation.
The type formatting is identical to FormatCheckedType.
funcFormatCheckedType¶
FormatCheckedType converts a type message into a string representation.
Types¶
typeAstNode¶added inv0.10.0
type AstNode interface {// Path returns a field path through the provided type declarations to the type of the AstNode, or nil if the AstNode does not// represent type directly reachable from the provided type declarations.// The first path element is a variable. All subsequent path elements are one of: field name, '@items', '@keys', '@values'.Path() []string// Type returns the deduced type of the AstNode.Type() *types.Type// Expr returns the expression of the AstNode.Expr()ast.Expr// ComputedSize returns a size estimate of the AstNode derived from information available in the CEL expression.// For constants and inline list and map declarations, the exact size is returned. For concatenated list, strings// and bytes, the size is derived from the size estimates of the operands. nil is returned if there is no// computed size available.ComputedSize() *SizeEstimate}AstNode represents an AST node for the purpose of cost estimations.
typeCallEstimate¶added inv0.10.0
type CallEstimate struct {CostEstimateResultSize *SizeEstimate}CallEstimate includes a CostEstimate for the call, and an optional estimate of the result object size.The ResultSize should only be provided if the call results in a map, list, string or bytes.
typeCostEstimate¶added inv0.10.0
type CostEstimate struct {Min, Maxuint64}CostEstimate represents an estimated cost range and provides add and multiply operationsthat do not overflow.
funcCost¶added inv0.10.0
func Cost(checked *ast.AST, estimatorCostEstimator, opts ...CostOption) (CostEstimate,error)
Cost estimates the cost of the parsed and type checked CEL expression.
funcFixedCostEstimate¶added inv0.23.0
func FixedCostEstimate(costuint64)CostEstimate
FixedCostEstimate returns a cost with a fixed min and max range.
funcUnknownCostEstimate¶added inv0.23.0
func UnknownCostEstimate()CostEstimate
UnknownCostEstimate returns a cost with an unknown impact.
func (CostEstimate)Add¶added inv0.10.0
func (ceCostEstimate) Add(costCostEstimate)CostEstimate
Add adds the costs and returns the sum.If add would result in an uint64 overflow for the min or max, the value is set to math.MaxUint64.
func (CostEstimate)Multiply¶added inv0.10.0
func (ceCostEstimate) Multiply(costCostEstimate)CostEstimate
Multiply multiplies by the cost and returns the product.If multiply would result in an uint64 overflow, the result is math.MaxUint64.
func (CostEstimate)MultiplyByCostFactor¶added inv0.10.0
func (ceCostEstimate) MultiplyByCostFactor(costPerUnitfloat64)CostEstimate
MultiplyByCostFactor multiplies a CostEstimate by a cost factor and returns the CostEstimate with thenearest integer of the result, rounded up.
func (CostEstimate)Union¶added inv0.10.0
func (ceCostEstimate) Union(sizeCostEstimate)CostEstimate
Union returns a CostEstimate that encompasses both input the CostEstimates.
typeCostEstimator¶added inv0.10.0
type CostEstimator interface {// EstimateSize returns a SizeEstimate for the given AstNode, or nil if the estimator has no// estimate to provide.//// The size is equivalent to the result of the CEL `size()` function:// * Number of unicode characters in a string// * Number of bytes in a sequence// * Number of map entries or number of list items.//// EstimateSize is only called for AstNodes where CEL does not know the size; EstimateSize is not// called for values defined inline in CEL where the size is already obvious to CEL.EstimateSize(elementAstNode) *SizeEstimate// EstimateCallCost returns the estimated cost of an invocation, or nil if the estimator has no// estimate to provide.EstimateCallCost(function, overloadIDstring, target *AstNode, args []AstNode) *CallEstimate}CostEstimator estimates the sizes of variable length input data and the costs of functions.
typeCostOption¶added inv0.16.0
type CostOption func(*coster)error
CostOption configures flags which affect cost computations.
funcOverloadCostEstimate¶added inv0.17.7
func OverloadCostEstimate(overloadIDstring, functionCosterFunctionEstimator)CostOption
OverloadCostEstimate binds a FunctionCoster to a specific function overload ID.
When a OverloadCostEstimate is provided, it will override the cost calculation of the CostEstimator provided tothe Cost() call.
funcPresenceTestHasCost¶added inv0.16.0
func PresenceTestHasCost(hasCostbool)CostOption
PresenceTestHasCost determines whether presence testing has a cost of one or zero.
Defaults to presence test has a cost of one.
typeEnv¶
type Env struct {// contains filtered or unexported fields}Env is the environment for type checking.
The Env is comprised of a container, type provider, declarations, and other related objectswhich can be used to assist with type-checking.
func (*Env)AddFunctions¶added inv0.17.0
func (e *Env) AddFunctions(declarations ...*decls.FunctionDecl)error
AddFunctions configures the checker with a list of function declarations.
If there are overlapping declarations, the method will error.
func (*Env)AddIdents¶added inv0.17.0
func (e *Env) AddIdents(declarations ...*decls.VariableDecl)error
AddIdents configures the checker with a list of variable declarations.
If there are overlapping declarations, the method will error.
func (*Env)LookupFunction¶
func (e *Env) LookupFunction(namestring) *decls.FunctionDecl
LookupFunction returns a Decl proto for typeName as a function in env.Returns nil if no such function is found in env.
func (*Env)LookupIdent¶
func (e *Env) LookupIdent(namestring) *decls.VariableDecl
LookupIdent returns a Decl proto for typeName as an identifier in the Env.Returns nil if no such identifier is found in the Env.
typeFunctionEstimator¶added inv0.17.7
type FunctionEstimator func(estimatorCostEstimator, target *AstNode, args []AstNode) *CallEstimate
FunctionEstimator provides a CallEstimate given the target and arguments for a specific function, overload pair.
typeGroup¶added inv0.17.0
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 identifier and function Decls.(Should be named "Scope" perhaps?)
typeOption¶added inv0.10.0
type Option func(*options)error
Option is a functional option for configuring the type-checker
funcCrossTypeNumericComparisons¶added inv0.10.0
CrossTypeNumericComparisons toggles type-checker support for numeric comparisons across typeSeehttps://github.com/google/cel-spec/wiki/proposal-210 for more details.
funcValidatedDeclarations¶added inv0.11.1
ValidatedDeclarations provides a references to validated declarations which will be copiedinto new checker instances.
typeScopes¶added inv0.17.0
type Scopes struct {// contains filtered or unexported fields}Scopes represents nested Decl sets where the Scopes value contains a Groups containing allidentifiers 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 (*Scopes)AddIdent¶added inv0.17.0
func (s *Scopes) AddIdent(decl *decls.VariableDecl)
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)Copy¶added inv0.17.0
Copy creates a copy of the current Scopes values, including a copy of its parent if non-nil.
func (*Scopes)FindFunction¶added inv0.17.0
func (s *Scopes) FindFunction(namestring) *decls.FunctionDecl
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¶added inv0.17.0
func (s *Scopes) FindIdent(namestring) *decls.VariableDecl
FindIdent finds the first ident Decl with a matching name in Scopes, or nil if one cannot befound.Note: The search is performed from innermost to outermost.
func (*Scopes)FindIdentInScope¶added inv0.17.0
func (s *Scopes) FindIdentInScope(namestring) *decls.VariableDecl
FindIdentInScope finds the first ident Decl with a matching name in the current Scopes value, ornil if one does not exist.Note: The search is only performed on the current scope and does not search outer scopes.
func (*Scopes)Pop¶added inv0.17.0
Pop returns the parent Scopes value for the current scope, or the current scope if the parentis nil.
func (*Scopes)Push¶added inv0.17.0
Push creates a new Scopes value which references the current Scope as its parent.
func (*Scopes)SetFunction¶added inv0.17.0
func (s *Scopes) SetFunction(fn *decls.FunctionDecl)
SetFunction 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.
typeSizeEstimate¶added inv0.10.0
type SizeEstimate struct {Min, Maxuint64}SizeEstimate represents an estimated size of a variable length string, bytes, map or list.
funcFixedSizeEstimate¶added inv0.23.0
func FixedSizeEstimate(sizeuint64)SizeEstimate
FixedSizeEstimate returns a size estimate with a fixed min and max range.
funcUnknownSizeEstimate¶added inv0.23.0
func UnknownSizeEstimate()SizeEstimate
UnknownSizeEstimate returns a size between 0 and max uint
func (SizeEstimate)Add¶added inv0.10.0
func (seSizeEstimate) Add(sizeEstimateSizeEstimate)SizeEstimate
Add adds to another SizeEstimate and returns the sum.If add would result in an uint64 overflow, the result is math.MaxUint64.
func (SizeEstimate)Multiply¶added inv0.10.0
func (seSizeEstimate) Multiply(sizeEstimateSizeEstimate)SizeEstimate
Multiply multiplies by another SizeEstimate and returns the product.If multiply would result in an uint64 overflow, the result is math.MaxUint64.
func (SizeEstimate)MultiplyByCost¶added inv0.10.0
func (seSizeEstimate) MultiplyByCost(costCostEstimate)CostEstimate
MultiplyByCost multiplies by the cost and returns the product.If multiply would result in an uint64 overflow, the result is math.MaxUint64.
func (SizeEstimate)MultiplyByCostFactor¶added inv0.10.0
func (seSizeEstimate) MultiplyByCostFactor(costPerUnitfloat64)CostEstimate
MultiplyByCostFactor multiplies a SizeEstimate by a cost factor and returns the CostEstimate with thenearest integer of the result, rounded up.
func (SizeEstimate)Union¶added inv0.10.0
func (seSizeEstimate) Union(sizeSizeEstimate)SizeEstimate
Union returns a SizeEstimate that encompasses both input the SizeEstimate.