Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 1 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2 | /* Parse tree node interface */ |
| 3 | |
Fred Drake | 5eb6d4e | 2000-07-08 23:37:28 +0000 | [diff] [blame] | 4 | #ifndef Py_NODE_H |
| 5 | #define Py_NODE_H |
| 6 | #ifdef __cplusplus |
| 7 | extern "C" { |
| 8 | #endif |
| 9 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 10 | typedef struct _node { |
Guido van Rossum | e5de778 | 2002-09-17 03:27:02 +0000 | [diff] [blame] | 11 | short n_type; |
Fred Drake | 5eb6d4e | 2000-07-08 23:37:28 +0000 | [diff] [blame] | 12 | char *n_str; |
Fred Drake | ef8ace3 | 2000-08-24 00:32:09 +0000 | [diff] [blame] | 13 | int n_lineno; |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 14 | int n_col_offset; |
Fred Drake | ef8ace3 | 2000-08-24 00:32:09 +0000 | [diff] [blame] | 15 | int n_nchildren; |
Guido van Rossum | e5de778 | 2002-09-17 03:27:02 +0000 | [diff] [blame] | 16 | struct _node *n_child; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 17 | } node; |
| 18 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 19 | PyAPI_FUNC(node *) PyNode_New(int type); |
| 20 | PyAPI_FUNC(int) PyNode_AddChild(node *n, int type, |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 21 | char *str, int lineno, int col_offset); |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 22 | PyAPI_FUNC(void) PyNode_Free(node *n); |
Jesus Cea | e9c5318 | 2012-08-03 14:28:37 +0200 | [diff] [blame] | 23 | #ifndef Py_LIMITED_API |
| 24 | Py_ssize_t _PyNode_SizeOf(node *n); |
| 25 | #endif |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 26 | |
| 27 | /* Node access functions */ |
| 28 | #define NCH(n) ((n)->n_nchildren) |
Anthony Baxter | c2a5a63 | 2004-08-02 06:10:11 +0000 | [diff] [blame] | 29 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 30 | #define CHILD(n, i) (&(n)->n_child[i]) |
Anthony Baxter | c2a5a63 | 2004-08-02 06:10:11 +0000 | [diff] [blame] | 31 | #define RCHILD(n, i) (CHILD(n, NCH(n) + i)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 32 | #define TYPE(n) ((n)->n_type) |
| 33 | #define STR(n) ((n)->n_str) |
Benjamin Peterson | c0beabc | 2012-01-16 17:29:05 -0500 | [diff] [blame] | 34 | #define LINENO(n) ((n)->n_lineno) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 35 | |
| 36 | /* Assert that the type of a node is what we expect */ |
Guido van Rossum | 5aace07 | 2001-10-15 17:23:13 +0000 | [diff] [blame] | 37 | #define REQ(n, type) assert(TYPE(n) == (type)) |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 38 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 39 | PyAPI_FUNC(void) PyNode_ListTree(node *); |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 40 | |
| 41 | #ifdef __cplusplus |
| 42 | } |
| 43 | #endif |
| 44 | #endif /* !Py_NODE_H */ |