Coverage Report

Created: 2026-05-27 07:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/proc/self/cwd/internal/casts.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_CASTS_H_
16
#define THIRD_PARTY_CEL_CPP_INTERNAL_CASTS_H_
17
18
#include <cassert>
19
#include <memory>
20
#include <type_traits>
21
22
namespace cel::internal {
23
24
template <typename To, typename From>
25
10.2k
To down_cast(From* from) {
26
10.2k
  static_assert(std::is_pointer_v<To>, "Target type not a pointer.");
27
10.2k
  static_assert((std::is_base_of_v<From, std::remove_pointer_t<To>>),
28
10.2k
                "Target type not derived from source type.");
29
10.2k
#if !defined(__GNUC__) || defined(__GXX_RTTI)
30
10.2k
  assert(from == nullptr || dynamic_cast<To>(from) != nullptr);
31
10.2k
#endif
32
10.2k
  return static_cast<To>(from);
33
10.2k
}
Unexecuted instantiation: google::api::expr::runtime::CelExpressionRecursiveImpl::EvaluationState* cel::internal::down_cast<google::api::expr::runtime::CelExpressionRecursiveImpl::EvaluationState*, google::api::expr::runtime::CelEvaluationState>(google::api::expr::runtime::CelEvaluationState*)
Unexecuted instantiation: google::api::expr::runtime::WrappedDirectStep const* cel::internal::down_cast<google::api::expr::runtime::WrappedDirectStep const*, google::api::expr::runtime::ExpressionStep const>(google::api::expr::runtime::ExpressionStep const*)
google::api::expr::runtime::CelExpressionFlatEvaluationState* cel::internal::down_cast<google::api::expr::runtime::CelExpressionFlatEvaluationState*, google::api::expr::runtime::CelEvaluationState>(google::api::expr::runtime::CelEvaluationState*)
Line
Count
Source
25
9.92k
To down_cast(From* from) {
26
9.92k
  static_assert(std::is_pointer_v<To>, "Target type not a pointer.");
27
9.92k
  static_assert((std::is_base_of_v<From, std::remove_pointer_t<To>>),
28
9.92k
                "Target type not derived from source type.");
29
9.92k
#if !defined(__GNUC__) || defined(__GXX_RTTI)
30
  assert(from == nullptr || dynamic_cast<To>(from) != nullptr);
31
9.92k
#endif
32
9.92k
  return static_cast<To>(from);
33
9.92k
}
Unexecuted instantiation: google::api::expr::runtime::TraceStep const* cel::internal::down_cast<google::api::expr::runtime::TraceStep const*, google::api::expr::runtime::DirectExpressionStep const>(google::api::expr::runtime::DirectExpressionStep const*)
Unexecuted instantiation: google::api::expr::runtime::DirectCompilerConstantStep const* cel::internal::down_cast<google::api::expr::runtime::DirectCompilerConstantStep const*, google::api::expr::runtime::DirectExpressionStep const>(google::api::expr::runtime::DirectExpressionStep const*)
Unexecuted instantiation: google::api::expr::runtime::CompilerConstantStep const* cel::internal::down_cast<google::api::expr::runtime::CompilerConstantStep const*, google::api::expr::runtime::ExpressionStep const>(google::api::expr::runtime::ExpressionStep const*)
cel::common_internal::CompatListValue const* cel::internal::down_cast<cel::common_internal::CompatListValue const*, cel::CustomListValueInterface const>(cel::CustomListValueInterface const*)
Line
Count
Source
25
273
To down_cast(From* from) {
26
273
  static_assert(std::is_pointer_v<To>, "Target type not a pointer.");
27
273
  static_assert((std::is_base_of_v<From, std::remove_pointer_t<To>>),
28
273
                "Target type not derived from source type.");
29
273
#if !defined(__GNUC__) || defined(__GXX_RTTI)
30
  assert(from == nullptr || dynamic_cast<To>(from) != nullptr);
31
273
#endif
32
273
  return static_cast<To>(from);
33
273
}
Unexecuted instantiation: cel::common_internal::MutableCompatListValue const* cel::internal::down_cast<cel::common_internal::MutableCompatListValue const*, cel::CustomListValueInterface const>(cel::CustomListValueInterface const*)
cel::common_internal::CompatMapValue const* cel::internal::down_cast<cel::common_internal::CompatMapValue const*, cel::CustomMapValueInterface const>(cel::CustomMapValueInterface const*)
Line
Count
Source
25
43
To down_cast(From* from) {
26
43
  static_assert(std::is_pointer_v<To>, "Target type not a pointer.");
27
43
  static_assert((std::is_base_of_v<From, std::remove_pointer_t<To>>),
28
43
                "Target type not derived from source type.");
29
43
#if !defined(__GNUC__) || defined(__GXX_RTTI)
30
  assert(from == nullptr || dynamic_cast<To>(from) != nullptr);
31
43
#endif
32
43
  return static_cast<To>(from);
33
43
}
Unexecuted instantiation: cel::common_internal::MutableCompatMapValue const* cel::internal::down_cast<cel::common_internal::MutableCompatMapValue const*, cel::CustomMapValueInterface const>(cel::CustomMapValueInterface const*)
Unexecuted instantiation: cel::common_internal::MutableListValue const* cel::internal::down_cast<cel::common_internal::MutableListValue const*, cel::CustomListValueInterface const>(cel::CustomListValueInterface const*)
Unexecuted instantiation: cel::common_internal::MutableMapValue const* cel::internal::down_cast<cel::common_internal::MutableMapValue const*, cel::CustomMapValueInterface const>(cel::CustomMapValueInterface const*)
34
35
template <typename To, typename From>
36
0
To down_cast(From& from) {
37
0
  static_assert(std::is_lvalue_reference_v<To>,
38
0
                "Target type not a lvalue reference.");
39
0
  static_assert((std::is_base_of_v<From, std::remove_reference_t<To>>),
40
0
                "Target type not derived from source type.");
41
0
#if !defined(__GNUC__) || defined(__GXX_RTTI)
42
  assert(dynamic_cast<std::add_pointer_t<std::remove_reference_t<To>>>(
43
0
             std::addressof(from)) != nullptr);
44
0
#endif
45
0
  return static_cast<To>(from);
46
0
}
Unexecuted instantiation: cel::runtime_internal::RuntimeImpl& cel::internal::down_cast<cel::runtime_internal::RuntimeImpl&, cel::Runtime>(cel::Runtime&)
Unexecuted instantiation: cel::common_internal::MutableListValue const& cel::internal::down_cast<cel::common_internal::MutableListValue const&, cel::CustomListValueInterface const>(cel::CustomListValueInterface const&)
Unexecuted instantiation: cel::common_internal::MutableCompatListValue const& cel::internal::down_cast<cel::common_internal::MutableCompatListValue const&, cel::CustomListValueInterface const>(cel::CustomListValueInterface const&)
Unexecuted instantiation: cel::common_internal::MutableMapValue const& cel::internal::down_cast<cel::common_internal::MutableMapValue const&, cel::CustomMapValueInterface const>(cel::CustomMapValueInterface const&)
Unexecuted instantiation: cel::common_internal::MutableCompatMapValue const& cel::internal::down_cast<cel::common_internal::MutableCompatMapValue const&, cel::CustomMapValueInterface const>(cel::CustomMapValueInterface const&)
47
48
}  // namespace cel::internal
49
50
#endif  // THIRD_PARTY_CEL_CPP_INTERNAL_CASTS_H_