2
2
/* List a node on a file */
3
3
4
4
#include "Python.h"
5
+ #include "pycore_pystate.h"
5
6
#include "token.h"
6
7
#include "node.h"
7
8
@@ -15,19 +16,21 @@ PyNode_ListTree(node *n)
15
16
listnode (stdout , n );
16
17
}
17
18
18
- static int level , atbol ;
19
-
20
19
static void
21
20
listnode (FILE * fp , node * n )
22
21
{
23
- level = 0 ;
24
- atbol = 1 ;
22
+ PyInterpreterState * interp = _PyInterpreterState_GET_UNSAFE ();
23
+
24
+ interp -> parser .listnode .level = 0 ;
25
+ interp -> parser .listnode .atbol = 1 ;
25
26
list1node (fp , n );
26
27
}
27
28
28
29
static void
29
30
list1node (FILE * fp , node * n )
30
31
{
32
+ PyInterpreterState * interp ;
33
+
31
34
if (n == NULL )
32
35
return ;
33
36
if (ISNONTERMINAL (TYPE (n ))) {
@@ -36,25 +39,26 @@ list1node(FILE *fp, node *n)
36
39
list1node (fp , CHILD (n , i ));
37
40
}
38
41
else if (ISTERMINAL (TYPE (n ))) {
42
+ interp = _PyInterpreterState_GET_UNSAFE ();
39
43
switch (TYPE (n )) {
40
44
case INDENT :
41
- ++ level ;
45
+ interp -> parser . listnode . level ++ ;
42
46
break ;
43
47
case DEDENT :
44
- -- level ;
48
+ interp -> parser . listnode . level -- ;
45
49
break ;
46
50
default :
47
- if (atbol ) {
51
+ if (interp -> parser . listnode . atbol ) {
48
52
int i ;
49
- for (i = 0 ; i < level ; ++ i )
53
+ for (i = 0 ; i < interp -> parser . listnode . level ; ++ i )
50
54
fprintf (fp , "\t" );
51
- atbol = 0 ;
55
+ interp -> parser . listnode . atbol = 0 ;
52
56
}
53
57
if (TYPE (n ) == NEWLINE ) {
54
58
if (STR (n ) != NULL )
55
59
fprintf (fp , "%s" , STR (n ));
56
60
fprintf (fp , "\n" );
57
- atbol = 1 ;
61
+ interp -> parser . listnode . atbol = 1 ;
58
62
}
59
63
else
60
64
fprintf (fp , "%s " , STR (n ));
0 commit comments