43
43
tok->lineno++; \
44
44
tok->col_offset = 0;
45
45
46
+ #ifdef Py_DEBUG
47
+ static inline tokenizer_mode * TOK_GET_MODE (struct tok_state * tok ) {
48
+ assert (tok -> tok_mode_stack_index >= 0 );
49
+ assert (tok -> tok_mode_stack_index < MAXLEVEL );
50
+ return & (tok -> tok_mode_stack [tok -> tok_mode_stack_index ]);
51
+ }
52
+ static inline tokenizer_mode * TOK_NEXT_MODE (struct tok_state * tok ) {
53
+ assert (tok -> tok_mode_stack_index >= 0 );
54
+ assert (tok -> tok_mode_stack_index < MAXLEVEL );
55
+ return & (tok -> tok_mode_stack [++ tok -> tok_mode_stack_index ]);
56
+ }
57
+ static inline int * TOK_GET_BRACKET_MARK (tokenizer_mode * mode ) {
58
+ assert (mode -> bracket_mark_index >= 0 );
59
+ assert (mode -> bracket_mark_index < MAX_EXPR_NEXTING );
60
+ return & (mode -> bracket_mark [mode -> bracket_mark_index ]);
61
+ }
62
+ #else
63
+ #define TOK_GET_MODE (tok ) (&(tok->tok_mode_stack[tok->tok_mode_stack_index]))
64
+ #define TOK_NEXT_MODE (tok ) (&(tok->tok_mode_stack[++tok->tok_mode_stack_index]))
65
+ #define TOK_GET_BRACKET_MARK (mode ) (&(mode->bracket_mark[mode->bracket_mark_index]))
66
+ #endif
67
+
46
68
/* Forward */
47
69
static struct tok_state * tok_new (void );
48
70
static int tok_nextc (struct tok_state * tok );
@@ -373,7 +395,7 @@ update_fstring_expr(struct tok_state *tok, char cur)
373
395
assert (tok -> cur != NULL );
374
396
375
397
Py_ssize_t size = strlen (tok -> cur );
376
- tokenizer_mode * tok_mode = & (tok -> tok_mode_stack [ tok -> tok_mode_stack_index ] );
398
+ tokenizer_mode * tok_mode = TOK_GET_MODE (tok );
377
399
378
400
switch (cur ) {
379
401
case '{' :
@@ -2186,7 +2208,7 @@ tok_get_normal_mode(struct tok_state *tok, tokenizer_mode* current_tok, struct t
2186
2208
2187
2209
p_start = tok -> start ;
2188
2210
p_end = tok -> cur ;
2189
- tokenizer_mode * current_tok = & (tok -> tok_mode_stack [ ++ tok -> tok_mode_stack_index ] );
2211
+ tokenizer_mode * current_tok = TOK_NEXT_MODE (tok );
2190
2212
current_tok -> kind = TOK_FSTRING_MODE ;
2191
2213
current_tok -> f_string_quote = quote ;
2192
2214
current_tok -> f_string_quote_size = quote_size ;
@@ -2266,7 +2288,7 @@ tok_get_normal_mode(struct tok_state *tok, tokenizer_mode* current_tok, struct t
2266
2288
* does the initial quote matches with f-strings quotes
2267
2289
* and if it is, then this must be a missing '}' token
2268
2290
* so raise the proper error */
2269
- tokenizer_mode * current_tok = & (tok -> tok_mode_stack [ tok -> tok_mode_stack_index ] );
2291
+ tokenizer_mode * current_tok = TOK_GET_MODE (tok );
2270
2292
if (current_tok -> f_string_quote == quote &&
2271
2293
current_tok -> f_string_quote_size == quote_size ) {
2272
2294
return MAKE_TOKEN (syntaxerror (tok , "f-string: expecting '}'" , start ));
@@ -2318,7 +2340,7 @@ tok_get_normal_mode(struct tok_state *tok, tokenizer_mode* current_tok, struct t
2318
2340
/* Punctuation character */
2319
2341
int is_punctuation = (c == ':' || c == '}' || c == '!' || c == '{' );
2320
2342
if (is_punctuation && tok -> tok_mode_stack_index > 0 && current_tok -> bracket_mark_index >= 0 ) {
2321
- int mark = current_tok -> bracket_mark [ current_tok -> bracket_mark_index ] ;
2343
+ int mark = * TOK_GET_BRACKET_MARK ( current_tok ) ;
2322
2344
/* This code block gets executed before the bracket_stack is incremented
2323
2345
* by the `{` case, so for ensuring that we are on the 0th level, we need
2324
2346
* to adjust it manually */
@@ -2372,7 +2394,6 @@ tok_get_normal_mode(struct tok_state *tok, tokenizer_mode* current_tok, struct t
2372
2394
if (tok -> tok_mode_stack_index > 0 ) {
2373
2395
current_tok -> bracket_stack ++ ;
2374
2396
}
2375
-
2376
2397
break ;
2377
2398
case ')' :
2378
2399
case ']' :
@@ -2397,7 +2418,7 @@ tok_get_normal_mode(struct tok_state *tok, tokenizer_mode* current_tok, struct t
2397
2418
if (tok -> tok_mode_stack_index > 0 && opening == '{' ) {
2398
2419
assert (current_tok -> bracket_stack >= 0 );
2399
2420
int previous_bracket = current_tok -> bracket_stack - 1 ;
2400
- if (previous_bracket == current_tok -> bracket_mark [ current_tok -> bracket_mark_index ] ) {
2421
+ if (previous_bracket == * TOK_GET_BRACKET_MARK ( current_tok ) ) {
2401
2422
return MAKE_TOKEN (syntaxerror (tok , "f-string: unmatched '%c'" , c ));
2402
2423
}
2403
2424
}
@@ -2417,7 +2438,7 @@ tok_get_normal_mode(struct tok_state *tok, tokenizer_mode* current_tok, struct t
2417
2438
2418
2439
if (tok -> tok_mode_stack_index > 0 ) {
2419
2440
current_tok -> bracket_stack -- ;
2420
- if (c == '}' && current_tok -> bracket_stack == current_tok -> bracket_mark [ current_tok -> bracket_mark_index ] ) {
2441
+ if (c == '}' && current_tok -> bracket_stack == * TOK_GET_BRACKET_MARK ( current_tok ) ) {
2421
2442
current_tok -> bracket_mark_index -- ;
2422
2443
current_tok -> kind = TOK_FSTRING_MODE ;
2423
2444
}
@@ -2461,10 +2482,10 @@ tok_get_fstring_mode(struct tok_state *tok, tokenizer_mode* current_tok, struct
2461
2482
if (current_tok -> bracket_mark_index >= MAX_EXPR_NEXTING ) {
2462
2483
return MAKE_TOKEN (syntaxerror (tok , "f-string: expressions nested too deeply" ));
2463
2484
}
2464
-
2465
- current_tok -> bracket_mark [ ++ current_tok -> bracket_mark_index ] = current_tok -> bracket_stack ;
2485
+ current_tok -> bracket_mark_index ++ ;
2486
+ * TOK_GET_BRACKET_MARK ( current_tok ) = current_tok -> bracket_stack ;
2466
2487
}
2467
- tok -> tok_mode_stack [ tok -> tok_mode_stack_index ]. kind = TOK_REGULAR_MODE ;
2488
+ TOK_GET_MODE ( tok ) -> kind = TOK_REGULAR_MODE ;
2468
2489
return tok_get_normal_mode (tok , current_tok , token );
2469
2490
}
2470
2491
@@ -2529,8 +2550,9 @@ tok_get_fstring_mode(struct tok_state *tok, tokenizer_mode* current_tok, struct
2529
2550
if (peek != '{' || in_format_spec ) {
2530
2551
tok_backup (tok , peek );
2531
2552
tok_backup (tok , c );
2532
- current_tok -> bracket_mark [++ current_tok -> bracket_mark_index ] = current_tok -> bracket_stack ;
2533
- tok -> tok_mode_stack [tok -> tok_mode_stack_index ].kind = TOK_REGULAR_MODE ;
2553
+ current_tok -> bracket_mark_index ++ ;
2554
+ * TOK_GET_BRACKET_MARK (current_tok ) = current_tok -> bracket_stack ;
2555
+ TOK_GET_MODE (tok )-> kind = TOK_REGULAR_MODE ;
2534
2556
p_start = tok -> start ;
2535
2557
p_end = tok -> cur ;
2536
2558
} else {
@@ -2556,7 +2578,7 @@ tok_get_fstring_mode(struct tok_state *tok, tokenizer_mode* current_tok, struct
2556
2578
} else {
2557
2579
tok_backup (tok , peek );
2558
2580
tok_backup (tok , c );
2559
- tok -> tok_mode_stack [ tok -> tok_mode_stack_index ]. kind = TOK_REGULAR_MODE ;
2581
+ TOK_GET_MODE ( tok ) -> kind = TOK_REGULAR_MODE ;
2560
2582
p_start = tok -> start ;
2561
2583
p_end = tok -> cur ;
2562
2584
}
@@ -2606,7 +2628,7 @@ tok_get_fstring_mode(struct tok_state *tok, tokenizer_mode* current_tok, struct
2606
2628
static int
2607
2629
tok_get (struct tok_state * tok , struct token * token )
2608
2630
{
2609
- tokenizer_mode * current_tok = & (tok -> tok_mode_stack [ tok -> tok_mode_stack_index ] );
2631
+ tokenizer_mode * current_tok = TOK_GET_MODE (tok );
2610
2632
if (current_tok -> kind == TOK_REGULAR_MODE ) {
2611
2633
return tok_get_normal_mode (tok , current_tok , token );
2612
2634
} else {
0 commit comments