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 143629 : Expr::Expr (Analysis::NodeMapping mappings, AST::AttrVec outer_attribs)
29 143629 : : outer_attrs (std::move (outer_attribs)), mappings (std::move (mappings))
30 143629 : {}
31 :
32 114533 : ExprWithoutBlock::ExprWithoutBlock (Analysis::NodeMapping mappings,
33 0 : AST::AttrVec outer_attribs)
34 114533 : : Expr (std::move (mappings), std::move (outer_attribs))
35 114533 : {}
36 :
37 36 : LoopLabel::LoopLabel (Analysis::NodeMapping mapping, Lifetime loop_label,
38 36 : location_t locus)
39 36 : : label (std::move (loop_label)), locus (locus), mappings (mapping)
40 36 : {}
41 :
42 29096 : ExprWithBlock::ExprWithBlock (Analysis::NodeMapping mappings,
43 0 : AST::AttrVec outer_attrs)
44 29096 : : Expr (std::move (mappings), std::move (outer_attrs))
45 29096 : {}
46 :
47 1271 : LiteralExpr::LiteralExpr (Analysis::NodeMapping mappings,
48 : std::string value_as_string, Literal::LitType type,
49 : PrimitiveCoreType type_hint, location_t locus,
50 1271 : AST::AttrVec outer_attrs)
51 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attrs)),
52 1271 : literal (std::move (value_as_string), type, type_hint), locus (locus)
53 1271 : {}
54 :
55 18999 : LiteralExpr::LiteralExpr (Analysis::NodeMapping mappings, Literal literal,
56 18999 : location_t locus, AST::AttrVec outer_attrs)
57 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attrs)),
58 18999 : literal (std::move (literal)), locus (locus)
59 18999 : {}
60 :
61 21121 : 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 21121 : locus (locus), main_or_left_expr (std::move (main_or_left_expr))
66 21121 : {}
67 :
68 9221 : OperatorExpr::OperatorExpr (OperatorExpr const &other)
69 9221 : : ExprWithoutBlock (other), locus (other.locus),
70 9221 : main_or_left_expr (other.main_or_left_expr->clone_expr ())
71 9221 : {}
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 1959 : BorrowExpr::BorrowExpr (Analysis::NodeMapping mappings,
84 : std::unique_ptr<Expr> borrow_lvalue, Mutability mut,
85 1959 : 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 1959 : mut (mut), raw (raw)
89 1959 : {}
90 :
91 3905 : DereferenceExpr::DereferenceExpr (Analysis::NodeMapping mappings,
92 : std::unique_ptr<Expr> deref_lvalue,
93 3905 : AST::AttrVec outer_attribs, location_t locus)
94 : : OperatorExpr (std::move (mappings), std::move (deref_lvalue),
95 3905 : std::move (outer_attribs), locus)
96 3905 : {}
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 530 : NegationExpr::NegationExpr (Analysis::NodeMapping mappings,
106 : std::unique_ptr<Expr> negated_value,
107 : ExprType expr_kind, AST::AttrVec outer_attribs,
108 530 : location_t locus)
109 : : OperatorExpr (std::move (mappings), std::move (negated_value),
110 : std::move (outer_attribs), locus),
111 530 : expr_type (expr_kind)
112 530 : {}
113 :
114 3359 : ArithmeticOrLogicalExpr::ArithmeticOrLogicalExpr (
115 : Analysis::NodeMapping mappings, std::unique_ptr<Expr> left_value,
116 3359 : std::unique_ptr<Expr> right_value, ExprType expr_kind, location_t locus)
117 3359 : : OperatorExpr (std::move (mappings), std::move (left_value), AST::AttrVec (),
118 : locus),
119 3359 : expr_type (expr_kind), right_expr (std::move (right_value))
120 3359 : {}
121 :
122 34 : ArithmeticOrLogicalExpr::ArithmeticOrLogicalExpr (
123 34 : ArithmeticOrLogicalExpr const &other)
124 34 : : OperatorExpr (other), expr_type (other.expr_type),
125 34 : right_expr (other.right_expr->clone_expr ())
126 34 : {}
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 2706 : ComparisonExpr::ComparisonExpr (Analysis::NodeMapping mappings,
139 : std::unique_ptr<Expr> left_value,
140 : std::unique_ptr<Expr> right_value,
141 2706 : ExprType comparison_kind, location_t locus)
142 2706 : : OperatorExpr (std::move (mappings), std::move (left_value), AST::AttrVec (),
143 : locus),
144 2706 : expr_type (comparison_kind), right_expr (std::move (right_value))
145 2706 : {}
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 385 : LazyBooleanExpr::LazyBooleanExpr (Analysis::NodeMapping mappings,
163 : std::unique_ptr<Expr> left_bool_expr,
164 : std::unique_ptr<Expr> right_bool_expr,
165 385 : ExprType expr_kind, location_t locus)
166 : : OperatorExpr (std::move (mappings), std::move (left_bool_expr),
167 385 : AST::AttrVec (), locus),
168 385 : expr_type (expr_kind), right_expr (std::move (right_bool_expr))
169 385 : {}
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 5112 : TypeCastExpr::TypeCastExpr (Analysis::NodeMapping mappings,
187 : std::unique_ptr<Expr> expr_to_cast,
188 : std::unique_ptr<Type> type_to_cast_to,
189 5112 : location_t locus)
190 : : OperatorExpr (std::move (mappings), std::move (expr_to_cast),
191 5112 : AST::AttrVec (), locus),
192 5112 : type_to_convert_to (std::move (type_to_cast_to))
193 5112 : {}
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 2491 : AssignmentExpr::AssignmentExpr (Analysis::NodeMapping mappings,
210 : std::unique_ptr<Expr> value_to_assign_to,
211 : std::unique_ptr<Expr> value_to_assign,
212 2491 : location_t locus)
213 : : OperatorExpr (std::move (mappings), std::move (value_to_assign_to),
214 2491 : AST::AttrVec (), locus),
215 2491 : right_expr (std::move (value_to_assign))
216 2491 : {}
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 674 : CompoundAssignmentExpr::CompoundAssignmentExpr (
232 : Analysis::NodeMapping mappings, std::unique_ptr<Expr> value_to_assign_to,
233 674 : 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 674 : AST::AttrVec (), locus),
236 674 : expr_type (expr_kind), right_expr (std::move (value_to_assign))
237 674 : {}
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 310 : GroupedExpr::GroupedExpr (Analysis::NodeMapping mappings,
256 : std::unique_ptr<Expr> parenthesised_expr,
257 : AST::AttrVec inner_attribs,
258 310 : AST::AttrVec outer_attribs, location_t locus)
259 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
260 : WithInnerAttrs (std::move (inner_attribs)),
261 310 : expr_in_parens (std::move (parenthesised_expr)), locus (locus)
262 310 : {}
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 305 : ArrayElemsValues::ArrayElemsValues (Analysis::NodeMapping mappings,
281 305 : std::vector<std::unique_ptr<Expr>> elems)
282 305 : : ArrayElems (mappings), values (std::move (elems))
283 305 : {}
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 427 : ArrayExpr::ArrayExpr (Analysis::NodeMapping mappings,
325 : std::unique_ptr<ArrayElems> array_elems,
326 : AST::AttrVec inner_attribs, AST::AttrVec outer_attribs,
327 427 : location_t locus)
328 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
329 : WithInnerAttrs (std::move (inner_attribs)),
330 427 : internal_elements (std::move (array_elems)), locus (locus)
331 427 : {}
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 243 : ArrayIndexExpr::ArrayIndexExpr (Analysis::NodeMapping mappings,
354 : std::unique_ptr<Expr> array_expr,
355 : std::unique_ptr<Expr> array_index_expr,
356 243 : AST::AttrVec outer_attribs, location_t locus)
357 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
358 243 : array_expr (std::move (array_expr)),
359 243 : index_expr (std::move (array_index_expr)), locus (locus)
360 243 : {}
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 573 : TupleExpr::TupleExpr (Analysis::NodeMapping mappings,
379 : std::vector<std::unique_ptr<Expr>> tuple_elements,
380 : AST::AttrVec inner_attribs, AST::AttrVec outer_attribs,
381 573 : location_t locus)
382 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
383 : WithInnerAttrs (std::move (inner_attribs)),
384 573 : tuple_elems (std::move (tuple_elements)), locus (locus)
385 573 : {}
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 897 : TupleIndexExpr::TupleIndexExpr (Analysis::NodeMapping mappings,
411 : std::unique_ptr<Expr> tuple_expr,
412 : TupleIndex index, AST::AttrVec outer_attribs,
413 897 : location_t locus)
414 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
415 897 : tuple_expr (std::move (tuple_expr)), tuple_index (index), locus (locus)
416 897 : {}
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 1406 : 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 1406 : struct_name (std::move (struct_path))
440 1406 : {}
441 :
442 1406 : 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 1406 : WithInnerAttrs (std::move (inner_attribs)), locus (locus)
450 1406 : {}
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 2900 : StructExprField::StructExprField (Analysis::NodeMapping mapping,
473 2900 : location_t locus)
474 2900 : : mappings (mapping), locus (locus)
475 2900 : {}
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 2684 : StructExprFieldWithVal::StructExprFieldWithVal (
483 : Analysis::NodeMapping mapping, std::unique_ptr<Expr> field_value,
484 2684 : location_t locus)
485 2684 : : StructExprField (mapping, locus), value (std::move (field_value))
486 2684 : {}
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 2640 : StructExprFieldIdentifierValue::StructExprFieldIdentifierValue (
505 : Analysis::NodeMapping mapping, Identifier field_identifier,
506 2640 : std::unique_ptr<Expr> field_value, location_t locus)
507 : : StructExprFieldWithVal (mapping, std::move (field_value), locus),
508 2640 : field_name (std::move (field_identifier))
509 2640 : {}
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 1325 : 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 1325 : 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 1325 : fields (std::move (expr_fields)), struct_base (std::move (base_struct))
528 1325 : {}
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 11039 : CallExpr::CallExpr (Analysis::NodeMapping mappings,
574 : std::unique_ptr<Expr> function_expr,
575 : std::vector<std::unique_ptr<Expr>> function_params,
576 11039 : AST::AttrVec outer_attribs, location_t locus)
577 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
578 11039 : function (std::move (function_expr)), params (std::move (function_params)),
579 11039 : locus (locus)
580 11039 : {}
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 2974 : 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 2974 : AST::AttrVec outer_attribs, location_t locus)
609 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
610 2974 : receiver (std::move (call_receiver)), method_name (std::move (method_path)),
611 2974 : params (std::move (method_params)), locus (locus)
612 2974 : {}
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 5552 : FieldAccessExpr::FieldAccessExpr (Analysis::NodeMapping mappings,
639 : std::unique_ptr<Expr> field_access_receiver,
640 : Identifier field_name,
641 5552 : AST::AttrVec outer_attribs, location_t locus)
642 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
643 5552 : receiver (std::move (field_access_receiver)),
644 5552 : field (std::move (field_name)), locus (locus)
645 5552 : {}
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 21916 : 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 21916 : location_t end_locus)
738 : : ExprWithBlock (std::move (mappings), std::move (outer_attribs)),
739 : WithInnerAttrs (std::move (inner_attribs)),
740 21916 : statements (std::move (block_statements)), expr (std::move (block_expr)),
741 21916 : tail_reachable (tail_reachable), label (std::move (label)),
742 21916 : start_locus (start_locus), end_locus (end_locus)
743 21916 : {}
744 :
745 37 : BlockExpr::BlockExpr (BlockExpr const &other)
746 : : ExprWithBlock (other), /*statements(other.statements),*/
747 37 : WithInnerAttrs (other.inner_attrs), label (other.label),
748 37 : start_locus (other.start_locus), end_locus (other.end_locus)
749 : {
750 : // guard to protect from null pointer dereference
751 37 : if (other.expr != nullptr)
752 36 : expr = other.expr->clone_expr ();
753 :
754 37 : statements.reserve (other.statements.size ());
755 63 : for (const auto &e : other.statements)
756 26 : statements.push_back (e->clone_stmt ());
757 37 : }
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 667 : AnonConst::AnonConst (Analysis::NodeMapping mappings,
776 667 : std::unique_ptr<Expr> &&expr, location_t locus)
777 667 : : ExprWithBlock (std::move (mappings), {}), locus (locus),
778 667 : kind (Kind::Explicit), expr (std::move (expr))
779 : {
780 667 : rust_assert (this->expr.value ());
781 667 : }
782 :
783 11 : AnonConst::AnonConst (Analysis::NodeMapping mappings, location_t locus)
784 11 : : ExprWithBlock (std::move (mappings), {}), locus (locus),
785 11 : kind (Kind::DeferredInference), expr (tl::nullopt)
786 11 : {}
787 :
788 22 : AnonConst::AnonConst (const AnonConst &other)
789 22 : : ExprWithBlock (other), locus (other.locus), kind (other.kind)
790 : {
791 22 : if (other.expr)
792 15 : expr = other.expr.value ()->clone_expr ();
793 22 : }
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 87 : BreakExpr::BreakExpr (Analysis::NodeMapping mappings, location_t locus,
838 : tl::optional<Lifetime> break_label,
839 : std::unique_ptr<Expr> expr_in_break,
840 87 : AST::AttrVec outer_attribs)
841 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
842 174 : label (std::move (break_label)), break_expr (std::move (expr_in_break)),
843 87 : locus (locus)
844 87 : {}
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 534 : ReturnExpr::ReturnExpr (Analysis::NodeMapping mappings, location_t locus,
976 : std::unique_ptr<Expr> returned_expr,
977 534 : AST::AttrVec outer_attribs)
978 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
979 534 : return_expr (std::move (returned_expr)), locus (locus)
980 534 : {}
981 :
982 0 : ReturnExpr::ReturnExpr (ReturnExpr const &other)
983 0 : : ExprWithoutBlock (other), locus (other.locus)
984 : {
985 : // guard to protect from null pointer dereference
986 0 : if (other.return_expr != nullptr)
987 0 : return_expr = other.return_expr->clone_expr ();
988 0 : }
989 :
990 : ReturnExpr &
991 0 : ReturnExpr::operator= (ReturnExpr const &other)
992 : {
993 0 : ExprWithoutBlock::operator= (other);
994 0 : return_expr = other.return_expr->clone_expr ();
995 0 : locus = other.locus;
996 :
997 0 : return *this;
998 : }
999 :
1000 3516 : UnsafeBlockExpr::UnsafeBlockExpr (Analysis::NodeMapping mappings,
1001 : std::unique_ptr<BlockExpr> block_expr,
1002 3516 : AST::AttrVec outer_attribs, location_t locus)
1003 : : ExprWithBlock (std::move (mappings), std::move (outer_attribs)),
1004 3516 : expr (std::move (block_expr)), locus (locus)
1005 3516 : {}
1006 :
1007 0 : UnsafeBlockExpr::UnsafeBlockExpr (UnsafeBlockExpr const &other)
1008 0 : : ExprWithBlock (other), expr (other.expr->clone_block_expr ()),
1009 0 : locus (other.locus)
1010 0 : {}
1011 :
1012 : UnsafeBlockExpr &
1013 0 : UnsafeBlockExpr::operator= (UnsafeBlockExpr const &other)
1014 : {
1015 0 : ExprWithBlock::operator= (other);
1016 0 : expr = other.expr->clone_block_expr ();
1017 0 : locus = other.locus;
1018 :
1019 0 : return *this;
1020 : }
1021 :
1022 201 : BaseLoopExpr::BaseLoopExpr (Analysis::NodeMapping mappings,
1023 : std::unique_ptr<BlockExpr> loop_block,
1024 : location_t locus,
1025 : tl::optional<LoopLabel> loop_label,
1026 0 : AST::AttrVec outer_attribs)
1027 : : ExprWithBlock (std::move (mappings), std::move (outer_attribs)),
1028 402 : loop_label (std::move (loop_label)), loop_block (std::move (loop_block)),
1029 201 : locus (locus)
1030 201 : {}
1031 :
1032 0 : BaseLoopExpr::BaseLoopExpr (BaseLoopExpr const &other)
1033 0 : : ExprWithBlock (other), loop_label (other.loop_label),
1034 0 : loop_block (other.loop_block->clone_block_expr ()), locus (other.locus)
1035 0 : {}
1036 :
1037 : BaseLoopExpr &
1038 0 : BaseLoopExpr::operator= (BaseLoopExpr const &other)
1039 : {
1040 0 : ExprWithBlock::operator= (other);
1041 0 : loop_block = other.loop_block->clone_block_expr ();
1042 0 : loop_label = other.loop_label;
1043 0 : locus = other.locus;
1044 :
1045 0 : return *this;
1046 : }
1047 :
1048 124 : LoopExpr::LoopExpr (Analysis::NodeMapping mappings,
1049 : std::unique_ptr<BlockExpr> loop_block, location_t locus,
1050 : tl::optional<LoopLabel> loop_label,
1051 124 : AST::AttrVec outer_attribs)
1052 : : BaseLoopExpr (std::move (mappings), std::move (loop_block), locus,
1053 158 : std::move (loop_label), std::move (outer_attribs))
1054 124 : {}
1055 :
1056 77 : WhileLoopExpr::WhileLoopExpr (Analysis::NodeMapping mappings,
1057 : std::unique_ptr<Expr> loop_condition,
1058 : std::unique_ptr<BlockExpr> loop_block,
1059 : location_t locus,
1060 : tl::optional<LoopLabel> loop_label,
1061 77 : AST::AttrVec outer_attribs)
1062 : : BaseLoopExpr (std::move (mappings), std::move (loop_block), locus,
1063 : std::move (loop_label), std::move (outer_attribs)),
1064 79 : condition (std::move (loop_condition))
1065 77 : {}
1066 :
1067 0 : WhileLoopExpr::WhileLoopExpr (WhileLoopExpr const &other)
1068 0 : : BaseLoopExpr (other), condition (other.condition->clone_expr ())
1069 0 : {}
1070 :
1071 : WhileLoopExpr &
1072 0 : WhileLoopExpr::operator= (WhileLoopExpr const &other)
1073 : {
1074 0 : BaseLoopExpr::operator= (other);
1075 0 : condition = other.condition->clone_expr ();
1076 0 : return *this;
1077 : }
1078 :
1079 0 : WhileLetLoopExpr::WhileLetLoopExpr (Analysis::NodeMapping mappings,
1080 : std::unique_ptr<Pattern> match_arm_pattern,
1081 : std::unique_ptr<Expr> condition,
1082 : std::unique_ptr<BlockExpr> loop_block,
1083 : location_t locus,
1084 : tl::optional<LoopLabel> loop_label,
1085 0 : AST::AttrVec outer_attribs)
1086 : : BaseLoopExpr (std::move (mappings), std::move (loop_block), locus,
1087 : std::move (loop_label), std::move (outer_attribs)),
1088 0 : match_arm_pattern (std::move (match_arm_pattern)),
1089 0 : condition (std::move (condition))
1090 0 : {}
1091 :
1092 0 : WhileLetLoopExpr::WhileLetLoopExpr (WhileLetLoopExpr const &other)
1093 : : BaseLoopExpr (other),
1094 0 : match_arm_pattern (other.match_arm_pattern->clone_pattern ()),
1095 0 : condition (other.condition->clone_expr ())
1096 0 : {}
1097 :
1098 : WhileLetLoopExpr &
1099 0 : WhileLetLoopExpr::operator= (WhileLetLoopExpr const &other)
1100 : {
1101 0 : BaseLoopExpr::operator= (other);
1102 0 : condition = other.condition->clone_expr ();
1103 0 : match_arm_pattern = other.match_arm_pattern->clone_pattern ();
1104 :
1105 0 : return *this;
1106 : }
1107 :
1108 1675 : IfExpr::IfExpr (Analysis::NodeMapping mappings, std::unique_ptr<Expr> condition,
1109 470 : std::unique_ptr<BlockExpr> if_block, location_t locus)
1110 1675 : : ExprWithBlock (std::move (mappings), AST::AttrVec ()),
1111 1675 : condition (std::move (condition)), if_block (std::move (if_block)),
1112 1675 : locus (locus)
1113 1675 : {}
1114 :
1115 0 : IfExpr::IfExpr (IfExpr const &other)
1116 0 : : ExprWithBlock (other), condition (other.condition->clone_expr ()),
1117 0 : if_block (other.if_block->clone_block_expr ()), locus (other.locus)
1118 0 : {}
1119 :
1120 : IfExpr &
1121 0 : IfExpr::operator= (IfExpr const &other)
1122 : {
1123 0 : ExprWithBlock::operator= (other);
1124 0 : condition = other.condition->clone_expr ();
1125 0 : if_block = other.if_block->clone_block_expr ();
1126 0 : locus = other.locus;
1127 :
1128 0 : return *this;
1129 : }
1130 :
1131 1205 : IfExprConseqElse::IfExprConseqElse (Analysis::NodeMapping mappings,
1132 : std::unique_ptr<Expr> condition,
1133 : std::unique_ptr<BlockExpr> if_block,
1134 : std::unique_ptr<ExprWithBlock> else_block,
1135 1205 : location_t locus)
1136 : : IfExpr (std::move (mappings), std::move (condition), std::move (if_block),
1137 : locus),
1138 1205 : else_block (std::move (else_block))
1139 1205 : {}
1140 :
1141 0 : IfExprConseqElse::IfExprConseqElse (IfExprConseqElse const &other)
1142 0 : : IfExpr (other), else_block (other.else_block->clone_expr_with_block ())
1143 0 : {}
1144 :
1145 : IfExprConseqElse &
1146 0 : IfExprConseqElse::operator= (IfExprConseqElse const &other)
1147 : {
1148 0 : IfExpr::operator= (other);
1149 : // condition = other.condition->clone_expr();
1150 : // if_block = other.if_block->clone_block_expr();
1151 0 : else_block = other.else_block->clone_expr_with_block ();
1152 :
1153 0 : return *this;
1154 : }
1155 :
1156 2535 : MatchArm::MatchArm (std::unique_ptr<Pattern> match_arm_pattern,
1157 : location_t locus, std::unique_ptr<Expr> guard_expr,
1158 2535 : AST::AttrVec outer_attrs)
1159 2535 : : outer_attrs (std::move (outer_attrs)),
1160 2535 : match_arm_pattern (std::move (match_arm_pattern)),
1161 2535 : guard_expr (std::move (guard_expr)), locus (locus)
1162 2535 : {}
1163 :
1164 3340 : MatchArm::MatchArm (MatchArm const &other) : outer_attrs (other.outer_attrs)
1165 : {
1166 : // guard to protect from null pointer dereference
1167 3340 : if (other.guard_expr != nullptr)
1168 0 : guard_expr = other.guard_expr->clone_expr ();
1169 :
1170 3340 : match_arm_pattern = other.match_arm_pattern->clone_pattern ();
1171 :
1172 3340 : locus = other.locus;
1173 3340 : }
1174 :
1175 : MatchArm &
1176 0 : MatchArm::operator= (MatchArm const &other)
1177 : {
1178 0 : outer_attrs = other.outer_attrs;
1179 :
1180 0 : if (other.guard_expr != nullptr)
1181 0 : guard_expr = other.guard_expr->clone_expr ();
1182 :
1183 0 : match_arm_pattern = other.match_arm_pattern->clone_pattern ();
1184 :
1185 0 : return *this;
1186 : }
1187 :
1188 2535 : MatchCase::MatchCase (Analysis::NodeMapping mappings, MatchArm arm,
1189 2535 : std::unique_ptr<Expr> expr)
1190 2535 : : mappings (mappings), arm (std::move (arm)), expr (std::move (expr))
1191 2535 : {}
1192 :
1193 0 : MatchCase::MatchCase (const MatchCase &other)
1194 0 : : mappings (other.mappings), arm (other.arm), expr (other.expr->clone_expr ())
1195 0 : {}
1196 :
1197 : MatchCase &
1198 0 : MatchCase::operator= (const MatchCase &other)
1199 : {
1200 0 : mappings = other.mappings;
1201 0 : arm = other.arm;
1202 0 : expr = other.expr->clone_expr ();
1203 :
1204 0 : return *this;
1205 : }
1206 :
1207 1095 : MatchExpr::MatchExpr (Analysis::NodeMapping mappings,
1208 : std::unique_ptr<Expr> branch_value,
1209 : std::vector<MatchCase> match_arms,
1210 : AST::AttrVec inner_attrs, AST::AttrVec outer_attrs,
1211 1095 : location_t locus)
1212 : : ExprWithBlock (std::move (mappings), std::move (outer_attrs)),
1213 : WithInnerAttrs (std::move (inner_attrs)),
1214 1095 : branch_value (std::move (branch_value)),
1215 1095 : match_arms (std::move (match_arms)), locus (locus)
1216 1095 : {}
1217 :
1218 0 : MatchExpr::MatchExpr (MatchExpr const &other)
1219 0 : : ExprWithBlock (other), WithInnerAttrs (other.inner_attrs),
1220 0 : branch_value (other.branch_value->clone_expr ()),
1221 0 : match_arms (other.match_arms), locus (other.locus)
1222 : {
1223 : /*match_arms.reserve (other.match_arms.size ());
1224 : for (const auto &e : other.match_arms)
1225 : match_arms.push_back (e->clone_match_case ());*/
1226 0 : }
1227 :
1228 : MatchExpr &
1229 0 : MatchExpr::operator= (MatchExpr const &other)
1230 : {
1231 0 : ExprWithBlock::operator= (other);
1232 0 : branch_value = other.branch_value->clone_expr ();
1233 0 : inner_attrs = other.inner_attrs;
1234 0 : match_arms = other.match_arms;
1235 0 : locus = other.locus;
1236 :
1237 : /*match_arms.reserve (other.match_arms.size ());
1238 : for (const auto &e : other.match_arms)
1239 : match_arms.push_back (e->clone_match_case ());*/
1240 :
1241 0 : return *this;
1242 : }
1243 :
1244 0 : AwaitExpr::AwaitExpr (Analysis::NodeMapping mappings,
1245 : std::unique_ptr<Expr> awaited_expr,
1246 0 : AST::AttrVec outer_attrs, location_t locus)
1247 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attrs)),
1248 0 : awaited_expr (std::move (awaited_expr)), locus (locus)
1249 0 : {}
1250 :
1251 0 : AwaitExpr::AwaitExpr (AwaitExpr const &other)
1252 0 : : ExprWithoutBlock (other), awaited_expr (other.awaited_expr->clone_expr ()),
1253 0 : locus (other.locus)
1254 0 : {}
1255 :
1256 : AwaitExpr &
1257 0 : AwaitExpr::operator= (AwaitExpr const &other)
1258 : {
1259 0 : ExprWithoutBlock::operator= (other);
1260 0 : awaited_expr = other.awaited_expr->clone_expr ();
1261 0 : locus = other.locus;
1262 :
1263 0 : return *this;
1264 : }
1265 :
1266 0 : AsyncBlockExpr::AsyncBlockExpr (Analysis::NodeMapping mappings,
1267 : std::unique_ptr<BlockExpr> block_expr,
1268 : bool has_move, AST::AttrVec outer_attrs,
1269 0 : location_t locus)
1270 : : ExprWithBlock (std::move (mappings), std::move (outer_attrs)),
1271 0 : has_move (has_move), block_expr (std::move (block_expr)), locus (locus)
1272 0 : {}
1273 :
1274 0 : AsyncBlockExpr::AsyncBlockExpr (AsyncBlockExpr const &other)
1275 0 : : ExprWithBlock (other), has_move (other.has_move),
1276 0 : block_expr (other.block_expr->clone_block_expr ()), locus (other.locus)
1277 0 : {}
1278 :
1279 : AsyncBlockExpr &
1280 0 : AsyncBlockExpr::operator= (AsyncBlockExpr const &other)
1281 : {
1282 0 : ExprWithBlock::operator= (other);
1283 0 : has_move = other.has_move;
1284 0 : block_expr = other.block_expr->clone_block_expr ();
1285 0 : locus = other.locus;
1286 :
1287 0 : return *this;
1288 : }
1289 :
1290 688 : OperatorExprMeta::OperatorExprMeta (HIR::CompoundAssignmentExpr &expr)
1291 688 : : node_mappings (expr.get_mappings ()),
1292 688 : lvalue_mappings (expr.get_expr ().get_mappings ()),
1293 688 : rvalue_mappings (expr.get_rhs ().get_mappings ()), locus (expr.get_locus ())
1294 688 : {}
1295 :
1296 3524 : OperatorExprMeta::OperatorExprMeta (HIR::ArithmeticOrLogicalExpr &expr)
1297 3524 : : node_mappings (expr.get_mappings ()),
1298 3524 : lvalue_mappings (expr.get_expr ().get_mappings ()),
1299 3524 : rvalue_mappings (expr.get_rhs ().get_mappings ()), locus (expr.get_locus ())
1300 3524 : {}
1301 :
1302 544 : OperatorExprMeta::OperatorExprMeta (HIR::NegationExpr &expr)
1303 544 : : node_mappings (expr.get_mappings ()),
1304 544 : lvalue_mappings (expr.get_expr ().get_mappings ()),
1305 544 : rvalue_mappings (Analysis::NodeMapping::get_error ()),
1306 544 : locus (expr.get_locus ())
1307 544 : {}
1308 :
1309 3954 : OperatorExprMeta::OperatorExprMeta (HIR::DereferenceExpr &expr)
1310 3954 : : node_mappings (expr.get_mappings ()),
1311 3954 : lvalue_mappings (expr.get_expr ().get_mappings ()),
1312 3954 : rvalue_mappings (Analysis::NodeMapping::get_error ()),
1313 3954 : locus (expr.get_locus ())
1314 3954 : {}
1315 :
1316 128 : OperatorExprMeta::OperatorExprMeta (HIR::ArrayIndexExpr &expr)
1317 128 : : node_mappings (expr.get_mappings ()),
1318 128 : lvalue_mappings (expr.get_array_expr ().get_mappings ()),
1319 128 : rvalue_mappings (expr.get_index_expr ().get_mappings ()),
1320 128 : locus (expr.get_locus ())
1321 128 : {}
1322 :
1323 3546 : OperatorExprMeta::OperatorExprMeta (HIR::ComparisonExpr &expr)
1324 3546 : : node_mappings (expr.get_mappings ()),
1325 3546 : lvalue_mappings (expr.get_expr ().get_mappings ()),
1326 3546 : rvalue_mappings (expr.get_rhs ().get_mappings ()), locus (expr.get_locus ())
1327 3546 : {}
1328 :
1329 10 : InlineAsmOperand::In::In (
1330 : const tl::optional<struct AST::InlineAsmRegOrRegClass> ®,
1331 10 : std::unique_ptr<Expr> expr)
1332 10 : : reg (reg), expr (std::move (expr))
1333 : {
1334 10 : rust_assert (this->expr != nullptr);
1335 10 : }
1336 :
1337 48 : InlineAsmOperand::In::In (const struct In &other)
1338 : {
1339 48 : reg = other.reg;
1340 :
1341 48 : expr = other.expr->clone_expr ();
1342 48 : }
1343 :
1344 : InlineAsmOperand::In
1345 0 : InlineAsmOperand::In::operator= (const struct In &other)
1346 : {
1347 0 : reg = other.reg;
1348 0 : expr = other.expr->clone_expr ();
1349 :
1350 0 : return *this;
1351 : }
1352 :
1353 17 : InlineAsmOperand::Out::Out (
1354 : tl::optional<struct AST::InlineAsmRegOrRegClass> ®, bool late,
1355 17 : std::unique_ptr<Expr> expr)
1356 17 : : reg (reg), late (late), expr (std::move (expr))
1357 : {
1358 17 : rust_assert (this->expr != nullptr);
1359 17 : }
1360 :
1361 69 : InlineAsmOperand::Out::Out (const struct Out &other)
1362 : {
1363 69 : reg = other.reg;
1364 69 : late = other.late;
1365 69 : expr = other.expr->clone_expr ();
1366 69 : }
1367 :
1368 : InlineAsmOperand::Out
1369 0 : InlineAsmOperand::Out::operator= (const struct Out &other)
1370 : {
1371 0 : reg = other.reg;
1372 0 : late = other.late;
1373 0 : expr = other.expr->clone_expr ();
1374 0 : return *this;
1375 : }
1376 :
1377 0 : InlineAsmOperand::InOut::InOut (
1378 : tl::optional<struct AST::InlineAsmRegOrRegClass> ®, bool late,
1379 0 : std::unique_ptr<Expr> expr)
1380 0 : : reg (reg), late (late), expr (std::move (expr))
1381 : {
1382 0 : rust_assert (this->expr != nullptr);
1383 0 : }
1384 :
1385 0 : InlineAsmOperand::InOut::InOut (const struct InOut &other)
1386 : {
1387 0 : reg = other.reg;
1388 0 : late = other.late;
1389 0 : expr = other.expr->clone_expr ();
1390 0 : }
1391 :
1392 : InlineAsmOperand::InOut
1393 0 : InlineAsmOperand::InOut::operator= (const struct InOut &other)
1394 : {
1395 0 : reg = other.reg;
1396 0 : late = other.late;
1397 0 : expr = other.expr->clone_expr ();
1398 :
1399 0 : return *this;
1400 : }
1401 :
1402 2 : InlineAsmOperand::SplitInOut::SplitInOut (
1403 : tl::optional<struct AST::InlineAsmRegOrRegClass> ®, bool late,
1404 2 : std::unique_ptr<Expr> in_expr, std::unique_ptr<Expr> out_expr)
1405 2 : : reg (reg), late (late), in_expr (std::move (in_expr)),
1406 2 : out_expr (std::move (out_expr))
1407 : {
1408 2 : rust_assert (this->in_expr != nullptr);
1409 2 : rust_assert (this->out_expr != nullptr);
1410 2 : }
1411 :
1412 8 : InlineAsmOperand::SplitInOut::SplitInOut (const struct SplitInOut &other)
1413 : {
1414 8 : reg = other.reg;
1415 8 : late = other.late;
1416 8 : in_expr = other.in_expr->clone_expr ();
1417 8 : out_expr = other.out_expr->clone_expr ();
1418 8 : }
1419 :
1420 : InlineAsmOperand::SplitInOut
1421 0 : InlineAsmOperand::SplitInOut::operator= (const struct SplitInOut &other)
1422 : {
1423 0 : reg = other.reg;
1424 0 : late = other.late;
1425 0 : in_expr = other.in_expr->clone_expr ();
1426 0 : out_expr = other.out_expr->clone_expr ();
1427 :
1428 0 : return *this;
1429 : }
1430 :
1431 0 : InlineAsmOperand::Sym::Sym (std::unique_ptr<Expr> expr)
1432 0 : : expr (std::move (expr))
1433 : {
1434 0 : rust_assert (this->expr != nullptr);
1435 0 : }
1436 :
1437 0 : InlineAsmOperand::Sym::Sym (const struct Sym &other)
1438 : {
1439 0 : expr = std::unique_ptr<Expr> (other.expr->clone_expr ());
1440 0 : }
1441 :
1442 : InlineAsmOperand::Sym
1443 0 : InlineAsmOperand::Sym::operator= (const struct Sym &other)
1444 : {
1445 0 : expr = std::unique_ptr<Expr> (other.expr->clone_expr ());
1446 0 : return *this;
1447 : }
1448 :
1449 0 : InlineAsmOperand::Label::Label (tl::optional<std::string> label_name,
1450 0 : std::unique_ptr<Expr> expr)
1451 0 : : expr (std::move (expr))
1452 : {
1453 0 : rust_assert (this->expr != nullptr);
1454 0 : if (label_name.has_value ())
1455 0 : this->label_name = label_name.value ();
1456 0 : }
1457 :
1458 0 : InlineAsmOperand::Label::Label (const struct Label &other)
1459 : {
1460 0 : expr = std::unique_ptr<Expr> (other.expr->clone_expr ());
1461 0 : }
1462 :
1463 : InlineAsmOperand::Label
1464 0 : InlineAsmOperand::Label::operator= (const struct Label &other)
1465 : {
1466 0 : expr = std::unique_ptr<Expr> (other.expr->clone_expr ());
1467 0 : return *this;
1468 : }
1469 :
1470 27 : InlineAsm::InlineAsm (location_t locus, bool is_global_asm,
1471 : std::vector<AST::InlineAsmTemplatePiece> template_,
1472 : std::vector<AST::TupleTemplateStr> template_strs,
1473 : std::vector<HIR::InlineAsmOperand> operands,
1474 : std::vector<AST::TupleClobber> clobber_abi,
1475 : std::set<AST::InlineAsm::Option> options,
1476 : Analysis::NodeMapping mappings,
1477 27 : AST::AttrVec outer_attribs)
1478 : : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
1479 27 : locus (locus), is_global_asm (is_global_asm),
1480 27 : template_ (std::move (template_)),
1481 27 : template_strs (std::move (template_strs)), operands (std::move (operands)),
1482 27 : clobber_abi (std::move (clobber_abi)), options (std::move (options))
1483 27 : {}
1484 :
1485 : OffsetOf &
1486 0 : OffsetOf::operator= (const OffsetOf &other)
1487 : {
1488 0 : ExprWithoutBlock::operator= (other);
1489 :
1490 0 : type = other.type->clone_type ();
1491 0 : field = other.field;
1492 0 : loc = other.loc;
1493 :
1494 0 : return *this;
1495 : }
1496 :
1497 : ExprWithoutBlock *
1498 0 : OffsetOf::clone_expr_without_block_impl () const
1499 : {
1500 0 : return new OffsetOf (*this);
1501 : }
1502 :
1503 : std::string
1504 0 : OffsetOf::to_string () const
1505 : {
1506 0 : return "OffsetOf(" + type->to_string () + ", " + field.as_string () + ")";
1507 : }
1508 :
1509 : void
1510 44 : OffsetOf::accept_vis (HIRExpressionVisitor &vis)
1511 : {
1512 44 : vis.visit (*this);
1513 44 : }
1514 :
1515 : void
1516 59 : OffsetOf::accept_vis (HIRFullVisitor &vis)
1517 : {
1518 59 : vis.visit (*this);
1519 59 : }
1520 :
1521 : } // namespace HIR
1522 : } // namespace Rust
|