blob: df6e5186d35f848deaa766ba1d27223549186270 [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 {
Fred Drake5eb6d4e2000-07-08 23:37:28 +000011 short n_type;
12 char *n_str;
Fred Drakeef8ace32000-08-24 00:32:09 +000013 int n_lineno;
14 int n_nchildren;
Fred Drake5eb6d4e2000-07-08 23:37:28 +000015 struct _node *n_child;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000016} node;
17
Fred Drake5eb6d4e2000-07-08 23:37:28 +000018extern DL_IMPORT(node *) PyNode_New(int type);
19extern DL_IMPORT(int) PyNode_AddChild(node *n, int type,
20 char *str, int lineno);
21extern DL_IMPORT(void) PyNode_Free(node *n);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000022
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 Rossum408027e1996-12-30 16:17:54 +000030#ifndef Py_DEBUG
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000031#define REQ(n, type) { /*pass*/ ; }
32#else
33#define REQ(n, type) \
34 { if (TYPE(n) != (type)) { \
Fred Drake5eb6d4e2000-07-08 23:37:28 +000035 fprintf(stderr, "FATAL: node type %d, required %d\n", \
36 TYPE(n), type); \
37 abort(); \
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000038 } }
39#endif
Guido van Rossum3f5da241990-12-20 15:06:42 +000040
Fred Drake5eb6d4e2000-07-08 23:37:28 +000041extern DL_IMPORT(void) PyNode_ListTree(node *);
Guido van Rossuma3309961993-07-28 09:05:47 +000042
43#ifdef __cplusplus
44}
45#endif
46#endif /* !Py_NODE_H */