GitHub

@@ -2,6 +2,7 @@

22

/* List a node on a file */

3344

#include "Python.h"

5+

#include "pycore_pystate.h"

56

#include "token.h"

67

#include "node.h"

78

@@ -15,19 +16,21 @@ PyNode_ListTree(node *n)

1516

listnode(stdout, n);

1617

}

171818-

static int level, atbol;

19-2019

static void

2120

listnode(FILE *fp, node *n)

2221

{

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;

2526

list1node(fp, n);

2627

}

27282829

static void

2930

list1node(FILE *fp, node *n)

3031

{

32+

PyInterpreterState *interp;

33+3134

if (n == NULL)

3235

return;

3336

if (ISNONTERMINAL(TYPE(n))) {

@@ -36,25 +39,26 @@ list1node(FILE *fp, node *n)

3639

list1node(fp, CHILD(n, i));

3740

}

3841

else if (ISTERMINAL(TYPE(n))) {

42+

interp = _PyInterpreterState_GET_UNSAFE();

3943

switch (TYPE(n)) {

4044

case INDENT:

41-

++level;

45+

interp->parser.listnode.level++;

4246

break;

4347

case DEDENT:

44-

--level;

48+

interp->parser.listnode.level--;

4549

break;

4650

default:

47-

if (atbol) {

51+

if (interp->parser.listnode.atbol) {

4852

int i;

49-

for (i = 0; i < level; ++i)

53+

for (i = 0; i < interp->parser.listnode.level; ++i)

5054

fprintf(fp, "\t");

51-

atbol = 0;

55+

interp->parser.listnode.atbol = 0;

5256

}

5357

if (TYPE(n) == NEWLINE) {

5458

if (STR(n) != NULL)

5559

fprintf(fp, "%s", STR(n));

5660

fprintf(fp, "\n");

57-

atbol = 1;

61+

interp->parser.listnode.atbol = 1;

5862

}

5963

else

6064

fprintf(fp, "%s ", STR(n));

Read the original on github.com ↗