blob: 96eb350f0a9ed1dd1bfecfbd02efb0d98044642e [file] [log] [blame]
Guido van Rossumf70e43a1991-02-19 12:39:46 +00001/***********************************************************
Guido van Rossumfd71b9e2000-06-30 23:50:40 +00002Copyright (c) 2000, BeOpen.com.
3Copyright (c) 1995-2000, Corporation for National Research Initiatives.
4Copyright (c) 1990-1995, Stichting Mathematisch Centrum.
5All rights reserved.
Guido van Rossumf70e43a1991-02-19 12:39:46 +00006
Guido van Rossumfd71b9e2000-06-30 23:50:40 +00007See the file "Misc/COPYRIGHT" for information on usage and
8redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
Guido van Rossumf70e43a1991-02-19 12:39:46 +00009******************************************************************/
10
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000011/* Parse tree node interface */
12
Fred Drake5eb6d4e2000-07-08 23:37:28 +000013#ifndef Py_NODE_H
14#define Py_NODE_H
15#ifdef __cplusplus
16extern "C" {
17#endif
18
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000019typedef struct _node {
Fred Drake5eb6d4e2000-07-08 23:37:28 +000020 short n_type;
21 char *n_str;
Fred Drakeef8ace32000-08-24 00:32:09 +000022 int n_lineno;
23 int n_nchildren;
Fred Drake5eb6d4e2000-07-08 23:37:28 +000024 struct _node *n_child;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000025} node;
26
Fred Drake5eb6d4e2000-07-08 23:37:28 +000027extern DL_IMPORT(node *) PyNode_New(int type);
28extern DL_IMPORT(int) PyNode_AddChild(node *n, int type,
29 char *str, int lineno);
30extern DL_IMPORT(void) PyNode_Free(node *n);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000031
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 Rossum408027e1996-12-30 16:17:54 +000039#ifndef Py_DEBUG
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000040#define REQ(n, type) { /*pass*/ ; }
41#else
42#define REQ(n, type) \
43 { if (TYPE(n) != (type)) { \
Fred Drake5eb6d4e2000-07-08 23:37:28 +000044 fprintf(stderr, "FATAL: node type %d, required %d\n", \
45 TYPE(n), type); \
46 abort(); \
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000047 } }
48#endif
Guido van Rossum3f5da241990-12-20 15:06:42 +000049
Fred Drake5eb6d4e2000-07-08 23:37:28 +000050extern DL_IMPORT(void) PyNode_ListTree(node *);
Guido van Rossuma3309961993-07-28 09:05:47 +000051
52#ifdef __cplusplus
53}
54#endif
55#endif /* !Py_NODE_H */