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-expr.h"
20 : #include "rust-hir-map.h"
21 : #include "optional.h"
22 : #include "rust-operators.h"
23 : #include "rust-hir-stmt.h"
24 :
25 : namespace Rust {
26 : namespace HIR {
27 :
28 154535 : Expr::Expr (Analysis::NodeMapping mappings, AST::AttrVec outer_attribs)
29 154535 : : outer_attrs (std::move (outer_attribs)), mappings (std::move (mappings))
30 154535 : {}
31 :
32 122761 : ExprWithoutBlock::ExprWithoutBlock (Analysis::NodeMapping mappings,
33 : AST::AttrVec outer_attribs)
34 122761 : : Expr (std::move (mappings), std::move (outer_attribs))
35 122761 : {}
36 :
37 53 : LoopLabel::LoopLabel (Analysis::NodeMapping mapping, Lifetime loop_label,
38 : location_t locus)
39 53 : : label (std::move (loop_label)), locus (locus), mappings (mapping)
40 53 : {}
41 :
42 31774 : ExprWithBlock::ExprWithBlock (Analysis::NodeMapping mappings,
43 : AST::AttrVec outer_attrs)
44 31774 : : Expr (std::move (mappings), std::move (outer_attrs))
45 31774 : {}
46 :
47 1311 : LiteralExpr::LiteralExpr (Analysis::NodeMapping mappings,
48 : std::string value_as_string, Literal::LitType type,
49 : PrimitiveCoreType type_hint, location_t locus,
50 : AST::AttrVec outer_attrs)
51 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attrs)),
52 1311 : literal (std::move (value_as_string), type, type_hint), locus (locus)
53 1311 : {}
54 :
55 21340 : LiteralExpr::LiteralExpr (Analysis::NodeMapping mappings, Literal literal,
56 : location_t locus, AST::AttrVec outer_attrs)
57 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attrs)),
58 21340 : literal (std::move (literal)), locus (locus)
59 21340 : {}
60 :
61 22519 : OperatorExpr::OperatorExpr (Analysis::NodeMapping mappings,
62 : std::unique_ptr<Expr> main_or_left_expr,
63 : AST::AttrVec outer_attribs, location_t locus)
64 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
65 22519 : locus (locus), main_or_left_expr (std::move (main_or_left_expr))
66 22519 : {}
67 :
68 8568 : OperatorExpr::OperatorExpr (OperatorExpr const &other)
69 8568 : : ExprWithoutBlock (other), locus (other.locus),
70 8568 : main_or_left_expr (other.main_or_left_expr->clone_expr ())
71 8568 : {}
72 :
73 : OperatorExpr &
74 0 : OperatorExpr::operator= (OperatorExpr const &other)
75 : {
76 0 : ExprWithoutBlock::operator= (other);
77 0 : main_or_left_expr = other.main_or_left_expr->clone_expr ();
78 0 : locus = other.locus;
79 :
80 0 : return *this;
81 : }
82 :
83 2033 : BorrowExpr::BorrowExpr (Analysis::NodeMapping mappings,
84 : std::unique_ptr<Expr> borrow_lvalue, Mutability mut,
85 : bool raw, AST::AttrVec outer_attribs, location_t locus)
86 : : OperatorExpr (std::move (mappings), std::move (borrow_lvalue),
87 : std::move (outer_attribs), locus),
88 2033 : mut (mut), raw (raw)
89 2033 : {}
90 :
91 3920 : DereferenceExpr::DereferenceExpr (Analysis::NodeMapping mappings,
92 : std::unique_ptr<Expr> deref_lvalue,
93 : AST::AttrVec outer_attribs, location_t locus)
94 : : OperatorExpr (std::move (mappings), std::move (deref_lvalue),
95 3920 : std::move (outer_attribs), locus)
96 3920 : {}
97 :
98 0 : ErrorPropagationExpr::ErrorPropagationExpr (
99 : Analysis::NodeMapping mappings, std::unique_ptr<Expr> potential_error_value,
100 : AST::AttrVec outer_attribs, location_t locus)
101 : : OperatorExpr (std::move (mappings), std::move (potential_error_value),
102 0 : std::move (outer_attribs), locus)
103 0 : {}
104 :
105 687 : NegationExpr::NegationExpr (Analysis::NodeMapping mappings,
106 : std::unique_ptr<Expr> negated_value,
107 : ExprType expr_kind, AST::AttrVec outer_attribs,
108 : location_t locus)
109 : : OperatorExpr (std::move (mappings), std::move (negated_value),
110 : std::move (outer_attribs), locus),
111 687 : expr_type (expr_kind)
112 687 : {}
113 :
114 3417 : ArithmeticOrLogicalExpr::ArithmeticOrLogicalExpr (
115 : Analysis::NodeMapping mappings, std::unique_ptr<Expr> left_value,
116 : std::unique_ptr<Expr> right_value, ExprType expr_kind, location_t locus)
117 3417 : : OperatorExpr (std::move (mappings), std::move (left_value), AST::AttrVec (),
118 : locus),
119 3417 : expr_type (expr_kind), right_expr (std::move (right_value))
120 3417 : {}
121 :
122 35 : ArithmeticOrLogicalExpr::ArithmeticOrLogicalExpr (
123 : ArithmeticOrLogicalExpr const &other)
124 35 : : OperatorExpr (other), expr_type (other.expr_type),
125 35 : right_expr (other.right_expr->clone_expr ())
126 35 : {}
127 :
128 : ArithmeticOrLogicalExpr &
129 0 : ArithmeticOrLogicalExpr::operator= (ArithmeticOrLogicalExpr const &other)
130 : {
131 0 : OperatorExpr::operator= (other);
132 0 : right_expr = other.right_expr->clone_expr ();
133 0 : expr_type = other.expr_type;
134 :
135 0 : return *this;
136 : }
137 :
138 3566 : ComparisonExpr::ComparisonExpr (Analysis::NodeMapping mappings,
139 : std::unique_ptr<Expr> left_value,
140 : std::unique_ptr<Expr> right_value,
141 : ExprType comparison_kind, location_t locus)
142 3566 : : OperatorExpr (std::move (mappings), std::move (left_value), AST::AttrVec (),
143 : locus),
144 3566 : expr_type (comparison_kind), right_expr (std::move (right_value))
145 3566 : {}
146 :
147 0 : ComparisonExpr::ComparisonExpr (ComparisonExpr const &other)
148 0 : : OperatorExpr (other), expr_type (other.expr_type),
149 0 : right_expr (other.right_expr->clone_expr ())
150 0 : {}
151 :
152 : ComparisonExpr &
153 0 : ComparisonExpr::operator= (ComparisonExpr const &other)
154 : {
155 0 : OperatorExpr::operator= (other);
156 0 : right_expr = other.right_expr->clone_expr ();
157 0 : expr_type = other.expr_type;
158 :
159 0 : return *this;
160 : }
161 :
162 405 : LazyBooleanExpr::LazyBooleanExpr (Analysis::NodeMapping mappings,
163 : std::unique_ptr<Expr> left_bool_expr,
164 : std::unique_ptr<Expr> right_bool_expr,
165 : ExprType expr_kind, location_t locus)
166 : : OperatorExpr (std::move (mappings), std::move (left_bool_expr),
167 405 : AST::AttrVec (), locus),
168 405 : expr_type (expr_kind), right_expr (std::move (right_bool_expr))
169 405 : {}
170 :
171 0 : LazyBooleanExpr::LazyBooleanExpr (LazyBooleanExpr const &other)
172 0 : : OperatorExpr (other), expr_type (other.expr_type),
173 0 : right_expr (other.right_expr->clone_expr ())
174 0 : {}
175 :
176 : LazyBooleanExpr &
177 0 : LazyBooleanExpr::operator= (LazyBooleanExpr const &other)
178 : {
179 0 : OperatorExpr::operator= (other);
180 0 : right_expr = other.right_expr->clone_expr ();
181 0 : expr_type = other.expr_type;
182 :
183 0 : return *this;
184 : }
185 :
186 5293 : TypeCastExpr::TypeCastExpr (Analysis::NodeMapping mappings,
187 : std::unique_ptr<Expr> expr_to_cast,
188 : std::unique_ptr<Type> type_to_cast_to,
189 : location_t locus)
190 : : OperatorExpr (std::move (mappings), std::move (expr_to_cast),
191 5293 : AST::AttrVec (), locus),
192 5293 : type_to_convert_to (std::move (type_to_cast_to))
193 5293 : {}
194 :
195 0 : TypeCastExpr::TypeCastExpr (TypeCastExpr const &other)
196 : : OperatorExpr (other),
197 0 : type_to_convert_to (other.type_to_convert_to->clone_type ())
198 0 : {}
199 :
200 : TypeCastExpr &
201 0 : TypeCastExpr::operator= (TypeCastExpr const &other)
202 : {
203 0 : OperatorExpr::operator= (other);
204 0 : type_to_convert_to = other.type_to_convert_to->clone_type ();
205 :
206 0 : return *this;
207 : }
208 :
209 2501 : AssignmentExpr::AssignmentExpr (Analysis::NodeMapping mappings,
210 : std::unique_ptr<Expr> value_to_assign_to,
211 : std::unique_ptr<Expr> value_to_assign,
212 : location_t locus)
213 : : OperatorExpr (std::move (mappings), std::move (value_to_assign_to),
214 2501 : AST::AttrVec (), locus),
215 2501 : right_expr (std::move (value_to_assign))
216 2501 : {}
217 :
218 0 : AssignmentExpr::AssignmentExpr (AssignmentExpr const &other)
219 0 : : OperatorExpr (other), right_expr (other.right_expr->clone_expr ())
220 0 : {}
221 :
222 : AssignmentExpr &
223 0 : AssignmentExpr::operator= (AssignmentExpr const &other)
224 : {
225 0 : OperatorExpr::operator= (other);
226 0 : right_expr = other.right_expr->clone_expr ();
227 :
228 0 : return *this;
229 : }
230 :
231 697 : CompoundAssignmentExpr::CompoundAssignmentExpr (
232 : Analysis::NodeMapping mappings, std::unique_ptr<Expr> value_to_assign_to,
233 : std::unique_ptr<Expr> value_to_assign, ExprType expr_kind, location_t locus)
234 : : OperatorExpr (std::move (mappings), std::move (value_to_assign_to),
235 697 : AST::AttrVec (), locus),
236 697 : expr_type (expr_kind), right_expr (std::move (value_to_assign))
237 697 : {}
238 :
239 0 : CompoundAssignmentExpr::CompoundAssignmentExpr (
240 : CompoundAssignmentExpr const &other)
241 0 : : OperatorExpr (other), expr_type (other.expr_type),
242 0 : right_expr (other.right_expr->clone_expr ())
243 0 : {}
244 :
245 : CompoundAssignmentExpr &
246 0 : CompoundAssignmentExpr::operator= (CompoundAssignmentExpr const &other)
247 : {
248 0 : OperatorExpr::operator= (other);
249 0 : right_expr = other.right_expr->clone_expr ();
250 0 : expr_type = other.expr_type;
251 :
252 0 : return *this;
253 : }
254 :
255 315 : GroupedExpr::GroupedExpr (Analysis::NodeMapping mappings,
256 : std::unique_ptr<Expr> parenthesised_expr,
257 : AST::AttrVec inner_attribs,
258 : AST::AttrVec outer_attribs, location_t locus)
259 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
260 : WithInnerAttrs (std::move (inner_attribs)),
261 315 : expr_in_parens (std::move (parenthesised_expr)), locus (locus)
262 315 : {}
263 :
264 0 : GroupedExpr::GroupedExpr (GroupedExpr const &other)
265 0 : : ExprWithoutBlock (other), WithInnerAttrs (other.inner_attrs),
266 0 : expr_in_parens (other.expr_in_parens->clone_expr ()), locus (other.locus)
267 0 : {}
268 :
269 : GroupedExpr &
270 0 : GroupedExpr::operator= (GroupedExpr const &other)
271 : {
272 0 : ExprWithoutBlock::operator= (other);
273 0 : inner_attrs = other.inner_attrs;
274 0 : expr_in_parens = other.expr_in_parens->clone_expr ();
275 0 : locus = other.locus;
276 :
277 0 : return *this;
278 : }
279 :
280 312 : ArrayElemsValues::ArrayElemsValues (Analysis::NodeMapping mappings,
281 : std::vector<std::unique_ptr<Expr>> elems)
282 312 : : ArrayElems (mappings), values (std::move (elems))
283 312 : {}
284 :
285 0 : ArrayElemsValues::ArrayElemsValues (ArrayElemsValues const &other)
286 0 : : ArrayElems (other)
287 : {
288 0 : values.reserve (other.values.size ());
289 0 : for (const auto &e : other.values)
290 0 : values.push_back (e->clone_expr ());
291 0 : }
292 :
293 : ArrayElemsValues &
294 0 : ArrayElemsValues::operator= (ArrayElemsValues const &other)
295 : {
296 0 : values.reserve (other.values.size ());
297 0 : for (const auto &e : other.values)
298 0 : values.push_back (e->clone_expr ());
299 :
300 0 : return *this;
301 : }
302 :
303 122 : ArrayElemsCopied::ArrayElemsCopied (Analysis::NodeMapping mappings,
304 : std::unique_ptr<Expr> copied_elem,
305 : std::unique_ptr<Expr> copy_amount)
306 122 : : ArrayElems (mappings), elem_to_copy (std::move (copied_elem)),
307 122 : num_copies (std::move (copy_amount))
308 122 : {}
309 :
310 0 : ArrayElemsCopied::ArrayElemsCopied (ArrayElemsCopied const &other)
311 0 : : ArrayElems (other), elem_to_copy (other.elem_to_copy->clone_expr ()),
312 0 : num_copies (other.num_copies->clone_expr ())
313 0 : {}
314 :
315 : ArrayElemsCopied &
316 0 : ArrayElemsCopied::operator= (ArrayElemsCopied const &other)
317 : {
318 0 : elem_to_copy = other.elem_to_copy->clone_expr ();
319 0 : num_copies = other.num_copies->clone_expr ();
320 :
321 0 : return *this;
322 : }
323 :
324 434 : ArrayExpr::ArrayExpr (Analysis::NodeMapping mappings,
325 : std::unique_ptr<ArrayElems> array_elems,
326 : AST::AttrVec inner_attribs, AST::AttrVec outer_attribs,
327 : location_t locus)
328 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
329 : WithInnerAttrs (std::move (inner_attribs)),
330 434 : internal_elements (std::move (array_elems)), locus (locus)
331 434 : {}
332 :
333 0 : ArrayExpr::ArrayExpr (ArrayExpr const &other)
334 0 : : ExprWithoutBlock (other), WithInnerAttrs (other.inner_attrs),
335 0 : locus (other.locus)
336 : {
337 0 : if (other.has_array_elems ())
338 0 : internal_elements = other.internal_elements->clone_array_elems ();
339 0 : }
340 :
341 : ArrayExpr &
342 0 : ArrayExpr::operator= (ArrayExpr const &other)
343 : {
344 0 : ExprWithoutBlock::operator= (other);
345 0 : inner_attrs = other.inner_attrs;
346 0 : if (other.has_array_elems ())
347 0 : internal_elements = other.internal_elements->clone_array_elems ();
348 0 : locus = other.locus;
349 :
350 0 : return *this;
351 : }
352 :
353 291 : ArrayIndexExpr::ArrayIndexExpr (Analysis::NodeMapping mappings,
354 : std::unique_ptr<Expr> array_expr,
355 : std::unique_ptr<Expr> array_index_expr,
356 : AST::AttrVec outer_attribs, location_t locus)
357 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
358 291 : array_expr (std::move (array_expr)),
359 291 : index_expr (std::move (array_index_expr)), locus (locus)
360 291 : {}
361 :
362 0 : ArrayIndexExpr::ArrayIndexExpr (ArrayIndexExpr const &other)
363 0 : : ExprWithoutBlock (other), array_expr (other.array_expr->clone_expr ()),
364 0 : index_expr (other.index_expr->clone_expr ()), locus (other.locus)
365 0 : {}
366 :
367 : ArrayIndexExpr &
368 0 : ArrayIndexExpr::operator= (ArrayIndexExpr const &other)
369 : {
370 0 : ExprWithoutBlock::operator= (other);
371 0 : array_expr = other.array_expr->clone_expr ();
372 0 : index_expr = other.index_expr->clone_expr ();
373 0 : locus = other.locus;
374 :
375 0 : return *this;
376 : }
377 :
378 591 : TupleExpr::TupleExpr (Analysis::NodeMapping mappings,
379 : std::vector<std::unique_ptr<Expr>> tuple_elements,
380 : AST::AttrVec inner_attribs, AST::AttrVec outer_attribs,
381 : location_t locus)
382 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
383 : WithInnerAttrs (std::move (inner_attribs)),
384 591 : tuple_elems (std::move (tuple_elements)), locus (locus)
385 591 : {}
386 :
387 0 : TupleExpr::TupleExpr (TupleExpr const &other)
388 0 : : ExprWithoutBlock (other), WithInnerAttrs (other.inner_attrs),
389 0 : locus (other.locus)
390 : {
391 0 : tuple_elems.reserve (other.tuple_elems.size ());
392 0 : for (const auto &e : other.tuple_elems)
393 0 : tuple_elems.push_back (e->clone_expr ());
394 0 : }
395 :
396 : TupleExpr &
397 0 : TupleExpr::operator= (TupleExpr const &other)
398 : {
399 0 : ExprWithoutBlock::operator= (other);
400 0 : inner_attrs = other.inner_attrs;
401 0 : locus = other.locus;
402 :
403 0 : tuple_elems.reserve (other.tuple_elems.size ());
404 0 : for (const auto &e : other.tuple_elems)
405 0 : tuple_elems.push_back (e->clone_expr ());
406 :
407 0 : return *this;
408 : }
409 :
410 900 : TupleIndexExpr::TupleIndexExpr (Analysis::NodeMapping mappings,
411 : std::unique_ptr<Expr> tuple_expr,
412 : TupleIndex index, AST::AttrVec outer_attribs,
413 : location_t locus)
414 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
415 900 : tuple_expr (std::move (tuple_expr)), tuple_index (index), locus (locus)
416 900 : {}
417 :
418 0 : TupleIndexExpr::TupleIndexExpr (TupleIndexExpr const &other)
419 0 : : ExprWithoutBlock (other), tuple_expr (other.tuple_expr->clone_expr ()),
420 0 : tuple_index (other.tuple_index), locus (other.locus)
421 0 : {}
422 :
423 : TupleIndexExpr &
424 0 : TupleIndexExpr::operator= (TupleIndexExpr const &other)
425 : {
426 0 : ExprWithoutBlock::operator= (other);
427 0 : tuple_expr = other.tuple_expr->clone_expr ();
428 0 : tuple_index = other.tuple_index;
429 0 : locus = other.locus;
430 : // outer_attrs = other.outer_attrs;
431 :
432 0 : return *this;
433 : }
434 :
435 1463 : StructExpr::StructExpr (Analysis::NodeMapping mappings,
436 : PathInExpression struct_path,
437 : AST::AttrVec outer_attribs)
438 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
439 1463 : struct_name (std::move (struct_path))
440 1463 : {}
441 :
442 1463 : StructExprStruct::StructExprStruct (Analysis::NodeMapping mappings,
443 : PathInExpression struct_path,
444 : AST::AttrVec inner_attribs,
445 : AST::AttrVec outer_attribs,
446 : location_t locus)
447 : : StructExpr (std::move (mappings), std::move (struct_path),
448 : std::move (outer_attribs)),
449 1463 : WithInnerAttrs (std::move (inner_attribs)), locus (locus)
450 1463 : {}
451 :
452 63 : StructBase::StructBase (std::unique_ptr<Expr> base_struct_ptr)
453 63 : : base_struct (std::move (base_struct_ptr))
454 63 : {}
455 :
456 0 : StructBase::StructBase (StructBase const &other)
457 : {
458 : /* HACK: gets around base_struct pointer being null (e.g. if no struct base
459 : * exists) */
460 0 : if (other.base_struct != nullptr)
461 0 : other.base_struct->clone_expr ();
462 0 : }
463 :
464 : StructBase &
465 0 : StructBase::operator= (StructBase const &other)
466 : {
467 0 : base_struct = other.base_struct->clone_expr ();
468 :
469 0 : return *this;
470 : }
471 :
472 2977 : StructExprField::StructExprField (Analysis::NodeMapping mapping,
473 : location_t locus)
474 2977 : : mappings (mapping), locus (locus)
475 2977 : {}
476 :
477 230 : StructExprFieldIdentifier::StructExprFieldIdentifier (
478 : Analysis::NodeMapping mapping, Identifier field_identifier, location_t locus)
479 230 : : StructExprField (mapping, locus), field_name (std::move (field_identifier))
480 230 : {}
481 :
482 2747 : StructExprFieldWithVal::StructExprFieldWithVal (
483 : Analysis::NodeMapping mapping, std::unique_ptr<Expr> field_value,
484 : location_t locus)
485 2747 : : StructExprField (mapping, locus), value (std::move (field_value))
486 2747 : {}
487 :
488 0 : StructExprFieldWithVal::StructExprFieldWithVal (
489 : StructExprFieldWithVal const &other)
490 0 : : StructExprField (other.mappings, other.locus),
491 0 : value (other.value->clone_expr ())
492 0 : {}
493 :
494 : StructExprFieldWithVal &
495 0 : StructExprFieldWithVal::operator= (StructExprFieldWithVal const &other)
496 : {
497 0 : value = other.value->clone_expr ();
498 0 : mappings = other.mappings;
499 0 : locus = other.locus;
500 :
501 0 : return *this;
502 : }
503 :
504 2703 : StructExprFieldIdentifierValue::StructExprFieldIdentifierValue (
505 : Analysis::NodeMapping mapping, Identifier field_identifier,
506 : std::unique_ptr<Expr> field_value, location_t locus)
507 : : StructExprFieldWithVal (mapping, std::move (field_value), locus),
508 2703 : field_name (std::move (field_identifier))
509 2703 : {}
510 :
511 44 : StructExprFieldIndexValue::StructExprFieldIndexValue (
512 : Analysis::NodeMapping mapping, TupleIndex tuple_index,
513 : std::unique_ptr<Expr> field_value, location_t locus)
514 : : StructExprFieldWithVal (mapping, std::move (field_value), locus),
515 44 : index (tuple_index)
516 44 : {}
517 :
518 1382 : StructExprStructFields::StructExprStructFields (
519 : Analysis::NodeMapping mappings, PathInExpression struct_path,
520 : std::vector<std::unique_ptr<StructExprField>> expr_fields, location_t locus,
521 : tl::optional<std::unique_ptr<StructBase>> base_struct,
522 : AST::AttrVec inner_attribs = AST::AttrVec (),
523 : AST::AttrVec outer_attribs = AST::AttrVec ())
524 : : StructExprStruct (std::move (mappings), std::move (struct_path),
525 : std::move (inner_attribs), std::move (outer_attribs),
526 : locus),
527 1382 : fields (std::move (expr_fields)), struct_base (std::move (base_struct))
528 1382 : {}
529 :
530 0 : StructExprStructFields::StructExprStructFields (
531 : StructExprStructFields const &other)
532 : : StructExprStruct (other),
533 0 : struct_base (other.has_struct_base ()
534 0 : ? tl::optional<std::unique_ptr<StructBase>> (
535 0 : std::make_unique<StructBase> (*other.struct_base.value ()))
536 : : tl::nullopt),
537 0 : union_index (other.union_index)
538 : {
539 0 : fields.reserve (other.fields.size ());
540 0 : for (const auto &e : other.fields)
541 0 : fields.push_back (e->clone_struct_expr_field ());
542 0 : }
543 :
544 : StructExprStructFields &
545 0 : StructExprStructFields::operator= (StructExprStructFields const &other)
546 : {
547 0 : StructExprStruct::operator= (other);
548 0 : struct_base = other.has_struct_base ()
549 0 : ? tl::optional<std::unique_ptr<StructBase>> (
550 0 : std::make_unique<StructBase> (*other.struct_base.value ()))
551 0 : : tl::nullopt;
552 0 : union_index = other.union_index;
553 :
554 0 : fields.reserve (other.fields.size ());
555 0 : for (const auto &e : other.fields)
556 0 : fields.push_back (e->clone_struct_expr_field ());
557 :
558 0 : return *this;
559 : }
560 :
561 0 : StructExprStructBase::StructExprStructBase (Analysis::NodeMapping mappings,
562 : PathInExpression struct_path,
563 : StructBase base_struct,
564 : AST::AttrVec inner_attribs,
565 : AST::AttrVec outer_attribs,
566 : location_t locus)
567 : : StructExprStruct (std::move (mappings), std::move (struct_path),
568 : std::move (inner_attribs), std::move (outer_attribs),
569 : locus),
570 0 : struct_base (std::move (base_struct))
571 0 : {}
572 :
573 12689 : CallExpr::CallExpr (Analysis::NodeMapping mappings,
574 : std::unique_ptr<Expr> function_expr,
575 : std::vector<std::unique_ptr<Expr>> function_params,
576 : AST::AttrVec outer_attribs, location_t locus)
577 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
578 12689 : function (std::move (function_expr)), params (std::move (function_params)),
579 12689 : locus (locus)
580 12689 : {}
581 :
582 8 : CallExpr::CallExpr (CallExpr const &other)
583 16 : : ExprWithoutBlock (other), function (other.function->clone_expr ()),
584 8 : locus (other.locus)
585 : /*, params(other.params),*/ {
586 8 : params.reserve (other.params.size ());
587 8 : for (const auto &e : other.params)
588 0 : params.push_back (e->clone_expr ());
589 8 : }
590 :
591 : CallExpr &
592 0 : CallExpr::operator= (CallExpr const &other)
593 : {
594 0 : ExprWithoutBlock::operator= (other);
595 0 : function = other.function->clone_expr ();
596 0 : locus = other.locus;
597 :
598 0 : params.reserve (other.params.size ());
599 0 : for (const auto &e : other.params)
600 0 : params.push_back (e->clone_expr ());
601 :
602 0 : return *this;
603 : }
604 :
605 3052 : MethodCallExpr::MethodCallExpr (
606 : Analysis::NodeMapping mappings, std::unique_ptr<Expr> call_receiver,
607 : PathExprSegment method_path, std::vector<std::unique_ptr<Expr>> method_params,
608 : AST::AttrVec outer_attribs, location_t locus)
609 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
610 3052 : receiver (std::move (call_receiver)), method_name (std::move (method_path)),
611 3052 : params (std::move (method_params)), locus (locus)
612 3052 : {}
613 :
614 0 : MethodCallExpr::MethodCallExpr (MethodCallExpr const &other)
615 0 : : ExprWithoutBlock (other), receiver (other.receiver->clone_expr ()),
616 0 : method_name (other.method_name), locus (other.locus)
617 : /*, params(other.params),*/ {
618 0 : params.reserve (other.params.size ());
619 0 : for (const auto &e : other.params)
620 0 : params.push_back (e->clone_expr ());
621 0 : }
622 :
623 : MethodCallExpr &
624 0 : MethodCallExpr::operator= (MethodCallExpr const &other)
625 : {
626 0 : ExprWithoutBlock::operator= (other);
627 0 : receiver = other.receiver->clone_expr ();
628 0 : method_name = other.method_name;
629 0 : locus = other.locus;
630 :
631 0 : params.reserve (other.params.size ());
632 0 : for (const auto &e : other.params)
633 0 : params.push_back (e->clone_expr ());
634 :
635 0 : return *this;
636 : }
637 :
638 5676 : FieldAccessExpr::FieldAccessExpr (Analysis::NodeMapping mappings,
639 : std::unique_ptr<Expr> field_access_receiver,
640 : Identifier field_name,
641 : AST::AttrVec outer_attribs, location_t locus)
642 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
643 5676 : receiver (std::move (field_access_receiver)),
644 5676 : field (std::move (field_name)), locus (locus)
645 5676 : {}
646 :
647 0 : FieldAccessExpr::FieldAccessExpr (FieldAccessExpr const &other)
648 0 : : ExprWithoutBlock (other), receiver (other.receiver->clone_expr ()),
649 0 : field (other.field), locus (other.locus)
650 0 : {}
651 :
652 : FieldAccessExpr &
653 0 : FieldAccessExpr::operator= (FieldAccessExpr const &other)
654 : {
655 0 : ExprWithoutBlock::operator= (other);
656 0 : receiver = other.receiver->clone_expr ();
657 0 : field = other.field;
658 0 : locus = other.locus;
659 :
660 0 : return *this;
661 : }
662 :
663 61 : ClosureParam::ClosureParam (std::unique_ptr<Pattern> param_pattern,
664 : location_t locus, std::unique_ptr<Type> param_type,
665 : std::vector<AST::Attribute> outer_attrs)
666 61 : : outer_attrs (std::move (outer_attrs)), pattern (std::move (param_pattern)),
667 61 : type (std::move (param_type)), locus (locus)
668 61 : {}
669 :
670 0 : ClosureParam::ClosureParam (ClosureParam const &other)
671 0 : : pattern (other.pattern->clone_pattern ())
672 : {
673 : // guard to protect from null pointer dereference
674 0 : if (other.pattern != nullptr)
675 0 : pattern = other.pattern->clone_pattern ();
676 0 : if (other.type != nullptr)
677 0 : type = other.type->clone_type ();
678 0 : }
679 :
680 : ClosureParam &
681 0 : ClosureParam::operator= (ClosureParam const &other)
682 : {
683 0 : outer_attrs = other.outer_attrs;
684 :
685 : // guard to protect from null pointer dereference
686 0 : if (other.pattern != nullptr)
687 0 : pattern = other.pattern->clone_pattern ();
688 : else
689 0 : pattern = nullptr;
690 0 : if (other.type != nullptr)
691 0 : type = other.type->clone_type ();
692 : else
693 0 : type = nullptr;
694 :
695 0 : return *this;
696 : }
697 :
698 66 : ClosureExpr::ClosureExpr (Analysis::NodeMapping mappings,
699 : std::vector<ClosureParam> closure_params,
700 : std::unique_ptr<Type> closure_return_type,
701 : std::unique_ptr<Expr> closure_expr, bool has_move,
702 : AST::AttrVec outer_attribs, location_t locus)
703 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
704 66 : has_move (has_move), params (std::move (closure_params)), locus (locus),
705 66 : return_type (std::move (closure_return_type)),
706 66 : expr (std::move (closure_expr))
707 66 : {}
708 :
709 0 : ClosureExpr::ClosureExpr (ClosureExpr const &other)
710 0 : : ExprWithoutBlock (other.get_mappings (), other.get_outer_attrs ())
711 : {
712 0 : return_type
713 0 : = other.has_return_type () ? other.return_type->clone_type () : nullptr;
714 0 : expr = other.expr->clone_expr ();
715 0 : params = other.params;
716 0 : has_move = other.has_move;
717 0 : }
718 :
719 : ClosureExpr &
720 0 : ClosureExpr::operator= (ClosureExpr const &other)
721 : {
722 0 : mappings = other.mappings;
723 0 : return_type
724 0 : = other.has_return_type () ? other.return_type->clone_type () : nullptr;
725 0 : expr = other.expr->clone_expr ();
726 0 : params = other.params;
727 0 : has_move = other.has_move;
728 :
729 0 : return *this;
730 : }
731 :
732 23517 : BlockExpr::BlockExpr (Analysis::NodeMapping mappings,
733 : std::vector<std::unique_ptr<Stmt>> block_statements,
734 : std::unique_ptr<Expr> block_expr, bool tail_reachable,
735 : AST::AttrVec inner_attribs, AST::AttrVec outer_attribs,
736 : tl::optional<LoopLabel> label, location_t start_locus,
737 : location_t end_locus)
738 : : ExprWithBlock (std::move (mappings), std::move (outer_attribs)),
739 : WithInnerAttrs (std::move (inner_attribs)),
740 23517 : statements (std::move (block_statements)), expr (std::move (block_expr)),
741 23517 : tail_reachable (tail_reachable), label (std::move (label)),
742 23517 : start_locus (start_locus), end_locus (end_locus)
743 23517 : {}
744 :
745 41 : BlockExpr::BlockExpr (BlockExpr const &other)
746 : : ExprWithBlock (other), /*statements(other.statements),*/
747 41 : WithInnerAttrs (other.inner_attrs), label (other.label),
748 41 : start_locus (other.start_locus), end_locus (other.end_locus)
749 : {
750 : // guard to protect from null pointer dereference
751 41 : if (other.expr != nullptr)
752 40 : expr = other.expr->clone_expr ();
753 :
754 41 : statements.reserve (other.statements.size ());
755 70 : for (const auto &e : other.statements)
756 29 : statements.push_back (e->clone_stmt ());
757 41 : }
758 :
759 : BlockExpr &
760 0 : BlockExpr::operator= (BlockExpr const &other)
761 : {
762 0 : ExprWithBlock::operator= (other);
763 0 : expr = other.expr->clone_expr ();
764 0 : inner_attrs = other.inner_attrs;
765 0 : start_locus = other.end_locus;
766 0 : end_locus = other.end_locus;
767 0 : statements.reserve (other.statements.size ());
768 :
769 0 : for (const auto &e : other.statements)
770 0 : statements.push_back (e->clone_stmt ());
771 :
772 0 : return *this;
773 : }
774 :
775 685 : AnonConst::AnonConst (Analysis::NodeMapping mappings,
776 : std::unique_ptr<Expr> &&expr, location_t locus)
777 685 : : ExprWithBlock (std::move (mappings), {}), locus (locus),
778 685 : kind (Kind::Explicit), expr (std::move (expr))
779 : {
780 685 : rust_assert (this->expr.value ());
781 685 : }
782 :
783 13 : AnonConst::AnonConst (Analysis::NodeMapping mappings, location_t locus)
784 13 : : ExprWithBlock (std::move (mappings), {}), locus (locus),
785 13 : kind (Kind::DeferredInference), expr (tl::nullopt)
786 13 : {}
787 :
788 28 : AnonConst::AnonConst (const AnonConst &other)
789 28 : : ExprWithBlock (other), locus (other.locus), kind (other.kind)
790 : {
791 28 : if (other.expr)
792 21 : expr = other.expr.value ()->clone_expr ();
793 28 : }
794 :
795 : AnonConst
796 0 : AnonConst::operator= (const AnonConst &other)
797 : {
798 0 : ExprWithBlock::operator= (other);
799 :
800 0 : locus = other.locus;
801 0 : kind = other.kind;
802 :
803 0 : if (other.expr)
804 0 : expr = other.expr.value ()->clone_expr ();
805 :
806 0 : return *this;
807 : }
808 :
809 15 : ConstBlock::ConstBlock (Analysis::NodeMapping mappings, AnonConst &&expr,
810 : location_t locus, AST::AttrVec outer_attrs)
811 : : ExprWithBlock (std::move (mappings), std::move (outer_attrs)),
812 15 : expr (std::move (expr)), locus (locus)
813 15 : {}
814 :
815 0 : ConstBlock::ConstBlock (const ConstBlock &other)
816 0 : : ExprWithBlock (other), expr (other.expr), locus (other.locus)
817 0 : {}
818 :
819 : ConstBlock
820 0 : ConstBlock::operator= (const ConstBlock &other)
821 : {
822 0 : ExprWithBlock::operator= (other);
823 :
824 0 : expr = other.expr;
825 0 : locus = other.locus;
826 :
827 0 : return *this;
828 : }
829 :
830 25 : ContinueExpr::ContinueExpr (Analysis::NodeMapping mappings, location_t locus,
831 : tl::optional<Lifetime> label,
832 : AST::AttrVec outer_attribs)
833 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
834 25 : label (std::move (label)), locus (locus)
835 25 : {}
836 :
837 105 : BreakExpr::BreakExpr (Analysis::NodeMapping mappings, location_t locus,
838 : tl::optional<Lifetime> break_label,
839 : std::unique_ptr<Expr> expr_in_break,
840 : AST::AttrVec outer_attribs)
841 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
842 210 : label (std::move (break_label)), break_expr (std::move (expr_in_break)),
843 105 : locus (locus)
844 105 : {}
845 :
846 0 : BreakExpr::BreakExpr (BreakExpr const &other)
847 0 : : ExprWithoutBlock (other), label (other.label), locus (other.locus)
848 : {
849 : // guard to protect from null pointer dereference
850 0 : if (other.break_expr != nullptr)
851 0 : break_expr = other.break_expr->clone_expr ();
852 0 : }
853 :
854 : BreakExpr &
855 0 : BreakExpr::operator= (BreakExpr const &other)
856 : {
857 0 : ExprWithoutBlock::operator= (other);
858 0 : label = other.label;
859 0 : break_expr = other.break_expr->clone_expr ();
860 0 : locus = other.locus;
861 :
862 0 : return *this;
863 : }
864 :
865 80 : RangeExpr::RangeExpr (Analysis::NodeMapping mappings, location_t locus)
866 80 : : ExprWithoutBlock (std::move (mappings), AST::AttrVec ()), locus (locus)
867 80 : {}
868 :
869 66 : RangeFromToExpr::RangeFromToExpr (Analysis::NodeMapping mappings,
870 : std::unique_ptr<Expr> range_from,
871 : std::unique_ptr<Expr> range_to,
872 : location_t locus)
873 66 : : RangeExpr (std::move (mappings), locus), from (std::move (range_from)),
874 66 : to (std::move (range_to))
875 66 : {}
876 :
877 0 : RangeFromToExpr::RangeFromToExpr (RangeFromToExpr const &other)
878 0 : : RangeExpr (other), from (other.from->clone_expr ()),
879 0 : to (other.to->clone_expr ())
880 0 : {}
881 :
882 : RangeFromToExpr &
883 0 : RangeFromToExpr::operator= (RangeFromToExpr const &other)
884 : {
885 0 : RangeExpr::operator= (other);
886 0 : from = other.from->clone_expr ();
887 0 : to = other.to->clone_expr ();
888 :
889 0 : return *this;
890 : }
891 :
892 7 : RangeFromExpr::RangeFromExpr (Analysis::NodeMapping mappings,
893 : std::unique_ptr<Expr> range_from,
894 : location_t locus)
895 7 : : RangeExpr (std::move (mappings), locus), from (std::move (range_from))
896 7 : {}
897 :
898 0 : RangeFromExpr::RangeFromExpr (RangeFromExpr const &other)
899 0 : : RangeExpr (other), from (other.from->clone_expr ())
900 0 : {}
901 :
902 : RangeFromExpr &
903 0 : RangeFromExpr::operator= (RangeFromExpr const &other)
904 : {
905 0 : RangeExpr::operator= (other);
906 0 : from = other.from->clone_expr ();
907 :
908 0 : return *this;
909 : }
910 :
911 7 : RangeToExpr::RangeToExpr (Analysis::NodeMapping mappings,
912 : std::unique_ptr<Expr> range_to, location_t locus)
913 7 : : RangeExpr (std::move (mappings), locus), to (std::move (range_to))
914 7 : {}
915 :
916 0 : RangeToExpr::RangeToExpr (RangeToExpr const &other)
917 0 : : RangeExpr (other), to (other.to->clone_expr ())
918 0 : {}
919 :
920 : RangeToExpr &
921 0 : RangeToExpr::operator= (RangeToExpr const &other)
922 : {
923 0 : RangeExpr::operator= (other);
924 0 : to = other.to->clone_expr ();
925 :
926 0 : return *this;
927 : }
928 :
929 0 : RangeFullExpr::RangeFullExpr (Analysis::NodeMapping mappings, location_t locus)
930 0 : : RangeExpr (std::move (mappings), locus)
931 0 : {}
932 :
933 0 : RangeToInclExpr::RangeToInclExpr (Analysis::NodeMapping mappings,
934 : std::unique_ptr<Expr> range_to,
935 : location_t locus)
936 0 : : RangeExpr (std::move (mappings), locus), to (std::move (range_to))
937 0 : {}
938 :
939 0 : RangeToInclExpr::RangeToInclExpr (RangeToInclExpr const &other)
940 0 : : RangeExpr (other), to (other.to->clone_expr ())
941 0 : {}
942 :
943 : RangeToInclExpr &
944 0 : RangeToInclExpr::operator= (RangeToInclExpr const &other)
945 : {
946 0 : RangeExpr::operator= (other);
947 0 : to = other.to->clone_expr ();
948 :
949 0 : return *this;
950 : }
951 :
952 3 : BoxExpr::BoxExpr (Analysis::NodeMapping mappings, location_t locus,
953 : std::unique_ptr<Expr> expr, AST::AttrVec outer_attribs)
954 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
955 3 : expr (std::move (expr)), locus (locus)
956 : {
957 3 : rust_assert (this->expr != nullptr);
958 3 : }
959 :
960 0 : BoxExpr::BoxExpr (BoxExpr const &other)
961 0 : : ExprWithoutBlock (other), locus (other.locus)
962 : {
963 0 : rust_assert (other.expr != nullptr);
964 0 : expr = other.expr->clone_expr ();
965 0 : }
966 :
967 : BoxExpr &
968 0 : BoxExpr::operator= (BoxExpr const &other)
969 : {
970 0 : ExprWithoutBlock::operator= (other);
971 :
972 0 : rust_assert (other.expr != nullptr);
973 0 : expr = other.expr->clone_expr ();
974 0 : locus = other.locus;
975 :
976 0 : return *this;
977 : }
978 :
979 559 : ReturnExpr::ReturnExpr (Analysis::NodeMapping mappings, location_t locus,
980 : std::unique_ptr<Expr> returned_expr,
981 : AST::AttrVec outer_attribs)
982 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
983 559 : return_expr (std::move (returned_expr)), locus (locus)
984 559 : {}
985 :
986 0 : ReturnExpr::ReturnExpr (ReturnExpr const &other)
987 0 : : ExprWithoutBlock (other), locus (other.locus)
988 : {
989 : // guard to protect from null pointer dereference
990 0 : if (other.return_expr != nullptr)
991 0 : return_expr = other.return_expr->clone_expr ();
992 0 : }
993 :
994 : ReturnExpr &
995 0 : ReturnExpr::operator= (ReturnExpr const &other)
996 : {
997 0 : ExprWithoutBlock::operator= (other);
998 0 : return_expr = other.return_expr->clone_expr ();
999 0 : locus = other.locus;
1000 :
1001 0 : return *this;
1002 : }
1003 :
1004 3700 : UnsafeBlockExpr::UnsafeBlockExpr (Analysis::NodeMapping mappings,
1005 : std::unique_ptr<BlockExpr> block_expr,
1006 : AST::AttrVec outer_attribs, location_t locus)
1007 : : ExprWithBlock (std::move (mappings), std::move (outer_attribs)),
1008 3700 : expr (std::move (block_expr)), locus (locus)
1009 3700 : {}
1010 :
1011 0 : UnsafeBlockExpr::UnsafeBlockExpr (UnsafeBlockExpr const &other)
1012 0 : : ExprWithBlock (other), expr (other.expr->clone_block_expr ()),
1013 0 : locus (other.locus)
1014 0 : {}
1015 :
1016 : UnsafeBlockExpr &
1017 0 : UnsafeBlockExpr::operator= (UnsafeBlockExpr const &other)
1018 : {
1019 0 : ExprWithBlock::operator= (other);
1020 0 : expr = other.expr->clone_block_expr ();
1021 0 : locus = other.locus;
1022 :
1023 0 : return *this;
1024 : }
1025 :
1026 221 : BaseLoopExpr::BaseLoopExpr (Analysis::NodeMapping mappings,
1027 : std::unique_ptr<BlockExpr> loop_block,
1028 : location_t locus,
1029 : tl::optional<LoopLabel> loop_label,
1030 : AST::AttrVec outer_attribs)
1031 : : ExprWithBlock (std::move (mappings), std::move (outer_attribs)),
1032 442 : loop_label (std::move (loop_label)), loop_block (std::move (loop_block)),
1033 221 : locus (locus)
1034 221 : {}
1035 :
1036 0 : BaseLoopExpr::BaseLoopExpr (BaseLoopExpr const &other)
1037 0 : : ExprWithBlock (other), loop_label (other.loop_label),
1038 0 : loop_block (other.loop_block->clone_block_expr ()), locus (other.locus)
1039 0 : {}
1040 :
1041 : BaseLoopExpr &
1042 0 : BaseLoopExpr::operator= (BaseLoopExpr const &other)
1043 : {
1044 0 : ExprWithBlock::operator= (other);
1045 0 : loop_block = other.loop_block->clone_block_expr ();
1046 0 : loop_label = other.loop_label;
1047 0 : locus = other.locus;
1048 :
1049 0 : return *this;
1050 : }
1051 :
1052 137 : LoopExpr::LoopExpr (Analysis::NodeMapping mappings,
1053 : std::unique_ptr<BlockExpr> loop_block, location_t locus,
1054 : tl::optional<LoopLabel> loop_label,
1055 : AST::AttrVec outer_attribs)
1056 : : BaseLoopExpr (std::move (mappings), std::move (loop_block), locus,
1057 180 : std::move (loop_label), std::move (outer_attribs))
1058 137 : {}
1059 :
1060 84 : WhileLoopExpr::WhileLoopExpr (Analysis::NodeMapping mappings,
1061 : std::unique_ptr<Expr> loop_condition,
1062 : std::unique_ptr<BlockExpr> loop_block,
1063 : location_t locus,
1064 : tl::optional<LoopLabel> loop_label,
1065 : AST::AttrVec outer_attribs)
1066 : : BaseLoopExpr (std::move (mappings), std::move (loop_block), locus,
1067 : std::move (loop_label), std::move (outer_attribs)),
1068 91 : condition (std::move (loop_condition))
1069 84 : {}
1070 :
1071 0 : WhileLoopExpr::WhileLoopExpr (WhileLoopExpr const &other)
1072 0 : : BaseLoopExpr (other), condition (other.condition->clone_expr ())
1073 0 : {}
1074 :
1075 : WhileLoopExpr &
1076 0 : WhileLoopExpr::operator= (WhileLoopExpr const &other)
1077 : {
1078 0 : BaseLoopExpr::operator= (other);
1079 0 : condition = other.condition->clone_expr ();
1080 0 : return *this;
1081 : }
1082 :
1083 0 : WhileLetLoopExpr::WhileLetLoopExpr (Analysis::NodeMapping mappings,
1084 : std::unique_ptr<Pattern> match_arm_pattern,
1085 : std::unique_ptr<Expr> condition,
1086 : std::unique_ptr<BlockExpr> loop_block,
1087 : location_t locus,
1088 : tl::optional<LoopLabel> loop_label,
1089 : AST::AttrVec outer_attribs)
1090 : : BaseLoopExpr (std::move (mappings), std::move (loop_block), locus,
1091 : std::move (loop_label), std::move (outer_attribs)),
1092 0 : match_arm_pattern (std::move (match_arm_pattern)),
1093 0 : condition (std::move (condition))
1094 0 : {}
1095 :
1096 0 : WhileLetLoopExpr::WhileLetLoopExpr (WhileLetLoopExpr const &other)
1097 : : BaseLoopExpr (other),
1098 0 : match_arm_pattern (other.match_arm_pattern->clone_pattern ()),
1099 0 : condition (other.condition->clone_expr ())
1100 0 : {}
1101 :
1102 : WhileLetLoopExpr &
1103 0 : WhileLetLoopExpr::operator= (WhileLetLoopExpr const &other)
1104 : {
1105 0 : BaseLoopExpr::operator= (other);
1106 0 : condition = other.condition->clone_expr ();
1107 0 : match_arm_pattern = other.match_arm_pattern->clone_pattern ();
1108 :
1109 0 : return *this;
1110 : }
1111 :
1112 2514 : IfExpr::IfExpr (Analysis::NodeMapping mappings, std::unique_ptr<Expr> condition,
1113 : std::unique_ptr<BlockExpr> if_block, location_t locus)
1114 2514 : : ExprWithBlock (std::move (mappings), AST::AttrVec ()),
1115 2514 : condition (std::move (condition)), if_block (std::move (if_block)),
1116 2514 : locus (locus)
1117 2514 : {}
1118 :
1119 0 : IfExpr::IfExpr (IfExpr const &other)
1120 0 : : ExprWithBlock (other), condition (other.condition->clone_expr ()),
1121 0 : if_block (other.if_block->clone_block_expr ()), locus (other.locus)
1122 0 : {}
1123 :
1124 : IfExpr &
1125 0 : IfExpr::operator= (IfExpr const &other)
1126 : {
1127 0 : ExprWithBlock::operator= (other);
1128 0 : condition = other.condition->clone_expr ();
1129 0 : if_block = other.if_block->clone_block_expr ();
1130 0 : locus = other.locus;
1131 :
1132 0 : return *this;
1133 : }
1134 :
1135 1262 : IfExprConseqElse::IfExprConseqElse (Analysis::NodeMapping mappings,
1136 : std::unique_ptr<Expr> condition,
1137 : std::unique_ptr<BlockExpr> if_block,
1138 : std::unique_ptr<ExprWithBlock> else_block,
1139 : location_t locus)
1140 : : IfExpr (std::move (mappings), std::move (condition), std::move (if_block),
1141 : locus),
1142 1262 : else_block (std::move (else_block))
1143 1262 : {}
1144 :
1145 0 : IfExprConseqElse::IfExprConseqElse (IfExprConseqElse const &other)
1146 0 : : IfExpr (other), else_block (other.else_block->clone_expr_with_block ())
1147 0 : {}
1148 :
1149 : IfExprConseqElse &
1150 0 : IfExprConseqElse::operator= (IfExprConseqElse const &other)
1151 : {
1152 0 : IfExpr::operator= (other);
1153 : // condition = other.condition->clone_expr();
1154 : // if_block = other.if_block->clone_block_expr();
1155 0 : else_block = other.else_block->clone_expr_with_block ();
1156 :
1157 0 : return *this;
1158 : }
1159 :
1160 2565 : MatchArm::MatchArm (std::unique_ptr<Pattern> match_arm_pattern,
1161 : location_t locus, std::unique_ptr<Expr> guard_expr,
1162 : AST::AttrVec outer_attrs)
1163 2565 : : outer_attrs (std::move (outer_attrs)),
1164 2565 : match_arm_pattern (std::move (match_arm_pattern)),
1165 2565 : guard_expr (std::move (guard_expr)), locus (locus)
1166 2565 : {}
1167 :
1168 3361 : MatchArm::MatchArm (MatchArm const &other) : outer_attrs (other.outer_attrs)
1169 : {
1170 : // guard to protect from null pointer dereference
1171 3361 : if (other.guard_expr != nullptr)
1172 0 : guard_expr = other.guard_expr->clone_expr ();
1173 :
1174 3361 : match_arm_pattern = other.match_arm_pattern->clone_pattern ();
1175 :
1176 3361 : locus = other.locus;
1177 3361 : }
1178 :
1179 : MatchArm &
1180 0 : MatchArm::operator= (MatchArm const &other)
1181 : {
1182 0 : outer_attrs = other.outer_attrs;
1183 :
1184 0 : if (other.guard_expr != nullptr)
1185 0 : guard_expr = other.guard_expr->clone_expr ();
1186 :
1187 0 : match_arm_pattern = other.match_arm_pattern->clone_pattern ();
1188 :
1189 0 : return *this;
1190 : }
1191 :
1192 2565 : MatchCase::MatchCase (Analysis::NodeMapping mappings, MatchArm arm,
1193 : std::unique_ptr<Expr> expr)
1194 2565 : : mappings (mappings), arm (std::move (arm)), expr (std::move (expr))
1195 2565 : {}
1196 :
1197 0 : MatchCase::MatchCase (const MatchCase &other)
1198 0 : : mappings (other.mappings), arm (other.arm), expr (other.expr->clone_expr ())
1199 0 : {}
1200 :
1201 : MatchCase &
1202 0 : MatchCase::operator= (const MatchCase &other)
1203 : {
1204 0 : mappings = other.mappings;
1205 0 : arm = other.arm;
1206 0 : expr = other.expr->clone_expr ();
1207 :
1208 0 : return *this;
1209 : }
1210 :
1211 1109 : MatchExpr::MatchExpr (Analysis::NodeMapping mappings,
1212 : std::unique_ptr<Expr> branch_value,
1213 : std::vector<MatchCase> match_arms,
1214 : AST::AttrVec inner_attrs, AST::AttrVec outer_attrs,
1215 : location_t locus)
1216 : : ExprWithBlock (std::move (mappings), std::move (outer_attrs)),
1217 : WithInnerAttrs (std::move (inner_attrs)),
1218 1109 : branch_value (std::move (branch_value)),
1219 1109 : match_arms (std::move (match_arms)), locus (locus)
1220 1109 : {}
1221 :
1222 0 : MatchExpr::MatchExpr (MatchExpr const &other)
1223 0 : : ExprWithBlock (other), WithInnerAttrs (other.inner_attrs),
1224 0 : branch_value (other.branch_value->clone_expr ()),
1225 0 : match_arms (other.match_arms), locus (other.locus)
1226 : {
1227 : /*match_arms.reserve (other.match_arms.size ());
1228 : for (const auto &e : other.match_arms)
1229 : match_arms.push_back (e->clone_match_case ());*/
1230 0 : }
1231 :
1232 : MatchExpr &
1233 0 : MatchExpr::operator= (MatchExpr const &other)
1234 : {
1235 0 : ExprWithBlock::operator= (other);
1236 0 : branch_value = other.branch_value->clone_expr ();
1237 0 : inner_attrs = other.inner_attrs;
1238 0 : match_arms = other.match_arms;
1239 0 : locus = other.locus;
1240 :
1241 : /*match_arms.reserve (other.match_arms.size ());
1242 : for (const auto &e : other.match_arms)
1243 : match_arms.push_back (e->clone_match_case ());*/
1244 :
1245 0 : return *this;
1246 : }
1247 :
1248 0 : AwaitExpr::AwaitExpr (Analysis::NodeMapping mappings,
1249 : std::unique_ptr<Expr> awaited_expr,
1250 : AST::AttrVec outer_attrs, location_t locus)
1251 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attrs)),
1252 0 : awaited_expr (std::move (awaited_expr)), locus (locus)
1253 0 : {}
1254 :
1255 0 : AwaitExpr::AwaitExpr (AwaitExpr const &other)
1256 0 : : ExprWithoutBlock (other), awaited_expr (other.awaited_expr->clone_expr ()),
1257 0 : locus (other.locus)
1258 0 : {}
1259 :
1260 : AwaitExpr &
1261 0 : AwaitExpr::operator= (AwaitExpr const &other)
1262 : {
1263 0 : ExprWithoutBlock::operator= (other);
1264 0 : awaited_expr = other.awaited_expr->clone_expr ();
1265 0 : locus = other.locus;
1266 :
1267 0 : return *this;
1268 : }
1269 :
1270 0 : AsyncBlockExpr::AsyncBlockExpr (Analysis::NodeMapping mappings,
1271 : std::unique_ptr<BlockExpr> block_expr,
1272 : bool has_move, AST::AttrVec outer_attrs,
1273 : location_t locus)
1274 : : ExprWithBlock (std::move (mappings), std::move (outer_attrs)),
1275 0 : has_move (has_move), block_expr (std::move (block_expr)), locus (locus)
1276 0 : {}
1277 :
1278 0 : AsyncBlockExpr::AsyncBlockExpr (AsyncBlockExpr const &other)
1279 0 : : ExprWithBlock (other), has_move (other.has_move),
1280 0 : block_expr (other.block_expr->clone_block_expr ()), locus (other.locus)
1281 0 : {}
1282 :
1283 : AsyncBlockExpr &
1284 0 : AsyncBlockExpr::operator= (AsyncBlockExpr const &other)
1285 : {
1286 0 : ExprWithBlock::operator= (other);
1287 0 : has_move = other.has_move;
1288 0 : block_expr = other.block_expr->clone_block_expr ();
1289 0 : locus = other.locus;
1290 :
1291 0 : return *this;
1292 : }
1293 :
1294 711 : OperatorExprMeta::OperatorExprMeta (HIR::CompoundAssignmentExpr &expr)
1295 711 : : node_mappings (expr.get_mappings ()),
1296 711 : lvalue_mappings (expr.get_expr ().get_mappings ()),
1297 711 : rvalue_mappings (expr.get_rhs ().get_mappings ()), locus (expr.get_locus ())
1298 711 : {}
1299 :
1300 3581 : OperatorExprMeta::OperatorExprMeta (HIR::ArithmeticOrLogicalExpr &expr)
1301 3581 : : node_mappings (expr.get_mappings ()),
1302 3581 : lvalue_mappings (expr.get_expr ().get_mappings ()),
1303 3581 : rvalue_mappings (expr.get_rhs ().get_mappings ()), locus (expr.get_locus ())
1304 3581 : {}
1305 :
1306 701 : OperatorExprMeta::OperatorExprMeta (HIR::NegationExpr &expr)
1307 701 : : node_mappings (expr.get_mappings ()),
1308 701 : lvalue_mappings (expr.get_expr ().get_mappings ()),
1309 701 : rvalue_mappings (Analysis::NodeMapping::get_error ()),
1310 701 : locus (expr.get_locus ())
1311 701 : {}
1312 :
1313 3968 : OperatorExprMeta::OperatorExprMeta (HIR::DereferenceExpr &expr)
1314 3968 : : node_mappings (expr.get_mappings ()),
1315 3968 : lvalue_mappings (expr.get_expr ().get_mappings ()),
1316 3968 : rvalue_mappings (Analysis::NodeMapping::get_error ()),
1317 3968 : locus (expr.get_locus ())
1318 3968 : {}
1319 :
1320 128 : OperatorExprMeta::OperatorExprMeta (HIR::ArrayIndexExpr &expr)
1321 128 : : node_mappings (expr.get_mappings ()),
1322 128 : lvalue_mappings (expr.get_array_expr ().get_mappings ()),
1323 128 : rvalue_mappings (expr.get_index_expr ().get_mappings ()),
1324 128 : locus (expr.get_locus ())
1325 128 : {}
1326 :
1327 4406 : OperatorExprMeta::OperatorExprMeta (HIR::ComparisonExpr &expr)
1328 4406 : : node_mappings (expr.get_mappings ()),
1329 4406 : lvalue_mappings (expr.get_expr ().get_mappings ()),
1330 4406 : rvalue_mappings (expr.get_rhs ().get_mappings ()), locus (expr.get_locus ())
1331 4406 : {}
1332 :
1333 10 : InlineAsmOperand::In::In (
1334 : const tl::optional<struct AST::InlineAsmRegOrRegClass> ®,
1335 : std::unique_ptr<Expr> expr)
1336 10 : : reg (reg), expr (std::move (expr))
1337 : {
1338 10 : rust_assert (this->expr != nullptr);
1339 10 : }
1340 :
1341 48 : InlineAsmOperand::In::In (const struct In &other)
1342 : {
1343 48 : reg = other.reg;
1344 :
1345 48 : expr = other.expr->clone_expr ();
1346 48 : }
1347 :
1348 : InlineAsmOperand::In
1349 0 : InlineAsmOperand::In::operator= (const struct In &other)
1350 : {
1351 0 : reg = other.reg;
1352 0 : expr = other.expr->clone_expr ();
1353 :
1354 0 : return *this;
1355 : }
1356 :
1357 17 : InlineAsmOperand::Out::Out (
1358 : tl::optional<struct AST::InlineAsmRegOrRegClass> ®, bool late,
1359 : std::unique_ptr<Expr> expr)
1360 17 : : reg (reg), late (late), expr (std::move (expr))
1361 : {
1362 17 : rust_assert (this->expr != nullptr);
1363 17 : }
1364 :
1365 69 : InlineAsmOperand::Out::Out (const struct Out &other)
1366 : {
1367 69 : reg = other.reg;
1368 69 : late = other.late;
1369 69 : expr = other.expr->clone_expr ();
1370 69 : }
1371 :
1372 : InlineAsmOperand::Out
1373 0 : InlineAsmOperand::Out::operator= (const struct Out &other)
1374 : {
1375 0 : reg = other.reg;
1376 0 : late = other.late;
1377 0 : expr = other.expr->clone_expr ();
1378 0 : return *this;
1379 : }
1380 :
1381 0 : InlineAsmOperand::InOut::InOut (
1382 : tl::optional<struct AST::InlineAsmRegOrRegClass> ®, bool late,
1383 : std::unique_ptr<Expr> expr)
1384 0 : : reg (reg), late (late), expr (std::move (expr))
1385 : {
1386 0 : rust_assert (this->expr != nullptr);
1387 0 : }
1388 :
1389 0 : InlineAsmOperand::InOut::InOut (const struct InOut &other)
1390 : {
1391 0 : reg = other.reg;
1392 0 : late = other.late;
1393 0 : expr = other.expr->clone_expr ();
1394 0 : }
1395 :
1396 : InlineAsmOperand::InOut
1397 0 : InlineAsmOperand::InOut::operator= (const struct InOut &other)
1398 : {
1399 0 : reg = other.reg;
1400 0 : late = other.late;
1401 0 : expr = other.expr->clone_expr ();
1402 :
1403 0 : return *this;
1404 : }
1405 :
1406 2 : InlineAsmOperand::SplitInOut::SplitInOut (
1407 : tl::optional<struct AST::InlineAsmRegOrRegClass> ®, bool late,
1408 : std::unique_ptr<Expr> in_expr, std::unique_ptr<Expr> out_expr)
1409 2 : : reg (reg), late (late), in_expr (std::move (in_expr)),
1410 2 : out_expr (std::move (out_expr))
1411 : {
1412 2 : rust_assert (this->in_expr != nullptr);
1413 2 : rust_assert (this->out_expr != nullptr);
1414 2 : }
1415 :
1416 8 : InlineAsmOperand::SplitInOut::SplitInOut (const struct SplitInOut &other)
1417 : {
1418 8 : reg = other.reg;
1419 8 : late = other.late;
1420 8 : in_expr = other.in_expr->clone_expr ();
1421 8 : out_expr = other.out_expr->clone_expr ();
1422 8 : }
1423 :
1424 : InlineAsmOperand::SplitInOut
1425 0 : InlineAsmOperand::SplitInOut::operator= (const struct SplitInOut &other)
1426 : {
1427 0 : reg = other.reg;
1428 0 : late = other.late;
1429 0 : in_expr = other.in_expr->clone_expr ();
1430 0 : out_expr = other.out_expr->clone_expr ();
1431 :
1432 0 : return *this;
1433 : }
1434 :
1435 0 : InlineAsmOperand::Sym::Sym (std::unique_ptr<Expr> expr)
1436 0 : : expr (std::move (expr))
1437 : {
1438 0 : rust_assert (this->expr != nullptr);
1439 0 : }
1440 :
1441 0 : InlineAsmOperand::Sym::Sym (const struct Sym &other)
1442 : {
1443 0 : expr = std::unique_ptr<Expr> (other.expr->clone_expr ());
1444 0 : }
1445 :
1446 : InlineAsmOperand::Sym
1447 0 : InlineAsmOperand::Sym::operator= (const struct Sym &other)
1448 : {
1449 0 : expr = std::unique_ptr<Expr> (other.expr->clone_expr ());
1450 0 : return *this;
1451 : }
1452 :
1453 0 : InlineAsmOperand::Label::Label (tl::optional<std::string> label_name,
1454 : std::unique_ptr<Expr> expr)
1455 0 : : expr (std::move (expr))
1456 : {
1457 0 : rust_assert (this->expr != nullptr);
1458 0 : if (label_name.has_value ())
1459 0 : this->label_name = label_name.value ();
1460 0 : }
1461 :
1462 0 : InlineAsmOperand::Label::Label (const struct Label &other)
1463 : {
1464 0 : expr = std::unique_ptr<Expr> (other.expr->clone_expr ());
1465 0 : }
1466 :
1467 : InlineAsmOperand::Label
1468 0 : InlineAsmOperand::Label::operator= (const struct Label &other)
1469 : {
1470 0 : expr = std::unique_ptr<Expr> (other.expr->clone_expr ());
1471 0 : return *this;
1472 : }
1473 :
1474 27 : InlineAsm::InlineAsm (location_t locus, bool is_global_asm,
1475 : std::vector<AST::InlineAsmTemplatePiece> template_,
1476 : std::vector<AST::TupleTemplateStr> template_strs,
1477 : std::vector<HIR::InlineAsmOperand> operands,
1478 : std::vector<AST::TupleClobber> clobber_abi,
1479 : std::set<AST::InlineAsm::Option> options,
1480 : Analysis::NodeMapping mappings,
1481 : AST::AttrVec outer_attribs)
1482 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
1483 27 : locus (locus), is_global_asm (is_global_asm),
1484 27 : template_ (std::move (template_)),
1485 27 : template_strs (std::move (template_strs)), operands (std::move (operands)),
1486 27 : clobber_abi (std::move (clobber_abi)), options (std::move (options))
1487 27 : {}
1488 :
1489 : OffsetOf &
1490 0 : OffsetOf::operator= (const OffsetOf &other)
1491 : {
1492 0 : ExprWithoutBlock::operator= (other);
1493 :
1494 0 : type = other.type->clone_type ();
1495 0 : field = other.field;
1496 0 : loc = other.loc;
1497 :
1498 0 : return *this;
1499 : }
1500 :
1501 : ExprWithoutBlock *
1502 0 : OffsetOf::clone_expr_without_block_impl () const
1503 : {
1504 0 : return new OffsetOf (*this);
1505 : }
1506 :
1507 : std::string
1508 0 : OffsetOf::to_string () const
1509 : {
1510 0 : return "OffsetOf(" + type->to_string () + ", " + field.as_string () + ")";
1511 : }
1512 :
1513 : void
1514 44 : OffsetOf::accept_vis (HIRExpressionVisitor &vis)
1515 : {
1516 44 : vis.visit (*this);
1517 44 : }
1518 :
1519 : void
1520 59 : OffsetOf::accept_vis (HIRFullVisitor &vis)
1521 : {
1522 59 : vis.visit (*this);
1523 59 : }
1524 :
1525 : } // namespace HIR
1526 : } // namespace Rust
|