Debian Codegraph @

gcc/rust/hir/tree/rust-hir-type.cc

raw
1
2 // Copyright (C) 2020-2024 Free Software Foundation, Inc.
3
4 // This file is part of GCC.
5
6 // GCC is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU General Public License as published by the Free
8 // Software Foundation; either version 3, or (at your option) any later
9 // version.
10
11 // GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 // for more details.
15
16 // You should have received a copy of the GNU General Public License
17 // along with GCC; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
19
20 #include "rust-hir-type.h"
21
22 namespace Rust {
23 namespace HIR {
24
25 ImplTraitType::ImplTraitType (
26 Analysis::NodeMapping mappings,
27 std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds,
28 location_t locus)
29 : Type (mappings, locus), type_param_bounds (std::move (type_param_bounds))
30 {}
31
32 ImplTraitType::ImplTraitType (ImplTraitType const &other)
33 : Type (other.mappings, other.locus)
34 {
35 type_param_bounds.reserve (other.type_param_bounds.size ());
36 for (const auto &e : other.type_param_bounds)
37 type_param_bounds.push_back (e->clone_type_param_bound ());
38 }
39
40 ImplTraitType &
41 ImplTraitType::operator= (ImplTraitType const &other)
42 {
43 locus = other.locus;
44 mappings = other.mappings;
45
46 type_param_bounds.reserve (other.type_param_bounds.size ());
47 for (const auto &e : other.type_param_bounds)
48 type_param_bounds.push_back (e->clone_type_param_bound ());
49
50 return *this;
51 }
52
53 TraitObjectType::TraitObjectType (
54 Analysis::NodeMapping mappings,
55 std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds,
56 location_t locus, bool is_dyn_dispatch)
57 : Type (mappings, locus), has_dyn (is_dyn_dispatch),
58 type_param_bounds (std::move (type_param_bounds))
59 {}
60
61 TraitObjectType::TraitObjectType (TraitObjectType const &other)
62 : Type (other.mappings, other.locus), has_dyn (other.has_dyn)
63 {
64 type_param_bounds.reserve (other.type_param_bounds.size ());
65 for (const auto &e : other.type_param_bounds)
66 type_param_bounds.push_back (e->clone_type_param_bound ());
67 }
68
69 TraitObjectType &
70 TraitObjectType::operator= (TraitObjectType const &other)
71 {
72 mappings = other.mappings;
73 has_dyn = other.has_dyn;
74 locus = other.locus;
75 type_param_bounds.reserve (other.type_param_bounds.size ());
76 for (const auto &e : other.type_param_bounds)
77 type_param_bounds.push_back (e->clone_type_param_bound ());
78
79 return *this;
80 }
81
82 ParenthesisedType::ParenthesisedType (Analysis::NodeMapping mappings,
83 std::unique_ptr<Type> type_inside_parens,
84 location_t locus)
85 : TypeNoBounds (mappings, locus),
86 type_in_parens (std::move (type_inside_parens))
87 {}
88
89 ParenthesisedType::ParenthesisedType (ParenthesisedType const &other)
90 : TypeNoBounds (other.mappings, other.locus),
91 type_in_parens (other.type_in_parens->clone_type ())
92 {}
93
94 ParenthesisedType &
95 ParenthesisedType::operator= (ParenthesisedType const &other)
96 {
97 mappings = other.mappings;
98 type_in_parens = other.type_in_parens->clone_type ();
99 locus = other.locus;
100 return *this;
101 }
102
103 std::unique_ptr<TraitBound>
104 ParenthesisedType::to_trait_bound (bool in_parens ATTRIBUTE_UNUSED) const
105 {
106 /* NOTE: obviously it is unknown whether the internal type is a trait bound
107 * due to polymorphism, so just let the internal type handle it. As
108 * parenthesised type, it must be in parentheses. */
109 return type_in_parens->to_trait_bound (true);
110 }
111
112 TupleType::TupleType (Analysis::NodeMapping mappings,
113 std::vector<std::unique_ptr<Type>> elems,
114 location_t locus)
115 : TypeNoBounds (mappings, locus), elems (std::move (elems))
116 {}
117
118 TupleType::TupleType (TupleType const &other)
119 : TypeNoBounds (other.mappings, other.locus)
120 {
121 mappings = other.mappings;
122 elems.reserve (other.elems.size ());
123 for (const auto &e : other.elems)
124 elems.push_back (e->clone_type ());
125 }
126
127 TupleType &
128 TupleType::operator= (TupleType const &other)
129 {
130 locus = other.locus;
131
132 elems.reserve (other.elems.size ());
133 for (const auto &e : other.elems)
134 elems.push_back (e->clone_type ());
135
136 return *this;
137 }
138
139 NeverType::NeverType (Analysis::NodeMapping mappings, location_t locus)
140 : TypeNoBounds (mappings, locus)
141 {}
142
143 RawPointerType::RawPointerType (Analysis::NodeMapping mappings, Mutability mut,
144 std::unique_ptr<Type> type, location_t locus)
145 : TypeNoBounds (mappings, locus), mut (mut), type (std::move (type))
146 {}
147
148 RawPointerType::RawPointerType (RawPointerType const &other)
149 : TypeNoBounds (other.mappings, other.locus), mut (other.mut),
150 type (other.type->clone_type ())
151 {}
152
153 RawPointerType &
154 RawPointerType::operator= (RawPointerType const &other)
155 {
156 mappings = other.mappings;
157 mut = other.mut;
158 type = other.type->clone_type ();
159 locus = other.locus;
160 return *this;
161 }
162
163 ReferenceType::ReferenceType (Analysis::NodeMapping mappings, Mutability mut,
164 std::unique_ptr<Type> type_no_bounds,
165 location_t locus, tl::optional<Lifetime> lifetime)
166 : TypeNoBounds (mappings, locus), lifetime (std::move (lifetime)), mut (mut),
167 type (std::move (type_no_bounds))
168 {}
169
170 ReferenceType::ReferenceType (ReferenceType const &other)
171 : TypeNoBounds (other.mappings, other.locus), lifetime (other.lifetime),
172 mut (other.mut), type (other.type->clone_type ())
173 {}
174
175 ReferenceType &
176 ReferenceType::operator= (ReferenceType const &other)
177 {
178 mappings = other.mappings;
179 lifetime = other.lifetime;
180 mut = other.mut;
181 type = other.type->clone_type ();
182 locus = other.locus;
183
184 return *this;
185 }
186
187 ArrayType::ArrayType (Analysis::NodeMapping mappings,
188 std::unique_ptr<Type> type,
189 std::unique_ptr<Expr> array_size, location_t locus)
190 : TypeNoBounds (mappings, locus), elem_type (std::move (type)),
191 size (std::move (array_size))
192 {}
193
194 ArrayType::ArrayType (ArrayType const &other)
195 : TypeNoBounds (other.mappings, other.locus),
196 elem_type (other.elem_type->clone_type ()), size (other.size->clone_expr ())
197 {}
198
199 ArrayType &
200 ArrayType::operator= (ArrayType const &other)
201 {
202 mappings = other.mappings;
203 elem_type = other.elem_type->clone_type ();
204 size = other.size->clone_expr ();
205 locus = other.locus;
206 return *this;
207 }
208
209 SliceType::SliceType (Analysis::NodeMapping mappings,
210 std::unique_ptr<Type> type, location_t locus)
211 : TypeNoBounds (mappings, locus), elem_type (std::move (type))
212 {}
213
214 SliceType::SliceType (SliceType const &other)
215 : TypeNoBounds (other.mappings, other.locus),
216 elem_type (other.elem_type->clone_type ())
217 {}
218
219 SliceType &
220 SliceType::operator= (SliceType const &other)
221 {
222 mappings = other.mappings;
223 elem_type = other.elem_type->clone_type ();
224 locus = other.locus;
225
226 return *this;
227 }
228
229 InferredType::InferredType (Analysis::NodeMapping mappings, location_t locus)
230 : TypeNoBounds (mappings, locus)
231 {}
232
233 MaybeNamedParam::MaybeNamedParam (Identifier name, ParamKind param_kind,
234 std::unique_ptr<Type> param_type,
235 location_t locus)
236 : param_type (std::move (param_type)), param_kind (param_kind),
237 name (std::move (name)), locus (locus)
238 {}
239
240 MaybeNamedParam::MaybeNamedParam (MaybeNamedParam const &other)
241 : param_type (other.param_type->clone_type ()), param_kind (other.param_kind),
242 name (other.name), locus (other.locus)
243 {}
244
245 MaybeNamedParam &
246 MaybeNamedParam::operator= (MaybeNamedParam const &other)
247 {
248 name = other.name;
249 param_kind = other.param_kind;
250 param_type = other.param_type->clone_type ();
251 locus = other.locus;
252
253 return *this;
254 }
255
256 BareFunctionType::BareFunctionType (
257 Analysis::NodeMapping mappings, std::vector<LifetimeParam> lifetime_params,
258 FunctionQualifiers qualifiers, std::vector<MaybeNamedParam> named_params,
259 bool is_variadic, std::unique_ptr<Type> type, location_t locus)
260 : TypeNoBounds (mappings, locus), for_lifetimes (std::move (lifetime_params)),
261 function_qualifiers (std::move (qualifiers)),
262 params (std::move (named_params)), is_variadic (is_variadic),
263 return_type (std::move (type))
264 {}
265
266 BareFunctionType::BareFunctionType (BareFunctionType const &other)
267 : TypeNoBounds (other.mappings, other.locus),
268 for_lifetimes (other.for_lifetimes),
269 function_qualifiers (other.function_qualifiers), params (other.params),
270 is_variadic (other.is_variadic),
271 return_type (other.has_return_type () ? other.return_type->clone_type ()
272 : nullptr)
273 {}
274
275 BareFunctionType &
276 BareFunctionType::operator= (BareFunctionType const &other)
277 {
278 mappings = other.mappings;
279 for_lifetimes = other.for_lifetimes;
280 function_qualifiers = other.function_qualifiers;
281 params = other.params;
282 is_variadic = other.is_variadic;
283 return_type = other.return_type->clone_type ();
284 locus = other.locus;
285
286 return *this;
287 }
288
289 } // namespace HIR
290 } // namespace Rust