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 164009 : Expr::Expr (Analysis::NodeMapping mappings, AST::AttrVec outer_attribs)
29 164009 : : outer_attrs (std::move (outer_attribs)), mappings (std::move (mappings))
30 164009 : {}
31 :
32 129851 : ExprWithoutBlock::ExprWithoutBlock (Analysis::NodeMapping mappings,
33 : AST::AttrVec outer_attribs)
34 129851 : : Expr (std::move (mappings), std::move (outer_attribs))
35 129851 : {}
36 :
37 54 : LoopLabel::LoopLabel (Analysis::NodeMapping mapping, Lifetime loop_label,
38 : location_t locus)
39 54 : : label (std::move (loop_label)), locus (locus), mappings (mapping)
40 54 : {}
41 :
42 34158 : ExprWithBlock::ExprWithBlock (Analysis::NodeMapping mappings,
43 : AST::AttrVec outer_attrs)
44 34158 : : Expr (std::move (mappings), std::move (outer_attrs))
45 34158 : {}
46 :
47 1359 : 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 1359 : literal (std::move (value_as_string), type, type_hint), locus (locus)
53 1359 : {}
54 :
55 21842 : 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 21842 : literal (std::move (literal)), locus (locus)
59 21842 : {}
60 :
61 23975 : 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 23975 : locus (locus), main_or_left_expr (std::move (main_or_left_expr))
66 23975 : {}
67 :
68 6767 : OperatorExpr::OperatorExpr (OperatorExpr const &other)
69 6767 : : ExprWithoutBlock (other), locus (other.locus),
70 6767 : main_or_left_expr (other.main_or_left_expr->clone_expr ())
71 6767 : {}
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 2155 : 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 2155 : mut (mut), raw (raw)
89 2155 : {}
90 :
91 4284 : 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 4284 : std::move (outer_attribs), locus)
96 4284 : {}
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 707 : 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 707 : expr_type (expr_kind)
112 707 : {}
113 :
114 3721 : 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 3721 : : OperatorExpr (std::move (mappings), std::move (left_value), AST::AttrVec (),
118 : locus),
119 3721 : expr_type (expr_kind), right_expr (std::move (right_value))
120 3721 : {}
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 3742 : 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 3742 : : OperatorExpr (std::move (mappings), std::move (left_value), AST::AttrVec (),
143 : locus),
144 3742 : expr_type (comparison_kind), right_expr (std::move (right_value))
145 3742 : {}
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 425 : 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 425 : AST::AttrVec (), locus),
168 425 : expr_type (expr_kind), right_expr (std::move (right_bool_expr))
169 425 : {}
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 5690 : 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 5690 : AST::AttrVec (), locus),
192 5690 : type_to_convert_to (std::move (type_to_cast_to))
193 5690 : {}
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 2546 : 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 2546 : AST::AttrVec (), locus),
215 2546 : right_expr (std::move (value_to_assign))
216 2546 : {}
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 705 : 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 705 : AST::AttrVec (), locus),
236 705 : expr_type (expr_kind), right_expr (std::move (value_to_assign))
237 705 : {}
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 368 : 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 368 : expr_in_parens (std::move (parenthesised_expr)), locus (locus)
262 368 : {}
263 :
264 1 : GroupedExpr::GroupedExpr (GroupedExpr const &other)
265 1 : : ExprWithoutBlock (other), WithInnerAttrs (other.inner_attrs),
266 1 : expr_in_parens (other.expr_in_parens->clone_expr ()), locus (other.locus)
267 1 : {}
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 319 : ArrayElemsValues::ArrayElemsValues (Analysis::NodeMapping mappings,
281 : std::vector<std::unique_ptr<Expr>> elems)
282 319 : : ArrayElems (mappings), values (std::move (elems))
283 319 : {}
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 133 : ArrayElemsCopied::ArrayElemsCopied (Analysis::NodeMapping mappings,
304 : std::unique_ptr<Expr> copied_elem,
305 : std::unique_ptr<Expr> copy_amount)
306 133 : : ArrayElems (mappings), elem_to_copy (std::move (copied_elem)),
307 133 : num_copies (std::move (copy_amount))
308 133 : {}
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 452 : 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 452 : internal_elements (std::move (array_elems)), locus (locus)
331 452 : {}
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 297 : 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 297 : array_expr (std::move (array_expr)),
359 297 : index_expr (std::move (array_index_expr)), locus (locus)
360 297 : {}
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 643 : 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 643 : tuple_elems (std::move (tuple_elements)), locus (locus)
385 643 : {}
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 921 : 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 921 : tuple_expr (std::move (tuple_expr)), tuple_index (index), locus (locus)
416 921 : {}
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 1526 : StructExpr::StructExpr (Analysis::NodeMapping mappings,
436 : PathInExpression struct_path,
437 : AST::AttrVec outer_attribs)
438 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
439 1526 : struct_name (std::move (struct_path))
440 1526 : {}
441 :
442 1526 : 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 1526 : WithInnerAttrs (std::move (inner_attribs)), locus (locus)
450 1526 : {}
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 3053 : StructExprField::StructExprField (Analysis::NodeMapping mapping,
473 : location_t locus)
474 3053 : : mappings (mapping), locus (locus)
475 3053 : {}
476 :
477 237 : StructExprFieldIdentifier::StructExprFieldIdentifier (
478 : Analysis::NodeMapping mapping, Identifier field_identifier, location_t locus)
479 237 : : StructExprField (mapping, locus), field_name (std::move (field_identifier))
480 237 : {}
481 :
482 2816 : StructExprFieldWithVal::StructExprFieldWithVal (
483 : Analysis::NodeMapping mapping, std::unique_ptr<Expr> field_value,
484 : location_t locus)
485 2816 : : StructExprField (mapping, locus), value (std::move (field_value))
486 2816 : {}
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 2772 : 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 2772 : field_name (std::move (field_identifier))
509 2772 : {}
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 1445 : 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 1445 : fields (std::move (expr_fields)), struct_base (std::move (base_struct))
528 1445 : {}
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 13589 : 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 13589 : function (std::move (function_expr)), params (std::move (function_params)),
579 13589 : locus (locus)
580 13589 : {}
581 :
582 9 : CallExpr::CallExpr (CallExpr const &other)
583 18 : : ExprWithoutBlock (other), function (other.function->clone_expr ()),
584 9 : locus (other.locus)
585 : /*, params(other.params),*/ {
586 9 : params.reserve (other.params.size ());
587 9 : for (const auto &e : other.params)
588 0 : params.push_back (e->clone_expr ());
589 9 : }
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 3158 : 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 3158 : receiver (std::move (call_receiver)), method_name (std::move (method_path)),
611 3158 : params (std::move (method_params)), locus (locus)
612 3158 : {}
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 5737 : 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 5737 : receiver (std::move (field_access_receiver)),
644 5737 : field (std::move (field_name)), locus (locus)
645 5737 : {}
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 ()), locus (other.locus)
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 : locus = other.locus;
696 :
697 0 : return *this;
698 : }
699 :
700 67 : ClosureExpr::ClosureExpr (Analysis::NodeMapping mappings,
701 : std::vector<ClosureParam> closure_params,
702 : std::unique_ptr<Type> closure_return_type,
703 : std::unique_ptr<Expr> closure_expr, bool has_move,
704 : AST::AttrVec outer_attribs, location_t locus)
705 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
706 67 : has_move (has_move), params (std::move (closure_params)), locus (locus),
707 67 : return_type (std::move (closure_return_type)),
708 67 : expr (std::move (closure_expr))
709 67 : {}
710 :
711 1 : ClosureExpr::ClosureExpr (ClosureExpr const &other)
712 1 : : ExprWithoutBlock (other.get_mappings (), other.get_outer_attrs ())
713 : {
714 1 : return_type
715 1 : = other.has_return_type () ? other.return_type->clone_type () : nullptr;
716 1 : expr = other.expr->clone_expr ();
717 1 : params = other.params;
718 1 : has_move = other.has_move;
719 1 : locus = other.locus;
720 1 : }
721 :
722 : ClosureExpr &
723 0 : ClosureExpr::operator= (ClosureExpr const &other)
724 : {
725 0 : mappings = other.mappings;
726 0 : return_type
727 0 : = other.has_return_type () ? other.return_type->clone_type () : nullptr;
728 0 : expr = other.expr->clone_expr ();
729 0 : params = other.params;
730 0 : has_move = other.has_move;
731 0 : locus = other.locus;
732 :
733 0 : return *this;
734 : }
735 :
736 25316 : BlockExpr::BlockExpr (Analysis::NodeMapping mappings,
737 : std::vector<std::unique_ptr<Stmt>> block_statements,
738 : std::unique_ptr<Expr> block_expr, bool tail_reachable,
739 : AST::AttrVec inner_attribs, AST::AttrVec outer_attribs,
740 : tl::optional<LoopLabel> label, location_t start_locus,
741 : location_t end_locus)
742 : : ExprWithBlock (std::move (mappings), std::move (outer_attribs)),
743 : WithInnerAttrs (std::move (inner_attribs)),
744 25316 : statements (std::move (block_statements)), expr (std::move (block_expr)),
745 25316 : tail_reachable (tail_reachable), label (std::move (label)),
746 25316 : start_locus (start_locus), end_locus (end_locus)
747 25316 : {}
748 :
749 41 : BlockExpr::BlockExpr (BlockExpr const &other)
750 : : ExprWithBlock (other), /*statements(other.statements),*/
751 41 : WithInnerAttrs (other.inner_attrs), label (other.label),
752 41 : start_locus (other.start_locus), end_locus (other.end_locus)
753 : {
754 : // guard to protect from null pointer dereference
755 41 : if (other.expr != nullptr)
756 40 : expr = other.expr->clone_expr ();
757 :
758 41 : statements.reserve (other.statements.size ());
759 70 : for (const auto &e : other.statements)
760 29 : statements.push_back (e->clone_stmt ());
761 41 : }
762 :
763 : BlockExpr &
764 0 : BlockExpr::operator= (BlockExpr const &other)
765 : {
766 0 : ExprWithBlock::operator= (other);
767 0 : expr = other.expr->clone_expr ();
768 0 : inner_attrs = other.inner_attrs;
769 0 : start_locus = other.end_locus;
770 0 : end_locus = other.end_locus;
771 0 : statements.reserve (other.statements.size ());
772 :
773 0 : for (const auto &e : other.statements)
774 0 : statements.push_back (e->clone_stmt ());
775 :
776 0 : return *this;
777 : }
778 :
779 800 : AnonConst::AnonConst (Analysis::NodeMapping mappings,
780 : std::unique_ptr<Expr> &&expr, location_t locus)
781 800 : : ExprWithBlock (std::move (mappings), {}), locus (locus),
782 800 : kind (Kind::Explicit), expr (std::move (expr))
783 : {
784 800 : rust_assert (this->expr.value ());
785 800 : }
786 :
787 13 : AnonConst::AnonConst (Analysis::NodeMapping mappings, location_t locus)
788 13 : : ExprWithBlock (std::move (mappings), {}), locus (locus),
789 13 : kind (Kind::DeferredInference), expr (tl::nullopt)
790 13 : {}
791 :
792 78 : AnonConst::AnonConst (const AnonConst &other)
793 78 : : ExprWithBlock (other), locus (other.locus), kind (other.kind)
794 : {
795 78 : if (other.expr)
796 71 : expr = other.expr.value ()->clone_expr ();
797 78 : }
798 :
799 : AnonConst
800 0 : AnonConst::operator= (const AnonConst &other)
801 : {
802 0 : ExprWithBlock::operator= (other);
803 :
804 0 : locus = other.locus;
805 0 : kind = other.kind;
806 :
807 0 : if (other.expr)
808 0 : expr = other.expr.value ()->clone_expr ();
809 :
810 0 : return *this;
811 : }
812 :
813 15 : ConstBlock::ConstBlock (Analysis::NodeMapping mappings, AnonConst &&expr,
814 : location_t locus, AST::AttrVec outer_attrs)
815 : : ExprWithBlock (std::move (mappings), std::move (outer_attrs)),
816 15 : expr (std::move (expr)), locus (locus)
817 15 : {}
818 :
819 0 : ConstBlock::ConstBlock (const ConstBlock &other)
820 0 : : ExprWithBlock (other), expr (other.expr), locus (other.locus)
821 0 : {}
822 :
823 : ConstBlock
824 0 : ConstBlock::operator= (const ConstBlock &other)
825 : {
826 0 : ExprWithBlock::operator= (other);
827 :
828 0 : expr = other.expr;
829 0 : locus = other.locus;
830 :
831 0 : return *this;
832 : }
833 :
834 28 : ContinueExpr::ContinueExpr (Analysis::NodeMapping mappings, location_t locus,
835 : tl::optional<Lifetime> label,
836 : AST::AttrVec outer_attribs)
837 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
838 28 : label (std::move (label)), locus (locus)
839 28 : {}
840 :
841 120 : BreakExpr::BreakExpr (Analysis::NodeMapping mappings, location_t locus,
842 : tl::optional<Lifetime> break_label,
843 : std::unique_ptr<Expr> expr_in_break,
844 : AST::AttrVec outer_attribs)
845 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
846 240 : label (std::move (break_label)), break_expr (std::move (expr_in_break)),
847 120 : locus (locus)
848 120 : {}
849 :
850 0 : BreakExpr::BreakExpr (BreakExpr const &other)
851 0 : : ExprWithoutBlock (other), label (other.label), locus (other.locus)
852 : {
853 : // guard to protect from null pointer dereference
854 0 : if (other.break_expr != nullptr)
855 0 : break_expr = other.break_expr->clone_expr ();
856 0 : }
857 :
858 : BreakExpr &
859 0 : BreakExpr::operator= (BreakExpr const &other)
860 : {
861 0 : ExprWithoutBlock::operator= (other);
862 0 : label = other.label;
863 0 : break_expr = other.break_expr->clone_expr ();
864 0 : locus = other.locus;
865 :
866 0 : return *this;
867 : }
868 :
869 88 : RangeExpr::RangeExpr (Analysis::NodeMapping mappings, location_t locus)
870 88 : : ExprWithoutBlock (std::move (mappings), AST::AttrVec ()), locus (locus)
871 88 : {}
872 :
873 74 : RangeFromToExpr::RangeFromToExpr (Analysis::NodeMapping mappings,
874 : std::unique_ptr<Expr> range_from,
875 : std::unique_ptr<Expr> range_to,
876 : location_t locus)
877 74 : : RangeExpr (std::move (mappings), locus), from (std::move (range_from)),
878 74 : to (std::move (range_to))
879 74 : {}
880 :
881 0 : RangeFromToExpr::RangeFromToExpr (RangeFromToExpr const &other)
882 0 : : RangeExpr (other), from (other.from->clone_expr ()),
883 0 : to (other.to->clone_expr ())
884 0 : {}
885 :
886 : RangeFromToExpr &
887 0 : RangeFromToExpr::operator= (RangeFromToExpr const &other)
888 : {
889 0 : RangeExpr::operator= (other);
890 0 : from = other.from->clone_expr ();
891 0 : to = other.to->clone_expr ();
892 :
893 0 : return *this;
894 : }
895 :
896 7 : RangeFromExpr::RangeFromExpr (Analysis::NodeMapping mappings,
897 : std::unique_ptr<Expr> range_from,
898 : location_t locus)
899 7 : : RangeExpr (std::move (mappings), locus), from (std::move (range_from))
900 7 : {}
901 :
902 0 : RangeFromExpr::RangeFromExpr (RangeFromExpr const &other)
903 0 : : RangeExpr (other), from (other.from->clone_expr ())
904 0 : {}
905 :
906 : RangeFromExpr &
907 0 : RangeFromExpr::operator= (RangeFromExpr const &other)
908 : {
909 0 : RangeExpr::operator= (other);
910 0 : from = other.from->clone_expr ();
911 :
912 0 : return *this;
913 : }
914 :
915 7 : RangeToExpr::RangeToExpr (Analysis::NodeMapping mappings,
916 : std::unique_ptr<Expr> range_to, location_t locus)
917 7 : : RangeExpr (std::move (mappings), locus), to (std::move (range_to))
918 7 : {}
919 :
920 0 : RangeToExpr::RangeToExpr (RangeToExpr const &other)
921 0 : : RangeExpr (other), to (other.to->clone_expr ())
922 0 : {}
923 :
924 : RangeToExpr &
925 0 : RangeToExpr::operator= (RangeToExpr const &other)
926 : {
927 0 : RangeExpr::operator= (other);
928 0 : to = other.to->clone_expr ();
929 :
930 0 : return *this;
931 : }
932 :
933 0 : RangeFullExpr::RangeFullExpr (Analysis::NodeMapping mappings, location_t locus)
934 0 : : RangeExpr (std::move (mappings), locus)
935 0 : {}
936 :
937 0 : RangeToInclExpr::RangeToInclExpr (Analysis::NodeMapping mappings,
938 : std::unique_ptr<Expr> range_to,
939 : location_t locus)
940 0 : : RangeExpr (std::move (mappings), locus), to (std::move (range_to))
941 0 : {}
942 :
943 0 : RangeToInclExpr::RangeToInclExpr (RangeToInclExpr const &other)
944 0 : : RangeExpr (other), to (other.to->clone_expr ())
945 0 : {}
946 :
947 : RangeToInclExpr &
948 0 : RangeToInclExpr::operator= (RangeToInclExpr const &other)
949 : {
950 0 : RangeExpr::operator= (other);
951 0 : to = other.to->clone_expr ();
952 :
953 0 : return *this;
954 : }
955 :
956 6 : BoxExpr::BoxExpr (Analysis::NodeMapping mappings, location_t locus,
957 : std::unique_ptr<Expr> expr, AST::AttrVec outer_attribs)
958 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
959 6 : expr (std::move (expr)), locus (locus)
960 : {
961 6 : rust_assert (this->expr != nullptr);
962 6 : }
963 :
964 0 : BoxExpr::BoxExpr (BoxExpr const &other)
965 0 : : ExprWithoutBlock (other), locus (other.locus)
966 : {
967 0 : rust_assert (other.expr != nullptr);
968 0 : expr = other.expr->clone_expr ();
969 0 : }
970 :
971 : BoxExpr &
972 0 : BoxExpr::operator= (BoxExpr const &other)
973 : {
974 0 : ExprWithoutBlock::operator= (other);
975 :
976 0 : rust_assert (other.expr != nullptr);
977 0 : expr = other.expr->clone_expr ();
978 0 : locus = other.locus;
979 :
980 0 : return *this;
981 : }
982 :
983 579 : ReturnExpr::ReturnExpr (Analysis::NodeMapping mappings, location_t locus,
984 : std::unique_ptr<Expr> returned_expr,
985 : AST::AttrVec outer_attribs)
986 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
987 579 : return_expr (std::move (returned_expr)), locus (locus)
988 579 : {}
989 :
990 0 : ReturnExpr::ReturnExpr (ReturnExpr const &other)
991 0 : : ExprWithoutBlock (other), locus (other.locus)
992 : {
993 : // guard to protect from null pointer dereference
994 0 : if (other.return_expr != nullptr)
995 0 : return_expr = other.return_expr->clone_expr ();
996 0 : }
997 :
998 : ReturnExpr &
999 0 : ReturnExpr::operator= (ReturnExpr const &other)
1000 : {
1001 0 : ExprWithoutBlock::operator= (other);
1002 0 : return_expr = other.return_expr->clone_expr ();
1003 0 : locus = other.locus;
1004 :
1005 0 : return *this;
1006 : }
1007 :
1008 4000 : UnsafeBlockExpr::UnsafeBlockExpr (Analysis::NodeMapping mappings,
1009 : std::unique_ptr<BlockExpr> block_expr,
1010 : AST::AttrVec outer_attribs, location_t locus)
1011 : : ExprWithBlock (std::move (mappings), std::move (outer_attribs)),
1012 4000 : expr (std::move (block_expr)), locus (locus)
1013 4000 : {}
1014 :
1015 0 : UnsafeBlockExpr::UnsafeBlockExpr (UnsafeBlockExpr const &other)
1016 0 : : ExprWithBlock (other), expr (other.expr->clone_block_expr ()),
1017 0 : locus (other.locus)
1018 0 : {}
1019 :
1020 : UnsafeBlockExpr &
1021 0 : UnsafeBlockExpr::operator= (UnsafeBlockExpr const &other)
1022 : {
1023 0 : ExprWithBlock::operator= (other);
1024 0 : expr = other.expr->clone_block_expr ();
1025 0 : locus = other.locus;
1026 :
1027 0 : return *this;
1028 : }
1029 :
1030 246 : BaseLoopExpr::BaseLoopExpr (Analysis::NodeMapping mappings,
1031 : std::unique_ptr<BlockExpr> loop_block,
1032 : location_t locus,
1033 : tl::optional<LoopLabel> loop_label,
1034 : AST::AttrVec outer_attribs)
1035 : : ExprWithBlock (std::move (mappings), std::move (outer_attribs)),
1036 492 : loop_label (std::move (loop_label)), loop_block (std::move (loop_block)),
1037 246 : locus (locus)
1038 246 : {}
1039 :
1040 0 : BaseLoopExpr::BaseLoopExpr (BaseLoopExpr const &other)
1041 0 : : ExprWithBlock (other), loop_label (other.loop_label),
1042 0 : loop_block (other.loop_block->clone_block_expr ()), locus (other.locus)
1043 0 : {}
1044 :
1045 : BaseLoopExpr &
1046 0 : BaseLoopExpr::operator= (BaseLoopExpr const &other)
1047 : {
1048 0 : ExprWithBlock::operator= (other);
1049 0 : loop_block = other.loop_block->clone_block_expr ();
1050 0 : loop_label = other.loop_label;
1051 0 : locus = other.locus;
1052 :
1053 0 : return *this;
1054 : }
1055 :
1056 152 : LoopExpr::LoopExpr (Analysis::NodeMapping mappings,
1057 : std::unique_ptr<BlockExpr> loop_block, location_t locus,
1058 : tl::optional<LoopLabel> loop_label,
1059 : AST::AttrVec outer_attribs)
1060 : : BaseLoopExpr (std::move (mappings), std::move (loop_block), locus,
1061 196 : std::move (loop_label), std::move (outer_attribs))
1062 152 : {}
1063 :
1064 94 : WhileLoopExpr::WhileLoopExpr (Analysis::NodeMapping mappings,
1065 : std::unique_ptr<Expr> loop_condition,
1066 : std::unique_ptr<BlockExpr> loop_block,
1067 : location_t locus,
1068 : tl::optional<LoopLabel> loop_label,
1069 : AST::AttrVec outer_attribs)
1070 : : BaseLoopExpr (std::move (mappings), std::move (loop_block), locus,
1071 : std::move (loop_label), std::move (outer_attribs)),
1072 101 : condition (std::move (loop_condition))
1073 94 : {}
1074 :
1075 0 : WhileLoopExpr::WhileLoopExpr (WhileLoopExpr const &other)
1076 0 : : BaseLoopExpr (other), condition (other.condition->clone_expr ())
1077 0 : {}
1078 :
1079 : WhileLoopExpr &
1080 0 : WhileLoopExpr::operator= (WhileLoopExpr const &other)
1081 : {
1082 0 : BaseLoopExpr::operator= (other);
1083 0 : condition = other.condition->clone_expr ();
1084 0 : return *this;
1085 : }
1086 :
1087 0 : WhileLetLoopExpr::WhileLetLoopExpr (Analysis::NodeMapping mappings,
1088 : std::unique_ptr<Pattern> match_arm_pattern,
1089 : std::unique_ptr<Expr> condition,
1090 : std::unique_ptr<BlockExpr> loop_block,
1091 : location_t locus,
1092 : tl::optional<LoopLabel> loop_label,
1093 : AST::AttrVec outer_attribs)
1094 : : BaseLoopExpr (std::move (mappings), std::move (loop_block), locus,
1095 : std::move (loop_label), std::move (outer_attribs)),
1096 0 : match_arm_pattern (std::move (match_arm_pattern)),
1097 0 : condition (std::move (condition))
1098 0 : {}
1099 :
1100 0 : WhileLetLoopExpr::WhileLetLoopExpr (WhileLetLoopExpr const &other)
1101 : : BaseLoopExpr (other),
1102 0 : match_arm_pattern (other.match_arm_pattern->clone_pattern ()),
1103 0 : condition (other.condition->clone_expr ())
1104 0 : {}
1105 :
1106 : WhileLetLoopExpr &
1107 0 : WhileLetLoopExpr::operator= (WhileLetLoopExpr const &other)
1108 : {
1109 0 : BaseLoopExpr::operator= (other);
1110 0 : condition = other.condition->clone_expr ();
1111 0 : match_arm_pattern = other.match_arm_pattern->clone_pattern ();
1112 :
1113 0 : return *this;
1114 : }
1115 :
1116 2624 : IfExpr::IfExpr (Analysis::NodeMapping mappings, std::unique_ptr<Expr> condition,
1117 : std::unique_ptr<BlockExpr> if_block, location_t locus)
1118 2624 : : ExprWithBlock (std::move (mappings), AST::AttrVec ()),
1119 2624 : condition (std::move (condition)), if_block (std::move (if_block)),
1120 2624 : locus (locus)
1121 2624 : {}
1122 :
1123 0 : IfExpr::IfExpr (IfExpr const &other)
1124 0 : : ExprWithBlock (other), condition (other.condition->clone_expr ()),
1125 0 : if_block (other.if_block->clone_block_expr ()), locus (other.locus)
1126 0 : {}
1127 :
1128 : IfExpr &
1129 0 : IfExpr::operator= (IfExpr const &other)
1130 : {
1131 0 : ExprWithBlock::operator= (other);
1132 0 : condition = other.condition->clone_expr ();
1133 0 : if_block = other.if_block->clone_block_expr ();
1134 0 : locus = other.locus;
1135 :
1136 0 : return *this;
1137 : }
1138 :
1139 1339 : IfExprConseqElse::IfExprConseqElse (Analysis::NodeMapping mappings,
1140 : std::unique_ptr<Expr> condition,
1141 : std::unique_ptr<BlockExpr> if_block,
1142 : std::unique_ptr<ExprWithBlock> else_block,
1143 : location_t locus)
1144 : : IfExpr (std::move (mappings), std::move (condition), std::move (if_block),
1145 : locus),
1146 1339 : else_block (std::move (else_block))
1147 1339 : {}
1148 :
1149 0 : IfExprConseqElse::IfExprConseqElse (IfExprConseqElse const &other)
1150 0 : : IfExpr (other), else_block (other.else_block->clone_expr_with_block ())
1151 0 : {}
1152 :
1153 : IfExprConseqElse &
1154 0 : IfExprConseqElse::operator= (IfExprConseqElse const &other)
1155 : {
1156 0 : IfExpr::operator= (other);
1157 : // condition = other.condition->clone_expr();
1158 : // if_block = other.if_block->clone_block_expr();
1159 0 : else_block = other.else_block->clone_expr_with_block ();
1160 :
1161 0 : return *this;
1162 : }
1163 :
1164 2631 : MatchArm::MatchArm (std::unique_ptr<Pattern> match_arm_pattern,
1165 : location_t locus, std::unique_ptr<Expr> guard_expr,
1166 : AST::AttrVec outer_attrs)
1167 2631 : : outer_attrs (std::move (outer_attrs)),
1168 2631 : match_arm_pattern (std::move (match_arm_pattern)),
1169 2631 : guard_expr (std::move (guard_expr)), locus (locus)
1170 2631 : {}
1171 :
1172 3382 : MatchArm::MatchArm (MatchArm const &other) : outer_attrs (other.outer_attrs)
1173 : {
1174 : // guard to protect from null pointer dereference
1175 3382 : if (other.guard_expr != nullptr)
1176 0 : guard_expr = other.guard_expr->clone_expr ();
1177 :
1178 3382 : match_arm_pattern = other.match_arm_pattern->clone_pattern ();
1179 :
1180 3382 : locus = other.locus;
1181 3382 : }
1182 :
1183 : MatchArm &
1184 0 : MatchArm::operator= (MatchArm const &other)
1185 : {
1186 0 : outer_attrs = other.outer_attrs;
1187 :
1188 0 : if (other.guard_expr != nullptr)
1189 0 : guard_expr = other.guard_expr->clone_expr ();
1190 :
1191 0 : match_arm_pattern = other.match_arm_pattern->clone_pattern ();
1192 :
1193 0 : return *this;
1194 : }
1195 :
1196 2631 : MatchCase::MatchCase (Analysis::NodeMapping mappings, MatchArm arm,
1197 : std::unique_ptr<Expr> expr)
1198 2631 : : mappings (mappings), arm (std::move (arm)), expr (std::move (expr))
1199 2631 : {}
1200 :
1201 0 : MatchCase::MatchCase (const MatchCase &other)
1202 0 : : mappings (other.mappings), arm (other.arm), expr (other.expr->clone_expr ())
1203 0 : {}
1204 :
1205 : MatchCase &
1206 0 : MatchCase::operator= (const MatchCase &other)
1207 : {
1208 0 : mappings = other.mappings;
1209 0 : arm = other.arm;
1210 0 : expr = other.expr->clone_expr ();
1211 :
1212 0 : return *this;
1213 : }
1214 :
1215 1144 : MatchExpr::MatchExpr (Analysis::NodeMapping mappings,
1216 : std::unique_ptr<Expr> branch_value,
1217 : std::vector<MatchCase> match_arms,
1218 : AST::AttrVec inner_attrs, AST::AttrVec outer_attrs,
1219 : location_t locus)
1220 : : ExprWithBlock (std::move (mappings), std::move (outer_attrs)),
1221 : WithInnerAttrs (std::move (inner_attrs)),
1222 1144 : branch_value (std::move (branch_value)),
1223 1144 : match_arms (std::move (match_arms)), locus (locus)
1224 1144 : {}
1225 :
1226 0 : MatchExpr::MatchExpr (MatchExpr const &other)
1227 0 : : ExprWithBlock (other), WithInnerAttrs (other.inner_attrs),
1228 0 : branch_value (other.branch_value->clone_expr ()),
1229 0 : match_arms (other.match_arms), locus (other.locus)
1230 : {
1231 : /*match_arms.reserve (other.match_arms.size ());
1232 : for (const auto &e : other.match_arms)
1233 : match_arms.push_back (e->clone_match_case ());*/
1234 0 : }
1235 :
1236 : MatchExpr &
1237 0 : MatchExpr::operator= (MatchExpr const &other)
1238 : {
1239 0 : ExprWithBlock::operator= (other);
1240 0 : branch_value = other.branch_value->clone_expr ();
1241 0 : inner_attrs = other.inner_attrs;
1242 0 : match_arms = other.match_arms;
1243 0 : locus = other.locus;
1244 :
1245 : /*match_arms.reserve (other.match_arms.size ());
1246 : for (const auto &e : other.match_arms)
1247 : match_arms.push_back (e->clone_match_case ());*/
1248 :
1249 0 : return *this;
1250 : }
1251 :
1252 0 : AwaitExpr::AwaitExpr (Analysis::NodeMapping mappings,
1253 : std::unique_ptr<Expr> awaited_expr,
1254 : AST::AttrVec outer_attrs, location_t locus)
1255 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attrs)),
1256 0 : awaited_expr (std::move (awaited_expr)), locus (locus)
1257 0 : {}
1258 :
1259 0 : AwaitExpr::AwaitExpr (AwaitExpr const &other)
1260 0 : : ExprWithoutBlock (other), awaited_expr (other.awaited_expr->clone_expr ()),
1261 0 : locus (other.locus)
1262 0 : {}
1263 :
1264 : AwaitExpr &
1265 0 : AwaitExpr::operator= (AwaitExpr const &other)
1266 : {
1267 0 : ExprWithoutBlock::operator= (other);
1268 0 : awaited_expr = other.awaited_expr->clone_expr ();
1269 0 : locus = other.locus;
1270 :
1271 0 : return *this;
1272 : }
1273 :
1274 0 : AsyncBlockExpr::AsyncBlockExpr (Analysis::NodeMapping mappings,
1275 : std::unique_ptr<BlockExpr> block_expr,
1276 : bool has_move, AST::AttrVec outer_attrs,
1277 : location_t locus)
1278 : : ExprWithBlock (std::move (mappings), std::move (outer_attrs)),
1279 0 : has_move (has_move), block_expr (std::move (block_expr)), locus (locus)
1280 0 : {}
1281 :
1282 0 : AsyncBlockExpr::AsyncBlockExpr (AsyncBlockExpr const &other)
1283 0 : : ExprWithBlock (other), has_move (other.has_move),
1284 0 : block_expr (other.block_expr->clone_block_expr ()), locus (other.locus)
1285 0 : {}
1286 :
1287 : AsyncBlockExpr &
1288 0 : AsyncBlockExpr::operator= (AsyncBlockExpr const &other)
1289 : {
1290 0 : ExprWithBlock::operator= (other);
1291 0 : has_move = other.has_move;
1292 0 : block_expr = other.block_expr->clone_block_expr ();
1293 0 : locus = other.locus;
1294 :
1295 0 : return *this;
1296 : }
1297 :
1298 719 : OperatorExprMeta::OperatorExprMeta (HIR::CompoundAssignmentExpr &expr)
1299 719 : : node_mappings (expr.get_mappings ()),
1300 719 : lvalue_mappings (expr.get_expr ().get_mappings ()),
1301 719 : rvalue_mappings (expr.get_rhs ().get_mappings ()), locus (expr.get_locus ())
1302 719 : {}
1303 :
1304 3920 : OperatorExprMeta::OperatorExprMeta (HIR::ArithmeticOrLogicalExpr &expr)
1305 3920 : : node_mappings (expr.get_mappings ()),
1306 3920 : lvalue_mappings (expr.get_expr ().get_mappings ()),
1307 3920 : rvalue_mappings (expr.get_rhs ().get_mappings ()), locus (expr.get_locus ())
1308 3920 : {}
1309 :
1310 721 : OperatorExprMeta::OperatorExprMeta (HIR::NegationExpr &expr)
1311 721 : : node_mappings (expr.get_mappings ()),
1312 721 : lvalue_mappings (expr.get_expr ().get_mappings ()),
1313 721 : rvalue_mappings (Analysis::NodeMapping::get_error ()),
1314 721 : locus (expr.get_locus ())
1315 721 : {}
1316 :
1317 4331 : OperatorExprMeta::OperatorExprMeta (HIR::DereferenceExpr &expr)
1318 4331 : : node_mappings (expr.get_mappings ()),
1319 4331 : lvalue_mappings (expr.get_expr ().get_mappings ()),
1320 4331 : rvalue_mappings (Analysis::NodeMapping::get_error ()),
1321 4331 : locus (expr.get_locus ())
1322 4331 : {}
1323 :
1324 134 : OperatorExprMeta::OperatorExprMeta (HIR::ArrayIndexExpr &expr)
1325 134 : : node_mappings (expr.get_mappings ()),
1326 134 : lvalue_mappings (expr.get_array_expr ().get_mappings ()),
1327 134 : rvalue_mappings (expr.get_index_expr ().get_mappings ()),
1328 134 : locus (expr.get_locus ())
1329 134 : {}
1330 :
1331 4617 : OperatorExprMeta::OperatorExprMeta (HIR::ComparisonExpr &expr)
1332 4617 : : node_mappings (expr.get_mappings ()),
1333 4617 : lvalue_mappings (expr.get_expr ().get_mappings ()),
1334 4617 : rvalue_mappings (expr.get_rhs ().get_mappings ()), locus (expr.get_locus ())
1335 4617 : {}
1336 :
1337 10 : InlineAsmOperand::In::In (
1338 : const tl::optional<struct AST::InlineAsmRegOrRegClass> ®,
1339 : std::unique_ptr<Expr> expr)
1340 10 : : reg (reg), expr (std::move (expr))
1341 : {
1342 10 : rust_assert (this->expr != nullptr);
1343 10 : }
1344 :
1345 48 : InlineAsmOperand::In::In (const struct In &other)
1346 : {
1347 48 : reg = other.reg;
1348 :
1349 48 : expr = other.expr->clone_expr ();
1350 48 : }
1351 :
1352 : InlineAsmOperand::In
1353 0 : InlineAsmOperand::In::operator= (const struct In &other)
1354 : {
1355 0 : reg = other.reg;
1356 0 : expr = other.expr->clone_expr ();
1357 :
1358 0 : return *this;
1359 : }
1360 :
1361 17 : InlineAsmOperand::Out::Out (
1362 : tl::optional<struct AST::InlineAsmRegOrRegClass> ®, bool late,
1363 : std::unique_ptr<Expr> expr)
1364 17 : : reg (reg), late (late), expr (std::move (expr))
1365 : {
1366 17 : rust_assert (this->expr != nullptr);
1367 17 : }
1368 :
1369 69 : InlineAsmOperand::Out::Out (const struct Out &other)
1370 : {
1371 69 : reg = other.reg;
1372 69 : late = other.late;
1373 69 : expr = other.expr->clone_expr ();
1374 69 : }
1375 :
1376 : InlineAsmOperand::Out
1377 0 : InlineAsmOperand::Out::operator= (const struct Out &other)
1378 : {
1379 0 : reg = other.reg;
1380 0 : late = other.late;
1381 0 : expr = other.expr->clone_expr ();
1382 0 : return *this;
1383 : }
1384 :
1385 0 : InlineAsmOperand::InOut::InOut (
1386 : tl::optional<struct AST::InlineAsmRegOrRegClass> ®, bool late,
1387 : std::unique_ptr<Expr> expr)
1388 0 : : reg (reg), late (late), expr (std::move (expr))
1389 : {
1390 0 : rust_assert (this->expr != nullptr);
1391 0 : }
1392 :
1393 0 : InlineAsmOperand::InOut::InOut (const struct InOut &other)
1394 : {
1395 0 : reg = other.reg;
1396 0 : late = other.late;
1397 0 : expr = other.expr->clone_expr ();
1398 0 : }
1399 :
1400 : InlineAsmOperand::InOut
1401 0 : InlineAsmOperand::InOut::operator= (const struct InOut &other)
1402 : {
1403 0 : reg = other.reg;
1404 0 : late = other.late;
1405 0 : expr = other.expr->clone_expr ();
1406 :
1407 0 : return *this;
1408 : }
1409 :
1410 2 : InlineAsmOperand::SplitInOut::SplitInOut (
1411 : tl::optional<struct AST::InlineAsmRegOrRegClass> ®, bool late,
1412 : std::unique_ptr<Expr> in_expr, std::unique_ptr<Expr> out_expr)
1413 2 : : reg (reg), late (late), in_expr (std::move (in_expr)),
1414 2 : out_expr (std::move (out_expr))
1415 : {
1416 2 : rust_assert (this->in_expr != nullptr);
1417 2 : rust_assert (this->out_expr != nullptr);
1418 2 : }
1419 :
1420 8 : InlineAsmOperand::SplitInOut::SplitInOut (const struct SplitInOut &other)
1421 : {
1422 8 : reg = other.reg;
1423 8 : late = other.late;
1424 8 : in_expr = other.in_expr->clone_expr ();
1425 8 : out_expr = other.out_expr->clone_expr ();
1426 8 : }
1427 :
1428 : InlineAsmOperand::SplitInOut
1429 0 : InlineAsmOperand::SplitInOut::operator= (const struct SplitInOut &other)
1430 : {
1431 0 : reg = other.reg;
1432 0 : late = other.late;
1433 0 : in_expr = other.in_expr->clone_expr ();
1434 0 : out_expr = other.out_expr->clone_expr ();
1435 :
1436 0 : return *this;
1437 : }
1438 :
1439 0 : InlineAsmOperand::Sym::Sym (std::unique_ptr<Expr> expr)
1440 0 : : expr (std::move (expr))
1441 : {
1442 0 : rust_assert (this->expr != nullptr);
1443 0 : }
1444 :
1445 0 : InlineAsmOperand::Sym::Sym (const struct Sym &other)
1446 : {
1447 0 : expr = std::unique_ptr<Expr> (other.expr->clone_expr ());
1448 0 : }
1449 :
1450 : InlineAsmOperand::Sym
1451 0 : InlineAsmOperand::Sym::operator= (const struct Sym &other)
1452 : {
1453 0 : expr = std::unique_ptr<Expr> (other.expr->clone_expr ());
1454 0 : return *this;
1455 : }
1456 :
1457 0 : InlineAsmOperand::Label::Label (tl::optional<std::string> label_name,
1458 : std::unique_ptr<Expr> expr)
1459 0 : : expr (std::move (expr))
1460 : {
1461 0 : rust_assert (this->expr != nullptr);
1462 0 : if (label_name.has_value ())
1463 0 : this->label_name = label_name.value ();
1464 0 : }
1465 :
1466 0 : InlineAsmOperand::Label::Label (const struct Label &other)
1467 : {
1468 0 : expr = std::unique_ptr<Expr> (other.expr->clone_expr ());
1469 0 : }
1470 :
1471 : InlineAsmOperand::Label
1472 0 : InlineAsmOperand::Label::operator= (const struct Label &other)
1473 : {
1474 0 : expr = std::unique_ptr<Expr> (other.expr->clone_expr ());
1475 0 : return *this;
1476 : }
1477 :
1478 27 : InlineAsm::InlineAsm (location_t locus, bool is_global_asm,
1479 : std::vector<AST::InlineAsmTemplatePiece> template_,
1480 : std::vector<AST::TupleTemplateStr> template_strs,
1481 : std::vector<HIR::InlineAsmOperand> operands,
1482 : std::vector<AST::TupleClobber> clobber_abi,
1483 : std::set<AST::InlineAsm::Option> options,
1484 : Analysis::NodeMapping mappings,
1485 : AST::AttrVec outer_attribs)
1486 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
1487 27 : locus (locus), is_global_asm (is_global_asm),
1488 27 : template_ (std::move (template_)),
1489 27 : template_strs (std::move (template_strs)), operands (std::move (operands)),
1490 27 : clobber_abi (std::move (clobber_abi)), options (std::move (options))
1491 27 : {}
1492 :
1493 : OffsetOf &
1494 0 : OffsetOf::operator= (const OffsetOf &other)
1495 : {
1496 0 : ExprWithoutBlock::operator= (other);
1497 :
1498 0 : type = other.type->clone_type ();
1499 0 : field = other.field;
1500 0 : loc = other.loc;
1501 :
1502 0 : return *this;
1503 : }
1504 :
1505 : ExprWithoutBlock *
1506 0 : OffsetOf::clone_expr_without_block_impl () const
1507 : {
1508 0 : return new OffsetOf (*this);
1509 : }
1510 :
1511 : std::string
1512 0 : OffsetOf::to_string () const
1513 : {
1514 0 : return "OffsetOf(" + type->to_string () + ", " + field.as_string () + ")";
1515 : }
1516 :
1517 : void
1518 44 : OffsetOf::accept_vis (HIRExpressionVisitor &vis)
1519 : {
1520 44 : vis.visit (*this);
1521 44 : }
1522 :
1523 : void
1524 59 : OffsetOf::accept_vis (HIRFullVisitor &vis)
1525 : {
1526 59 : vis.visit (*this);
1527 59 : }
1528 :
1529 : } // namespace HIR
1530 : } // namespace Rust
|