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