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