blob: e23e709fffa30cb625c700201102f54e6957e04f [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);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000023
24/* Node access functions */
25#define NCH(n) ((n)->n_nchildren)
Anthony Baxterc2a5a632004-08-02 06:10:11 +000026
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000027#define CHILD(n, i) (&(n)->n_child[i])
Anthony Baxterc2a5a632004-08-02 06:10:11 +000028#define RCHILD(n, i) (CHILD(n, NCH(n) + i))
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000029#define TYPE(n) ((n)->n_type)
30#define STR(n) ((n)->n_str)
31
32/* Assert that the type of a node is what we expect */
Guido van Rossum5aace072001-10-15 17:23:13 +000033#define REQ(n, type) assert(TYPE(n) == (type))
Guido van Rossum3f5da241990-12-20 15:06:42 +000034
Mark Hammond91a681d2002-08-12 07:21:58 +000035PyAPI_FUNC(void) PyNode_ListTree(node *);
Guido van Rossuma3309961993-07-28 09:05:47 +000036
37#ifdef __cplusplus
38}
39#endif
40#endif /* !Py_NODE_H */