blob: 2b39074097387335f3675271048b2f3783a7c7f0 [file] [log] [blame]
Guido van Rossumf70e43a1991-02-19 12:39:46 +00001
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002/* Parse tree node interface */
3
Fred Drake5eb6d4e2000-07-08 23:37:28 +00004#ifndef Py_NODE_H
5#define Py_NODE_H
6#ifdef __cplusplus
7extern "C" {
8#endif
9
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000010typedef struct _node {
Serhiy Storchaka598ceae2017-11-28 17:56:10 +020011 short n_type;
12 char *n_str;
13 int n_lineno;
14 int n_col_offset;
15 int n_nchildren;
16 struct _node *n_child;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +000017 int n_end_lineno;
18 int n_end_col_offset;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000019} node;
20
Mark Hammond91a681d2002-08-12 07:21:58 +000021PyAPI_FUNC(node *) PyNode_New(int type);
22PyAPI_FUNC(int) PyNode_AddChild(node *n, int type,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +000023 char *str, int lineno, int col_offset,
24 int end_lineno, int end_col_offset);
Mark Hammond91a681d2002-08-12 07:21:58 +000025PyAPI_FUNC(void) PyNode_Free(node *n);
Jesus Ceae9c53182012-08-03 14:28:37 +020026#ifndef Py_LIMITED_API
Serhiy Storchaka60fe5692014-11-18 17:30:15 +020027PyAPI_FUNC(Py_ssize_t) _PyNode_SizeOf(node *n);
Jesus Ceae9c53182012-08-03 14:28:37 +020028#endif
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000029
30/* Node access functions */
Serhiy Storchaka598ceae2017-11-28 17:56:10 +020031#define NCH(n) ((n)->n_nchildren)
Serhiy Storchakaf4027752015-03-21 09:25:53 +020032
Serhiy Storchaka598ceae2017-11-28 17:56:10 +020033#define CHILD(n, i) (&(n)->n_child[i])
34#define RCHILD(n, i) (CHILD(n, NCH(n) + i))
35#define TYPE(n) ((n)->n_type)
36#define STR(n) ((n)->n_str)
Benjamin Petersonc0beabc2012-01-16 17:29:05 -050037#define LINENO(n) ((n)->n_lineno)
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000038
39/* Assert that the type of a node is what we expect */
Guido van Rossum5aace072001-10-15 17:23:13 +000040#define REQ(n, type) assert(TYPE(n) == (type))
Guido van Rossum3f5da241990-12-20 15:06:42 +000041
Mark Hammond91a681d2002-08-12 07:21:58 +000042PyAPI_FUNC(void) PyNode_ListTree(node *);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +000043void _PyNode_FinalizeEndPos(node *n); // helper also used in parsetok.c
Guido van Rossuma3309961993-07-28 09:05:47 +000044
45#ifdef __cplusplus
46}
47#endif
48#endif /* !Py_NODE_H */