annotate Python/Python-ast.c @ 57673:20b7deb53d4e legacy-trunk

account for PyObject_IsInstance's new ability to fail
author Benjamin Peterson <benjamin@python.org>
date Sun, 13 Dec 2009 00:54:15 +0000
parents 247f8d268d58
children c2fdf25329ff
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
40824
180d4e899683 Modify Parser/asdl_c.py so that the __version__ number for Python/Python-ast.c
Brett Cannon <bcannon@gmail.com>
parents: 40817
diff changeset
1 /* File automatically generated by Parser/asdl_c.py. */
180d4e899683 Modify Parser/asdl_c.py so that the __version__ number for Python/Python-ast.c
Brett Cannon <bcannon@gmail.com>
parents: 40817
diff changeset
2
180d4e899683 Modify Parser/asdl_c.py so that the __version__ number for Python/Python-ast.c
Brett Cannon <bcannon@gmail.com>
parents: 40817
diff changeset
3
180d4e899683 Modify Parser/asdl_c.py so that the __version__ number for Python/Python-ast.c
Brett Cannon <bcannon@gmail.com>
parents: 40817
diff changeset
4 /*
54744
247f8d268d58 update ast version
Benjamin Peterson <benjamin@python.org>
parents: 54743
diff changeset
5 __version__ 73421.
40824
180d4e899683 Modify Parser/asdl_c.py so that the __version__ number for Python/Python-ast.c
Brett Cannon <bcannon@gmail.com>
parents: 40817
diff changeset
6
180d4e899683 Modify Parser/asdl_c.py so that the __version__ number for Python/Python-ast.c
Brett Cannon <bcannon@gmail.com>
parents: 40817
diff changeset
7 This module must be committed separately after each AST grammar change;
180d4e899683 Modify Parser/asdl_c.py so that the __version__ number for Python/Python-ast.c
Brett Cannon <bcannon@gmail.com>
parents: 40817
diff changeset
8 The __version__ number is set to the revision number of the commit
180d4e899683 Modify Parser/asdl_c.py so that the __version__ number for Python/Python-ast.c
Brett Cannon <bcannon@gmail.com>
parents: 40817
diff changeset
9 containing the grammar change.
180d4e899683 Modify Parser/asdl_c.py so that the __version__ number for Python/Python-ast.c
Brett Cannon <bcannon@gmail.com>
parents: 40817
diff changeset
10 */
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
11
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
12 #include "Python.h"
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
13 #include "Python-ast.h"
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
14
46202
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
15 static PyTypeObject AST_type;
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
16 static PyTypeObject *mod_type;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
17 static PyObject* ast2obj_mod(void*);
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
18 static PyTypeObject *Module_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
19 static char *Module_fields[]={
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
20 "body",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
21 };
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
22 static PyTypeObject *Interactive_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
23 static char *Interactive_fields[]={
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
24 "body",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
25 };
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
26 static PyTypeObject *Expression_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
27 static char *Expression_fields[]={
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
28 "body",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
29 };
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
30 static PyTypeObject *Suite_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
31 static char *Suite_fields[]={
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
32 "body",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
33 };
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
34 static PyTypeObject *stmt_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
35 static char *stmt_attributes[] = {
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
36 "lineno",
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
37 "col_offset",
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
38 };
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
39 static PyObject* ast2obj_stmt(void*);
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
40 static PyTypeObject *FunctionDef_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
41 static char *FunctionDef_fields[]={
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
42 "name",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
43 "args",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
44 "body",
45447
393822f2ef90 Patch #1759: Backport of PEP 3129 class decorators
Christian Heimes <christian@cheimes.de>
parents: 40936
diff changeset
45 "decorator_list",
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
46 };
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
47 static PyTypeObject *ClassDef_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
48 static char *ClassDef_fields[]={
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
49 "name",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
50 "bases",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
51 "body",
45447
393822f2ef90 Patch #1759: Backport of PEP 3129 class decorators
Christian Heimes <christian@cheimes.de>
parents: 40936
diff changeset
52 "decorator_list",
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
53 };
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
54 static PyTypeObject *Return_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
55 static char *Return_fields[]={
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
56 "value",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
57 };
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
58 static PyTypeObject *Delete_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
59 static char *Delete_fields[]={
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
60 "targets",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
61 };
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
62 static PyTypeObject *Assign_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
63 static char *Assign_fields[]={
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
64 "targets",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
65 "value",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
66 };
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
67 static PyTypeObject *AugAssign_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
68 static char *AugAssign_fields[]={
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
69 "target",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
70 "op",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
71 "value",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
72 };
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
73 static PyTypeObject *Print_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
74 static char *Print_fields[]={
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
75 "dest",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
76 "values",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
77 "nl",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
78 };
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
79 static PyTypeObject *For_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
80 static char *For_fields[]={
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
81 "target",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
82 "iter",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
83 "body",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
84 "orelse",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
85 };
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
86 static PyTypeObject *While_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
87 static char *While_fields[]={
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
88 "test",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
89 "body",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
90 "orelse",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
91 };
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
92 static PyTypeObject *If_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
93 static char *If_fields[]={
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
94 "test",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
95 "body",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
96 "orelse",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
97 };
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
98 static PyTypeObject *With_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
99 static char *With_fields[]={
36695
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36669
diff changeset
100 "context_expr",
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36669
diff changeset
101 "optional_vars",
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36669
diff changeset
102 "body",
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36669
diff changeset
103 };
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
104 static PyTypeObject *Raise_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
105 static char *Raise_fields[]={
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
106 "type",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
107 "inst",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
108 "tback",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
109 };
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
110 static PyTypeObject *TryExcept_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
111 static char *TryExcept_fields[]={
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
112 "body",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
113 "handlers",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
114 "orelse",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
115 };
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
116 static PyTypeObject *TryFinally_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
117 static char *TryFinally_fields[]={
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
118 "body",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
119 "finalbody",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
120 };
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
121 static PyTypeObject *Assert_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
122 static char *Assert_fields[]={
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
123 "test",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
124 "msg",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
125 };
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
126 static PyTypeObject *Import_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
127 static char *Import_fields[]={
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
128 "names",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
129 };
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
130 static PyTypeObject *ImportFrom_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
131 static char *ImportFrom_fields[]={
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
132 "module",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
133 "names",
36712
5c36c222e7ca SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents: 36707
diff changeset
134 "level",
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
135 };
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
136 static PyTypeObject *Exec_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
137 static char *Exec_fields[]={
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
138 "body",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
139 "globals",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
140 "locals",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
141 };
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
142 static PyTypeObject *Global_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
143 static char *Global_fields[]={
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
144 "names",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
145 };
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
146 static PyTypeObject *Expr_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
147 static char *Expr_fields[]={
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
148 "value",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
149 };
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
150 static PyTypeObject *Pass_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
151 static PyTypeObject *Break_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
152 static PyTypeObject *Continue_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
153 static PyTypeObject *expr_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
154 static char *expr_attributes[] = {
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
155 "lineno",
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
156 "col_offset",
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
157 };
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
158 static PyObject* ast2obj_expr(void*);
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
159 static PyTypeObject *BoolOp_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
160 static char *BoolOp_fields[]={
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
161 "op",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
162 "values",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
163 };
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
164 static PyTypeObject *BinOp_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
165 static char *BinOp_fields[]={
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
166 "left",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
167 "op",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
168 "right",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
169 };
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
170 static PyTypeObject *UnaryOp_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
171 static char *UnaryOp_fields[]={
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
172 "op",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
173 "operand",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
174 };
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
175 static PyTypeObject *Lambda_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
176 static char *Lambda_fields[]={
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
177 "args",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
178 "body",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
179 };
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
180 static PyTypeObject *IfExp_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
181 static char *IfExp_fields[]={
36666
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
182 "test",
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
183 "body",
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
184 "orelse",
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
185 };
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
186 static PyTypeObject *Dict_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
187 static char *Dict_fields[]={
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
188 "keys",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
189 "values",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
190 };
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
191 static PyTypeObject *ListComp_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
192 static char *ListComp_fields[]={
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
193 "elt",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
194 "generators",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
195 };
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
196 static PyTypeObject *GeneratorExp_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
197 static char *GeneratorExp_fields[]={
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
198 "elt",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
199 "generators",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
200 };
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
201 static PyTypeObject *Yield_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
202 static char *Yield_fields[]={
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
203 "value",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
204 };
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
205 static PyTypeObject *Compare_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
206 static char *Compare_fields[]={
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
207 "left",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
208 "ops",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
209 "comparators",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
210 };
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
211 static PyTypeObject *Call_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
212 static char *Call_fields[]={
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
213 "func",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
214 "args",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
215 "keywords",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
216 "starargs",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
217 "kwargs",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
218 };
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
219 static PyTypeObject *Repr_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
220 static char *Repr_fields[]={
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
221 "value",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
222 };
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
223 static PyTypeObject *Num_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
224 static char *Num_fields[]={
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
225 "n",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
226 };
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
227 static PyTypeObject *Str_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
228 static char *Str_fields[]={
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
229 "s",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
230 };
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
231 static PyTypeObject *Attribute_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
232 static char *Attribute_fields[]={
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
233 "value",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
234 "attr",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
235 "ctx",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
236 };
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
237 static PyTypeObject *Subscript_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
238 static char *Subscript_fields[]={
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
239 "value",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
240 "slice",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
241 "ctx",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
242 };
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
243 static PyTypeObject *Name_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
244 static char *Name_fields[]={
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
245 "id",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
246 "ctx",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
247 };
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
248 static PyTypeObject *List_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
249 static char *List_fields[]={
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
250 "elts",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
251 "ctx",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
252 };
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
253 static PyTypeObject *Tuple_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
254 static char *Tuple_fields[]={
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
255 "elts",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
256 "ctx",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
257 };
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
258 static PyTypeObject *expr_context_type;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
259 static PyObject *Load_singleton, *Store_singleton, *Del_singleton,
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
260 *AugLoad_singleton, *AugStore_singleton, *Param_singleton;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
261 static PyObject* ast2obj_expr_context(expr_context_ty);
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
262 static PyTypeObject *Load_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
263 static PyTypeObject *Store_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
264 static PyTypeObject *Del_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
265 static PyTypeObject *AugLoad_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
266 static PyTypeObject *AugStore_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
267 static PyTypeObject *Param_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
268 static PyTypeObject *slice_type;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
269 static PyObject* ast2obj_slice(void*);
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
270 static PyTypeObject *Ellipsis_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
271 static PyTypeObject *Slice_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
272 static char *Slice_fields[]={
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
273 "lower",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
274 "upper",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
275 "step",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
276 };
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
277 static PyTypeObject *ExtSlice_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
278 static char *ExtSlice_fields[]={
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
279 "dims",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
280 };
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
281 static PyTypeObject *Index_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
282 static char *Index_fields[]={
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
283 "value",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
284 };
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
285 static PyTypeObject *boolop_type;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
286 static PyObject *And_singleton, *Or_singleton;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
287 static PyObject* ast2obj_boolop(boolop_ty);
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
288 static PyTypeObject *And_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
289 static PyTypeObject *Or_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
290 static PyTypeObject *operator_type;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
291 static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton,
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
292 *Div_singleton, *Mod_singleton, *Pow_singleton, *LShift_singleton,
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
293 *RShift_singleton, *BitOr_singleton, *BitXor_singleton, *BitAnd_singleton,
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
294 *FloorDiv_singleton;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
295 static PyObject* ast2obj_operator(operator_ty);
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
296 static PyTypeObject *Add_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
297 static PyTypeObject *Sub_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
298 static PyTypeObject *Mult_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
299 static PyTypeObject *Div_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
300 static PyTypeObject *Mod_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
301 static PyTypeObject *Pow_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
302 static PyTypeObject *LShift_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
303 static PyTypeObject *RShift_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
304 static PyTypeObject *BitOr_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
305 static PyTypeObject *BitXor_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
306 static PyTypeObject *BitAnd_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
307 static PyTypeObject *FloorDiv_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
308 static PyTypeObject *unaryop_type;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
309 static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton,
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
310 *USub_singleton;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
311 static PyObject* ast2obj_unaryop(unaryop_ty);
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
312 static PyTypeObject *Invert_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
313 static PyTypeObject *Not_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
314 static PyTypeObject *UAdd_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
315 static PyTypeObject *USub_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
316 static PyTypeObject *cmpop_type;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
317 static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton,
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
318 *Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton,
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
319 *NotIn_singleton;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
320 static PyObject* ast2obj_cmpop(cmpop_ty);
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
321 static PyTypeObject *Eq_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
322 static PyTypeObject *NotEq_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
323 static PyTypeObject *Lt_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
324 static PyTypeObject *LtE_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
325 static PyTypeObject *Gt_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
326 static PyTypeObject *GtE_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
327 static PyTypeObject *Is_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
328 static PyTypeObject *IsNot_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
329 static PyTypeObject *In_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
330 static PyTypeObject *NotIn_type;
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
331 static PyTypeObject *comprehension_type;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
332 static PyObject* ast2obj_comprehension(void*);
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
333 static char *comprehension_fields[]={
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
334 "target",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
335 "iter",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
336 "ifs",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
337 };
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
338 static PyTypeObject *excepthandler_type;
46200
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
339 static char *excepthandler_attributes[] = {
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
340 "lineno",
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
341 "col_offset",
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
342 };
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
343 static PyObject* ast2obj_excepthandler(void*);
46200
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
344 static PyTypeObject *ExceptHandler_type;
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
345 static char *ExceptHandler_fields[]={
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
346 "type",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
347 "name",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
348 "body",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
349 };
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
350 static PyTypeObject *arguments_type;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
351 static PyObject* ast2obj_arguments(void*);
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
352 static char *arguments_fields[]={
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
353 "args",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
354 "vararg",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
355 "kwarg",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
356 "defaults",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
357 };
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
358 static PyTypeObject *keyword_type;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
359 static PyObject* ast2obj_keyword(void*);
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
360 static char *keyword_fields[]={
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
361 "arg",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
362 "value",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
363 };
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
364 static PyTypeObject *alias_type;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
365 static PyObject* ast2obj_alias(void*);
36743
dbf9cc6c36eb Don't pollute namespace as bad as before. All the types are static now.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36726
diff changeset
366 static char *alias_fields[]={
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
367 "name",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
368 "asname",
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
369 };
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
370
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
371
46202
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
372 static int
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
373 ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
374 {
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
375 Py_ssize_t i, numfields = 0;
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
376 int res = -1;
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
377 PyObject *key, *value, *fields;
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
378 fields = PyObject_GetAttrString((PyObject*)Py_TYPE(self), "_fields");
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
379 if (!fields)
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
380 PyErr_Clear();
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
381 if (fields) {
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
382 numfields = PySequence_Size(fields);
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
383 if (numfields == -1)
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
384 goto cleanup;
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
385 }
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
386 res = 0; /* if no error occurs, this stays 0 to the end */
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
387 if (PyTuple_GET_SIZE(args) > 0) {
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
388 if (numfields != PyTuple_GET_SIZE(args)) {
46207
59d42e6d1885 Fix error message -- "expects either 0 or 0 arguments"
Georg Brandl <georg@python.org>
parents: 46204
diff changeset
389 PyErr_Format(PyExc_TypeError, "%.400s constructor takes %s"
49138
145449109a31 #3743: PY_FORMAT_SIZE_T is designed for the OS "printf" functions, not for
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47527
diff changeset
390 "%zd positional argument%s",
46207
59d42e6d1885 Fix error message -- "expects either 0 or 0 arguments"
Georg Brandl <georg@python.org>
parents: 46204
diff changeset
391 Py_TYPE(self)->tp_name,
59d42e6d1885 Fix error message -- "expects either 0 or 0 arguments"
Georg Brandl <georg@python.org>
parents: 46204
diff changeset
392 numfields == 0 ? "" : "either 0 or ",
46202
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
393 numfields, numfields == 1 ? "" : "s");
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
394 res = -1;
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
395 goto cleanup;
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
396 }
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
397 for (i = 0; i < PyTuple_GET_SIZE(args); i++) {
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
398 /* cannot be reached when fields is NULL */
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
399 PyObject *name = PySequence_GetItem(fields, i);
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
400 if (!name) {
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
401 res = -1;
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
402 goto cleanup;
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
403 }
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
404 res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i));
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
405 Py_DECREF(name);
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
406 if (res < 0)
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
407 goto cleanup;
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
408 }
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
409 }
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
410 if (kw) {
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
411 i = 0; /* needed by PyDict_Next */
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
412 while (PyDict_Next(kw, &i, &key, &value)) {
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
413 res = PyObject_SetAttr(self, key, value);
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
414 if (res < 0)
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
415 goto cleanup;
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
416 }
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
417 }
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
418 cleanup:
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
419 Py_XDECREF(fields);
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
420 return res;
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
421 }
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
422
46212
be18df634405 Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents: 46207
diff changeset
423 /* Pickling support */
be18df634405 Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents: 46207
diff changeset
424 static PyObject *
be18df634405 Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents: 46207
diff changeset
425 ast_type_reduce(PyObject *self, PyObject *unused)
be18df634405 Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents: 46207
diff changeset
426 {
be18df634405 Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents: 46207
diff changeset
427 PyObject *res;
be18df634405 Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents: 46207
diff changeset
428 PyObject *dict = PyObject_GetAttrString(self, "__dict__");
be18df634405 Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents: 46207
diff changeset
429 if (dict == NULL) {
be18df634405 Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents: 46207
diff changeset
430 if (PyErr_ExceptionMatches(PyExc_AttributeError))
be18df634405 Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents: 46207
diff changeset
431 PyErr_Clear();
be18df634405 Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents: 46207
diff changeset
432 else
be18df634405 Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents: 46207
diff changeset
433 return NULL;
be18df634405 Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents: 46207
diff changeset
434 }
be18df634405 Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents: 46207
diff changeset
435 if (dict) {
be18df634405 Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents: 46207
diff changeset
436 res = Py_BuildValue("O()O", Py_TYPE(self), dict);
be18df634405 Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents: 46207
diff changeset
437 Py_DECREF(dict);
be18df634405 Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents: 46207
diff changeset
438 return res;
be18df634405 Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents: 46207
diff changeset
439 }
be18df634405 Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents: 46207
diff changeset
440 return Py_BuildValue("O()", Py_TYPE(self));
be18df634405 Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents: 46207
diff changeset
441 }
be18df634405 Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents: 46207
diff changeset
442
be18df634405 Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents: 46207
diff changeset
443 static PyMethodDef ast_type_methods[] = {
be18df634405 Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents: 46207
diff changeset
444 {"__reduce__", ast_type_reduce, METH_NOARGS, NULL},
be18df634405 Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents: 46207
diff changeset
445 {NULL}
be18df634405 Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents: 46207
diff changeset
446 };
be18df634405 Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents: 46207
diff changeset
447
46202
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
448 static PyTypeObject AST_type = {
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
449 PyVarObject_HEAD_INIT(&PyType_Type, 0)
46212
be18df634405 Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents: 46207
diff changeset
450 "_ast.AST",
46202
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
451 sizeof(PyObject),
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
452 0,
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
453 0, /* tp_dealloc */
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
454 0, /* tp_print */
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
455 0, /* tp_getattr */
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
456 0, /* tp_setattr */
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
457 0, /* tp_compare */
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
458 0, /* tp_repr */
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
459 0, /* tp_as_number */
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
460 0, /* tp_as_sequence */
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
461 0, /* tp_as_mapping */
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
462 0, /* tp_hash */
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
463 0, /* tp_call */
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
464 0, /* tp_str */
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
465 PyObject_GenericGetAttr, /* tp_getattro */
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
466 PyObject_GenericSetAttr, /* tp_setattro */
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
467 0, /* tp_as_buffer */
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
468 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
469 0, /* tp_doc */
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
470 0, /* tp_traverse */
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
471 0, /* tp_clear */
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
472 0, /* tp_richcompare */
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
473 0, /* tp_weaklistoffset */
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
474 0, /* tp_iter */
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
475 0, /* tp_iternext */
46212
be18df634405 Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents: 46207
diff changeset
476 ast_type_methods, /* tp_methods */
46202
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
477 0, /* tp_members */
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
478 0, /* tp_getset */
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
479 0, /* tp_base */
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
480 0, /* tp_dict */
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
481 0, /* tp_descr_get */
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
482 0, /* tp_descr_set */
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
483 0, /* tp_dictoffset */
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
484 (initproc)ast_type_init, /* tp_init */
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
485 PyType_GenericAlloc, /* tp_alloc */
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
486 PyType_GenericNew, /* tp_new */
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
487 PyObject_Del, /* tp_free */
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
488 };
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
489
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
490
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
491 static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
492 {
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
493 PyObject *fnames, *result;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
494 int i;
46204
29ea507fd998 Make _fields attr for no fields consistent with _attributes attr.
Georg Brandl <georg@python.org>
parents: 46202
diff changeset
495 fnames = PyTuple_New(num_fields);
29ea507fd998 Make _fields attr for no fields consistent with _attributes attr.
Georg Brandl <georg@python.org>
parents: 46202
diff changeset
496 if (!fnames) return NULL;
29ea507fd998 Make _fields attr for no fields consistent with _attributes attr.
Georg Brandl <georg@python.org>
parents: 46202
diff changeset
497 for (i = 0; i < num_fields; i++) {
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
498 PyObject *field = PyString_FromString(fields[i]);
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
499 if (!field) {
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
500 Py_DECREF(fnames);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
501 return NULL;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
502 }
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
503 PyTuple_SET_ITEM(fnames, i, field);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
504 }
36726
bbf16fd024df from __future__ import with_statement addon for 'with', mostly written by
Thomas Wouters <thomas@python.org>
parents: 36712
diff changeset
505 result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}",
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
506 type, base, "_fields", fnames, "__module__", "_ast");
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
507 Py_DECREF(fnames);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
508 return (PyTypeObject*)result;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
509 }
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
510
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
511 static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
512 {
37412
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
513 int i, result;
46202
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
514 PyObject *s, *l = PyTuple_New(num_fields);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
515 if (!l) return 0;
37412
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
516 for(i = 0; i < num_fields; i++) {
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
517 s = PyString_FromString(attrs[i]);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
518 if (!s) {
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
519 Py_DECREF(l);
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
520 return 0;
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
521 }
46202
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
522 PyTuple_SET_ITEM(l, i, s);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
523 }
37412
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
524 result = PyObject_SetAttrString((PyObject*)type, "_attributes", l) >= 0;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
525 Py_DECREF(l);
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
526 return result;
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
527 }
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
528
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
529 /* Conversion AST -> Python */
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
530
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
531 static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
532 {
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
533 int i, n = asdl_seq_LEN(seq);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
534 PyObject *result = PyList_New(n);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
535 PyObject *value;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
536 if (!result)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
537 return NULL;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
538 for (i = 0; i < n; i++) {
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
539 value = func(asdl_seq_GET(seq, i));
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
540 if (!value) {
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
541 Py_DECREF(result);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
542 return NULL;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
543 }
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
544 PyList_SET_ITEM(result, i, value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
545 }
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
546 return result;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
547 }
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
548
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
549 static PyObject* ast2obj_object(void *o)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
550 {
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
551 if (!o)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
552 o = Py_None;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
553 Py_INCREF((PyObject*)o);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
554 return (PyObject*)o;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
555 }
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
556 #define ast2obj_identifier ast2obj_object
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
557 #define ast2obj_string ast2obj_object
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
558 static PyObject* ast2obj_bool(bool b)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
559 {
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
560 return PyBool_FromLong(b);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
561 }
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
562
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
563 static PyObject* ast2obj_int(long b)
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
564 {
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
565 return PyInt_FromLong(b);
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
566 }
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
567
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
568 /* Conversion Python -> AST */
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
569
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
570 static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena)
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
571 {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
572 if (obj == Py_None)
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
573 obj = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
574 if (obj)
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
575 PyArena_AddPyObject(arena, obj);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
576 Py_XINCREF(obj);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
577 *out = obj;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
578 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
579 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
580
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
581 #define obj2ast_identifier obj2ast_object
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
582 #define obj2ast_string obj2ast_object
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
583
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
584 static int obj2ast_int(PyObject* obj, int* out, PyArena* arena)
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
585 {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
586 int i;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
587 if (!PyInt_Check(obj) && !PyLong_Check(obj)) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
588 PyObject *s = PyObject_Repr(obj);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
589 if (s == NULL) return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
590 PyErr_Format(PyExc_ValueError, "invalid integer value: %.400s",
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
591 PyString_AS_STRING(s));
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
592 Py_DECREF(s);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
593 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
594 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
595
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
596 i = (int)PyLong_AsLong(obj);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
597 if (i == -1 && PyErr_Occurred())
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
598 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
599 *out = i;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
600 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
601 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
602
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
603 static int obj2ast_bool(PyObject* obj, bool* out, PyArena* arena)
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
604 {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
605 if (!PyBool_Check(obj)) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
606 PyObject *s = PyObject_Repr(obj);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
607 if (s == NULL) return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
608 PyErr_Format(PyExc_ValueError, "invalid boolean value: %.400s",
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
609 PyString_AS_STRING(s));
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
610 Py_DECREF(s);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
611 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
612 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
613
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
614 *out = (obj == Py_True);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
615 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
616 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
617
49552
2e38ca709b1d fix compiler warning
Benjamin Peterson <benjamin@python.org>
parents: 49551
diff changeset
618 static int add_ast_fields(void)
49551
dbd54bac0b6f Fixed #4067 by implementing _attributes and _fields for the AST root node.
Armin Ronacher <armin.ronacher@active-4.com>
parents: 49138
diff changeset
619 {
dbd54bac0b6f Fixed #4067 by implementing _attributes and _fields for the AST root node.
Armin Ronacher <armin.ronacher@active-4.com>
parents: 49138
diff changeset
620 PyObject *empty_tuple, *d;
dbd54bac0b6f Fixed #4067 by implementing _attributes and _fields for the AST root node.
Armin Ronacher <armin.ronacher@active-4.com>
parents: 49138
diff changeset
621 if (PyType_Ready(&AST_type) < 0)
dbd54bac0b6f Fixed #4067 by implementing _attributes and _fields for the AST root node.
Armin Ronacher <armin.ronacher@active-4.com>
parents: 49138
diff changeset
622 return -1;
dbd54bac0b6f Fixed #4067 by implementing _attributes and _fields for the AST root node.
Armin Ronacher <armin.ronacher@active-4.com>
parents: 49138
diff changeset
623 d = AST_type.tp_dict;
dbd54bac0b6f Fixed #4067 by implementing _attributes and _fields for the AST root node.
Armin Ronacher <armin.ronacher@active-4.com>
parents: 49138
diff changeset
624 empty_tuple = PyTuple_New(0);
dbd54bac0b6f Fixed #4067 by implementing _attributes and _fields for the AST root node.
Armin Ronacher <armin.ronacher@active-4.com>
parents: 49138
diff changeset
625 if (!empty_tuple ||
dbd54bac0b6f Fixed #4067 by implementing _attributes and _fields for the AST root node.
Armin Ronacher <armin.ronacher@active-4.com>
parents: 49138
diff changeset
626 PyDict_SetItemString(d, "_fields", empty_tuple) < 0 ||
dbd54bac0b6f Fixed #4067 by implementing _attributes and _fields for the AST root node.
Armin Ronacher <armin.ronacher@active-4.com>
parents: 49138
diff changeset
627 PyDict_SetItemString(d, "_attributes", empty_tuple) < 0) {
dbd54bac0b6f Fixed #4067 by implementing _attributes and _fields for the AST root node.
Armin Ronacher <armin.ronacher@active-4.com>
parents: 49138
diff changeset
628 Py_XDECREF(empty_tuple);
dbd54bac0b6f Fixed #4067 by implementing _attributes and _fields for the AST root node.
Armin Ronacher <armin.ronacher@active-4.com>
parents: 49138
diff changeset
629 return -1;
dbd54bac0b6f Fixed #4067 by implementing _attributes and _fields for the AST root node.
Armin Ronacher <armin.ronacher@active-4.com>
parents: 49138
diff changeset
630 }
dbd54bac0b6f Fixed #4067 by implementing _attributes and _fields for the AST root node.
Armin Ronacher <armin.ronacher@active-4.com>
parents: 49138
diff changeset
631 Py_DECREF(empty_tuple);
dbd54bac0b6f Fixed #4067 by implementing _attributes and _fields for the AST root node.
Armin Ronacher <armin.ronacher@active-4.com>
parents: 49138
diff changeset
632 return 0;
dbd54bac0b6f Fixed #4067 by implementing _attributes and _fields for the AST root node.
Armin Ronacher <armin.ronacher@active-4.com>
parents: 49138
diff changeset
633 }
dbd54bac0b6f Fixed #4067 by implementing _attributes and _fields for the AST root node.
Armin Ronacher <armin.ronacher@active-4.com>
parents: 49138
diff changeset
634
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
635
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
636 static int init_types(void)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
637 {
37412
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
638 static int initialized;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
639 if (initialized) return 1;
49551
dbd54bac0b6f Fixed #4067 by implementing _attributes and _fields for the AST root node.
Armin Ronacher <armin.ronacher@active-4.com>
parents: 49138
diff changeset
640 if (add_ast_fields() < 0) return 0;
46202
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
641 mod_type = make_type("mod", &AST_type, NULL, 0);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
642 if (!mod_type) return 0;
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
643 if (!add_attributes(mod_type, NULL, 0)) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
644 Module_type = make_type("Module", mod_type, Module_fields, 1);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
645 if (!Module_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
646 Interactive_type = make_type("Interactive", mod_type,
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
647 Interactive_fields, 1);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
648 if (!Interactive_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
649 Expression_type = make_type("Expression", mod_type, Expression_fields,
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
650 1);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
651 if (!Expression_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
652 Suite_type = make_type("Suite", mod_type, Suite_fields, 1);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
653 if (!Suite_type) return 0;
46202
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
654 stmt_type = make_type("stmt", &AST_type, NULL, 0);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
655 if (!stmt_type) return 0;
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
656 if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
657 FunctionDef_type = make_type("FunctionDef", stmt_type,
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
658 FunctionDef_fields, 4);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
659 if (!FunctionDef_type) return 0;
45447
393822f2ef90 Patch #1759: Backport of PEP 3129 class decorators
Christian Heimes <christian@cheimes.de>
parents: 40936
diff changeset
660 ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 4);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
661 if (!ClassDef_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
662 Return_type = make_type("Return", stmt_type, Return_fields, 1);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
663 if (!Return_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
664 Delete_type = make_type("Delete", stmt_type, Delete_fields, 1);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
665 if (!Delete_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
666 Assign_type = make_type("Assign", stmt_type, Assign_fields, 2);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
667 if (!Assign_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
668 AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
669 if (!AugAssign_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
670 Print_type = make_type("Print", stmt_type, Print_fields, 3);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
671 if (!Print_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
672 For_type = make_type("For", stmt_type, For_fields, 4);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
673 if (!For_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
674 While_type = make_type("While", stmt_type, While_fields, 3);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
675 if (!While_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
676 If_type = make_type("If", stmt_type, If_fields, 3);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
677 if (!If_type) return 0;
36695
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36669
diff changeset
678 With_type = make_type("With", stmt_type, With_fields, 3);
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36669
diff changeset
679 if (!With_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
680 Raise_type = make_type("Raise", stmt_type, Raise_fields, 3);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
681 if (!Raise_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
682 TryExcept_type = make_type("TryExcept", stmt_type, TryExcept_fields, 3);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
683 if (!TryExcept_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
684 TryFinally_type = make_type("TryFinally", stmt_type, TryFinally_fields,
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
685 2);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
686 if (!TryFinally_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
687 Assert_type = make_type("Assert", stmt_type, Assert_fields, 2);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
688 if (!Assert_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
689 Import_type = make_type("Import", stmt_type, Import_fields, 1);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
690 if (!Import_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
691 ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields,
36712
5c36c222e7ca SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents: 36707
diff changeset
692 3);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
693 if (!ImportFrom_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
694 Exec_type = make_type("Exec", stmt_type, Exec_fields, 3);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
695 if (!Exec_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
696 Global_type = make_type("Global", stmt_type, Global_fields, 1);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
697 if (!Global_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
698 Expr_type = make_type("Expr", stmt_type, Expr_fields, 1);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
699 if (!Expr_type) return 0;
36664
7bfbfb2ef4e2 Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents: 36661
diff changeset
700 Pass_type = make_type("Pass", stmt_type, NULL, 0);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
701 if (!Pass_type) return 0;
36664
7bfbfb2ef4e2 Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents: 36661
diff changeset
702 Break_type = make_type("Break", stmt_type, NULL, 0);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
703 if (!Break_type) return 0;
36664
7bfbfb2ef4e2 Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents: 36661
diff changeset
704 Continue_type = make_type("Continue", stmt_type, NULL, 0);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
705 if (!Continue_type) return 0;
46202
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
706 expr_type = make_type("expr", &AST_type, NULL, 0);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
707 if (!expr_type) return 0;
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
708 if (!add_attributes(expr_type, expr_attributes, 2)) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
709 BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
710 if (!BoolOp_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
711 BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
712 if (!BinOp_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
713 UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
714 if (!UnaryOp_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
715 Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
716 if (!Lambda_type) return 0;
36666
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
717 IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
718 if (!IfExp_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
719 Dict_type = make_type("Dict", expr_type, Dict_fields, 2);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
720 if (!Dict_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
721 ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
722 if (!ListComp_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
723 GeneratorExp_type = make_type("GeneratorExp", expr_type,
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
724 GeneratorExp_fields, 2);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
725 if (!GeneratorExp_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
726 Yield_type = make_type("Yield", expr_type, Yield_fields, 1);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
727 if (!Yield_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
728 Compare_type = make_type("Compare", expr_type, Compare_fields, 3);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
729 if (!Compare_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
730 Call_type = make_type("Call", expr_type, Call_fields, 5);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
731 if (!Call_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
732 Repr_type = make_type("Repr", expr_type, Repr_fields, 1);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
733 if (!Repr_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
734 Num_type = make_type("Num", expr_type, Num_fields, 1);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
735 if (!Num_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
736 Str_type = make_type("Str", expr_type, Str_fields, 1);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
737 if (!Str_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
738 Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
739 if (!Attribute_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
740 Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
741 if (!Subscript_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
742 Name_type = make_type("Name", expr_type, Name_fields, 2);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
743 if (!Name_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
744 List_type = make_type("List", expr_type, List_fields, 2);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
745 if (!List_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
746 Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
747 if (!Tuple_type) return 0;
46202
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
748 expr_context_type = make_type("expr_context", &AST_type, NULL, 0);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
749 if (!expr_context_type) return 0;
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
750 if (!add_attributes(expr_context_type, NULL, 0)) return 0;
36664
7bfbfb2ef4e2 Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents: 36661
diff changeset
751 Load_type = make_type("Load", expr_context_type, NULL, 0);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
752 if (!Load_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
753 Load_singleton = PyType_GenericNew(Load_type, NULL, NULL);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
754 if (!Load_singleton) return 0;
36664
7bfbfb2ef4e2 Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents: 36661
diff changeset
755 Store_type = make_type("Store", expr_context_type, NULL, 0);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
756 if (!Store_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
757 Store_singleton = PyType_GenericNew(Store_type, NULL, NULL);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
758 if (!Store_singleton) return 0;
36664
7bfbfb2ef4e2 Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents: 36661
diff changeset
759 Del_type = make_type("Del", expr_context_type, NULL, 0);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
760 if (!Del_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
761 Del_singleton = PyType_GenericNew(Del_type, NULL, NULL);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
762 if (!Del_singleton) return 0;
36664
7bfbfb2ef4e2 Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents: 36661
diff changeset
763 AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
764 if (!AugLoad_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
765 AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
766 if (!AugLoad_singleton) return 0;
36664
7bfbfb2ef4e2 Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents: 36661
diff changeset
767 AugStore_type = make_type("AugStore", expr_context_type, NULL, 0);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
768 if (!AugStore_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
769 AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
770 if (!AugStore_singleton) return 0;
36664
7bfbfb2ef4e2 Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents: 36661
diff changeset
771 Param_type = make_type("Param", expr_context_type, NULL, 0);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
772 if (!Param_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
773 Param_singleton = PyType_GenericNew(Param_type, NULL, NULL);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
774 if (!Param_singleton) return 0;
46202
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
775 slice_type = make_type("slice", &AST_type, NULL, 0);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
776 if (!slice_type) return 0;
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
777 if (!add_attributes(slice_type, NULL, 0)) return 0;
36664
7bfbfb2ef4e2 Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents: 36661
diff changeset
778 Ellipsis_type = make_type("Ellipsis", slice_type, NULL, 0);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
779 if (!Ellipsis_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
780 Slice_type = make_type("Slice", slice_type, Slice_fields, 3);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
781 if (!Slice_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
782 ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
783 if (!ExtSlice_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
784 Index_type = make_type("Index", slice_type, Index_fields, 1);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
785 if (!Index_type) return 0;
46202
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
786 boolop_type = make_type("boolop", &AST_type, NULL, 0);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
787 if (!boolop_type) return 0;
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
788 if (!add_attributes(boolop_type, NULL, 0)) return 0;
36664
7bfbfb2ef4e2 Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents: 36661
diff changeset
789 And_type = make_type("And", boolop_type, NULL, 0);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
790 if (!And_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
791 And_singleton = PyType_GenericNew(And_type, NULL, NULL);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
792 if (!And_singleton) return 0;
36664
7bfbfb2ef4e2 Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents: 36661
diff changeset
793 Or_type = make_type("Or", boolop_type, NULL, 0);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
794 if (!Or_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
795 Or_singleton = PyType_GenericNew(Or_type, NULL, NULL);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
796 if (!Or_singleton) return 0;
46202
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
797 operator_type = make_type("operator", &AST_type, NULL, 0);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
798 if (!operator_type) return 0;
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
799 if (!add_attributes(operator_type, NULL, 0)) return 0;
36664
7bfbfb2ef4e2 Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents: 36661
diff changeset
800 Add_type = make_type("Add", operator_type, NULL, 0);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
801 if (!Add_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
802 Add_singleton = PyType_GenericNew(Add_type, NULL, NULL);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
803 if (!Add_singleton) return 0;
36664
7bfbfb2ef4e2 Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents: 36661
diff changeset
804 Sub_type = make_type("Sub", operator_type, NULL, 0);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
805 if (!Sub_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
806 Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
807 if (!Sub_singleton) return 0;
36664
7bfbfb2ef4e2 Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents: 36661
diff changeset
808 Mult_type = make_type("Mult", operator_type, NULL, 0);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
809 if (!Mult_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
810 Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
811 if (!Mult_singleton) return 0;
36664
7bfbfb2ef4e2 Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents: 36661
diff changeset
812 Div_type = make_type("Div", operator_type, NULL, 0);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
813 if (!Div_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
814 Div_singleton = PyType_GenericNew(Div_type, NULL, NULL);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
815 if (!Div_singleton) return 0;
36664
7bfbfb2ef4e2 Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents: 36661
diff changeset
816 Mod_type = make_type("Mod", operator_type, NULL, 0);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
817 if (!Mod_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
818 Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
819 if (!Mod_singleton) return 0;
36664
7bfbfb2ef4e2 Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents: 36661
diff changeset
820 Pow_type = make_type("Pow", operator_type, NULL, 0);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
821 if (!Pow_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
822 Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
823 if (!Pow_singleton) return 0;
36664
7bfbfb2ef4e2 Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents: 36661
diff changeset
824 LShift_type = make_type("LShift", operator_type, NULL, 0);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
825 if (!LShift_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
826 LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
827 if (!LShift_singleton) return 0;
36664
7bfbfb2ef4e2 Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents: 36661
diff changeset
828 RShift_type = make_type("RShift", operator_type, NULL, 0);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
829 if (!RShift_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
830 RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
831 if (!RShift_singleton) return 0;
36664
7bfbfb2ef4e2 Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents: 36661
diff changeset
832 BitOr_type = make_type("BitOr", operator_type, NULL, 0);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
833 if (!BitOr_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
834 BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
835 if (!BitOr_singleton) return 0;
36664
7bfbfb2ef4e2 Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents: 36661
diff changeset
836 BitXor_type = make_type("BitXor", operator_type, NULL, 0);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
837 if (!BitXor_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
838 BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
839 if (!BitXor_singleton) return 0;
36664
7bfbfb2ef4e2 Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents: 36661
diff changeset
840 BitAnd_type = make_type("BitAnd", operator_type, NULL, 0);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
841 if (!BitAnd_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
842 BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
843 if (!BitAnd_singleton) return 0;
36664
7bfbfb2ef4e2 Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents: 36661
diff changeset
844 FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
845 if (!FloorDiv_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
846 FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
847 if (!FloorDiv_singleton) return 0;
46202
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
848 unaryop_type = make_type("unaryop", &AST_type, NULL, 0);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
849 if (!unaryop_type) return 0;
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
850 if (!add_attributes(unaryop_type, NULL, 0)) return 0;
36664
7bfbfb2ef4e2 Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents: 36661
diff changeset
851 Invert_type = make_type("Invert", unaryop_type, NULL, 0);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
852 if (!Invert_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
853 Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
854 if (!Invert_singleton) return 0;
36664
7bfbfb2ef4e2 Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents: 36661
diff changeset
855 Not_type = make_type("Not", unaryop_type, NULL, 0);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
856 if (!Not_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
857 Not_singleton = PyType_GenericNew(Not_type, NULL, NULL);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
858 if (!Not_singleton) return 0;
36664
7bfbfb2ef4e2 Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents: 36661
diff changeset
859 UAdd_type = make_type("UAdd", unaryop_type, NULL, 0);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
860 if (!UAdd_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
861 UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
862 if (!UAdd_singleton) return 0;
36664
7bfbfb2ef4e2 Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents: 36661
diff changeset
863 USub_type = make_type("USub", unaryop_type, NULL, 0);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
864 if (!USub_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
865 USub_singleton = PyType_GenericNew(USub_type, NULL, NULL);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
866 if (!USub_singleton) return 0;
46202
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
867 cmpop_type = make_type("cmpop", &AST_type, NULL, 0);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
868 if (!cmpop_type) return 0;
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
869 if (!add_attributes(cmpop_type, NULL, 0)) return 0;
36664
7bfbfb2ef4e2 Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents: 36661
diff changeset
870 Eq_type = make_type("Eq", cmpop_type, NULL, 0);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
871 if (!Eq_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
872 Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
873 if (!Eq_singleton) return 0;
36664
7bfbfb2ef4e2 Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents: 36661
diff changeset
874 NotEq_type = make_type("NotEq", cmpop_type, NULL, 0);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
875 if (!NotEq_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
876 NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
877 if (!NotEq_singleton) return 0;
36664
7bfbfb2ef4e2 Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents: 36661
diff changeset
878 Lt_type = make_type("Lt", cmpop_type, NULL, 0);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
879 if (!Lt_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
880 Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
881 if (!Lt_singleton) return 0;
36664
7bfbfb2ef4e2 Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents: 36661
diff changeset
882 LtE_type = make_type("LtE", cmpop_type, NULL, 0);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
883 if (!LtE_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
884 LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
885 if (!LtE_singleton) return 0;
36664
7bfbfb2ef4e2 Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents: 36661
diff changeset
886 Gt_type = make_type("Gt", cmpop_type, NULL, 0);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
887 if (!Gt_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
888 Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
889 if (!Gt_singleton) return 0;
36664
7bfbfb2ef4e2 Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents: 36661
diff changeset
890 GtE_type = make_type("GtE", cmpop_type, NULL, 0);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
891 if (!GtE_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
892 GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
893 if (!GtE_singleton) return 0;
36664
7bfbfb2ef4e2 Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents: 36661
diff changeset
894 Is_type = make_type("Is", cmpop_type, NULL, 0);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
895 if (!Is_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
896 Is_singleton = PyType_GenericNew(Is_type, NULL, NULL);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
897 if (!Is_singleton) return 0;
36664
7bfbfb2ef4e2 Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents: 36661
diff changeset
898 IsNot_type = make_type("IsNot", cmpop_type, NULL, 0);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
899 if (!IsNot_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
900 IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
901 if (!IsNot_singleton) return 0;
36664
7bfbfb2ef4e2 Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents: 36661
diff changeset
902 In_type = make_type("In", cmpop_type, NULL, 0);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
903 if (!In_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
904 In_singleton = PyType_GenericNew(In_type, NULL, NULL);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
905 if (!In_singleton) return 0;
36664
7bfbfb2ef4e2 Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents: 36661
diff changeset
906 NotIn_type = make_type("NotIn", cmpop_type, NULL, 0);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
907 if (!NotIn_type) return 0;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
908 NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
909 if (!NotIn_singleton) return 0;
46202
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
910 comprehension_type = make_type("comprehension", &AST_type,
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
911 comprehension_fields, 3);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
912 if (!comprehension_type) return 0;
46202
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
913 excepthandler_type = make_type("excepthandler", &AST_type, NULL, 0);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
914 if (!excepthandler_type) return 0;
46200
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
915 if (!add_attributes(excepthandler_type, excepthandler_attributes, 2))
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
916 return 0;
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
917 ExceptHandler_type = make_type("ExceptHandler", excepthandler_type,
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
918 ExceptHandler_fields, 3);
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
919 if (!ExceptHandler_type) return 0;
46202
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
920 arguments_type = make_type("arguments", &AST_type, arguments_fields, 4);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
921 if (!arguments_type) return 0;
46202
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
922 keyword_type = make_type("keyword", &AST_type, keyword_fields, 2);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
923 if (!keyword_type) return 0;
46202
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
924 alias_type = make_type("alias", &AST_type, alias_fields, 2);
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
925 if (!alias_type) return 0;
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
926 initialized = 1;
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
927 return 1;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
928 }
35866
9f73dc0953d2 Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents: 35862
diff changeset
929
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
930 static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
931 static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
932 static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
933 static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena*
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
934 arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
935 static int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
936 static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
937 static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
938 static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
939 static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
940 static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena*
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
941 arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
942 static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena*
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
943 arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
944 static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
945 static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
946 static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
947
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
948 mod_ty
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
949 Module(asdl_seq * body, PyArena *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
950 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
951 mod_ty p;
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
952 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
953 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
954 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
955 p->kind = Module_kind;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
956 p->v.Module.body = body;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
957 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
958 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
959
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
960 mod_ty
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
961 Interactive(asdl_seq * body, PyArena *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
962 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
963 mod_ty p;
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
964 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
965 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
966 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
967 p->kind = Interactive_kind;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
968 p->v.Interactive.body = body;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
969 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
970 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
971
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
972 mod_ty
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
973 Expression(expr_ty body, PyArena *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
974 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
975 mod_ty p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
976 if (!body) {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
977 PyErr_SetString(PyExc_ValueError,
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
978 "field body is required for Expression");
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
979 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
980 }
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
981 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
982 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
983 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
984 p->kind = Expression_kind;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
985 p->v.Expression.body = body;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
986 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
987 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
988
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
989 mod_ty
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
990 Suite(asdl_seq * body, PyArena *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
991 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
992 mod_ty p;
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
993 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
994 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
995 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
996 p->kind = Suite_kind;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
997 p->v.Suite.body = body;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
998 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
999 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1000
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1001 stmt_ty
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1002 FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
45447
393822f2ef90 Patch #1759: Backport of PEP 3129 class decorators
Christian Heimes <christian@cheimes.de>
parents: 40936
diff changeset
1003 decorator_list, int lineno, int col_offset, PyArena *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1004 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1005 stmt_ty p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1006 if (!name) {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1007 PyErr_SetString(PyExc_ValueError,
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1008 "field name is required for FunctionDef");
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1009 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1010 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1011 if (!args) {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1012 PyErr_SetString(PyExc_ValueError,
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1013 "field args is required for FunctionDef");
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1014 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1015 }
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1016 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
1017 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1018 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1019 p->kind = FunctionDef_kind;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1020 p->v.FunctionDef.name = name;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1021 p->v.FunctionDef.args = args;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1022 p->v.FunctionDef.body = body;
45447
393822f2ef90 Patch #1759: Backport of PEP 3129 class decorators
Christian Heimes <christian@cheimes.de>
parents: 40936
diff changeset
1023 p->v.FunctionDef.decorator_list = decorator_list;
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1024 p->lineno = lineno;
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1025 p->col_offset = col_offset;
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1026 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1027 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1028
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1029 stmt_ty
45447
393822f2ef90 Patch #1759: Backport of PEP 3129 class decorators
Christian Heimes <christian@cheimes.de>
parents: 40936
diff changeset
1030 ClassDef(identifier name, asdl_seq * bases, asdl_seq * body, asdl_seq *
393822f2ef90 Patch #1759: Backport of PEP 3129 class decorators
Christian Heimes <christian@cheimes.de>
parents: 40936
diff changeset
1031 decorator_list, int lineno, int col_offset, PyArena *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1032 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1033 stmt_ty p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1034 if (!name) {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1035 PyErr_SetString(PyExc_ValueError,
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1036 "field name is required for ClassDef");
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1037 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1038 }
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1039 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
1040 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1041 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1042 p->kind = ClassDef_kind;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1043 p->v.ClassDef.name = name;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1044 p->v.ClassDef.bases = bases;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1045 p->v.ClassDef.body = body;
45447
393822f2ef90 Patch #1759: Backport of PEP 3129 class decorators
Christian Heimes <christian@cheimes.de>
parents: 40936
diff changeset
1046 p->v.ClassDef.decorator_list = decorator_list;
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1047 p->lineno = lineno;
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1048 p->col_offset = col_offset;
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1049 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1050 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1051
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1052 stmt_ty
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1053 Return(expr_ty value, int lineno, int col_offset, PyArena *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1054 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1055 stmt_ty p;
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1056 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
1057 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1058 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1059 p->kind = Return_kind;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1060 p->v.Return.value = value;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1061 p->lineno = lineno;
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1062 p->col_offset = col_offset;
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1063 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1064 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1065
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1066 stmt_ty
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1067 Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1068 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1069 stmt_ty p;
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1070 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
1071 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1072 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1073 p->kind = Delete_kind;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1074 p->v.Delete.targets = targets;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1075 p->lineno = lineno;
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1076 p->col_offset = col_offset;
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1077 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1078 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1079
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1080 stmt_ty
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1081 Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1082 *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1083 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1084 stmt_ty p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1085 if (!value) {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1086 PyErr_SetString(PyExc_ValueError,
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1087 "field value is required for Assign");
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1088 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1089 }
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1090 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
1091 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1092 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1093 p->kind = Assign_kind;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1094 p->v.Assign.targets = targets;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1095 p->v.Assign.value = value;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1096 p->lineno = lineno;
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1097 p->col_offset = col_offset;
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1098 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1099 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1100
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1101 stmt_ty
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1102 AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1103 col_offset, PyArena *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1104 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1105 stmt_ty p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1106 if (!target) {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1107 PyErr_SetString(PyExc_ValueError,
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1108 "field target is required for AugAssign");
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1109 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1110 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1111 if (!op) {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1112 PyErr_SetString(PyExc_ValueError,
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1113 "field op is required for AugAssign");
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1114 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1115 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1116 if (!value) {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1117 PyErr_SetString(PyExc_ValueError,
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1118 "field value is required for AugAssign");
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1119 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1120 }
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1121 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
1122 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1123 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1124 p->kind = AugAssign_kind;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1125 p->v.AugAssign.target = target;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1126 p->v.AugAssign.op = op;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1127 p->v.AugAssign.value = value;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1128 p->lineno = lineno;
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1129 p->col_offset = col_offset;
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1130 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1131 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1132
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1133 stmt_ty
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1134 Print(expr_ty dest, asdl_seq * values, bool nl, int lineno, int col_offset,
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1135 PyArena *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1136 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1137 stmt_ty p;
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1138 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
1139 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1140 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1141 p->kind = Print_kind;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1142 p->v.Print.dest = dest;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1143 p->v.Print.values = values;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1144 p->v.Print.nl = nl;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1145 p->lineno = lineno;
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1146 p->col_offset = col_offset;
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1147 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1148 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1149
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1150 stmt_ty
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1151 For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1152 lineno, int col_offset, PyArena *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1153 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1154 stmt_ty p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1155 if (!target) {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1156 PyErr_SetString(PyExc_ValueError,
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1157 "field target is required for For");
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1158 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1159 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1160 if (!iter) {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1161 PyErr_SetString(PyExc_ValueError,
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1162 "field iter is required for For");
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1163 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1164 }
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1165 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
1166 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1167 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1168 p->kind = For_kind;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1169 p->v.For.target = target;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1170 p->v.For.iter = iter;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1171 p->v.For.body = body;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1172 p->v.For.orelse = orelse;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1173 p->lineno = lineno;
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1174 p->col_offset = col_offset;
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1175 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1176 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1177
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1178 stmt_ty
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1179 While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1180 col_offset, PyArena *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1181 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1182 stmt_ty p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1183 if (!test) {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1184 PyErr_SetString(PyExc_ValueError,
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1185 "field test is required for While");
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1186 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1187 }
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1188 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
1189 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1190 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1191 p->kind = While_kind;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1192 p->v.While.test = test;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1193 p->v.While.body = body;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1194 p->v.While.orelse = orelse;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1195 p->lineno = lineno;
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1196 p->col_offset = col_offset;
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1197 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1198 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1199
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1200 stmt_ty
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1201 If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1202 col_offset, PyArena *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1203 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1204 stmt_ty p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1205 if (!test) {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1206 PyErr_SetString(PyExc_ValueError,
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1207 "field test is required for If");
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1208 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1209 }
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1210 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
1211 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1212 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1213 p->kind = If_kind;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1214 p->v.If.test = test;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1215 p->v.If.body = body;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1216 p->v.If.orelse = orelse;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1217 p->lineno = lineno;
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1218 p->col_offset = col_offset;
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1219 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1220 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1221
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1222 stmt_ty
36695
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36669
diff changeset
1223 With(expr_ty context_expr, expr_ty optional_vars, asdl_seq * body, int lineno,
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1224 int col_offset, PyArena *arena)
36695
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36669
diff changeset
1225 {
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36669
diff changeset
1226 stmt_ty p;
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36669
diff changeset
1227 if (!context_expr) {
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36669
diff changeset
1228 PyErr_SetString(PyExc_ValueError,
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36669
diff changeset
1229 "field context_expr is required for With");
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36669
diff changeset
1230 return NULL;
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36669
diff changeset
1231 }
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36669
diff changeset
1232 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
1233 if (!p)
36695
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36669
diff changeset
1234 return NULL;
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36669
diff changeset
1235 p->kind = With_kind;
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36669
diff changeset
1236 p->v.With.context_expr = context_expr;
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36669
diff changeset
1237 p->v.With.optional_vars = optional_vars;
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36669
diff changeset
1238 p->v.With.body = body;
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36669
diff changeset
1239 p->lineno = lineno;
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1240 p->col_offset = col_offset;
36695
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36669
diff changeset
1241 return p;
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36669
diff changeset
1242 }
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36669
diff changeset
1243
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36669
diff changeset
1244 stmt_ty
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1245 Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno, int col_offset,
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1246 PyArena *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1247 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1248 stmt_ty p;
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1249 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
1250 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1251 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1252 p->kind = Raise_kind;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1253 p->v.Raise.type = type;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1254 p->v.Raise.inst = inst;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1255 p->v.Raise.tback = tback;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1256 p->lineno = lineno;
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1257 p->col_offset = col_offset;
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1258 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1259 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1260
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1261 stmt_ty
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1262 TryExcept(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, int lineno,
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1263 int col_offset, PyArena *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1264 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1265 stmt_ty p;
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1266 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
1267 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1268 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1269 p->kind = TryExcept_kind;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1270 p->v.TryExcept.body = body;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1271 p->v.TryExcept.handlers = handlers;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1272 p->v.TryExcept.orelse = orelse;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1273 p->lineno = lineno;
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1274 p->col_offset = col_offset;
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1275 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1276 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1277
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1278 stmt_ty
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1279 TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, int col_offset,
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1280 PyArena *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1281 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1282 stmt_ty p;
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1283 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
1284 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1285 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1286 p->kind = TryFinally_kind;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1287 p->v.TryFinally.body = body;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1288 p->v.TryFinally.finalbody = finalbody;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1289 p->lineno = lineno;
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1290 p->col_offset = col_offset;
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1291 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1292 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1293
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1294 stmt_ty
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1295 Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, PyArena *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1296 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1297 stmt_ty p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1298 if (!test) {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1299 PyErr_SetString(PyExc_ValueError,
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1300 "field test is required for Assert");
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1301 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1302 }
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1303 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
1304 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1305 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1306 p->kind = Assert_kind;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1307 p->v.Assert.test = test;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1308 p->v.Assert.msg = msg;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1309 p->lineno = lineno;
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1310 p->col_offset = col_offset;
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1311 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1312 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1313
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1314 stmt_ty
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1315 Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1316 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1317 stmt_ty p;
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1318 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
1319 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1320 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1321 p->kind = Import_kind;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1322 p->v.Import.names = names;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1323 p->lineno = lineno;
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1324 p->col_offset = col_offset;
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1325 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1326 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1327
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1328 stmt_ty
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1329 ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1330 col_offset, PyArena *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1331 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1332 stmt_ty p;
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1333 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
1334 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1335 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1336 p->kind = ImportFrom_kind;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1337 p->v.ImportFrom.module = module;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1338 p->v.ImportFrom.names = names;
36712
5c36c222e7ca SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents: 36707
diff changeset
1339 p->v.ImportFrom.level = level;
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1340 p->lineno = lineno;
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1341 p->col_offset = col_offset;
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1342 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1343 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1344
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1345 stmt_ty
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1346 Exec(expr_ty body, expr_ty globals, expr_ty locals, int lineno, int col_offset,
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1347 PyArena *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1348 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1349 stmt_ty p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1350 if (!body) {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1351 PyErr_SetString(PyExc_ValueError,
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1352 "field body is required for Exec");
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1353 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1354 }
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1355 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
1356 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1357 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1358 p->kind = Exec_kind;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1359 p->v.Exec.body = body;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1360 p->v.Exec.globals = globals;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1361 p->v.Exec.locals = locals;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1362 p->lineno = lineno;
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1363 p->col_offset = col_offset;
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1364 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1365 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1366
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1367 stmt_ty
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1368 Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1369 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1370 stmt_ty p;
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1371 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
1372 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1373 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1374 p->kind = Global_kind;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1375 p->v.Global.names = names;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1376 p->lineno = lineno;
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1377 p->col_offset = col_offset;
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1378 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1379 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1380
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1381 stmt_ty
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1382 Expr(expr_ty value, int lineno, int col_offset, PyArena *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1383 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1384 stmt_ty p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1385 if (!value) {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1386 PyErr_SetString(PyExc_ValueError,
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1387 "field value is required for Expr");
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1388 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1389 }
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1390 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
1391 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1392 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1393 p->kind = Expr_kind;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1394 p->v.Expr.value = value;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1395 p->lineno = lineno;
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1396 p->col_offset = col_offset;
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1397 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1398 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1399
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1400 stmt_ty
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1401 Pass(int lineno, int col_offset, PyArena *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1402 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1403 stmt_ty p;
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1404 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
1405 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1406 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1407 p->kind = Pass_kind;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1408 p->lineno = lineno;
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1409 p->col_offset = col_offset;
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1410 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1411 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1412
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1413 stmt_ty
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1414 Break(int lineno, int col_offset, PyArena *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1415 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1416 stmt_ty p;
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1417 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
1418 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1419 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1420 p->kind = Break_kind;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1421 p->lineno = lineno;
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1422 p->col_offset = col_offset;
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1423 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1424 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1425
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1426 stmt_ty
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1427 Continue(int lineno, int col_offset, PyArena *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1428 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1429 stmt_ty p;
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1430 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
1431 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1432 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1433 p->kind = Continue_kind;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1434 p->lineno = lineno;
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1435 p->col_offset = col_offset;
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1436 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1437 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1438
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1439 expr_ty
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1440 BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1441 *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1442 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1443 expr_ty p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1444 if (!op) {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1445 PyErr_SetString(PyExc_ValueError,
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1446 "field op is required for BoolOp");
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1447 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1448 }
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1449 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
1450 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1451 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1452 p->kind = BoolOp_kind;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1453 p->v.BoolOp.op = op;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1454 p->v.BoolOp.values = values;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1455 p->lineno = lineno;
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1456 p->col_offset = col_offset;
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1457 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1458 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1459
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1460 expr_ty
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1461 BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset,
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1462 PyArena *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1463 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1464 expr_ty p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1465 if (!left) {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1466 PyErr_SetString(PyExc_ValueError,
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1467 "field left is required for BinOp");
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1468 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1469 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1470 if (!op) {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1471 PyErr_SetString(PyExc_ValueError,
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1472 "field op is required for BinOp");
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1473 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1474 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1475 if (!right) {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1476 PyErr_SetString(PyExc_ValueError,
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1477 "field right is required for BinOp");
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1478 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1479 }
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1480 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
1481 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1482 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1483 p->kind = BinOp_kind;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1484 p->v.BinOp.left = left;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1485 p->v.BinOp.op = op;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1486 p->v.BinOp.right = right;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1487 p->lineno = lineno;
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1488 p->col_offset = col_offset;
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1489 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1490 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1491
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1492 expr_ty
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1493 UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1494 *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1495 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1496 expr_ty p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1497 if (!op) {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1498 PyErr_SetString(PyExc_ValueError,
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1499 "field op is required for UnaryOp");
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1500 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1501 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1502 if (!operand) {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1503 PyErr_SetString(PyExc_ValueError,
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1504 "field operand is required for UnaryOp");
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1505 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1506 }
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1507 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
1508 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1509 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1510 p->kind = UnaryOp_kind;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1511 p->v.UnaryOp.op = op;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1512 p->v.UnaryOp.operand = operand;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1513 p->lineno = lineno;
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1514 p->col_offset = col_offset;
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1515 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1516 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1517
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1518 expr_ty
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1519 Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1520 *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1521 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1522 expr_ty p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1523 if (!args) {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1524 PyErr_SetString(PyExc_ValueError,
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1525 "field args is required for Lambda");
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1526 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1527 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1528 if (!body) {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1529 PyErr_SetString(PyExc_ValueError,
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1530 "field body is required for Lambda");
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1531 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1532 }
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1533 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
1534 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1535 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1536 p->kind = Lambda_kind;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1537 p->v.Lambda.args = args;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1538 p->v.Lambda.body = body;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1539 p->lineno = lineno;
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1540 p->col_offset = col_offset;
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1541 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1542 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1543
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1544 expr_ty
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1545 IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset,
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1546 PyArena *arena)
36666
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
1547 {
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
1548 expr_ty p;
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
1549 if (!test) {
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
1550 PyErr_SetString(PyExc_ValueError,
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
1551 "field test is required for IfExp");
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
1552 return NULL;
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
1553 }
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
1554 if (!body) {
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
1555 PyErr_SetString(PyExc_ValueError,
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
1556 "field body is required for IfExp");
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
1557 return NULL;
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
1558 }
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
1559 if (!orelse) {
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
1560 PyErr_SetString(PyExc_ValueError,
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
1561 "field orelse is required for IfExp");
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
1562 return NULL;
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
1563 }
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
1564 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
1565 if (!p)
36666
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
1566 return NULL;
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
1567 p->kind = IfExp_kind;
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
1568 p->v.IfExp.test = test;
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
1569 p->v.IfExp.body = body;
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
1570 p->v.IfExp.orelse = orelse;
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
1571 p->lineno = lineno;
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1572 p->col_offset = col_offset;
36666
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
1573 return p;
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
1574 }
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
1575
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
1576 expr_ty
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1577 Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1578 *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1579 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1580 expr_ty p;
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1581 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
1582 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1583 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1584 p->kind = Dict_kind;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1585 p->v.Dict.keys = keys;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1586 p->v.Dict.values = values;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1587 p->lineno = lineno;
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1588 p->col_offset = col_offset;
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1589 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1590 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1591
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1592 expr_ty
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1593 ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1594 PyArena *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1595 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1596 expr_ty p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1597 if (!elt) {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1598 PyErr_SetString(PyExc_ValueError,
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1599 "field elt is required for ListComp");
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1600 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1601 }
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1602 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
1603 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1604 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1605 p->kind = ListComp_kind;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1606 p->v.ListComp.elt = elt;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1607 p->v.ListComp.generators = generators;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1608 p->lineno = lineno;
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1609 p->col_offset = col_offset;
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1610 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1611 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1612
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1613 expr_ty
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1614 GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1615 PyArena *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1616 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1617 expr_ty p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1618 if (!elt) {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1619 PyErr_SetString(PyExc_ValueError,
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1620 "field elt is required for GeneratorExp");
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1621 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1622 }
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1623 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
1624 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1625 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1626 p->kind = GeneratorExp_kind;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1627 p->v.GeneratorExp.elt = elt;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1628 p->v.GeneratorExp.generators = generators;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1629 p->lineno = lineno;
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1630 p->col_offset = col_offset;
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1631 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1632 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1633
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1634 expr_ty
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1635 Yield(expr_ty value, int lineno, int col_offset, PyArena *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1636 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1637 expr_ty p;
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1638 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
1639 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1640 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1641 p->kind = Yield_kind;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1642 p->v.Yield.value = value;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1643 p->lineno = lineno;
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1644 p->col_offset = col_offset;
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1645 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1646 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1647
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1648 expr_ty
37685
5e72b0c74100 Introduce asdl_int_seq, to hold cmpop_ty.
Martin v. Löwis <martin@v.loewis.de>
parents: 37601
diff changeset
1649 Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno,
5e72b0c74100 Introduce asdl_int_seq, to hold cmpop_ty.
Martin v. Löwis <martin@v.loewis.de>
parents: 37601
diff changeset
1650 int col_offset, PyArena *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1651 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1652 expr_ty p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1653 if (!left) {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1654 PyErr_SetString(PyExc_ValueError,
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1655 "field left is required for Compare");
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1656 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1657 }
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1658 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
1659 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1660 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1661 p->kind = Compare_kind;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1662 p->v.Compare.left = left;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1663 p->v.Compare.ops = ops;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1664 p->v.Compare.comparators = comparators;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1665 p->lineno = lineno;
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1666 p->col_offset = col_offset;
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1667 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1668 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1669
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1670 expr_ty
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1671 Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, expr_ty starargs,
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1672 expr_ty kwargs, int lineno, int col_offset, PyArena *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1673 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1674 expr_ty p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1675 if (!func) {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1676 PyErr_SetString(PyExc_ValueError,
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1677 "field func is required for Call");
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1678 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1679 }
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1680 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
1681 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1682 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1683 p->kind = Call_kind;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1684 p->v.Call.func = func;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1685 p->v.Call.args = args;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1686 p->v.Call.keywords = keywords;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1687 p->v.Call.starargs = starargs;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1688 p->v.Call.kwargs = kwargs;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1689 p->lineno = lineno;
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1690 p->col_offset = col_offset;
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1691 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1692 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1693
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1694 expr_ty
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1695 Repr(expr_ty value, int lineno, int col_offset, PyArena *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1696 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1697 expr_ty p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1698 if (!value) {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1699 PyErr_SetString(PyExc_ValueError,
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1700 "field value is required for Repr");
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1701 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1702 }
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1703 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
1704 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1705 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1706 p->kind = Repr_kind;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1707 p->v.Repr.value = value;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1708 p->lineno = lineno;
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1709 p->col_offset = col_offset;
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1710 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1711 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1712
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1713 expr_ty
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1714 Num(object n, int lineno, int col_offset, PyArena *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1715 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1716 expr_ty p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1717 if (!n) {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1718 PyErr_SetString(PyExc_ValueError,
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1719 "field n is required for Num");
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1720 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1721 }
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1722 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
1723 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1724 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1725 p->kind = Num_kind;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1726 p->v.Num.n = n;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1727 p->lineno = lineno;
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1728 p->col_offset = col_offset;
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1729 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1730 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1731
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1732 expr_ty
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1733 Str(string s, int lineno, int col_offset, PyArena *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1734 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1735 expr_ty p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1736 if (!s) {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1737 PyErr_SetString(PyExc_ValueError,
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1738 "field s is required for Str");
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1739 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1740 }
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1741 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
1742 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1743 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1744 p->kind = Str_kind;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1745 p->v.Str.s = s;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1746 p->lineno = lineno;
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1747 p->col_offset = col_offset;
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1748 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1749 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1750
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1751 expr_ty
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1752 Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1753 col_offset, PyArena *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1754 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1755 expr_ty p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1756 if (!value) {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1757 PyErr_SetString(PyExc_ValueError,
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1758 "field value is required for Attribute");
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1759 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1760 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1761 if (!attr) {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1762 PyErr_SetString(PyExc_ValueError,
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1763 "field attr is required for Attribute");
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1764 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1765 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1766 if (!ctx) {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1767 PyErr_SetString(PyExc_ValueError,
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1768 "field ctx is required for Attribute");
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1769 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1770 }
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1771 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
1772 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1773 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1774 p->kind = Attribute_kind;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1775 p->v.Attribute.value = value;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1776 p->v.Attribute.attr = attr;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1777 p->v.Attribute.ctx = ctx;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1778 p->lineno = lineno;
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1779 p->col_offset = col_offset;
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1780 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1781 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1782
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1783 expr_ty
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1784 Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1785 col_offset, PyArena *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1786 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1787 expr_ty p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1788 if (!value) {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1789 PyErr_SetString(PyExc_ValueError,
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1790 "field value is required for Subscript");
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1791 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1792 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1793 if (!slice) {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1794 PyErr_SetString(PyExc_ValueError,
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1795 "field slice is required for Subscript");
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1796 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1797 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1798 if (!ctx) {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1799 PyErr_SetString(PyExc_ValueError,
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1800 "field ctx is required for Subscript");
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1801 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1802 }
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1803 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
1804 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1805 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1806 p->kind = Subscript_kind;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1807 p->v.Subscript.value = value;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1808 p->v.Subscript.slice = slice;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1809 p->v.Subscript.ctx = ctx;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1810 p->lineno = lineno;
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1811 p->col_offset = col_offset;
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1812 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1813 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1814
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1815 expr_ty
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1816 Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1817 *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1818 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1819 expr_ty p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1820 if (!id) {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1821 PyErr_SetString(PyExc_ValueError,
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1822 "field id is required for Name");
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1823 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1824 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1825 if (!ctx) {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1826 PyErr_SetString(PyExc_ValueError,
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1827 "field ctx is required for Name");
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1828 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1829 }
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1830 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
1831 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1832 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1833 p->kind = Name_kind;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1834 p->v.Name.id = id;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1835 p->v.Name.ctx = ctx;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1836 p->lineno = lineno;
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1837 p->col_offset = col_offset;
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1838 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1839 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1840
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1841 expr_ty
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1842 List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1843 *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1844 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1845 expr_ty p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1846 if (!ctx) {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1847 PyErr_SetString(PyExc_ValueError,
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1848 "field ctx is required for List");
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1849 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1850 }
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1851 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
1852 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1853 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1854 p->kind = List_kind;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1855 p->v.List.elts = elts;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1856 p->v.List.ctx = ctx;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1857 p->lineno = lineno;
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1858 p->col_offset = col_offset;
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1859 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1860 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1861
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1862 expr_ty
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1863 Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1864 *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1865 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1866 expr_ty p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1867 if (!ctx) {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1868 PyErr_SetString(PyExc_ValueError,
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1869 "field ctx is required for Tuple");
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1870 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1871 }
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1872 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
1873 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1874 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1875 p->kind = Tuple_kind;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1876 p->v.Tuple.elts = elts;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1877 p->v.Tuple.ctx = ctx;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1878 p->lineno = lineno;
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
1879 p->col_offset = col_offset;
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1880 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1881 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1882
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1883 slice_ty
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1884 Ellipsis(PyArena *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1885 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1886 slice_ty p;
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1887 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
1888 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1889 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1890 p->kind = Ellipsis_kind;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1891 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1892 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1893
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1894 slice_ty
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1895 Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1896 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1897 slice_ty p;
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1898 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
1899 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1900 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1901 p->kind = Slice_kind;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1902 p->v.Slice.lower = lower;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1903 p->v.Slice.upper = upper;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1904 p->v.Slice.step = step;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1905 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1906 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1907
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1908 slice_ty
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1909 ExtSlice(asdl_seq * dims, PyArena *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1910 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1911 slice_ty p;
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1912 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
1913 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1914 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1915 p->kind = ExtSlice_kind;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1916 p->v.ExtSlice.dims = dims;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1917 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1918 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1919
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1920 slice_ty
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1921 Index(expr_ty value, PyArena *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1922 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1923 slice_ty p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1924 if (!value) {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1925 PyErr_SetString(PyExc_ValueError,
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1926 "field value is required for Index");
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1927 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1928 }
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1929 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
1930 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1931 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1932 p->kind = Index_kind;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1933 p->v.Index.value = value;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1934 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1935 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1936
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1937 comprehension_ty
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1938 comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1939 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1940 comprehension_ty p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1941 if (!target) {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1942 PyErr_SetString(PyExc_ValueError,
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1943 "field target is required for comprehension");
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1944 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1945 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1946 if (!iter) {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1947 PyErr_SetString(PyExc_ValueError,
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1948 "field iter is required for comprehension");
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1949 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1950 }
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1951 p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
1952 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1953 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1954 p->target = target;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1955 p->iter = iter;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1956 p->ifs = ifs;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1957 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1958 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1959
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1960 excepthandler_ty
46200
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
1961 ExceptHandler(expr_ty type, expr_ty name, asdl_seq * body, int lineno, int
37453
16a64e394602 Add lineno, col_offset to excephandler to enable future fix for
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 37412
diff changeset
1962 col_offset, PyArena *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1963 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1964 excepthandler_ty p;
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1965 p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
1966 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1967 return NULL;
46200
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
1968 p->kind = ExceptHandler_kind;
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
1969 p->v.ExceptHandler.type = type;
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
1970 p->v.ExceptHandler.name = name;
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
1971 p->v.ExceptHandler.body = body;
37453
16a64e394602 Add lineno, col_offset to excephandler to enable future fix for
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 37412
diff changeset
1972 p->lineno = lineno;
16a64e394602 Add lineno, col_offset to excephandler to enable future fix for
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 37412
diff changeset
1973 p->col_offset = col_offset;
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1974 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1975 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1976
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1977 arguments_ty
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1978 arguments(asdl_seq * args, identifier vararg, identifier kwarg, asdl_seq *
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1979 defaults, PyArena *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1980 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1981 arguments_ty p;
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1982 p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
1983 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1984 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1985 p->args = args;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1986 p->vararg = vararg;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1987 p->kwarg = kwarg;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1988 p->defaults = defaults;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1989 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1990 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1991
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1992 keyword_ty
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
1993 keyword(identifier arg, expr_ty value, PyArena *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1994 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1995 keyword_ty p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1996 if (!arg) {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1997 PyErr_SetString(PyExc_ValueError,
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1998 "field arg is required for keyword");
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1999 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
2000 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
2001 if (!value) {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
2002 PyErr_SetString(PyExc_ValueError,
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
2003 "field value is required for keyword");
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
2004 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
2005 }
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
2006 p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
2007 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
2008 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
2009 p->arg = arg;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
2010 p->value = value;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
2011 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
2012 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
2013
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
2014 alias_ty
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
2015 alias(identifier name, identifier asname, PyArena *arena)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
2016 {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
2017 alias_ty p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
2018 if (!name) {
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
2019 PyErr_SetString(PyExc_ValueError,
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
2020 "field name is required for alias");
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
2021 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
2022 }
36065
ea083efdc96c Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents: 36003
diff changeset
2023 p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));
40936
0376f13a1af9 Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents: 40824
diff changeset
2024 if (!p)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
2025 return NULL;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
2026 p->name = name;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
2027 p->asname = asname;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
2028 return p;
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
2029 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
2030
35866
9f73dc0953d2 Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents: 35862
diff changeset
2031
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2032 PyObject*
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2033 ast2obj_mod(void* _o)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2034 {
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2035 mod_ty o = (mod_ty)_o;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2036 PyObject *result = NULL, *value = NULL;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2037 if (!o) {
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2038 Py_INCREF(Py_None);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2039 return Py_None;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2040 }
35866
9f73dc0953d2 Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents: 35862
diff changeset
2041
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2042 switch (o->kind) {
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2043 case Module_kind:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2044 result = PyType_GenericNew(Module_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2045 if (!result) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2046 value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2047 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2048 if (PyObject_SetAttrString(result, "body", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2049 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2050 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2051 break;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2052 case Interactive_kind:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2053 result = PyType_GenericNew(Interactive_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2054 if (!result) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2055 value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2056 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2057 if (PyObject_SetAttrString(result, "body", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2058 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2059 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2060 break;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2061 case Expression_kind:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2062 result = PyType_GenericNew(Expression_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2063 if (!result) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2064 value = ast2obj_expr(o->v.Expression.body);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2065 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2066 if (PyObject_SetAttrString(result, "body", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2067 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2068 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2069 break;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2070 case Suite_kind:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2071 result = PyType_GenericNew(Suite_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2072 if (!result) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2073 value = ast2obj_list(o->v.Suite.body, ast2obj_stmt);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2074 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2075 if (PyObject_SetAttrString(result, "body", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2076 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2077 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2078 break;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2079 }
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2080 return result;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2081 failed:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2082 Py_XDECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2083 Py_XDECREF(result);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2084 return NULL;
36174
85b2d804ac0a Regenerate.
Martin v. Löwis <martin@v.loewis.de>
parents: 36065
diff changeset
2085 }
35866
9f73dc0953d2 Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents: 35862
diff changeset
2086
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2087 PyObject*
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2088 ast2obj_stmt(void* _o)
35866
9f73dc0953d2 Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents: 35862
diff changeset
2089 {
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2090 stmt_ty o = (stmt_ty)_o;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2091 PyObject *result = NULL, *value = NULL;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2092 if (!o) {
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2093 Py_INCREF(Py_None);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2094 return Py_None;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2095 }
35866
9f73dc0953d2 Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents: 35862
diff changeset
2096
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2097 switch (o->kind) {
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2098 case FunctionDef_kind:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2099 result = PyType_GenericNew(FunctionDef_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2100 if (!result) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2101 value = ast2obj_identifier(o->v.FunctionDef.name);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2102 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2103 if (PyObject_SetAttrString(result, "name", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2104 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2105 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2106 value = ast2obj_arguments(o->v.FunctionDef.args);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2107 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2108 if (PyObject_SetAttrString(result, "args", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2109 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2110 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2111 value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2112 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2113 if (PyObject_SetAttrString(result, "body", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2114 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2115 Py_DECREF(value);
45447
393822f2ef90 Patch #1759: Backport of PEP 3129 class decorators
Christian Heimes <christian@cheimes.de>
parents: 40936
diff changeset
2116 value = ast2obj_list(o->v.FunctionDef.decorator_list,
393822f2ef90 Patch #1759: Backport of PEP 3129 class decorators
Christian Heimes <christian@cheimes.de>
parents: 40936
diff changeset
2117 ast2obj_expr);
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2118 if (!value) goto failed;
45447
393822f2ef90 Patch #1759: Backport of PEP 3129 class decorators
Christian Heimes <christian@cheimes.de>
parents: 40936
diff changeset
2119 if (PyObject_SetAttrString(result, "decorator_list", value) ==
393822f2ef90 Patch #1759: Backport of PEP 3129 class decorators
Christian Heimes <christian@cheimes.de>
parents: 40936
diff changeset
2120 -1)
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2121 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2122 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2123 break;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2124 case ClassDef_kind:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2125 result = PyType_GenericNew(ClassDef_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2126 if (!result) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2127 value = ast2obj_identifier(o->v.ClassDef.name);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2128 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2129 if (PyObject_SetAttrString(result, "name", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2130 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2131 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2132 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2133 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2134 if (PyObject_SetAttrString(result, "bases", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2135 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2136 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2137 value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2138 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2139 if (PyObject_SetAttrString(result, "body", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2140 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2141 Py_DECREF(value);
45447
393822f2ef90 Patch #1759: Backport of PEP 3129 class decorators
Christian Heimes <christian@cheimes.de>
parents: 40936
diff changeset
2142 value = ast2obj_list(o->v.ClassDef.decorator_list,
393822f2ef90 Patch #1759: Backport of PEP 3129 class decorators
Christian Heimes <christian@cheimes.de>
parents: 40936
diff changeset
2143 ast2obj_expr);
393822f2ef90 Patch #1759: Backport of PEP 3129 class decorators
Christian Heimes <christian@cheimes.de>
parents: 40936
diff changeset
2144 if (!value) goto failed;
393822f2ef90 Patch #1759: Backport of PEP 3129 class decorators
Christian Heimes <christian@cheimes.de>
parents: 40936
diff changeset
2145 if (PyObject_SetAttrString(result, "decorator_list", value) ==
393822f2ef90 Patch #1759: Backport of PEP 3129 class decorators
Christian Heimes <christian@cheimes.de>
parents: 40936
diff changeset
2146 -1)
393822f2ef90 Patch #1759: Backport of PEP 3129 class decorators
Christian Heimes <christian@cheimes.de>
parents: 40936
diff changeset
2147 goto failed;
393822f2ef90 Patch #1759: Backport of PEP 3129 class decorators
Christian Heimes <christian@cheimes.de>
parents: 40936
diff changeset
2148 Py_DECREF(value);
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2149 break;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2150 case Return_kind:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2151 result = PyType_GenericNew(Return_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2152 if (!result) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2153 value = ast2obj_expr(o->v.Return.value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2154 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2155 if (PyObject_SetAttrString(result, "value", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2156 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2157 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2158 break;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2159 case Delete_kind:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2160 result = PyType_GenericNew(Delete_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2161 if (!result) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2162 value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2163 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2164 if (PyObject_SetAttrString(result, "targets", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2165 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2166 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2167 break;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2168 case Assign_kind:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2169 result = PyType_GenericNew(Assign_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2170 if (!result) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2171 value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2172 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2173 if (PyObject_SetAttrString(result, "targets", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2174 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2175 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2176 value = ast2obj_expr(o->v.Assign.value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2177 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2178 if (PyObject_SetAttrString(result, "value", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2179 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2180 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2181 break;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2182 case AugAssign_kind:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2183 result = PyType_GenericNew(AugAssign_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2184 if (!result) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2185 value = ast2obj_expr(o->v.AugAssign.target);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2186 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2187 if (PyObject_SetAttrString(result, "target", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2188 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2189 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2190 value = ast2obj_operator(o->v.AugAssign.op);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2191 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2192 if (PyObject_SetAttrString(result, "op", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2193 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2194 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2195 value = ast2obj_expr(o->v.AugAssign.value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2196 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2197 if (PyObject_SetAttrString(result, "value", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2198 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2199 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2200 break;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2201 case Print_kind:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2202 result = PyType_GenericNew(Print_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2203 if (!result) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2204 value = ast2obj_expr(o->v.Print.dest);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2205 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2206 if (PyObject_SetAttrString(result, "dest", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2207 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2208 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2209 value = ast2obj_list(o->v.Print.values, ast2obj_expr);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2210 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2211 if (PyObject_SetAttrString(result, "values", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2212 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2213 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2214 value = ast2obj_bool(o->v.Print.nl);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2215 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2216 if (PyObject_SetAttrString(result, "nl", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2217 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2218 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2219 break;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2220 case For_kind:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2221 result = PyType_GenericNew(For_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2222 if (!result) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2223 value = ast2obj_expr(o->v.For.target);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2224 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2225 if (PyObject_SetAttrString(result, "target", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2226 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2227 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2228 value = ast2obj_expr(o->v.For.iter);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2229 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2230 if (PyObject_SetAttrString(result, "iter", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2231 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2232 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2233 value = ast2obj_list(o->v.For.body, ast2obj_stmt);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2234 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2235 if (PyObject_SetAttrString(result, "body", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2236 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2237 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2238 value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2239 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2240 if (PyObject_SetAttrString(result, "orelse", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2241 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2242 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2243 break;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2244 case While_kind:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2245 result = PyType_GenericNew(While_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2246 if (!result) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2247 value = ast2obj_expr(o->v.While.test);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2248 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2249 if (PyObject_SetAttrString(result, "test", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2250 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2251 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2252 value = ast2obj_list(o->v.While.body, ast2obj_stmt);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2253 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2254 if (PyObject_SetAttrString(result, "body", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2255 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2256 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2257 value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2258 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2259 if (PyObject_SetAttrString(result, "orelse", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2260 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2261 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2262 break;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2263 case If_kind:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2264 result = PyType_GenericNew(If_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2265 if (!result) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2266 value = ast2obj_expr(o->v.If.test);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2267 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2268 if (PyObject_SetAttrString(result, "test", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2269 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2270 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2271 value = ast2obj_list(o->v.If.body, ast2obj_stmt);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2272 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2273 if (PyObject_SetAttrString(result, "body", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2274 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2275 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2276 value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2277 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2278 if (PyObject_SetAttrString(result, "orelse", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2279 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2280 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2281 break;
36695
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36669
diff changeset
2282 case With_kind:
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36669
diff changeset
2283 result = PyType_GenericNew(With_type, NULL, NULL);
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36669
diff changeset
2284 if (!result) goto failed;
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36669
diff changeset
2285 value = ast2obj_expr(o->v.With.context_expr);
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36669
diff changeset
2286 if (!value) goto failed;
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36669
diff changeset
2287 if (PyObject_SetAttrString(result, "context_expr", value) == -1)
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36669
diff changeset
2288 goto failed;
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36669
diff changeset
2289 Py_DECREF(value);
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36669
diff changeset
2290 value = ast2obj_expr(o->v.With.optional_vars);
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36669
diff changeset
2291 if (!value) goto failed;
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36669
diff changeset
2292 if (PyObject_SetAttrString(result, "optional_vars", value) ==
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36669
diff changeset
2293 -1)
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36669
diff changeset
2294 goto failed;
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36669
diff changeset
2295 Py_DECREF(value);
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36669
diff changeset
2296 value = ast2obj_list(o->v.With.body, ast2obj_stmt);
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36669
diff changeset
2297 if (!value) goto failed;
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36669
diff changeset
2298 if (PyObject_SetAttrString(result, "body", value) == -1)
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36669
diff changeset
2299 goto failed;
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36669
diff changeset
2300 Py_DECREF(value);
b6d2f6fd3e11 PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents: 36669
diff changeset
2301 break;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2302 case Raise_kind:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2303 result = PyType_GenericNew(Raise_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2304 if (!result) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2305 value = ast2obj_expr(o->v.Raise.type);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2306 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2307 if (PyObject_SetAttrString(result, "type", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2308 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2309 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2310 value = ast2obj_expr(o->v.Raise.inst);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2311 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2312 if (PyObject_SetAttrString(result, "inst", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2313 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2314 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2315 value = ast2obj_expr(o->v.Raise.tback);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2316 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2317 if (PyObject_SetAttrString(result, "tback", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2318 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2319 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2320 break;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2321 case TryExcept_kind:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2322 result = PyType_GenericNew(TryExcept_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2323 if (!result) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2324 value = ast2obj_list(o->v.TryExcept.body, ast2obj_stmt);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2325 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2326 if (PyObject_SetAttrString(result, "body", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2327 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2328 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2329 value = ast2obj_list(o->v.TryExcept.handlers,
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2330 ast2obj_excepthandler);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2331 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2332 if (PyObject_SetAttrString(result, "handlers", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2333 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2334 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2335 value = ast2obj_list(o->v.TryExcept.orelse, ast2obj_stmt);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2336 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2337 if (PyObject_SetAttrString(result, "orelse", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2338 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2339 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2340 break;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2341 case TryFinally_kind:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2342 result = PyType_GenericNew(TryFinally_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2343 if (!result) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2344 value = ast2obj_list(o->v.TryFinally.body, ast2obj_stmt);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2345 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2346 if (PyObject_SetAttrString(result, "body", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2347 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2348 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2349 value = ast2obj_list(o->v.TryFinally.finalbody, ast2obj_stmt);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2350 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2351 if (PyObject_SetAttrString(result, "finalbody", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2352 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2353 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2354 break;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2355 case Assert_kind:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2356 result = PyType_GenericNew(Assert_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2357 if (!result) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2358 value = ast2obj_expr(o->v.Assert.test);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2359 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2360 if (PyObject_SetAttrString(result, "test", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2361 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2362 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2363 value = ast2obj_expr(o->v.Assert.msg);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2364 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2365 if (PyObject_SetAttrString(result, "msg", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2366 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2367 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2368 break;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2369 case Import_kind:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2370 result = PyType_GenericNew(Import_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2371 if (!result) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2372 value = ast2obj_list(o->v.Import.names, ast2obj_alias);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2373 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2374 if (PyObject_SetAttrString(result, "names", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2375 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2376 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2377 break;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2378 case ImportFrom_kind:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2379 result = PyType_GenericNew(ImportFrom_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2380 if (!result) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2381 value = ast2obj_identifier(o->v.ImportFrom.module);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2382 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2383 if (PyObject_SetAttrString(result, "module", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2384 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2385 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2386 value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2387 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2388 if (PyObject_SetAttrString(result, "names", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2389 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2390 Py_DECREF(value);
36712
5c36c222e7ca SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents: 36707
diff changeset
2391 value = ast2obj_int(o->v.ImportFrom.level);
5c36c222e7ca SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents: 36707
diff changeset
2392 if (!value) goto failed;
5c36c222e7ca SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents: 36707
diff changeset
2393 if (PyObject_SetAttrString(result, "level", value) == -1)
5c36c222e7ca SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents: 36707
diff changeset
2394 goto failed;
5c36c222e7ca SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents: 36707
diff changeset
2395 Py_DECREF(value);
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2396 break;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2397 case Exec_kind:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2398 result = PyType_GenericNew(Exec_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2399 if (!result) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2400 value = ast2obj_expr(o->v.Exec.body);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2401 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2402 if (PyObject_SetAttrString(result, "body", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2403 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2404 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2405 value = ast2obj_expr(o->v.Exec.globals);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2406 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2407 if (PyObject_SetAttrString(result, "globals", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2408 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2409 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2410 value = ast2obj_expr(o->v.Exec.locals);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2411 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2412 if (PyObject_SetAttrString(result, "locals", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2413 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2414 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2415 break;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2416 case Global_kind:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2417 result = PyType_GenericNew(Global_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2418 if (!result) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2419 value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2420 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2421 if (PyObject_SetAttrString(result, "names", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2422 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2423 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2424 break;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2425 case Expr_kind:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2426 result = PyType_GenericNew(Expr_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2427 if (!result) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2428 value = ast2obj_expr(o->v.Expr.value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2429 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2430 if (PyObject_SetAttrString(result, "value", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2431 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2432 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2433 break;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2434 case Pass_kind:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2435 result = PyType_GenericNew(Pass_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2436 if (!result) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2437 break;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2438 case Break_kind:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2439 result = PyType_GenericNew(Break_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2440 if (!result) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2441 break;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2442 case Continue_kind:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2443 result = PyType_GenericNew(Continue_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2444 if (!result) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2445 break;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2446 }
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
2447 value = ast2obj_int(o->lineno);
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
2448 if (!value) goto failed;
36794
df843b07f5fe Fix memory leak on attributes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36786
diff changeset
2449 if (PyObject_SetAttrString(result, "lineno", value) < 0)
df843b07f5fe Fix memory leak on attributes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36786
diff changeset
2450 goto failed;
df843b07f5fe Fix memory leak on attributes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36786
diff changeset
2451 Py_DECREF(value);
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
2452 value = ast2obj_int(o->col_offset);
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
2453 if (!value) goto failed;
36794
df843b07f5fe Fix memory leak on attributes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36786
diff changeset
2454 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
df843b07f5fe Fix memory leak on attributes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36786
diff changeset
2455 goto failed;
df843b07f5fe Fix memory leak on attributes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36786
diff changeset
2456 Py_DECREF(value);
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2457 return result;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2458 failed:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2459 Py_XDECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2460 Py_XDECREF(result);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2461 return NULL;
35866
9f73dc0953d2 Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents: 35862
diff changeset
2462 }
9f73dc0953d2 Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents: 35862
diff changeset
2463
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2464 PyObject*
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2465 ast2obj_expr(void* _o)
35866
9f73dc0953d2 Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents: 35862
diff changeset
2466 {
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2467 expr_ty o = (expr_ty)_o;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2468 PyObject *result = NULL, *value = NULL;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2469 if (!o) {
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2470 Py_INCREF(Py_None);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2471 return Py_None;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2472 }
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2473
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2474 switch (o->kind) {
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2475 case BoolOp_kind:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2476 result = PyType_GenericNew(BoolOp_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2477 if (!result) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2478 value = ast2obj_boolop(o->v.BoolOp.op);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2479 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2480 if (PyObject_SetAttrString(result, "op", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2481 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2482 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2483 value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2484 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2485 if (PyObject_SetAttrString(result, "values", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2486 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2487 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2488 break;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2489 case BinOp_kind:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2490 result = PyType_GenericNew(BinOp_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2491 if (!result) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2492 value = ast2obj_expr(o->v.BinOp.left);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2493 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2494 if (PyObject_SetAttrString(result, "left", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2495 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2496 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2497 value = ast2obj_operator(o->v.BinOp.op);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2498 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2499 if (PyObject_SetAttrString(result, "op", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2500 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2501 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2502 value = ast2obj_expr(o->v.BinOp.right);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2503 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2504 if (PyObject_SetAttrString(result, "right", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2505 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2506 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2507 break;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2508 case UnaryOp_kind:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2509 result = PyType_GenericNew(UnaryOp_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2510 if (!result) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2511 value = ast2obj_unaryop(o->v.UnaryOp.op);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2512 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2513 if (PyObject_SetAttrString(result, "op", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2514 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2515 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2516 value = ast2obj_expr(o->v.UnaryOp.operand);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2517 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2518 if (PyObject_SetAttrString(result, "operand", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2519 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2520 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2521 break;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2522 case Lambda_kind:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2523 result = PyType_GenericNew(Lambda_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2524 if (!result) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2525 value = ast2obj_arguments(o->v.Lambda.args);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2526 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2527 if (PyObject_SetAttrString(result, "args", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2528 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2529 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2530 value = ast2obj_expr(o->v.Lambda.body);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2531 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2532 if (PyObject_SetAttrString(result, "body", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2533 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2534 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2535 break;
36666
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
2536 case IfExp_kind:
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
2537 result = PyType_GenericNew(IfExp_type, NULL, NULL);
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
2538 if (!result) goto failed;
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
2539 value = ast2obj_expr(o->v.IfExp.test);
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
2540 if (!value) goto failed;
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
2541 if (PyObject_SetAttrString(result, "test", value) == -1)
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
2542 goto failed;
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
2543 Py_DECREF(value);
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
2544 value = ast2obj_expr(o->v.IfExp.body);
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
2545 if (!value) goto failed;
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
2546 if (PyObject_SetAttrString(result, "body", value) == -1)
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
2547 goto failed;
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
2548 Py_DECREF(value);
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
2549 value = ast2obj_expr(o->v.IfExp.orelse);
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
2550 if (!value) goto failed;
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
2551 if (PyObject_SetAttrString(result, "orelse", value) == -1)
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
2552 goto failed;
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
2553 Py_DECREF(value);
6165927431d6 PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents: 36665
diff changeset
2554 break;
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2555 case Dict_kind:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2556 result = PyType_GenericNew(Dict_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2557 if (!result) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2558 value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2559 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2560 if (PyObject_SetAttrString(result, "keys", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2561 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2562 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2563 value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2564 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2565 if (PyObject_SetAttrString(result, "values", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2566 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2567 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2568 break;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2569 case ListComp_kind:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2570 result = PyType_GenericNew(ListComp_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2571 if (!result) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2572 value = ast2obj_expr(o->v.ListComp.elt);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2573 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2574 if (PyObject_SetAttrString(result, "elt", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2575 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2576 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2577 value = ast2obj_list(o->v.ListComp.generators,
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2578 ast2obj_comprehension);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2579 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2580 if (PyObject_SetAttrString(result, "generators", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2581 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2582 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2583 break;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2584 case GeneratorExp_kind:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2585 result = PyType_GenericNew(GeneratorExp_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2586 if (!result) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2587 value = ast2obj_expr(o->v.GeneratorExp.elt);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2588 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2589 if (PyObject_SetAttrString(result, "elt", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2590 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2591 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2592 value = ast2obj_list(o->v.GeneratorExp.generators,
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2593 ast2obj_comprehension);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2594 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2595 if (PyObject_SetAttrString(result, "generators", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2596 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2597 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2598 break;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2599 case Yield_kind:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2600 result = PyType_GenericNew(Yield_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2601 if (!result) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2602 value = ast2obj_expr(o->v.Yield.value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2603 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2604 if (PyObject_SetAttrString(result, "value", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2605 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2606 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2607 break;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2608 case Compare_kind:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2609 result = PyType_GenericNew(Compare_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2610 if (!result) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2611 value = ast2obj_expr(o->v.Compare.left);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2612 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2613 if (PyObject_SetAttrString(result, "left", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2614 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2615 Py_DECREF(value);
36661
710cbdd478a8 Fix iterating over cmpop_ty lists.
Martin v. Löwis <martin@v.loewis.de>
parents: 36660
diff changeset
2616 {
710cbdd478a8 Fix iterating over cmpop_ty lists.
Martin v. Löwis <martin@v.loewis.de>
parents: 36660
diff changeset
2617 int i, n = asdl_seq_LEN(o->v.Compare.ops);
710cbdd478a8 Fix iterating over cmpop_ty lists.
Martin v. Löwis <martin@v.loewis.de>
parents: 36660
diff changeset
2618 value = PyList_New(n);
710cbdd478a8 Fix iterating over cmpop_ty lists.
Martin v. Löwis <martin@v.loewis.de>
parents: 36660
diff changeset
2619 if (!value) goto failed;
710cbdd478a8 Fix iterating over cmpop_ty lists.
Martin v. Löwis <martin@v.loewis.de>
parents: 36660
diff changeset
2620 for(i = 0; i < n; i++)
37685
5e72b0c74100 Introduce asdl_int_seq, to hold cmpop_ty.
Martin v. Löwis <martin@v.loewis.de>
parents: 37601
diff changeset
2621 PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
36661
710cbdd478a8 Fix iterating over cmpop_ty lists.
Martin v. Löwis <martin@v.loewis.de>
parents: 36660
diff changeset
2622 }
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2623 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2624 if (PyObject_SetAttrString(result, "ops", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2625 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2626 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2627 value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2628 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2629 if (PyObject_SetAttrString(result, "comparators", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2630 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2631 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2632 break;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2633 case Call_kind:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2634 result = PyType_GenericNew(Call_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2635 if (!result) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2636 value = ast2obj_expr(o->v.Call.func);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2637 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2638 if (PyObject_SetAttrString(result, "func", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2639 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2640 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2641 value = ast2obj_list(o->v.Call.args, ast2obj_expr);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2642 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2643 if (PyObject_SetAttrString(result, "args", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2644 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2645 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2646 value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2647 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2648 if (PyObject_SetAttrString(result, "keywords", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2649 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2650 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2651 value = ast2obj_expr(o->v.Call.starargs);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2652 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2653 if (PyObject_SetAttrString(result, "starargs", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2654 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2655 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2656 value = ast2obj_expr(o->v.Call.kwargs);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2657 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2658 if (PyObject_SetAttrString(result, "kwargs", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2659 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2660 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2661 break;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2662 case Repr_kind:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2663 result = PyType_GenericNew(Repr_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2664 if (!result) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2665 value = ast2obj_expr(o->v.Repr.value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2666 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2667 if (PyObject_SetAttrString(result, "value", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2668 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2669 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2670 break;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2671 case Num_kind:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2672 result = PyType_GenericNew(Num_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2673 if (!result) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2674 value = ast2obj_object(o->v.Num.n);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2675 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2676 if (PyObject_SetAttrString(result, "n", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2677 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2678 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2679 break;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2680 case Str_kind:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2681 result = PyType_GenericNew(Str_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2682 if (!result) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2683 value = ast2obj_string(o->v.Str.s);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2684 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2685 if (PyObject_SetAttrString(result, "s", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2686 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2687 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2688 break;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2689 case Attribute_kind:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2690 result = PyType_GenericNew(Attribute_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2691 if (!result) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2692 value = ast2obj_expr(o->v.Attribute.value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2693 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2694 if (PyObject_SetAttrString(result, "value", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2695 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2696 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2697 value = ast2obj_identifier(o->v.Attribute.attr);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2698 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2699 if (PyObject_SetAttrString(result, "attr", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2700 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2701 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2702 value = ast2obj_expr_context(o->v.Attribute.ctx);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2703 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2704 if (PyObject_SetAttrString(result, "ctx", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2705 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2706 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2707 break;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2708 case Subscript_kind:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2709 result = PyType_GenericNew(Subscript_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2710 if (!result) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2711 value = ast2obj_expr(o->v.Subscript.value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2712 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2713 if (PyObject_SetAttrString(result, "value", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2714 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2715 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2716 value = ast2obj_slice(o->v.Subscript.slice);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2717 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2718 if (PyObject_SetAttrString(result, "slice", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2719 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2720 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2721 value = ast2obj_expr_context(o->v.Subscript.ctx);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2722 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2723 if (PyObject_SetAttrString(result, "ctx", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2724 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2725 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2726 break;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2727 case Name_kind:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2728 result = PyType_GenericNew(Name_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2729 if (!result) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2730 value = ast2obj_identifier(o->v.Name.id);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2731 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2732 if (PyObject_SetAttrString(result, "id", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2733 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2734 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2735 value = ast2obj_expr_context(o->v.Name.ctx);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2736 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2737 if (PyObject_SetAttrString(result, "ctx", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2738 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2739 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2740 break;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2741 case List_kind:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2742 result = PyType_GenericNew(List_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2743 if (!result) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2744 value = ast2obj_list(o->v.List.elts, ast2obj_expr);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2745 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2746 if (PyObject_SetAttrString(result, "elts", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2747 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2748 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2749 value = ast2obj_expr_context(o->v.List.ctx);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2750 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2751 if (PyObject_SetAttrString(result, "ctx", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2752 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2753 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2754 break;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2755 case Tuple_kind:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2756 result = PyType_GenericNew(Tuple_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2757 if (!result) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2758 value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2759 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2760 if (PyObject_SetAttrString(result, "elts", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2761 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2762 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2763 value = ast2obj_expr_context(o->v.Tuple.ctx);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2764 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2765 if (PyObject_SetAttrString(result, "ctx", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2766 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2767 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2768 break;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2769 }
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
2770 value = ast2obj_int(o->lineno);
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
2771 if (!value) goto failed;
36794
df843b07f5fe Fix memory leak on attributes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36786
diff changeset
2772 if (PyObject_SetAttrString(result, "lineno", value) < 0)
df843b07f5fe Fix memory leak on attributes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36786
diff changeset
2773 goto failed;
df843b07f5fe Fix memory leak on attributes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36786
diff changeset
2774 Py_DECREF(value);
36786
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
2775 value = ast2obj_int(o->col_offset);
57322cb2ca11 Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36743
diff changeset
2776 if (!value) goto failed;
36794
df843b07f5fe Fix memory leak on attributes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36786
diff changeset
2777 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
df843b07f5fe Fix memory leak on attributes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36786
diff changeset
2778 goto failed;
df843b07f5fe Fix memory leak on attributes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36786
diff changeset
2779 Py_DECREF(value);
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2780 return result;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2781 failed:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2782 Py_XDECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2783 Py_XDECREF(result);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2784 return NULL;
35866
9f73dc0953d2 Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents: 35862
diff changeset
2785 }
9f73dc0953d2 Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents: 35862
diff changeset
2786
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2787 PyObject* ast2obj_expr_context(expr_context_ty o)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2788 {
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2789 switch(o) {
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2790 case Load:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2791 Py_INCREF(Load_singleton);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2792 return Load_singleton;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2793 case Store:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2794 Py_INCREF(Store_singleton);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2795 return Store_singleton;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2796 case Del:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2797 Py_INCREF(Del_singleton);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2798 return Del_singleton;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2799 case AugLoad:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2800 Py_INCREF(AugLoad_singleton);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2801 return AugLoad_singleton;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2802 case AugStore:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2803 Py_INCREF(AugStore_singleton);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2804 return AugStore_singleton;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2805 case Param:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2806 Py_INCREF(Param_singleton);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2807 return Param_singleton;
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
2808 default:
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
2809 /* should never happen, but just in case ... */
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
2810 PyErr_Format(PyExc_SystemError, "unknown expr_context found");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
2811 return NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
2812 }
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2813 }
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2814 PyObject*
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2815 ast2obj_slice(void* _o)
35866
9f73dc0953d2 Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents: 35862
diff changeset
2816 {
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2817 slice_ty o = (slice_ty)_o;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2818 PyObject *result = NULL, *value = NULL;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2819 if (!o) {
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2820 Py_INCREF(Py_None);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2821 return Py_None;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2822 }
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2823
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2824 switch (o->kind) {
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2825 case Ellipsis_kind:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2826 result = PyType_GenericNew(Ellipsis_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2827 if (!result) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2828 break;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2829 case Slice_kind:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2830 result = PyType_GenericNew(Slice_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2831 if (!result) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2832 value = ast2obj_expr(o->v.Slice.lower);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2833 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2834 if (PyObject_SetAttrString(result, "lower", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2835 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2836 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2837 value = ast2obj_expr(o->v.Slice.upper);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2838 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2839 if (PyObject_SetAttrString(result, "upper", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2840 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2841 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2842 value = ast2obj_expr(o->v.Slice.step);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2843 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2844 if (PyObject_SetAttrString(result, "step", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2845 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2846 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2847 break;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2848 case ExtSlice_kind:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2849 result = PyType_GenericNew(ExtSlice_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2850 if (!result) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2851 value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2852 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2853 if (PyObject_SetAttrString(result, "dims", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2854 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2855 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2856 break;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2857 case Index_kind:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2858 result = PyType_GenericNew(Index_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2859 if (!result) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2860 value = ast2obj_expr(o->v.Index.value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2861 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2862 if (PyObject_SetAttrString(result, "value", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2863 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2864 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2865 break;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2866 }
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2867 return result;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2868 failed:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2869 Py_XDECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2870 Py_XDECREF(result);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2871 return NULL;
35866
9f73dc0953d2 Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents: 35862
diff changeset
2872 }
9f73dc0953d2 Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents: 35862
diff changeset
2873
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2874 PyObject* ast2obj_boolop(boolop_ty o)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2875 {
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2876 switch(o) {
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2877 case And:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2878 Py_INCREF(And_singleton);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2879 return And_singleton;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2880 case Or:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2881 Py_INCREF(Or_singleton);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2882 return Or_singleton;
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
2883 default:
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
2884 /* should never happen, but just in case ... */
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
2885 PyErr_Format(PyExc_SystemError, "unknown boolop found");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
2886 return NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
2887 }
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2888 }
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2889 PyObject* ast2obj_operator(operator_ty o)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2890 {
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2891 switch(o) {
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2892 case Add:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2893 Py_INCREF(Add_singleton);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2894 return Add_singleton;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2895 case Sub:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2896 Py_INCREF(Sub_singleton);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2897 return Sub_singleton;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2898 case Mult:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2899 Py_INCREF(Mult_singleton);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2900 return Mult_singleton;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2901 case Div:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2902 Py_INCREF(Div_singleton);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2903 return Div_singleton;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2904 case Mod:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2905 Py_INCREF(Mod_singleton);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2906 return Mod_singleton;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2907 case Pow:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2908 Py_INCREF(Pow_singleton);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2909 return Pow_singleton;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2910 case LShift:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2911 Py_INCREF(LShift_singleton);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2912 return LShift_singleton;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2913 case RShift:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2914 Py_INCREF(RShift_singleton);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2915 return RShift_singleton;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2916 case BitOr:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2917 Py_INCREF(BitOr_singleton);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2918 return BitOr_singleton;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2919 case BitXor:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2920 Py_INCREF(BitXor_singleton);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2921 return BitXor_singleton;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2922 case BitAnd:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2923 Py_INCREF(BitAnd_singleton);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2924 return BitAnd_singleton;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2925 case FloorDiv:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2926 Py_INCREF(FloorDiv_singleton);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2927 return FloorDiv_singleton;
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
2928 default:
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
2929 /* should never happen, but just in case ... */
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
2930 PyErr_Format(PyExc_SystemError, "unknown operator found");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
2931 return NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
2932 }
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2933 }
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2934 PyObject* ast2obj_unaryop(unaryop_ty o)
35866
9f73dc0953d2 Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents: 35862
diff changeset
2935 {
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2936 switch(o) {
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2937 case Invert:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2938 Py_INCREF(Invert_singleton);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2939 return Invert_singleton;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2940 case Not:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2941 Py_INCREF(Not_singleton);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2942 return Not_singleton;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2943 case UAdd:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2944 Py_INCREF(UAdd_singleton);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2945 return UAdd_singleton;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2946 case USub:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2947 Py_INCREF(USub_singleton);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2948 return USub_singleton;
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
2949 default:
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
2950 /* should never happen, but just in case ... */
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
2951 PyErr_Format(PyExc_SystemError, "unknown unaryop found");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
2952 return NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
2953 }
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2954 }
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2955 PyObject* ast2obj_cmpop(cmpop_ty o)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2956 {
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2957 switch(o) {
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2958 case Eq:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2959 Py_INCREF(Eq_singleton);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2960 return Eq_singleton;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2961 case NotEq:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2962 Py_INCREF(NotEq_singleton);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2963 return NotEq_singleton;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2964 case Lt:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2965 Py_INCREF(Lt_singleton);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2966 return Lt_singleton;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2967 case LtE:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2968 Py_INCREF(LtE_singleton);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2969 return LtE_singleton;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2970 case Gt:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2971 Py_INCREF(Gt_singleton);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2972 return Gt_singleton;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2973 case GtE:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2974 Py_INCREF(GtE_singleton);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2975 return GtE_singleton;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2976 case Is:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2977 Py_INCREF(Is_singleton);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2978 return Is_singleton;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2979 case IsNot:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2980 Py_INCREF(IsNot_singleton);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2981 return IsNot_singleton;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2982 case In:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2983 Py_INCREF(In_singleton);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2984 return In_singleton;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2985 case NotIn:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2986 Py_INCREF(NotIn_singleton);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2987 return NotIn_singleton;
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
2988 default:
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
2989 /* should never happen, but just in case ... */
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
2990 PyErr_Format(PyExc_SystemError, "unknown cmpop found");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
2991 return NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
2992 }
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2993 }
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2994 PyObject*
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2995 ast2obj_comprehension(void* _o)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2996 {
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2997 comprehension_ty o = (comprehension_ty)_o;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2998 PyObject *result = NULL, *value = NULL;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
2999 if (!o) {
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3000 Py_INCREF(Py_None);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3001 return Py_None;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3002 }
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3003
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3004 result = PyType_GenericNew(comprehension_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3005 if (!result) return NULL;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3006 value = ast2obj_expr(o->target);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3007 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3008 if (PyObject_SetAttrString(result, "target", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3009 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3010 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3011 value = ast2obj_expr(o->iter);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3012 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3013 if (PyObject_SetAttrString(result, "iter", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3014 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3015 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3016 value = ast2obj_list(o->ifs, ast2obj_expr);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3017 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3018 if (PyObject_SetAttrString(result, "ifs", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3019 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3020 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3021 return result;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3022 failed:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3023 Py_XDECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3024 Py_XDECREF(result);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3025 return NULL;
35866
9f73dc0953d2 Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents: 35862
diff changeset
3026 }
9f73dc0953d2 Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents: 35862
diff changeset
3027
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3028 PyObject*
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3029 ast2obj_excepthandler(void* _o)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3030 {
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3031 excepthandler_ty o = (excepthandler_ty)_o;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3032 PyObject *result = NULL, *value = NULL;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3033 if (!o) {
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3034 Py_INCREF(Py_None);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3035 return Py_None;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3036 }
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3037
46200
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
3038 switch (o->kind) {
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
3039 case ExceptHandler_kind:
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
3040 result = PyType_GenericNew(ExceptHandler_type, NULL, NULL);
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
3041 if (!result) goto failed;
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
3042 value = ast2obj_expr(o->v.ExceptHandler.type);
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
3043 if (!value) goto failed;
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
3044 if (PyObject_SetAttrString(result, "type", value) == -1)
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
3045 goto failed;
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
3046 Py_DECREF(value);
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
3047 value = ast2obj_expr(o->v.ExceptHandler.name);
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
3048 if (!value) goto failed;
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
3049 if (PyObject_SetAttrString(result, "name", value) == -1)
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
3050 goto failed;
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
3051 Py_DECREF(value);
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
3052 value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt);
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
3053 if (!value) goto failed;
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
3054 if (PyObject_SetAttrString(result, "body", value) == -1)
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
3055 goto failed;
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
3056 Py_DECREF(value);
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
3057 break;
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
3058 }
37453
16a64e394602 Add lineno, col_offset to excephandler to enable future fix for
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 37412
diff changeset
3059 value = ast2obj_int(o->lineno);
16a64e394602 Add lineno, col_offset to excephandler to enable future fix for
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 37412
diff changeset
3060 if (!value) goto failed;
46200
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
3061 if (PyObject_SetAttrString(result, "lineno", value) < 0)
37453
16a64e394602 Add lineno, col_offset to excephandler to enable future fix for
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 37412
diff changeset
3062 goto failed;
16a64e394602 Add lineno, col_offset to excephandler to enable future fix for
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 37412
diff changeset
3063 Py_DECREF(value);
16a64e394602 Add lineno, col_offset to excephandler to enable future fix for
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 37412
diff changeset
3064 value = ast2obj_int(o->col_offset);
16a64e394602 Add lineno, col_offset to excephandler to enable future fix for
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 37412
diff changeset
3065 if (!value) goto failed;
46200
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
3066 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
37453
16a64e394602 Add lineno, col_offset to excephandler to enable future fix for
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 37412
diff changeset
3067 goto failed;
16a64e394602 Add lineno, col_offset to excephandler to enable future fix for
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 37412
diff changeset
3068 Py_DECREF(value);
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3069 return result;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3070 failed:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3071 Py_XDECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3072 Py_XDECREF(result);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3073 return NULL;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3074 }
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3075
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3076 PyObject*
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3077 ast2obj_arguments(void* _o)
35866
9f73dc0953d2 Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents: 35862
diff changeset
3078 {
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3079 arguments_ty o = (arguments_ty)_o;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3080 PyObject *result = NULL, *value = NULL;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3081 if (!o) {
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3082 Py_INCREF(Py_None);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3083 return Py_None;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3084 }
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3085
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3086 result = PyType_GenericNew(arguments_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3087 if (!result) return NULL;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3088 value = ast2obj_list(o->args, ast2obj_expr);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3089 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3090 if (PyObject_SetAttrString(result, "args", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3091 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3092 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3093 value = ast2obj_identifier(o->vararg);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3094 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3095 if (PyObject_SetAttrString(result, "vararg", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3096 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3097 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3098 value = ast2obj_identifier(o->kwarg);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3099 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3100 if (PyObject_SetAttrString(result, "kwarg", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3101 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3102 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3103 value = ast2obj_list(o->defaults, ast2obj_expr);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3104 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3105 if (PyObject_SetAttrString(result, "defaults", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3106 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3107 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3108 return result;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3109 failed:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3110 Py_XDECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3111 Py_XDECREF(result);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3112 return NULL;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3113 }
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3114
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3115 PyObject*
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3116 ast2obj_keyword(void* _o)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3117 {
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3118 keyword_ty o = (keyword_ty)_o;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3119 PyObject *result = NULL, *value = NULL;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3120 if (!o) {
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3121 Py_INCREF(Py_None);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3122 return Py_None;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3123 }
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3124
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3125 result = PyType_GenericNew(keyword_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3126 if (!result) return NULL;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3127 value = ast2obj_identifier(o->arg);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3128 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3129 if (PyObject_SetAttrString(result, "arg", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3130 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3131 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3132 value = ast2obj_expr(o->value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3133 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3134 if (PyObject_SetAttrString(result, "value", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3135 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3136 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3137 return result;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3138 failed:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3139 Py_XDECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3140 Py_XDECREF(result);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3141 return NULL;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3142 }
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3143
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3144 PyObject*
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3145 ast2obj_alias(void* _o)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3146 {
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3147 alias_ty o = (alias_ty)_o;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3148 PyObject *result = NULL, *value = NULL;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3149 if (!o) {
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3150 Py_INCREF(Py_None);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3151 return Py_None;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3152 }
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3153
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3154 result = PyType_GenericNew(alias_type, NULL, NULL);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3155 if (!result) return NULL;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3156 value = ast2obj_identifier(o->name);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3157 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3158 if (PyObject_SetAttrString(result, "name", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3159 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3160 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3161 value = ast2obj_identifier(o->asname);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3162 if (!value) goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3163 if (PyObject_SetAttrString(result, "asname", value) == -1)
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3164 goto failed;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3165 Py_DECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3166 return result;
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3167 failed:
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3168 Py_XDECREF(value);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3169 Py_XDECREF(result);
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
3170 return NULL;
35866
9f73dc0953d2 Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents: 35862
diff changeset
3171 }
9f73dc0953d2 Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents: 35862
diff changeset
3172
9f73dc0953d2 Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents: 35862
diff changeset
3173
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3174 int
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3175 obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena)
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3176 {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3177 PyObject* tmp = NULL;
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3178 int isinstance;
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3179
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3180
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3181 if (obj == Py_None) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3182 *out = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3183 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3184 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3185 isinstance = PyObject_IsInstance(obj, (PyObject*)Module_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3186 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3187 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3188 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3189 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3190 asdl_seq* body;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3191
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3192 if (PyObject_HasAttrString(obj, "body")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3193 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3194 Py_ssize_t len;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3195 Py_ssize_t i;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3196 tmp = PyObject_GetAttrString(obj, "body");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3197 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3198 if (!PyList_Check(tmp)) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3199 PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3200 goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3201 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3202 len = PyList_GET_SIZE(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3203 body = asdl_seq_new(len, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3204 if (body == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3205 for (i = 0; i < len; i++) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3206 stmt_ty value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3207 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3208 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3209 asdl_seq_SET(body, i, value);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3210 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3211 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3212 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3213 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3214 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3215 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3216 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3217 *out = Module(body, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3218 if (*out == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3219 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3220 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3221 isinstance = PyObject_IsInstance(obj, (PyObject*)Interactive_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3222 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3223 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3224 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3225 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3226 asdl_seq* body;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3227
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3228 if (PyObject_HasAttrString(obj, "body")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3229 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3230 Py_ssize_t len;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3231 Py_ssize_t i;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3232 tmp = PyObject_GetAttrString(obj, "body");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3233 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3234 if (!PyList_Check(tmp)) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3235 PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3236 goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3237 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3238 len = PyList_GET_SIZE(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3239 body = asdl_seq_new(len, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3240 if (body == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3241 for (i = 0; i < len; i++) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3242 stmt_ty value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3243 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3244 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3245 asdl_seq_SET(body, i, value);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3246 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3247 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3248 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3249 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3250 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3251 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3252 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3253 *out = Interactive(body, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3254 if (*out == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3255 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3256 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3257 isinstance = PyObject_IsInstance(obj, (PyObject*)Expression_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3258 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3259 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3260 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3261 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3262 expr_ty body;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3263
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3264 if (PyObject_HasAttrString(obj, "body")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3265 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3266 tmp = PyObject_GetAttrString(obj, "body");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3267 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3268 res = obj2ast_expr(tmp, &body, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3269 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3270 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3271 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3272 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3273 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3274 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3275 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3276 *out = Expression(body, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3277 if (*out == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3278 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3279 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3280 isinstance = PyObject_IsInstance(obj, (PyObject*)Suite_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3281 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3282 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3283 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3284 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3285 asdl_seq* body;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3286
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3287 if (PyObject_HasAttrString(obj, "body")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3288 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3289 Py_ssize_t len;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3290 Py_ssize_t i;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3291 tmp = PyObject_GetAttrString(obj, "body");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3292 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3293 if (!PyList_Check(tmp)) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3294 PyErr_Format(PyExc_TypeError, "Suite field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3295 goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3296 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3297 len = PyList_GET_SIZE(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3298 body = asdl_seq_new(len, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3299 if (body == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3300 for (i = 0; i < len; i++) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3301 stmt_ty value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3302 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3303 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3304 asdl_seq_SET(body, i, value);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3305 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3306 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3307 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3308 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3309 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Suite");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3310 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3311 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3312 *out = Suite(body, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3313 if (*out == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3314 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3315 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3316
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3317 tmp = PyObject_Repr(obj);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3318 if (tmp == NULL) goto failed;
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
3319 PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %.400s", PyString_AS_STRING(tmp));
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3320 failed:
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3321 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3322 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3323 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3324
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3325 int
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3326 obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3327 {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3328 PyObject* tmp = NULL;
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3329 int isinstance;
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3330
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3331 int lineno;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3332 int col_offset;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3333
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3334 if (obj == Py_None) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3335 *out = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3336 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3337 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3338 if (PyObject_HasAttrString(obj, "lineno")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3339 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3340 tmp = PyObject_GetAttrString(obj, "lineno");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3341 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3342 res = obj2ast_int(tmp, &lineno, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3343 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3344 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3345 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3346 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3347 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3348 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3349 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3350 if (PyObject_HasAttrString(obj, "col_offset")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3351 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3352 tmp = PyObject_GetAttrString(obj, "col_offset");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3353 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3354 res = obj2ast_int(tmp, &col_offset, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3355 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3356 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3357 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3358 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3359 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3360 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3361 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3362 isinstance = PyObject_IsInstance(obj, (PyObject*)FunctionDef_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3363 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3364 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3365 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3366 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3367 identifier name;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3368 arguments_ty args;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3369 asdl_seq* body;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3370 asdl_seq* decorator_list;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3371
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3372 if (PyObject_HasAttrString(obj, "name")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3373 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3374 tmp = PyObject_GetAttrString(obj, "name");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3375 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3376 res = obj2ast_identifier(tmp, &name, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3377 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3378 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3379 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3380 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3381 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3382 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3383 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3384 if (PyObject_HasAttrString(obj, "args")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3385 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3386 tmp = PyObject_GetAttrString(obj, "args");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3387 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3388 res = obj2ast_arguments(tmp, &args, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3389 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3390 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3391 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3392 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3393 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3394 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3395 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3396 if (PyObject_HasAttrString(obj, "body")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3397 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3398 Py_ssize_t len;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3399 Py_ssize_t i;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3400 tmp = PyObject_GetAttrString(obj, "body");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3401 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3402 if (!PyList_Check(tmp)) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3403 PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3404 goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3405 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3406 len = PyList_GET_SIZE(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3407 body = asdl_seq_new(len, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3408 if (body == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3409 for (i = 0; i < len; i++) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3410 stmt_ty value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3411 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3412 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3413 asdl_seq_SET(body, i, value);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3414 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3415 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3416 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3417 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3418 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3419 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3420 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3421 if (PyObject_HasAttrString(obj, "decorator_list")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3422 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3423 Py_ssize_t len;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3424 Py_ssize_t i;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3425 tmp = PyObject_GetAttrString(obj, "decorator_list");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3426 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3427 if (!PyList_Check(tmp)) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3428 PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3429 goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3430 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3431 len = PyList_GET_SIZE(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3432 decorator_list = asdl_seq_new(len, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3433 if (decorator_list == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3434 for (i = 0; i < len; i++) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3435 expr_ty value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3436 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3437 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3438 asdl_seq_SET(decorator_list, i, value);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3439 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3440 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3441 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3442 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3443 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3444 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3445 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3446 *out = FunctionDef(name, args, body, decorator_list, lineno,
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3447 col_offset, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3448 if (*out == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3449 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3450 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3451 isinstance = PyObject_IsInstance(obj, (PyObject*)ClassDef_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3452 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3453 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3454 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3455 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3456 identifier name;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3457 asdl_seq* bases;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3458 asdl_seq* body;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3459 asdl_seq* decorator_list;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3460
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3461 if (PyObject_HasAttrString(obj, "name")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3462 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3463 tmp = PyObject_GetAttrString(obj, "name");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3464 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3465 res = obj2ast_identifier(tmp, &name, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3466 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3467 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3468 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3469 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3470 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3471 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3472 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3473 if (PyObject_HasAttrString(obj, "bases")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3474 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3475 Py_ssize_t len;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3476 Py_ssize_t i;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3477 tmp = PyObject_GetAttrString(obj, "bases");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3478 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3479 if (!PyList_Check(tmp)) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3480 PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", tmp->ob_type->tp_name);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3481 goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3482 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3483 len = PyList_GET_SIZE(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3484 bases = asdl_seq_new(len, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3485 if (bases == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3486 for (i = 0; i < len; i++) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3487 expr_ty value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3488 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3489 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3490 asdl_seq_SET(bases, i, value);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3491 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3492 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3493 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3494 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3495 PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3496 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3497 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3498 if (PyObject_HasAttrString(obj, "body")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3499 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3500 Py_ssize_t len;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3501 Py_ssize_t i;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3502 tmp = PyObject_GetAttrString(obj, "body");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3503 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3504 if (!PyList_Check(tmp)) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3505 PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3506 goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3507 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3508 len = PyList_GET_SIZE(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3509 body = asdl_seq_new(len, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3510 if (body == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3511 for (i = 0; i < len; i++) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3512 stmt_ty value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3513 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3514 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3515 asdl_seq_SET(body, i, value);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3516 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3517 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3518 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3519 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3520 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3521 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3522 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3523 if (PyObject_HasAttrString(obj, "decorator_list")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3524 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3525 Py_ssize_t len;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3526 Py_ssize_t i;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3527 tmp = PyObject_GetAttrString(obj, "decorator_list");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3528 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3529 if (!PyList_Check(tmp)) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3530 PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3531 goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3532 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3533 len = PyList_GET_SIZE(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3534 decorator_list = asdl_seq_new(len, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3535 if (decorator_list == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3536 for (i = 0; i < len; i++) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3537 expr_ty value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3538 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3539 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3540 asdl_seq_SET(decorator_list, i, value);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3541 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3542 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3543 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3544 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3545 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3546 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3547 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3548 *out = ClassDef(name, bases, body, decorator_list, lineno,
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3549 col_offset, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3550 if (*out == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3551 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3552 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3553 isinstance = PyObject_IsInstance(obj, (PyObject*)Return_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3554 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3555 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3556 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3557 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3558 expr_ty value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3559
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3560 if (PyObject_HasAttrString(obj, "value")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3561 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3562 tmp = PyObject_GetAttrString(obj, "value");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3563 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3564 res = obj2ast_expr(tmp, &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3565 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3566 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3567 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3568 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3569 value = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3570 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3571 *out = Return(value, lineno, col_offset, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3572 if (*out == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3573 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3574 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3575 isinstance = PyObject_IsInstance(obj, (PyObject*)Delete_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3576 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3577 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3578 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3579 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3580 asdl_seq* targets;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3581
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3582 if (PyObject_HasAttrString(obj, "targets")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3583 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3584 Py_ssize_t len;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3585 Py_ssize_t i;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3586 tmp = PyObject_GetAttrString(obj, "targets");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3587 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3588 if (!PyList_Check(tmp)) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3589 PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3590 goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3591 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3592 len = PyList_GET_SIZE(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3593 targets = asdl_seq_new(len, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3594 if (targets == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3595 for (i = 0; i < len; i++) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3596 expr_ty value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3597 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3598 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3599 asdl_seq_SET(targets, i, value);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3600 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3601 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3602 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3603 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3604 PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3605 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3606 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3607 *out = Delete(targets, lineno, col_offset, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3608 if (*out == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3609 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3610 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3611 isinstance = PyObject_IsInstance(obj, (PyObject*)Assign_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3612 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3613 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3614 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3615 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3616 asdl_seq* targets;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3617 expr_ty value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3618
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3619 if (PyObject_HasAttrString(obj, "targets")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3620 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3621 Py_ssize_t len;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3622 Py_ssize_t i;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3623 tmp = PyObject_GetAttrString(obj, "targets");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3624 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3625 if (!PyList_Check(tmp)) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3626 PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3627 goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3628 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3629 len = PyList_GET_SIZE(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3630 targets = asdl_seq_new(len, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3631 if (targets == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3632 for (i = 0; i < len; i++) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3633 expr_ty value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3634 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3635 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3636 asdl_seq_SET(targets, i, value);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3637 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3638 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3639 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3640 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3641 PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3642 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3643 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3644 if (PyObject_HasAttrString(obj, "value")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3645 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3646 tmp = PyObject_GetAttrString(obj, "value");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3647 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3648 res = obj2ast_expr(tmp, &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3649 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3650 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3651 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3652 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3653 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3654 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3655 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3656 *out = Assign(targets, value, lineno, col_offset, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3657 if (*out == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3658 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3659 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3660 isinstance = PyObject_IsInstance(obj, (PyObject*)AugAssign_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3661 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3662 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3663 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3664 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3665 expr_ty target;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3666 operator_ty op;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3667 expr_ty value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3668
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3669 if (PyObject_HasAttrString(obj, "target")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3670 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3671 tmp = PyObject_GetAttrString(obj, "target");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3672 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3673 res = obj2ast_expr(tmp, &target, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3674 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3675 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3676 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3677 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3678 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3679 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3680 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3681 if (PyObject_HasAttrString(obj, "op")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3682 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3683 tmp = PyObject_GetAttrString(obj, "op");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3684 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3685 res = obj2ast_operator(tmp, &op, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3686 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3687 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3688 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3689 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3690 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3691 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3692 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3693 if (PyObject_HasAttrString(obj, "value")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3694 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3695 tmp = PyObject_GetAttrString(obj, "value");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3696 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3697 res = obj2ast_expr(tmp, &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3698 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3699 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3700 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3701 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3702 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3703 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3704 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3705 *out = AugAssign(target, op, value, lineno, col_offset, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3706 if (*out == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3707 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3708 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3709 isinstance = PyObject_IsInstance(obj, (PyObject*)Print_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3710 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3711 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3712 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3713 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3714 expr_ty dest;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3715 asdl_seq* values;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3716 bool nl;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3717
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3718 if (PyObject_HasAttrString(obj, "dest")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3719 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3720 tmp = PyObject_GetAttrString(obj, "dest");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3721 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3722 res = obj2ast_expr(tmp, &dest, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3723 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3724 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3725 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3726 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3727 dest = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3728 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3729 if (PyObject_HasAttrString(obj, "values")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3730 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3731 Py_ssize_t len;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3732 Py_ssize_t i;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3733 tmp = PyObject_GetAttrString(obj, "values");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3734 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3735 if (!PyList_Check(tmp)) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3736 PyErr_Format(PyExc_TypeError, "Print field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3737 goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3738 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3739 len = PyList_GET_SIZE(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3740 values = asdl_seq_new(len, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3741 if (values == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3742 for (i = 0; i < len; i++) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3743 expr_ty value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3744 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3745 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3746 asdl_seq_SET(values, i, value);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3747 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3748 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3749 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3750 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3751 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Print");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3752 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3753 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3754 if (PyObject_HasAttrString(obj, "nl")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3755 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3756 tmp = PyObject_GetAttrString(obj, "nl");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3757 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3758 res = obj2ast_bool(tmp, &nl, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3759 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3760 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3761 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3762 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3763 PyErr_SetString(PyExc_TypeError, "required field \"nl\" missing from Print");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3764 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3765 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3766 *out = Print(dest, values, nl, lineno, col_offset, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3767 if (*out == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3768 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3769 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3770 isinstance = PyObject_IsInstance(obj, (PyObject*)For_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3771 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3772 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3773 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3774 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3775 expr_ty target;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3776 expr_ty iter;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3777 asdl_seq* body;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3778 asdl_seq* orelse;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3779
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3780 if (PyObject_HasAttrString(obj, "target")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3781 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3782 tmp = PyObject_GetAttrString(obj, "target");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3783 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3784 res = obj2ast_expr(tmp, &target, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3785 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3786 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3787 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3788 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3789 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3790 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3791 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3792 if (PyObject_HasAttrString(obj, "iter")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3793 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3794 tmp = PyObject_GetAttrString(obj, "iter");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3795 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3796 res = obj2ast_expr(tmp, &iter, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3797 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3798 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3799 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3800 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3801 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3802 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3803 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3804 if (PyObject_HasAttrString(obj, "body")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3805 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3806 Py_ssize_t len;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3807 Py_ssize_t i;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3808 tmp = PyObject_GetAttrString(obj, "body");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3809 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3810 if (!PyList_Check(tmp)) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3811 PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3812 goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3813 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3814 len = PyList_GET_SIZE(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3815 body = asdl_seq_new(len, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3816 if (body == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3817 for (i = 0; i < len; i++) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3818 stmt_ty value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3819 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3820 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3821 asdl_seq_SET(body, i, value);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3822 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3823 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3824 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3825 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3826 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3827 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3828 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3829 if (PyObject_HasAttrString(obj, "orelse")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3830 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3831 Py_ssize_t len;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3832 Py_ssize_t i;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3833 tmp = PyObject_GetAttrString(obj, "orelse");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3834 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3835 if (!PyList_Check(tmp)) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3836 PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3837 goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3838 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3839 len = PyList_GET_SIZE(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3840 orelse = asdl_seq_new(len, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3841 if (orelse == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3842 for (i = 0; i < len; i++) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3843 stmt_ty value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3844 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3845 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3846 asdl_seq_SET(orelse, i, value);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3847 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3848 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3849 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3850 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3851 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3852 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3853 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3854 *out = For(target, iter, body, orelse, lineno, col_offset,
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3855 arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3856 if (*out == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3857 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3858 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3859 isinstance = PyObject_IsInstance(obj, (PyObject*)While_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3860 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3861 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3862 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3863 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3864 expr_ty test;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3865 asdl_seq* body;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3866 asdl_seq* orelse;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3867
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3868 if (PyObject_HasAttrString(obj, "test")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3869 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3870 tmp = PyObject_GetAttrString(obj, "test");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3871 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3872 res = obj2ast_expr(tmp, &test, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3873 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3874 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3875 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3876 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3877 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3878 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3879 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3880 if (PyObject_HasAttrString(obj, "body")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3881 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3882 Py_ssize_t len;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3883 Py_ssize_t i;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3884 tmp = PyObject_GetAttrString(obj, "body");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3885 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3886 if (!PyList_Check(tmp)) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3887 PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3888 goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3889 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3890 len = PyList_GET_SIZE(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3891 body = asdl_seq_new(len, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3892 if (body == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3893 for (i = 0; i < len; i++) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3894 stmt_ty value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3895 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3896 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3897 asdl_seq_SET(body, i, value);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3898 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3899 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3900 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3901 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3902 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3903 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3904 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3905 if (PyObject_HasAttrString(obj, "orelse")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3906 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3907 Py_ssize_t len;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3908 Py_ssize_t i;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3909 tmp = PyObject_GetAttrString(obj, "orelse");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3910 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3911 if (!PyList_Check(tmp)) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3912 PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3913 goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3914 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3915 len = PyList_GET_SIZE(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3916 orelse = asdl_seq_new(len, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3917 if (orelse == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3918 for (i = 0; i < len; i++) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3919 stmt_ty value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3920 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3921 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3922 asdl_seq_SET(orelse, i, value);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3923 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3924 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3925 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3926 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3927 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3928 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3929 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3930 *out = While(test, body, orelse, lineno, col_offset, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3931 if (*out == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3932 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3933 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3934 isinstance = PyObject_IsInstance(obj, (PyObject*)If_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3935 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3936 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3937 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
3938 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3939 expr_ty test;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3940 asdl_seq* body;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3941 asdl_seq* orelse;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3942
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3943 if (PyObject_HasAttrString(obj, "test")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3944 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3945 tmp = PyObject_GetAttrString(obj, "test");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3946 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3947 res = obj2ast_expr(tmp, &test, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3948 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3949 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3950 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3951 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3952 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3953 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3954 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3955 if (PyObject_HasAttrString(obj, "body")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3956 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3957 Py_ssize_t len;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3958 Py_ssize_t i;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3959 tmp = PyObject_GetAttrString(obj, "body");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3960 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3961 if (!PyList_Check(tmp)) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3962 PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3963 goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3964 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3965 len = PyList_GET_SIZE(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3966 body = asdl_seq_new(len, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3967 if (body == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3968 for (i = 0; i < len; i++) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3969 stmt_ty value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3970 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3971 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3972 asdl_seq_SET(body, i, value);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3973 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3974 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3975 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3976 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3977 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3978 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3979 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3980 if (PyObject_HasAttrString(obj, "orelse")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3981 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3982 Py_ssize_t len;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3983 Py_ssize_t i;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3984 tmp = PyObject_GetAttrString(obj, "orelse");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3985 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3986 if (!PyList_Check(tmp)) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3987 PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3988 goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3989 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3990 len = PyList_GET_SIZE(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3991 orelse = asdl_seq_new(len, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3992 if (orelse == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3993 for (i = 0; i < len; i++) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3994 stmt_ty value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3995 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3996 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3997 asdl_seq_SET(orelse, i, value);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3998 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
3999 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4000 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4001 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4002 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4003 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4004 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4005 *out = If(test, body, orelse, lineno, col_offset, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4006 if (*out == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4007 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4008 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4009 isinstance = PyObject_IsInstance(obj, (PyObject*)With_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4010 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4011 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4012 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4013 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4014 expr_ty context_expr;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4015 expr_ty optional_vars;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4016 asdl_seq* body;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4017
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4018 if (PyObject_HasAttrString(obj, "context_expr")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4019 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4020 tmp = PyObject_GetAttrString(obj, "context_expr");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4021 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4022 res = obj2ast_expr(tmp, &context_expr, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4023 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4024 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4025 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4026 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4027 PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from With");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4028 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4029 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4030 if (PyObject_HasAttrString(obj, "optional_vars")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4031 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4032 tmp = PyObject_GetAttrString(obj, "optional_vars");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4033 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4034 res = obj2ast_expr(tmp, &optional_vars, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4035 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4036 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4037 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4038 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4039 optional_vars = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4040 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4041 if (PyObject_HasAttrString(obj, "body")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4042 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4043 Py_ssize_t len;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4044 Py_ssize_t i;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4045 tmp = PyObject_GetAttrString(obj, "body");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4046 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4047 if (!PyList_Check(tmp)) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4048 PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4049 goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4050 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4051 len = PyList_GET_SIZE(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4052 body = asdl_seq_new(len, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4053 if (body == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4054 for (i = 0; i < len; i++) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4055 stmt_ty value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4056 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4057 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4058 asdl_seq_SET(body, i, value);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4059 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4060 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4061 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4062 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4063 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4064 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4065 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4066 *out = With(context_expr, optional_vars, body, lineno,
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4067 col_offset, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4068 if (*out == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4069 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4070 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4071 isinstance = PyObject_IsInstance(obj, (PyObject*)Raise_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4072 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4073 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4074 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4075 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4076 expr_ty type;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4077 expr_ty inst;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4078 expr_ty tback;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4079
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4080 if (PyObject_HasAttrString(obj, "type")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4081 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4082 tmp = PyObject_GetAttrString(obj, "type");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4083 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4084 res = obj2ast_expr(tmp, &type, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4085 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4086 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4087 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4088 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4089 type = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4090 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4091 if (PyObject_HasAttrString(obj, "inst")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4092 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4093 tmp = PyObject_GetAttrString(obj, "inst");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4094 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4095 res = obj2ast_expr(tmp, &inst, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4096 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4097 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4098 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4099 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4100 inst = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4101 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4102 if (PyObject_HasAttrString(obj, "tback")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4103 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4104 tmp = PyObject_GetAttrString(obj, "tback");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4105 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4106 res = obj2ast_expr(tmp, &tback, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4107 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4108 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4109 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4110 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4111 tback = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4112 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4113 *out = Raise(type, inst, tback, lineno, col_offset, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4114 if (*out == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4115 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4116 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4117 isinstance = PyObject_IsInstance(obj, (PyObject*)TryExcept_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4118 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4119 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4120 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4121 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4122 asdl_seq* body;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4123 asdl_seq* handlers;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4124 asdl_seq* orelse;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4125
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4126 if (PyObject_HasAttrString(obj, "body")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4127 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4128 Py_ssize_t len;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4129 Py_ssize_t i;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4130 tmp = PyObject_GetAttrString(obj, "body");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4131 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4132 if (!PyList_Check(tmp)) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4133 PyErr_Format(PyExc_TypeError, "TryExcept field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4134 goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4135 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4136 len = PyList_GET_SIZE(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4137 body = asdl_seq_new(len, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4138 if (body == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4139 for (i = 0; i < len; i++) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4140 stmt_ty value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4141 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4142 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4143 asdl_seq_SET(body, i, value);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4144 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4145 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4146 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4147 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4148 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from TryExcept");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4149 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4150 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4151 if (PyObject_HasAttrString(obj, "handlers")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4152 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4153 Py_ssize_t len;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4154 Py_ssize_t i;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4155 tmp = PyObject_GetAttrString(obj, "handlers");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4156 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4157 if (!PyList_Check(tmp)) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4158 PyErr_Format(PyExc_TypeError, "TryExcept field \"handlers\" must be a list, not a %.200s", tmp->ob_type->tp_name);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4159 goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4160 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4161 len = PyList_GET_SIZE(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4162 handlers = asdl_seq_new(len, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4163 if (handlers == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4164 for (i = 0; i < len; i++) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4165 excepthandler_ty value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4166 res = obj2ast_excepthandler(PyList_GET_ITEM(tmp, i), &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4167 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4168 asdl_seq_SET(handlers, i, value);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4169 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4170 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4171 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4172 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4173 PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from TryExcept");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4174 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4175 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4176 if (PyObject_HasAttrString(obj, "orelse")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4177 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4178 Py_ssize_t len;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4179 Py_ssize_t i;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4180 tmp = PyObject_GetAttrString(obj, "orelse");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4181 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4182 if (!PyList_Check(tmp)) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4183 PyErr_Format(PyExc_TypeError, "TryExcept field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4184 goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4185 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4186 len = PyList_GET_SIZE(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4187 orelse = asdl_seq_new(len, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4188 if (orelse == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4189 for (i = 0; i < len; i++) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4190 stmt_ty value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4191 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4192 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4193 asdl_seq_SET(orelse, i, value);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4194 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4195 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4196 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4197 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4198 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from TryExcept");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4199 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4200 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4201 *out = TryExcept(body, handlers, orelse, lineno, col_offset,
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4202 arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4203 if (*out == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4204 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4205 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4206 isinstance = PyObject_IsInstance(obj, (PyObject*)TryFinally_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4207 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4208 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4209 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4210 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4211 asdl_seq* body;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4212 asdl_seq* finalbody;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4213
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4214 if (PyObject_HasAttrString(obj, "body")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4215 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4216 Py_ssize_t len;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4217 Py_ssize_t i;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4218 tmp = PyObject_GetAttrString(obj, "body");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4219 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4220 if (!PyList_Check(tmp)) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4221 PyErr_Format(PyExc_TypeError, "TryFinally field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4222 goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4223 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4224 len = PyList_GET_SIZE(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4225 body = asdl_seq_new(len, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4226 if (body == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4227 for (i = 0; i < len; i++) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4228 stmt_ty value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4229 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4230 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4231 asdl_seq_SET(body, i, value);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4232 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4233 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4234 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4235 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4236 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from TryFinally");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4237 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4238 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4239 if (PyObject_HasAttrString(obj, "finalbody")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4240 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4241 Py_ssize_t len;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4242 Py_ssize_t i;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4243 tmp = PyObject_GetAttrString(obj, "finalbody");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4244 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4245 if (!PyList_Check(tmp)) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4246 PyErr_Format(PyExc_TypeError, "TryFinally field \"finalbody\" must be a list, not a %.200s", tmp->ob_type->tp_name);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4247 goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4248 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4249 len = PyList_GET_SIZE(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4250 finalbody = asdl_seq_new(len, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4251 if (finalbody == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4252 for (i = 0; i < len; i++) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4253 stmt_ty value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4254 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4255 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4256 asdl_seq_SET(finalbody, i, value);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4257 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4258 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4259 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4260 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4261 PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from TryFinally");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4262 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4263 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4264 *out = TryFinally(body, finalbody, lineno, col_offset, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4265 if (*out == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4266 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4267 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4268 isinstance = PyObject_IsInstance(obj, (PyObject*)Assert_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4269 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4270 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4271 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4272 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4273 expr_ty test;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4274 expr_ty msg;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4275
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4276 if (PyObject_HasAttrString(obj, "test")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4277 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4278 tmp = PyObject_GetAttrString(obj, "test");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4279 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4280 res = obj2ast_expr(tmp, &test, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4281 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4282 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4283 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4284 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4285 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4286 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4287 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4288 if (PyObject_HasAttrString(obj, "msg")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4289 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4290 tmp = PyObject_GetAttrString(obj, "msg");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4291 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4292 res = obj2ast_expr(tmp, &msg, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4293 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4294 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4295 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4296 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4297 msg = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4298 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4299 *out = Assert(test, msg, lineno, col_offset, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4300 if (*out == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4301 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4302 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4303 isinstance = PyObject_IsInstance(obj, (PyObject*)Import_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4304 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4305 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4306 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4307 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4308 asdl_seq* names;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4309
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4310 if (PyObject_HasAttrString(obj, "names")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4311 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4312 Py_ssize_t len;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4313 Py_ssize_t i;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4314 tmp = PyObject_GetAttrString(obj, "names");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4315 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4316 if (!PyList_Check(tmp)) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4317 PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4318 goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4319 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4320 len = PyList_GET_SIZE(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4321 names = asdl_seq_new(len, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4322 if (names == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4323 for (i = 0; i < len; i++) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4324 alias_ty value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4325 res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4326 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4327 asdl_seq_SET(names, i, value);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4328 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4329 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4330 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4331 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4332 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4333 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4334 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4335 *out = Import(names, lineno, col_offset, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4336 if (*out == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4337 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4338 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4339 isinstance = PyObject_IsInstance(obj, (PyObject*)ImportFrom_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4340 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4341 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4342 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4343 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4344 identifier module;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4345 asdl_seq* names;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4346 int level;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4347
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4348 if (PyObject_HasAttrString(obj, "module")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4349 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4350 tmp = PyObject_GetAttrString(obj, "module");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4351 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4352 res = obj2ast_identifier(tmp, &module, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4353 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4354 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4355 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4356 } else {
54743
40c8c35492f1 when no module is given in a 'from' relative import, make ImportFrom.module NULL
Benjamin Peterson <benjamin@python.org>
parents: 49552
diff changeset
4357 module = NULL;
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4358 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4359 if (PyObject_HasAttrString(obj, "names")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4360 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4361 Py_ssize_t len;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4362 Py_ssize_t i;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4363 tmp = PyObject_GetAttrString(obj, "names");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4364 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4365 if (!PyList_Check(tmp)) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4366 PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4367 goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4368 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4369 len = PyList_GET_SIZE(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4370 names = asdl_seq_new(len, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4371 if (names == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4372 for (i = 0; i < len; i++) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4373 alias_ty value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4374 res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4375 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4376 asdl_seq_SET(names, i, value);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4377 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4378 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4379 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4380 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4381 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4382 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4383 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4384 if (PyObject_HasAttrString(obj, "level")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4385 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4386 tmp = PyObject_GetAttrString(obj, "level");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4387 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4388 res = obj2ast_int(tmp, &level, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4389 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4390 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4391 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4392 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4393 level = 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4394 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4395 *out = ImportFrom(module, names, level, lineno, col_offset,
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4396 arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4397 if (*out == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4398 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4399 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4400 isinstance = PyObject_IsInstance(obj, (PyObject*)Exec_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4401 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4402 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4403 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4404 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4405 expr_ty body;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4406 expr_ty globals;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4407 expr_ty locals;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4408
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4409 if (PyObject_HasAttrString(obj, "body")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4410 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4411 tmp = PyObject_GetAttrString(obj, "body");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4412 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4413 res = obj2ast_expr(tmp, &body, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4414 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4415 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4416 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4417 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4418 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Exec");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4419 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4420 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4421 if (PyObject_HasAttrString(obj, "globals")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4422 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4423 tmp = PyObject_GetAttrString(obj, "globals");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4424 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4425 res = obj2ast_expr(tmp, &globals, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4426 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4427 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4428 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4429 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4430 globals = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4431 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4432 if (PyObject_HasAttrString(obj, "locals")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4433 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4434 tmp = PyObject_GetAttrString(obj, "locals");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4435 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4436 res = obj2ast_expr(tmp, &locals, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4437 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4438 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4439 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4440 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4441 locals = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4442 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4443 *out = Exec(body, globals, locals, lineno, col_offset, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4444 if (*out == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4445 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4446 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4447 isinstance = PyObject_IsInstance(obj, (PyObject*)Global_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4448 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4449 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4450 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4451 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4452 asdl_seq* names;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4453
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4454 if (PyObject_HasAttrString(obj, "names")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4455 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4456 Py_ssize_t len;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4457 Py_ssize_t i;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4458 tmp = PyObject_GetAttrString(obj, "names");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4459 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4460 if (!PyList_Check(tmp)) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4461 PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4462 goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4463 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4464 len = PyList_GET_SIZE(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4465 names = asdl_seq_new(len, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4466 if (names == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4467 for (i = 0; i < len; i++) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4468 identifier value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4469 res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4470 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4471 asdl_seq_SET(names, i, value);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4472 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4473 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4474 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4475 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4476 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4477 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4478 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4479 *out = Global(names, lineno, col_offset, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4480 if (*out == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4481 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4482 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4483 isinstance = PyObject_IsInstance(obj, (PyObject*)Expr_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4484 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4485 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4486 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4487 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4488 expr_ty value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4489
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4490 if (PyObject_HasAttrString(obj, "value")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4491 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4492 tmp = PyObject_GetAttrString(obj, "value");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4493 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4494 res = obj2ast_expr(tmp, &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4495 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4496 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4497 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4498 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4499 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4500 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4501 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4502 *out = Expr(value, lineno, col_offset, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4503 if (*out == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4504 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4505 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4506 isinstance = PyObject_IsInstance(obj, (PyObject*)Pass_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4507 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4508 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4509 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4510 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4511
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4512 *out = Pass(lineno, col_offset, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4513 if (*out == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4514 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4515 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4516 isinstance = PyObject_IsInstance(obj, (PyObject*)Break_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4517 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4518 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4519 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4520 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4521
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4522 *out = Break(lineno, col_offset, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4523 if (*out == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4524 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4525 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4526 isinstance = PyObject_IsInstance(obj, (PyObject*)Continue_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4527 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4528 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4529 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4530 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4531
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4532 *out = Continue(lineno, col_offset, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4533 if (*out == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4534 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4535 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4536
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4537 tmp = PyObject_Repr(obj);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4538 if (tmp == NULL) goto failed;
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
4539 PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %.400s", PyString_AS_STRING(tmp));
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4540 failed:
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4541 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4542 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4543 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4544
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4545 int
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4546 obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4547 {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4548 PyObject* tmp = NULL;
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4549 int isinstance;
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4550
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4551 int lineno;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4552 int col_offset;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4553
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4554 if (obj == Py_None) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4555 *out = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4556 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4557 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4558 if (PyObject_HasAttrString(obj, "lineno")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4559 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4560 tmp = PyObject_GetAttrString(obj, "lineno");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4561 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4562 res = obj2ast_int(tmp, &lineno, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4563 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4564 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4565 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4566 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4567 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4568 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4569 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4570 if (PyObject_HasAttrString(obj, "col_offset")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4571 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4572 tmp = PyObject_GetAttrString(obj, "col_offset");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4573 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4574 res = obj2ast_int(tmp, &col_offset, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4575 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4576 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4577 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4578 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4579 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4580 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4581 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4582 isinstance = PyObject_IsInstance(obj, (PyObject*)BoolOp_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4583 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4584 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4585 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4586 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4587 boolop_ty op;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4588 asdl_seq* values;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4589
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4590 if (PyObject_HasAttrString(obj, "op")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4591 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4592 tmp = PyObject_GetAttrString(obj, "op");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4593 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4594 res = obj2ast_boolop(tmp, &op, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4595 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4596 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4597 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4598 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4599 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4600 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4601 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4602 if (PyObject_HasAttrString(obj, "values")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4603 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4604 Py_ssize_t len;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4605 Py_ssize_t i;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4606 tmp = PyObject_GetAttrString(obj, "values");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4607 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4608 if (!PyList_Check(tmp)) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4609 PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4610 goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4611 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4612 len = PyList_GET_SIZE(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4613 values = asdl_seq_new(len, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4614 if (values == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4615 for (i = 0; i < len; i++) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4616 expr_ty value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4617 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4618 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4619 asdl_seq_SET(values, i, value);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4620 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4621 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4622 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4623 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4624 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4625 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4626 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4627 *out = BoolOp(op, values, lineno, col_offset, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4628 if (*out == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4629 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4630 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4631 isinstance = PyObject_IsInstance(obj, (PyObject*)BinOp_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4632 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4633 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4634 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4635 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4636 expr_ty left;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4637 operator_ty op;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4638 expr_ty right;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4639
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4640 if (PyObject_HasAttrString(obj, "left")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4641 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4642 tmp = PyObject_GetAttrString(obj, "left");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4643 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4644 res = obj2ast_expr(tmp, &left, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4645 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4646 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4647 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4648 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4649 PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4650 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4651 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4652 if (PyObject_HasAttrString(obj, "op")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4653 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4654 tmp = PyObject_GetAttrString(obj, "op");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4655 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4656 res = obj2ast_operator(tmp, &op, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4657 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4658 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4659 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4660 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4661 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4662 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4663 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4664 if (PyObject_HasAttrString(obj, "right")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4665 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4666 tmp = PyObject_GetAttrString(obj, "right");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4667 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4668 res = obj2ast_expr(tmp, &right, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4669 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4670 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4671 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4672 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4673 PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4674 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4675 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4676 *out = BinOp(left, op, right, lineno, col_offset, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4677 if (*out == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4678 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4679 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4680 isinstance = PyObject_IsInstance(obj, (PyObject*)UnaryOp_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4681 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4682 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4683 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4684 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4685 unaryop_ty op;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4686 expr_ty operand;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4687
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4688 if (PyObject_HasAttrString(obj, "op")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4689 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4690 tmp = PyObject_GetAttrString(obj, "op");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4691 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4692 res = obj2ast_unaryop(tmp, &op, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4693 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4694 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4695 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4696 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4697 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4698 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4699 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4700 if (PyObject_HasAttrString(obj, "operand")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4701 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4702 tmp = PyObject_GetAttrString(obj, "operand");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4703 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4704 res = obj2ast_expr(tmp, &operand, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4705 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4706 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4707 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4708 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4709 PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4710 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4711 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4712 *out = UnaryOp(op, operand, lineno, col_offset, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4713 if (*out == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4714 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4715 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4716 isinstance = PyObject_IsInstance(obj, (PyObject*)Lambda_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4717 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4718 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4719 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4720 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4721 arguments_ty args;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4722 expr_ty body;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4723
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4724 if (PyObject_HasAttrString(obj, "args")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4725 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4726 tmp = PyObject_GetAttrString(obj, "args");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4727 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4728 res = obj2ast_arguments(tmp, &args, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4729 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4730 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4731 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4732 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4733 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4734 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4735 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4736 if (PyObject_HasAttrString(obj, "body")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4737 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4738 tmp = PyObject_GetAttrString(obj, "body");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4739 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4740 res = obj2ast_expr(tmp, &body, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4741 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4742 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4743 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4744 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4745 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4746 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4747 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4748 *out = Lambda(args, body, lineno, col_offset, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4749 if (*out == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4750 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4751 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4752 isinstance = PyObject_IsInstance(obj, (PyObject*)IfExp_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4753 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4754 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4755 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4756 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4757 expr_ty test;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4758 expr_ty body;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4759 expr_ty orelse;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4760
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4761 if (PyObject_HasAttrString(obj, "test")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4762 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4763 tmp = PyObject_GetAttrString(obj, "test");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4764 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4765 res = obj2ast_expr(tmp, &test, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4766 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4767 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4768 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4769 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4770 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4771 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4772 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4773 if (PyObject_HasAttrString(obj, "body")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4774 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4775 tmp = PyObject_GetAttrString(obj, "body");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4776 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4777 res = obj2ast_expr(tmp, &body, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4778 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4779 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4780 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4781 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4782 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4783 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4784 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4785 if (PyObject_HasAttrString(obj, "orelse")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4786 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4787 tmp = PyObject_GetAttrString(obj, "orelse");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4788 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4789 res = obj2ast_expr(tmp, &orelse, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4790 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4791 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4792 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4793 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4794 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4795 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4796 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4797 *out = IfExp(test, body, orelse, lineno, col_offset, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4798 if (*out == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4799 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4800 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4801 isinstance = PyObject_IsInstance(obj, (PyObject*)Dict_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4802 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4803 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4804 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4805 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4806 asdl_seq* keys;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4807 asdl_seq* values;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4808
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4809 if (PyObject_HasAttrString(obj, "keys")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4810 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4811 Py_ssize_t len;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4812 Py_ssize_t i;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4813 tmp = PyObject_GetAttrString(obj, "keys");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4814 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4815 if (!PyList_Check(tmp)) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4816 PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", tmp->ob_type->tp_name);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4817 goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4818 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4819 len = PyList_GET_SIZE(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4820 keys = asdl_seq_new(len, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4821 if (keys == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4822 for (i = 0; i < len; i++) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4823 expr_ty value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4824 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4825 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4826 asdl_seq_SET(keys, i, value);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4827 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4828 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4829 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4830 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4831 PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4832 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4833 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4834 if (PyObject_HasAttrString(obj, "values")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4835 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4836 Py_ssize_t len;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4837 Py_ssize_t i;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4838 tmp = PyObject_GetAttrString(obj, "values");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4839 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4840 if (!PyList_Check(tmp)) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4841 PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4842 goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4843 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4844 len = PyList_GET_SIZE(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4845 values = asdl_seq_new(len, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4846 if (values == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4847 for (i = 0; i < len; i++) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4848 expr_ty value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4849 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4850 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4851 asdl_seq_SET(values, i, value);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4852 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4853 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4854 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4855 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4856 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4857 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4858 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4859 *out = Dict(keys, values, lineno, col_offset, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4860 if (*out == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4861 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4862 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4863 isinstance = PyObject_IsInstance(obj, (PyObject*)ListComp_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4864 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4865 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4866 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4867 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4868 expr_ty elt;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4869 asdl_seq* generators;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4870
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4871 if (PyObject_HasAttrString(obj, "elt")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4872 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4873 tmp = PyObject_GetAttrString(obj, "elt");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4874 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4875 res = obj2ast_expr(tmp, &elt, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4876 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4877 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4878 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4879 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4880 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4881 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4882 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4883 if (PyObject_HasAttrString(obj, "generators")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4884 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4885 Py_ssize_t len;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4886 Py_ssize_t i;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4887 tmp = PyObject_GetAttrString(obj, "generators");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4888 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4889 if (!PyList_Check(tmp)) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4890 PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4891 goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4892 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4893 len = PyList_GET_SIZE(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4894 generators = asdl_seq_new(len, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4895 if (generators == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4896 for (i = 0; i < len; i++) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4897 comprehension_ty value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4898 res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4899 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4900 asdl_seq_SET(generators, i, value);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4901 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4902 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4903 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4904 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4905 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4906 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4907 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4908 *out = ListComp(elt, generators, lineno, col_offset, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4909 if (*out == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4910 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4911 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4912 isinstance = PyObject_IsInstance(obj, (PyObject*)GeneratorExp_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4913 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4914 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4915 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4916 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4917 expr_ty elt;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4918 asdl_seq* generators;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4919
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4920 if (PyObject_HasAttrString(obj, "elt")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4921 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4922 tmp = PyObject_GetAttrString(obj, "elt");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4923 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4924 res = obj2ast_expr(tmp, &elt, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4925 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4926 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4927 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4928 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4929 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4930 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4931 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4932 if (PyObject_HasAttrString(obj, "generators")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4933 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4934 Py_ssize_t len;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4935 Py_ssize_t i;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4936 tmp = PyObject_GetAttrString(obj, "generators");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4937 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4938 if (!PyList_Check(tmp)) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4939 PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4940 goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4941 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4942 len = PyList_GET_SIZE(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4943 generators = asdl_seq_new(len, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4944 if (generators == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4945 for (i = 0; i < len; i++) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4946 comprehension_ty value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4947 res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4948 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4949 asdl_seq_SET(generators, i, value);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4950 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4951 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4952 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4953 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4954 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4955 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4956 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4957 *out = GeneratorExp(elt, generators, lineno, col_offset, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4958 if (*out == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4959 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4960 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4961 isinstance = PyObject_IsInstance(obj, (PyObject*)Yield_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4962 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4963 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4964 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4965 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4966 expr_ty value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4967
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4968 if (PyObject_HasAttrString(obj, "value")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4969 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4970 tmp = PyObject_GetAttrString(obj, "value");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4971 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4972 res = obj2ast_expr(tmp, &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4973 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4974 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4975 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4976 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4977 value = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4978 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4979 *out = Yield(value, lineno, col_offset, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4980 if (*out == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4981 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4982 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4983 isinstance = PyObject_IsInstance(obj, (PyObject*)Compare_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4984 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4985 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4986 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
4987 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4988 expr_ty left;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4989 asdl_int_seq* ops;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4990 asdl_seq* comparators;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4991
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4992 if (PyObject_HasAttrString(obj, "left")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4993 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4994 tmp = PyObject_GetAttrString(obj, "left");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4995 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4996 res = obj2ast_expr(tmp, &left, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4997 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4998 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
4999 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5000 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5001 PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5002 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5003 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5004 if (PyObject_HasAttrString(obj, "ops")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5005 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5006 Py_ssize_t len;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5007 Py_ssize_t i;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5008 tmp = PyObject_GetAttrString(obj, "ops");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5009 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5010 if (!PyList_Check(tmp)) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5011 PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", tmp->ob_type->tp_name);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5012 goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5013 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5014 len = PyList_GET_SIZE(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5015 ops = asdl_int_seq_new(len, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5016 if (ops == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5017 for (i = 0; i < len; i++) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5018 cmpop_ty value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5019 res = obj2ast_cmpop(PyList_GET_ITEM(tmp, i), &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5020 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5021 asdl_seq_SET(ops, i, value);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5022 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5023 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5024 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5025 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5026 PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5027 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5028 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5029 if (PyObject_HasAttrString(obj, "comparators")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5030 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5031 Py_ssize_t len;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5032 Py_ssize_t i;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5033 tmp = PyObject_GetAttrString(obj, "comparators");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5034 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5035 if (!PyList_Check(tmp)) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5036 PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", tmp->ob_type->tp_name);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5037 goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5038 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5039 len = PyList_GET_SIZE(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5040 comparators = asdl_seq_new(len, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5041 if (comparators == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5042 for (i = 0; i < len; i++) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5043 expr_ty value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5044 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5045 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5046 asdl_seq_SET(comparators, i, value);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5047 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5048 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5049 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5050 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5051 PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5052 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5053 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5054 *out = Compare(left, ops, comparators, lineno, col_offset,
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5055 arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5056 if (*out == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5057 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5058 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5059 isinstance = PyObject_IsInstance(obj, (PyObject*)Call_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5060 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5061 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5062 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5063 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5064 expr_ty func;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5065 asdl_seq* args;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5066 asdl_seq* keywords;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5067 expr_ty starargs;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5068 expr_ty kwargs;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5069
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5070 if (PyObject_HasAttrString(obj, "func")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5071 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5072 tmp = PyObject_GetAttrString(obj, "func");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5073 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5074 res = obj2ast_expr(tmp, &func, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5075 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5076 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5077 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5078 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5079 PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5080 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5081 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5082 if (PyObject_HasAttrString(obj, "args")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5083 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5084 Py_ssize_t len;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5085 Py_ssize_t i;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5086 tmp = PyObject_GetAttrString(obj, "args");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5087 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5088 if (!PyList_Check(tmp)) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5089 PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5090 goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5091 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5092 len = PyList_GET_SIZE(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5093 args = asdl_seq_new(len, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5094 if (args == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5095 for (i = 0; i < len; i++) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5096 expr_ty value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5097 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5098 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5099 asdl_seq_SET(args, i, value);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5100 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5101 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5102 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5103 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5104 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5105 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5106 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5107 if (PyObject_HasAttrString(obj, "keywords")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5108 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5109 Py_ssize_t len;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5110 Py_ssize_t i;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5111 tmp = PyObject_GetAttrString(obj, "keywords");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5112 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5113 if (!PyList_Check(tmp)) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5114 PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5115 goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5116 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5117 len = PyList_GET_SIZE(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5118 keywords = asdl_seq_new(len, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5119 if (keywords == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5120 for (i = 0; i < len; i++) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5121 keyword_ty value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5122 res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5123 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5124 asdl_seq_SET(keywords, i, value);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5125 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5126 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5127 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5128 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5129 PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5130 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5131 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5132 if (PyObject_HasAttrString(obj, "starargs")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5133 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5134 tmp = PyObject_GetAttrString(obj, "starargs");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5135 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5136 res = obj2ast_expr(tmp, &starargs, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5137 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5138 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5139 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5140 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5141 starargs = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5142 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5143 if (PyObject_HasAttrString(obj, "kwargs")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5144 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5145 tmp = PyObject_GetAttrString(obj, "kwargs");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5146 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5147 res = obj2ast_expr(tmp, &kwargs, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5148 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5149 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5150 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5151 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5152 kwargs = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5153 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5154 *out = Call(func, args, keywords, starargs, kwargs, lineno,
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5155 col_offset, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5156 if (*out == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5157 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5158 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5159 isinstance = PyObject_IsInstance(obj, (PyObject*)Repr_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5160 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5161 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5162 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5163 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5164 expr_ty value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5165
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5166 if (PyObject_HasAttrString(obj, "value")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5167 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5168 tmp = PyObject_GetAttrString(obj, "value");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5169 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5170 res = obj2ast_expr(tmp, &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5171 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5172 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5173 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5174 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5175 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Repr");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5176 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5177 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5178 *out = Repr(value, lineno, col_offset, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5179 if (*out == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5180 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5181 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5182 isinstance = PyObject_IsInstance(obj, (PyObject*)Num_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5183 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5184 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5185 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5186 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5187 object n;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5188
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5189 if (PyObject_HasAttrString(obj, "n")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5190 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5191 tmp = PyObject_GetAttrString(obj, "n");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5192 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5193 res = obj2ast_object(tmp, &n, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5194 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5195 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5196 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5197 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5198 PyErr_SetString(PyExc_TypeError, "required field \"n\" missing from Num");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5199 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5200 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5201 *out = Num(n, lineno, col_offset, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5202 if (*out == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5203 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5204 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5205 isinstance = PyObject_IsInstance(obj, (PyObject*)Str_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5206 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5207 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5208 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5209 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5210 string s;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5211
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5212 if (PyObject_HasAttrString(obj, "s")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5213 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5214 tmp = PyObject_GetAttrString(obj, "s");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5215 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5216 res = obj2ast_string(tmp, &s, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5217 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5218 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5219 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5220 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5221 PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Str");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5222 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5223 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5224 *out = Str(s, lineno, col_offset, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5225 if (*out == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5226 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5227 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5228 isinstance = PyObject_IsInstance(obj, (PyObject*)Attribute_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5229 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5230 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5231 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5232 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5233 expr_ty value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5234 identifier attr;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5235 expr_context_ty ctx;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5236
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5237 if (PyObject_HasAttrString(obj, "value")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5238 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5239 tmp = PyObject_GetAttrString(obj, "value");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5240 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5241 res = obj2ast_expr(tmp, &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5242 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5243 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5244 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5245 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5246 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5247 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5248 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5249 if (PyObject_HasAttrString(obj, "attr")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5250 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5251 tmp = PyObject_GetAttrString(obj, "attr");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5252 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5253 res = obj2ast_identifier(tmp, &attr, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5254 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5255 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5256 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5257 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5258 PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5259 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5260 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5261 if (PyObject_HasAttrString(obj, "ctx")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5262 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5263 tmp = PyObject_GetAttrString(obj, "ctx");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5264 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5265 res = obj2ast_expr_context(tmp, &ctx, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5266 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5267 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5268 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5269 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5270 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5271 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5272 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5273 *out = Attribute(value, attr, ctx, lineno, col_offset, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5274 if (*out == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5275 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5276 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5277 isinstance = PyObject_IsInstance(obj, (PyObject*)Subscript_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5278 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5279 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5280 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5281 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5282 expr_ty value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5283 slice_ty slice;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5284 expr_context_ty ctx;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5285
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5286 if (PyObject_HasAttrString(obj, "value")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5287 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5288 tmp = PyObject_GetAttrString(obj, "value");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5289 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5290 res = obj2ast_expr(tmp, &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5291 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5292 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5293 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5294 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5295 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5296 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5297 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5298 if (PyObject_HasAttrString(obj, "slice")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5299 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5300 tmp = PyObject_GetAttrString(obj, "slice");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5301 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5302 res = obj2ast_slice(tmp, &slice, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5303 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5304 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5305 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5306 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5307 PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5308 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5309 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5310 if (PyObject_HasAttrString(obj, "ctx")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5311 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5312 tmp = PyObject_GetAttrString(obj, "ctx");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5313 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5314 res = obj2ast_expr_context(tmp, &ctx, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5315 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5316 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5317 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5318 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5319 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5320 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5321 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5322 *out = Subscript(value, slice, ctx, lineno, col_offset, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5323 if (*out == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5324 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5325 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5326 isinstance = PyObject_IsInstance(obj, (PyObject*)Name_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5327 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5328 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5329 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5330 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5331 identifier id;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5332 expr_context_ty ctx;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5333
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5334 if (PyObject_HasAttrString(obj, "id")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5335 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5336 tmp = PyObject_GetAttrString(obj, "id");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5337 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5338 res = obj2ast_identifier(tmp, &id, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5339 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5340 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5341 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5342 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5343 PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5344 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5345 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5346 if (PyObject_HasAttrString(obj, "ctx")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5347 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5348 tmp = PyObject_GetAttrString(obj, "ctx");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5349 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5350 res = obj2ast_expr_context(tmp, &ctx, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5351 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5352 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5353 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5354 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5355 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5356 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5357 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5358 *out = Name(id, ctx, lineno, col_offset, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5359 if (*out == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5360 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5361 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5362 isinstance = PyObject_IsInstance(obj, (PyObject*)List_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5363 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5364 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5365 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5366 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5367 asdl_seq* elts;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5368 expr_context_ty ctx;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5369
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5370 if (PyObject_HasAttrString(obj, "elts")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5371 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5372 Py_ssize_t len;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5373 Py_ssize_t i;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5374 tmp = PyObject_GetAttrString(obj, "elts");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5375 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5376 if (!PyList_Check(tmp)) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5377 PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5378 goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5379 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5380 len = PyList_GET_SIZE(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5381 elts = asdl_seq_new(len, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5382 if (elts == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5383 for (i = 0; i < len; i++) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5384 expr_ty value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5385 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5386 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5387 asdl_seq_SET(elts, i, value);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5388 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5389 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5390 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5391 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5392 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5393 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5394 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5395 if (PyObject_HasAttrString(obj, "ctx")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5396 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5397 tmp = PyObject_GetAttrString(obj, "ctx");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5398 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5399 res = obj2ast_expr_context(tmp, &ctx, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5400 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5401 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5402 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5403 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5404 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5405 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5406 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5407 *out = List(elts, ctx, lineno, col_offset, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5408 if (*out == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5409 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5410 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5411 isinstance = PyObject_IsInstance(obj, (PyObject*)Tuple_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5412 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5413 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5414 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5415 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5416 asdl_seq* elts;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5417 expr_context_ty ctx;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5418
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5419 if (PyObject_HasAttrString(obj, "elts")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5420 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5421 Py_ssize_t len;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5422 Py_ssize_t i;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5423 tmp = PyObject_GetAttrString(obj, "elts");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5424 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5425 if (!PyList_Check(tmp)) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5426 PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5427 goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5428 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5429 len = PyList_GET_SIZE(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5430 elts = asdl_seq_new(len, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5431 if (elts == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5432 for (i = 0; i < len; i++) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5433 expr_ty value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5434 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5435 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5436 asdl_seq_SET(elts, i, value);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5437 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5438 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5439 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5440 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5441 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5442 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5443 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5444 if (PyObject_HasAttrString(obj, "ctx")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5445 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5446 tmp = PyObject_GetAttrString(obj, "ctx");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5447 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5448 res = obj2ast_expr_context(tmp, &ctx, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5449 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5450 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5451 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5452 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5453 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5454 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5455 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5456 *out = Tuple(elts, ctx, lineno, col_offset, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5457 if (*out == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5458 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5459 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5460
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5461 tmp = PyObject_Repr(obj);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5462 if (tmp == NULL) goto failed;
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
5463 PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %.400s", PyString_AS_STRING(tmp));
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5464 failed:
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5465 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5466 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5467 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5468
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5469 int
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5470 obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena)
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5471 {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5472 PyObject* tmp = NULL;
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5473 int isinstance;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5474
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5475 isinstance = PyObject_IsInstance(obj, (PyObject *)Load_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5476 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5477 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5478 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5479 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5480 *out = Load;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5481 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5482 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5483 isinstance = PyObject_IsInstance(obj, (PyObject *)Store_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5484 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5485 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5486 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5487 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5488 *out = Store;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5489 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5490 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5491 isinstance = PyObject_IsInstance(obj, (PyObject *)Del_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5492 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5493 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5494 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5495 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5496 *out = Del;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5497 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5498 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5499 isinstance = PyObject_IsInstance(obj, (PyObject *)AugLoad_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5500 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5501 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5502 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5503 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5504 *out = AugLoad;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5505 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5506 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5507 isinstance = PyObject_IsInstance(obj, (PyObject *)AugStore_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5508 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5509 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5510 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5511 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5512 *out = AugStore;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5513 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5514 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5515 isinstance = PyObject_IsInstance(obj, (PyObject *)Param_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5516 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5517 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5518 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5519 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5520 *out = Param;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5521 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5522 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5523
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5524 tmp = PyObject_Repr(obj);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5525 if (tmp == NULL) goto failed;
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
5526 PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %.400s", PyString_AS_STRING(tmp));
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5527 failed:
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5528 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5529 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5530 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5531
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5532 int
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5533 obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena)
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5534 {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5535 PyObject* tmp = NULL;
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5536 int isinstance;
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5537
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5538
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5539 if (obj == Py_None) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5540 *out = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5541 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5542 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5543 isinstance = PyObject_IsInstance(obj, (PyObject*)Ellipsis_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5544 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5545 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5546 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5547 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5548
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5549 *out = Ellipsis(arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5550 if (*out == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5551 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5552 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5553 isinstance = PyObject_IsInstance(obj, (PyObject*)Slice_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5554 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5555 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5556 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5557 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5558 expr_ty lower;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5559 expr_ty upper;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5560 expr_ty step;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5561
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5562 if (PyObject_HasAttrString(obj, "lower")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5563 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5564 tmp = PyObject_GetAttrString(obj, "lower");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5565 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5566 res = obj2ast_expr(tmp, &lower, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5567 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5568 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5569 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5570 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5571 lower = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5572 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5573 if (PyObject_HasAttrString(obj, "upper")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5574 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5575 tmp = PyObject_GetAttrString(obj, "upper");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5576 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5577 res = obj2ast_expr(tmp, &upper, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5578 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5579 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5580 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5581 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5582 upper = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5583 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5584 if (PyObject_HasAttrString(obj, "step")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5585 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5586 tmp = PyObject_GetAttrString(obj, "step");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5587 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5588 res = obj2ast_expr(tmp, &step, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5589 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5590 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5591 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5592 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5593 step = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5594 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5595 *out = Slice(lower, upper, step, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5596 if (*out == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5597 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5598 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5599 isinstance = PyObject_IsInstance(obj, (PyObject*)ExtSlice_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5600 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5601 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5602 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5603 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5604 asdl_seq* dims;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5605
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5606 if (PyObject_HasAttrString(obj, "dims")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5607 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5608 Py_ssize_t len;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5609 Py_ssize_t i;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5610 tmp = PyObject_GetAttrString(obj, "dims");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5611 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5612 if (!PyList_Check(tmp)) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5613 PyErr_Format(PyExc_TypeError, "ExtSlice field \"dims\" must be a list, not a %.200s", tmp->ob_type->tp_name);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5614 goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5615 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5616 len = PyList_GET_SIZE(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5617 dims = asdl_seq_new(len, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5618 if (dims == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5619 for (i = 0; i < len; i++) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5620 slice_ty value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5621 res = obj2ast_slice(PyList_GET_ITEM(tmp, i), &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5622 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5623 asdl_seq_SET(dims, i, value);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5624 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5625 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5626 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5627 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5628 PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5629 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5630 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5631 *out = ExtSlice(dims, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5632 if (*out == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5633 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5634 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5635 isinstance = PyObject_IsInstance(obj, (PyObject*)Index_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5636 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5637 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5638 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5639 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5640 expr_ty value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5641
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5642 if (PyObject_HasAttrString(obj, "value")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5643 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5644 tmp = PyObject_GetAttrString(obj, "value");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5645 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5646 res = obj2ast_expr(tmp, &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5647 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5648 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5649 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5650 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5651 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5652 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5653 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5654 *out = Index(value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5655 if (*out == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5656 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5657 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5658
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5659 tmp = PyObject_Repr(obj);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5660 if (tmp == NULL) goto failed;
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
5661 PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %.400s", PyString_AS_STRING(tmp));
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5662 failed:
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5663 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5664 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5665 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5666
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5667 int
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5668 obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena)
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5669 {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5670 PyObject* tmp = NULL;
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5671 int isinstance;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5672
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5673 isinstance = PyObject_IsInstance(obj, (PyObject *)And_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5674 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5675 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5676 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5677 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5678 *out = And;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5679 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5680 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5681 isinstance = PyObject_IsInstance(obj, (PyObject *)Or_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5682 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5683 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5684 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5685 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5686 *out = Or;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5687 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5688 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5689
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5690 tmp = PyObject_Repr(obj);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5691 if (tmp == NULL) goto failed;
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
5692 PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %.400s", PyString_AS_STRING(tmp));
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5693 failed:
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5694 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5695 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5696 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5697
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5698 int
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5699 obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena)
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5700 {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5701 PyObject* tmp = NULL;
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5702 int isinstance;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5703
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5704 isinstance = PyObject_IsInstance(obj, (PyObject *)Add_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5705 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5706 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5707 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5708 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5709 *out = Add;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5710 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5711 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5712 isinstance = PyObject_IsInstance(obj, (PyObject *)Sub_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5713 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5714 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5715 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5716 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5717 *out = Sub;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5718 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5719 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5720 isinstance = PyObject_IsInstance(obj, (PyObject *)Mult_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5721 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5722 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5723 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5724 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5725 *out = Mult;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5726 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5727 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5728 isinstance = PyObject_IsInstance(obj, (PyObject *)Div_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5729 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5730 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5731 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5732 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5733 *out = Div;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5734 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5735 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5736 isinstance = PyObject_IsInstance(obj, (PyObject *)Mod_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5737 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5738 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5739 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5740 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5741 *out = Mod;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5742 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5743 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5744 isinstance = PyObject_IsInstance(obj, (PyObject *)Pow_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5745 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5746 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5747 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5748 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5749 *out = Pow;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5750 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5751 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5752 isinstance = PyObject_IsInstance(obj, (PyObject *)LShift_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5753 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5754 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5755 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5756 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5757 *out = LShift;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5758 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5759 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5760 isinstance = PyObject_IsInstance(obj, (PyObject *)RShift_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5761 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5762 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5763 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5764 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5765 *out = RShift;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5766 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5767 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5768 isinstance = PyObject_IsInstance(obj, (PyObject *)BitOr_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5769 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5770 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5771 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5772 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5773 *out = BitOr;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5774 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5775 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5776 isinstance = PyObject_IsInstance(obj, (PyObject *)BitXor_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5777 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5778 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5779 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5780 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5781 *out = BitXor;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5782 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5783 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5784 isinstance = PyObject_IsInstance(obj, (PyObject *)BitAnd_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5785 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5786 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5787 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5788 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5789 *out = BitAnd;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5790 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5791 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5792 isinstance = PyObject_IsInstance(obj, (PyObject *)FloorDiv_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5793 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5794 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5795 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5796 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5797 *out = FloorDiv;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5798 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5799 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5800
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5801 tmp = PyObject_Repr(obj);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5802 if (tmp == NULL) goto failed;
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
5803 PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %.400s", PyString_AS_STRING(tmp));
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5804 failed:
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5805 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5806 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5807 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5808
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5809 int
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5810 obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena)
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5811 {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5812 PyObject* tmp = NULL;
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5813 int isinstance;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5814
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5815 isinstance = PyObject_IsInstance(obj, (PyObject *)Invert_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5816 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5817 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5818 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5819 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5820 *out = Invert;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5821 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5822 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5823 isinstance = PyObject_IsInstance(obj, (PyObject *)Not_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5824 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5825 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5826 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5827 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5828 *out = Not;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5829 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5830 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5831 isinstance = PyObject_IsInstance(obj, (PyObject *)UAdd_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5832 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5833 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5834 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5835 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5836 *out = UAdd;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5837 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5838 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5839 isinstance = PyObject_IsInstance(obj, (PyObject *)USub_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5840 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5841 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5842 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5843 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5844 *out = USub;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5845 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5846 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5847
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5848 tmp = PyObject_Repr(obj);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5849 if (tmp == NULL) goto failed;
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
5850 PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %.400s", PyString_AS_STRING(tmp));
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5851 failed:
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5852 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5853 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5854 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5855
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5856 int
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5857 obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena)
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5858 {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5859 PyObject* tmp = NULL;
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5860 int isinstance;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5861
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5862 isinstance = PyObject_IsInstance(obj, (PyObject *)Eq_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5863 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5864 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5865 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5866 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5867 *out = Eq;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5868 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5869 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5870 isinstance = PyObject_IsInstance(obj, (PyObject *)NotEq_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5871 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5872 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5873 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5874 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5875 *out = NotEq;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5876 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5877 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5878 isinstance = PyObject_IsInstance(obj, (PyObject *)Lt_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5879 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5880 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5881 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5882 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5883 *out = Lt;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5884 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5885 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5886 isinstance = PyObject_IsInstance(obj, (PyObject *)LtE_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5887 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5888 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5889 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5890 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5891 *out = LtE;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5892 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5893 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5894 isinstance = PyObject_IsInstance(obj, (PyObject *)Gt_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5895 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5896 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5897 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5898 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5899 *out = Gt;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5900 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5901 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5902 isinstance = PyObject_IsInstance(obj, (PyObject *)GtE_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5903 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5904 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5905 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5906 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5907 *out = GtE;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5908 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5909 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5910 isinstance = PyObject_IsInstance(obj, (PyObject *)Is_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5911 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5912 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5913 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5914 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5915 *out = Is;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5916 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5917 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5918 isinstance = PyObject_IsInstance(obj, (PyObject *)IsNot_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5919 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5920 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5921 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5922 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5923 *out = IsNot;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5924 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5925 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5926 isinstance = PyObject_IsInstance(obj, (PyObject *)In_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5927 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5928 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5929 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5930 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5931 *out = In;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5932 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5933 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5934 isinstance = PyObject_IsInstance(obj, (PyObject *)NotIn_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5935 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5936 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5937 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
5938 if (isinstance) {
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5939 *out = NotIn;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5940 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5941 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5942
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5943 tmp = PyObject_Repr(obj);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5944 if (tmp == NULL) goto failed;
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
5945 PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %.400s", PyString_AS_STRING(tmp));
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5946 failed:
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5947 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5948 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5949 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5950
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5951 int
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5952 obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena)
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5953 {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5954 PyObject* tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5955 expr_ty target;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5956 expr_ty iter;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5957 asdl_seq* ifs;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5958
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5959 if (PyObject_HasAttrString(obj, "target")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5960 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5961 tmp = PyObject_GetAttrString(obj, "target");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5962 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5963 res = obj2ast_expr(tmp, &target, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5964 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5965 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5966 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5967 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5968 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5969 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5970 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5971 if (PyObject_HasAttrString(obj, "iter")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5972 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5973 tmp = PyObject_GetAttrString(obj, "iter");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5974 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5975 res = obj2ast_expr(tmp, &iter, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5976 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5977 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5978 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5979 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5980 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5981 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5982 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5983 if (PyObject_HasAttrString(obj, "ifs")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5984 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5985 Py_ssize_t len;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5986 Py_ssize_t i;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5987 tmp = PyObject_GetAttrString(obj, "ifs");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5988 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5989 if (!PyList_Check(tmp)) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5990 PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", tmp->ob_type->tp_name);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5991 goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5992 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5993 len = PyList_GET_SIZE(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5994 ifs = asdl_seq_new(len, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5995 if (ifs == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5996 for (i = 0; i < len; i++) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5997 expr_ty value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5998 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
5999 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6000 asdl_seq_SET(ifs, i, value);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6001 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6002 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6003 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6004 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6005 PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6006 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6007 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6008 *out = comprehension(target, iter, ifs, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6009 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6010 failed:
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6011 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6012 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6013 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6014
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6015 int
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6016 obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena)
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6017 {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6018 PyObject* tmp = NULL;
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
6019 int isinstance;
46200
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6020
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6021 int lineno;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6022 int col_offset;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6023
46200
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6024 if (obj == Py_None) {
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6025 *out = NULL;
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6026 return 0;
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6027 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6028 if (PyObject_HasAttrString(obj, "lineno")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6029 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6030 tmp = PyObject_GetAttrString(obj, "lineno");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6031 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6032 res = obj2ast_int(tmp, &lineno, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6033 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6034 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6035 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6036 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6037 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6038 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6039 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6040 if (PyObject_HasAttrString(obj, "col_offset")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6041 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6042 tmp = PyObject_GetAttrString(obj, "col_offset");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6043 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6044 res = obj2ast_int(tmp, &col_offset, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6045 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6046 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6047 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6048 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6049 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6050 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6051 }
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
6052 isinstance = PyObject_IsInstance(obj, (PyObject*)ExceptHandler_type);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
6053 if (isinstance == -1) {
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
6054 return 1;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
6055 }
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
6056 if (isinstance) {
46200
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6057 expr_ty type;
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6058 expr_ty name;
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6059 asdl_seq* body;
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6060
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6061 if (PyObject_HasAttrString(obj, "type")) {
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6062 int res;
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6063 tmp = PyObject_GetAttrString(obj, "type");
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6064 if (tmp == NULL) goto failed;
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6065 res = obj2ast_expr(tmp, &type, arena);
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6066 if (res != 0) goto failed;
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6067 Py_XDECREF(tmp);
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6068 tmp = NULL;
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6069 } else {
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6070 type = NULL;
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6071 }
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6072 if (PyObject_HasAttrString(obj, "name")) {
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6073 int res;
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6074 tmp = PyObject_GetAttrString(obj, "name");
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6075 if (tmp == NULL) goto failed;
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6076 res = obj2ast_expr(tmp, &name, arena);
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6077 if (res != 0) goto failed;
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6078 Py_XDECREF(tmp);
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6079 tmp = NULL;
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6080 } else {
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6081 name = NULL;
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6082 }
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6083 if (PyObject_HasAttrString(obj, "body")) {
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6084 int res;
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6085 Py_ssize_t len;
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6086 Py_ssize_t i;
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6087 tmp = PyObject_GetAttrString(obj, "body");
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6088 if (tmp == NULL) goto failed;
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6089 if (!PyList_Check(tmp)) {
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6090 PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6091 goto failed;
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6092 }
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6093 len = PyList_GET_SIZE(tmp);
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6094 body = asdl_seq_new(len, arena);
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6095 if (body == NULL) goto failed;
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6096 for (i = 0; i < len; i++) {
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6097 stmt_ty value;
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6098 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6099 if (res != 0) goto failed;
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6100 asdl_seq_SET(body, i, value);
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6101 }
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6102 Py_XDECREF(tmp);
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6103 tmp = NULL;
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6104 } else {
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6105 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler");
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6106 return 1;
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6107 }
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6108 *out = ExceptHandler(type, name, body, lineno, col_offset,
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6109 arena);
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6110 if (*out == NULL) goto failed;
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6111 return 0;
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6112 }
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6113
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6114 tmp = PyObject_Repr(obj);
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6115 if (tmp == NULL) goto failed;
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
6116 PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %.400s", PyString_AS_STRING(tmp));
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6117 failed:
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6118 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6119 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6120 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6121
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6122 int
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6123 obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena)
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6124 {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6125 PyObject* tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6126 asdl_seq* args;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6127 identifier vararg;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6128 identifier kwarg;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6129 asdl_seq* defaults;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6130
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6131 if (PyObject_HasAttrString(obj, "args")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6132 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6133 Py_ssize_t len;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6134 Py_ssize_t i;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6135 tmp = PyObject_GetAttrString(obj, "args");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6136 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6137 if (!PyList_Check(tmp)) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6138 PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6139 goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6140 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6141 len = PyList_GET_SIZE(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6142 args = asdl_seq_new(len, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6143 if (args == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6144 for (i = 0; i < len; i++) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6145 expr_ty value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6146 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6147 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6148 asdl_seq_SET(args, i, value);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6149 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6150 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6151 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6152 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6153 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6154 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6155 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6156 if (PyObject_HasAttrString(obj, "vararg")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6157 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6158 tmp = PyObject_GetAttrString(obj, "vararg");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6159 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6160 res = obj2ast_identifier(tmp, &vararg, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6161 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6162 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6163 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6164 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6165 vararg = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6166 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6167 if (PyObject_HasAttrString(obj, "kwarg")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6168 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6169 tmp = PyObject_GetAttrString(obj, "kwarg");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6170 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6171 res = obj2ast_identifier(tmp, &kwarg, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6172 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6173 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6174 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6175 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6176 kwarg = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6177 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6178 if (PyObject_HasAttrString(obj, "defaults")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6179 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6180 Py_ssize_t len;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6181 Py_ssize_t i;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6182 tmp = PyObject_GetAttrString(obj, "defaults");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6183 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6184 if (!PyList_Check(tmp)) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6185 PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6186 goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6187 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6188 len = PyList_GET_SIZE(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6189 defaults = asdl_seq_new(len, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6190 if (defaults == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6191 for (i = 0; i < len; i++) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6192 expr_ty value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6193 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6194 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6195 asdl_seq_SET(defaults, i, value);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6196 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6197 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6198 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6199 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6200 PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6201 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6202 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6203 *out = arguments(args, vararg, kwarg, defaults, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6204 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6205 failed:
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6206 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6207 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6208 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6209
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6210 int
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6211 obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena)
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6212 {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6213 PyObject* tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6214 identifier arg;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6215 expr_ty value;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6216
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6217 if (PyObject_HasAttrString(obj, "arg")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6218 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6219 tmp = PyObject_GetAttrString(obj, "arg");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6220 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6221 res = obj2ast_identifier(tmp, &arg, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6222 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6223 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6224 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6225 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6226 PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from keyword");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6227 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6228 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6229 if (PyObject_HasAttrString(obj, "value")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6230 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6231 tmp = PyObject_GetAttrString(obj, "value");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6232 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6233 res = obj2ast_expr(tmp, &value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6234 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6235 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6236 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6237 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6238 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6239 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6240 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6241 *out = keyword(arg, value, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6242 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6243 failed:
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6244 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6245 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6246 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6247
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6248 int
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6249 obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena)
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6250 {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6251 PyObject* tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6252 identifier name;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6253 identifier asname;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6254
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6255 if (PyObject_HasAttrString(obj, "name")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6256 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6257 tmp = PyObject_GetAttrString(obj, "name");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6258 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6259 res = obj2ast_identifier(tmp, &name, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6260 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6261 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6262 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6263 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6264 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6265 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6266 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6267 if (PyObject_HasAttrString(obj, "asname")) {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6268 int res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6269 tmp = PyObject_GetAttrString(obj, "asname");
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6270 if (tmp == NULL) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6271 res = obj2ast_identifier(tmp, &asname, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6272 if (res != 0) goto failed;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6273 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6274 tmp = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6275 } else {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6276 asname = NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6277 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6278 *out = alias(name, asname, arena);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6279 return 0;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6280 failed:
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6281 Py_XDECREF(tmp);
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6282 return 1;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6283 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6284
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6285
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
6286 PyMODINIT_FUNC
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
6287 init_ast(void)
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
6288 {
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
6289 PyObject *m, *d;
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
6290 if (!init_types()) return;
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
6291 m = Py_InitModule3("_ast", NULL, NULL);
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
6292 if (!m) return;
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
6293 d = PyModule_GetDict(m);
46202
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
6294 if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return;
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
6295 if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
6296 return;
54744
247f8d268d58 update ast version
Benjamin Peterson <benjamin@python.org>
parents: 54743
diff changeset
6297 if (PyModule_AddStringConstant(m, "__version__", "73421") < 0)
36707
cd847e726837 Regenerate.
Martin v. Löwis <martin@v.loewis.de>
parents: 36695
diff changeset
6298 return;
37412
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6299 if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6300 if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0)
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6301 return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6302 if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type)
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6303 < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6304 if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) <
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6305 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6306 if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6307 if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6308 if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type)
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6309 < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6310 if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0)
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6311 return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6312 if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0)
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6313 return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6314 if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0)
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6315 return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6316 if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0)
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6317 return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6318 if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) <
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6319 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6320 if (PyDict_SetItemString(d, "Print", (PyObject*)Print_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6321 if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6322 if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6323 if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6324 if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6325 if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6326 if (PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) <
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6327 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6328 if (PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) <
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6329 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6330 if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0)
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6331 return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6332 if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0)
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6333 return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6334 if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) <
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6335 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6336 if (PyDict_SetItemString(d, "Exec", (PyObject*)Exec_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6337 if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0)
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6338 return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6339 if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6340 if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6341 if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6342 if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0)
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6343 return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6344 if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6345 if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0)
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6346 return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6347 if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6348 if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0)
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6349 return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6350 if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0)
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6351 return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6352 if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6353 if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6354 if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0)
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6355 return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6356 if (PyDict_SetItemString(d, "GeneratorExp",
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6357 (PyObject*)GeneratorExp_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6358 if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6359 if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0)
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6360 return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6361 if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6362 if (PyDict_SetItemString(d, "Repr", (PyObject*)Repr_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6363 if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6364 if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6365 if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) <
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6366 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6367 if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) <
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6368 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6369 if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6370 if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6371 if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6372 if (PyDict_SetItemString(d, "expr_context",
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6373 (PyObject*)expr_context_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6374 if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6375 if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6376 if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6377 if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0)
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6378 return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6379 if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0)
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6380 return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6381 if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6382 if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6383 if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0)
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6384 return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6385 if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6386 if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0)
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6387 return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6388 if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6389 if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0)
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6390 return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6391 if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6392 if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6393 if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0)
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6394 return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6395 if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6396 if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6397 if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6398 if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6399 if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6400 if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6401 if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0)
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6402 return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6403 if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0)
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6404 return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6405 if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6406 if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0)
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6407 return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6408 if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0)
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6409 return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6410 if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0)
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6411 return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6412 if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0)
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6413 return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6414 if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0)
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6415 return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6416 if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6417 if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6418 if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6419 if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6420 if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6421 if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6422 if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6423 if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6424 if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6425 if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6426 if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6427 if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6428 if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6429 if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6430 if (PyDict_SetItemString(d, "comprehension",
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6431 (PyObject*)comprehension_type) < 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6432 if (PyDict_SetItemString(d, "excepthandler",
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6433 (PyObject*)excepthandler_type) < 0) return;
46200
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6434 if (PyDict_SetItemString(d, "ExceptHandler",
2ff88ae9850c Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents: 46193
diff changeset
6435 (PyObject*)ExceptHandler_type) < 0) return;
37412
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6436 if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) <
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6437 0) return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6438 if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0)
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6439 return;
dfc33ec7f73a * Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36794
diff changeset
6440 if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return;
36669
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
6441 }
9504f7ac3669 Create _ast module.
Martin v. Löwis <martin@v.loewis.de>
parents: 36666
diff changeset
6442
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
6443
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
6444 PyObject* PyAST_mod2obj(mod_ty t)
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
6445 {
36660
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
6446 init_types();
3c0b26113df6 Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents: 36174
diff changeset
6447 return ast2obj_mod(t);
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
6448 }
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
6449
46193
b0bf06d49647 Properly check for consistency with the third argument of
Georg Brandl <georg@python.org>
parents: 46168
diff changeset
6450 /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */
b0bf06d49647 Properly check for consistency with the third argument of
Georg Brandl <georg@python.org>
parents: 46168
diff changeset
6451 mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode)
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6452 {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6453 mod_ty res;
46193
b0bf06d49647 Properly check for consistency with the third argument of
Georg Brandl <georg@python.org>
parents: 46168
diff changeset
6454 PyObject *req_type[] = {(PyObject*)Module_type, (PyObject*)Expression_type,
b0bf06d49647 Properly check for consistency with the third argument of
Georg Brandl <georg@python.org>
parents: 46168
diff changeset
6455 (PyObject*)Interactive_type};
b0bf06d49647 Properly check for consistency with the third argument of
Georg Brandl <georg@python.org>
parents: 46168
diff changeset
6456 char *req_name[] = {"Module", "Expression", "Interactive"};
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
6457 int isinstance;
46193
b0bf06d49647 Properly check for consistency with the third argument of
Georg Brandl <georg@python.org>
parents: 46168
diff changeset
6458 assert(0 <= mode && mode <= 2);
b0bf06d49647 Properly check for consistency with the third argument of
Georg Brandl <georg@python.org>
parents: 46168
diff changeset
6459
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6460 init_types();
46193
b0bf06d49647 Properly check for consistency with the third argument of
Georg Brandl <georg@python.org>
parents: 46168
diff changeset
6461
57673
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
6462 isinstance = PyObject_IsInstance(ast, req_type[mode]);
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
6463 if (isinstance == -1)
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
6464 return NULL;
20b7deb53d4e account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents: 54744
diff changeset
6465 if (!isinstance) {
46193
b0bf06d49647 Properly check for consistency with the third argument of
Georg Brandl <georg@python.org>
parents: 46168
diff changeset
6466 PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s",
b0bf06d49647 Properly check for consistency with the third argument of
Georg Brandl <georg@python.org>
parents: 46168
diff changeset
6467 req_name[mode], Py_TYPE(ast)->tp_name);
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6468 return NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6469 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6470 if (obj2ast_mod(ast, &res, arena) != 0)
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6471 return NULL;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6472 else
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6473 return res;
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6474 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6475
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6476 int PyAST_Check(PyObject* obj)
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6477 {
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6478 init_types();
46202
42c5d287a852 #2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents: 46200
diff changeset
6479 return PyObject_IsInstance(obj, (PyObject*)&AST_type);
46162
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6480 }
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6481
ca38f7a4b4c9 Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents: 45470
diff changeset
6482