MCPcopy Create free account
hub / github.com/cel-expr/cel-go / SubsetFunction

Method SubsetFunction

common/env/env.go:583–624  ·  view source on GitHub ↗

SubsetFunction produces a function declaration which matches the supported subset, or nil if the function is not supported by the LibrarySubset. For IncludeFunctions, if the function does not specify a set of overloads to include, the whole function definition is included. If overloads are set, the

(fn *decls.FunctionDecl)

Source from the content-addressed store, hash-verified

581// whole function definition is excluded. If overloads are set, then a new function which
582// includes only the permitted overloads is produced.
583func (lib *LibrarySubset) SubsetFunction(fn *decls.FunctionDecl) (*decls.FunctionDecl, bool) {
584 // When lib is null, it should indicate that all values are included in the subset.
585 if lib == nil {
586 return fn, true
587 }
588 if lib.Disabled {
589 return nil, false
590 }
591 if len(lib.IncludeFunctions) != 0 {
592 for _, include := range lib.IncludeFunctions {
593 if include.Name != fn.Name() {
594 continue
595 }
596 if len(include.Overloads) == 0 {
597 return fn, true
598 }
599 overloadIDs := make([]string, len(include.Overloads))
600 for i, o := range include.Overloads {
601 overloadIDs[i] = o.ID
602 }
603 return fn.Subset(decls.IncludeOverloads(overloadIDs...)), true
604 }
605 return nil, false
606 }
607 if len(lib.ExcludeFunctions) != 0 {
608 for _, exclude := range lib.ExcludeFunctions {
609 if exclude.Name != fn.Name() {
610 continue
611 }
612 if len(exclude.Overloads) == 0 {
613 return nil, false
614 }
615 overloadIDs := make([]string, len(exclude.Overloads))
616 for i, o := range exclude.Overloads {
617 overloadIDs[i] = o.ID
618 }
619 return fn.Subset(decls.ExcludeOverloads(overloadIDs...)), true
620 }
621 return fn, true
622 }
623 return fn, true
624}
625
626// SubsetMacro indicates whether the macro function should be included in the library subset.
627func (lib *LibrarySubset) SubsetMacro(macroFunction string) bool {

Callers 2

CompileOptionsMethod · 0.80
TestSubsetFunctionFunction · 0.80

Calls 4

IncludeOverloadsFunction · 0.92
ExcludeOverloadsFunction · 0.92
SubsetMethod · 0.80
NameMethod · 0.65

Tested by 1

TestSubsetFunctionFunction · 0.64