Coverage Report

Created: 2026-05-27 07:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/proc/self/cwd/base/function_result.h
Line
Count
Source
1
// Copyright 2022 Google LLC
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     https://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
#ifndef THIRD_PARTY_CEL_CPP_BASE_FUNCTION_RESULT_H_
16
#define THIRD_PARTY_CEL_CPP_BASE_FUNCTION_RESULT_H_
17
18
#include <cstdint>
19
#include <utility>
20
21
#include "base/function_descriptor.h"
22
23
namespace cel {
24
25
// Represents a function result that is unknown at the time of execution. This
26
// allows for lazy evaluation of expensive functions.
27
class FunctionResult final {
28
 public:
29
  FunctionResult() = delete;
30
0
  FunctionResult(const FunctionResult&) = default;
31
0
  FunctionResult(FunctionResult&&) = default;
32
  FunctionResult& operator=(const FunctionResult&) = default;
33
  FunctionResult& operator=(FunctionResult&&) = default;
34
35
  FunctionResult(FunctionDescriptor descriptor, int64_t expr_id)
36
0
      : descriptor_(std::move(descriptor)), expr_id_(expr_id) {}
37
38
  // The descriptor of the called function that return Unknown.
39
0
  const FunctionDescriptor& descriptor() const { return descriptor_; }
40
41
  // The id of the |Expr| that triggered the function call step. Provided
42
  // informationally -- if two different |Expr|s generate the same unknown call,
43
  // they will be treated as the same unknown function result.
44
0
  int64_t call_expr_id() const { return expr_id_; }
45
46
  // Equality operator provided for testing. Compatible with set less-than
47
  // comparator.
48
  // Compares descriptor then arguments elementwise.
49
0
  bool IsEqualTo(const FunctionResult& other) const {
50
0
    return descriptor() == other.descriptor();
51
0
  }
52
53
  // TODO(uncreated-issue/5): re-implement argument capture
54
55
 private:
56
  FunctionDescriptor descriptor_;
57
  int64_t expr_id_;
58
};
59
60
0
inline bool operator==(const FunctionResult& lhs, const FunctionResult& rhs) {
61
0
  return lhs.IsEqualTo(rhs);
62
0
}
63
64
0
inline bool operator<(const FunctionResult& lhs, const FunctionResult& rhs) {
65
0
  return lhs.descriptor() < rhs.descriptor();
66
0
}
67
68
}  // namespace cel
69
70
#endif  // THIRD_PARTY_CEL_CPP_BASE_FUNCTION_RESULT_H_