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-ast-lower-expr.h"
20 : #include "optional.h"
21 : #include "rust-ast-lower-base.h"
22 : #include "rust-ast-lower-block.h"
23 : #include "rust-ast-lower-struct-field-expr.h"
24 : #include "rust-ast-lower-pattern.h"
25 : #include "rust-ast-lower-type.h"
26 : #include "rust-ast.h"
27 : #include "rust-builtin-ast-nodes.h"
28 : #include "rust-diagnostics.h"
29 : #include "rust-hir-map.h"
30 : #include "rust-system.h"
31 : #include "tree/rust-hir-expr.h"
32 :
33 : namespace Rust {
34 : namespace HIR {
35 :
36 116495 : ASTLoweringExpr::ASTLoweringExpr ()
37 116495 : : ASTLoweringBase (), translated (nullptr), translated_array_elems (nullptr),
38 116495 : terminated (false)
39 116495 : {}
40 :
41 : HIR::Expr *
42 116495 : ASTLoweringExpr::translate (AST::Expr &expr, bool *terminated)
43 : {
44 116495 : ASTLoweringExpr resolver;
45 116495 : expr.accept_vis (resolver);
46 116495 : if (resolver.translated == nullptr)
47 : {
48 0 : rust_fatal_error (expr.get_locus (), "Failed to lower expr: [%s]",
49 0 : expr.as_string ().c_str ());
50 : return nullptr;
51 : }
52 :
53 116495 : resolver.mappings.insert_hir_expr (resolver.translated);
54 116495 : resolver.mappings.insert_location (
55 116495 : resolver.translated->get_mappings ().get_hirid (), expr.get_locus ());
56 :
57 116495 : if (terminated != nullptr)
58 26660 : *terminated = resolver.terminated;
59 :
60 116495 : return resolver.translated;
61 116495 : }
62 :
63 : void
64 897 : ASTLoweringExpr::visit (AST::TupleIndexExpr &expr)
65 : {
66 897 : HIR::Expr *tuple_expr
67 897 : = ASTLoweringExpr::translate (expr.get_tuple_expr (), &terminated);
68 :
69 897 : auto crate_num = mappings.get_current_crate ();
70 1794 : Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
71 897 : mappings.get_next_hir_id (crate_num),
72 897 : UNKNOWN_LOCAL_DEFID);
73 :
74 897 : translated
75 897 : = new HIR::TupleIndexExpr (mapping, std::unique_ptr<HIR::Expr> (tuple_expr),
76 897 : expr.get_tuple_index (), expr.get_outer_attrs (),
77 1794 : expr.get_locus ());
78 897 : }
79 :
80 : void
81 556 : ASTLoweringExpr::visit (AST::TupleExpr &expr)
82 : {
83 556 : std::vector<std::unique_ptr<HIR::Expr>> tuple_elements;
84 556 : tuple_elements.reserve (expr.get_tuple_elems ().size ());
85 :
86 1523 : for (auto &e : expr.get_tuple_elems ())
87 967 : tuple_elements.emplace_back (ASTLoweringExpr::translate (*e));
88 :
89 556 : auto crate_num = mappings.get_current_crate ();
90 1112 : Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
91 556 : mappings.get_next_hir_id (crate_num),
92 556 : UNKNOWN_LOCAL_DEFID);
93 :
94 556 : translated
95 556 : = new HIR::TupleExpr (std::move (mapping), std::move (tuple_elements),
96 1112 : expr.get_inner_attrs (), expr.get_outer_attrs (),
97 556 : expr.get_locus ());
98 556 : }
99 :
100 : void
101 461 : ASTLoweringExpr::visit (AST::IfExpr &expr)
102 : {
103 461 : translated = ASTLoweringIfBlock::translate (expr, &terminated);
104 461 : }
105 :
106 : void
107 892 : ASTLoweringExpr::visit (AST::IfExprConseqElse &expr)
108 : {
109 892 : translated = ASTLoweringIfBlock::translate (expr, &terminated);
110 892 : }
111 :
112 : void
113 17 : ASTLoweringExpr::visit (AST::IfLetExpr &expr)
114 : {
115 17 : translated = ASTLoweringIfLetBlock::translate (expr);
116 17 : }
117 :
118 : void
119 11 : ASTLoweringExpr::visit (AST::IfLetExprConseqElse &expr)
120 : {
121 11 : translated = ASTLoweringIfLetBlock::translate (expr);
122 11 : }
123 :
124 : void
125 1593 : ASTLoweringExpr::visit (AST::BlockExpr &expr)
126 : {
127 1593 : translated = ASTLoweringBlock::translate (expr, &terminated);
128 1593 : }
129 :
130 : void
131 678 : ASTLoweringExpr::visit (AST::AnonConst &expr)
132 : {
133 678 : auto &mappings = Analysis::Mappings::get ();
134 678 : auto crate_num = mappings.get_current_crate ();
135 1356 : auto mapping = Analysis::NodeMapping (crate_num, expr.get_node_id (),
136 : mappings.get_next_hir_id (crate_num),
137 678 : UNKNOWN_LOCAL_DEFID);
138 :
139 678 : if (expr.is_deferred ())
140 : {
141 11 : translated = new HIR::AnonConst (std::move (mapping), expr.get_locus ());
142 : }
143 : else
144 : {
145 667 : auto inner_expr = ASTLoweringExpr::translate (expr.get_inner_expr ());
146 :
147 1334 : translated = new HIR::AnonConst (std::move (mapping),
148 667 : std::unique_ptr<Expr> (inner_expr),
149 667 : expr.get_locus ());
150 : }
151 678 : }
152 :
153 : void
154 15 : ASTLoweringExpr::visit (AST::ConstBlock &expr)
155 : {
156 15 : auto inner_expr = ASTLoweringExpr::translate (expr.get_const_expr ());
157 :
158 : // we know this will always be an `AnonConst`, or we have an issue. Let's
159 : // assert just to be sure.
160 15 : rust_assert (inner_expr->get_expression_type () == Expr::ExprType::AnonConst);
161 15 : auto anon_const = static_cast<AnonConst *> (inner_expr);
162 :
163 15 : auto &mappings = Analysis::Mappings::get ();
164 15 : auto crate_num = mappings.get_current_crate ();
165 30 : auto mapping = Analysis::NodeMapping (crate_num, expr.get_node_id (),
166 : mappings.get_next_hir_id (crate_num),
167 15 : UNKNOWN_LOCAL_DEFID);
168 :
169 15 : translated
170 15 : = new HIR::ConstBlock (std::move (mapping), std::move (*anon_const),
171 15 : expr.get_locus (), expr.get_outer_attrs ());
172 15 : }
173 :
174 : void
175 3516 : ASTLoweringExpr::visit (AST::UnsafeBlockExpr &expr)
176 : {
177 3516 : translated = ASTLoweringBlock::translate (expr, &terminated);
178 3516 : }
179 :
180 : void
181 20465 : ASTLoweringExpr::visit (AST::PathInExpression &expr)
182 : {
183 20465 : translated = ASTLowerPathInExpression::translate (expr);
184 20465 : }
185 :
186 : void
187 114 : ASTLoweringExpr::visit (AST::QualifiedPathInExpression &expr)
188 : {
189 114 : translated = ASTLowerQualPathInExpression::translate (expr);
190 114 : }
191 :
192 : void
193 0 : ASTLoweringExpr::visit (AST::BoxExpr &expr)
194 : {
195 0 : rust_sorry_at (expr.get_locus (),
196 : "box expression syntax is not supported yet");
197 0 : }
198 :
199 : void
200 534 : ASTLoweringExpr::visit (AST::ReturnExpr &expr)
201 : {
202 534 : terminated = true;
203 534 : HIR::Expr *return_expr
204 534 : = expr.has_returned_expr ()
205 534 : ? ASTLoweringExpr::translate (expr.get_returned_expr ())
206 : : nullptr;
207 :
208 534 : auto crate_num = mappings.get_current_crate ();
209 1068 : Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
210 534 : mappings.get_next_hir_id (crate_num),
211 534 : UNKNOWN_LOCAL_DEFID);
212 :
213 1068 : translated = new HIR::ReturnExpr (mapping, expr.get_locus (),
214 534 : std::unique_ptr<HIR::Expr> (return_expr));
215 534 : }
216 :
217 : void
218 11039 : ASTLoweringExpr::visit (AST::CallExpr &expr)
219 : {
220 11039 : HIR::Expr *func = ASTLoweringExpr::translate (expr.get_function_expr ());
221 :
222 11039 : auto const &in_params = expr.get_params ();
223 :
224 11039 : std::vector<std::unique_ptr<HIR::Expr>> params;
225 11039 : params.reserve (in_params.size ());
226 :
227 24121 : for (auto ¶m : in_params)
228 13082 : params.emplace_back (ASTLoweringExpr::translate (*param));
229 :
230 11039 : auto crate_num = mappings.get_current_crate ();
231 11039 : Analysis::NodeMapping mapping (
232 : crate_num, UNKNOWN_NODEID /* this can map back to the AST*/,
233 11039 : mappings.get_next_hir_id (crate_num), UNKNOWN_LOCAL_DEFID);
234 :
235 11039 : translated = new HIR::CallExpr (mapping, std::unique_ptr<HIR::Expr> (func),
236 11039 : std::move (params), expr.get_outer_attrs (),
237 22078 : expr.get_locus ());
238 11039 : }
239 :
240 : void
241 2974 : ASTLoweringExpr::visit (AST::MethodCallExpr &expr)
242 : {
243 2974 : HIR::PathExprSegment method_path
244 2974 : = lower_path_expr_seg (expr.get_method_name ());
245 :
246 2974 : HIR::Expr *receiver = ASTLoweringExpr::translate (expr.get_receiver_expr ());
247 :
248 2974 : auto const &in_params = expr.get_params ();
249 2974 : std::vector<std::unique_ptr<HIR::Expr>> params;
250 2974 : params.reserve (in_params.size ());
251 :
252 5009 : for (auto ¶m : in_params)
253 2035 : params.emplace_back (ASTLoweringExpr::translate (*param));
254 :
255 2974 : auto crate_num = mappings.get_current_crate ();
256 5948 : Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
257 2974 : mappings.get_next_hir_id (crate_num),
258 2974 : UNKNOWN_LOCAL_DEFID);
259 :
260 2974 : translated
261 2974 : = new HIR::MethodCallExpr (mapping, std::unique_ptr<HIR::Expr> (receiver),
262 : method_path, std::move (params),
263 5948 : expr.get_outer_attrs (), expr.get_locus ());
264 2974 : }
265 :
266 : void
267 2491 : ASTLoweringExpr::visit (AST::AssignmentExpr &expr)
268 : {
269 2491 : HIR::Expr *lhs = ASTLoweringExpr::translate (expr.get_left_expr ());
270 2491 : HIR::Expr *rhs = ASTLoweringExpr::translate (expr.get_right_expr ());
271 :
272 2491 : auto crate_num = mappings.get_current_crate ();
273 4982 : Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
274 2491 : mappings.get_next_hir_id (crate_num),
275 2491 : UNKNOWN_LOCAL_DEFID);
276 :
277 2491 : translated
278 2491 : = new HIR::AssignmentExpr (mapping, std::unique_ptr<HIR::Expr> (lhs),
279 4982 : std::unique_ptr<HIR::Expr> (rhs),
280 2491 : expr.get_locus ());
281 2491 : }
282 :
283 : void
284 24212 : ASTLoweringExpr::visit (AST::IdentifierExpr &expr)
285 : {
286 24212 : auto crate_num = mappings.get_current_crate ();
287 48424 : Analysis::NodeMapping mapping1 (crate_num, expr.get_node_id (),
288 24212 : mappings.get_next_hir_id (crate_num),
289 24212 : UNKNOWN_LOCAL_DEFID);
290 24212 : Analysis::NodeMapping mapping2 (mapping1);
291 :
292 48424 : HIR::PathIdentSegment ident_seg (expr.get_ident ().as_string ());
293 24212 : HIR::PathExprSegment seg (mapping1, ident_seg, expr.get_locus (),
294 48424 : HIR::GenericArgs::create_empty ());
295 48424 : translated = new HIR::PathInExpression (mapping2, {seg}, expr.get_locus (),
296 48424 : false, expr.get_outer_attrs ());
297 24212 : }
298 :
299 : void
300 427 : ASTLoweringExpr::visit (AST::ArrayExpr &expr)
301 : {
302 427 : expr.get_array_elems ()->accept_vis (*this);
303 427 : rust_assert (translated_array_elems != nullptr);
304 427 : HIR::ArrayElems *elems = translated_array_elems;
305 :
306 427 : auto crate_num = mappings.get_current_crate ();
307 854 : Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
308 427 : mappings.get_next_hir_id (crate_num),
309 427 : UNKNOWN_LOCAL_DEFID);
310 :
311 427 : translated
312 427 : = new HIR::ArrayExpr (mapping, std::unique_ptr<HIR::ArrayElems> (elems),
313 854 : expr.get_inner_attrs (), expr.get_outer_attrs (),
314 854 : expr.get_locus ());
315 427 : }
316 :
317 : void
318 243 : ASTLoweringExpr::visit (AST::ArrayIndexExpr &expr)
319 : {
320 243 : HIR::Expr *array_expr = ASTLoweringExpr::translate (expr.get_array_expr ());
321 243 : HIR::Expr *array_index_expr
322 243 : = ASTLoweringExpr::translate (expr.get_index_expr ());
323 :
324 243 : auto crate_num = mappings.get_current_crate ();
325 486 : Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
326 243 : mappings.get_next_hir_id (crate_num),
327 243 : UNKNOWN_LOCAL_DEFID);
328 :
329 243 : translated
330 243 : = new HIR::ArrayIndexExpr (mapping, std::unique_ptr<HIR::Expr> (array_expr),
331 486 : std::unique_ptr<HIR::Expr> (array_index_expr),
332 486 : expr.get_outer_attrs (), expr.get_locus ());
333 243 : }
334 :
335 : void
336 305 : ASTLoweringExpr::visit (AST::ArrayElemsValues &elems)
337 : {
338 305 : std::vector<std::unique_ptr<HIR::Expr>> elements;
339 305 : elements.reserve (elems.get_values ().size ());
340 :
341 1769 : for (auto &elem : elems.get_values ())
342 1464 : elements.emplace_back (ASTLoweringExpr::translate (*elem));
343 :
344 305 : auto crate_num = mappings.get_current_crate ();
345 305 : Analysis::NodeMapping mapping (mappings.get_current_crate (),
346 : elems.get_node_id (),
347 305 : mappings.get_next_hir_id (crate_num),
348 305 : UNKNOWN_LOCAL_DEFID);
349 :
350 305 : translated_array_elems
351 305 : = new HIR::ArrayElemsValues (mapping, std::move (elements));
352 305 : }
353 :
354 : void
355 122 : ASTLoweringExpr::visit (AST::ArrayElemsCopied &elems)
356 : {
357 122 : HIR::Expr *element = ASTLoweringExpr::translate (elems.get_elem_to_copy ());
358 122 : HIR::Expr *num_copies = ASTLoweringExpr::translate (elems.get_num_copies ());
359 :
360 122 : auto crate_num = mappings.get_current_crate ();
361 122 : Analysis::NodeMapping mapping (mappings.get_current_crate (),
362 : elems.get_node_id (),
363 122 : mappings.get_next_hir_id (crate_num),
364 122 : UNKNOWN_LOCAL_DEFID);
365 :
366 122 : translated_array_elems
367 122 : = new HIR::ArrayElemsCopied (mapping, std::unique_ptr<HIR::Expr> (element),
368 244 : std::unique_ptr<HIR::Expr> (num_copies));
369 122 : }
370 :
371 : void
372 18534 : ASTLoweringExpr::visit (AST::LiteralExpr &expr)
373 : {
374 18534 : auto crate_num = mappings.get_current_crate ();
375 37068 : Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
376 18534 : mappings.get_next_hir_id (crate_num),
377 18534 : UNKNOWN_LOCAL_DEFID);
378 :
379 18534 : HIR::Literal l = lower_literal (expr.get_literal ());
380 18534 : translated = new HIR::LiteralExpr (mapping, std::move (l), expr.get_locus (),
381 37068 : expr.get_outer_attrs ());
382 18534 : }
383 :
384 : void
385 3359 : ASTLoweringExpr::visit (AST::ArithmeticOrLogicalExpr &expr)
386 : {
387 3359 : HIR::Expr *lhs = ASTLoweringExpr::translate (expr.get_left_expr ());
388 3359 : rust_assert (lhs != nullptr);
389 3359 : HIR::Expr *rhs = ASTLoweringExpr::translate (expr.get_right_expr ());
390 3359 : rust_assert (rhs != nullptr);
391 :
392 3359 : auto crate_num = mappings.get_current_crate ();
393 6718 : Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
394 3359 : mappings.get_next_hir_id (crate_num),
395 3359 : UNKNOWN_LOCAL_DEFID);
396 :
397 6718 : translated = new HIR::ArithmeticOrLogicalExpr (
398 3359 : mapping, std::unique_ptr<HIR::Expr> (lhs), std::unique_ptr<HIR::Expr> (rhs),
399 3359 : expr.get_expr_type (), expr.get_locus ());
400 3359 : }
401 :
402 : void
403 2706 : ASTLoweringExpr::visit (AST::ComparisonExpr &expr)
404 : {
405 2706 : HIR::Expr *lhs = ASTLoweringExpr::translate (expr.get_left_expr ());
406 2706 : rust_assert (lhs != nullptr);
407 2706 : HIR::Expr *rhs = ASTLoweringExpr::translate (expr.get_right_expr ());
408 2706 : rust_assert (rhs != nullptr);
409 :
410 2706 : auto crate_num = mappings.get_current_crate ();
411 5412 : Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
412 2706 : mappings.get_next_hir_id (crate_num),
413 2706 : UNKNOWN_LOCAL_DEFID);
414 :
415 2706 : translated
416 2706 : = new HIR::ComparisonExpr (mapping, std::unique_ptr<HIR::Expr> (lhs),
417 5412 : std::unique_ptr<HIR::Expr> (rhs),
418 2706 : expr.get_expr_type (), expr.get_locus ());
419 2706 : }
420 :
421 : void
422 385 : ASTLoweringExpr::visit (AST::LazyBooleanExpr &expr)
423 : {
424 385 : HIR::Expr *lhs = ASTLoweringExpr::translate (expr.get_left_expr ());
425 385 : rust_assert (lhs != nullptr);
426 385 : HIR::Expr *rhs = ASTLoweringExpr::translate (expr.get_right_expr ());
427 385 : rust_assert (rhs != nullptr);
428 :
429 385 : auto crate_num = mappings.get_current_crate ();
430 770 : Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
431 385 : mappings.get_next_hir_id (crate_num),
432 385 : UNKNOWN_LOCAL_DEFID);
433 :
434 385 : translated
435 385 : = new HIR::LazyBooleanExpr (mapping, std::unique_ptr<HIR::Expr> (lhs),
436 770 : std::unique_ptr<HIR::Expr> (rhs),
437 385 : expr.get_expr_type (), expr.get_locus ());
438 385 : }
439 :
440 : void
441 530 : ASTLoweringExpr::visit (AST::NegationExpr &expr)
442 : {
443 530 : HIR::Expr *negated_value
444 530 : = ASTLoweringExpr::translate (expr.get_negated_expr ());
445 :
446 530 : auto crate_num = mappings.get_current_crate ();
447 1060 : Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
448 530 : mappings.get_next_hir_id (crate_num),
449 530 : UNKNOWN_LOCAL_DEFID);
450 530 : translated
451 530 : = new HIR::NegationExpr (mapping,
452 530 : std::unique_ptr<HIR::Expr> (negated_value),
453 530 : expr.get_expr_type (), expr.get_outer_attrs (),
454 1060 : expr.get_locus ());
455 530 : }
456 :
457 : void
458 5112 : ASTLoweringExpr::visit (AST::TypeCastExpr &expr)
459 : {
460 5112 : HIR::Expr *expr_to_cast_to
461 5112 : = ASTLoweringExpr::translate (expr.get_casted_expr ());
462 5112 : HIR::Type *type_to_cast_to
463 5112 : = lower_type_no_bounds (expr.get_type_to_cast_to ());
464 :
465 5112 : auto crate_num = mappings.get_current_crate ();
466 10224 : Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
467 5112 : mappings.get_next_hir_id (crate_num),
468 5112 : UNKNOWN_LOCAL_DEFID);
469 :
470 5112 : translated
471 5112 : = new HIR::TypeCastExpr (mapping,
472 5112 : std::unique_ptr<HIR::Expr> (expr_to_cast_to),
473 10224 : std::unique_ptr<HIR::Type> (type_to_cast_to),
474 5112 : expr.get_locus ());
475 5112 : }
476 :
477 : void
478 674 : ASTLoweringExpr::visit (AST::CompoundAssignmentExpr &expr)
479 : {
480 674 : ArithmeticOrLogicalOperator op;
481 674 : switch (expr.get_expr_type ())
482 : {
483 : case CompoundAssignmentOperator::ADD:
484 : op = ArithmeticOrLogicalOperator::ADD;
485 : break;
486 : case CompoundAssignmentOperator::SUBTRACT:
487 : op = ArithmeticOrLogicalOperator::SUBTRACT;
488 : break;
489 : case CompoundAssignmentOperator::MULTIPLY:
490 : op = ArithmeticOrLogicalOperator::MULTIPLY;
491 : break;
492 : case CompoundAssignmentOperator::DIVIDE:
493 : op = ArithmeticOrLogicalOperator::DIVIDE;
494 : break;
495 : case CompoundAssignmentOperator::MODULUS:
496 : op = ArithmeticOrLogicalOperator::MODULUS;
497 : break;
498 : case CompoundAssignmentOperator::BITWISE_AND:
499 : op = ArithmeticOrLogicalOperator::BITWISE_AND;
500 : break;
501 : case CompoundAssignmentOperator::BITWISE_OR:
502 : op = ArithmeticOrLogicalOperator::BITWISE_OR;
503 : break;
504 : case CompoundAssignmentOperator::BITWISE_XOR:
505 : op = ArithmeticOrLogicalOperator::BITWISE_XOR;
506 : break;
507 : case CompoundAssignmentOperator::LEFT_SHIFT:
508 : op = ArithmeticOrLogicalOperator::LEFT_SHIFT;
509 : break;
510 : case CompoundAssignmentOperator::RIGHT_SHIFT:
511 : op = ArithmeticOrLogicalOperator::RIGHT_SHIFT;
512 : break;
513 0 : default:
514 0 : rust_unreachable ();
515 : }
516 :
517 674 : HIR::Expr *asignee_expr = ASTLoweringExpr::translate (expr.get_left_expr ());
518 674 : HIR::Expr *value = ASTLoweringExpr::translate (expr.get_right_expr ());
519 :
520 674 : auto crate_num = mappings.get_current_crate ();
521 1348 : Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
522 674 : mappings.get_next_hir_id (crate_num),
523 674 : UNKNOWN_LOCAL_DEFID);
524 :
525 1348 : translated = new HIR::CompoundAssignmentExpr (
526 674 : mapping, std::unique_ptr<HIR::Expr> (asignee_expr),
527 1348 : std::unique_ptr<HIR::Expr> (value), op, expr.get_locus ());
528 674 : }
529 :
530 : void
531 81 : ASTLoweringExpr::visit (AST::StructExprStruct &struct_expr)
532 : {
533 81 : HIR::PathInExpression *path
534 81 : = ASTLowerPathInExpression::translate (struct_expr.get_struct_name ());
535 81 : HIR::PathInExpression copied_path (*path);
536 81 : delete path;
537 :
538 81 : auto crate_num = mappings.get_current_crate ();
539 162 : Analysis::NodeMapping mapping (crate_num, struct_expr.get_node_id (),
540 81 : mappings.get_next_hir_id (crate_num),
541 81 : UNKNOWN_LOCAL_DEFID);
542 :
543 162 : translated = new HIR::StructExprStruct (mapping, copied_path,
544 81 : struct_expr.get_inner_attrs (),
545 81 : struct_expr.get_outer_attrs (),
546 81 : struct_expr.get_locus ());
547 81 : }
548 :
549 : void
550 1325 : ASTLoweringExpr::visit (AST::StructExprStructFields &struct_expr)
551 : {
552 : // bit of a hack for now
553 1325 : HIR::PathInExpression *path
554 1325 : = ASTLowerPathInExpression::translate (struct_expr.get_struct_name ());
555 1325 : HIR::PathInExpression copied_path (*path);
556 1325 : delete path;
557 :
558 1325 : tl::optional<std::unique_ptr<HIR::StructBase>> base = tl::nullopt;
559 1325 : if (struct_expr.has_struct_base ())
560 : {
561 63 : HIR::Expr *translated_base = ASTLoweringExpr::translate (
562 63 : struct_expr.get_struct_base ().get_base_struct ());
563 63 : base = tl::optional<std::unique_ptr<HIR::StructBase>> (
564 126 : std::make_unique<StructBase> (
565 126 : std::unique_ptr<HIR::Expr> (translated_base)));
566 : }
567 :
568 1325 : auto const &in_fields = struct_expr.get_fields ();
569 :
570 1325 : std::vector<std::unique_ptr<HIR::StructExprField>> fields;
571 1325 : fields.reserve (in_fields.size ());
572 :
573 3609 : for (auto &field : in_fields)
574 2284 : fields.emplace_back (ASTLowerStructExprField::translate (*field));
575 :
576 1325 : auto crate_num = mappings.get_current_crate ();
577 2650 : Analysis::NodeMapping mapping (crate_num, struct_expr.get_node_id (),
578 1325 : mappings.get_next_hir_id (crate_num),
579 1325 : UNKNOWN_LOCAL_DEFID);
580 :
581 1325 : translated
582 1325 : = new HIR::StructExprStructFields (mapping, copied_path, std::move (fields),
583 : struct_expr.get_locus (),
584 : std::move (base),
585 1325 : struct_expr.get_inner_attrs (),
586 2713 : struct_expr.get_outer_attrs ());
587 1388 : }
588 :
589 : void
590 310 : ASTLoweringExpr::visit (AST::GroupedExpr &expr)
591 : {
592 310 : HIR::Expr *paren_expr
593 310 : = ASTLoweringExpr::translate (expr.get_expr_in_parens ());
594 :
595 310 : auto crate_num = mappings.get_current_crate ();
596 620 : Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
597 310 : mappings.get_next_hir_id (crate_num),
598 310 : UNKNOWN_LOCAL_DEFID);
599 :
600 310 : translated
601 310 : = new HIR::GroupedExpr (mapping, std::unique_ptr<HIR::Expr> (paren_expr),
602 620 : expr.get_inner_attrs (), expr.get_outer_attrs (),
603 620 : expr.get_locus ());
604 310 : }
605 :
606 : void
607 4936 : ASTLoweringExpr::visit (AST::FieldAccessExpr &expr)
608 : {
609 4936 : HIR::Expr *receiver = ASTLoweringExpr::translate (expr.get_receiver_expr ());
610 :
611 4936 : auto crate_num = mappings.get_current_crate ();
612 9872 : Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
613 4936 : mappings.get_next_hir_id (crate_num),
614 4936 : UNKNOWN_LOCAL_DEFID);
615 4936 : translated
616 4936 : = new HIR::FieldAccessExpr (mapping, std::unique_ptr<HIR::Expr> (receiver),
617 9872 : expr.get_field_name (), expr.get_outer_attrs (),
618 9872 : expr.get_locus ());
619 4936 : }
620 :
621 : void
622 124 : ASTLoweringExpr::visit (AST::LoopExpr &expr)
623 : {
624 124 : translated = ASTLoweringExprWithBlock::translate (expr, &terminated);
625 124 : }
626 :
627 : void
628 77 : ASTLoweringExpr::visit (AST::WhileLoopExpr &expr)
629 : {
630 77 : translated = ASTLoweringExprWithBlock::translate (expr, &terminated);
631 77 : }
632 :
633 : void
634 87 : ASTLoweringExpr::visit (AST::BreakExpr &expr)
635 : {
636 87 : tl::optional<HIR::Lifetime> break_label = tl::nullopt;
637 87 : if (expr.has_label ())
638 18 : break_label = lower_lifetime (expr.get_label_unchecked ().get_lifetime ());
639 :
640 87 : HIR::Expr *break_expr
641 87 : = expr.has_break_expr ()
642 87 : ? ASTLoweringExpr::translate (expr.get_break_expr_unchecked ())
643 : : nullptr;
644 :
645 87 : auto crate_num = mappings.get_current_crate ();
646 174 : Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
647 87 : mappings.get_next_hir_id (crate_num),
648 87 : UNKNOWN_LOCAL_DEFID);
649 :
650 87 : translated
651 87 : = new HIR::BreakExpr (mapping, expr.get_locus (), std ::move (break_label),
652 87 : std::unique_ptr<HIR::Expr> (break_expr),
653 174 : expr.get_outer_attrs ());
654 87 : }
655 :
656 : void
657 16 : ASTLoweringExpr::visit (AST::ContinueExpr &expr)
658 : {
659 16 : tl::optional<HIR::Lifetime> break_label;
660 16 : if (expr.has_label ())
661 2 : break_label = lower_lifetime (expr.get_label_unchecked ());
662 :
663 16 : auto crate_num = mappings.get_current_crate ();
664 32 : Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
665 16 : mappings.get_next_hir_id (crate_num),
666 16 : UNKNOWN_LOCAL_DEFID);
667 :
668 16 : translated
669 16 : = new HIR::ContinueExpr (mapping, expr.get_locus (),
670 32 : std ::move (break_label), expr.get_outer_attrs ());
671 16 : }
672 :
673 : void
674 1936 : ASTLoweringExpr::visit (AST::BorrowExpr &expr)
675 : {
676 1936 : HIR::Expr *borrow_lvalue
677 1936 : = ASTLoweringExpr::translate (expr.get_borrowed_expr ());
678 :
679 1936 : auto crate_num = mappings.get_current_crate ();
680 3872 : Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
681 1936 : mappings.get_next_hir_id (crate_num),
682 1936 : UNKNOWN_LOCAL_DEFID);
683 :
684 1936 : auto *borrow_expr
685 1936 : = new HIR::BorrowExpr (mapping, std::unique_ptr<HIR::Expr> (borrow_lvalue),
686 1936 : expr.get_mutability (), expr.is_raw_borrow (),
687 1936 : expr.get_outer_attrs (), expr.get_locus ());
688 :
689 1936 : if (expr.get_is_double_borrow ())
690 : {
691 23 : NodeId artificial_double_borrow_id = mappings.get_next_node_id ();
692 23 : Analysis::NodeMapping mapping (crate_num, artificial_double_borrow_id,
693 23 : mappings.get_next_hir_id (crate_num),
694 23 : UNKNOWN_LOCAL_DEFID);
695 :
696 23 : borrow_expr
697 23 : = new HIR::BorrowExpr (mapping,
698 23 : std::unique_ptr<HIR::Expr> (borrow_expr),
699 23 : expr.get_mutability (), expr.is_raw_borrow (),
700 46 : expr.get_outer_attrs (), expr.get_locus ());
701 : }
702 :
703 1936 : translated = borrow_expr;
704 1936 : }
705 :
706 : void
707 3905 : ASTLoweringExpr::visit (AST::DereferenceExpr &expr)
708 : {
709 3905 : HIR::Expr *dref_lvalue
710 3905 : = ASTLoweringExpr::translate (expr.get_dereferenced_expr ());
711 :
712 3905 : auto crate_num = mappings.get_current_crate ();
713 7810 : Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
714 3905 : mappings.get_next_hir_id (crate_num),
715 3905 : UNKNOWN_LOCAL_DEFID);
716 :
717 3905 : translated
718 3905 : = new HIR::DereferenceExpr (mapping,
719 3905 : std::unique_ptr<HIR::Expr> (dref_lvalue),
720 7810 : expr.get_outer_attrs (), expr.get_locus ());
721 3905 : }
722 :
723 : void
724 1066 : ASTLoweringExpr::visit (AST::MatchExpr &expr)
725 : {
726 1066 : translated = ASTLoweringExprWithBlock::translate (expr, &terminated);
727 1066 : }
728 :
729 : void
730 66 : ASTLoweringExpr::visit (AST::RangeFromToExpr &expr)
731 : {
732 66 : auto crate_num = mappings.get_current_crate ();
733 132 : Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
734 66 : mappings.get_next_hir_id (crate_num),
735 66 : UNKNOWN_LOCAL_DEFID);
736 :
737 66 : HIR::Expr *range_from = ASTLoweringExpr::translate (expr.get_from_expr ());
738 66 : HIR::Expr *range_to = ASTLoweringExpr::translate (expr.get_to_expr ());
739 :
740 66 : translated
741 66 : = new HIR::RangeFromToExpr (mapping,
742 66 : std::unique_ptr<HIR::Expr> (range_from),
743 132 : std::unique_ptr<HIR::Expr> (range_to),
744 66 : expr.get_locus ());
745 66 : }
746 :
747 : void
748 7 : ASTLoweringExpr::visit (AST::RangeFromExpr &expr)
749 : {
750 7 : auto crate_num = mappings.get_current_crate ();
751 14 : Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
752 7 : mappings.get_next_hir_id (crate_num),
753 7 : UNKNOWN_LOCAL_DEFID);
754 :
755 7 : HIR::Expr *range_from = ASTLoweringExpr::translate (expr.get_from_expr ());
756 :
757 7 : translated
758 7 : = new HIR::RangeFromExpr (mapping, std::unique_ptr<HIR::Expr> (range_from),
759 7 : expr.get_locus ());
760 7 : }
761 :
762 : void
763 7 : ASTLoweringExpr::visit (AST::RangeToExpr &expr)
764 : {
765 7 : auto crate_num = mappings.get_current_crate ();
766 14 : Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
767 7 : mappings.get_next_hir_id (crate_num),
768 7 : UNKNOWN_LOCAL_DEFID);
769 :
770 7 : HIR::Expr *range_to = ASTLoweringExpr::translate (expr.get_to_expr ());
771 :
772 7 : translated
773 7 : = new HIR::RangeToExpr (mapping, std::unique_ptr<HIR::Expr> (range_to),
774 7 : expr.get_locus ());
775 7 : }
776 :
777 : void
778 0 : ASTLoweringExpr::visit (AST::RangeFullExpr &expr)
779 : {
780 0 : auto crate_num = mappings.get_current_crate ();
781 0 : Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
782 0 : mappings.get_next_hir_id (crate_num),
783 0 : UNKNOWN_LOCAL_DEFID);
784 :
785 0 : translated = new HIR::RangeFullExpr (mapping, expr.get_locus ());
786 0 : }
787 :
788 : void
789 7 : ASTLoweringExpr::visit (AST::RangeFromToInclExpr &expr)
790 : {
791 7 : auto crate_num = mappings.get_current_crate ();
792 14 : Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
793 7 : mappings.get_next_hir_id (crate_num),
794 7 : UNKNOWN_LOCAL_DEFID);
795 :
796 7 : HIR::Expr *range_from = ASTLoweringExpr::translate (expr.get_from_expr ());
797 7 : HIR::Expr *range_to = ASTLoweringExpr::translate (expr.get_to_expr ());
798 :
799 7 : translated
800 7 : = new HIR::RangeFromToInclExpr (mapping,
801 7 : std::unique_ptr<HIR::Expr> (range_from),
802 14 : std::unique_ptr<HIR::Expr> (range_to),
803 7 : expr.get_locus ());
804 7 : }
805 :
806 : void
807 36 : ASTLoweringExpr::visit (AST::ClosureExprInner &expr)
808 : {
809 36 : HIR::Expr *closure_expr
810 36 : = ASTLoweringExpr::translate (expr.get_definition_expr ());
811 :
812 36 : std::vector<HIR::ClosureParam> closure_params;
813 36 : closure_params.reserve (expr.get_params ().size ());
814 :
815 60 : for (auto ¶m : expr.get_params ())
816 24 : closure_params.emplace_back (lower_closure_param (param));
817 :
818 36 : auto crate_num = mappings.get_current_crate ();
819 72 : Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
820 36 : mappings.get_next_hir_id (crate_num),
821 36 : mappings.get_next_localdef_id (crate_num));
822 :
823 36 : translated
824 36 : = new HIR::ClosureExpr (mapping, std::move (closure_params),
825 : nullptr /* closure_return_type */,
826 36 : std::unique_ptr<HIR::Expr> (closure_expr),
827 72 : expr.get_has_move (), expr.get_outer_attrs (),
828 36 : expr.get_locus ());
829 36 : }
830 :
831 : void
832 30 : ASTLoweringExpr::visit (AST::ClosureExprInnerTyped &expr)
833 : {
834 30 : HIR::Type *closure_return_type = nullptr;
835 30 : HIR::Expr *closure_expr
836 30 : = ASTLoweringExpr::translate (expr.get_definition_expr ());
837 :
838 30 : std::vector<HIR::ClosureParam> closure_params;
839 30 : closure_params.reserve (expr.get_params ().size ());
840 :
841 67 : for (auto ¶m : expr.get_params ())
842 37 : closure_params.emplace_back (lower_closure_param (param));
843 :
844 30 : auto crate_num = mappings.get_current_crate ();
845 60 : Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
846 30 : mappings.get_next_hir_id (crate_num),
847 30 : mappings.get_next_localdef_id (crate_num));
848 :
849 30 : translated
850 30 : = new HIR::ClosureExpr (mapping, std::move (closure_params),
851 90 : std::unique_ptr<HIR::Type> (closure_return_type),
852 60 : std::unique_ptr<HIR::Expr> (closure_expr),
853 60 : expr.get_has_move (), expr.get_outer_attrs (),
854 60 : expr.get_locus ());
855 30 : }
856 :
857 : HIR::InlineAsmOperand
858 10 : translate_operand_in (const AST::InlineAsmOperand &operand)
859 : {
860 10 : auto in_value = operand.get_in ();
861 :
862 10 : struct HIR::InlineAsmOperand::In in (
863 : in_value.reg,
864 10 : std::unique_ptr<Expr> (ASTLoweringExpr::translate (*in_value.expr.get ())));
865 10 : return in;
866 10 : }
867 :
868 : HIR::InlineAsmOperand
869 17 : translate_operand_out (const AST::InlineAsmOperand &operand)
870 : {
871 17 : auto out_value = operand.get_out ();
872 17 : struct HIR::InlineAsmOperand::Out out (out_value.reg, out_value.late,
873 17 : std::unique_ptr<Expr> (
874 : ASTLoweringExpr::translate (
875 17 : *out_value.expr.get ())));
876 17 : return out;
877 17 : }
878 :
879 : HIR::InlineAsmOperand
880 0 : translate_operand_inout (const AST::InlineAsmOperand &operand)
881 : {
882 0 : auto inout_value = operand.get_in_out ();
883 0 : struct HIR::InlineAsmOperand::InOut inout (inout_value.reg, inout_value.late,
884 0 : std::unique_ptr<Expr> (
885 : ASTLoweringExpr::translate (
886 0 : *inout_value.expr.get ())));
887 0 : return inout;
888 0 : }
889 :
890 : HIR::InlineAsmOperand
891 2 : translate_operand_split_in_out (const AST::InlineAsmOperand &operand)
892 : {
893 2 : auto split_in_out_value = operand.get_split_in_out ();
894 2 : struct HIR::InlineAsmOperand::SplitInOut split_in_out (
895 2 : split_in_out_value.reg, split_in_out_value.late,
896 2 : std::unique_ptr<Expr> (
897 2 : ASTLoweringExpr::translate (*split_in_out_value.in_expr.get ())),
898 2 : std::unique_ptr<Expr> (
899 2 : ASTLoweringExpr::translate (*split_in_out_value.out_expr.get ())));
900 2 : return split_in_out;
901 2 : }
902 :
903 : HIR::InlineAsmOperand
904 0 : translate_operand_const (const AST::InlineAsmOperand &operand)
905 : {
906 0 : auto const_value = operand.get_const ();
907 :
908 0 : auto inner_expr = ASTLoweringExpr::translate (const_value.anon_const);
909 :
910 : // Like `ConstBlock`, we know this should only be an `AnonConst` - let's
911 : // assert to make sure and static cast
912 0 : rust_assert (inner_expr->get_expression_type () == Expr::ExprType::AnonConst);
913 :
914 0 : auto anon_const = static_cast<AnonConst *> (inner_expr);
915 :
916 0 : return HIR::InlineAsmOperand::Const{*anon_const};
917 0 : }
918 :
919 : HIR::InlineAsmOperand
920 0 : translate_operand_sym (const AST::InlineAsmOperand &operand)
921 : {
922 0 : auto sym_value = operand.get_sym ();
923 0 : struct HIR::InlineAsmOperand::Sym sym (std::unique_ptr<Expr> (
924 0 : ASTLoweringExpr::translate (*sym_value.expr.get ())));
925 0 : return sym;
926 0 : }
927 : HIR::InlineAsmOperand
928 0 : translate_operand_label (const AST::InlineAsmOperand &operand)
929 : {
930 0 : auto label_value = operand.get_label ();
931 0 : struct HIR::InlineAsmOperand::Label label (label_value.label_name,
932 0 : std::unique_ptr<Expr> (
933 : ASTLoweringExpr::translate (
934 0 : *label_value.expr.get ())));
935 0 : return label;
936 0 : }
937 : HIR::InlineAsmOperand
938 29 : from_operand (const AST::InlineAsmOperand &operand)
939 : {
940 29 : using RegisterType = AST::InlineAsmOperand::RegisterType;
941 29 : auto type = operand.get_register_type ();
942 :
943 : /*In,*/
944 : /*Out,*/
945 : /*InOut,*/
946 : /*SplitInOut,*/
947 : /*Const,*/
948 : /*Sym,*/
949 : /*Label,*/
950 29 : switch (type)
951 : {
952 10 : case RegisterType::In:
953 10 : return translate_operand_in (operand);
954 17 : case RegisterType::Out:
955 17 : return translate_operand_out (operand);
956 0 : case RegisterType::InOut:
957 0 : return translate_operand_inout (operand);
958 2 : case RegisterType::SplitInOut:
959 2 : return translate_operand_split_in_out (operand);
960 0 : case RegisterType::Const:
961 0 : return translate_operand_const (operand);
962 0 : case RegisterType::Sym:
963 0 : return translate_operand_sym (operand);
964 0 : case RegisterType::Label:
965 0 : return translate_operand_label (operand);
966 0 : default:
967 0 : rust_unreachable ();
968 : }
969 : }
970 : void
971 27 : ASTLoweringExpr::visit (AST::InlineAsm &expr)
972 : {
973 27 : auto crate_num = mappings.get_current_crate ();
974 54 : Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
975 27 : mappings.get_next_hir_id (crate_num),
976 27 : mappings.get_next_localdef_id (crate_num));
977 :
978 27 : std::vector<HIR::InlineAsmOperand> hir_operands;
979 27 : const std::vector<AST::InlineAsmOperand> &ast_operands = expr.get_operands ();
980 : /*int ast_operands_size = ast_operands.size ();*/
981 56 : for (auto &operand : ast_operands)
982 : {
983 29 : hir_operands.push_back (from_operand (operand));
984 : }
985 : /*int hir_operands_size = hir_operands.size ();*/
986 :
987 : /*rust_debug ("{bdbt} : There are %d ast operands prelowering and %d hir "*/
988 : /* "operands after lowering\n",*/
989 : /* ast_operands_size, hir_operands_size);*/
990 27 : translated
991 54 : = new HIR::InlineAsm (expr.get_locus (), expr.is_global_asm,
992 54 : expr.get_template_ (), expr.get_template_strs (),
993 27 : hir_operands, expr.get_clobber_abi (),
994 108 : expr.get_options (), mapping);
995 27 : }
996 :
997 : namespace {
998 : // We're not really supporting llvm_asm, only the bare minimum for libcore's
999 : // blackbox
1000 : // llvm_asm!("" : : "r"(&mut dummy) : "memory" : "volatile");
1001 : bool
1002 2 : check_llvm_asm_support (const std::vector<LlvmOperand> &inputs,
1003 : const std::vector<LlvmOperand> &outputs,
1004 : const AST::LlvmInlineAsm &expr)
1005 : {
1006 4 : return outputs.size () == 0 && inputs.size () <= 1
1007 2 : && expr.get_clobbers ().size () <= 1
1008 2 : && expr.get_templates ().size () == 1
1009 4 : && expr.get_templates ()[0].symbol == "";
1010 : }
1011 :
1012 : } // namespace
1013 :
1014 : void
1015 2 : ASTLoweringExpr::visit (AST::LlvmInlineAsm &expr)
1016 : {
1017 2 : auto crate_num = mappings.get_current_crate ();
1018 4 : Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
1019 2 : mappings.get_next_hir_id (crate_num),
1020 2 : mappings.get_next_localdef_id (crate_num));
1021 :
1022 2 : std::vector<LlvmOperand> inputs;
1023 2 : inputs.reserve (expr.get_inputs ().size ());
1024 :
1025 2 : std::vector<LlvmOperand> outputs;
1026 2 : outputs.reserve (expr.get_outputs ().size ());
1027 :
1028 4 : for (auto i : expr.get_inputs ())
1029 : {
1030 2 : std::unique_ptr<Expr> inner_expr
1031 2 : = std::unique_ptr<Expr> (translate (*i.expr.get ()));
1032 2 : inputs.emplace_back (i.constraint, std::move (inner_expr));
1033 4 : }
1034 :
1035 2 : for (auto o : expr.get_outputs ())
1036 : {
1037 0 : std::unique_ptr<Expr> inner_expr
1038 0 : = std::unique_ptr<Expr> (translate (*o.expr.get ()));
1039 0 : outputs.emplace_back (o.constraint, std::move (inner_expr));
1040 0 : }
1041 :
1042 2 : HIR::LlvmInlineAsm::Options options{expr.is_volatile (),
1043 2 : expr.is_stack_aligned (),
1044 2 : expr.get_dialect ()};
1045 :
1046 2 : if (!check_llvm_asm_support (inputs, outputs, expr))
1047 : {
1048 0 : rust_error_at (expr.get_locus (), "unsupported %qs construct",
1049 : "llvm_asm");
1050 0 : rust_inform (
1051 0 : expr.get_locus (),
1052 : "%<llvm_asm%> has been replaced with %<asm%>, gccrs only supports a "
1053 : "subset of %<llvm_asm%> to compile libcore");
1054 : }
1055 :
1056 2 : translated
1057 4 : = new HIR::LlvmInlineAsm (expr.get_locus (), inputs, outputs,
1058 2 : expr.get_templates (), expr.get_clobbers (),
1059 2 : options, expr.get_outer_attrs (), mapping);
1060 2 : }
1061 :
1062 : void
1063 0 : ASTLoweringExpr::visit (AST::FormatArgs &fmt)
1064 : {
1065 0 : rust_sorry_at (fmt.get_locus (),
1066 : "FormatArgs lowering is not implemented yet");
1067 0 : }
1068 :
1069 : void
1070 15 : ASTLoweringExpr::visit (AST::OffsetOf &offset_of)
1071 : {
1072 15 : auto type = std::unique_ptr<Type> (
1073 15 : ASTLoweringType::translate (offset_of.get_type ()));
1074 :
1075 15 : auto crate_num = mappings.get_current_crate ();
1076 30 : Analysis::NodeMapping mapping (crate_num, offset_of.get_node_id (),
1077 15 : mappings.get_next_hir_id (crate_num),
1078 15 : mappings.get_next_localdef_id (crate_num));
1079 :
1080 15 : translated = new HIR::OffsetOf (std::move (type), offset_of.get_field (),
1081 15 : mapping, offset_of.get_locus ());
1082 15 : }
1083 :
1084 : } // namespace HIR
1085 : } // namespace Rust
|