Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 1 | /*********************************************************** |
Guido van Rossum | fd71b9e | 2000-06-30 23:50:40 +0000 | [diff] [blame] | 2 | Copyright (c) 2000, BeOpen.com. |
| 3 | Copyright (c) 1995-2000, Corporation for National Research Initiatives. |
| 4 | Copyright (c) 1990-1995, Stichting Mathematisch Centrum. |
| 5 | All rights reserved. |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 6 | |
Guido van Rossum | fd71b9e | 2000-06-30 23:50:40 +0000 | [diff] [blame] | 7 | See the file "Misc/COPYRIGHT" for information on usage and |
| 8 | redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 9 | ******************************************************************/ |
| 10 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 11 | /* Parse tree node interface */ |
| 12 | |
Fred Drake | 5eb6d4e | 2000-07-08 23:37:28 +0000 | [diff] [blame] | 13 | #ifndef Py_NODE_H |
| 14 | #define Py_NODE_H |
| 15 | #ifdef __cplusplus |
| 16 | extern "C" { |
| 17 | #endif |
| 18 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 19 | typedef struct _node { |
Fred Drake | 5eb6d4e | 2000-07-08 23:37:28 +0000 | [diff] [blame] | 20 | short n_type; |
| 21 | char *n_str; |
| 22 | short n_lineno; |
| 23 | short n_nchildren; |
| 24 | struct _node *n_child; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 25 | } node; |
| 26 | |
Fred Drake | 5eb6d4e | 2000-07-08 23:37:28 +0000 | [diff] [blame] | 27 | extern DL_IMPORT(node *) PyNode_New(int type); |
| 28 | extern DL_IMPORT(int) PyNode_AddChild(node *n, int type, |
| 29 | char *str, int lineno); |
| 30 | extern DL_IMPORT(void) PyNode_Free(node *n); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 31 | |
| 32 | /* Node access functions */ |
| 33 | #define NCH(n) ((n)->n_nchildren) |
| 34 | #define CHILD(n, i) (&(n)->n_child[i]) |
| 35 | #define TYPE(n) ((n)->n_type) |
| 36 | #define STR(n) ((n)->n_str) |
| 37 | |
| 38 | /* Assert that the type of a node is what we expect */ |
Guido van Rossum | 408027e | 1996-12-30 16:17:54 +0000 | [diff] [blame] | 39 | #ifndef Py_DEBUG |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 40 | #define REQ(n, type) { /*pass*/ ; } |
| 41 | #else |
| 42 | #define REQ(n, type) \ |
| 43 | { if (TYPE(n) != (type)) { \ |
Fred Drake | 5eb6d4e | 2000-07-08 23:37:28 +0000 | [diff] [blame] | 44 | fprintf(stderr, "FATAL: node type %d, required %d\n", \ |
| 45 | TYPE(n), type); \ |
| 46 | abort(); \ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 47 | } } |
| 48 | #endif |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 49 | |
Fred Drake | 5eb6d4e | 2000-07-08 23:37:28 +0000 | [diff] [blame] | 50 | extern DL_IMPORT(void) PyNode_ListTree(node *); |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 51 | |
| 52 | #ifdef __cplusplus |
| 53 | } |
| 54 | #endif |
| 55 | #endif /* !Py_NODE_H */ |