blob: 40596dfecf1807b21edb10f41f53c004c4877afd [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;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000017} node;
18
Mark Hammond91a681d2002-08-12 07:21:58 +000019PyAPI_FUNC(node *) PyNode_New(int type);
20PyAPI_FUNC(int) PyNode_AddChild(node *n, int type,
Martin v. Löwis49c5da12006-03-01 22:49:05 +000021 char *str, int lineno, int col_offset);
Mark Hammond91a681d2002-08-12 07:21:58 +000022PyAPI_FUNC(void) PyNode_Free(node *n);
Jesus Ceae9c53182012-08-03 14:28:37 +020023#ifndef Py_LIMITED_API
Serhiy Storchaka60fe5692014-11-18 17:30:15 +020024PyAPI_FUNC(Py_ssize_t) _PyNode_SizeOf(node *n);
Jesus Ceae9c53182012-08-03 14:28:37 +020025#endif
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000026
27/* Node access functions */
Serhiy Storchaka598ceae2017-11-28 17:56:10 +020028#define NCH(n) ((n)->n_nchildren)
Serhiy Storchakaf4027752015-03-21 09:25:53 +020029
Serhiy Storchaka598ceae2017-11-28 17:56:10 +020030#define CHILD(n, i) (&(n)->n_child[i])
31#define RCHILD(n, i) (CHILD(n, NCH(n) + i))
32#define TYPE(n) ((n)->n_type)
33#define STR(n) ((n)->n_str)
Benjamin Petersonc0beabc2012-01-16 17:29:05 -050034#define LINENO(n) ((n)->n_lineno)
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000035
36/* Assert that the type of a node is what we expect */
Guido van Rossum5aace072001-10-15 17:23:13 +000037#define REQ(n, type) assert(TYPE(n) == (type))
Guido van Rossum3f5da241990-12-20 15:06:42 +000038
Mark Hammond91a681d2002-08-12 07:21:58 +000039PyAPI_FUNC(void) PyNode_ListTree(node *);
Guido van Rossuma3309961993-07-28 09:05:47 +000040
41#ifdef __cplusplus
42}
43#endif
44#endif /* !Py_NODE_H */