Coverage Report

Created: 2026-05-27 07:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/proc/self/cwd/eval/public/cel_function.h
Line
Count
Source
1
#ifndef THIRD_PARTY_CEL_CPP_EVAL_PUBLIC_CEL_FUNCTION_H_
2
#define THIRD_PARTY_CEL_CPP_EVAL_PUBLIC_CEL_FUNCTION_H_
3
4
#include <utility>
5
6
#include "absl/status/status.h"
7
#include "absl/status/statusor.h"
8
#include "absl/types/span.h"
9
#include "common/function_descriptor.h"
10
#include "common/value.h"
11
#include "eval/public/cel_value.h"
12
#include "runtime/function.h"
13
#include "google/protobuf/arena.h"
14
15
namespace google::api::expr::runtime {
16
17
// Type that describes CelFunction.
18
// This complex structure is needed for overloads support.
19
using CelFunctionDescriptor = ::cel::FunctionDescriptor;
20
21
// CelFunction is a handler that represents single
22
// CEL function.
23
// CelFunction provides Evaluate() method, that performs
24
// evaluation of the function. CelFunction instances provide
25
// descriptors that contain function information:
26
// - name
27
// - is function receiver style (e.f(g) vs f(e,g))
28
// - amount of arguments and their types.
29
// Function overloads are resolved based on their arguments and
30
// receiver style.
31
class CelFunction : public ::cel::Function {
32
 public:
33
  // Build CelFunction from descriptor
34
  explicit CelFunction(CelFunctionDescriptor descriptor)
35
0
      : descriptor_(std::move(descriptor)) {}
36
37
  // Non-copyable
38
  CelFunction(const CelFunction& other) = delete;
39
  CelFunction& operator=(const CelFunction& other) = delete;
40
41
  ~CelFunction() override = default;
42
43
  // Evaluates CelValue based on arguments supplied.
44
  // If result content is to be allocated (e.g. string concatenation),
45
  // arena parameter must be used as allocation manager.
46
  // Provides resulting value in *result, returns evaluation success/failure.
47
  // Methods should discriminate between internal evaluator errors, that
48
  // makes further evaluation impossible or unreasonable (example - argument
49
  // type or number mismatch) and business logic errors (example division by
50
  // zero). When former happens, error Status is returned and *result is
51
  // not changed. In case of business logic error, returned Status is Ok, and
52
  // error is provided as CelValue - wrapped CelError in *result.
53
  virtual absl::Status Evaluate(absl::Span<const CelValue> arguments,
54
                                CelValue* result,
55
                                google::protobuf::Arena* arena) const = 0;
56
57
  // Determines whether instance of CelFunction is applicable to
58
  // arguments supplied.
59
  // Method is called during runtime.
60
  bool MatchArguments(absl::Span<const CelValue> arguments) const;
61
62
  bool MatchArguments(absl::Span<const cel::Value> arguments) const;
63
64
  // Implements cel::Function.
65
  using cel::Function::Invoke;
66
67
  absl::StatusOr<cel::Value> Invoke(
68
      absl::Span<const cel::Value> arguments,
69
      const cel::Function::InvokeContext& context) const final;
70
71
  // CelFunction descriptor
72
0
  const CelFunctionDescriptor& descriptor() const { return descriptor_; }
73
74
 private:
75
  CelFunctionDescriptor descriptor_;
76
};
77
78
}  // namespace google::api::expr::runtime
79
80
#endif  // THIRD_PARTY_CEL_CPP_EVAL_PUBLIC_CEL_FUNCTION_H_