@@ -130,8 +130,6 @@ PycRef<ASTNode> BuildFromCode(PycRef<PycCode> code, PycModule* mod)
130130 && opcode != Pyc::POP_JUMP_IF_TRUE_A
131131 && opcode != Pyc::POP_JUMP_FORWARD_IF_TRUE_A
132132 && opcode != Pyc::POP_BLOCK) {
133- else_pop = false ;
134-
135133 PycRef<ASTBlock> prev = curblock;
136134 while (prev->end () < pos
137135 && prev->blktype () != ASTBlock::BLK_MAIN) {
@@ -2480,7 +2478,6 @@ PycRef<ASTNode> BuildFromCode(PycRef<PycCode> code, PycModule* mod)
24802478 case Pyc::RESUME_A:
24812479 case Pyc::INSTRUMENTED_RESUME_A:
24822480 /* We just entirely ignore this / no-op */
2483- break ;
24842481 case Pyc::CACHE:
24852482 /* These "fake" opcodes are used as placeholders for optimizing
24862483 certain opcodes in Python 3.11+. Since we have no need for
@@ -2645,11 +2642,10 @@ static int cmp_prec(PycRef<ASTNode> parent, PycRef<ASTNode> child)
26452642 if (parent.type () == ASTNode::NODE_BINARY) {
26462643 PycRef<ASTBinary> binParent = parent.cast <ASTBinary>();
26472644 if (binParent->right () == child) {
2648- if (binParent->op () == ASTBinary::BIN_SUBTRACT &&
2649- binChild->op () == ASTBinary::BIN_ADD)
2650- return 1 ;
2651- else if (binParent->op () == ASTBinary::BIN_DIVIDE &&
2652- binChild->op () == ASTBinary::BIN_MULTIPLY)
2645+ if ((binParent->op () == ASTBinary::BIN_SUBTRACT &&
2646+ binChild->op () == ASTBinary::BIN_ADD) ||
2647+ (binParent->op () == ASTBinary::BIN_DIVIDE &&
2648+ binChild->op () == ASTBinary::BIN_MULTIPLY))
26532649 return 1 ;
26542650 }
26552651 return binChild->op () - binParent->op ();
@@ -2663,6 +2659,9 @@ static int cmp_prec(PycRef<ASTNode> parent, PycRef<ASTNode> child)
26632659 PycRef<ASTUnary> unChild = child.cast <ASTUnary>();
26642660 if (parent.type () == ASTNode::NODE_BINARY) {
26652661 PycRef<ASTBinary> binParent = parent.cast <ASTBinary>();
2662+
2663+ // NOLINTBEGIN(bugprone-branch-clone)f
2664+ // Not sure if reordering the branches could lead to some bugs
26662665 if (binParent->op () == ASTBinary::BIN_LOG_AND ||
26672666 binParent->op () == ASTBinary::BIN_LOG_OR)
26682667 return -1 ;
@@ -2672,6 +2671,7 @@ static int cmp_prec(PycRef<ASTNode> parent, PycRef<ASTNode> child)
26722671 return 1 ;
26732672 else
26742673 return -1 ;
2674+ // NOLINTEND(bugprone-branch-clone)
26752675 } else if (parent.type () == ASTNode::NODE_COMPARE) {
26762676 return (unChild->op () == ASTUnary::UN_NOT) ? 1 : -1 ;
26772677 } else if (parent.type () == ASTNode::NODE_UNARY) {
@@ -2696,23 +2696,18 @@ static void print_ordered(PycRef<ASTNode> parent, PycRef<ASTNode> child,
26962696 PycModule* mod, std::ostream& pyc_output)
26972697{
26982698 if (child.type () == ASTNode::NODE_BINARY ||
2699- child.type () == ASTNode::NODE_COMPARE) {
2699+ child.type () == ASTNode::NODE_COMPARE ||
2700+ child.type () == ASTNode::NODE_UNARY) {
27002701 if (cmp_prec (parent, child) > 0 ) {
27012702 pyc_output << " (" ;
27022703 print_src (child, mod, pyc_output);
27032704 pyc_output << " )" ;
2704- } else {
2705- print_src (child, mod, pyc_output);
27062705 }
2707- } else if (child.type () == ASTNode::NODE_UNARY) {
2708- if (cmp_prec (parent, child) > 0 ) {
2709- pyc_output << " (" ;
2710- print_src (child, mod, pyc_output);
2711- pyc_output << " )" ;
2712- } else {
2706+ else {
27132707 print_src (child, mod, pyc_output);
27142708 }
2715- } else {
2709+ }
2710+ else {
27162711 print_src (child, mod, pyc_output);
27172712 }
27182713}
@@ -2773,6 +2768,9 @@ void print_formatted_value(PycRef<ASTFormattedValue> formatted_value, PycModule*
27732768 case ASTFormattedValue::ASCII:
27742769 pyc_output << " !a" ;
27752770 break ;
2771+ default :
2772+ // error case
2773+ break ;
27762774 }
27772775 if (formatted_value->conversion () & ASTFormattedValue::HAVE_FMT_SPEC) {
27782776 pyc_output << " :" << formatted_value->format_spec ().cast <ASTObject>()->object ().cast <PycString>()->value ();
@@ -2849,7 +2847,6 @@ void print_src(PycRef<ASTNode> node, PycModule* mod, std::ostream& pyc_output)
28492847 pyc_output << " , " ;
28502848 pyc_output << " **" ;
28512849 print_src (call->kw (), mod, pyc_output);
2852- first = false ;
28532850 }
28542851 pyc_output << " )" ;
28552852 }
0 commit comments