Coverage Report

Created: 2026-03-31 06:24

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_(other.version_ == nullptr
65
0
                   ? nullptr
66
0
                   : std::make_unique<Version>(*other.version_)) {}
67
68
0
ExtensionSpec& ExtensionSpec::operator=(const ExtensionSpec& other) {
69
0
  id_ = other.id_;
70
0
  affected_components_ = other.affected_components_;
71
0
  if (other.version_ != nullptr) {
72
0
    version_ = std::make_unique<Version>(other.version());
73
0
  } else {
74
0
    version_ = nullptr;
75
0
  }
76
0
  return *this;
77
0
}
78
79
0
const TypeSpec& ListTypeSpec::elem_type() const {
80
0
  if (elem_type_ != nullptr) {
81
0
    return *elem_type_;
82
0
  }
83
0
  return DefaultTypeSpec();
84
0
}
85
86
0
bool ListTypeSpec::operator==(const ListTypeSpec& other) const {
87
0
  return elem_type() == other.elem_type();
88
0
}
89
90
0
const TypeSpec& MapTypeSpec::key_type() const {
91
0
  if (key_type_ != nullptr) {
92
0
    return *key_type_;
93
0
  }
94
0
  return DefaultTypeSpec();
95
0
}
96
97
0
const TypeSpec& MapTypeSpec::value_type() const {
98
0
  if (value_type_ != nullptr) {
99
0
    return *value_type_;
100
0
  }
101
0
  return DefaultTypeSpec();
102
0
}
103
104
0
bool MapTypeSpec::operator==(const MapTypeSpec& other) const {
105
0
  return key_type() == other.key_type() && value_type() == other.value_type();
106
0
}
107
108
0
const TypeSpec& FunctionTypeSpec::result_type() const {
109
0
  if (result_type_ != nullptr) {
110
0
    return *result_type_;
111
0
  }
112
0
  return DefaultTypeSpec();
113
0
}
114
115
0
bool FunctionTypeSpec::operator==(const FunctionTypeSpec& other) const {
116
0
  return result_type() == other.result_type() && arg_types_ == other.arg_types_;
117
0
}
118
119
0
const TypeSpec& TypeSpec::type() const {
120
0
  auto* value = absl::get_if<std::unique_ptr<TypeSpec>>(&type_kind_);
121
0
  if (value != nullptr) {
122
0
    if (*value != nullptr) return **value;
123
0
  }
124
0
  return DefaultTypeSpec();
125
0
}
126
127
TypeSpec::TypeSpec(const TypeSpec& other)
128
0
    : type_kind_(CopyImpl(other.type_kind_)) {}
129
130
0
TypeSpec& TypeSpec::operator=(const TypeSpec& other) {
131
0
  type_kind_ = CopyImpl(other.type_kind_);
132
0
  return *this;
133
0
}
134
135
FunctionTypeSpec::FunctionTypeSpec(const FunctionTypeSpec& other)
136
0
    : result_type_(std::make_unique<TypeSpec>(other.result_type())),
137
0
      arg_types_(other.arg_types()) {}
138
139
0
FunctionTypeSpec& FunctionTypeSpec::operator=(const FunctionTypeSpec& other) {
140
0
  result_type_ = std::make_unique<TypeSpec>(other.result_type());
141
0
  arg_types_ = other.arg_types();
142
0
  return *this;
143
0
}
144
145
}  // namespace cel