Mercurial > cpython-lru_cache-weakref
annotate Parser/node.c @ 7278:59d2761ba1cf legacy-trunk
Remove obsolete pagenumbering / pagestyle cruft.
| author | Fred Drake <fdrake@acm.org> |
|---|---|
| date | Fri, 13 Feb 1998 07:08:56 +0000 |
| parents | 1c9a84e0981d |
| children | 63436719d12e |
| rev | line source |
|---|---|
| 145 | 1 /*********************************************************** |
|
2060
146890653a57
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
1848
diff
changeset
|
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
|
146890653a57
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
1848
diff
changeset
|
3 The Netherlands. |
| 145 | 4 |
| 5 All Rights Reserved | |
| 6 | |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2060
diff
changeset
|
7 Permission to use, copy, modify, and distribute this software and its |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2060
diff
changeset
|
8 documentation for any purpose and without fee is hereby granted, |
| 145 | 9 provided that the above copyright notice appear in all copies and that |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2060
diff
changeset
|
10 both that copyright notice and this permission notice appear in |
| 145 | 11 supporting documentation, and that the names of Stichting Mathematisch |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2060
diff
changeset
|
12 Centrum or CWI or Corporation for National Research Initiatives or |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2060
diff
changeset
|
13 CNRI not be used in advertising or publicity pertaining to |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2060
diff
changeset
|
14 distribution of the software without specific, written prior |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2060
diff
changeset
|
15 permission. |
| 145 | 16 |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2060
diff
changeset
|
17 While CWI is the initial source for this software, a modified version |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2060
diff
changeset
|
18 is made available by the Corporation for National Research Initiatives |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2060
diff
changeset
|
19 (CNRI) at the Internet address ftp://ftp.python.org. |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2060
diff
changeset
|
20 |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2060
diff
changeset
|
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2060
diff
changeset
|
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2060
diff
changeset
|
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2060
diff
changeset
|
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2060
diff
changeset
|
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2060
diff
changeset
|
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2060
diff
changeset
|
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2060
diff
changeset
|
28 PERFORMANCE OF THIS SOFTWARE. |
| 145 | 29 |
| 30 ******************************************************************/ | |
| 31 | |
| 6 | 32 /* Parse tree node implementation */ |
| 33 | |
| 86 | 34 #include "pgenheaders.h" |
| 6 | 35 #include "node.h" |
| 36 | |
| 37 node * | |
|
5379
1c9a84e0981d
Another directory quickly renamed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
38 PyNode_New(type) |
| 6 | 39 int type; |
| 40 { | |
|
5379
1c9a84e0981d
Another directory quickly renamed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
41 node *n = PyMem_NEW(node, 1); |
| 6 | 42 if (n == NULL) |
| 43 return NULL; | |
| 44 n->n_type = type; | |
| 45 n->n_str = NULL; | |
| 86 | 46 n->n_lineno = 0; |
| 6 | 47 n->n_nchildren = 0; |
| 48 n->n_child = NULL; | |
| 49 return n; | |
| 50 } | |
| 51 | |
| 52 #define XXX 3 /* Node alignment factor to speed up realloc */ | |
| 53 #define XXXROUNDUP(n) ((n) == 1 ? 1 : ((n) + XXX - 1) / XXX * XXX) | |
| 54 | |
| 55 node * | |
|
5379
1c9a84e0981d
Another directory quickly renamed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
56 PyNode_AddChild(n1, type, str, lineno) |
| 6 | 57 register node *n1; |
| 58 int type; | |
| 59 char *str; | |
| 86 | 60 int lineno; |
| 6 | 61 { |
| 62 register int nch = n1->n_nchildren; | |
| 63 register int nch1 = nch+1; | |
| 64 register node *n; | |
| 65 if (XXXROUNDUP(nch) < nch1) { | |
| 66 n = n1->n_child; | |
| 67 nch1 = XXXROUNDUP(nch1); | |
|
5379
1c9a84e0981d
Another directory quickly renamed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
68 PyMem_RESIZE(n, node, nch1); |
| 6 | 69 if (n == NULL) |
| 70 return NULL; | |
| 71 n1->n_child = n; | |
| 72 } | |
| 73 n = &n1->n_child[n1->n_nchildren++]; | |
| 74 n->n_type = type; | |
| 75 n->n_str = str; | |
| 86 | 76 n->n_lineno = lineno; |
| 6 | 77 n->n_nchildren = 0; |
| 78 n->n_child = NULL; | |
| 79 return n; | |
| 80 } | |
|
76
ede86799705b
Add function to free an entire parse tree.
Guido van Rossum <guido@python.org>
parents:
6
diff
changeset
|
81 |
| 86 | 82 /* Forward */ |
|
5379
1c9a84e0981d
Another directory quickly renamed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
83 static void freechildren Py_PROTO((node *)); |
| 86 | 84 |
| 85 | |
| 86 void | |
|
5379
1c9a84e0981d
Another directory quickly renamed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
87 PyNode_Free(n) |
| 86 | 88 node *n; |
| 89 { | |
| 90 if (n != NULL) { | |
| 91 freechildren(n); | |
|
5379
1c9a84e0981d
Another directory quickly renamed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
92 PyMem_DEL(n); |
| 86 | 93 } |
| 94 } | |
| 95 | |
|
76
ede86799705b
Add function to free an entire parse tree.
Guido van Rossum <guido@python.org>
parents:
6
diff
changeset
|
96 static void |
|
ede86799705b
Add function to free an entire parse tree.
Guido van Rossum <guido@python.org>
parents:
6
diff
changeset
|
97 freechildren(n) |
|
ede86799705b
Add function to free an entire parse tree.
Guido van Rossum <guido@python.org>
parents:
6
diff
changeset
|
98 node *n; |
|
ede86799705b
Add function to free an entire parse tree.
Guido van Rossum <guido@python.org>
parents:
6
diff
changeset
|
99 { |
|
ede86799705b
Add function to free an entire parse tree.
Guido van Rossum <guido@python.org>
parents:
6
diff
changeset
|
100 int i; |
|
ede86799705b
Add function to free an entire parse tree.
Guido van Rossum <guido@python.org>
parents:
6
diff
changeset
|
101 for (i = NCH(n); --i >= 0; ) |
|
ede86799705b
Add function to free an entire parse tree.
Guido van Rossum <guido@python.org>
parents:
6
diff
changeset
|
102 freechildren(CHILD(n, i)); |
|
ede86799705b
Add function to free an entire parse tree.
Guido van Rossum <guido@python.org>
parents:
6
diff
changeset
|
103 if (n->n_child != NULL) |
|
5379
1c9a84e0981d
Another directory quickly renamed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
104 PyMem_DEL(n->n_child); |
|
76
ede86799705b
Add function to free an entire parse tree.
Guido van Rossum <guido@python.org>
parents:
6
diff
changeset
|
105 if (STR(n) != NULL) |
|
5379
1c9a84e0981d
Another directory quickly renamed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
106 PyMem_DEL(STR(n)); |
|
76
ede86799705b
Add function to free an entire parse tree.
Guido van Rossum <guido@python.org>
parents:
6
diff
changeset
|
107 } |
