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