Coverage Report

Created: 2025-11-29 07:01

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/proc/self/cwd/common/ast/metadata.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 "common/ast/metadata.h"
16
17
#include <memory>
18
#include <vector>
19
20
#include "absl/base/no_destructor.h"
21
#include "absl/functional/overload.h"
22
#include "absl/types/variant.h"
23
24
namespace cel {
25
26
namespace {
27
28
0
const TypeSpec& DefaultTypeSpec() {
29
0
  static absl::NoDestructor<TypeSpec> type(TypeSpecKind{UnsetTypeSpec()});
30
0
  return *type;
31
0
}
32
33
0
TypeSpecKind CopyImpl(const TypeSpecKind& other) {
34
0
  return absl::visit(
35
0
      absl::Overload(
36
0
          [](const std::unique_ptr<TypeSpec>& other) -> TypeSpecKind {
37
0
            if (other == nullptr) {
38
0
              return std::make_unique<TypeSpec>();
39
0
            }
40
0
            return std::make_unique<TypeSpec>(*other);
41
0
          },
42
0
          [](const auto& other) -> TypeSpecKind {
43
            // Other variants define copy ctor.
44
0
            return other;
45
0
          }),
Unexecuted instantiation: metadata.cc:std::__1::variant<std::__1::monostate, cel::DynTypeSpec, cel::NullTypeSpec, cel::PrimitiveType, cel::PrimitiveTypeWrapper, cel::WellKnownTypeSpec, cel::ListTypeSpec, cel::MapTypeSpec, cel::FunctionTypeSpec, cel::MessageTypeSpec, cel::ParamTypeSpec, std::__1::unique_ptr<cel::TypeSpec, std::__1::default_delete<cel::TypeSpec> >, cel::ErrorTypeSpec, cel::AbstractType> cel::(anonymous namespace)::CopyImpl(std::__1::variant<std::__1::monostate, cel::DynTypeSpec, cel::NullTypeSpec, cel::PrimitiveType, cel::PrimitiveTypeWrapper, cel::WellKnownTypeSpec, cel::ListTypeSpec, cel::MapTypeSpec, cel::FunctionTypeSpec, cel::MessageTypeSpec, cel::ParamTypeSpec, std::__1::unique_ptr<cel::TypeSpec, std::__1::default_delete<cel::TypeSpec> >, cel::ErrorTypeSpec, cel::AbstractType> const&)::$_1::operator()<std::__1::monostate>(std::__1::monostate const&) const
Unexecuted instantiation: metadata.cc:std::__1::variant<std::__1::monostate, cel::DynTypeSpec, cel::NullTypeSpec, cel::PrimitiveType, cel::PrimitiveTypeWrapper, cel::WellKnownTypeSpec, cel::ListTypeSpec, cel::MapTypeSpec, cel::FunctionTypeSpec, cel::MessageTypeSpec, cel::ParamTypeSpec, std::__1::unique_ptr<cel::TypeSpec, std::__1::default_delete<cel::TypeSpec> >, cel::ErrorTypeSpec, cel::AbstractType> cel::(anonymous namespace)::CopyImpl(std::__1::variant<std::__1::monostate, cel::DynTypeSpec, cel::NullTypeSpec, cel::PrimitiveType, cel::PrimitiveTypeWrapper, cel::WellKnownTypeSpec, cel::ListTypeSpec, cel::MapTypeSpec, cel::FunctionTypeSpec, cel::MessageTypeSpec, cel::ParamTypeSpec, std::__1::unique_ptr<cel::TypeSpec, std::__1::default_delete<cel::TypeSpec> >, cel::ErrorTypeSpec, cel::AbstractType> const&)::$_1::operator()<cel::DynTypeSpec>(cel::DynTypeSpec const&) const
Unexecuted instantiation: metadata.cc:std::__1::variant<std::__1::monostate, cel::DynTypeSpec, cel::NullTypeSpec, cel::PrimitiveType, cel::PrimitiveTypeWrapper, cel::WellKnownTypeSpec, cel::ListTypeSpec, cel::MapTypeSpec, cel::FunctionTypeSpec, cel::MessageTypeSpec, cel::ParamTypeSpec, std::__1::unique_ptr<cel::TypeSpec, std::__1::default_delete<cel::TypeSpec> >, cel::ErrorTypeSpec, cel::AbstractType> cel::(anonymous namespace)::CopyImpl(std::__1::variant<std::__1::monostate, cel::DynTypeSpec, cel::NullTypeSpec, cel::PrimitiveType, cel::PrimitiveTypeWrapper, cel::WellKnownTypeSpec, cel::ListTypeSpec, cel::MapTypeSpec, cel::FunctionTypeSpec, cel::MessageTypeSpec, cel::ParamTypeSpec, std::__1::unique_ptr<cel::TypeSpec, std::__1::default_delete<cel::TypeSpec> >, cel::ErrorTypeSpec, cel::AbstractType> const&)::$_1::operator()<cel::NullTypeSpec>(cel::NullTypeSpec const&) const
Unexecuted instantiation: metadata.cc:std::__1::variant<std::__1::monostate, cel::DynTypeSpec, cel::NullTypeSpec, cel::PrimitiveType, cel::PrimitiveTypeWrapper, cel::WellKnownTypeSpec, cel::ListTypeSpec, cel::MapTypeSpec, cel::FunctionTypeSpec, cel::MessageTypeSpec, cel::ParamTypeSpec, std::__1::unique_ptr<cel::TypeSpec, std::__1::default_delete<cel::TypeSpec> >, cel::ErrorTypeSpec, cel::AbstractType> cel::(anonymous namespace)::CopyImpl(std::__1::variant<std::__1::monostate, cel::DynTypeSpec, cel::NullTypeSpec, cel::PrimitiveType, cel::PrimitiveTypeWrapper, cel::WellKnownTypeSpec, cel::ListTypeSpec, cel::MapTypeSpec, cel::FunctionTypeSpec, cel::MessageTypeSpec, cel::ParamTypeSpec, std::__1::unique_ptr<cel::TypeSpec, std::__1::default_delete<cel::TypeSpec> >, cel::ErrorTypeSpec, cel::AbstractType> const&)::$_1::operator()<cel::PrimitiveType>(cel::PrimitiveType const&) const
Unexecuted instantiation: metadata.cc:std::__1::variant<std::__1::monostate, cel::DynTypeSpec, cel::NullTypeSpec, cel::PrimitiveType, cel::PrimitiveTypeWrapper, cel::WellKnownTypeSpec, cel::ListTypeSpec, cel::MapTypeSpec, cel::FunctionTypeSpec, cel::MessageTypeSpec, cel::ParamTypeSpec, std::__1::unique_ptr<cel::TypeSpec, std::__1::default_delete<cel::TypeSpec> >, cel::ErrorTypeSpec, cel::AbstractType> cel::(anonymous namespace)::CopyImpl(std::__1::variant<std::__1::monostate, cel::DynTypeSpec, cel::NullTypeSpec, cel::PrimitiveType, cel::PrimitiveTypeWrapper, cel::WellKnownTypeSpec, cel::ListTypeSpec, cel::MapTypeSpec, cel::FunctionTypeSpec, cel::MessageTypeSpec, cel::ParamTypeSpec, std::__1::unique_ptr<cel::TypeSpec, std::__1::default_delete<cel::TypeSpec> >, cel::ErrorTypeSpec, cel::AbstractType> const&)::$_1::operator()<cel::PrimitiveTypeWrapper>(cel::PrimitiveTypeWrapper const&) const
Unexecuted instantiation: metadata.cc:std::__1::variant<std::__1::monostate, cel::DynTypeSpec, cel::NullTypeSpec, cel::PrimitiveType, cel::PrimitiveTypeWrapper, cel::WellKnownTypeSpec, cel::ListTypeSpec, cel::MapTypeSpec, cel::FunctionTypeSpec, cel::MessageTypeSpec, cel::ParamTypeSpec, std::__1::unique_ptr<cel::TypeSpec, std::__1::default_delete<cel::TypeSpec> >, cel::ErrorTypeSpec, cel::AbstractType> cel::(anonymous namespace)::CopyImpl(std::__1::variant<std::__1::monostate, cel::DynTypeSpec, cel::NullTypeSpec, cel::PrimitiveType, cel::PrimitiveTypeWrapper, cel::WellKnownTypeSpec, cel::ListTypeSpec, cel::MapTypeSpec, cel::FunctionTypeSpec, cel::MessageTypeSpec, cel::ParamTypeSpec, std::__1::unique_ptr<cel::TypeSpec, std::__1::default_delete<cel::TypeSpec> >, cel::ErrorTypeSpec, cel::AbstractType> const&)::$_1::operator()<cel::WellKnownTypeSpec>(cel::WellKnownTypeSpec const&) const
Unexecuted instantiation: metadata.cc:std::__1::variant<std::__1::monostate, cel::DynTypeSpec, cel::NullTypeSpec, cel::PrimitiveType, cel::PrimitiveTypeWrapper, cel::WellKnownTypeSpec, cel::ListTypeSpec, cel::MapTypeSpec, cel::FunctionTypeSpec, cel::MessageTypeSpec, cel::ParamTypeSpec, std::__1::unique_ptr<cel::TypeSpec, std::__1::default_delete<cel::TypeSpec> >, cel::ErrorTypeSpec, cel::AbstractType> cel::(anonymous namespace)::CopyImpl(std::__1::variant<std::__1::monostate, cel::DynTypeSpec, cel::NullTypeSpec, cel::PrimitiveType, cel::PrimitiveTypeWrapper, cel::WellKnownTypeSpec, cel::ListTypeSpec, cel::MapTypeSpec, cel::FunctionTypeSpec, cel::MessageTypeSpec, cel::ParamTypeSpec, std::__1::unique_ptr<cel::TypeSpec, std::__1::default_delete<cel::TypeSpec> >, cel::ErrorTypeSpec, cel::AbstractType> const&)::$_1::operator()<cel::ListTypeSpec>(cel::ListTypeSpec const&) const
Unexecuted instantiation: metadata.cc:std::__1::variant<std::__1::monostate, cel::DynTypeSpec, cel::NullTypeSpec, cel::PrimitiveType, cel::PrimitiveTypeWrapper, cel::WellKnownTypeSpec, cel::ListTypeSpec, cel::MapTypeSpec, cel::FunctionTypeSpec, cel::MessageTypeSpec, cel::ParamTypeSpec, std::__1::unique_ptr<cel::TypeSpec, std::__1::default_delete<cel::TypeSpec> >, cel::ErrorTypeSpec, cel::AbstractType> cel::(anonymous namespace)::CopyImpl(std::__1::variant<std::__1::monostate, cel::DynTypeSpec, cel::NullTypeSpec, cel::PrimitiveType, cel::PrimitiveTypeWrapper, cel::WellKnownTypeSpec, cel::ListTypeSpec, cel::MapTypeSpec, cel::FunctionTypeSpec, cel::MessageTypeSpec, cel::ParamTypeSpec, std::__1::unique_ptr<cel::TypeSpec, std::__1::default_delete<cel::TypeSpec> >, cel::ErrorTypeSpec, cel::AbstractType> const&)::$_1::operator()<cel::MapTypeSpec>(cel::MapTypeSpec const&) const
Unexecuted instantiation: metadata.cc:std::__1::variant<std::__1::monostate, cel::DynTypeSpec, cel::NullTypeSpec, cel::PrimitiveType, cel::PrimitiveTypeWrapper, cel::WellKnownTypeSpec, cel::ListTypeSpec, cel::MapTypeSpec, cel::FunctionTypeSpec, cel::MessageTypeSpec, cel::ParamTypeSpec, std::__1::unique_ptr<cel::TypeSpec, std::__1::default_delete<cel::TypeSpec> >, cel::ErrorTypeSpec, cel::AbstractType> cel::(anonymous namespace)::CopyImpl(std::__1::variant<std::__1::monostate, cel::DynTypeSpec, cel::NullTypeSpec, cel::PrimitiveType, cel::PrimitiveTypeWrapper, cel::WellKnownTypeSpec, cel::ListTypeSpec, cel::MapTypeSpec, cel::FunctionTypeSpec, cel::MessageTypeSpec, cel::ParamTypeSpec, std::__1::unique_ptr<cel::TypeSpec, std::__1::default_delete<cel::TypeSpec> >, cel::ErrorTypeSpec, cel::AbstractType> const&)::$_1::operator()<cel::FunctionTypeSpec>(cel::FunctionTypeSpec const&) const
Unexecuted instantiation: metadata.cc:std::__1::variant<std::__1::monostate, cel::DynTypeSpec, cel::NullTypeSpec, cel::PrimitiveType, cel::PrimitiveTypeWrapper, cel::WellKnownTypeSpec, cel::ListTypeSpec, cel::MapTypeSpec, cel::FunctionTypeSpec, cel::MessageTypeSpec, cel::ParamTypeSpec, std::__1::unique_ptr<cel::TypeSpec, std::__1::default_delete<cel::TypeSpec> >, cel::ErrorTypeSpec, cel::AbstractType> cel::(anonymous namespace)::CopyImpl(std::__1::variant<std::__1::monostate, cel::DynTypeSpec, cel::NullTypeSpec, cel::PrimitiveType, cel::PrimitiveTypeWrapper, cel::WellKnownTypeSpec, cel::ListTypeSpec, cel::MapTypeSpec, cel::FunctionTypeSpec, cel::MessageTypeSpec, cel::ParamTypeSpec, std::__1::unique_ptr<cel::TypeSpec, std::__1::default_delete<cel::TypeSpec> >, cel::ErrorTypeSpec, cel::AbstractType> const&)::$_1::operator()<cel::MessageTypeSpec>(cel::MessageTypeSpec const&) const
Unexecuted instantiation: metadata.cc:std::__1::variant<std::__1::monostate, cel::DynTypeSpec, cel::NullTypeSpec, cel::PrimitiveType, cel::PrimitiveTypeWrapper, cel::WellKnownTypeSpec, cel::ListTypeSpec, cel::MapTypeSpec, cel::FunctionTypeSpec, cel::MessageTypeSpec, cel::ParamTypeSpec, std::__1::unique_ptr<cel::TypeSpec, std::__1::default_delete<cel::TypeSpec> >, cel::ErrorTypeSpec, cel::AbstractType> cel::(anonymous namespace)::CopyImpl(std::__1::variant<std::__1::monostate, cel::DynTypeSpec, cel::NullTypeSpec, cel::PrimitiveType, cel::PrimitiveTypeWrapper, cel::WellKnownTypeSpec, cel::ListTypeSpec, cel::MapTypeSpec, cel::FunctionTypeSpec, cel::MessageTypeSpec, cel::ParamTypeSpec, std::__1::unique_ptr<cel::TypeSpec, std::__1::default_delete<cel::TypeSpec> >, cel::ErrorTypeSpec, cel::AbstractType> const&)::$_1::operator()<cel::ParamTypeSpec>(cel::ParamTypeSpec const&) const
Unexecuted instantiation: metadata.cc:std::__1::variant<std::__1::monostate, cel::DynTypeSpec, cel::NullTypeSpec, cel::PrimitiveType, cel::PrimitiveTypeWrapper, cel::WellKnownTypeSpec, cel::ListTypeSpec, cel::MapTypeSpec, cel::FunctionTypeSpec, cel::MessageTypeSpec, cel::ParamTypeSpec, std::__1::unique_ptr<cel::TypeSpec, std::__1::default_delete<cel::TypeSpec> >, cel::ErrorTypeSpec, cel::AbstractType> cel::(anonymous namespace)::CopyImpl(std::__1::variant<std::__1::monostate, cel::DynTypeSpec, cel::NullTypeSpec, cel::PrimitiveType, cel::PrimitiveTypeWrapper, cel::WellKnownTypeSpec, cel::ListTypeSpec, cel::MapTypeSpec, cel::FunctionTypeSpec, cel::MessageTypeSpec, cel::ParamTypeSpec, std::__1::unique_ptr<cel::TypeSpec, std::__1::default_delete<cel::TypeSpec> >, cel::ErrorTypeSpec, cel::AbstractType> const&)::$_1::operator()<cel::ErrorTypeSpec>(cel::ErrorTypeSpec const&) const
Unexecuted instantiation: metadata.cc:std::__1::variant<std::__1::monostate, cel::DynTypeSpec, cel::NullTypeSpec, cel::PrimitiveType, cel::PrimitiveTypeWrapper, cel::WellKnownTypeSpec, cel::ListTypeSpec, cel::MapTypeSpec, cel::FunctionTypeSpec, cel::MessageTypeSpec, cel::ParamTypeSpec, std::__1::unique_ptr<cel::TypeSpec, std::__1::default_delete<cel::TypeSpec> >, cel::ErrorTypeSpec, cel::AbstractType> cel::(anonymous namespace)::CopyImpl(std::__1::variant<std::__1::monostate, cel::DynTypeSpec, cel::NullTypeSpec, cel::PrimitiveType, cel::PrimitiveTypeWrapper, cel::WellKnownTypeSpec, cel::ListTypeSpec, cel::MapTypeSpec, cel::FunctionTypeSpec, cel::MessageTypeSpec, cel::ParamTypeSpec, std::__1::unique_ptr<cel::TypeSpec, std::__1::default_delete<cel::TypeSpec> >, cel::ErrorTypeSpec, cel::AbstractType> const&)::$_1::operator()<cel::AbstractType>(cel::AbstractType const&) const
46
0
      other);
47
0
}
48
49
}  // namespace
50
51
0
const ExtensionSpec::Version& ExtensionSpec::Version::DefaultInstance() {
52
0
  static absl::NoDestructor<Version> instance;
53
0
  return *instance;
54
0
}
55
56
0
const ExtensionSpec& ExtensionSpec::DefaultInstance() {
57
0
  static absl::NoDestructor<ExtensionSpec> instance;
58
0
  return *instance;
59
0
}
60
61
ExtensionSpec::ExtensionSpec(const ExtensionSpec& other)
62
0
    : id_(other.id_),
63
0
      affected_components_(other.affected_components_),
64
0
      version_(std::make_unique<Version>(*other.version_)) {}
65
66
0
ExtensionSpec& ExtensionSpec::operator=(const ExtensionSpec& other) {
67
0
  id_ = other.id_;
68
0
  affected_components_ = other.affected_components_;
69
0
  version_ = std::make_unique<Version>(*other.version_);
70
0
  return *this;
71
0
}
72
73
0
const TypeSpec& ListTypeSpec::elem_type() const {
74
0
  if (elem_type_ != nullptr) {
75
0
    return *elem_type_;
76
0
  }
77
0
  return DefaultTypeSpec();
78
0
}
79
80
0
bool ListTypeSpec::operator==(const ListTypeSpec& other) const {
81
0
  return elem_type() == other.elem_type();
82
0
}
83
84
0
const TypeSpec& MapTypeSpec::key_type() const {
85
0
  if (key_type_ != nullptr) {
86
0
    return *key_type_;
87
0
  }
88
0
  return DefaultTypeSpec();
89
0
}
90
91
0
const TypeSpec& MapTypeSpec::value_type() const {
92
0
  if (value_type_ != nullptr) {
93
0
    return *value_type_;
94
0
  }
95
0
  return DefaultTypeSpec();
96
0
}
97
98
0
bool MapTypeSpec::operator==(const MapTypeSpec& other) const {
99
0
  return key_type() == other.key_type() && value_type() == other.value_type();
100
0
}
101
102
0
const TypeSpec& FunctionTypeSpec::result_type() const {
103
0
  if (result_type_ != nullptr) {
104
0
    return *result_type_;
105
0
  }
106
0
  return DefaultTypeSpec();
107
0
}
108
109
0
bool FunctionTypeSpec::operator==(const FunctionTypeSpec& other) const {
110
0
  return result_type() == other.result_type() && arg_types_ == other.arg_types_;
111
0
}
112
113
0
const TypeSpec& TypeSpec::type() const {
114
0
  auto* value = absl::get_if<std::unique_ptr<TypeSpec>>(&type_kind_);
115
0
  if (value != nullptr) {
116
0
    if (*value != nullptr) return **value;
117
0
  }
118
0
  return DefaultTypeSpec();
119
0
}
120
121
TypeSpec::TypeSpec(const TypeSpec& other)
122
0
    : type_kind_(CopyImpl(other.type_kind_)) {}
123
124
0
TypeSpec& TypeSpec::operator=(const TypeSpec& other) {
125
0
  type_kind_ = CopyImpl(other.type_kind_);
126
0
  return *this;
127
0
}
128
129
FunctionTypeSpec::FunctionTypeSpec(const FunctionTypeSpec& other)
130
0
    : result_type_(std::make_unique<TypeSpec>(other.result_type())),
131
0
      arg_types_(other.arg_types()) {}
132
133
0
FunctionTypeSpec& FunctionTypeSpec::operator=(const FunctionTypeSpec& other) {
134
0
  result_type_ = std::make_unique<TypeSpec>(other.result_type());
135
0
  arg_types_ = other.arg_types();
136
0
  return *this;
137
0
}
138
139
}  // namespace cel