/proc/self/cwd/runtime/activation_interface.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_RUNTIME_ACTIVATION_INTERFACE_H_ |
16 | | #define THIRD_PARTY_CEL_CPP_RUNTIME_ACTIVATION_INTERFACE_H_ |
17 | | |
18 | | #include <vector> |
19 | | |
20 | | #include "absl/base/nullability.h" |
21 | | #include "absl/status/statusor.h" |
22 | | #include "absl/strings/string_view.h" |
23 | | #include "absl/types/optional.h" |
24 | | #include "absl/types/span.h" |
25 | | #include "base/attribute.h" |
26 | | #include "common/value.h" |
27 | | #include "internal/status_macros.h" |
28 | | #include "runtime/function_overload_reference.h" |
29 | | #include "runtime/internal/attribute_matcher.h" |
30 | | #include "google/protobuf/arena.h" |
31 | | #include "google/protobuf/descriptor.h" |
32 | | #include "google/protobuf/message.h" |
33 | | |
34 | | namespace cel { |
35 | | |
36 | | namespace runtime_internal { |
37 | | class ActivationAttributeMatcherAccess; |
38 | | } // namespace runtime_internal |
39 | | |
40 | | // Interface for providing runtime with variable lookups. |
41 | | // |
42 | | // Clients should prefer to use one of the concrete implementations provided by |
43 | | // the CEL library rather than implementing this interface directly. |
44 | | // TODO(uncreated-issue/40): After finalizing, make this public and add instructions |
45 | | // for clients to migrate. |
46 | | class ActivationInterface { |
47 | | public: |
48 | 9.92k | virtual ~ActivationInterface() = default; |
49 | | |
50 | | // Find value for a string (possibly qualified) variable name. |
51 | | virtual absl::StatusOr<bool> FindVariable( |
52 | | absl::string_view name, |
53 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, |
54 | | google::protobuf::MessageFactory* absl_nonnull message_factory, |
55 | | google::protobuf::Arena* absl_nonnull arena, Value* absl_nonnull result) const = 0; |
56 | | absl::StatusOr<absl::optional<Value>> FindVariable( |
57 | | absl::string_view name, |
58 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, |
59 | | google::protobuf::MessageFactory* absl_nonnull message_factory, |
60 | 0 | google::protobuf::Arena* absl_nonnull arena) const { |
61 | 0 | Value result; |
62 | 0 | CEL_ASSIGN_OR_RETURN( |
63 | 0 | auto found, |
64 | 0 | FindVariable(name, descriptor_pool, message_factory, arena, &result)); |
65 | 0 | if (found) { |
66 | 0 | return result; |
67 | 0 | } |
68 | 0 | return absl::nullopt; |
69 | 0 | } |
70 | | |
71 | | // Find a set of context function overloads by name. |
72 | | virtual std::vector<FunctionOverloadReference> FindFunctionOverloads( |
73 | | absl::string_view name) const = 0; |
74 | | |
75 | | // Return a list of unknown attribute patterns. |
76 | | // |
77 | | // If an attribute (select path) encountered during evaluation matches any of |
78 | | // the patterns, the value will be treated as unknown and propagated in an |
79 | | // unknown set. |
80 | | // |
81 | | // The returned span must remain valid for the duration of any evaluation |
82 | | // using this this activation. |
83 | | virtual absl::Span<const cel::AttributePattern> GetUnknownAttributes() |
84 | | const = 0; |
85 | | |
86 | | // Return a list of missing attribute patterns. |
87 | | // |
88 | | // If an attribute (select path) encountered during evaluation matches any of |
89 | | // the patterns, the value will be treated as missing and propagated as an |
90 | | // error. |
91 | | // |
92 | | // The returned span must remain valid for the duration of any evaluation |
93 | | // using this activation. |
94 | | virtual absl::Span<const cel::AttributePattern> GetMissingAttributes() |
95 | | const = 0; |
96 | | |
97 | | private: |
98 | | friend class runtime_internal::ActivationAttributeMatcherAccess; |
99 | | |
100 | | // Returns the attribute matcher for this activation. |
101 | | virtual const runtime_internal::AttributeMatcher* absl_nullable |
102 | 0 | GetAttributeMatcher() const { |
103 | 0 | return nullptr; |
104 | 0 | } |
105 | | }; |
106 | | |
107 | | } // namespace cel |
108 | | |
109 | | #endif // THIRD_PARTY_CEL_CPP_RUNTIME_ACTIVATION_INTERFACE_H_ |