Coverage Report

Created: 2026-11-12 06:42

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/proc/self/cwd/common/values/unknown_value.h
Line
Count
Source
1
// Copyright 2024 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
// IWYU pragma: private, include "common/value.h"
16
// IWYU pragma: friend "common/value.h"
17
18
#ifndef THIRD_PARTY_CEL_CPP_COMMON_VALUES_UNKNOWN_VALUE_H_
19
#define THIRD_PARTY_CEL_CPP_COMMON_VALUES_UNKNOWN_VALUE_H_
20
21
#include <ostream>
22
#include <string>
23
24
#include "absl/base/attributes.h"
25
#include "absl/base/nullability.h"
26
#include "absl/status/status.h"
27
#include "absl/strings/string_view.h"
28
#include "base/attribute_set.h"
29
#include "common/internal/unknowns.h"
30
#include "common/type.h"
31
#include "common/unknown.h"
32
#include "common/value_kind.h"
33
#include "common/values/values.h"
34
#include "google/protobuf/arena.h"
35
#include "google/protobuf/descriptor.h"
36
#include "google/protobuf/io/zero_copy_stream.h"
37
#include "google/protobuf/message.h"
38
39
namespace cel {
40
41
class Value;
42
class UnknownValue;
43
44
namespace common_internal {
45
[[nodiscard]]
46
UnknownValue MakeUnknownValue(const Unknown& value,
47
                              google::protobuf::Arena* absl_nonnull arena);
48
[[nodiscard]]
49
UnknownValue MakeUnknownValue(
50
    const common_internal::UnknownRoot* root,
51
    const common_internal::UnknownAttributeSet* attributes,
52
    const common_internal::UnknownFunctionSet* functions);
53
[[nodiscard]]
54
Unknown ToUnknown(const UnknownValue& value);
55
using UnknownValueRep = UnknownSet;
56
[[nodiscard]]
57
UnknownValue MakeUnknownValue(const UnknownValueRep& rep);
58
[[nodiscard]]
59
const UnknownValueRep& GetUnknownValueRep(
60
    const UnknownValue& value ABSL_ATTRIBUTE_LIFETIME_BOUND);
61
[[nodiscard]]
62
UnknownValueRep& GetUnknownValueRep(
63
    UnknownValue& value ABSL_ATTRIBUTE_LIFETIME_BOUND);
64
}  // namespace common_internal
65
66
// `UnknownValue` represents matches to unknown attribute patterns encountered
67
// during evaluation.
68
class UnknownValue final : private common_internal::ValueMixin<UnknownValue> {
69
 public:
70
  static constexpr ValueKind kKind = ValueKind::kUnknown;
71
72
  // There is currently no supported way for clients create "well-formed"
73
  // unknown values, only the evaluator may create them. The reasons for this
74
  // are performance and correctness, by hiding the internal representation we
75
  // can easily change it as necessary. If it became absolutely necessary due to
76
  // an appropriate use case, we can introduce a way for clients to create them
77
  // as well without exposing the internal implementation details.
78
0
  UnknownValue() = default;
79
  UnknownValue(const UnknownValue&) = default;
80
  UnknownValue(UnknownValue&&) = default;
81
  UnknownValue& operator=(const UnknownValue&) = default;
82
  UnknownValue& operator=(UnknownValue&&) = default;
83
84
0
  constexpr ValueKind kind() const { return kKind; }
85
86
0
  absl::string_view GetTypeName() const { return UnknownType::kName; }
87
88
0
  std::string DebugString() const { return ""; }
89
90
  // See Value::SerializeTo().
91
  absl::Status SerializeTo(
92
      const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,
93
      google::protobuf::MessageFactory* absl_nonnull message_factory,
94
      google::protobuf::io::ZeroCopyOutputStream* absl_nonnull output) const;
95
96
  // See Value::ConvertToJson().
97
  absl::Status ConvertToJson(
98
      const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,
99
      google::protobuf::MessageFactory* absl_nonnull message_factory,
100
      google::protobuf::Message* absl_nonnull json) const;
101
102
  absl::Status Equal(const Value& other,
103
                     const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,
104
                     google::protobuf::MessageFactory* absl_nonnull message_factory,
105
                     google::protobuf::Arena* absl_nonnull arena,
106
                     Value* absl_nonnull result) const;
107
  using ValueMixin::Equal;
108
109
0
  bool IsZeroValue() const { return false; }
110
111
  [[nodiscard]]
112
  AttributeSet ToAttributeSet() const;
113
114
  [[nodiscard]]
115
  FunctionResultSet ToFunctionResultSet() const;
116
117
 private:
118
  friend UnknownValue common_internal::MakeUnknownValue(
119
      const common_internal::UnknownRoot* root,
120
      const common_internal::UnknownAttributeSet* attributes,
121
      const common_internal::UnknownFunctionSet* functions);
122
  friend Unknown common_internal::ToUnknown(const UnknownValue& value);
123
  friend const common_internal::UnknownValueRep&
124
  common_internal::GetUnknownValueRep(const UnknownValue& value);
125
  friend common_internal::UnknownValueRep& common_internal::GetUnknownValueRep(
126
      UnknownValue& value);
127
  friend UnknownValue common_internal::MakeUnknownValue(
128
      const common_internal::UnknownValueRep& rep);
129
  friend class common_internal::ValueMixin<UnknownValue>;
130
131
  UnknownValue(const common_internal::UnknownRoot* root,
132
               const common_internal::UnknownAttributeSet* attributes,
133
               const common_internal::UnknownFunctionSet* functions)
134
0
      : rep_{root, attributes, functions} {}
135
136
  explicit UnknownValue(const common_internal::UnknownValueRep& rep)
137
0
      : rep_(rep) {}
138
139
  common_internal::UnknownValueRep rep_;
140
};
141
142
0
inline std::ostream& operator<<(std::ostream& out, const UnknownValue& value) {
143
0
  return out << value.DebugString();
144
0
}
145
146
namespace common_internal {
147
148
const FunctionResultSet& GetEmptyFunctionResults();
149
150
[[nodiscard]]
151
inline UnknownValue MakeUnknownValue(
152
    const common_internal::UnknownRoot* root,
153
    const common_internal::UnknownAttributeSet* attributes,
154
0
    const common_internal::UnknownFunctionSet* functions) {
155
0
  return UnknownValue(root, attributes, functions);
156
0
}
157
158
[[nodiscard]]
159
0
inline Unknown ToUnknown(const UnknownValue& value) {
160
0
  return Unknown(value.ToAttributeSet(), value.ToFunctionResultSet());
161
0
}
162
163
[[nodiscard]]
164
0
inline UnknownValue MakeUnknownValue(const UnknownValueRep& rep) {
165
0
  return UnknownValue(rep);
166
0
}
167
168
[[nodiscard]]
169
inline const UnknownValueRep& GetUnknownValueRep(
170
0
    const UnknownValue& value ABSL_ATTRIBUTE_LIFETIME_BOUND) {
171
0
  return value.rep_;
172
0
}
173
174
[[nodiscard]]
175
inline UnknownValueRep& GetUnknownValueRep(
176
0
    UnknownValue& value ABSL_ATTRIBUTE_LIFETIME_BOUND) {
177
0
  return value.rep_;
178
0
}
179
180
}  // namespace common_internal
181
182
}  // namespace cel
183
184
#endif  // THIRD_PARTY_CEL_CPP_COMMON_VALUES_UNKNOWN_VALUE_H_