blob: ca24f289085920e5c87cbb27beed4cf4d7e19b22 [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])
Serhiy Storchaka598ceae2017-11-28 17:56:10 +020034#define TYPE(n) ((n)->n_type)
35#define STR(n) ((n)->n_str)
Benjamin Petersonc0beabc2012-01-16 17:29:05 -050036#define LINENO(n) ((n)->n_lineno)
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000037
38/* Assert that the type of a node is what we expect */
Guido van Rossum5aace072001-10-15 17:23:13 +000039#define REQ(n, type) assert(TYPE(n) == (type))
Guido van Rossum3f5da241990-12-20 15:06:42 +000040
Mark Hammond91a681d2002-08-12 07:21:58 +000041PyAPI_FUNC(void) PyNode_ListTree(node *);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +000042void _PyNode_FinalizeEndPos(node *n); // helper also used in parsetok.c
Guido van Rossuma3309961993-07-28 09:05:47 +000043
44#ifdef __cplusplus
45}
46#endif
47#endif /* !Py_NODE_H */