blob: 55fcd0f6bce967e85891345e7cab232d11f61075 [file] [log] [blame]
Guido van Rossuma3309961993-07-28 09:05:47 +00001#ifndef Py_NODE_H
2#define Py_NODE_H
3#ifdef __cplusplus
4extern "C" {
5#endif
6
Guido van Rossumf70e43a1991-02-19 12:39:46 +00007/***********************************************************
Guido van Rossumfd71b9e2000-06-30 23:50:40 +00008Copyright (c) 2000, BeOpen.com.
9Copyright (c) 1995-2000, Corporation for National Research Initiatives.
10Copyright (c) 1990-1995, Stichting Mathematisch Centrum.
11All rights reserved.
Guido van Rossumf70e43a1991-02-19 12:39:46 +000012
Guido van Rossumfd71b9e2000-06-30 23:50:40 +000013See the file "Misc/COPYRIGHT" for information on usage and
14redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
Guido van Rossumf70e43a1991-02-19 12:39:46 +000015******************************************************************/
16
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000017/* Parse tree node interface */
18
19typedef struct _node {
Guido van Rossumb4f066d1994-08-23 13:37:43 +000020 short n_type;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000021 char *n_str;
Guido van Rossumb4f066d1994-08-23 13:37:43 +000022 short n_lineno;
23 short n_nchildren;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000024 struct _node *n_child;
25} node;
26
Guido van Rossum43466ec1998-12-04 18:48:25 +000027extern DL_IMPORT(node *) PyNode_New Py_PROTO((int type));
Jeremy Hylton94988062000-06-20 19:10:44 +000028extern DL_IMPORT(int) PyNode_AddChild Py_PROTO((node *n, int type, char *str, int lineno));
Guido van Rossum43466ec1998-12-04 18:48:25 +000029extern DL_IMPORT(void) PyNode_Free Py_PROTO((node *n));
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000030
31/* Node access functions */
32#define NCH(n) ((n)->n_nchildren)
33#define CHILD(n, i) (&(n)->n_child[i])
34#define TYPE(n) ((n)->n_type)
35#define STR(n) ((n)->n_str)
36
37/* Assert that the type of a node is what we expect */
Guido van Rossum408027e1996-12-30 16:17:54 +000038#ifndef Py_DEBUG
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000039#define REQ(n, type) { /*pass*/ ; }
40#else
41#define REQ(n, type) \
42 { if (TYPE(n) != (type)) { \
43 fprintf(stderr, "FATAL: node type %d, required %d\n", \
44 TYPE(n), type); \
45 abort(); \
46 } }
47#endif
Guido van Rossum3f5da241990-12-20 15:06:42 +000048
Guido van Rossum43466ec1998-12-04 18:48:25 +000049extern DL_IMPORT(void) PyNode_ListTree Py_PROTO((node *));
Guido van Rossuma3309961993-07-28 09:05:47 +000050
51#ifdef __cplusplus
52}
53#endif
54#endif /* !Py_NODE_H */