/proc/self/cwd/runtime/standard/logical_functions.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 "runtime/standard/logical_functions.h" |
16 | | |
17 | | #include "absl/status/status.h" |
18 | | #include "absl/strings/string_view.h" |
19 | | #include "base/builtins.h" |
20 | | #include "base/function_adapter.h" |
21 | | #include "common/value.h" |
22 | | #include "internal/status_macros.h" |
23 | | #include "runtime/function_registry.h" |
24 | | #include "runtime/internal/errors.h" |
25 | | #include "runtime/register_function_helper.h" |
26 | | #include "runtime/runtime_options.h" |
27 | | |
28 | | namespace cel { |
29 | | namespace { |
30 | | |
31 | | using ::cel::runtime_internal::CreateNoMatchingOverloadError; |
32 | | |
33 | 0 | Value NotStrictlyFalseImpl(const Value& value) { |
34 | 0 | if (value.IsBool()) { |
35 | 0 | return value; |
36 | 0 | } |
37 | | |
38 | 0 | if (value.IsError() || value.IsUnknown()) { |
39 | 0 | return TrueValue(); |
40 | 0 | } |
41 | | |
42 | | // Should only accept bool unknown or error. |
43 | 0 | return ErrorValue(CreateNoMatchingOverloadError(builtin::kNotStrictlyFalse)); |
44 | 0 | } |
45 | | |
46 | | } // namespace |
47 | | |
48 | | absl::Status RegisterLogicalFunctions(FunctionRegistry& registry, |
49 | 14.5k | const RuntimeOptions& options) { |
50 | | // logical NOT |
51 | 14.5k | CEL_RETURN_IF_ERROR( |
52 | 14.5k | (RegisterHelper<UnaryFunctionAdapter<bool, bool>>::RegisterGlobalOverload( |
53 | 14.5k | builtin::kNot, [](bool value) -> bool { return !value; }, registry))); |
54 | | |
55 | | // Strictness |
56 | 14.5k | using StrictnessHelper = RegisterHelper<UnaryFunctionAdapter<Value, Value>>; |
57 | 14.5k | CEL_RETURN_IF_ERROR(StrictnessHelper::RegisterNonStrictOverload( |
58 | 14.5k | builtin::kNotStrictlyFalse, &NotStrictlyFalseImpl, registry)); |
59 | | |
60 | 14.5k | CEL_RETURN_IF_ERROR(StrictnessHelper::RegisterNonStrictOverload( |
61 | 14.5k | builtin::kNotStrictlyFalseDeprecated, &NotStrictlyFalseImpl, registry)); |
62 | | |
63 | 14.5k | return absl::OkStatus(); |
64 | 14.5k | } |
65 | | |
66 | | } // namespace cel |