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 8076 : 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 8076 : bool was_impl_trait)
31 8076 : : GenericParam (mappings), outer_attrs (std::move (outer_attrs)),
32 8076 : type_representation (std::move (type_representation)),
33 8076 : type_param_bounds (std::move (type_param_bounds)), type (std::move (type)),
34 8076 : locus (locus), was_impl_trait (was_impl_trait)
35 8076 : {}
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 8990 : TypeParam::get_type_param_bounds ()
84 : {
85 8990 : 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 4866 : SelfParam::SelfParam (Analysis::NodeMapping mappings,
143 : tl::optional<Lifetime> lifetime, bool is_mut,
144 4866 : location_t locus)
145 4866 : : self_kind (is_mut ? ImplicitSelfKind::MUT_REF : ImplicitSelfKind::IMM_REF),
146 4866 : lifetime (std::move (lifetime)), locus (locus), mappings (mappings)
147 4866 : {}
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 23791 : SelfParam::is_mut () const
182 : {
183 23791 : return self_kind == ImplicitSelfKind::MUT
184 23791 : || self_kind == ImplicitSelfKind::MUT_REF;
185 : }
186 :
187 : bool
188 29513 : SelfParam::is_ref () const
189 : {
190 29513 : return self_kind == ImplicitSelfKind::IMM_REF
191 29513 : || self_kind == ImplicitSelfKind::MUT_REF;
192 : }
193 :
194 7937 : FunctionParam::FunctionParam (Analysis::NodeMapping mappings,
195 : std::unique_ptr<Pattern> param_name,
196 : std::unique_ptr<Type> param_type,
197 7937 : location_t locus)
198 7937 : : param_name (std::move (param_name)), type (std::move (param_type)),
199 7937 : locus (locus), mappings (mappings)
200 7937 : {}
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 0 : VisItem::VisItem (VisItem const &other)
230 0 : : Item (other), visibility (other.visibility)
231 0 : {}
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 13192 : 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 13192 : Defaultness defaultness, location_t locus)
272 : : VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
273 13192 : qualifiers (std::move (qualifiers)),
274 13192 : function_name (std::move (function_name)),
275 13192 : generic_params (std::move (generic_params)),
276 13192 : function_params (std::move (function_params)),
277 13192 : return_type (std::move (return_type)),
278 13192 : where_clause (std::move (where_clause)),
279 13192 : function_body (std::move (function_body)), self (std::move (self)),
280 13192 : locus (locus), defaultness (defaultness)
281 13192 : {}
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 2275 : StructField::StructField (Analysis::NodeMapping mappings, Identifier field_name,
368 : std::unique_ptr<Type> field_type, Visibility vis,
369 2275 : location_t locus, AST::AttrVec outer_attrs)
370 2275 : : outer_attrs (std::move (outer_attrs)), visibility (std::move (vis)),
371 2275 : field_name (std::move (field_name)), field_type (std::move (field_type)),
372 2275 : mappings (mappings), locus (locus)
373 2275 : {}
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 2056 : TupleField::TupleField (Analysis::NodeMapping mapping,
394 : std::unique_ptr<Type> field_type, Visibility vis,
395 2056 : location_t locus, AST::AttrVec outer_attrs)
396 2056 : : outer_attrs (std::move (outer_attrs)), visibility (std::move (vis)),
397 2056 : field_type (std::move (field_type)), locus (locus), mappings (mapping)
398 2056 : {}
399 :
400 0 : TupleField::TupleField (TupleField const &other)
401 0 : : outer_attrs (other.outer_attrs), visibility (other.visibility),
402 0 : field_type (other.field_type->clone_type ()), locus (other.locus),
403 0 : mappings (other.mappings)
404 0 : {}
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 957 : 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 957 : 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 957 : fields (std::move (fields))
428 957 : {}
429 :
430 1225 : EnumItem::EnumItem (Analysis::NodeMapping mappings, Identifier variant_name,
431 1225 : AST::AttrVec outer_attrs, location_t locus)
432 : : Item (std::move (mappings), std::move (outer_attrs)),
433 1225 : variant_name (std::move (variant_name)), locus (locus)
434 1225 : {}
435 :
436 419 : EnumItemTuple::EnumItemTuple (Analysis::NodeMapping mappings,
437 : Identifier variant_name,
438 : std::vector<TupleField> tuple_fields,
439 419 : AST::AttrVec outer_attrs, location_t locus)
440 : : EnumItem (std::move (mappings), std::move (variant_name),
441 : std::move (outer_attrs), locus),
442 419 : tuple_fields (std::move (tuple_fields))
443 419 : {}
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 273 : EnumItemDiscriminant::EnumItemDiscriminant (Analysis::NodeMapping mappings,
455 : Identifier variant_name,
456 : std::unique_ptr<Expr> expr,
457 : AST::AttrVec outer_attrs,
458 273 : location_t locus)
459 : : EnumItem (std::move (mappings), std::move (variant_name),
460 : std::move (outer_attrs), locus),
461 273 : expression (std::move (expr))
462 273 : {}
463 :
464 0 : EnumItemDiscriminant::EnumItemDiscriminant (EnumItemDiscriminant const &other)
465 0 : : EnumItem (other), expression (other.expression->clone_expr ())
466 0 : {}
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 521 : 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 521 : AST::AttrVec outer_attrs, location_t locus)
485 : : VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
486 1042 : enum_name (std::move (enum_name)),
487 521 : generic_params (std::move (generic_params)),
488 521 : where_clause (std::move (where_clause)), items (std::move (items)),
489 521 : locus (locus)
490 521 : {}
491 :
492 0 : Enum::Enum (Enum const &other)
493 0 : : VisItem (other), enum_name (other.enum_name),
494 0 : where_clause (other.where_clause), locus (other.locus)
495 : {
496 0 : generic_params.reserve (other.generic_params.size ());
497 0 : for (const auto &e : other.generic_params)
498 0 : generic_params.push_back (e->clone_generic_param ());
499 :
500 0 : items.reserve (other.items.size ());
501 0 : for (const auto &e : other.items)
502 0 : items.push_back (e->clone_enum_item ());
503 0 : }
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 102 : 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 102 : AST::AttrVec outer_attrs, location_t locus)
529 : : VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
530 204 : union_name (std::move (union_name)),
531 102 : generic_params (std::move (generic_params)),
532 102 : where_clause (std::move (where_clause)), variants (std::move (variants)),
533 102 : locus (locus)
534 102 : {}
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 525 : ConstantItem::ConstantItem (Analysis::NodeMapping mappings, Identifier ident,
563 : Visibility vis, std::unique_ptr<Type> type,
564 : std::unique_ptr<Expr> const_expr,
565 525 : AST::AttrVec outer_attrs, location_t locus)
566 : : VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
567 525 : identifier (std::move (ident)), type (std::move (type)),
568 525 : const_expr (std::move (const_expr)), locus (locus)
569 525 : {}
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 54 : StaticItem::StaticItem (Analysis::NodeMapping mappings, Identifier name,
590 : Mutability mut, std::unique_ptr<Type> type,
591 : std::unique_ptr<Expr> expr, Visibility vis,
592 54 : AST::AttrVec outer_attrs, location_t locus)
593 : : VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
594 108 : mut (mut), name (std::move (name)), type (std::move (type)),
595 54 : expr (std::move (expr)), locus (locus)
596 54 : {}
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 2545 : 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 2545 : std::unique_ptr<Type> return_type, WhereClause where_clause)
622 2545 : : qualifiers (std::move (qualifiers)),
623 2545 : function_name (std::move (function_name)),
624 2545 : generic_params (std::move (generic_params)),
625 2545 : function_params (std::move (function_params)),
626 2545 : return_type (std::move (return_type)),
627 2545 : where_clause (std::move (where_clause)), self (std::move (self))
628 2545 : {}
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->clone_type ()),
634 0 : where_clause (other.where_clause), self (other.self)
635 : {
636 0 : generic_params.reserve (other.generic_params.size ());
637 0 : for (const auto &e : other.generic_params)
638 0 : generic_params.push_back (e->clone_generic_param ());
639 0 : }
640 :
641 : TraitFunctionDecl &
642 0 : TraitFunctionDecl::operator= (TraitFunctionDecl const &other)
643 : {
644 0 : function_name = other.function_name;
645 0 : qualifiers = other.qualifiers;
646 0 : function_params = other.function_params;
647 0 : return_type = other.return_type->clone_type ();
648 0 : where_clause = other.where_clause;
649 0 : self = other.self;
650 :
651 0 : generic_params.reserve (other.generic_params.size ());
652 0 : for (const auto &e : other.generic_params)
653 0 : generic_params.push_back (e->clone_generic_param ());
654 :
655 0 : return *this;
656 : }
657 :
658 2545 : TraitItemFunc::TraitItemFunc (Analysis::NodeMapping mappings,
659 : TraitFunctionDecl decl,
660 : std::unique_ptr<BlockExpr> block_expr,
661 2545 : AST::AttrVec outer_attrs, location_t locus)
662 2545 : : TraitItem (mappings), outer_attrs (std::move (outer_attrs)),
663 2545 : decl (std::move (decl)), block_expr (std::move (block_expr)), locus (locus)
664 2545 : {}
665 :
666 0 : TraitItemFunc::TraitItemFunc (TraitItemFunc const &other)
667 0 : : TraitItem (other.mappings), outer_attrs (other.outer_attrs),
668 0 : decl (other.decl), locus (other.locus)
669 : {
670 0 : if (other.block_expr != nullptr)
671 0 : block_expr = other.block_expr->clone_block_expr ();
672 0 : }
673 :
674 : TraitItemFunc &
675 0 : TraitItemFunc::operator= (TraitItemFunc const &other)
676 : {
677 0 : TraitItem::operator= (other);
678 0 : outer_attrs = other.outer_attrs;
679 0 : decl = other.decl;
680 0 : locus = other.locus;
681 0 : mappings = other.mappings;
682 0 : if (other.block_expr != nullptr)
683 0 : block_expr = other.block_expr->clone_block_expr ();
684 :
685 0 : return *this;
686 : }
687 :
688 38 : TraitItemConst::TraitItemConst (Analysis::NodeMapping mappings, Identifier name,
689 : std::unique_ptr<Type> type,
690 : std::unique_ptr<Expr> expr,
691 38 : AST::AttrVec outer_attrs, location_t locus)
692 38 : : TraitItem (mappings), outer_attrs (std::move (outer_attrs)),
693 38 : name (std::move (name)), type (std::move (type)), expr (std::move (expr)),
694 38 : locus (locus)
695 38 : {}
696 :
697 0 : TraitItemConst::TraitItemConst (TraitItemConst const &other)
698 0 : : TraitItem (other.mappings), outer_attrs (other.outer_attrs),
699 0 : name (other.name), type (other.type->clone_type ()),
700 0 : expr (other.expr->clone_expr ()), locus (other.locus)
701 0 : {}
702 :
703 : TraitItemConst &
704 0 : TraitItemConst::operator= (TraitItemConst const &other)
705 : {
706 0 : TraitItem::operator= (other);
707 0 : outer_attrs = other.outer_attrs;
708 0 : name = other.name;
709 0 : type = other.type->clone_type ();
710 0 : expr = other.expr->clone_expr ();
711 0 : locus = other.locus;
712 0 : mappings = other.mappings;
713 :
714 0 : return *this;
715 : }
716 :
717 738 : TraitItemType::TraitItemType (
718 : Analysis::NodeMapping mappings, Identifier name,
719 : std::vector<std::unique_ptr<GenericParam>> generic_params,
720 : std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds,
721 738 : AST::AttrVec outer_attrs, location_t locus)
722 738 : : TraitItem (mappings), outer_attrs (std::move (outer_attrs)),
723 738 : name (std::move (name)), generic_params (std::move (generic_params)),
724 738 : type_param_bounds (std::move (type_param_bounds)), locus (locus)
725 738 : {}
726 :
727 0 : TraitItemType::TraitItemType (TraitItemType const &other)
728 0 : : TraitItem (other.mappings), outer_attrs (other.outer_attrs),
729 0 : name (other.name), locus (other.locus)
730 : {
731 0 : generic_params.reserve (other.generic_params.size ());
732 0 : for (const auto &e : other.generic_params)
733 0 : generic_params.push_back (e->clone_generic_param ());
734 0 : type_param_bounds.reserve (other.type_param_bounds.size ());
735 0 : for (const auto &e : other.type_param_bounds)
736 0 : type_param_bounds.push_back (e->clone_type_param_bound ());
737 0 : }
738 :
739 : TraitItemType &
740 0 : TraitItemType::operator= (TraitItemType const &other)
741 : {
742 0 : TraitItem::operator= (other);
743 0 : outer_attrs = other.outer_attrs;
744 0 : name = other.name;
745 0 : locus = other.locus;
746 0 : mappings = other.mappings;
747 :
748 0 : generic_params.reserve (other.generic_params.size ());
749 0 : for (const auto &e : other.generic_params)
750 0 : generic_params.push_back (e->clone_generic_param ());
751 0 : type_param_bounds.reserve (other.type_param_bounds.size ());
752 0 : for (const auto &e : other.type_param_bounds)
753 0 : type_param_bounds.push_back (e->clone_type_param_bound ());
754 :
755 0 : return *this;
756 : }
757 :
758 3699 : Trait::Trait (Analysis::NodeMapping mappings, Identifier name,
759 : Unsafety unsafety,
760 : std::vector<std::unique_ptr<GenericParam>> generic_params,
761 : std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds,
762 : WhereClause where_clause,
763 : std::vector<std::unique_ptr<TraitItem>> trait_items,
764 3699 : Visibility vis, AST::AttrVec outer_attrs, location_t locus)
765 : : VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
766 7398 : unsafety (unsafety), name (std::move (name)),
767 3699 : generic_params (std::move (generic_params)),
768 3699 : type_param_bounds (std::move (type_param_bounds)),
769 3699 : where_clause (std::move (where_clause)),
770 3699 : trait_items (std::move (trait_items)), locus (locus)
771 3699 : {}
772 :
773 0 : Trait::Trait (Trait const &other)
774 0 : : VisItem (other), unsafety (other.unsafety), name (other.name),
775 0 : where_clause (other.where_clause), locus (other.locus)
776 : {
777 0 : generic_params.reserve (other.generic_params.size ());
778 0 : for (const auto &e : other.generic_params)
779 0 : generic_params.push_back (e->clone_generic_param ());
780 :
781 0 : type_param_bounds.reserve (other.type_param_bounds.size ());
782 0 : for (const auto &e : other.type_param_bounds)
783 0 : type_param_bounds.push_back (e->clone_type_param_bound ());
784 :
785 0 : trait_items.reserve (other.trait_items.size ());
786 0 : for (const auto &e : other.trait_items)
787 0 : trait_items.push_back (e->clone_trait_item ());
788 0 : }
789 :
790 : Trait &
791 0 : Trait::operator= (Trait const &other)
792 : {
793 0 : VisItem::operator= (other);
794 0 : name = other.name;
795 0 : unsafety = other.unsafety;
796 0 : where_clause = other.where_clause;
797 0 : locus = other.locus;
798 :
799 0 : generic_params.reserve (other.generic_params.size ());
800 0 : for (const auto &e : other.generic_params)
801 0 : generic_params.push_back (e->clone_generic_param ());
802 :
803 0 : type_param_bounds.reserve (other.type_param_bounds.size ());
804 0 : for (const auto &e : other.type_param_bounds)
805 0 : type_param_bounds.push_back (e->clone_type_param_bound ());
806 :
807 0 : trait_items.reserve (other.trait_items.size ());
808 0 : for (const auto &e : other.trait_items)
809 0 : trait_items.push_back (e->clone_trait_item ());
810 :
811 0 : return *this;
812 : }
813 :
814 10235 : ImplBlock::ImplBlock (Analysis::NodeMapping mappings,
815 : std::vector<std::unique_ptr<ImplItem>> impl_items,
816 : std::vector<std::unique_ptr<GenericParam>> generic_params,
817 : std::unique_ptr<Type> impl_type,
818 : std::unique_ptr<TypePath> trait_ref,
819 : WhereClause where_clause, BoundPolarity polarity,
820 : Visibility vis, AST::AttrVec inner_attrs,
821 10235 : AST::AttrVec outer_attrs, location_t locus, bool unsafe)
822 : : VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
823 : WithInnerAttrs (std::move (inner_attrs)),
824 10235 : generic_params (std::move (generic_params)),
825 10235 : impl_type (std::move (impl_type)), trait_ref (std::move (trait_ref)),
826 10235 : where_clause (std::move (where_clause)), polarity (polarity), locus (locus),
827 10235 : impl_items (std::move (impl_items)), unsafe (unsafe)
828 10235 : {}
829 :
830 0 : ImplBlock::ImplBlock (ImplBlock const &other)
831 0 : : VisItem (other), WithInnerAttrs (other.inner_attrs),
832 0 : impl_type (other.impl_type->clone_type ()),
833 0 : where_clause (other.where_clause), polarity (other.polarity),
834 0 : locus (other.locus), unsafe (other.unsafe)
835 : {
836 0 : generic_params.reserve (other.generic_params.size ());
837 0 : for (const auto &e : other.generic_params)
838 0 : generic_params.push_back (e->clone_generic_param ());
839 :
840 0 : impl_items.reserve (other.impl_items.size ());
841 0 : for (const auto &e : other.impl_items)
842 0 : impl_items.push_back (e->clone_inherent_impl_item ());
843 0 : }
844 :
845 : ImplBlock &
846 0 : ImplBlock::operator= (ImplBlock const &other)
847 : {
848 0 : VisItem::operator= (other);
849 0 : impl_type = other.impl_type->clone_type ();
850 0 : where_clause = other.where_clause;
851 0 : polarity = other.polarity;
852 0 : inner_attrs = other.inner_attrs;
853 0 : locus = other.locus;
854 0 : unsafe = other.unsafe;
855 :
856 0 : generic_params.reserve (other.generic_params.size ());
857 0 : for (const auto &e : other.generic_params)
858 0 : generic_params.push_back (e->clone_generic_param ());
859 :
860 0 : impl_items.reserve (other.impl_items.size ());
861 0 : for (const auto &e : other.impl_items)
862 0 : impl_items.push_back (e->clone_inherent_impl_item ());
863 :
864 0 : return *this;
865 : }
866 :
867 2214 : ExternalItem::ExternalItem (Analysis::NodeMapping mappings,
868 : Identifier item_name, Visibility vis,
869 2214 : AST::AttrVec outer_attrs, location_t locus)
870 2214 : : mappings (mappings), outer_attrs (std::move (outer_attrs)),
871 2214 : visibility (std::move (vis)), item_name (std::move (item_name)),
872 2214 : locus (locus)
873 2214 : {}
874 :
875 0 : ExternalItem::ExternalItem (ExternalItem const &other)
876 0 : : mappings (other.mappings), outer_attrs (other.outer_attrs),
877 0 : visibility (other.visibility), item_name (other.item_name),
878 0 : locus (other.locus)
879 0 : {}
880 :
881 : ExternalItem &
882 0 : ExternalItem::operator= (ExternalItem const &other)
883 : {
884 0 : mappings = other.mappings;
885 0 : item_name = other.item_name;
886 0 : visibility = other.visibility;
887 0 : outer_attrs = other.outer_attrs;
888 0 : locus = other.locus;
889 :
890 0 : return *this;
891 : }
892 :
893 1 : ExternalStaticItem::ExternalStaticItem (Analysis::NodeMapping mappings,
894 : Identifier item_name,
895 : std::unique_ptr<Type> item_type,
896 : Mutability mut, Visibility vis,
897 : AST::AttrVec outer_attrs,
898 1 : location_t locus)
899 : : ExternalItem (std::move (mappings), std::move (item_name), std::move (vis),
900 : std::move (outer_attrs), locus),
901 1 : mut (mut), item_type (std::move (item_type))
902 1 : {}
903 :
904 0 : ExternalStaticItem::ExternalStaticItem (ExternalStaticItem const &other)
905 0 : : ExternalItem (other), mut (other.mut),
906 0 : item_type (other.item_type->clone_type ())
907 0 : {}
908 :
909 : ExternalStaticItem &
910 0 : ExternalStaticItem::operator= (ExternalStaticItem const &other)
911 : {
912 0 : ExternalItem::operator= (other);
913 0 : item_type = other.item_type->clone_type ();
914 0 : mut = other.mut;
915 :
916 0 : return *this;
917 : }
918 :
919 2690 : NamedFunctionParam::NamedFunctionParam (Analysis::NodeMapping mappings,
920 : Identifier name,
921 2690 : std::unique_ptr<Type> param_type)
922 2690 : : name (std::move (name)), param_type (std::move (param_type)),
923 2690 : mappings (std::move (mappings))
924 2690 : {}
925 :
926 0 : NamedFunctionParam::NamedFunctionParam (NamedFunctionParam const &other)
927 0 : : name (other.name), param_type (other.param_type->clone_type ()),
928 0 : mappings (other.mappings)
929 0 : {}
930 :
931 : NamedFunctionParam &
932 0 : NamedFunctionParam::operator= (NamedFunctionParam const &other)
933 : {
934 0 : mappings = other.mappings;
935 0 : name = other.name;
936 0 : param_type = other.param_type->clone_type ();
937 : // has_name = other.has_name;
938 :
939 0 : return *this;
940 : }
941 :
942 2213 : ExternalFunctionItem::ExternalFunctionItem (
943 : Analysis::NodeMapping mappings, Identifier item_name,
944 : std::vector<std::unique_ptr<GenericParam>> generic_params,
945 : std::unique_ptr<Type> return_type, WhereClause where_clause,
946 : std::vector<NamedFunctionParam> function_params, bool has_variadics,
947 2213 : Visibility vis, AST::AttrVec outer_attrs, location_t locus)
948 : : ExternalItem (std::move (mappings), std::move (item_name), std::move (vis),
949 : std::move (outer_attrs), locus),
950 2213 : generic_params (std::move (generic_params)),
951 2213 : return_type (std::move (return_type)),
952 2213 : where_clause (std::move (where_clause)),
953 2213 : function_params (std::move (function_params)), has_variadics (has_variadics)
954 2213 : {}
955 :
956 0 : ExternalFunctionItem::ExternalFunctionItem (ExternalFunctionItem const &other)
957 0 : : ExternalItem (other), where_clause (other.where_clause),
958 0 : function_params (other.function_params), has_variadics (other.has_variadics)
959 : {
960 0 : if (other.return_type)
961 0 : return_type = other.return_type->clone_type ();
962 :
963 0 : generic_params.reserve (other.generic_params.size ());
964 0 : for (const auto &e : other.generic_params)
965 0 : generic_params.push_back (e->clone_generic_param ());
966 0 : }
967 :
968 : ExternalFunctionItem &
969 0 : ExternalFunctionItem::operator= (ExternalFunctionItem const &other)
970 : {
971 0 : ExternalItem::operator= (other);
972 :
973 0 : where_clause = other.where_clause;
974 0 : function_params = other.function_params;
975 0 : has_variadics = other.has_variadics;
976 :
977 0 : if (other.return_type)
978 0 : return_type = other.return_type->clone_type ();
979 :
980 0 : generic_params.reserve (other.generic_params.size ());
981 0 : for (const auto &e : other.generic_params)
982 0 : generic_params.push_back (e->clone_generic_param ());
983 :
984 0 : return *this;
985 : }
986 :
987 0 : ExternalTypeItem::ExternalTypeItem (Analysis::NodeMapping mappings,
988 : Identifier item_name, Visibility vis,
989 0 : location_t locus)
990 : : ExternalItem (std::move (mappings), std::move (item_name),
991 0 : Visibility (std::move (vis)),
992 : /* FIXME: Is that correct? */
993 0 : {}, locus)
994 0 : {}
995 :
996 0 : ExternalTypeItem::ExternalTypeItem (ExternalTypeItem const &other)
997 0 : : ExternalItem (other)
998 0 : {}
999 :
1000 1469 : ExternBlock::ExternBlock (
1001 : Analysis::NodeMapping mappings, ABI abi,
1002 : std::vector<std::unique_ptr<ExternalItem>> extern_items, Visibility vis,
1003 1469 : AST::AttrVec inner_attrs, AST::AttrVec outer_attrs, location_t locus)
1004 : : VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
1005 1469 : WithInnerAttrs (std::move (inner_attrs)), abi (abi),
1006 1469 : extern_items (std::move (extern_items)), locus (locus)
1007 1469 : {}
1008 :
1009 0 : ExternBlock::ExternBlock (ExternBlock const &other)
1010 0 : : VisItem (other), WithInnerAttrs (other.inner_attrs), abi (other.abi),
1011 0 : locus (other.locus)
1012 : {
1013 0 : extern_items.reserve (other.extern_items.size ());
1014 0 : for (const auto &e : other.extern_items)
1015 0 : extern_items.push_back (e->clone_external_item ());
1016 0 : }
1017 :
1018 : ExternBlock &
1019 0 : ExternBlock::operator= (ExternBlock const &other)
1020 : {
1021 0 : VisItem::operator= (other);
1022 0 : abi = other.abi;
1023 0 : inner_attrs = other.inner_attrs;
1024 0 : locus = other.locus;
1025 :
1026 0 : extern_items.reserve (other.extern_items.size ());
1027 0 : for (const auto &e : other.extern_items)
1028 0 : extern_items.push_back (e->clone_external_item ());
1029 :
1030 0 : return *this;
1031 : }
1032 :
1033 : } // namespace HIR
1034 : } // namespace Rust
|