Coverage Report

Created: 2026-05-27 07:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/proc/self/cwd/internal/status_macros.h
Line
Count
Source
1
// Copyright 2021 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_INTERNAL_STATUS_MACROS_H_
16
#define THIRD_PARTY_CEL_CPP_INTERNAL_STATUS_MACROS_H_
17
18
#include <utility>
19
20
#include "absl/base/optimization.h"
21
#include "absl/status/status.h"
22
#include "internal/status_builder.h"
23
24
#define CEL_RETURN_IF_ERROR(expr)                                            \
25
17.6M
  CEL_INTERNAL_STATUS_MACROS_IMPL_ELSE_BLOCKER_                              \
26
17.6M
  if (::cel::internal::StatusAdaptor cel_internal_status_macro = {(expr)}) { \
arithmetic_functions.cc:cel::RegisterArithmeticFunctions(cel::FunctionRegistry&, cel::RuntimeOptions const&)::$_0::operator()(long) const
Line
Count
Source
26
696
  if (::cel::internal::StatusAdaptor cel_internal_status_macro = {(expr)}) { \
Unexecuted instantiation: equality_functions.cc:cel::(anonymous namespace)::RegisterNullMessageEqualityFunctions(cel::FunctionRegistry&)::$_0::operator()(cel::StructValue const&, cel::NullValue const&) const
Unexecuted instantiation: equality_functions.cc:cel::(anonymous namespace)::RegisterNullMessageEqualityFunctions(cel::FunctionRegistry&)::$_1::operator()(cel::NullValue const&, cel::StructValue const&) const
Unexecuted instantiation: equality_functions.cc:cel::(anonymous namespace)::RegisterNullMessageEqualityFunctions(cel::FunctionRegistry&)::$_2::operator()(cel::StructValue const&, cel::NullValue const&) const
Unexecuted instantiation: logical_functions.cc:cel::RegisterLogicalFunctions(cel::FunctionRegistry&, cel::RuntimeOptions const&)::$_0::operator()(bool) const
Unexecuted instantiation: time_functions.cc:cel::(anonymous namespace)::RegisterTimestampFunctions(cel::FunctionRegistry&, cel::RuntimeOptions const&)::$_0::operator()(absl::lts_20260107::Time, cel::StringValue const&) const
Unexecuted instantiation: time_functions.cc:cel::(anonymous namespace)::RegisterTimestampFunctions(cel::FunctionRegistry&, cel::RuntimeOptions const&)::$_1::operator()(absl::lts_20260107::Time) const
Unexecuted instantiation: time_functions.cc:cel::(anonymous namespace)::RegisterTimestampFunctions(cel::FunctionRegistry&, cel::RuntimeOptions const&)::$_2::operator()(absl::lts_20260107::Time, cel::StringValue const&) const
Unexecuted instantiation: time_functions.cc:cel::(anonymous namespace)::RegisterTimestampFunctions(cel::FunctionRegistry&, cel::RuntimeOptions const&)::$_3::operator()(absl::lts_20260107::Time) const
Unexecuted instantiation: time_functions.cc:cel::(anonymous namespace)::RegisterTimestampFunctions(cel::FunctionRegistry&, cel::RuntimeOptions const&)::$_4::operator()(absl::lts_20260107::Time, cel::StringValue const&) const
Unexecuted instantiation: time_functions.cc:cel::(anonymous namespace)::RegisterTimestampFunctions(cel::FunctionRegistry&, cel::RuntimeOptions const&)::$_5::operator()(absl::lts_20260107::Time) const
Unexecuted instantiation: time_functions.cc:cel::(anonymous namespace)::RegisterTimestampFunctions(cel::FunctionRegistry&, cel::RuntimeOptions const&)::$_6::operator()(absl::lts_20260107::Time, cel::StringValue const&) const
Unexecuted instantiation: time_functions.cc:cel::(anonymous namespace)::RegisterTimestampFunctions(cel::FunctionRegistry&, cel::RuntimeOptions const&)::$_7::operator()(absl::lts_20260107::Time) const
Unexecuted instantiation: time_functions.cc:cel::(anonymous namespace)::RegisterTimestampFunctions(cel::FunctionRegistry&, cel::RuntimeOptions const&)::$_8::operator()(absl::lts_20260107::Time, cel::StringValue const&) const
Unexecuted instantiation: time_functions.cc:cel::(anonymous namespace)::RegisterTimestampFunctions(cel::FunctionRegistry&, cel::RuntimeOptions const&)::$_9::operator()(absl::lts_20260107::Time) const
Unexecuted instantiation: time_functions.cc:cel::(anonymous namespace)::RegisterTimestampFunctions(cel::FunctionRegistry&, cel::RuntimeOptions const&)::$_10::operator()(absl::lts_20260107::Time, cel::StringValue const&) const
Unexecuted instantiation: time_functions.cc:cel::(anonymous namespace)::RegisterTimestampFunctions(cel::FunctionRegistry&, cel::RuntimeOptions const&)::$_11::operator()(absl::lts_20260107::Time) const
Unexecuted instantiation: time_functions.cc:cel::(anonymous namespace)::RegisterTimestampFunctions(cel::FunctionRegistry&, cel::RuntimeOptions const&)::$_12::operator()(absl::lts_20260107::Time, cel::StringValue const&) const
Unexecuted instantiation: time_functions.cc:cel::(anonymous namespace)::RegisterTimestampFunctions(cel::FunctionRegistry&, cel::RuntimeOptions const&)::$_13::operator()(absl::lts_20260107::Time) const
Unexecuted instantiation: time_functions.cc:cel::(anonymous namespace)::RegisterTimestampFunctions(cel::FunctionRegistry&, cel::RuntimeOptions const&)::$_14::operator()(absl::lts_20260107::Time, cel::StringValue const&) const
Unexecuted instantiation: time_functions.cc:cel::(anonymous namespace)::RegisterTimestampFunctions(cel::FunctionRegistry&, cel::RuntimeOptions const&)::$_15::operator()(absl::lts_20260107::Time) const
Unexecuted instantiation: time_functions.cc:cel::(anonymous namespace)::RegisterTimestampFunctions(cel::FunctionRegistry&, cel::RuntimeOptions const&)::$_16::operator()(absl::lts_20260107::Time, cel::StringValue const&) const
Unexecuted instantiation: time_functions.cc:cel::(anonymous namespace)::RegisterTimestampFunctions(cel::FunctionRegistry&, cel::RuntimeOptions const&)::$_17::operator()(absl::lts_20260107::Time) const
Unexecuted instantiation: time_functions.cc:cel::(anonymous namespace)::RegisterTimestampFunctions(cel::FunctionRegistry&, cel::RuntimeOptions const&)::$_18::operator()(absl::lts_20260107::Time, cel::StringValue const&) const
Unexecuted instantiation: time_functions.cc:cel::(anonymous namespace)::RegisterDurationFunctions(cel::FunctionRegistry&)::$_0::operator()(absl::lts_20260107::Duration) const
Unexecuted instantiation: time_functions.cc:cel::(anonymous namespace)::RegisterDurationFunctions(cel::FunctionRegistry&)::$_1::operator()(absl::lts_20260107::Duration) const
Unexecuted instantiation: time_functions.cc:cel::(anonymous namespace)::RegisterDurationFunctions(cel::FunctionRegistry&)::$_2::operator()(absl::lts_20260107::Duration) const
Unexecuted instantiation: time_functions.cc:cel::(anonymous namespace)::RegisterCheckedTimeArithmeticFunctions(cel::FunctionRegistry&)::$_0::operator()(absl::lts_20260107::Time, absl::lts_20260107::Duration) const
Unexecuted instantiation: time_functions.cc:cel::(anonymous namespace)::RegisterCheckedTimeArithmeticFunctions(cel::FunctionRegistry&)::$_1::operator()(absl::lts_20260107::Duration, absl::lts_20260107::Time) const
Unexecuted instantiation: time_functions.cc:cel::(anonymous namespace)::RegisterCheckedTimeArithmeticFunctions(cel::FunctionRegistry&)::$_2::operator()(absl::lts_20260107::Duration, absl::lts_20260107::Duration) const
Unexecuted instantiation: time_functions.cc:cel::(anonymous namespace)::RegisterCheckedTimeArithmeticFunctions(cel::FunctionRegistry&)::$_3::operator()(absl::lts_20260107::Time, absl::lts_20260107::Duration) const
Unexecuted instantiation: time_functions.cc:cel::(anonymous namespace)::RegisterCheckedTimeArithmeticFunctions(cel::FunctionRegistry&)::$_4::operator()(absl::lts_20260107::Time, absl::lts_20260107::Time) const
Unexecuted instantiation: time_functions.cc:cel::(anonymous namespace)::RegisterCheckedTimeArithmeticFunctions(cel::FunctionRegistry&)::$_5::operator()(absl::lts_20260107::Duration, absl::lts_20260107::Duration) const
time_functions.cc:cel::(anonymous namespace)::RegisterUncheckedTimeArithmeticFunctions(cel::FunctionRegistry&)::$_0::operator()(absl::lts_20260107::Time, absl::lts_20260107::Duration) const
Line
Count
Source
26
1
  if (::cel::internal::StatusAdaptor cel_internal_status_macro = {(expr)}) { \
Unexecuted instantiation: time_functions.cc:cel::(anonymous namespace)::RegisterUncheckedTimeArithmeticFunctions(cel::FunctionRegistry&)::$_1::operator()(absl::lts_20260107::Duration, absl::lts_20260107::Time) const
time_functions.cc:cel::(anonymous namespace)::RegisterUncheckedTimeArithmeticFunctions(cel::FunctionRegistry&)::$_2::operator()(absl::lts_20260107::Duration, absl::lts_20260107::Duration) const
Line
Count
Source
26
1
  if (::cel::internal::StatusAdaptor cel_internal_status_macro = {(expr)}) { \
Unexecuted instantiation: time_functions.cc:cel::(anonymous namespace)::RegisterUncheckedTimeArithmeticFunctions(cel::FunctionRegistry&)::$_3::operator()(absl::lts_20260107::Time, absl::lts_20260107::Duration) const
Unexecuted instantiation: time_functions.cc:cel::(anonymous namespace)::RegisterUncheckedTimeArithmeticFunctions(cel::FunctionRegistry&)::$_4::operator()(absl::lts_20260107::Time, absl::lts_20260107::Time) const
time_functions.cc:cel::(anonymous namespace)::RegisterUncheckedTimeArithmeticFunctions(cel::FunctionRegistry&)::$_5::operator()(absl::lts_20260107::Duration, absl::lts_20260107::Duration) const
Line
Count
Source
26
1
  if (::cel::internal::StatusAdaptor cel_internal_status_macro = {(expr)}) { \
Unexecuted instantiation: type_conversion_functions.cc:cel::(anonymous namespace)::RegisterTimeConversionFunctions(cel::FunctionRegistry&, cel::RuntimeOptions const&)::$_0::operator()(long) const
Unexecuted instantiation: type_conversion_functions.cc:cel::(anonymous namespace)::RegisterTimeConversionFunctions(cel::FunctionRegistry&, cel::RuntimeOptions const&)::$_1::operator()(absl::lts_20260107::Time) const
Unexecuted instantiation: type_conversion_functions.cc:cel::(anonymous namespace)::RegisterTimeConversionFunctions(cel::FunctionRegistry&, cel::RuntimeOptions const&)::$_2::operator()(absl::lts_20260107::Duration) const
custom_list_value.cc:cel::CustomListValueInterface::Contains(cel::Value const&, google::protobuf::DescriptorPool const*, google::protobuf::MessageFactory*, google::protobuf::Arena*, cel::Value*) const::$_0::operator()(unsigned long, cel::Value const&) const
Line
Count
Source
26
102k
  if (::cel::internal::StatusAdaptor cel_internal_status_macro = {(expr)}) { \
Unexecuted instantiation: custom_list_value.cc:cel::CustomListValue::Contains(cel::Value const&, google::protobuf::DescriptorPool const*, google::protobuf::MessageFactory*, google::protobuf::Arena*, cel::Value*) const::$_0::operator()(unsigned long, cel::Value const&) const
Unexecuted instantiation: struct_value.cc:cel::common_internal::StructValueEqual(cel::StructValue const&, cel::StructValue const&, google::protobuf::DescriptorPool const*, google::protobuf::MessageFactory*, google::protobuf::Arena*, cel::Value*)::$_0::operator()(std::__1::basic_string_view<char, std::__1::char_traits<char> >, cel::Value const&) const
Unexecuted instantiation: struct_value.cc:cel::common_internal::StructValueEqual(cel::StructValue const&, cel::StructValue const&, google::protobuf::DescriptorPool const*, google::protobuf::MessageFactory*, google::protobuf::Arena*, cel::Value*)::$_1::operator()(std::__1::basic_string_view<char, std::__1::char_traits<char> >, cel::Value const&) const
Unexecuted instantiation: struct_value.cc:cel::common_internal::StructValueEqual(cel::CustomStructValueInterface const&, cel::StructValue const&, google::protobuf::DescriptorPool const*, google::protobuf::MessageFactory*, google::protobuf::Arena*, cel::Value*)::$_0::operator()(std::__1::basic_string_view<char, std::__1::char_traits<char> >, cel::Value const&) const
Unexecuted instantiation: struct_value.cc:cel::common_internal::StructValueEqual(cel::CustomStructValueInterface const&, cel::StructValue const&, google::protobuf::DescriptorPool const*, google::protobuf::MessageFactory*, google::protobuf::Arena*, cel::Value*)::$_1::operator()(std::__1::basic_string_view<char, std::__1::char_traits<char> >, cel::Value const&) const
Unexecuted instantiation: struct_value_builder.cc:cel::common_internal::(anonymous namespace)::MessageValueBuilderImpl::SetRepeatedField(google::protobuf::FieldDescriptor const*, cel::Value)::{lambda(cel::Value const&)#1}::operator()(cel::Value const&) const
Unexecuted instantiation: value_builder.cc:cel::common_internal::MakeCompatListValue(cel::CustomListValue const&, google::protobuf::DescriptorPool const*, google::protobuf::MessageFactory*, google::protobuf::Arena*)::$_0::operator()(cel::Value const&) const
Unexecuted instantiation: value_builder.cc:cel::common_internal::MakeCompatMapValue(cel::CustomMapValue const&, google::protobuf::DescriptorPool const*, google::protobuf::MessageFactory*, google::protobuf::Arena*)::$_0::operator()(cel::Value const&, cel::Value const&) const
27
7.61M
  } else /* NOLINT */                                                        \
28
17.6M
    return cel_internal_status_macro.Consume()
29
30
// The GNU compiler historically emitted warnings for obscure usages of
31
// `if (foo) if (bar) {} else`. This suppresses that.
32
33
// clang-format off
34
#define CEL_INTERNAL_STATUS_MACROS_IMPL_ELSE_BLOCKER_ \
35
15.2M
  switch (0) case 0: default: /* NOLINT */
36
// clang-format on
37
38
#define CEL_ASSIGN_OR_RETURN(...)                                   \
39
1.23M
  CEL_INTERNAL_STATUS_MACROS_GET_VARIADIC_(                         \
40
1.23M
      (__VA_ARGS__, CEL_INTERNAL_STATUS_MACROS_ASSIGN_OR_RETURN_3_, \
41
1.23M
       CEL_INTERNAL_STATUS_MACROS_ASSIGN_OR_RETURN_2_))             \
42
1.23M
  (__VA_ARGS__)
43
44
// The following are macro magic to select either the 2 arg variant or 3 arg
45
// variant of CEL_ASSIGN_OR_RETURN.
46
47
#define CEL_INTERNAL_STATUS_MACROS_GET_VARIADIC_HELPER_(_1, _2, _3, NAME, ...) \
48
1.23M
  NAME
49
#define CEL_INTERNAL_STATUS_MACROS_GET_VARIADIC_(args) \
50
1.23M
  CEL_INTERNAL_STATUS_MACROS_GET_VARIADIC_HELPER_ args
51
52
#define CEL_INTERNAL_STATUS_MACROS_ASSIGN_OR_RETURN_2_(lhs, rexpr)        \
53
1.25M
  CEL_INTERNAL_STATUS_MACROS_ASSIGN_OR_RETURN_(                           \
54
1.23M
      CEL_INTERNAL_STATUS_MACROS_CONCAT(_status_or_value, __LINE__), lhs, \
55
1.23M
      rexpr,                                                              \
56
1.23M
      return absl::Status(std::move(CEL_INTERNAL_STATUS_MACROS_CONCAT(    \
57
1.23M
                                        _status_or_value, __LINE__))      \
58
1.23M
                              .status()))
59
60
#define CEL_INTERNAL_STATUS_MACROS_ASSIGN_OR_RETURN_3_(lhs, rexpr,           \
61
                                                       error_expression)     \
62
3.86k
  CEL_INTERNAL_STATUS_MACROS_ASSIGN_OR_RETURN_(                              \
63
3.86k
      CEL_INTERNAL_STATUS_MACROS_CONCAT(_status_or_value, __LINE__), lhs,    \
64
3.86k
      rexpr,                                                                 \
65
3.86k
      ::cel::internal::StatusBuilder _(                                      \
66
3.86k
          std::move(                                                         \
67
3.86k
              CEL_INTERNAL_STATUS_MACROS_CONCAT(_status_or_value, __LINE__)) \
68
3.86k
              .status());                                                    \
69
3.86k
      (void)_; /* error_expression is allowed to not use this variable */    \
70
3.86k
      return (error_expression))
71
72
// Common implementation of CEL_ASSIGN_OR_RETURN. Both the 2 arg variant and 3
73
// arg variant are implemented by this macro.
74
75
#define CEL_INTERNAL_STATUS_MACROS_ASSIGN_OR_RETURN_(statusor, lhs, rexpr, \
76
                                                     error_expression)     \
77
1.25M
  auto statusor = (rexpr);                                                 \
78
1.25M
  if (ABSL_PREDICT_FALSE(!statusor.ok())) {                                \
79
19.3k
    error_expression;                                                      \
80
19.3k
  }                                                                        \
81
1.25M
  CEL_INTERNAL_STATUS_MACROS_UNPARENTHESIZE_IF_PARENTHESIZED(lhs) =        \
82
1.23M
      std::move(statusor).value()
83
84
#define CEL_INTERNAL_STATUS_MACROS_IS_EMPTY_INNER(...) \
85
  CEL_INTERNAL_STATUS_MACROS_IS_EMPTY_INNER_HELPER((__VA_ARGS__, 0, 1))
86
87
// MSVC historically expands variadic macros incorrectly, so another level of
88
// indirection is required.
89
#define CEL_INTERNAL_STATUS_MACROS_IS_EMPTY_INNER_HELPER(args) \
90
  CEL_INTERNAL_STATUS_MACROS_IS_EMPTY_INNER_I args
91
#define CEL_INTERNAL_STATUS_MACROS_IS_EMPTY_INNER_I(e0, e1, is_empty, ...) \
92
  is_empty
93
94
#define CEL_INTERNAL_STATUS_MACROS_IS_EMPTY(...) \
95
  CEL_INTERNAL_STATUS_MACROS_IS_EMPTY_I(__VA_ARGS__)
96
#define CEL_INTERNAL_STATUS_MACROS_IS_EMPTY_I(...) \
97
  CEL_INTERNAL_STATUS_MACROS_IS_EMPTY_INNER(_, ##__VA_ARGS__)
98
99
#define CEL_INTERNAL_STATUS_MACROS_IF_1(_Then, _Else) _Then
100
#define CEL_INTERNAL_STATUS_MACROS_IF_0(_Then, _Else) _Else
101
#define CEL_INTERNAL_STATUS_MACROS_IF(_Cond, _Then, _Else)                 \
102
  CEL_INTERNAL_STATUS_MACROS_CONCAT(CEL_INTERNAL_STATUS_MACROS_IF_, _Cond) \
103
  (_Then, _Else)
104
105
#define CEL_INTERNAL_STATUS_MACROS_EAT(...)
106
#define CEL_INTERNAL_STATUS_MACROS_REM(...) __VA_ARGS__
107
#define CEL_INTERNAL_STATUS_MACROS_EMPTY()
108
109
// Expands to 1 if the input is surrounded by parenthesis, 0 otherwise.
110
#define CEL_INTERNAL_STATUS_MACROS_IS_PARENTHESIZED(...) \
111
  CEL_INTERNAL_STATUS_MACROS_IS_EMPTY(                   \
112
      CEL_INTERNAL_STATUS_MACROS_EAT __VA_ARGS__)
113
114
// If the input is surrounded by parenthesis, remove them. Otherwise expand it
115
// unchanged.
116
#define CEL_INTERNAL_STATUS_MACROS_UNPARENTHESIZE_IF_PARENTHESIZED(...)   \
117
1.27M
  CEL_INTERNAL_STATUS_MACROS_IF(                                          \
118
1.27M
      CEL_INTERNAL_STATUS_MACROS_IS_PARENTHESIZED(__VA_ARGS__),           \
119
1.27M
      CEL_INTERNAL_STATUS_MACROS_REM, CEL_INTERNAL_STATUS_MACROS_EMPTY()) \
120
1.27M
  __VA_ARGS__
121
122
#define CEL_INTERNAL_STATUS_MACROS_CONCAT_HELPER(x, y) x##y
123
#define CEL_INTERNAL_STATUS_MACROS_CONCAT(x, y) \
124
  CEL_INTERNAL_STATUS_MACROS_CONCAT_HELPER(x, y)
125
126
namespace cel::internal {
127
128
class StatusAdaptor final {
129
 public:
130
  StatusAdaptor() = default;
131
132
  StatusAdaptor(const StatusAdaptor&) = delete;
133
134
  StatusAdaptor(StatusAdaptor&&) = delete;
135
136
7.63M
  StatusAdaptor(const absl::Status& status) : builder_(status) {}  // NOLINT
137
138
  StatusAdaptor& operator=(const StatusAdaptor&) = delete;
139
140
  StatusAdaptor& operator=(StatusAdaptor&&) = delete;
141
142
1.78k
  StatusBuilder&& Consume() { return std::move(builder_); }
143
144
7.63M
  explicit operator bool() const { return ABSL_PREDICT_TRUE(builder_.ok()); }
145
146
 private:
147
  StatusBuilder builder_;
148
};
149
150
}  // namespace cel::internal
151
152
#endif  // THIRD_PARTY_CEL_CPP_INTERNAL_STATUS_MACROS_H_