@@ -1345,6 +1345,21 @@ class ClangASTtoASRVisitor: public clang::RecursiveASTVisitor<ClangASTtoASRVisit
1345
1345
}
1346
1346
}
1347
1347
1348
+ void CreateLogicalOp (ASR::expr_t * lhs, ASR::expr_t * rhs,
1349
+ ASR::logicalbinopType binop_type, const Location& loc) {
1350
+ cast_helper (lhs, rhs, false );
1351
+ ASRUtils::make_ArrayBroadcast_t_util (al, loc, lhs, rhs);
1352
+ if ( ASRUtils::is_integer (*ASRUtils::expr_type (lhs)) &&
1353
+ ASRUtils::is_integer (*ASRUtils::expr_type (rhs)) ) {
1354
+ tmp = ASR::make_LogicalBinOp_t (al, loc, lhs,
1355
+ binop_type, rhs, ASRUtils::expr_type (lhs), nullptr );
1356
+ } else {
1357
+ throw std::runtime_error (" Only integer types are supported so "
1358
+ " far for logical binary operator, found: " + ASRUtils::type_to_str (ASRUtils::expr_type (lhs))
1359
+ + " and " + ASRUtils::type_to_str (ASRUtils::expr_type (rhs)));
1360
+ }
1361
+ }
1362
+
1348
1363
void CreateBinOp (ASR::expr_t * lhs, ASR::expr_t * rhs,
1349
1364
ASR::binopType binop_type, const Location& loc) {
1350
1365
cast_helper (lhs, rhs, false );
@@ -1368,6 +1383,17 @@ class ClangASTtoASRVisitor: public clang::RecursiveASTVisitor<ClangASTtoASRVisit
1368
1383
}
1369
1384
}
1370
1385
1386
+ void CreateLogicalNot (ASR::expr_t * op, const Location& loc) {
1387
+ if ( ASRUtils::is_logical (*ASRUtils::expr_type (op)) ) {
1388
+ tmp = ASR::make_LogicalNot_t (al, loc, op,
1389
+ ASRUtils::expr_type (op), nullptr );
1390
+ } else {
1391
+ throw std::runtime_error (" Only logical types are supported so "
1392
+ " far for logical not operator, found: " +
1393
+ ASRUtils::type_to_str (ASRUtils::expr_type (op)));
1394
+ }
1395
+ }
1396
+
1371
1397
void CreateUnaryMinus (ASR::expr_t * op, const Location& loc) {
1372
1398
if ( ASRUtils::is_integer (*ASRUtils::expr_type (op)) ) {
1373
1399
tmp = ASR::make_IntegerUnaryMinus_t (al, loc, op,
@@ -1393,8 +1419,10 @@ class ClangASTtoASRVisitor: public clang::RecursiveASTVisitor<ClangASTtoASRVisit
1393
1419
is_stmt_created = true ;
1394
1420
} else {
1395
1421
bool is_binop = false , is_cmpop = false ;
1422
+ bool is_logicalbinop = false ;
1396
1423
ASR::binopType binop_type;
1397
1424
ASR::cmpopType cmpop_type;
1425
+ ASR::logicalbinopType logicalbinop_type;
1398
1426
switch (op) {
1399
1427
case clang::BO_Add: {
1400
1428
binop_type = ASR::binopType::Add;
@@ -1446,6 +1474,11 @@ class ClangASTtoASRVisitor: public clang::RecursiveASTVisitor<ClangASTtoASRVisit
1446
1474
is_cmpop = true ;
1447
1475
break ;
1448
1476
}
1477
+ case clang::BO_LAnd: {
1478
+ logicalbinop_type = ASR::logicalbinopType::And;
1479
+ is_logicalbinop = true ;
1480
+ break ;
1481
+ }
1449
1482
default : {
1450
1483
throw std::runtime_error (" BinaryOperator not supported " + std::to_string (op));
1451
1484
break ;
@@ -1455,6 +1488,8 @@ class ClangASTtoASRVisitor: public clang::RecursiveASTVisitor<ClangASTtoASRVisit
1455
1488
CreateBinOp (x_lhs, x_rhs, binop_type, Lloc (x));
1456
1489
} else if ( is_cmpop ) {
1457
1490
CreateCompareOp (x_lhs, x_rhs, cmpop_type, Lloc (x));
1491
+ } else if ( is_logicalbinop ) {
1492
+ CreateLogicalOp (x_lhs, x_rhs, logicalbinop_type, Lloc (x));
1458
1493
} else {
1459
1494
throw std::runtime_error (" Only binary operators supported so far" );
1460
1495
}
@@ -1604,6 +1639,14 @@ class ClangASTtoASRVisitor: public clang::RecursiveASTVisitor<ClangASTtoASRVisit
1604
1639
return true ;
1605
1640
}
1606
1641
1642
+ bool TraverseCXXBoolLiteralExpr (clang::CXXBoolLiteralExpr* x) {
1643
+ bool b = x->getValue ();
1644
+ tmp = ASR::make_LogicalConstant_t (al, Lloc (x), b,
1645
+ ASRUtils::TYPE (ASR::make_Logical_t (al, Lloc (x), 4 )));
1646
+ is_stmt_created = false ;
1647
+ return true ;
1648
+ }
1649
+
1607
1650
bool TraverseFloatingLiteral (clang::FloatingLiteral* x) {
1608
1651
double d = x->getValue ().convertToDouble ();
1609
1652
tmp = ASR::make_RealConstant_t (al, Lloc (x), d,
@@ -1715,6 +1758,10 @@ class ClangASTtoASRVisitor: public clang::RecursiveASTVisitor<ClangASTtoASRVisit
1715
1758
CreateUnaryMinus (var, Lloc (x));
1716
1759
break ;
1717
1760
}
1761
+ case clang::UnaryOperatorKind::UO_LNot: {
1762
+ CreateLogicalNot (var, Lloc (x));
1763
+ break ;
1764
+ }
1718
1765
default : {
1719
1766
throw std::runtime_error (" Only postfix increment and minus are supported so far." );
1720
1767
}
0 commit comments