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