Skip to content

Commit 50b2228

Browse files
committed
Format: Pretty if-else ladder
1 parent ba76069 commit 50b2228

File tree

1 file changed

+17
-40
lines changed

1 file changed

+17
-40
lines changed

src/lpython/semantics/python_ast_to_asr.cpp

Lines changed: 17 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3404,7 +3404,6 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
34043404
ASR::expr_t *value = nullptr;
34053405

34063406
if (x.m_op == AST::unaryopType::Invert) {
3407-
34083407
if (ASRUtils::is_integer(*operand_type)) {
34093408
if (ASRUtils::expr_value(operand) != nullptr) {
34103409
int64_t op_value = ASR::down_cast<ASR::IntegerConstant_t>(
@@ -3414,8 +3413,7 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
34143413
}
34153414
tmp = ASR::make_IntegerBitNot_t(al, x.base.base.loc, operand, dest_type, value);
34163415
return;
3417-
}
3418-
else if (ASRUtils::is_unsigned_integer(*operand_type)) {
3416+
} else if (ASRUtils::is_unsigned_integer(*operand_type)) {
34193417
if (ASRUtils::expr_value(operand) != nullptr) {
34203418
int64_t op_value = ASR::down_cast<ASR::UnsignedIntegerConstant_t>(
34213419
ASRUtils::expr_value(operand))->m_n;
@@ -3425,12 +3423,10 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
34253423
}
34263424
tmp = ASR::make_UnsignedIntegerBitNot_t(al, x.base.base.loc, operand, dest_type, value);
34273425
return;
3428-
}
3429-
else if (ASRUtils::is_real(*operand_type)) {
3426+
} else if (ASRUtils::is_real(*operand_type)) {
34303427
throw SemanticError("Unary operator '~' not supported for floats",
34313428
x.base.base.loc);
3432-
}
3433-
else if (ASRUtils::is_logical(*operand_type)) {
3429+
} else if (ASRUtils::is_logical(*operand_type)) {
34343430
if (ASRUtils::expr_value(operand) != nullptr) {
34353431
bool op_value = ASR::down_cast<ASR::LogicalConstant_t>(
34363432
ASRUtils::expr_value(operand))->m_value;
@@ -3444,15 +3440,11 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
34443440
int_type, value));
34453441
tmp = ASR::make_IntegerBitNot_t(al, x.base.base.loc, int_arg, int_type, value);
34463442
return;
3447-
}
3448-
else if (ASRUtils::is_complex(*operand_type)) {
3443+
} else if (ASRUtils::is_complex(*operand_type)) {
34493444
throw SemanticError("Unary operator '~' not supported for complex type",
34503445
x.base.base.loc);
34513446
}
3452-
3453-
}
3454-
else if (x.m_op == AST::unaryopType::Not) {
3455-
3447+
} else if (x.m_op == AST::unaryopType::Not) {
34563448
ASR::expr_t *logical_arg = operand;
34573449
if (ASRUtils::is_integer(*operand_type)) {
34583450
if (ASRUtils::expr_value(operand) != nullptr) {
@@ -3466,8 +3458,7 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
34663458
logical_arg = ASR::down_cast<ASR::expr_t>(ASR::make_Cast_t(
34673459
al, x.base.base.loc, operand, ASR::cast_kindType::IntegerToLogical,
34683460
logical_type, value));
3469-
}
3470-
else if (ASRUtils::is_real(*operand_type)) {
3461+
} else if (ASRUtils::is_real(*operand_type)) {
34713462
if (ASRUtils::expr_value(operand) != nullptr) {
34723463
double op_value = ASR::down_cast<ASR::RealConstant_t>(
34733464
ASRUtils::expr_value(operand))->m_r;
@@ -3479,16 +3470,14 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
34793470
logical_arg = ASR::down_cast<ASR::expr_t>(ASR::make_Cast_t(
34803471
al, x.base.base.loc, operand, ASR::cast_kindType::RealToLogical,
34813472
logical_type, value));
3482-
}
3483-
else if (ASRUtils::is_logical(*operand_type)) {
3473+
} else if (ASRUtils::is_logical(*operand_type)) {
34843474
if (ASRUtils::expr_value(operand) != nullptr) {
34853475
bool op_value = ASR::down_cast<ASR::LogicalConstant_t>(
34863476
ASRUtils::expr_value(operand))->m_value;
34873477
value = ASR::down_cast<ASR::expr_t>(ASR::make_LogicalConstant_t(
34883478
al, x.base.base.loc, !op_value, logical_type));
34893479
}
3490-
}
3491-
else if (ASRUtils::is_complex(*operand_type)) {
3480+
} else if (ASRUtils::is_complex(*operand_type)) {
34923481
if (ASRUtils::expr_value(operand) != nullptr) {
34933482
if( ASR::is_a<ASR::FunctionCall_t>(*operand) ) {
34943483
ASR::FunctionCall_t* operand_func_call = ASR::down_cast<ASR::FunctionCall_t>(operand);
@@ -3509,25 +3498,20 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
35093498

35103499
tmp = ASR::make_LogicalNot_t(al, x.base.base.loc, logical_arg, logical_type, value);
35113500
return;
3512-
3513-
}
3514-
else if (x.m_op == AST::unaryopType::UAdd) {
3515-
3501+
} else if (x.m_op == AST::unaryopType::UAdd) {
35163502
if (ASRUtils::is_integer(*operand_type)) {
35173503
if (ASRUtils::expr_value(operand) != nullptr) {
35183504
int64_t op_value = ASR::down_cast<ASR::IntegerConstant_t>(
35193505
ASRUtils::expr_value(operand))->m_n;
35203506
tmp = ASR::make_IntegerConstant_t(al, x.base.base.loc, op_value, operand_type);
35213507
}
3522-
}
3523-
else if (ASRUtils::is_real(*operand_type)) {
3508+
} else if (ASRUtils::is_real(*operand_type)) {
35243509
if (ASRUtils::expr_value(operand) != nullptr) {
35253510
double op_value = ASR::down_cast<ASR::RealConstant_t>(
35263511
ASRUtils::expr_value(operand))->m_r;
35273512
tmp = ASR::make_RealConstant_t(al, x.base.base.loc, op_value, operand_type);
35283513
}
3529-
}
3530-
else if (ASRUtils::is_logical(*operand_type)) {
3514+
} else if (ASRUtils::is_logical(*operand_type)) {
35313515
if (ASRUtils::expr_value(operand) != nullptr) {
35323516
bool op_value = ASR::down_cast<ASR::LogicalConstant_t>(
35333517
ASRUtils::expr_value(operand))->m_value;
@@ -3536,8 +3520,7 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
35363520
}
35373521
tmp = ASR::make_Cast_t(al, x.base.base.loc, operand, ASR::cast_kindType::LogicalToInteger,
35383522
int_type, value);
3539-
}
3540-
else if (ASRUtils::is_complex(*operand_type)) {
3523+
} else if (ASRUtils::is_complex(*operand_type)) {
35413524
if (ASRUtils::expr_value(operand) != nullptr) {
35423525
if( ASR::is_a<ASR::FunctionCall_t>(*operand) ) {
35433526
ASR::FunctionCall_t* operand_func_call = ASR::down_cast<ASR::FunctionCall_t>(operand);
@@ -3551,10 +3534,7 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
35513534
}
35523535
}
35533536
return;
3554-
3555-
}
3556-
else if (x.m_op == AST::unaryopType::USub) {
3557-
3537+
} else if (x.m_op == AST::unaryopType::USub) {
35583538
if (ASRUtils::is_integer(*operand_type)) {
35593539
if (ASRUtils::expr_value(operand) != nullptr) {
35603540
int64_t op_value = ASR::down_cast<ASR::IntegerConstant_t>(
@@ -3565,8 +3545,7 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
35653545
tmp = ASR::make_IntegerUnaryMinus_t(al, x.base.base.loc, operand,
35663546
operand_type, value);
35673547
return;
3568-
}
3569-
else if (ASRUtils::is_real(*operand_type)) {
3548+
} else if (ASRUtils::is_real(*operand_type)) {
35703549
if (ASRUtils::expr_value(operand) != nullptr) {
35713550
double op_value = ASR::down_cast<ASR::RealConstant_t>(
35723551
ASRUtils::expr_value(operand))->m_r;
@@ -3576,8 +3555,7 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
35763555
tmp = ASR::make_RealUnaryMinus_t(al, x.base.base.loc, operand,
35773556
operand_type, value);
35783557
return;
3579-
}
3580-
else if (ASRUtils::is_logical(*operand_type)) {
3558+
} else if (ASRUtils::is_logical(*operand_type)) {
35813559
if (ASRUtils::expr_value(operand) != nullptr) {
35823560
bool op_value = ASR::down_cast<ASR::LogicalConstant_t>(
35833561
ASRUtils::expr_value(operand))->m_value;
@@ -3591,8 +3569,7 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
35913569
tmp = ASR::make_IntegerUnaryMinus_t(al, x.base.base.loc, int_arg,
35923570
int_type, value);
35933571
return;
3594-
}
3595-
else if (ASRUtils::is_complex(*operand_type)) {
3572+
} else if (ASRUtils::is_complex(*operand_type)) {
35963573
if (ASRUtils::expr_value(operand) != nullptr) {
35973574
ASR::ComplexConstant_t *c = ASR::down_cast<ASR::ComplexConstant_t>(
35983575
ASRUtils::expr_value(operand));
@@ -4765,7 +4742,7 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
47654742
if (t == nullptr) {
47664743
// Throw Not implemented error.
47674744
throw SemanticError("Internal FunctionDef: Not implemented", x.base.base.loc);
4768-
}
4745+
}
47694746

47704747
if (ASR::is_a<ASR::Function_t>(*t)) {
47714748
ASR::Function_t *f = ASR::down_cast<ASR::Function_t>(t);

0 commit comments

Comments
 (0)