Branch data Line data Source code
1 : : // Copyright (C) 2020-2024 Free Software Foundation, Inc.
2 : :
3 : : // This file is part of GCC.
4 : :
5 : : // GCC is free software; you can redistribute it and/or modify it under
6 : : // the terms of the GNU General Public License as published by the Free
7 : : // Software Foundation; either version 3, or (at your option) any later
8 : : // version.
9 : :
10 : : // GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11 : : // WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 : : // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 : : // for more details.
14 : :
15 : : // You should have received a copy of the GNU General Public License
16 : : // along with GCC; see the file COPYING3. If not see
17 : : // <http://www.gnu.org/licenses/>.
18 : :
19 : : #include "rust-hir-item.h"
20 : : #include "optional.h"
21 : :
22 : : namespace Rust {
23 : : namespace HIR {
24 : :
25 : 7264 : TypeParam::TypeParam (
26 : : Analysis::NodeMapping mappings, Identifier type_representation,
27 : : location_t locus,
28 : : std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds,
29 : 7264 : tl::optional<std::unique_ptr<Type>> type, AST::AttrVec outer_attrs)
30 : 7264 : : GenericParam (mappings), outer_attrs (std::move (outer_attrs)),
31 : 7264 : type_representation (std::move (type_representation)),
32 : 7264 : type_param_bounds (std::move (type_param_bounds)), type (std::move (type)),
33 : 7264 : locus (locus)
34 : 7264 : {}
35 : :
36 : 0 : TypeParam::TypeParam (TypeParam const &other)
37 : 0 : : GenericParam (other.mappings), outer_attrs (other.outer_attrs),
38 : 0 : type_representation (other.type_representation), locus (other.locus)
39 : : {
40 : : // guard to prevent null pointer dereference
41 : 0 : if (other.has_type ())
42 : 0 : type = {other.type.value ()->clone_type ()};
43 : : else
44 : 0 : type = tl::nullopt;
45 : :
46 : 0 : type_param_bounds.reserve (other.type_param_bounds.size ());
47 : 0 : for (const auto &e : other.type_param_bounds)
48 : 0 : type_param_bounds.push_back (e->clone_type_param_bound ());
49 : 0 : }
50 : :
51 : : TypeParam &
52 : 0 : TypeParam::operator= (TypeParam const &other)
53 : : {
54 : 0 : type_representation = other.type_representation;
55 : 0 : outer_attrs = other.outer_attrs;
56 : 0 : locus = other.locus;
57 : 0 : mappings = other.mappings;
58 : :
59 : : // guard to prevent null pointer dereference
60 : 0 : if (other.has_type ())
61 : 0 : type = {other.type.value ()->clone_type ()};
62 : : else
63 : 0 : type = tl::nullopt;
64 : :
65 : 0 : type_param_bounds.reserve (other.type_param_bounds.size ());
66 : 0 : for (const auto &e : other.type_param_bounds)
67 : 0 : type_param_bounds.push_back (e->clone_type_param_bound ());
68 : :
69 : 0 : return *this;
70 : : }
71 : :
72 : : Analysis::NodeMapping
73 : 576 : TypeParam::get_type_mappings () const
74 : : {
75 : 576 : rust_assert (type.has_value ());
76 : 576 : return type.value ()->get_mappings ();
77 : : }
78 : :
79 : : std::vector<std::unique_ptr<TypeParamBound>> &
80 : 668 : TypeParam::get_type_param_bounds ()
81 : : {
82 : 668 : return type_param_bounds;
83 : : }
84 : :
85 : 113 : TypeBoundWhereClauseItem::TypeBoundWhereClauseItem (
86 : : Analysis::NodeMapping mappings, std::vector<LifetimeParam> for_lifetimes,
87 : : std::unique_ptr<Type> bound_type,
88 : : std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds,
89 : 113 : location_t locus)
90 : 113 : : for_lifetimes (std::move (for_lifetimes)),
91 : 113 : bound_type (std::move (bound_type)),
92 : 113 : type_param_bounds (std::move (type_param_bounds)),
93 : 113 : mappings (std::move (mappings)), locus (locus)
94 : 113 : {}
95 : :
96 : 90 : TypeBoundWhereClauseItem::TypeBoundWhereClauseItem (
97 : 90 : TypeBoundWhereClauseItem const &other)
98 : 90 : : for_lifetimes (other.for_lifetimes),
99 : 90 : bound_type (other.bound_type->clone_type ()), mappings (other.mappings)
100 : : {
101 : 90 : type_param_bounds.reserve (other.type_param_bounds.size ());
102 : 180 : for (const auto &e : other.type_param_bounds)
103 : 90 : type_param_bounds.push_back (e->clone_type_param_bound ());
104 : 90 : }
105 : :
106 : : TypeBoundWhereClauseItem &
107 : 0 : TypeBoundWhereClauseItem::operator= (TypeBoundWhereClauseItem const &other)
108 : : {
109 : 0 : mappings = other.mappings;
110 : 0 : for_lifetimes = other.for_lifetimes;
111 : 0 : bound_type = other.bound_type->clone_type ();
112 : 0 : type_param_bounds.reserve (other.type_param_bounds.size ());
113 : 0 : for (const auto &e : other.type_param_bounds)
114 : 0 : type_param_bounds.push_back (e->clone_type_param_bound ());
115 : :
116 : 0 : return *this;
117 : : }
118 : :
119 : : std::vector<std::unique_ptr<TypeParamBound>> &
120 : 506 : TypeBoundWhereClauseItem::get_type_param_bounds ()
121 : : {
122 : 506 : return type_param_bounds;
123 : : }
124 : :
125 : 0 : SelfParam::SelfParam (Analysis::NodeMapping mappings,
126 : : ImplicitSelfKind self_kind,
127 : 0 : tl::optional<Lifetime> lifetime, Type *type)
128 : 0 : : self_kind (self_kind), lifetime (std::move (lifetime)), type (type),
129 : 0 : mappings (mappings)
130 : 0 : {}
131 : :
132 : 3025 : SelfParam::SelfParam (Analysis::NodeMapping mappings,
133 : 3025 : std::unique_ptr<Type> type, bool is_mut, location_t locus)
134 : 3025 : : self_kind (is_mut ? ImplicitSelfKind::MUT : ImplicitSelfKind::IMM),
135 : 3025 : lifetime (tl::nullopt), type (std::move (type)), locus (locus),
136 : 3025 : mappings (mappings)
137 : 3025 : {}
138 : :
139 : 2959 : SelfParam::SelfParam (Analysis::NodeMapping mappings,
140 : : tl::optional<Lifetime> lifetime, bool is_mut,
141 : 2959 : location_t locus)
142 : 2959 : : self_kind (is_mut ? ImplicitSelfKind::MUT_REF : ImplicitSelfKind::IMM_REF),
143 : 2959 : lifetime (std::move (lifetime)), locus (locus), mappings (mappings)
144 : 2959 : {}
145 : :
146 : 0 : SelfParam::SelfParam (SelfParam const &other)
147 : 0 : : self_kind (other.self_kind), lifetime (other.lifetime), locus (other.locus),
148 : 0 : mappings (other.mappings)
149 : : {
150 : 0 : if (other.type != nullptr)
151 : 0 : type = other.type->clone_type ();
152 : 0 : }
153 : :
154 : : SelfParam &
155 : 0 : SelfParam::operator= (SelfParam const &other)
156 : : {
157 : 0 : if (other.type != nullptr)
158 : 0 : type = other.type->clone_type ();
159 : :
160 : 0 : self_kind = other.self_kind;
161 : 0 : lifetime = other.lifetime;
162 : 0 : locus = other.locus;
163 : 0 : mappings = other.mappings;
164 : :
165 : 0 : return *this;
166 : : }
167 : :
168 : : Mutability
169 : 4608 : SelfParam::get_mut () const
170 : : {
171 : 4608 : return (self_kind == ImplicitSelfKind::MUT
172 : 4608 : || self_kind == ImplicitSelfKind::MUT_REF)
173 : 4608 : ? Mutability::Mut
174 : 4608 : : Mutability::Imm;
175 : : }
176 : :
177 : : bool
178 : 8913 : SelfParam::is_mut () const
179 : : {
180 : 8913 : return self_kind == ImplicitSelfKind::MUT
181 : 8913 : || self_kind == ImplicitSelfKind::MUT_REF;
182 : : }
183 : :
184 : : bool
185 : 13521 : SelfParam::is_ref () const
186 : : {
187 : 13521 : return self_kind == ImplicitSelfKind::IMM_REF
188 : 13521 : || self_kind == ImplicitSelfKind::MUT_REF;
189 : : }
190 : :
191 : 6070 : FunctionParam::FunctionParam (Analysis::NodeMapping mappings,
192 : : std::unique_ptr<Pattern> param_name,
193 : : std::unique_ptr<Type> param_type,
194 : 6070 : location_t locus)
195 : 6070 : : param_name (std::move (param_name)), type (std::move (param_type)),
196 : 6070 : locus (locus), mappings (mappings)
197 : 6070 : {}
198 : :
199 : 798 : FunctionParam::FunctionParam (FunctionParam const &other)
200 : 798 : : param_name (other.param_name->clone_pattern ()),
201 : 798 : type (other.type->clone_type ()), locus (other.locus),
202 : 798 : mappings (other.mappings)
203 : 798 : {}
204 : :
205 : : FunctionParam &
206 : 0 : FunctionParam::operator= (FunctionParam const &other)
207 : : {
208 : 0 : param_name = other.param_name->clone_pattern ();
209 : 0 : type = other.type->clone_type ();
210 : 0 : locus = other.locus;
211 : 0 : mappings = other.mappings;
212 : :
213 : 0 : return *this;
214 : : }
215 : :
216 : : VisItem &
217 : 0 : VisItem::operator= (VisItem const &other)
218 : : {
219 : 0 : Item::operator= (other);
220 : 0 : visibility = other.visibility;
221 : : // outer_attrs = other.outer_attrs;
222 : :
223 : 0 : return *this;
224 : : }
225 : :
226 : 0 : VisItem::VisItem (VisItem const &other)
227 : 0 : : Item (other), visibility (other.visibility)
228 : 0 : {}
229 : :
230 : 929 : Module::Module (Analysis::NodeMapping mappings, Identifier module_name,
231 : : location_t locus, std::vector<std::unique_ptr<Item>> items,
232 : : Visibility visibility, AST::AttrVec inner_attrs,
233 : 929 : AST::AttrVec outer_attrs)
234 : : : VisItem (std::move (mappings), std::move (visibility),
235 : : std::move (outer_attrs)),
236 : 929 : WithInnerAttrs (std::move (inner_attrs)), module_name (module_name),
237 : 929 : locus (locus), items (std::move (items))
238 : 929 : {}
239 : :
240 : 0 : Module::Module (Module const &other)
241 : 0 : : VisItem (other), WithInnerAttrs (other.inner_attrs), module_name ("")
242 : : {
243 : 0 : items.reserve (other.items.size ());
244 : 0 : for (const auto &e : other.items)
245 : 0 : items.push_back (e->clone_item ());
246 : 0 : }
247 : :
248 : : Module &
249 : 0 : Module::operator= (Module const &other)
250 : : {
251 : 0 : VisItem::operator= (other);
252 : 0 : inner_attrs = other.inner_attrs;
253 : :
254 : 0 : items.reserve (other.items.size ());
255 : 0 : for (const auto &e : other.items)
256 : 0 : items.push_back (e->clone_item ());
257 : :
258 : 0 : return *this;
259 : : }
260 : :
261 : 12538 : Function::Function (Analysis::NodeMapping mappings, Identifier function_name,
262 : : FunctionQualifiers qualifiers,
263 : : std::vector<std::unique_ptr<GenericParam>> generic_params,
264 : : std::vector<FunctionParam> function_params,
265 : : std::unique_ptr<Type> return_type, WhereClause where_clause,
266 : : std::unique_ptr<BlockExpr> function_body, Visibility vis,
267 : : AST::AttrVec outer_attrs, tl::optional<SelfParam> self,
268 : 12538 : Defaultness defaultness, location_t locus)
269 : : : VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
270 : 12538 : qualifiers (std::move (qualifiers)),
271 : 12538 : function_name (std::move (function_name)),
272 : 12538 : generic_params (std::move (generic_params)),
273 : 12538 : function_params (std::move (function_params)),
274 : 12538 : return_type (std::move (return_type)),
275 : 12538 : where_clause (std::move (where_clause)),
276 : 12538 : function_body (std::move (function_body)), self (std::move (self)),
277 : 12538 : locus (locus), defaultness (defaultness)
278 : 12538 : {}
279 : :
280 : 0 : Function::Function (Function const &other)
281 : 0 : : VisItem (other), qualifiers (other.qualifiers),
282 : 0 : function_name (other.function_name),
283 : 0 : function_params (other.function_params), where_clause (other.where_clause),
284 : 0 : function_body (other.function_body->clone_block_expr ()), self (other.self),
285 : 0 : locus (other.locus), defaultness (other.defaultness)
286 : : {
287 : : // guard to prevent null dereference (always required)
288 : 0 : if (other.return_type != nullptr)
289 : 0 : return_type = other.return_type->clone_type ();
290 : : else
291 : 0 : return_type = nullptr;
292 : :
293 : 0 : generic_params.reserve (other.generic_params.size ());
294 : 0 : for (const auto &e : other.generic_params)
295 : 0 : generic_params.push_back (e->clone_generic_param ());
296 : 0 : }
297 : :
298 : : Function &
299 : 0 : Function::operator= (Function const &other)
300 : : {
301 : 0 : VisItem::operator= (other);
302 : 0 : function_name = other.function_name;
303 : 0 : qualifiers = other.qualifiers;
304 : 0 : function_params = other.function_params;
305 : :
306 : : // guard to prevent null dereference (always required)
307 : 0 : if (other.return_type != nullptr)
308 : 0 : return_type = other.return_type->clone_type ();
309 : : else
310 : 0 : return_type = nullptr;
311 : :
312 : 0 : where_clause = other.where_clause;
313 : 0 : function_body = other.function_body->clone_block_expr ();
314 : 0 : locus = other.locus;
315 : 0 : self = other.self;
316 : :
317 : 0 : defaultness = other.defaultness;
318 : :
319 : 0 : generic_params.reserve (other.generic_params.size ());
320 : 0 : for (const auto &e : other.generic_params)
321 : 0 : generic_params.push_back (e->clone_generic_param ());
322 : :
323 : 0 : return *this;
324 : : }
325 : :
326 : 1260 : TypeAlias::TypeAlias (Analysis::NodeMapping mappings, Identifier new_type_name,
327 : : std::vector<std::unique_ptr<GenericParam>> generic_params,
328 : : WhereClause where_clause,
329 : : std::unique_ptr<Type> existing_type, Visibility vis,
330 : 1260 : AST::AttrVec outer_attrs, location_t locus)
331 : : : VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
332 : 1260 : new_type_name (std::move (new_type_name)),
333 : 1260 : generic_params (std::move (generic_params)),
334 : 1260 : where_clause (std::move (where_clause)),
335 : 1260 : existing_type (std::move (existing_type)), locus (locus)
336 : 1260 : {}
337 : :
338 : 0 : TypeAlias::TypeAlias (TypeAlias const &other)
339 : 0 : : VisItem (other), new_type_name (other.new_type_name),
340 : 0 : where_clause (other.where_clause),
341 : 0 : existing_type (other.existing_type->clone_type ()), locus (other.locus)
342 : : {
343 : 0 : generic_params.reserve (other.generic_params.size ());
344 : 0 : for (const auto &e : other.generic_params)
345 : 0 : generic_params.push_back (e->clone_generic_param ());
346 : 0 : }
347 : :
348 : : TypeAlias &
349 : 0 : TypeAlias::operator= (TypeAlias const &other)
350 : : {
351 : 0 : VisItem::operator= (other);
352 : 0 : new_type_name = other.new_type_name;
353 : 0 : where_clause = other.where_clause;
354 : 0 : existing_type = other.existing_type->clone_type ();
355 : 0 : locus = other.locus;
356 : :
357 : 0 : generic_params.reserve (other.generic_params.size ());
358 : 0 : for (const auto &e : other.generic_params)
359 : 0 : generic_params.push_back (e->clone_generic_param ());
360 : :
361 : 0 : return *this;
362 : : }
363 : :
364 : 2183 : StructField::StructField (Analysis::NodeMapping mappings, Identifier field_name,
365 : : std::unique_ptr<Type> field_type, Visibility vis,
366 : 2183 : location_t locus, AST::AttrVec outer_attrs)
367 : 2183 : : outer_attrs (std::move (outer_attrs)), visibility (std::move (vis)),
368 : 2183 : field_name (std::move (field_name)), field_type (std::move (field_type)),
369 : 2183 : mappings (mappings), locus (locus)
370 : 2183 : {}
371 : :
372 : 0 : StructField::StructField (StructField const &other)
373 : 0 : : outer_attrs (other.outer_attrs), visibility (other.visibility),
374 : 0 : field_name (other.field_name), field_type (other.field_type->clone_type ()),
375 : 0 : mappings (other.mappings)
376 : 0 : {}
377 : :
378 : : StructField &
379 : 0 : StructField::operator= (StructField const &other)
380 : : {
381 : 0 : field_name = other.field_name;
382 : 0 : field_type = other.field_type->clone_type ();
383 : 0 : visibility = other.visibility;
384 : 0 : outer_attrs = other.outer_attrs;
385 : 0 : mappings = other.mappings;
386 : :
387 : 0 : return *this;
388 : : }
389 : :
390 : 2089 : TupleField::TupleField (Analysis::NodeMapping mapping,
391 : : std::unique_ptr<Type> field_type, Visibility vis,
392 : 2089 : location_t locus, AST::AttrVec outer_attrs)
393 : 2089 : : outer_attrs (std::move (outer_attrs)), visibility (std::move (vis)),
394 : 2089 : field_type (std::move (field_type)), locus (locus), mappings (mapping)
395 : 2089 : {}
396 : :
397 : 0 : TupleField::TupleField (TupleField const &other)
398 : 0 : : outer_attrs (other.outer_attrs), visibility (other.visibility),
399 : 0 : field_type (other.field_type->clone_type ()), locus (other.locus),
400 : 0 : mappings (other.mappings)
401 : 0 : {}
402 : :
403 : : TupleField &
404 : 0 : TupleField::operator= (TupleField const &other)
405 : : {
406 : 0 : field_type = other.field_type->clone_type ();
407 : 0 : visibility = other.visibility;
408 : 0 : outer_attrs = other.outer_attrs;
409 : 0 : locus = other.locus;
410 : 0 : mappings = other.mappings;
411 : :
412 : 0 : return *this;
413 : : }
414 : :
415 : 984 : TupleStruct::TupleStruct (
416 : : Analysis::NodeMapping mappings, std::vector<TupleField> fields,
417 : : Identifier struct_name,
418 : : std::vector<std::unique_ptr<GenericParam>> generic_params,
419 : : WhereClause where_clause, Visibility vis, AST::AttrVec outer_attrs,
420 : 984 : location_t locus)
421 : : : Struct (std::move (mappings), std::move (struct_name),
422 : : std::move (generic_params), std::move (where_clause),
423 : : std::move (vis), locus, std::move (outer_attrs)),
424 : 984 : fields (std::move (fields))
425 : 984 : {}
426 : :
427 : 888 : EnumItem::EnumItem (Analysis::NodeMapping mappings, Identifier variant_name,
428 : 888 : AST::AttrVec outer_attrs, location_t locus)
429 : : : Item (std::move (mappings), std::move (outer_attrs)),
430 : 888 : variant_name (std::move (variant_name)), locus (locus)
431 : 888 : {}
432 : :
433 : 382 : EnumItemTuple::EnumItemTuple (Analysis::NodeMapping mappings,
434 : : Identifier variant_name,
435 : : std::vector<TupleField> tuple_fields,
436 : 382 : AST::AttrVec outer_attrs, location_t locus)
437 : : : EnumItem (std::move (mappings), std::move (variant_name),
438 : : std::move (outer_attrs), locus),
439 : 382 : tuple_fields (std::move (tuple_fields))
440 : 382 : {}
441 : :
442 : 78 : EnumItemStruct::EnumItemStruct (Analysis::NodeMapping mappings,
443 : : Identifier variant_name,
444 : : std::vector<StructField> struct_fields,
445 : 78 : AST::AttrVec outer_attrs, location_t locus)
446 : : : EnumItem (std::move (mappings), std::move (variant_name),
447 : : std::move (outer_attrs), locus),
448 : 78 : struct_fields (std::move (struct_fields))
449 : 78 : {}
450 : :
451 : 28 : EnumItemDiscriminant::EnumItemDiscriminant (Analysis::NodeMapping mappings,
452 : : Identifier variant_name,
453 : : std::unique_ptr<Expr> expr,
454 : : AST::AttrVec outer_attrs,
455 : 28 : location_t locus)
456 : : : EnumItem (std::move (mappings), std::move (variant_name),
457 : : std::move (outer_attrs), locus),
458 : 28 : expression (std::move (expr))
459 : 28 : {}
460 : :
461 : 0 : EnumItemDiscriminant::EnumItemDiscriminant (EnumItemDiscriminant const &other)
462 : 0 : : EnumItem (other), expression (other.expression->clone_expr ())
463 : 0 : {}
464 : :
465 : : EnumItemDiscriminant &
466 : 0 : EnumItemDiscriminant::operator= (EnumItemDiscriminant const &other)
467 : : {
468 : 0 : EnumItem::operator= (other);
469 : 0 : expression = other.expression->clone_expr ();
470 : : // variant_name = other.variant_name;
471 : : // outer_attrs = other.outer_attrs;
472 : :
473 : 0 : return *this;
474 : : }
475 : :
476 : 397 : Enum::Enum (Analysis::NodeMapping mappings, Identifier enum_name,
477 : : Visibility vis,
478 : : std::vector<std::unique_ptr<GenericParam>> generic_params,
479 : : WhereClause where_clause,
480 : : std::vector<std::unique_ptr<EnumItem>> items,
481 : 397 : AST::AttrVec outer_attrs, location_t locus)
482 : : : VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
483 : 794 : enum_name (std::move (enum_name)),
484 : 397 : generic_params (std::move (generic_params)),
485 : 397 : where_clause (std::move (where_clause)), items (std::move (items)),
486 : 397 : locus (locus)
487 : 397 : {}
488 : :
489 : 0 : Enum::Enum (Enum const &other)
490 : 0 : : VisItem (other), enum_name (other.enum_name),
491 : 0 : where_clause (other.where_clause), locus (other.locus)
492 : : {
493 : 0 : generic_params.reserve (other.generic_params.size ());
494 : 0 : for (const auto &e : other.generic_params)
495 : 0 : generic_params.push_back (e->clone_generic_param ());
496 : :
497 : 0 : items.reserve (other.items.size ());
498 : 0 : for (const auto &e : other.items)
499 : 0 : items.push_back (e->clone_enum_item ());
500 : 0 : }
501 : :
502 : : Enum &
503 : 0 : Enum::operator= (Enum const &other)
504 : : {
505 : 0 : VisItem::operator= (other);
506 : 0 : enum_name = other.enum_name;
507 : 0 : where_clause = other.where_clause;
508 : 0 : locus = other.locus;
509 : :
510 : 0 : generic_params.reserve (other.generic_params.size ());
511 : 0 : for (const auto &e : other.generic_params)
512 : 0 : generic_params.push_back (e->clone_generic_param ());
513 : :
514 : 0 : items.reserve (other.items.size ());
515 : 0 : for (const auto &e : other.items)
516 : 0 : items.push_back (e->clone_enum_item ());
517 : :
518 : 0 : return *this;
519 : : }
520 : :
521 : 108 : Union::Union (Analysis::NodeMapping mappings, Identifier union_name,
522 : : Visibility vis,
523 : : std::vector<std::unique_ptr<GenericParam>> generic_params,
524 : : WhereClause where_clause, std::vector<StructField> variants,
525 : 108 : AST::AttrVec outer_attrs, location_t locus)
526 : : : VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
527 : 216 : union_name (std::move (union_name)),
528 : 108 : generic_params (std::move (generic_params)),
529 : 108 : where_clause (std::move (where_clause)), variants (std::move (variants)),
530 : 108 : locus (locus)
531 : 108 : {}
532 : :
533 : 0 : Union::Union (Union const &other)
534 : 0 : : VisItem (other), union_name (other.union_name),
535 : 0 : where_clause (other.where_clause), variants (other.variants),
536 : 0 : locus (other.locus)
537 : : {
538 : 0 : generic_params.reserve (other.generic_params.size ());
539 : 0 : for (const auto &e : other.generic_params)
540 : 0 : generic_params.push_back (e->clone_generic_param ());
541 : 0 : }
542 : :
543 : : Union &
544 : 0 : Union::operator= (Union const &other)
545 : : {
546 : 0 : VisItem::operator= (other);
547 : 0 : union_name = other.union_name;
548 : 0 : where_clause = other.where_clause;
549 : 0 : variants = other.variants;
550 : 0 : locus = other.locus;
551 : :
552 : 0 : generic_params.reserve (other.generic_params.size ());
553 : 0 : for (const auto &e : other.generic_params)
554 : 0 : generic_params.push_back (e->clone_generic_param ());
555 : :
556 : 0 : return *this;
557 : : }
558 : :
559 : 567 : ConstantItem::ConstantItem (Analysis::NodeMapping mappings, Identifier ident,
560 : : Visibility vis, std::unique_ptr<Type> type,
561 : : std::unique_ptr<Expr> const_expr,
562 : 567 : AST::AttrVec outer_attrs, location_t locus)
563 : : : VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
564 : 567 : identifier (std::move (ident)), type (std::move (type)),
565 : 567 : const_expr (std::move (const_expr)), locus (locus)
566 : 567 : {}
567 : :
568 : 0 : ConstantItem::ConstantItem (ConstantItem const &other)
569 : 0 : : VisItem (other), identifier (other.identifier),
570 : 0 : type (other.type->clone_type ()),
571 : 0 : const_expr (other.const_expr->clone_expr ()), locus (other.locus)
572 : 0 : {}
573 : :
574 : : ConstantItem &
575 : 0 : ConstantItem::operator= (ConstantItem const &other)
576 : : {
577 : 0 : VisItem::operator= (other);
578 : 0 : identifier = other.identifier;
579 : 0 : type = other.type->clone_type ();
580 : 0 : const_expr = other.const_expr->clone_expr ();
581 : 0 : locus = other.locus;
582 : :
583 : 0 : return *this;
584 : : }
585 : :
586 : 63 : StaticItem::StaticItem (Analysis::NodeMapping mappings, Identifier name,
587 : : Mutability mut, std::unique_ptr<Type> type,
588 : : std::unique_ptr<Expr> expr, Visibility vis,
589 : 63 : AST::AttrVec outer_attrs, location_t locus)
590 : : : VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
591 : 126 : mut (mut), name (std::move (name)), type (std::move (type)),
592 : 63 : expr (std::move (expr)), locus (locus)
593 : 63 : {}
594 : :
595 : 0 : StaticItem::StaticItem (StaticItem const &other)
596 : 0 : : VisItem (other), mut (other.mut), name (other.name),
597 : 0 : type (other.type->clone_type ()), expr (other.expr->clone_expr ()),
598 : 0 : locus (other.locus)
599 : 0 : {}
600 : :
601 : : StaticItem &
602 : 0 : StaticItem::operator= (StaticItem const &other)
603 : : {
604 : 0 : VisItem::operator= (other);
605 : 0 : name = other.name;
606 : 0 : mut = other.mut;
607 : 0 : type = other.type->clone_type ();
608 : 0 : expr = other.expr->clone_expr ();
609 : 0 : locus = other.locus;
610 : :
611 : 0 : return *this;
612 : : }
613 : :
614 : 1741 : TraitFunctionDecl::TraitFunctionDecl (
615 : : Identifier function_name, FunctionQualifiers qualifiers,
616 : : std::vector<std::unique_ptr<GenericParam>> generic_params,
617 : : tl::optional<SelfParam> self, std::vector<FunctionParam> function_params,
618 : 1741 : std::unique_ptr<Type> return_type, WhereClause where_clause)
619 : 1741 : : qualifiers (std::move (qualifiers)),
620 : 1741 : function_name (std::move (function_name)),
621 : 1741 : generic_params (std::move (generic_params)),
622 : 1741 : function_params (std::move (function_params)),
623 : 1741 : return_type (std::move (return_type)),
624 : 1741 : where_clause (std::move (where_clause)), self (std::move (self))
625 : 1741 : {}
626 : :
627 : 0 : TraitFunctionDecl::TraitFunctionDecl (TraitFunctionDecl const &other)
628 : 0 : : qualifiers (other.qualifiers), function_name (other.function_name),
629 : 0 : function_params (other.function_params),
630 : 0 : return_type (other.return_type->clone_type ()),
631 : 0 : where_clause (other.where_clause), self (other.self)
632 : : {
633 : 0 : generic_params.reserve (other.generic_params.size ());
634 : 0 : for (const auto &e : other.generic_params)
635 : 0 : generic_params.push_back (e->clone_generic_param ());
636 : 0 : }
637 : :
638 : : TraitFunctionDecl &
639 : 0 : TraitFunctionDecl::operator= (TraitFunctionDecl const &other)
640 : : {
641 : 0 : function_name = other.function_name;
642 : 0 : qualifiers = other.qualifiers;
643 : 0 : function_params = other.function_params;
644 : 0 : return_type = other.return_type->clone_type ();
645 : 0 : where_clause = other.where_clause;
646 : 0 : self = other.self;
647 : :
648 : 0 : generic_params.reserve (other.generic_params.size ());
649 : 0 : for (const auto &e : other.generic_params)
650 : 0 : generic_params.push_back (e->clone_generic_param ());
651 : :
652 : 0 : return *this;
653 : : }
654 : :
655 : 1741 : TraitItemFunc::TraitItemFunc (Analysis::NodeMapping mappings,
656 : : TraitFunctionDecl decl,
657 : : std::unique_ptr<BlockExpr> block_expr,
658 : 1741 : AST::AttrVec outer_attrs, location_t locus)
659 : 1741 : : TraitItem (mappings), outer_attrs (std::move (outer_attrs)),
660 : 1741 : decl (std::move (decl)), block_expr (std::move (block_expr)), locus (locus)
661 : 1741 : {}
662 : :
663 : 0 : TraitItemFunc::TraitItemFunc (TraitItemFunc const &other)
664 : 0 : : TraitItem (other.mappings), outer_attrs (other.outer_attrs),
665 : 0 : decl (other.decl), locus (other.locus)
666 : : {
667 : 0 : if (other.block_expr != nullptr)
668 : 0 : block_expr = other.block_expr->clone_block_expr ();
669 : 0 : }
670 : :
671 : : TraitItemFunc &
672 : 0 : TraitItemFunc::operator= (TraitItemFunc const &other)
673 : : {
674 : 0 : TraitItem::operator= (other);
675 : 0 : outer_attrs = other.outer_attrs;
676 : 0 : decl = other.decl;
677 : 0 : locus = other.locus;
678 : 0 : mappings = other.mappings;
679 : 0 : if (other.block_expr != nullptr)
680 : 0 : block_expr = other.block_expr->clone_block_expr ();
681 : :
682 : 0 : return *this;
683 : : }
684 : :
685 : 48 : TraitItemConst::TraitItemConst (Analysis::NodeMapping mappings, Identifier name,
686 : : std::unique_ptr<Type> type,
687 : : std::unique_ptr<Expr> expr,
688 : 48 : AST::AttrVec outer_attrs, location_t locus)
689 : 48 : : TraitItem (mappings), outer_attrs (std::move (outer_attrs)),
690 : 48 : name (std::move (name)), type (std::move (type)), expr (std::move (expr)),
691 : 48 : locus (locus)
692 : 48 : {}
693 : :
694 : 0 : TraitItemConst::TraitItemConst (TraitItemConst const &other)
695 : 0 : : TraitItem (other.mappings), outer_attrs (other.outer_attrs),
696 : 0 : name (other.name), type (other.type->clone_type ()),
697 : 0 : expr (other.expr->clone_expr ()), locus (other.locus)
698 : 0 : {}
699 : :
700 : : TraitItemConst &
701 : 0 : TraitItemConst::operator= (TraitItemConst const &other)
702 : : {
703 : 0 : TraitItem::operator= (other);
704 : 0 : outer_attrs = other.outer_attrs;
705 : 0 : name = other.name;
706 : 0 : type = other.type->clone_type ();
707 : 0 : expr = other.expr->clone_expr ();
708 : 0 : locus = other.locus;
709 : 0 : mappings = other.mappings;
710 : :
711 : 0 : return *this;
712 : : }
713 : :
714 : 715 : TraitItemType::TraitItemType (
715 : : Analysis::NodeMapping mappings, Identifier name,
716 : : std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds,
717 : 715 : AST::AttrVec outer_attrs, location_t locus)
718 : 715 : : TraitItem (mappings), outer_attrs (std::move (outer_attrs)),
719 : 715 : name (std::move (name)), type_param_bounds (std::move (type_param_bounds)),
720 : 715 : locus (locus)
721 : 715 : {}
722 : :
723 : 0 : TraitItemType::TraitItemType (TraitItemType const &other)
724 : 0 : : TraitItem (other.mappings), outer_attrs (other.outer_attrs),
725 : 0 : name (other.name), locus (other.locus)
726 : : {
727 : 0 : type_param_bounds.reserve (other.type_param_bounds.size ());
728 : 0 : for (const auto &e : other.type_param_bounds)
729 : 0 : type_param_bounds.push_back (e->clone_type_param_bound ());
730 : 0 : }
731 : :
732 : : TraitItemType &
733 : 0 : TraitItemType::operator= (TraitItemType const &other)
734 : : {
735 : 0 : TraitItem::operator= (other);
736 : 0 : outer_attrs = other.outer_attrs;
737 : 0 : name = other.name;
738 : 0 : locus = other.locus;
739 : 0 : mappings = other.mappings;
740 : :
741 : 0 : type_param_bounds.reserve (other.type_param_bounds.size ());
742 : 0 : for (const auto &e : other.type_param_bounds)
743 : 0 : type_param_bounds.push_back (e->clone_type_param_bound ());
744 : :
745 : 0 : return *this;
746 : : }
747 : :
748 : 3163 : Trait::Trait (Analysis::NodeMapping mappings, Identifier name,
749 : : Unsafety unsafety,
750 : : std::vector<std::unique_ptr<GenericParam>> generic_params,
751 : : std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds,
752 : : WhereClause where_clause,
753 : : std::vector<std::unique_ptr<TraitItem>> trait_items,
754 : 3163 : Visibility vis, AST::AttrVec outer_attrs, location_t locus)
755 : : : VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
756 : 6326 : unsafety (unsafety), name (std::move (name)),
757 : 3163 : generic_params (std::move (generic_params)),
758 : 3163 : type_param_bounds (std::move (type_param_bounds)),
759 : 3163 : where_clause (std::move (where_clause)),
760 : 3163 : trait_items (std::move (trait_items)), locus (locus)
761 : 3163 : {}
762 : :
763 : 0 : Trait::Trait (Trait const &other)
764 : 0 : : VisItem (other), unsafety (other.unsafety), name (other.name),
765 : 0 : where_clause (other.where_clause), locus (other.locus)
766 : : {
767 : 0 : generic_params.reserve (other.generic_params.size ());
768 : 0 : for (const auto &e : other.generic_params)
769 : 0 : generic_params.push_back (e->clone_generic_param ());
770 : :
771 : 0 : type_param_bounds.reserve (other.type_param_bounds.size ());
772 : 0 : for (const auto &e : other.type_param_bounds)
773 : 0 : type_param_bounds.push_back (e->clone_type_param_bound ());
774 : :
775 : 0 : trait_items.reserve (other.trait_items.size ());
776 : 0 : for (const auto &e : other.trait_items)
777 : 0 : trait_items.push_back (e->clone_trait_item ());
778 : 0 : }
779 : :
780 : : Trait &
781 : 0 : Trait::operator= (Trait const &other)
782 : : {
783 : 0 : VisItem::operator= (other);
784 : 0 : name = other.name;
785 : 0 : unsafety = other.unsafety;
786 : 0 : where_clause = other.where_clause;
787 : 0 : locus = other.locus;
788 : :
789 : 0 : generic_params.reserve (other.generic_params.size ());
790 : 0 : for (const auto &e : other.generic_params)
791 : 0 : generic_params.push_back (e->clone_generic_param ());
792 : :
793 : 0 : type_param_bounds.reserve (other.type_param_bounds.size ());
794 : 0 : for (const auto &e : other.type_param_bounds)
795 : 0 : type_param_bounds.push_back (e->clone_type_param_bound ());
796 : :
797 : 0 : trait_items.reserve (other.trait_items.size ());
798 : 0 : for (const auto &e : other.trait_items)
799 : 0 : trait_items.push_back (e->clone_trait_item ());
800 : :
801 : 0 : return *this;
802 : : }
803 : :
804 : 10052 : ImplBlock::ImplBlock (Analysis::NodeMapping mappings,
805 : : std::vector<std::unique_ptr<ImplItem>> impl_items,
806 : : std::vector<std::unique_ptr<GenericParam>> generic_params,
807 : : std::unique_ptr<Type> impl_type,
808 : : std::unique_ptr<TypePath> trait_ref,
809 : : WhereClause where_clause, BoundPolarity polarity,
810 : : Visibility vis, AST::AttrVec inner_attrs,
811 : 10052 : AST::AttrVec outer_attrs, location_t locus, bool unsafe)
812 : : : VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
813 : : WithInnerAttrs (std::move (inner_attrs)),
814 : 10052 : generic_params (std::move (generic_params)),
815 : 10052 : impl_type (std::move (impl_type)), trait_ref (std::move (trait_ref)),
816 : 10052 : where_clause (std::move (where_clause)), polarity (polarity), locus (locus),
817 : 10052 : impl_items (std::move (impl_items)), unsafe (unsafe)
818 : 10052 : {}
819 : :
820 : 0 : ImplBlock::ImplBlock (ImplBlock const &other)
821 : 0 : : VisItem (other), WithInnerAttrs (other.inner_attrs),
822 : 0 : impl_type (other.impl_type->clone_type ()),
823 : 0 : where_clause (other.where_clause), polarity (other.polarity),
824 : 0 : locus (other.locus), unsafe (other.unsafe)
825 : : {
826 : 0 : generic_params.reserve (other.generic_params.size ());
827 : 0 : for (const auto &e : other.generic_params)
828 : 0 : generic_params.push_back (e->clone_generic_param ());
829 : :
830 : 0 : impl_items.reserve (other.impl_items.size ());
831 : 0 : for (const auto &e : other.impl_items)
832 : 0 : impl_items.push_back (e->clone_inherent_impl_item ());
833 : 0 : }
834 : :
835 : : ImplBlock &
836 : 0 : ImplBlock::operator= (ImplBlock const &other)
837 : : {
838 : 0 : VisItem::operator= (other);
839 : 0 : impl_type = other.impl_type->clone_type ();
840 : 0 : where_clause = other.where_clause;
841 : 0 : polarity = other.polarity;
842 : 0 : inner_attrs = other.inner_attrs;
843 : 0 : locus = other.locus;
844 : 0 : unsafe = other.unsafe;
845 : :
846 : 0 : generic_params.reserve (other.generic_params.size ());
847 : 0 : for (const auto &e : other.generic_params)
848 : 0 : generic_params.push_back (e->clone_generic_param ());
849 : :
850 : 0 : impl_items.reserve (other.impl_items.size ());
851 : 0 : for (const auto &e : other.impl_items)
852 : 0 : impl_items.push_back (e->clone_inherent_impl_item ());
853 : :
854 : 0 : return *this;
855 : : }
856 : :
857 : 2100 : ExternalItem::ExternalItem (Analysis::NodeMapping mappings,
858 : : Identifier item_name, Visibility vis,
859 : 2100 : AST::AttrVec outer_attrs, location_t locus)
860 : 2100 : : mappings (mappings), outer_attrs (std::move (outer_attrs)),
861 : 2100 : visibility (std::move (vis)), item_name (std::move (item_name)),
862 : 2100 : locus (locus)
863 : 2100 : {}
864 : :
865 : 0 : ExternalItem::ExternalItem (ExternalItem const &other)
866 : 0 : : mappings (other.mappings), outer_attrs (other.outer_attrs),
867 : 0 : visibility (other.visibility), item_name (other.item_name),
868 : 0 : locus (other.locus)
869 : 0 : {}
870 : :
871 : : ExternalItem &
872 : 0 : ExternalItem::operator= (ExternalItem const &other)
873 : : {
874 : 0 : mappings = other.mappings;
875 : 0 : item_name = other.item_name;
876 : 0 : visibility = other.visibility;
877 : 0 : outer_attrs = other.outer_attrs;
878 : 0 : locus = other.locus;
879 : :
880 : 0 : return *this;
881 : : }
882 : :
883 : 2 : ExternalStaticItem::ExternalStaticItem (Analysis::NodeMapping mappings,
884 : : Identifier item_name,
885 : : std::unique_ptr<Type> item_type,
886 : : Mutability mut, Visibility vis,
887 : : AST::AttrVec outer_attrs,
888 : 2 : location_t locus)
889 : : : ExternalItem (std::move (mappings), std::move (item_name), std::move (vis),
890 : : std::move (outer_attrs), locus),
891 : 2 : mut (mut), item_type (std::move (item_type))
892 : 2 : {}
893 : :
894 : 0 : ExternalStaticItem::ExternalStaticItem (ExternalStaticItem const &other)
895 : 0 : : ExternalItem (other), mut (other.mut),
896 : 0 : item_type (other.item_type->clone_type ())
897 : 0 : {}
898 : :
899 : : ExternalStaticItem &
900 : 0 : ExternalStaticItem::operator= (ExternalStaticItem const &other)
901 : : {
902 : 0 : ExternalItem::operator= (other);
903 : 0 : item_type = other.item_type->clone_type ();
904 : 0 : mut = other.mut;
905 : :
906 : 0 : return *this;
907 : : }
908 : :
909 : 2615 : NamedFunctionParam::NamedFunctionParam (Analysis::NodeMapping mappings,
910 : : Identifier name,
911 : 2615 : std::unique_ptr<Type> param_type)
912 : 2615 : : name (std::move (name)), param_type (std::move (param_type)),
913 : 2615 : mappings (std::move (mappings))
914 : 2615 : {}
915 : :
916 : 0 : NamedFunctionParam::NamedFunctionParam (NamedFunctionParam const &other)
917 : 0 : : name (other.name), param_type (other.param_type->clone_type ()),
918 : 0 : mappings (other.mappings)
919 : 0 : {}
920 : :
921 : : NamedFunctionParam &
922 : 0 : NamedFunctionParam::operator= (NamedFunctionParam const &other)
923 : : {
924 : 0 : mappings = other.mappings;
925 : 0 : name = other.name;
926 : 0 : param_type = other.param_type->clone_type ();
927 : : // has_name = other.has_name;
928 : :
929 : 0 : return *this;
930 : : }
931 : :
932 : 2098 : ExternalFunctionItem::ExternalFunctionItem (
933 : : Analysis::NodeMapping mappings, Identifier item_name,
934 : : std::vector<std::unique_ptr<GenericParam>> generic_params,
935 : : std::unique_ptr<Type> return_type, WhereClause where_clause,
936 : : std::vector<NamedFunctionParam> function_params, bool has_variadics,
937 : 2098 : Visibility vis, AST::AttrVec outer_attrs, location_t locus)
938 : : : ExternalItem (std::move (mappings), std::move (item_name), std::move (vis),
939 : : std::move (outer_attrs), locus),
940 : 2098 : generic_params (std::move (generic_params)),
941 : 2098 : return_type (std::move (return_type)),
942 : 2098 : where_clause (std::move (where_clause)),
943 : 2098 : function_params (std::move (function_params)), has_variadics (has_variadics)
944 : 2098 : {}
945 : :
946 : 0 : ExternalFunctionItem::ExternalFunctionItem (ExternalFunctionItem const &other)
947 : 0 : : ExternalItem (other), where_clause (other.where_clause),
948 : 0 : function_params (other.function_params), has_variadics (other.has_variadics)
949 : : {
950 : 0 : if (other.return_type)
951 : 0 : return_type = other.return_type->clone_type ();
952 : :
953 : 0 : generic_params.reserve (other.generic_params.size ());
954 : 0 : for (const auto &e : other.generic_params)
955 : 0 : generic_params.push_back (e->clone_generic_param ());
956 : 0 : }
957 : :
958 : : ExternalFunctionItem &
959 : 0 : ExternalFunctionItem::operator= (ExternalFunctionItem const &other)
960 : : {
961 : 0 : ExternalItem::operator= (other);
962 : :
963 : 0 : where_clause = other.where_clause;
964 : 0 : function_params = other.function_params;
965 : 0 : has_variadics = other.has_variadics;
966 : :
967 : 0 : if (other.return_type)
968 : 0 : return_type = other.return_type->clone_type ();
969 : :
970 : 0 : generic_params.reserve (other.generic_params.size ());
971 : 0 : for (const auto &e : other.generic_params)
972 : 0 : generic_params.push_back (e->clone_generic_param ());
973 : :
974 : 0 : return *this;
975 : : }
976 : :
977 : 0 : ExternalTypeItem::ExternalTypeItem (Analysis::NodeMapping mappings,
978 : : Identifier item_name, Visibility vis,
979 : 0 : location_t locus)
980 : : : ExternalItem (std::move (mappings), std::move (item_name),
981 : 0 : Visibility (std::move (vis)),
982 : : /* FIXME: Is that correct? */
983 : 0 : {}, locus)
984 : 0 : {}
985 : :
986 : 0 : ExternalTypeItem::ExternalTypeItem (ExternalTypeItem const &other)
987 : 0 : : ExternalItem (other)
988 : 0 : {}
989 : :
990 : 1266 : ExternBlock::ExternBlock (
991 : : Analysis::NodeMapping mappings, ABI abi,
992 : : std::vector<std::unique_ptr<ExternalItem>> extern_items, Visibility vis,
993 : 1266 : AST::AttrVec inner_attrs, AST::AttrVec outer_attrs, location_t locus)
994 : : : VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
995 : 1266 : WithInnerAttrs (std::move (inner_attrs)), abi (abi),
996 : 1266 : extern_items (std::move (extern_items)), locus (locus)
997 : 1266 : {}
998 : :
999 : 0 : ExternBlock::ExternBlock (ExternBlock const &other)
1000 : 0 : : VisItem (other), WithInnerAttrs (other.inner_attrs), abi (other.abi),
1001 : 0 : locus (other.locus)
1002 : : {
1003 : 0 : extern_items.reserve (other.extern_items.size ());
1004 : 0 : for (const auto &e : other.extern_items)
1005 : 0 : extern_items.push_back (e->clone_external_item ());
1006 : 0 : }
1007 : :
1008 : : ExternBlock &
1009 : 0 : ExternBlock::operator= (ExternBlock const &other)
1010 : : {
1011 : 0 : VisItem::operator= (other);
1012 : 0 : abi = other.abi;
1013 : 0 : inner_attrs = other.inner_attrs;
1014 : 0 : locus = other.locus;
1015 : :
1016 : 0 : extern_items.reserve (other.extern_items.size ());
1017 : 0 : for (const auto &e : other.extern_items)
1018 : 0 : extern_items.push_back (e->clone_external_item ());
1019 : :
1020 : 0 : return *this;
1021 : : }
1022 : :
1023 : : } // namespace HIR
1024 : : } // namespace Rust
|