Coverage Report

Created: 2026-10-09 06:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/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.h"
24
#include "runtime/function_registry.h"
25
#include "runtime/internal/errors.h"
26
#include "runtime/register_function_helper.h"
27
#include "runtime/runtime_options.h"
28
29
namespace cel {
30
namespace {
31
32
using ::cel::runtime_internal::CreateNoMatchingOverloadError;
33
34
Value NotStrictlyFalseImpl(const Value& value,
35
0
                           const Function::InvokeContext& context) {
36
0
  if (value.IsBool()) {
37
0
    return value;
38
0
  }
39
40
0
  if (value.IsError() || value.IsUnknown()) {
41
0
    return TrueValue();
42
0
  }
43
44
  // Should only accept bool unknown or error.
45
0
  return ErrorValue::From(
46
0
      CreateNoMatchingOverloadError(builtin::kNotStrictlyFalse),
47
0
      context.arena());
48
0
}
49
50
}  // namespace
51
52
absl::Status RegisterLogicalFunctions(FunctionRegistry& registry,
53
22.7k
                                      const RuntimeOptions& options) {
54
  // logical NOT
55
22.7k
  CEL_RETURN_IF_ERROR(
56
22.7k
      (RegisterHelper<UnaryFunctionAdapter<bool, bool>>::RegisterGlobalOverload(
57
22.7k
          builtin::kNot, [](bool value) -> bool { return !value; }, registry)));
58
59
  // Strictness
60
22.7k
  using StrictnessHelper = RegisterHelper<UnaryFunctionAdapter<Value, Value>>;
61
22.7k
  CEL_RETURN_IF_ERROR(StrictnessHelper::RegisterNonStrictOverload(
62
22.7k
      builtin::kNotStrictlyFalse, &NotStrictlyFalseImpl, registry));
63
64
22.7k
  CEL_RETURN_IF_ERROR(StrictnessHelper::RegisterNonStrictOverload(
65
22.7k
      builtin::kNotStrictlyFalseDeprecated, &NotStrictlyFalseImpl, registry));
66
67
22.7k
  return absl::OkStatus();
68
22.7k
}
69
70
}  // namespace cel