MCPcopy Create free account
hub / github.com/cel-expr/cel-cpp / FunctionDescriptor

Class FunctionDescriptor

common/function_descriptor.h:46–120  ·  view source on GitHub ↗

Coarsely describes a function for the purpose of runtime resolution of overloads.

Source from the content-addressed store, hash-verified

44// Coarsely describes a function for the purpose of runtime resolution of
45// overloads.
46class FunctionDescriptor final {
47 public:
48 FunctionDescriptor(absl::string_view name, bool receiver_style,
49 std::vector<Kind> types, bool is_strict)
50 : impl_(std::make_shared<Impl>(
51 name, std::move(types), receiver_style,
52 FunctionDescriptorOptions{is_strict,
53 /*is_contextual=*/false})) {}
54
55 FunctionDescriptor(absl::string_view name, bool receiver_style,
56 std::vector<Kind> types, bool is_strict,
57 bool is_contextual)
58 : impl_(std::make_shared<Impl>(
59 name, std::move(types), receiver_style,
60 FunctionDescriptorOptions{is_strict, is_contextual})) {}
61
62 FunctionDescriptor(absl::string_view name, bool is_receiver_style,
63 std::vector<Kind> types,
64 FunctionDescriptorOptions options = {})
65 : impl_(std::make_shared<Impl>(name, std::move(types), is_receiver_style,
66 options)) {}
67
68 // Function name.
69 const std::string& name() const { return impl_->name; }
70
71 // Whether function is receiver style i.e. true means arg0.name(args[1:]...).
72 bool receiver_style() const { return impl_->is_receiver_style; }
73
74 // The argument types the function accepts.
75 //
76 // TODO(uncreated-issue/17): make this kinds
77 const std::vector<Kind>& types() const { return impl_->types; }
78
79 // if true (strict, default), error or unknown arguments are propagated
80 // instead of calling the function. if false (non-strict), the function may
81 // receive error or unknown values as arguments.
82 bool is_strict() const { return impl_->options.is_strict; }
83
84 // Whether the function is contextual (impure).
85 //
86 // Contextual functions depend on state other than the arguments received in
87 // the CEL expression evaluation or have visible side effects. This breaks
88 // some of the assumptions of CEL. This flag is used as a hint to the planner
89 // that some optimizations are not safe or not effective.
90 bool is_contextual() const { return impl_->options.is_contextual; }
91
92 // Helper for matching a descriptor. This tests that the shape is the same --
93 // |other| accepts the same number and types of arguments and is the same call
94 // style).
95 bool ShapeMatches(const FunctionDescriptor& other) const {
96 return ShapeMatches(other.receiver_style(), other.types());
97 }
98 bool ShapeMatches(bool receiver_style, absl::Span<const Kind> types) const;
99
100 bool operator==(const FunctionDescriptor& other) const;
101
102 bool operator<(const FunctionDescriptor& other) const;
103

Callers 12

ASSERT_OK_AND_ASSIGNFunction · 0.85
EnableSelectOptimizationFunction · 0.85
MakeDescriptorMethod · 0.85
TESTFunction · 0.85
TESTFunction · 0.85
TEST_FFunction · 0.85
CreateDescriptorMethod · 0.85
CreateDescriptorMethod · 0.85
CreateDescriptorMethod · 0.85
CreateDescriptorMethod · 0.85
CreateDescriptorMethod · 0.85
CreateDescriptorMethod · 0.85

Calls

no outgoing calls

Tested by 5

ASSERT_OK_AND_ASSIGNFunction · 0.68
MakeDescriptorMethod · 0.68
TESTFunction · 0.68
TESTFunction · 0.68
TEST_FFunction · 0.68