/proc/self/cwd/eval/internal/adapter_activation_impl.cc
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 | | #include "eval/internal/adapter_activation_impl.h" |
16 | | |
17 | | #include <vector> |
18 | | |
19 | | #include "absl/base/nullability.h" |
20 | | #include "absl/status/statusor.h" |
21 | | #include "absl/strings/string_view.h" |
22 | | #include "absl/types/optional.h" |
23 | | #include "common/value.h" |
24 | | #include "eval/internal/interop.h" |
25 | | #include "eval/public/cel_value.h" |
26 | | #include "internal/status_macros.h" |
27 | | #include "runtime/function_overload_reference.h" |
28 | | #include "runtime/internal/activation_attribute_matcher_access.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::interop_internal { |
35 | | |
36 | | using ::google::api::expr::runtime::CelFunction; |
37 | | |
38 | | absl::StatusOr<bool> AdapterActivationImpl::FindVariable( |
39 | | absl::string_view name, |
40 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, |
41 | | google::protobuf::MessageFactory* absl_nonnull message_factory, |
42 | 55.1k | google::protobuf::Arena* absl_nonnull arena, Value* absl_nonnull result) const { |
43 | | // This implementation should only be used during interop, when we can |
44 | | // always assume the memory manager is backed by a protobuf arena. |
45 | | |
46 | 55.1k | absl::optional<google::api::expr::runtime::CelValue> legacy_value = |
47 | 55.1k | legacy_activation_.FindValue(name, arena); |
48 | 55.1k | if (!legacy_value.has_value()) { |
49 | 55.1k | return false; |
50 | 55.1k | } |
51 | 55.1k | CEL_RETURN_IF_ERROR(ModernValue(arena, *legacy_value, *result)); |
52 | 0 | return true; |
53 | 0 | } |
54 | | |
55 | | std::vector<FunctionOverloadReference> |
56 | | AdapterActivationImpl::FindFunctionOverloads(absl::string_view name) const |
57 | 0 | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
58 | 0 | std::vector<const CelFunction*> legacy_candidates = |
59 | 0 | legacy_activation_.FindFunctionOverloads(name); |
60 | 0 | std::vector<FunctionOverloadReference> result; |
61 | 0 | result.reserve(legacy_candidates.size()); |
62 | 0 | for (const auto* candidate : legacy_candidates) { |
63 | 0 | if (candidate == nullptr) { |
64 | 0 | continue; |
65 | 0 | } |
66 | 0 | result.push_back({candidate->descriptor(), *candidate}); |
67 | 0 | } |
68 | 0 | return result; |
69 | 0 | } |
70 | | |
71 | | absl::Span<const AttributePattern> AdapterActivationImpl::GetUnknownAttributes() |
72 | 9.92k | const { |
73 | 9.92k | return legacy_activation_.unknown_attribute_patterns(); |
74 | 9.92k | } |
75 | | |
76 | | absl::Span<const AttributePattern> AdapterActivationImpl::GetMissingAttributes() |
77 | 9.92k | const { |
78 | 9.92k | return legacy_activation_.missing_attribute_patterns(); |
79 | 9.92k | } |
80 | | |
81 | | const runtime_internal::AttributeMatcher* absl_nullable |
82 | 0 | AdapterActivationImpl::GetAttributeMatcher() const { |
83 | 0 | return runtime_internal::ActivationAttributeMatcherAccess:: |
84 | 0 | GetAttributeMatcher(legacy_activation_); |
85 | 0 | } |
86 | | |
87 | | } // namespace cel::interop_internal |