@@ -207,6 +207,7 @@ static int compiler_next_instr(basicblock *);
207
207
static int compiler_addop (struct compiler * , int );
208
208
static int compiler_addop_i (struct compiler * , int , Py_ssize_t );
209
209
static int compiler_addop_j (struct compiler * , int , basicblock * );
210
+ static int compiler_addop_j_noline (struct compiler * , int , basicblock * );
210
211
static int compiler_error (struct compiler * , const char * );
211
212
static int compiler_warn (struct compiler * , const char * , ...);
212
213
static int compiler_nameop (struct compiler * , identifier , expr_context_ty );
@@ -1425,6 +1426,12 @@ compiler_addop_j(struct compiler *c, int opcode, basicblock *b)
1425
1426
return add_jump_to_block (c -> u -> u_curblock , opcode , c -> u -> u_lineno , b );
1426
1427
}
1427
1428
1429
+ static int
1430
+ compiler_addop_j_noline (struct compiler * c , int opcode , basicblock * b )
1431
+ {
1432
+ return add_jump_to_block (c -> u -> u_curblock , opcode , -1 , b );
1433
+ }
1434
+
1428
1435
/* NEXT_BLOCK() creates an implicit jump from the current block
1429
1436
to the new block.
1430
1437
@@ -1495,6 +1502,14 @@ compiler_addop_j(struct compiler *c, int opcode, basicblock *b)
1495
1502
return 0; \
1496
1503
}
1497
1504
1505
+ /* Add a jump with no line number.
1506
+ * Used for artificial jumps that have no corresponding
1507
+ * token in the source code. */
1508
+ #define ADDOP_JUMP_NOLINE (C , OP , O ) { \
1509
+ if (!compiler_addop_j_noline((C), (OP), (O))) \
1510
+ return 0; \
1511
+ }
1512
+
1498
1513
#define ADDOP_COMPARE (C , CMP ) { \
1499
1514
if (!compiler_addcompare((C), (cmpop_ty)(CMP))) \
1500
1515
return 0; \
@@ -2527,7 +2542,7 @@ compiler_jump_if(struct compiler *c, expr_ty e, basicblock *next, int cond)
2527
2542
return 0 ;
2528
2543
if (!compiler_jump_if (c , e -> v .IfExp .body , next , cond ))
2529
2544
return 0 ;
2530
- ADDOP_JUMP (c , JUMP_FORWARD , end );
2545
+ ADDOP_JUMP_NOLINE (c , JUMP_FORWARD , end );
2531
2546
compiler_use_next_block (c , next2 );
2532
2547
if (!compiler_jump_if (c , e -> v .IfExp .orelse , next , cond ))
2533
2548
return 0 ;
@@ -2560,11 +2575,11 @@ compiler_jump_if(struct compiler *c, expr_ty e, basicblock *next, int cond)
2560
2575
basicblock * end = compiler_new_block (c );
2561
2576
if (end == NULL )
2562
2577
return 0 ;
2563
- ADDOP_JUMP (c , JUMP_FORWARD , end );
2578
+ ADDOP_JUMP_NOLINE (c , JUMP_FORWARD , end );
2564
2579
compiler_use_next_block (c , cleanup );
2565
2580
ADDOP (c , POP_TOP );
2566
2581
if (!cond ) {
2567
- ADDOP_JUMP (c , JUMP_FORWARD , next );
2582
+ ADDOP_JUMP_NOLINE (c , JUMP_FORWARD , next );
2568
2583
}
2569
2584
compiler_use_next_block (c , end );
2570
2585
return 1 ;
@@ -2599,7 +2614,7 @@ compiler_ifexp(struct compiler *c, expr_ty e)
2599
2614
if (!compiler_jump_if (c , e -> v .IfExp .test , next , 0 ))
2600
2615
return 0 ;
2601
2616
VISIT (c , expr , e -> v .IfExp .body );
2602
- ADDOP_JUMP (c , JUMP_FORWARD , end );
2617
+ ADDOP_JUMP_NOLINE (c , JUMP_FORWARD , end );
2603
2618
compiler_use_next_block (c , next );
2604
2619
VISIT (c , expr , e -> v .IfExp .orelse );
2605
2620
compiler_use_next_block (c , end );
@@ -2686,7 +2701,7 @@ compiler_if(struct compiler *c, stmt_ty s)
2686
2701
}
2687
2702
VISIT_SEQ (c , stmt , s -> v .If .body );
2688
2703
if (asdl_seq_LEN (s -> v .If .orelse )) {
2689
- ADDOP_JUMP (c , JUMP_FORWARD , end );
2704
+ ADDOP_JUMP_NOLINE (c , JUMP_FORWARD , end );
2690
2705
compiler_use_next_block (c , next );
2691
2706
VISIT_SEQ (c , stmt , s -> v .If .orelse );
2692
2707
}
@@ -2945,7 +2960,7 @@ compiler_try_finally(struct compiler *c, stmt_ty s)
2945
2960
ADDOP (c , POP_BLOCK );
2946
2961
compiler_pop_fblock (c , FINALLY_TRY , body );
2947
2962
VISIT_SEQ (c , stmt , s -> v .Try .finalbody );
2948
- ADDOP_JUMP (c , JUMP_FORWARD , exit );
2963
+ ADDOP_JUMP_NOLINE (c , JUMP_FORWARD , exit );
2949
2964
/* `finally` block */
2950
2965
compiler_use_next_block (c , end );
2951
2966
if (!compiler_push_fblock (c , FINALLY_END , end , NULL , NULL ))
@@ -3094,6 +3109,8 @@ compiler_try_except(struct compiler *c, stmt_ty s)
3094
3109
return 0 ;
3095
3110
VISIT_SEQ (c , stmt , handler -> v .ExceptHandler .body );
3096
3111
compiler_pop_fblock (c , HANDLER_CLEANUP , cleanup_body );
3112
+ /* name = None; del name; # Mark as artificial */
3113
+ c -> u -> u_lineno = -1 ;
3097
3114
ADDOP (c , POP_EXCEPT );
3098
3115
ADDOP_JUMP (c , JUMP_FORWARD , end );
3099
3116
}
@@ -3907,7 +3924,7 @@ compiler_compare(struct compiler *c, expr_ty e)
3907
3924
basicblock * end = compiler_new_block (c );
3908
3925
if (end == NULL )
3909
3926
return 0 ;
3910
- ADDOP_JUMP (c , JUMP_FORWARD , end );
3927
+ ADDOP_JUMP_NOLINE (c , JUMP_FORWARD , end );
3911
3928
compiler_use_next_block (c , cleanup );
3912
3929
ADDOP (c , ROT_TWO );
3913
3930
ADDOP (c , POP_TOP );
0 commit comments