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 { |
Fred Drake | 5eb6d4e | 2000-07-08 23:37:28 +0000 | [diff] [blame] | 11 | short n_type; |
| 12 | char *n_str; |
Fred Drake | ef8ace3 | 2000-08-24 00:32:09 +0000 | [diff] [blame] | 13 | int n_lineno; |
| 14 | int n_nchildren; |
Fred Drake | 5eb6d4e | 2000-07-08 23:37:28 +0000 | [diff] [blame] | 15 | struct _node *n_child; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 16 | } node; |
| 17 | |
Fred Drake | 5eb6d4e | 2000-07-08 23:37:28 +0000 | [diff] [blame] | 18 | extern DL_IMPORT(node *) PyNode_New(int type); |
| 19 | extern DL_IMPORT(int) PyNode_AddChild(node *n, int type, |
| 20 | char *str, int lineno); |
| 21 | extern DL_IMPORT(void) PyNode_Free(node *n); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 22 | |
| 23 | /* Node access functions */ |
| 24 | #define NCH(n) ((n)->n_nchildren) |
| 25 | #define CHILD(n, i) (&(n)->n_child[i]) |
| 26 | #define TYPE(n) ((n)->n_type) |
| 27 | #define STR(n) ((n)->n_str) |
| 28 | |
| 29 | /* Assert that the type of a node is what we expect */ |
Guido van Rossum | 408027e | 1996-12-30 16:17:54 +0000 | [diff] [blame] | 30 | #ifndef Py_DEBUG |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 31 | #define REQ(n, type) { /*pass*/ ; } |
| 32 | #else |
| 33 | #define REQ(n, type) \ |
| 34 | { if (TYPE(n) != (type)) { \ |
Fred Drake | 5eb6d4e | 2000-07-08 23:37:28 +0000 | [diff] [blame] | 35 | fprintf(stderr, "FATAL: node type %d, required %d\n", \ |
| 36 | TYPE(n), type); \ |
| 37 | abort(); \ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 38 | } } |
| 39 | #endif |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 40 | |
Fred Drake | 5eb6d4e | 2000-07-08 23:37:28 +0000 | [diff] [blame] | 41 | extern DL_IMPORT(void) PyNode_ListTree(node *); |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 42 | |
| 43 | #ifdef __cplusplus |
| 44 | } |
| 45 | #endif |
| 46 | #endif /* !Py_NODE_H */ |