blob: 99c13f7dc9069f193ade676b95b9b56e39ce7b79 [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 {
Guido van Rossume5de7782002-09-17 03:27:02 +000011 short n_type;
Fred Drake5eb6d4e2000-07-08 23:37:28 +000012 char *n_str;
Fred Drakeef8ace32000-08-24 00:32:09 +000013 int n_lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +000014 int n_col_offset;
Fred Drakeef8ace32000-08-24 00:32:09 +000015 int n_nchildren;
Guido van Rossume5de7782002-09-17 03:27:02 +000016 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
24Py_ssize_t _PyNode_SizeOf(node *n);
25#endif
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000026
27/* Node access functions */
28#define NCH(n) ((n)->n_nchildren)
Anthony Baxterc2a5a632004-08-02 06:10:11 +000029
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000030#define CHILD(n, i) (&(n)->n_child[i])
Anthony Baxterc2a5a632004-08-02 06:10:11 +000031#define RCHILD(n, i) (CHILD(n, NCH(n) + i))
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000032#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 */