@@ -790,7 +790,7 @@ CompileExpr::resolve_method_address (TyTy::FnType *fntype, HirId ref,
790
790
791
791
tree
792
792
CompileExpr::resolve_operator_overload (
793
- Analysis::RustLangItem::ItemType lang_item_type, HIR::OperatorExpr & expr,
793
+ Analysis::RustLangItem::ItemType lang_item_type, HIR::OperatorExprMeta expr,
794
794
tree lhs, tree rhs, HIR::Expr *lhs_expr, HIR::Expr *rhs_expr)
795
795
{
796
796
TyTy::FnType *fntype;
@@ -1377,5 +1377,172 @@ CompileExpr::visit (HIR::IdentifierExpr &expr)
1377
1377
}
1378
1378
}
1379
1379
1380
+ void
1381
+ CompileExpr::visit (HIR::RangeFromToExpr &expr)
1382
+ {
1383
+ tree from = CompileExpr::Compile (expr.get_from_expr ().get (), ctx);
1384
+ tree to = CompileExpr::Compile (expr.get_to_expr ().get (), ctx);
1385
+ if (from == error_mark_node || to == error_mark_node)
1386
+ {
1387
+ translated = error_mark_node;
1388
+ return ;
1389
+ }
1390
+
1391
+ TyTy::BaseType *tyty = nullptr ;
1392
+ bool ok
1393
+ = ctx->get_tyctx ()->lookup_type (expr.get_mappings ().get_hirid (), &tyty);
1394
+ rust_assert (ok);
1395
+
1396
+ tree adt = TyTyResolveCompile::compile (ctx, tyty);
1397
+
1398
+ // make the constructor
1399
+ translated
1400
+ = ctx->get_backend ()->constructor_expression (adt, false , {from, to}, -1 ,
1401
+ expr.get_locus ());
1402
+ }
1403
+
1404
+ void
1405
+ CompileExpr::visit (HIR::RangeFromExpr &expr)
1406
+ {
1407
+ tree from = CompileExpr::Compile (expr.get_from_expr ().get (), ctx);
1408
+ if (from == error_mark_node)
1409
+ {
1410
+ translated = error_mark_node;
1411
+ return ;
1412
+ }
1413
+
1414
+ TyTy::BaseType *tyty = nullptr ;
1415
+ bool ok
1416
+ = ctx->get_tyctx ()->lookup_type (expr.get_mappings ().get_hirid (), &tyty);
1417
+ rust_assert (ok);
1418
+
1419
+ tree adt = TyTyResolveCompile::compile (ctx, tyty);
1420
+
1421
+ // make the constructor
1422
+ translated
1423
+ = ctx->get_backend ()->constructor_expression (adt, false , {from}, -1 ,
1424
+ expr.get_locus ());
1425
+ }
1426
+
1427
+ void
1428
+ CompileExpr::visit (HIR::RangeToExpr &expr)
1429
+ {
1430
+ tree to = CompileExpr::Compile (expr.get_to_expr ().get (), ctx);
1431
+ if (to == error_mark_node)
1432
+ {
1433
+ translated = error_mark_node;
1434
+ return ;
1435
+ }
1436
+
1437
+ TyTy::BaseType *tyty = nullptr ;
1438
+ bool ok
1439
+ = ctx->get_tyctx ()->lookup_type (expr.get_mappings ().get_hirid (), &tyty);
1440
+ rust_assert (ok);
1441
+
1442
+ tree adt = TyTyResolveCompile::compile (ctx, tyty);
1443
+
1444
+ // make the constructor
1445
+ translated
1446
+ = ctx->get_backend ()->constructor_expression (adt, false , {to}, -1 ,
1447
+ expr.get_locus ());
1448
+ }
1449
+
1450
+ void
1451
+ CompileExpr::visit (HIR::RangeFullExpr &expr)
1452
+ {
1453
+ TyTy::BaseType *tyty = nullptr ;
1454
+ bool ok
1455
+ = ctx->get_tyctx ()->lookup_type (expr.get_mappings ().get_hirid (), &tyty);
1456
+ rust_assert (ok);
1457
+
1458
+ tree adt = TyTyResolveCompile::compile (ctx, tyty);
1459
+ translated = ctx->get_backend ()->constructor_expression (adt, false , {}, -1 ,
1460
+ expr.get_locus ());
1461
+ }
1462
+
1463
+ void
1464
+ CompileExpr::visit (HIR::RangeFromToInclExpr &expr)
1465
+ {
1466
+ tree from = CompileExpr::Compile (expr.get_from_expr ().get (), ctx);
1467
+ tree to = CompileExpr::Compile (expr.get_to_expr ().get (), ctx);
1468
+ if (from == error_mark_node || to == error_mark_node)
1469
+ {
1470
+ translated = error_mark_node;
1471
+ return ;
1472
+ }
1473
+
1474
+ TyTy::BaseType *tyty = nullptr ;
1475
+ bool ok
1476
+ = ctx->get_tyctx ()->lookup_type (expr.get_mappings ().get_hirid (), &tyty);
1477
+ rust_assert (ok);
1478
+
1479
+ tree adt = TyTyResolveCompile::compile (ctx, tyty);
1480
+
1481
+ // make the constructor
1482
+ translated
1483
+ = ctx->get_backend ()->constructor_expression (adt, false , {from, to}, -1 ,
1484
+ expr.get_locus ());
1485
+ }
1486
+
1487
+ void
1488
+ CompileExpr::visit (HIR::ArrayIndexExpr &expr)
1489
+ {
1490
+ tree array_reference = CompileExpr::Compile (expr.get_array_expr (), ctx);
1491
+ tree index = CompileExpr::Compile (expr.get_index_expr (), ctx);
1492
+
1493
+ // this might be an core::ops::index lang item situation
1494
+ TyTy::FnType *fntype;
1495
+ bool is_op_overload = ctx->get_tyctx ()->lookup_operator_overload (
1496
+ expr.get_mappings ().get_hirid (), &fntype);
1497
+ if (is_op_overload)
1498
+ {
1499
+ auto lang_item_type = Analysis::RustLangItem::ItemType::INDEX;
1500
+ tree operator_overload_call
1501
+ = resolve_operator_overload (lang_item_type, expr, array_reference,
1502
+ index , expr.get_array_expr (),
1503
+ expr.get_index_expr ());
1504
+
1505
+ // lookup the expected type for this expression
1506
+ TyTy::BaseType *tyty = nullptr ;
1507
+ bool ok
1508
+ = ctx->get_tyctx ()->lookup_type (expr.get_mappings ().get_hirid (),
1509
+ &tyty);
1510
+ rust_assert (ok);
1511
+ tree expected_type = TyTyResolveCompile::compile (ctx, tyty);
1512
+
1513
+ // rust deref always returns a reference from this overload then we can
1514
+ // actually do the indirection
1515
+ translated
1516
+ = ctx->get_backend ()->indirect_expression (expected_type,
1517
+ operator_overload_call,
1518
+ true , expr.get_locus ());
1519
+ return ;
1520
+ }
1521
+
1522
+ // lets check if the array is a reference type then we can add an
1523
+ // indirection if required
1524
+ TyTy::BaseType *array_expr_ty = nullptr ;
1525
+ bool ok = ctx->get_tyctx ()->lookup_type (
1526
+ expr.get_array_expr ()->get_mappings ().get_hirid (), &array_expr_ty);
1527
+ rust_assert (ok);
1528
+
1529
+ // do we need to add an indirect reference
1530
+ if (array_expr_ty->get_kind () == TyTy::TypeKind::REF)
1531
+ {
1532
+ TyTy::ReferenceType *r
1533
+ = static_cast <TyTy::ReferenceType *> (array_expr_ty);
1534
+ TyTy::BaseType *tuple_type = r->get_base ();
1535
+ tree array_tyty = TyTyResolveCompile::compile (ctx, tuple_type);
1536
+
1537
+ array_reference
1538
+ = ctx->get_backend ()->indirect_expression (array_tyty, array_reference,
1539
+ true , expr.get_locus ());
1540
+ }
1541
+
1542
+ translated
1543
+ = ctx->get_backend ()->array_index_expression (array_reference, index ,
1544
+ expr.get_locus ());
1545
+ }
1546
+
1380
1547
} // namespace Compile
1381
1548
} // namespace Rust
0 commit comments