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 153229 : Expr::Expr (Analysis::NodeMapping mappings, AST::AttrVec outer_attribs)
29 153229 : : outer_attrs (std::move (outer_attribs)), mappings (std::move (mappings))
30 153229 : {}
31 :
32 121798 : ExprWithoutBlock::ExprWithoutBlock (Analysis::NodeMapping mappings,
33 0 : AST::AttrVec outer_attribs)
34 121798 : : Expr (std::move (mappings), std::move (outer_attribs))
35 121798 : {}
36 :
37 40 : LoopLabel::LoopLabel (Analysis::NodeMapping mapping, Lifetime loop_label,
38 40 : location_t locus)
39 40 : : label (std::move (loop_label)), locus (locus), mappings (mapping)
40 40 : {}
41 :
42 31431 : ExprWithBlock::ExprWithBlock (Analysis::NodeMapping mappings,
43 0 : AST::AttrVec outer_attrs)
44 31431 : : Expr (std::move (mappings), std::move (outer_attrs))
45 31431 : {}
46 :
47 1293 : LiteralExpr::LiteralExpr (Analysis::NodeMapping mappings,
48 : std::string value_as_string, Literal::LitType type,
49 : PrimitiveCoreType type_hint, location_t locus,
50 1293 : AST::AttrVec outer_attrs)
51 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attrs)),
52 1293 : literal (std::move (value_as_string), type, type_hint), locus (locus)
53 1293 : {}
54 :
55 21110 : LiteralExpr::LiteralExpr (Analysis::NodeMapping mappings, Literal literal,
56 21110 : location_t locus, AST::AttrVec outer_attrs)
57 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attrs)),
58 21110 : literal (std::move (literal)), locus (locus)
59 21110 : {}
60 :
61 22360 : OperatorExpr::OperatorExpr (Analysis::NodeMapping mappings,
62 : std::unique_ptr<Expr> main_or_left_expr,
63 0 : AST::AttrVec outer_attribs, location_t locus)
64 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
65 22360 : locus (locus), main_or_left_expr (std::move (main_or_left_expr))
66 22360 : {}
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 2029 : BorrowExpr::BorrowExpr (Analysis::NodeMapping mappings,
84 : std::unique_ptr<Expr> borrow_lvalue, Mutability mut,
85 2029 : 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 2029 : mut (mut), raw (raw)
89 2029 : {}
90 :
91 3918 : DereferenceExpr::DereferenceExpr (Analysis::NodeMapping mappings,
92 : std::unique_ptr<Expr> deref_lvalue,
93 3918 : AST::AttrVec outer_attribs, location_t locus)
94 : : OperatorExpr (std::move (mappings), std::move (deref_lvalue),
95 3918 : std::move (outer_attribs), locus)
96 3918 : {}
97 :
98 0 : ErrorPropagationExpr::ErrorPropagationExpr (
99 : Analysis::NodeMapping mappings, std::unique_ptr<Expr> potential_error_value,
100 0 : 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 687 : 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 3388 : ArithmeticOrLogicalExpr::ArithmeticOrLogicalExpr (
115 : Analysis::NodeMapping mappings, std::unique_ptr<Expr> left_value,
116 3388 : std::unique_ptr<Expr> right_value, ExprType expr_kind, location_t locus)
117 3388 : : OperatorExpr (std::move (mappings), std::move (left_value), AST::AttrVec (),
118 : locus),
119 3388 : expr_type (expr_kind), right_expr (std::move (right_value))
120 3388 : {}
121 :
122 35 : ArithmeticOrLogicalExpr::ArithmeticOrLogicalExpr (
123 35 : 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 3536 : ComparisonExpr::ComparisonExpr (Analysis::NodeMapping mappings,
139 : std::unique_ptr<Expr> left_value,
140 : std::unique_ptr<Expr> right_value,
141 3536 : ExprType comparison_kind, location_t locus)
142 3536 : : OperatorExpr (std::move (mappings), std::move (left_value), AST::AttrVec (),
143 : locus),
144 3536 : expr_type (comparison_kind), right_expr (std::move (right_value))
145 3536 : {}
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 403 : LazyBooleanExpr::LazyBooleanExpr (Analysis::NodeMapping mappings,
163 : std::unique_ptr<Expr> left_bool_expr,
164 : std::unique_ptr<Expr> right_bool_expr,
165 403 : ExprType expr_kind, location_t locus)
166 : : OperatorExpr (std::move (mappings), std::move (left_bool_expr),
167 403 : AST::AttrVec (), locus),
168 403 : expr_type (expr_kind), right_expr (std::move (right_bool_expr))
169 403 : {}
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 5222 : TypeCastExpr::TypeCastExpr (Analysis::NodeMapping mappings,
187 : std::unique_ptr<Expr> expr_to_cast,
188 : std::unique_ptr<Type> type_to_cast_to,
189 5222 : location_t locus)
190 : : OperatorExpr (std::move (mappings), std::move (expr_to_cast),
191 5222 : AST::AttrVec (), locus),
192 5222 : type_to_convert_to (std::move (type_to_cast_to))
193 5222 : {}
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 2500 : AssignmentExpr::AssignmentExpr (Analysis::NodeMapping mappings,
210 : std::unique_ptr<Expr> value_to_assign_to,
211 : std::unique_ptr<Expr> value_to_assign,
212 2500 : location_t locus)
213 : : OperatorExpr (std::move (mappings), std::move (value_to_assign_to),
214 2500 : AST::AttrVec (), locus),
215 2500 : right_expr (std::move (value_to_assign))
216 2500 : {}
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 677 : CompoundAssignmentExpr::CompoundAssignmentExpr (
232 : Analysis::NodeMapping mappings, std::unique_ptr<Expr> value_to_assign_to,
233 677 : 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 677 : AST::AttrVec (), locus),
236 677 : expr_type (expr_kind), right_expr (std::move (value_to_assign))
237 677 : {}
238 :
239 0 : CompoundAssignmentExpr::CompoundAssignmentExpr (
240 0 : 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 315 : 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 312 : 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 122 : 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 434 : 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 291 : 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 575 : TupleExpr::TupleExpr (Analysis::NodeMapping mappings,
379 : std::vector<std::unique_ptr<Expr>> tuple_elements,
380 : AST::AttrVec inner_attribs, AST::AttrVec outer_attribs,
381 575 : location_t locus)
382 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
383 : WithInnerAttrs (std::move (inner_attribs)),
384 575 : tuple_elems (std::move (tuple_elements)), locus (locus)
385 575 : {}
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 900 : 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 1452 : StructExpr::StructExpr (Analysis::NodeMapping mappings,
436 : PathInExpression struct_path,
437 0 : AST::AttrVec outer_attribs)
438 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
439 1452 : struct_name (std::move (struct_path))
440 1452 : {}
441 :
442 1452 : StructExprStruct::StructExprStruct (Analysis::NodeMapping mappings,
443 : PathInExpression struct_path,
444 : AST::AttrVec inner_attribs,
445 : AST::AttrVec outer_attribs,
446 81 : location_t locus)
447 : : StructExpr (std::move (mappings), std::move (struct_path),
448 : std::move (outer_attribs)),
449 1452 : WithInnerAttrs (std::move (inner_attribs)), locus (locus)
450 1452 : {}
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 2952 : StructExprField::StructExprField (Analysis::NodeMapping mapping,
473 2952 : location_t locus)
474 2952 : : mappings (mapping), locus (locus)
475 2952 : {}
476 :
477 216 : StructExprFieldIdentifier::StructExprFieldIdentifier (
478 216 : Analysis::NodeMapping mapping, Identifier field_identifier, location_t locus)
479 216 : : StructExprField (mapping, locus), field_name (std::move (field_identifier))
480 216 : {}
481 :
482 2736 : StructExprFieldWithVal::StructExprFieldWithVal (
483 : Analysis::NodeMapping mapping, std::unique_ptr<Expr> field_value,
484 2736 : location_t locus)
485 2736 : : StructExprField (mapping, locus), value (std::move (field_value))
486 2736 : {}
487 :
488 0 : StructExprFieldWithVal::StructExprFieldWithVal (
489 0 : 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 2692 : StructExprFieldIdentifierValue::StructExprFieldIdentifierValue (
505 : Analysis::NodeMapping mapping, Identifier field_identifier,
506 2692 : std::unique_ptr<Expr> field_value, location_t locus)
507 : : StructExprFieldWithVal (mapping, std::move (field_value), locus),
508 2692 : field_name (std::move (field_identifier))
509 2692 : {}
510 :
511 44 : StructExprFieldIndexValue::StructExprFieldIndexValue (
512 : Analysis::NodeMapping mapping, TupleIndex tuple_index,
513 44 : 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 1371 : 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 1371 : 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 1371 : fields (std::move (expr_fields)), struct_base (std::move (base_struct))
528 1371 : {}
529 :
530 0 : StructExprStructFields::StructExprStructFields (
531 0 : 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 0 : 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 12582 : CallExpr::CallExpr (Analysis::NodeMapping mappings,
574 : std::unique_ptr<Expr> function_expr,
575 : std::vector<std::unique_ptr<Expr>> function_params,
576 12582 : AST::AttrVec outer_attribs, location_t locus)
577 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
578 12582 : function (std::move (function_expr)), params (std::move (function_params)),
579 12582 : locus (locus)
580 12582 : {}
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 3050 : 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 3050 : AST::AttrVec outer_attribs, location_t locus)
609 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
610 3050 : receiver (std::move (call_receiver)), method_name (std::move (method_path)),
611 3050 : params (std::move (method_params)), locus (locus)
612 3050 : {}
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 5671 : FieldAccessExpr::FieldAccessExpr (Analysis::NodeMapping mappings,
639 : std::unique_ptr<Expr> field_access_receiver,
640 : Identifier field_name,
641 5671 : AST::AttrVec outer_attribs, location_t locus)
642 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
643 5671 : receiver (std::move (field_access_receiver)),
644 5671 : field (std::move (field_name)), locus (locus)
645 5671 : {}
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 61 : 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 66 : 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 23265 : 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 23265 : location_t end_locus)
738 : : ExprWithBlock (std::move (mappings), std::move (outer_attribs)),
739 : WithInnerAttrs (std::move (inner_attribs)),
740 23265 : statements (std::move (block_statements)), expr (std::move (block_expr)),
741 23265 : tail_reachable (tail_reachable), label (std::move (label)),
742 23265 : start_locus (start_locus), end_locus (end_locus)
743 23265 : {}
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 676 : AnonConst::AnonConst (Analysis::NodeMapping mappings,
776 676 : std::unique_ptr<Expr> &&expr, location_t locus)
777 676 : : ExprWithBlock (std::move (mappings), {}), locus (locus),
778 676 : kind (Kind::Explicit), expr (std::move (expr))
779 : {
780 676 : rust_assert (this->expr.value ());
781 676 : }
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 27 : AnonConst::AnonConst (const AnonConst &other)
789 27 : : ExprWithBlock (other), locus (other.locus), kind (other.kind)
790 : {
791 27 : if (other.expr)
792 20 : expr = other.expr.value ()->clone_expr ();
793 27 : }
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 15 : 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 16 : ContinueExpr::ContinueExpr (Analysis::NodeMapping mappings, location_t locus,
831 : tl::optional<Lifetime> label,
832 16 : AST::AttrVec outer_attribs)
833 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
834 16 : label (std::move (label)), locus (locus)
835 16 : {}
836 :
837 91 : BreakExpr::BreakExpr (Analysis::NodeMapping mappings, location_t locus,
838 : tl::optional<Lifetime> break_label,
839 : std::unique_ptr<Expr> expr_in_break,
840 91 : AST::AttrVec outer_attribs)
841 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
842 182 : label (std::move (break_label)), break_expr (std::move (expr_in_break)),
843 91 : locus (locus)
844 91 : {}
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 87 : RangeExpr::RangeExpr (Analysis::NodeMapping mappings, location_t locus)
866 87 : : ExprWithoutBlock (std::move (mappings), AST::AttrVec ()), locus (locus)
867 87 : {}
868 :
869 66 : RangeFromToExpr::RangeFromToExpr (Analysis::NodeMapping mappings,
870 : std::unique_ptr<Expr> range_from,
871 : std::unique_ptr<Expr> range_to,
872 66 : 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 7 : 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 7 : 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 7 : RangeFromToInclExpr::RangeFromToInclExpr (Analysis::NodeMapping mappings,
934 : std::unique_ptr<Expr> range_from,
935 : std::unique_ptr<Expr> range_to,
936 7 : location_t locus)
937 7 : : RangeExpr (std::move (mappings), locus), from (std::move (range_from)),
938 7 : to (std::move (range_to))
939 7 : {}
940 :
941 0 : RangeFromToInclExpr::RangeFromToInclExpr (RangeFromToInclExpr const &other)
942 0 : : RangeExpr (other), from (other.from->clone_expr ()),
943 0 : to (other.to->clone_expr ())
944 0 : {}
945 :
946 : RangeFromToInclExpr &
947 0 : RangeFromToInclExpr::operator= (RangeFromToInclExpr const &other)
948 : {
949 0 : RangeExpr::operator= (other);
950 0 : from = other.from->clone_expr ();
951 0 : to = other.to->clone_expr ();
952 :
953 0 : return *this;
954 : }
955 :
956 0 : RangeToInclExpr::RangeToInclExpr (Analysis::NodeMapping mappings,
957 : std::unique_ptr<Expr> range_to,
958 0 : location_t locus)
959 0 : : RangeExpr (std::move (mappings), locus), to (std::move (range_to))
960 0 : {}
961 :
962 0 : RangeToInclExpr::RangeToInclExpr (RangeToInclExpr const &other)
963 0 : : RangeExpr (other), to (other.to->clone_expr ())
964 0 : {}
965 :
966 : RangeToInclExpr &
967 0 : RangeToInclExpr::operator= (RangeToInclExpr const &other)
968 : {
969 0 : RangeExpr::operator= (other);
970 0 : to = other.to->clone_expr ();
971 :
972 0 : return *this;
973 : }
974 :
975 3 : BoxExpr::BoxExpr (Analysis::NodeMapping mappings, location_t locus,
976 3 : std::unique_ptr<Expr> expr, AST::AttrVec outer_attribs)
977 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
978 3 : expr (std::move (expr)), locus (locus)
979 : {
980 3 : rust_assert (this->expr != nullptr);
981 3 : }
982 :
983 0 : BoxExpr::BoxExpr (BoxExpr const &other)
984 0 : : ExprWithoutBlock (other), locus (other.locus)
985 : {
986 0 : rust_assert (other.expr != nullptr);
987 0 : expr = other.expr->clone_expr ();
988 0 : }
989 :
990 : BoxExpr &
991 0 : BoxExpr::operator= (BoxExpr const &other)
992 : {
993 0 : ExprWithoutBlock::operator= (other);
994 :
995 0 : rust_assert (other.expr != nullptr);
996 0 : expr = other.expr->clone_expr ();
997 0 : locus = other.locus;
998 :
999 0 : return *this;
1000 : }
1001 :
1002 537 : ReturnExpr::ReturnExpr (Analysis::NodeMapping mappings, location_t locus,
1003 : std::unique_ptr<Expr> returned_expr,
1004 537 : AST::AttrVec outer_attribs)
1005 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
1006 537 : return_expr (std::move (returned_expr)), locus (locus)
1007 537 : {}
1008 :
1009 0 : ReturnExpr::ReturnExpr (ReturnExpr const &other)
1010 0 : : ExprWithoutBlock (other), locus (other.locus)
1011 : {
1012 : // guard to protect from null pointer dereference
1013 0 : if (other.return_expr != nullptr)
1014 0 : return_expr = other.return_expr->clone_expr ();
1015 0 : }
1016 :
1017 : ReturnExpr &
1018 0 : ReturnExpr::operator= (ReturnExpr const &other)
1019 : {
1020 0 : ExprWithoutBlock::operator= (other);
1021 0 : return_expr = other.return_expr->clone_expr ();
1022 0 : locus = other.locus;
1023 :
1024 0 : return *this;
1025 : }
1026 :
1027 3661 : UnsafeBlockExpr::UnsafeBlockExpr (Analysis::NodeMapping mappings,
1028 : std::unique_ptr<BlockExpr> block_expr,
1029 3661 : AST::AttrVec outer_attribs, location_t locus)
1030 : : ExprWithBlock (std::move (mappings), std::move (outer_attribs)),
1031 3661 : expr (std::move (block_expr)), locus (locus)
1032 3661 : {}
1033 :
1034 0 : UnsafeBlockExpr::UnsafeBlockExpr (UnsafeBlockExpr const &other)
1035 0 : : ExprWithBlock (other), expr (other.expr->clone_block_expr ()),
1036 0 : locus (other.locus)
1037 0 : {}
1038 :
1039 : UnsafeBlockExpr &
1040 0 : UnsafeBlockExpr::operator= (UnsafeBlockExpr const &other)
1041 : {
1042 0 : ExprWithBlock::operator= (other);
1043 0 : expr = other.expr->clone_block_expr ();
1044 0 : locus = other.locus;
1045 :
1046 0 : return *this;
1047 : }
1048 :
1049 205 : BaseLoopExpr::BaseLoopExpr (Analysis::NodeMapping mappings,
1050 : std::unique_ptr<BlockExpr> loop_block,
1051 : location_t locus,
1052 : tl::optional<LoopLabel> loop_label,
1053 0 : AST::AttrVec outer_attribs)
1054 : : ExprWithBlock (std::move (mappings), std::move (outer_attribs)),
1055 410 : loop_label (std::move (loop_label)), loop_block (std::move (loop_block)),
1056 205 : locus (locus)
1057 205 : {}
1058 :
1059 0 : BaseLoopExpr::BaseLoopExpr (BaseLoopExpr const &other)
1060 0 : : ExprWithBlock (other), loop_label (other.loop_label),
1061 0 : loop_block (other.loop_block->clone_block_expr ()), locus (other.locus)
1062 0 : {}
1063 :
1064 : BaseLoopExpr &
1065 0 : BaseLoopExpr::operator= (BaseLoopExpr const &other)
1066 : {
1067 0 : ExprWithBlock::operator= (other);
1068 0 : loop_block = other.loop_block->clone_block_expr ();
1069 0 : loop_label = other.loop_label;
1070 0 : locus = other.locus;
1071 :
1072 0 : return *this;
1073 : }
1074 :
1075 127 : LoopExpr::LoopExpr (Analysis::NodeMapping mappings,
1076 : std::unique_ptr<BlockExpr> loop_block, location_t locus,
1077 : tl::optional<LoopLabel> loop_label,
1078 127 : AST::AttrVec outer_attribs)
1079 : : BaseLoopExpr (std::move (mappings), std::move (loop_block), locus,
1080 162 : std::move (loop_label), std::move (outer_attribs))
1081 127 : {}
1082 :
1083 78 : WhileLoopExpr::WhileLoopExpr (Analysis::NodeMapping mappings,
1084 : std::unique_ptr<Expr> loop_condition,
1085 : std::unique_ptr<BlockExpr> loop_block,
1086 : location_t locus,
1087 : tl::optional<LoopLabel> loop_label,
1088 78 : AST::AttrVec outer_attribs)
1089 : : BaseLoopExpr (std::move (mappings), std::move (loop_block), locus,
1090 : std::move (loop_label), std::move (outer_attribs)),
1091 80 : condition (std::move (loop_condition))
1092 78 : {}
1093 :
1094 0 : WhileLoopExpr::WhileLoopExpr (WhileLoopExpr const &other)
1095 0 : : BaseLoopExpr (other), condition (other.condition->clone_expr ())
1096 0 : {}
1097 :
1098 : WhileLoopExpr &
1099 0 : WhileLoopExpr::operator= (WhileLoopExpr const &other)
1100 : {
1101 0 : BaseLoopExpr::operator= (other);
1102 0 : condition = other.condition->clone_expr ();
1103 0 : return *this;
1104 : }
1105 :
1106 0 : WhileLetLoopExpr::WhileLetLoopExpr (Analysis::NodeMapping mappings,
1107 : std::unique_ptr<Pattern> match_arm_pattern,
1108 : std::unique_ptr<Expr> condition,
1109 : std::unique_ptr<BlockExpr> loop_block,
1110 : location_t locus,
1111 : tl::optional<LoopLabel> loop_label,
1112 0 : AST::AttrVec outer_attribs)
1113 : : BaseLoopExpr (std::move (mappings), std::move (loop_block), locus,
1114 : std::move (loop_label), std::move (outer_attribs)),
1115 0 : match_arm_pattern (std::move (match_arm_pattern)),
1116 0 : condition (std::move (condition))
1117 0 : {}
1118 :
1119 0 : WhileLetLoopExpr::WhileLetLoopExpr (WhileLetLoopExpr const &other)
1120 : : BaseLoopExpr (other),
1121 0 : match_arm_pattern (other.match_arm_pattern->clone_pattern ()),
1122 0 : condition (other.condition->clone_expr ())
1123 0 : {}
1124 :
1125 : WhileLetLoopExpr &
1126 0 : WhileLetLoopExpr::operator= (WhileLetLoopExpr const &other)
1127 : {
1128 0 : BaseLoopExpr::operator= (other);
1129 0 : condition = other.condition->clone_expr ();
1130 0 : match_arm_pattern = other.match_arm_pattern->clone_pattern ();
1131 :
1132 0 : return *this;
1133 : }
1134 :
1135 2490 : IfExpr::IfExpr (Analysis::NodeMapping mappings, std::unique_ptr<Expr> condition,
1136 1229 : std::unique_ptr<BlockExpr> if_block, location_t locus)
1137 2490 : : ExprWithBlock (std::move (mappings), AST::AttrVec ()),
1138 2490 : condition (std::move (condition)), if_block (std::move (if_block)),
1139 2490 : locus (locus)
1140 2490 : {}
1141 :
1142 0 : IfExpr::IfExpr (IfExpr const &other)
1143 0 : : ExprWithBlock (other), condition (other.condition->clone_expr ()),
1144 0 : if_block (other.if_block->clone_block_expr ()), locus (other.locus)
1145 0 : {}
1146 :
1147 : IfExpr &
1148 0 : IfExpr::operator= (IfExpr const &other)
1149 : {
1150 0 : ExprWithBlock::operator= (other);
1151 0 : condition = other.condition->clone_expr ();
1152 0 : if_block = other.if_block->clone_block_expr ();
1153 0 : locus = other.locus;
1154 :
1155 0 : return *this;
1156 : }
1157 :
1158 1261 : IfExprConseqElse::IfExprConseqElse (Analysis::NodeMapping mappings,
1159 : std::unique_ptr<Expr> condition,
1160 : std::unique_ptr<BlockExpr> if_block,
1161 : std::unique_ptr<ExprWithBlock> else_block,
1162 1261 : location_t locus)
1163 : : IfExpr (std::move (mappings), std::move (condition), std::move (if_block),
1164 : locus),
1165 1261 : else_block (std::move (else_block))
1166 1261 : {}
1167 :
1168 0 : IfExprConseqElse::IfExprConseqElse (IfExprConseqElse const &other)
1169 0 : : IfExpr (other), else_block (other.else_block->clone_expr_with_block ())
1170 0 : {}
1171 :
1172 : IfExprConseqElse &
1173 0 : IfExprConseqElse::operator= (IfExprConseqElse const &other)
1174 : {
1175 0 : IfExpr::operator= (other);
1176 : // condition = other.condition->clone_expr();
1177 : // if_block = other.if_block->clone_block_expr();
1178 0 : else_block = other.else_block->clone_expr_with_block ();
1179 :
1180 0 : return *this;
1181 : }
1182 :
1183 2557 : MatchArm::MatchArm (std::unique_ptr<Pattern> match_arm_pattern,
1184 : location_t locus, std::unique_ptr<Expr> guard_expr,
1185 2557 : AST::AttrVec outer_attrs)
1186 2557 : : outer_attrs (std::move (outer_attrs)),
1187 2557 : match_arm_pattern (std::move (match_arm_pattern)),
1188 2557 : guard_expr (std::move (guard_expr)), locus (locus)
1189 2557 : {}
1190 :
1191 3353 : MatchArm::MatchArm (MatchArm const &other) : outer_attrs (other.outer_attrs)
1192 : {
1193 : // guard to protect from null pointer dereference
1194 3353 : if (other.guard_expr != nullptr)
1195 0 : guard_expr = other.guard_expr->clone_expr ();
1196 :
1197 3353 : match_arm_pattern = other.match_arm_pattern->clone_pattern ();
1198 :
1199 3353 : locus = other.locus;
1200 3353 : }
1201 :
1202 : MatchArm &
1203 0 : MatchArm::operator= (MatchArm const &other)
1204 : {
1205 0 : outer_attrs = other.outer_attrs;
1206 :
1207 0 : if (other.guard_expr != nullptr)
1208 0 : guard_expr = other.guard_expr->clone_expr ();
1209 :
1210 0 : match_arm_pattern = other.match_arm_pattern->clone_pattern ();
1211 :
1212 0 : return *this;
1213 : }
1214 :
1215 2557 : MatchCase::MatchCase (Analysis::NodeMapping mappings, MatchArm arm,
1216 2557 : std::unique_ptr<Expr> expr)
1217 2557 : : mappings (mappings), arm (std::move (arm)), expr (std::move (expr))
1218 2557 : {}
1219 :
1220 0 : MatchCase::MatchCase (const MatchCase &other)
1221 0 : : mappings (other.mappings), arm (other.arm), expr (other.expr->clone_expr ())
1222 0 : {}
1223 :
1224 : MatchCase &
1225 0 : MatchCase::operator= (const MatchCase &other)
1226 : {
1227 0 : mappings = other.mappings;
1228 0 : arm = other.arm;
1229 0 : expr = other.expr->clone_expr ();
1230 :
1231 0 : return *this;
1232 : }
1233 :
1234 1106 : MatchExpr::MatchExpr (Analysis::NodeMapping mappings,
1235 : std::unique_ptr<Expr> branch_value,
1236 : std::vector<MatchCase> match_arms,
1237 : AST::AttrVec inner_attrs, AST::AttrVec outer_attrs,
1238 1106 : location_t locus)
1239 : : ExprWithBlock (std::move (mappings), std::move (outer_attrs)),
1240 : WithInnerAttrs (std::move (inner_attrs)),
1241 1106 : branch_value (std::move (branch_value)),
1242 1106 : match_arms (std::move (match_arms)), locus (locus)
1243 1106 : {}
1244 :
1245 0 : MatchExpr::MatchExpr (MatchExpr const &other)
1246 0 : : ExprWithBlock (other), WithInnerAttrs (other.inner_attrs),
1247 0 : branch_value (other.branch_value->clone_expr ()),
1248 0 : match_arms (other.match_arms), locus (other.locus)
1249 : {
1250 : /*match_arms.reserve (other.match_arms.size ());
1251 : for (const auto &e : other.match_arms)
1252 : match_arms.push_back (e->clone_match_case ());*/
1253 0 : }
1254 :
1255 : MatchExpr &
1256 0 : MatchExpr::operator= (MatchExpr const &other)
1257 : {
1258 0 : ExprWithBlock::operator= (other);
1259 0 : branch_value = other.branch_value->clone_expr ();
1260 0 : inner_attrs = other.inner_attrs;
1261 0 : match_arms = other.match_arms;
1262 0 : locus = other.locus;
1263 :
1264 : /*match_arms.reserve (other.match_arms.size ());
1265 : for (const auto &e : other.match_arms)
1266 : match_arms.push_back (e->clone_match_case ());*/
1267 :
1268 0 : return *this;
1269 : }
1270 :
1271 0 : AwaitExpr::AwaitExpr (Analysis::NodeMapping mappings,
1272 : std::unique_ptr<Expr> awaited_expr,
1273 0 : AST::AttrVec outer_attrs, location_t locus)
1274 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attrs)),
1275 0 : awaited_expr (std::move (awaited_expr)), locus (locus)
1276 0 : {}
1277 :
1278 0 : AwaitExpr::AwaitExpr (AwaitExpr const &other)
1279 0 : : ExprWithoutBlock (other), awaited_expr (other.awaited_expr->clone_expr ()),
1280 0 : locus (other.locus)
1281 0 : {}
1282 :
1283 : AwaitExpr &
1284 0 : AwaitExpr::operator= (AwaitExpr const &other)
1285 : {
1286 0 : ExprWithoutBlock::operator= (other);
1287 0 : awaited_expr = other.awaited_expr->clone_expr ();
1288 0 : locus = other.locus;
1289 :
1290 0 : return *this;
1291 : }
1292 :
1293 0 : AsyncBlockExpr::AsyncBlockExpr (Analysis::NodeMapping mappings,
1294 : std::unique_ptr<BlockExpr> block_expr,
1295 : bool has_move, AST::AttrVec outer_attrs,
1296 0 : location_t locus)
1297 : : ExprWithBlock (std::move (mappings), std::move (outer_attrs)),
1298 0 : has_move (has_move), block_expr (std::move (block_expr)), locus (locus)
1299 0 : {}
1300 :
1301 0 : AsyncBlockExpr::AsyncBlockExpr (AsyncBlockExpr const &other)
1302 0 : : ExprWithBlock (other), has_move (other.has_move),
1303 0 : block_expr (other.block_expr->clone_block_expr ()), locus (other.locus)
1304 0 : {}
1305 :
1306 : AsyncBlockExpr &
1307 0 : AsyncBlockExpr::operator= (AsyncBlockExpr const &other)
1308 : {
1309 0 : ExprWithBlock::operator= (other);
1310 0 : has_move = other.has_move;
1311 0 : block_expr = other.block_expr->clone_block_expr ();
1312 0 : locus = other.locus;
1313 :
1314 0 : return *this;
1315 : }
1316 :
1317 691 : OperatorExprMeta::OperatorExprMeta (HIR::CompoundAssignmentExpr &expr)
1318 691 : : node_mappings (expr.get_mappings ()),
1319 691 : lvalue_mappings (expr.get_expr ().get_mappings ()),
1320 691 : rvalue_mappings (expr.get_rhs ().get_mappings ()), locus (expr.get_locus ())
1321 691 : {}
1322 :
1323 3552 : OperatorExprMeta::OperatorExprMeta (HIR::ArithmeticOrLogicalExpr &expr)
1324 3552 : : node_mappings (expr.get_mappings ()),
1325 3552 : lvalue_mappings (expr.get_expr ().get_mappings ()),
1326 3552 : rvalue_mappings (expr.get_rhs ().get_mappings ()), locus (expr.get_locus ())
1327 3552 : {}
1328 :
1329 701 : OperatorExprMeta::OperatorExprMeta (HIR::NegationExpr &expr)
1330 701 : : node_mappings (expr.get_mappings ()),
1331 701 : lvalue_mappings (expr.get_expr ().get_mappings ()),
1332 701 : rvalue_mappings (Analysis::NodeMapping::get_error ()),
1333 701 : locus (expr.get_locus ())
1334 701 : {}
1335 :
1336 3967 : OperatorExprMeta::OperatorExprMeta (HIR::DereferenceExpr &expr)
1337 3967 : : node_mappings (expr.get_mappings ()),
1338 3967 : lvalue_mappings (expr.get_expr ().get_mappings ()),
1339 3967 : rvalue_mappings (Analysis::NodeMapping::get_error ()),
1340 3967 : locus (expr.get_locus ())
1341 3967 : {}
1342 :
1343 128 : OperatorExprMeta::OperatorExprMeta (HIR::ArrayIndexExpr &expr)
1344 128 : : node_mappings (expr.get_mappings ()),
1345 128 : lvalue_mappings (expr.get_array_expr ().get_mappings ()),
1346 128 : rvalue_mappings (expr.get_index_expr ().get_mappings ()),
1347 128 : locus (expr.get_locus ())
1348 128 : {}
1349 :
1350 4376 : OperatorExprMeta::OperatorExprMeta (HIR::ComparisonExpr &expr)
1351 4376 : : node_mappings (expr.get_mappings ()),
1352 4376 : lvalue_mappings (expr.get_expr ().get_mappings ()),
1353 4376 : rvalue_mappings (expr.get_rhs ().get_mappings ()), locus (expr.get_locus ())
1354 4376 : {}
1355 :
1356 10 : InlineAsmOperand::In::In (
1357 : const tl::optional<struct AST::InlineAsmRegOrRegClass> ®,
1358 10 : std::unique_ptr<Expr> expr)
1359 10 : : reg (reg), expr (std::move (expr))
1360 : {
1361 10 : rust_assert (this->expr != nullptr);
1362 10 : }
1363 :
1364 48 : InlineAsmOperand::In::In (const struct In &other)
1365 : {
1366 48 : reg = other.reg;
1367 :
1368 48 : expr = other.expr->clone_expr ();
1369 48 : }
1370 :
1371 : InlineAsmOperand::In
1372 0 : InlineAsmOperand::In::operator= (const struct In &other)
1373 : {
1374 0 : reg = other.reg;
1375 0 : expr = other.expr->clone_expr ();
1376 :
1377 0 : return *this;
1378 : }
1379 :
1380 17 : InlineAsmOperand::Out::Out (
1381 : tl::optional<struct AST::InlineAsmRegOrRegClass> ®, bool late,
1382 17 : std::unique_ptr<Expr> expr)
1383 17 : : reg (reg), late (late), expr (std::move (expr))
1384 : {
1385 17 : rust_assert (this->expr != nullptr);
1386 17 : }
1387 :
1388 69 : InlineAsmOperand::Out::Out (const struct Out &other)
1389 : {
1390 69 : reg = other.reg;
1391 69 : late = other.late;
1392 69 : expr = other.expr->clone_expr ();
1393 69 : }
1394 :
1395 : InlineAsmOperand::Out
1396 0 : InlineAsmOperand::Out::operator= (const struct Out &other)
1397 : {
1398 0 : reg = other.reg;
1399 0 : late = other.late;
1400 0 : expr = other.expr->clone_expr ();
1401 0 : return *this;
1402 : }
1403 :
1404 0 : InlineAsmOperand::InOut::InOut (
1405 : tl::optional<struct AST::InlineAsmRegOrRegClass> ®, bool late,
1406 0 : std::unique_ptr<Expr> expr)
1407 0 : : reg (reg), late (late), expr (std::move (expr))
1408 : {
1409 0 : rust_assert (this->expr != nullptr);
1410 0 : }
1411 :
1412 0 : InlineAsmOperand::InOut::InOut (const struct InOut &other)
1413 : {
1414 0 : reg = other.reg;
1415 0 : late = other.late;
1416 0 : expr = other.expr->clone_expr ();
1417 0 : }
1418 :
1419 : InlineAsmOperand::InOut
1420 0 : InlineAsmOperand::InOut::operator= (const struct InOut &other)
1421 : {
1422 0 : reg = other.reg;
1423 0 : late = other.late;
1424 0 : expr = other.expr->clone_expr ();
1425 :
1426 0 : return *this;
1427 : }
1428 :
1429 2 : InlineAsmOperand::SplitInOut::SplitInOut (
1430 : tl::optional<struct AST::InlineAsmRegOrRegClass> ®, bool late,
1431 2 : std::unique_ptr<Expr> in_expr, std::unique_ptr<Expr> out_expr)
1432 2 : : reg (reg), late (late), in_expr (std::move (in_expr)),
1433 2 : out_expr (std::move (out_expr))
1434 : {
1435 2 : rust_assert (this->in_expr != nullptr);
1436 2 : rust_assert (this->out_expr != nullptr);
1437 2 : }
1438 :
1439 8 : InlineAsmOperand::SplitInOut::SplitInOut (const struct SplitInOut &other)
1440 : {
1441 8 : reg = other.reg;
1442 8 : late = other.late;
1443 8 : in_expr = other.in_expr->clone_expr ();
1444 8 : out_expr = other.out_expr->clone_expr ();
1445 8 : }
1446 :
1447 : InlineAsmOperand::SplitInOut
1448 0 : InlineAsmOperand::SplitInOut::operator= (const struct SplitInOut &other)
1449 : {
1450 0 : reg = other.reg;
1451 0 : late = other.late;
1452 0 : in_expr = other.in_expr->clone_expr ();
1453 0 : out_expr = other.out_expr->clone_expr ();
1454 :
1455 0 : return *this;
1456 : }
1457 :
1458 0 : InlineAsmOperand::Sym::Sym (std::unique_ptr<Expr> expr)
1459 0 : : expr (std::move (expr))
1460 : {
1461 0 : rust_assert (this->expr != nullptr);
1462 0 : }
1463 :
1464 0 : InlineAsmOperand::Sym::Sym (const struct Sym &other)
1465 : {
1466 0 : expr = std::unique_ptr<Expr> (other.expr->clone_expr ());
1467 0 : }
1468 :
1469 : InlineAsmOperand::Sym
1470 0 : InlineAsmOperand::Sym::operator= (const struct Sym &other)
1471 : {
1472 0 : expr = std::unique_ptr<Expr> (other.expr->clone_expr ());
1473 0 : return *this;
1474 : }
1475 :
1476 0 : InlineAsmOperand::Label::Label (tl::optional<std::string> label_name,
1477 0 : std::unique_ptr<Expr> expr)
1478 0 : : expr (std::move (expr))
1479 : {
1480 0 : rust_assert (this->expr != nullptr);
1481 0 : if (label_name.has_value ())
1482 0 : this->label_name = label_name.value ();
1483 0 : }
1484 :
1485 0 : InlineAsmOperand::Label::Label (const struct Label &other)
1486 : {
1487 0 : expr = std::unique_ptr<Expr> (other.expr->clone_expr ());
1488 0 : }
1489 :
1490 : InlineAsmOperand::Label
1491 0 : InlineAsmOperand::Label::operator= (const struct Label &other)
1492 : {
1493 0 : expr = std::unique_ptr<Expr> (other.expr->clone_expr ());
1494 0 : return *this;
1495 : }
1496 :
1497 27 : InlineAsm::InlineAsm (location_t locus, bool is_global_asm,
1498 : std::vector<AST::InlineAsmTemplatePiece> template_,
1499 : std::vector<AST::TupleTemplateStr> template_strs,
1500 : std::vector<HIR::InlineAsmOperand> operands,
1501 : std::vector<AST::TupleClobber> clobber_abi,
1502 : std::set<AST::InlineAsm::Option> options,
1503 : Analysis::NodeMapping mappings,
1504 27 : AST::AttrVec outer_attribs)
1505 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
1506 27 : locus (locus), is_global_asm (is_global_asm),
1507 27 : template_ (std::move (template_)),
1508 27 : template_strs (std::move (template_strs)), operands (std::move (operands)),
1509 27 : clobber_abi (std::move (clobber_abi)), options (std::move (options))
1510 27 : {}
1511 :
1512 : OffsetOf &
1513 0 : OffsetOf::operator= (const OffsetOf &other)
1514 : {
1515 0 : ExprWithoutBlock::operator= (other);
1516 :
1517 0 : type = other.type->clone_type ();
1518 0 : field = other.field;
1519 0 : loc = other.loc;
1520 :
1521 0 : return *this;
1522 : }
1523 :
1524 : ExprWithoutBlock *
1525 0 : OffsetOf::clone_expr_without_block_impl () const
1526 : {
1527 0 : return new OffsetOf (*this);
1528 : }
1529 :
1530 : std::string
1531 0 : OffsetOf::to_string () const
1532 : {
1533 0 : return "OffsetOf(" + type->to_string () + ", " + field.as_string () + ")";
1534 : }
1535 :
1536 : void
1537 44 : OffsetOf::accept_vis (HIRExpressionVisitor &vis)
1538 : {
1539 44 : vis.visit (*this);
1540 44 : }
1541 :
1542 : void
1543 59 : OffsetOf::accept_vis (HIRFullVisitor &vis)
1544 : {
1545 59 : vis.visit (*this);
1546 59 : }
1547 :
1548 : } // namespace HIR
1549 : } // namespace Rust
|