1 /***********************************************************
2 Copyright (c) 2000, BeOpen.com.
3 Copyright (c) 1995-2000, Corporation for National Research Initiatives.
4 Copyright (c) 1990-1995, Stichting Mathematisch Centrum.
7 See the file "Misc/COPYRIGHT" for information on usage and
8 redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
9 ******************************************************************/
15 #define INT_MAX 2147483647
18 /* Parse tree node implementation */
20 #include "pgenheaders.h"
27 node
*n
= PyMem_NEW(node
, 1);
38 #define XXX 3 /* Node alignment factor to speed up realloc */
39 #define XXXROUNDUP(n) ((n) == 1 ? 1 : ((n) + XXX - 1) / XXX * XXX)
42 PyNode_AddChild(register node
*n1
, int type
, char *str
, int lineno
)
44 register int nch
= n1
->n_nchildren
;
45 register int nch1
= nch
+1;
47 if (nch
== INT_MAX
|| nch
< 0)
49 if (XXXROUNDUP(nch
) < nch1
) {
51 nch1
= XXXROUNDUP(nch1
);
52 PyMem_RESIZE(n
, node
, nch1
);
57 n
= &n1
->n_child
[n1
->n_nchildren
++];
67 static void freechildren(node
*);
83 for (i
= NCH(n
); --i
>= 0; )
84 freechildren(CHILD(n
, i
));
85 if (n
->n_child
!= NULL
)
86 PyMem_DEL(n
->n_child
);