/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 "google/protobuf/arena.h" |
29 | | #include "google/protobuf/descriptor.h" |
30 | | #include "google/protobuf/message.h" |
31 | | |
32 | | namespace cel::interop_internal { |
33 | | |
34 | | using ::google::api::expr::runtime::CelFunction; |
35 | | |
36 | | absl::StatusOr<bool> AdapterActivationImpl::FindVariable( |
37 | | absl::string_view name, |
38 | | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, |
39 | | google::protobuf::MessageFactory* absl_nonnull message_factory, |
40 | 47.2k | google::protobuf::Arena* absl_nonnull arena, Value* absl_nonnull result) const { |
41 | | // This implementation should only be used during interop, when we can |
42 | | // always assume the memory manager is backed by a protobuf arena. |
43 | | |
44 | 47.2k | absl::optional<google::api::expr::runtime::CelValue> legacy_value = |
45 | 47.2k | legacy_activation_.FindValue(name, arena); |
46 | 47.2k | if (!legacy_value.has_value()) { |
47 | 47.2k | return false; |
48 | 47.2k | } |
49 | 0 | CEL_RETURN_IF_ERROR(ModernValue(arena, *legacy_value, *result)); |
50 | 0 | return true; |
51 | 0 | } |
52 | | |
53 | | std::vector<FunctionOverloadReference> |
54 | | AdapterActivationImpl::FindFunctionOverloads(absl::string_view name) const |
55 | 0 | ABSL_ATTRIBUTE_LIFETIME_BOUND { |
56 | 0 | std::vector<const CelFunction*> legacy_candidates = |
57 | 0 | legacy_activation_.FindFunctionOverloads(name); |
58 | 0 | std::vector<FunctionOverloadReference> result; |
59 | 0 | result.reserve(legacy_candidates.size()); |
60 | 0 | for (const auto* candidate : legacy_candidates) { |
61 | 0 | if (candidate == nullptr) { |
62 | 0 | continue; |
63 | 0 | } |
64 | 0 | result.push_back({candidate->descriptor(), *candidate}); |
65 | 0 | } |
66 | 0 | return result; |
67 | 0 | } |
68 | | |
69 | | } // namespace cel::interop_internal |