Mercurial > cpython-lru_cache-weakref
annotate Python/Python-ast.c @ 61622:1d4dbfa8ed4f legacy-trunk
Use 4-spaces for indentation (instead of tabs) in pgen outputs
Regenerate (reindent) Python/graminit.c
| author | Victor Stinner <victor.stinner@haypocalc.com> |
|---|---|
| date | Sat, 15 May 2010 22:55:28 +0000 |
| parents | 8a5ac9ff5057 |
| children | 5bf7336ea0aa |
| 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 /* |
|
58251
8a5ac9ff5057
Update version information for AST changes in r77422.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58250
diff
changeset
|
5 __version__ 77422. |
|
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 | 11 |
| 12 #include "Python.h" | |
| 13 #include "Python-ast.h" | |
| 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 | 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 | 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 | 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 | 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 }; |
|
58229
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
191 static PyTypeObject *Set_type; |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
192 static char *Set_fields[]={ |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
193 "elts", |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
194 }; |
|
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
|
195 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
|
196 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
|
197 "elt", |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
198 "generators", |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
199 }; |
|
58250
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
200 static PyTypeObject *SetComp_type; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
201 static char *SetComp_fields[]={ |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
202 "elt", |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
203 "generators", |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
204 }; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
205 static PyTypeObject *DictComp_type; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
206 static char *DictComp_fields[]={ |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
207 "key", |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
208 "value", |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
209 "generators", |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
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 *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
|
212 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
|
213 "elt", |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
214 "generators", |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
215 }; |
|
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
|
216 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
|
217 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
|
218 "value", |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
219 }; |
|
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
|
220 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
|
221 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
|
222 "left", |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
223 "ops", |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
224 "comparators", |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
225 }; |
|
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
|
226 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
|
227 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
|
228 "func", |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
229 "args", |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
230 "keywords", |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
231 "starargs", |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
232 "kwargs", |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
233 }; |
|
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
|
234 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
|
235 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
|
236 "value", |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
237 }; |
|
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
|
238 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
|
239 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
|
240 "n", |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
241 }; |
|
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
|
242 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
|
243 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
|
244 "s", |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
245 }; |
|
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
|
246 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
|
247 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
|
248 "value", |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
249 "attr", |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
250 "ctx", |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
251 }; |
|
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
|
252 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
|
253 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
|
254 "value", |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
255 "slice", |
|
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 *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
|
259 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
|
260 "id", |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
261 "ctx", |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
262 }; |
|
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
|
263 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
|
264 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
|
265 "elts", |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
266 "ctx", |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
267 }; |
|
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
|
268 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
|
269 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
|
270 "elts", |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
271 "ctx", |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
272 }; |
|
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
|
273 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
|
274 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
|
275 *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
|
276 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
|
277 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
|
278 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
|
279 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
|
280 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
|
281 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
|
282 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
|
283 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
|
284 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
|
285 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
|
286 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
|
287 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
|
288 "lower", |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
289 "upper", |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
290 "step", |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
291 }; |
|
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
|
292 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
|
293 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
|
294 "dims", |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
295 }; |
|
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 *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
|
297 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
|
298 "value", |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
299 }; |
|
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
|
300 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
|
301 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
|
302 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
|
303 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
|
304 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
|
305 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
|
306 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
|
307 *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
|
308 *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
|
309 *FloorDiv_singleton; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
310 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
|
311 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
|
312 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
|
313 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
|
314 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
|
315 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
|
316 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
|
317 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
|
318 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
|
319 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
|
320 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
|
321 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
|
322 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
|
323 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
|
324 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
|
325 *USub_singleton; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
326 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
|
327 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
|
328 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
|
329 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
|
330 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
|
331 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
|
332 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
|
333 *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
|
334 *NotIn_singleton; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
335 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
|
336 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
|
337 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
|
338 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
|
339 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
|
340 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
|
341 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
|
342 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
|
343 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
|
344 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
|
345 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
|
346 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
|
347 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
|
348 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
|
349 "target", |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
350 "iter", |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
351 "ifs", |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
352 }; |
|
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
|
353 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
|
354 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
|
355 "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
|
356 "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
|
357 }; |
|
36660
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
358 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
|
359 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
|
360 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
|
361 "type", |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
362 "name", |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
363 "body", |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
364 }; |
|
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
|
365 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
|
366 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
|
367 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
|
368 "args", |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
369 "vararg", |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
370 "kwarg", |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
371 "defaults", |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
372 }; |
|
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
|
373 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
|
374 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
|
375 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
|
376 "arg", |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
377 "value", |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
378 }; |
|
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
|
379 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
|
380 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
|
381 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
|
382 "name", |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
383 "asname", |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
384 }; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
385 |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
386 |
|
46202
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
387 static int |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
388 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
|
389 { |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
390 Py_ssize_t i, numfields = 0; |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
391 int res = -1; |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
392 PyObject *key, *value, *fields; |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
393 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
|
394 if (!fields) |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
395 PyErr_Clear(); |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
396 if (fields) { |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
397 numfields = PySequence_Size(fields); |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
398 if (numfields == -1) |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
399 goto cleanup; |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
400 } |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
401 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
|
402 if (PyTuple_GET_SIZE(args) > 0) { |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
403 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
|
404 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
|
405 "%zd positional argument%s", |
|
46207
59d42e6d1885
Fix error message -- "expects either 0 or 0 arguments"
Georg Brandl <georg@python.org>
parents:
46204
diff
changeset
|
406 Py_TYPE(self)->tp_name, |
|
59d42e6d1885
Fix error message -- "expects either 0 or 0 arguments"
Georg Brandl <georg@python.org>
parents:
46204
diff
changeset
|
407 numfields == 0 ? "" : "either 0 or ", |
|
46202
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
408 numfields, numfields == 1 ? "" : "s"); |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
409 res = -1; |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
410 goto cleanup; |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
411 } |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
412 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
|
413 /* cannot be reached when fields is NULL */ |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
414 PyObject *name = PySequence_GetItem(fields, i); |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
415 if (!name) { |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
416 res = -1; |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
417 goto cleanup; |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
418 } |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
419 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
|
420 Py_DECREF(name); |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
421 if (res < 0) |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
422 goto cleanup; |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
423 } |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
424 } |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
425 if (kw) { |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
426 i = 0; /* needed by PyDict_Next */ |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
427 while (PyDict_Next(kw, &i, &key, &value)) { |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
428 res = PyObject_SetAttr(self, key, value); |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
429 if (res < 0) |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
430 goto cleanup; |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
431 } |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
432 } |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
433 cleanup: |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
434 Py_XDECREF(fields); |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
435 return res; |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
436 } |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
437 |
|
46212
be18df634405
Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents:
46207
diff
changeset
|
438 /* Pickling support */ |
|
be18df634405
Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents:
46207
diff
changeset
|
439 static PyObject * |
|
be18df634405
Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents:
46207
diff
changeset
|
440 ast_type_reduce(PyObject *self, PyObject *unused) |
|
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 PyObject *res; |
|
be18df634405
Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents:
46207
diff
changeset
|
443 PyObject *dict = PyObject_GetAttrString(self, "__dict__"); |
|
be18df634405
Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents:
46207
diff
changeset
|
444 if (dict == NULL) { |
|
be18df634405
Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents:
46207
diff
changeset
|
445 if (PyErr_ExceptionMatches(PyExc_AttributeError)) |
|
be18df634405
Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents:
46207
diff
changeset
|
446 PyErr_Clear(); |
|
be18df634405
Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents:
46207
diff
changeset
|
447 else |
|
be18df634405
Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents:
46207
diff
changeset
|
448 return NULL; |
|
be18df634405
Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents:
46207
diff
changeset
|
449 } |
|
be18df634405
Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents:
46207
diff
changeset
|
450 if (dict) { |
|
be18df634405
Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents:
46207
diff
changeset
|
451 res = Py_BuildValue("O()O", Py_TYPE(self), dict); |
|
be18df634405
Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents:
46207
diff
changeset
|
452 Py_DECREF(dict); |
|
be18df634405
Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents:
46207
diff
changeset
|
453 return res; |
|
be18df634405
Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents:
46207
diff
changeset
|
454 } |
|
be18df634405
Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents:
46207
diff
changeset
|
455 return Py_BuildValue("O()", Py_TYPE(self)); |
|
be18df634405
Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents:
46207
diff
changeset
|
456 } |
|
be18df634405
Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents:
46207
diff
changeset
|
457 |
|
be18df634405
Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents:
46207
diff
changeset
|
458 static PyMethodDef ast_type_methods[] = { |
|
be18df634405
Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents:
46207
diff
changeset
|
459 {"__reduce__", ast_type_reduce, METH_NOARGS, NULL}, |
|
be18df634405
Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents:
46207
diff
changeset
|
460 {NULL} |
|
be18df634405
Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents:
46207
diff
changeset
|
461 }; |
|
be18df634405
Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents:
46207
diff
changeset
|
462 |
|
46202
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
463 static PyTypeObject AST_type = { |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
464 PyVarObject_HEAD_INIT(&PyType_Type, 0) |
|
46212
be18df634405
Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents:
46207
diff
changeset
|
465 "_ast.AST", |
|
46202
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
466 sizeof(PyObject), |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
467 0, |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
468 0, /* tp_dealloc */ |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
469 0, /* tp_print */ |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
470 0, /* tp_getattr */ |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
471 0, /* tp_setattr */ |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
472 0, /* tp_compare */ |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
473 0, /* tp_repr */ |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
474 0, /* tp_as_number */ |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
475 0, /* tp_as_sequence */ |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
476 0, /* tp_as_mapping */ |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
477 0, /* tp_hash */ |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
478 0, /* tp_call */ |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
479 0, /* tp_str */ |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
480 PyObject_GenericGetAttr, /* tp_getattro */ |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
481 PyObject_GenericSetAttr, /* tp_setattro */ |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
482 0, /* tp_as_buffer */ |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
483 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
|
484 0, /* tp_doc */ |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
485 0, /* tp_traverse */ |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
486 0, /* tp_clear */ |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
487 0, /* tp_richcompare */ |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
488 0, /* tp_weaklistoffset */ |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
489 0, /* tp_iter */ |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
490 0, /* tp_iternext */ |
|
46212
be18df634405
Make AST nodes pickleable.
Georg Brandl <georg@python.org>
parents:
46207
diff
changeset
|
491 ast_type_methods, /* tp_methods */ |
|
46202
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
492 0, /* tp_members */ |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
493 0, /* tp_getset */ |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
494 0, /* tp_base */ |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
495 0, /* tp_dict */ |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
496 0, /* tp_descr_get */ |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
497 0, /* tp_descr_set */ |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
498 0, /* tp_dictoffset */ |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
499 (initproc)ast_type_init, /* tp_init */ |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
500 PyType_GenericAlloc, /* tp_alloc */ |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
501 PyType_GenericNew, /* tp_new */ |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
502 PyObject_Del, /* tp_free */ |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
503 }; |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
504 |
|
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
505 |
|
36660
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
506 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
|
507 { |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
508 PyObject *fnames, *result; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
509 int i; |
|
46204
29ea507fd998
Make _fields attr for no fields consistent with _attributes attr.
Georg Brandl <georg@python.org>
parents:
46202
diff
changeset
|
510 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
|
511 if (!fnames) return NULL; |
|
29ea507fd998
Make _fields attr for no fields consistent with _attributes attr.
Georg Brandl <georg@python.org>
parents:
46202
diff
changeset
|
512 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
|
513 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
|
514 if (!field) { |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
515 Py_DECREF(fnames); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
516 return NULL; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
517 } |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
518 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
|
519 } |
|
36726
bbf16fd024df
from __future__ import with_statement addon for 'with', mostly written by
Thomas Wouters <thomas@python.org>
parents:
36712
diff
changeset
|
520 result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}", |
| 36669 | 521 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
|
522 Py_DECREF(fnames); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
523 return (PyTypeObject*)result; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
524 } |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
525 |
| 36669 | 526 static int add_attributes(PyTypeObject* type, char**attrs, int num_fields) |
| 527 { | |
|
37412
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
528 int i, result; |
|
46202
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
529 PyObject *s, *l = PyTuple_New(num_fields); |
| 36669 | 530 if (!l) return 0; |
|
37412
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
531 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
|
532 s = PyString_FromString(attrs[i]); |
| 36669 | 533 if (!s) { |
| 534 Py_DECREF(l); | |
| 535 return 0; | |
| 536 } | |
|
46202
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
537 PyTuple_SET_ITEM(l, i, s); |
| 36669 | 538 } |
|
37412
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
539 result = PyObject_SetAttrString((PyObject*)type, "_attributes", l) >= 0; |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
540 Py_DECREF(l); |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
541 return result; |
| 36669 | 542 } |
| 543 | |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
544 /* Conversion AST -> Python */ |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
545 |
|
36660
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
546 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
|
547 { |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
548 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
|
549 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
|
550 PyObject *value; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
551 if (!result) |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
552 return NULL; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
553 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
|
554 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
|
555 if (!value) { |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
556 Py_DECREF(result); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
557 return NULL; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
558 } |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
559 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
|
560 } |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
561 return result; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
562 } |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
563 |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
564 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
|
565 { |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
566 if (!o) |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
567 o = Py_None; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
568 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
|
569 return (PyObject*)o; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
570 } |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
571 #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
|
572 #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
|
573 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
|
574 { |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
575 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
|
576 } |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
577 |
|
40936
0376f13a1af9
Fix a couple of problems in generating the AST code:
Neal Norwitz <nnorwitz@gmail.com>
parents:
40824
diff
changeset
|
578 static PyObject* ast2obj_int(long b) |
| 36669 | 579 { |
| 580 return PyInt_FromLong(b); | |
| 581 } | |
| 582 | |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
583 /* Conversion Python -> AST */ |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
584 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
585 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
|
586 { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
587 if (obj == Py_None) |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
588 obj = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
589 if (obj) |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
590 PyArena_AddPyObject(arena, obj); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
591 Py_XINCREF(obj); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
592 *out = obj; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
593 return 0; |
|
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 #define obj2ast_identifier obj2ast_object |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
597 #define obj2ast_string obj2ast_object |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
598 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
599 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
|
600 { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
601 int i; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
602 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
|
603 PyObject *s = PyObject_Repr(obj); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
604 if (s == NULL) return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
605 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
|
606 PyString_AS_STRING(s)); |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
607 Py_DECREF(s); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
608 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
609 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
610 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
611 i = (int)PyLong_AsLong(obj); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
612 if (i == -1 && PyErr_Occurred()) |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
613 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
614 *out = i; |
|
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 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
618 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
|
619 { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
620 if (!PyBool_Check(obj)) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
621 PyObject *s = PyObject_Repr(obj); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
622 if (s == NULL) return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
623 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
|
624 PyString_AS_STRING(s)); |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
625 Py_DECREF(s); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
626 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
627 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
628 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
629 *out = (obj == Py_True); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
630 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
631 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
632 |
|
49552
2e38ca709b1d
fix compiler warning
Benjamin Peterson <benjamin@python.org>
parents:
49551
diff
changeset
|
633 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
|
634 { |
|
dbd54bac0b6f
Fixed #4067 by implementing _attributes and _fields for the AST root node.
Armin Ronacher <armin.ronacher@active-4.com>
parents:
49138
diff
changeset
|
635 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
|
636 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
|
637 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
|
638 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
|
639 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
|
640 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
|
641 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
|
642 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
|
643 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
|
644 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
|
645 } |
|
dbd54bac0b6f
Fixed #4067 by implementing _attributes and _fields for the AST root node.
Armin Ronacher <armin.ronacher@active-4.com>
parents:
49138
diff
changeset
|
646 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
|
647 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
|
648 } |
|
dbd54bac0b6f
Fixed #4067 by implementing _attributes and _fields for the AST root node.
Armin Ronacher <armin.ronacher@active-4.com>
parents:
49138
diff
changeset
|
649 |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
650 |
|
36660
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
651 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
|
652 { |
|
37412
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
653 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
|
654 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
|
655 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
|
656 mod_type = make_type("mod", &AST_type, NULL, 0); |
| 36669 | 657 if (!mod_type) return 0; |
| 658 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
|
659 Module_type = make_type("Module", mod_type, Module_fields, 1); |
| 36669 | 660 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
|
661 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
|
662 Interactive_fields, 1); |
| 36669 | 663 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
|
664 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
|
665 1); |
| 36669 | 666 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
|
667 Suite_type = make_type("Suite", mod_type, Suite_fields, 1); |
| 36669 | 668 if (!Suite_type) return 0; |
|
46202
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
669 stmt_type = make_type("stmt", &AST_type, NULL, 0); |
| 36669 | 670 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
|
671 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
|
672 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
|
673 FunctionDef_fields, 4); |
| 36669 | 674 if (!FunctionDef_type) return 0; |
|
45447
393822f2ef90
Patch #1759: Backport of PEP 3129 class decorators
Christian Heimes <christian@cheimes.de>
parents:
40936
diff
changeset
|
675 ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 4); |
| 36669 | 676 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
|
677 Return_type = make_type("Return", stmt_type, Return_fields, 1); |
| 36669 | 678 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
|
679 Delete_type = make_type("Delete", stmt_type, Delete_fields, 1); |
| 36669 | 680 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
|
681 Assign_type = make_type("Assign", stmt_type, Assign_fields, 2); |
| 36669 | 682 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
|
683 AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3); |
| 36669 | 684 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
|
685 Print_type = make_type("Print", stmt_type, Print_fields, 3); |
| 36669 | 686 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
|
687 For_type = make_type("For", stmt_type, For_fields, 4); |
| 36669 | 688 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
|
689 While_type = make_type("While", stmt_type, While_fields, 3); |
| 36669 | 690 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
|
691 If_type = make_type("If", stmt_type, If_fields, 3); |
| 36669 | 692 if (!If_type) return 0; |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36669
diff
changeset
|
693 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
|
694 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
|
695 Raise_type = make_type("Raise", stmt_type, Raise_fields, 3); |
| 36669 | 696 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
|
697 TryExcept_type = make_type("TryExcept", stmt_type, TryExcept_fields, 3); |
| 36669 | 698 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
|
699 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
|
700 2); |
| 36669 | 701 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
|
702 Assert_type = make_type("Assert", stmt_type, Assert_fields, 2); |
| 36669 | 703 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
|
704 Import_type = make_type("Import", stmt_type, Import_fields, 1); |
| 36669 | 705 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
|
706 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
|
707 3); |
| 36669 | 708 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
|
709 Exec_type = make_type("Exec", stmt_type, Exec_fields, 3); |
| 36669 | 710 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
|
711 Global_type = make_type("Global", stmt_type, Global_fields, 1); |
| 36669 | 712 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
|
713 Expr_type = make_type("Expr", stmt_type, Expr_fields, 1); |
| 36669 | 714 if (!Expr_type) return 0; |
|
36664
7bfbfb2ef4e2
Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents:
36661
diff
changeset
|
715 Pass_type = make_type("Pass", stmt_type, NULL, 0); |
| 36669 | 716 if (!Pass_type) return 0; |
|
36664
7bfbfb2ef4e2
Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents:
36661
diff
changeset
|
717 Break_type = make_type("Break", stmt_type, NULL, 0); |
| 36669 | 718 if (!Break_type) return 0; |
|
36664
7bfbfb2ef4e2
Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents:
36661
diff
changeset
|
719 Continue_type = make_type("Continue", stmt_type, NULL, 0); |
| 36669 | 720 if (!Continue_type) return 0; |
|
46202
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
721 expr_type = make_type("expr", &AST_type, NULL, 0); |
| 36669 | 722 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
|
723 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
|
724 BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2); |
| 36669 | 725 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
|
726 BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3); |
| 36669 | 727 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
|
728 UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2); |
| 36669 | 729 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
|
730 Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2); |
| 36669 | 731 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
|
732 IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3); |
| 36669 | 733 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
|
734 Dict_type = make_type("Dict", expr_type, Dict_fields, 2); |
| 36669 | 735 if (!Dict_type) return 0; |
|
58229
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
736 Set_type = make_type("Set", expr_type, Set_fields, 1); |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
737 if (!Set_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 ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2); |
| 36669 | 739 if (!ListComp_type) return 0; |
|
58250
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
740 SetComp_type = make_type("SetComp", expr_type, SetComp_fields, 2); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
741 if (!SetComp_type) return 0; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
742 DictComp_type = make_type("DictComp", expr_type, DictComp_fields, 3); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
743 if (!DictComp_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 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
|
745 GeneratorExp_fields, 2); |
| 36669 | 746 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
|
747 Yield_type = make_type("Yield", expr_type, Yield_fields, 1); |
| 36669 | 748 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
|
749 Compare_type = make_type("Compare", expr_type, Compare_fields, 3); |
| 36669 | 750 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
|
751 Call_type = make_type("Call", expr_type, Call_fields, 5); |
| 36669 | 752 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
|
753 Repr_type = make_type("Repr", expr_type, Repr_fields, 1); |
| 36669 | 754 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
|
755 Num_type = make_type("Num", expr_type, Num_fields, 1); |
| 36669 | 756 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
|
757 Str_type = make_type("Str", expr_type, Str_fields, 1); |
| 36669 | 758 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
|
759 Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3); |
| 36669 | 760 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
|
761 Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3); |
| 36669 | 762 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
|
763 Name_type = make_type("Name", expr_type, Name_fields, 2); |
| 36669 | 764 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
|
765 List_type = make_type("List", expr_type, List_fields, 2); |
| 36669 | 766 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
|
767 Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2); |
| 36669 | 768 if (!Tuple_type) return 0; |
|
46202
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
769 expr_context_type = make_type("expr_context", &AST_type, NULL, 0); |
| 36669 | 770 if (!expr_context_type) return 0; |
| 771 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
|
772 Load_type = make_type("Load", expr_context_type, NULL, 0); |
| 36669 | 773 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
|
774 Load_singleton = PyType_GenericNew(Load_type, NULL, NULL); |
| 36669 | 775 if (!Load_singleton) return 0; |
|
36664
7bfbfb2ef4e2
Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents:
36661
diff
changeset
|
776 Store_type = make_type("Store", expr_context_type, NULL, 0); |
| 36669 | 777 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
|
778 Store_singleton = PyType_GenericNew(Store_type, NULL, NULL); |
| 36669 | 779 if (!Store_singleton) return 0; |
|
36664
7bfbfb2ef4e2
Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents:
36661
diff
changeset
|
780 Del_type = make_type("Del", expr_context_type, NULL, 0); |
| 36669 | 781 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
|
782 Del_singleton = PyType_GenericNew(Del_type, NULL, NULL); |
| 36669 | 783 if (!Del_singleton) return 0; |
|
36664
7bfbfb2ef4e2
Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents:
36661
diff
changeset
|
784 AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0); |
| 36669 | 785 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
|
786 AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL); |
| 36669 | 787 if (!AugLoad_singleton) return 0; |
|
36664
7bfbfb2ef4e2
Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents:
36661
diff
changeset
|
788 AugStore_type = make_type("AugStore", expr_context_type, NULL, 0); |
| 36669 | 789 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
|
790 AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL); |
| 36669 | 791 if (!AugStore_singleton) return 0; |
|
36664
7bfbfb2ef4e2
Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents:
36661
diff
changeset
|
792 Param_type = make_type("Param", expr_context_type, NULL, 0); |
| 36669 | 793 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
|
794 Param_singleton = PyType_GenericNew(Param_type, NULL, NULL); |
| 36669 | 795 if (!Param_singleton) return 0; |
|
46202
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
796 slice_type = make_type("slice", &AST_type, NULL, 0); |
| 36669 | 797 if (!slice_type) return 0; |
| 798 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
|
799 Ellipsis_type = make_type("Ellipsis", slice_type, NULL, 0); |
| 36669 | 800 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
|
801 Slice_type = make_type("Slice", slice_type, Slice_fields, 3); |
| 36669 | 802 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
|
803 ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1); |
| 36669 | 804 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
|
805 Index_type = make_type("Index", slice_type, Index_fields, 1); |
| 36669 | 806 if (!Index_type) return 0; |
|
46202
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
807 boolop_type = make_type("boolop", &AST_type, NULL, 0); |
| 36669 | 808 if (!boolop_type) return 0; |
| 809 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
|
810 And_type = make_type("And", boolop_type, NULL, 0); |
| 36669 | 811 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
|
812 And_singleton = PyType_GenericNew(And_type, NULL, NULL); |
| 36669 | 813 if (!And_singleton) return 0; |
|
36664
7bfbfb2ef4e2
Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents:
36661
diff
changeset
|
814 Or_type = make_type("Or", boolop_type, NULL, 0); |
| 36669 | 815 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
|
816 Or_singleton = PyType_GenericNew(Or_type, NULL, NULL); |
| 36669 | 817 if (!Or_singleton) return 0; |
|
46202
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
818 operator_type = make_type("operator", &AST_type, NULL, 0); |
| 36669 | 819 if (!operator_type) return 0; |
| 820 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
|
821 Add_type = make_type("Add", operator_type, NULL, 0); |
| 36669 | 822 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
|
823 Add_singleton = PyType_GenericNew(Add_type, NULL, NULL); |
| 36669 | 824 if (!Add_singleton) return 0; |
|
36664
7bfbfb2ef4e2
Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents:
36661
diff
changeset
|
825 Sub_type = make_type("Sub", operator_type, NULL, 0); |
| 36669 | 826 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
|
827 Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL); |
| 36669 | 828 if (!Sub_singleton) return 0; |
|
36664
7bfbfb2ef4e2
Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents:
36661
diff
changeset
|
829 Mult_type = make_type("Mult", operator_type, NULL, 0); |
| 36669 | 830 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
|
831 Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL); |
| 36669 | 832 if (!Mult_singleton) return 0; |
|
36664
7bfbfb2ef4e2
Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents:
36661
diff
changeset
|
833 Div_type = make_type("Div", operator_type, NULL, 0); |
| 36669 | 834 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
|
835 Div_singleton = PyType_GenericNew(Div_type, NULL, NULL); |
| 36669 | 836 if (!Div_singleton) return 0; |
|
36664
7bfbfb2ef4e2
Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents:
36661
diff
changeset
|
837 Mod_type = make_type("Mod", operator_type, NULL, 0); |
| 36669 | 838 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
|
839 Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL); |
| 36669 | 840 if (!Mod_singleton) return 0; |
|
36664
7bfbfb2ef4e2
Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents:
36661
diff
changeset
|
841 Pow_type = make_type("Pow", operator_type, NULL, 0); |
| 36669 | 842 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
|
843 Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL); |
| 36669 | 844 if (!Pow_singleton) return 0; |
|
36664
7bfbfb2ef4e2
Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents:
36661
diff
changeset
|
845 LShift_type = make_type("LShift", operator_type, NULL, 0); |
| 36669 | 846 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
|
847 LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL); |
| 36669 | 848 if (!LShift_singleton) return 0; |
|
36664
7bfbfb2ef4e2
Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents:
36661
diff
changeset
|
849 RShift_type = make_type("RShift", operator_type, NULL, 0); |
| 36669 | 850 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
|
851 RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL); |
| 36669 | 852 if (!RShift_singleton) return 0; |
|
36664
7bfbfb2ef4e2
Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents:
36661
diff
changeset
|
853 BitOr_type = make_type("BitOr", operator_type, NULL, 0); |
| 36669 | 854 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
|
855 BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL); |
| 36669 | 856 if (!BitOr_singleton) return 0; |
|
36664
7bfbfb2ef4e2
Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents:
36661
diff
changeset
|
857 BitXor_type = make_type("BitXor", operator_type, NULL, 0); |
| 36669 | 858 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
|
859 BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL); |
| 36669 | 860 if (!BitXor_singleton) return 0; |
|
36664
7bfbfb2ef4e2
Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents:
36661
diff
changeset
|
861 BitAnd_type = make_type("BitAnd", operator_type, NULL, 0); |
| 36669 | 862 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
|
863 BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL); |
| 36669 | 864 if (!BitAnd_singleton) return 0; |
|
36664
7bfbfb2ef4e2
Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents:
36661
diff
changeset
|
865 FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0); |
| 36669 | 866 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
|
867 FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL); |
| 36669 | 868 if (!FloorDiv_singleton) return 0; |
|
46202
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
869 unaryop_type = make_type("unaryop", &AST_type, NULL, 0); |
| 36669 | 870 if (!unaryop_type) return 0; |
| 871 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
|
872 Invert_type = make_type("Invert", unaryop_type, NULL, 0); |
| 36669 | 873 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
|
874 Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL); |
| 36669 | 875 if (!Invert_singleton) return 0; |
|
36664
7bfbfb2ef4e2
Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents:
36661
diff
changeset
|
876 Not_type = make_type("Not", unaryop_type, NULL, 0); |
| 36669 | 877 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
|
878 Not_singleton = PyType_GenericNew(Not_type, NULL, NULL); |
| 36669 | 879 if (!Not_singleton) return 0; |
|
36664
7bfbfb2ef4e2
Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents:
36661
diff
changeset
|
880 UAdd_type = make_type("UAdd", unaryop_type, NULL, 0); |
| 36669 | 881 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
|
882 UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL); |
| 36669 | 883 if (!UAdd_singleton) return 0; |
|
36664
7bfbfb2ef4e2
Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents:
36661
diff
changeset
|
884 USub_type = make_type("USub", unaryop_type, NULL, 0); |
| 36669 | 885 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
|
886 USub_singleton = PyType_GenericNew(USub_type, NULL, NULL); |
| 36669 | 887 if (!USub_singleton) return 0; |
|
46202
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
888 cmpop_type = make_type("cmpop", &AST_type, NULL, 0); |
| 36669 | 889 if (!cmpop_type) return 0; |
| 890 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
|
891 Eq_type = make_type("Eq", cmpop_type, NULL, 0); |
| 36669 | 892 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
|
893 Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL); |
| 36669 | 894 if (!Eq_singleton) return 0; |
|
36664
7bfbfb2ef4e2
Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents:
36661
diff
changeset
|
895 NotEq_type = make_type("NotEq", cmpop_type, NULL, 0); |
| 36669 | 896 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
|
897 NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL); |
| 36669 | 898 if (!NotEq_singleton) return 0; |
|
36664
7bfbfb2ef4e2
Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents:
36661
diff
changeset
|
899 Lt_type = make_type("Lt", cmpop_type, NULL, 0); |
| 36669 | 900 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
|
901 Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL); |
| 36669 | 902 if (!Lt_singleton) return 0; |
|
36664
7bfbfb2ef4e2
Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents:
36661
diff
changeset
|
903 LtE_type = make_type("LtE", cmpop_type, NULL, 0); |
| 36669 | 904 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
|
905 LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL); |
| 36669 | 906 if (!LtE_singleton) return 0; |
|
36664
7bfbfb2ef4e2
Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents:
36661
diff
changeset
|
907 Gt_type = make_type("Gt", cmpop_type, NULL, 0); |
| 36669 | 908 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
|
909 Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL); |
| 36669 | 910 if (!Gt_singleton) return 0; |
|
36664
7bfbfb2ef4e2
Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents:
36661
diff
changeset
|
911 GtE_type = make_type("GtE", cmpop_type, NULL, 0); |
| 36669 | 912 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
|
913 GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL); |
| 36669 | 914 if (!GtE_singleton) return 0; |
|
36664
7bfbfb2ef4e2
Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents:
36661
diff
changeset
|
915 Is_type = make_type("Is", cmpop_type, NULL, 0); |
| 36669 | 916 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
|
917 Is_singleton = PyType_GenericNew(Is_type, NULL, NULL); |
| 36669 | 918 if (!Is_singleton) return 0; |
|
36664
7bfbfb2ef4e2
Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents:
36661
diff
changeset
|
919 IsNot_type = make_type("IsNot", cmpop_type, NULL, 0); |
| 36669 | 920 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
|
921 IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL); |
| 36669 | 922 if (!IsNot_singleton) return 0; |
|
36664
7bfbfb2ef4e2
Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents:
36661
diff
changeset
|
923 In_type = make_type("In", cmpop_type, NULL, 0); |
| 36669 | 924 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
|
925 In_singleton = PyType_GenericNew(In_type, NULL, NULL); |
| 36669 | 926 if (!In_singleton) return 0; |
|
36664
7bfbfb2ef4e2
Stop generating empty arrays.
Martin v. Löwis <martin@v.loewis.de>
parents:
36661
diff
changeset
|
927 NotIn_type = make_type("NotIn", cmpop_type, NULL, 0); |
| 36669 | 928 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
|
929 NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL); |
| 36669 | 930 if (!NotIn_singleton) return 0; |
|
46202
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
931 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
|
932 comprehension_fields, 3); |
| 36669 | 933 if (!comprehension_type) return 0; |
|
46202
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
934 excepthandler_type = make_type("excepthandler", &AST_type, NULL, 0); |
| 36669 | 935 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
|
936 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
|
937 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
|
938 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
|
939 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
|
940 if (!ExceptHandler_type) return 0; |
|
46202
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
941 arguments_type = make_type("arguments", &AST_type, arguments_fields, 4); |
| 36669 | 942 if (!arguments_type) return 0; |
|
46202
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
943 keyword_type = make_type("keyword", &AST_type, keyword_fields, 2); |
| 36669 | 944 if (!keyword_type) return 0; |
|
46202
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
945 alias_type = make_type("alias", &AST_type, alias_fields, 2); |
| 36669 | 946 if (!alias_type) return 0; |
| 947 initialized = 1; | |
| 948 return 1; | |
|
36660
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
949 } |
|
35866
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
950 |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
951 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
|
952 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
|
953 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
|
954 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
|
955 arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
956 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
|
957 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
|
958 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
|
959 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
|
960 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
|
961 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
|
962 arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
963 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
|
964 arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
965 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
|
966 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
|
967 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
|
968 |
| 35742 | 969 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
|
970 Module(asdl_seq * body, PyArena *arena) |
| 35742 | 971 { |
| 972 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
|
973 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
|
974 if (!p) |
| 35742 | 975 return NULL; |
| 976 p->kind = Module_kind; | |
| 977 p->v.Module.body = body; | |
| 978 return p; | |
| 979 } | |
| 980 | |
| 981 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
|
982 Interactive(asdl_seq * body, PyArena *arena) |
| 35742 | 983 { |
| 984 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
|
985 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
|
986 if (!p) |
| 35742 | 987 return NULL; |
| 988 p->kind = Interactive_kind; | |
| 989 p->v.Interactive.body = body; | |
| 990 return p; | |
| 991 } | |
| 992 | |
| 993 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
|
994 Expression(expr_ty body, PyArena *arena) |
| 35742 | 995 { |
| 996 mod_ty p; | |
| 997 if (!body) { | |
| 998 PyErr_SetString(PyExc_ValueError, | |
| 999 "field body is required for Expression"); | |
| 1000 return NULL; | |
| 1001 } | |
|
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
|
1002 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
|
1003 if (!p) |
| 35742 | 1004 return NULL; |
| 1005 p->kind = Expression_kind; | |
| 1006 p->v.Expression.body = body; | |
| 1007 return p; | |
| 1008 } | |
| 1009 | |
| 1010 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
|
1011 Suite(asdl_seq * body, PyArena *arena) |
| 35742 | 1012 { |
| 1013 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
|
1014 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
|
1015 if (!p) |
| 35742 | 1016 return NULL; |
| 1017 p->kind = Suite_kind; | |
| 1018 p->v.Suite.body = body; | |
| 1019 return p; | |
| 1020 } | |
| 1021 | |
| 1022 stmt_ty | |
| 1023 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
|
1024 decorator_list, int lineno, int col_offset, PyArena *arena) |
| 35742 | 1025 { |
| 1026 stmt_ty p; | |
| 1027 if (!name) { | |
| 1028 PyErr_SetString(PyExc_ValueError, | |
| 1029 "field name is required for FunctionDef"); | |
| 1030 return NULL; | |
| 1031 } | |
| 1032 if (!args) { | |
| 1033 PyErr_SetString(PyExc_ValueError, | |
| 1034 "field args is required for FunctionDef"); | |
| 1035 return NULL; | |
| 1036 } | |
|
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
|
1037 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
|
1038 if (!p) |
| 35742 | 1039 return NULL; |
| 1040 p->kind = FunctionDef_kind; | |
| 1041 p->v.FunctionDef.name = name; | |
| 1042 p->v.FunctionDef.args = args; | |
| 1043 p->v.FunctionDef.body = body; | |
|
45447
393822f2ef90
Patch #1759: Backport of PEP 3129 class decorators
Christian Heimes <christian@cheimes.de>
parents:
40936
diff
changeset
|
1044 p->v.FunctionDef.decorator_list = decorator_list; |
| 35742 | 1045 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
|
1046 p->col_offset = col_offset; |
| 35742 | 1047 return p; |
| 1048 } | |
| 1049 | |
| 1050 stmt_ty | |
|
45447
393822f2ef90
Patch #1759: Backport of PEP 3129 class decorators
Christian Heimes <christian@cheimes.de>
parents:
40936
diff
changeset
|
1051 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
|
1052 decorator_list, int lineno, int col_offset, PyArena *arena) |
| 35742 | 1053 { |
| 1054 stmt_ty p; | |
| 1055 if (!name) { | |
| 1056 PyErr_SetString(PyExc_ValueError, | |
| 1057 "field name is required for ClassDef"); | |
| 1058 return NULL; | |
| 1059 } | |
|
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
|
1060 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
|
1061 if (!p) |
| 35742 | 1062 return NULL; |
| 1063 p->kind = ClassDef_kind; | |
| 1064 p->v.ClassDef.name = name; | |
| 1065 p->v.ClassDef.bases = bases; | |
| 1066 p->v.ClassDef.body = body; | |
|
45447
393822f2ef90
Patch #1759: Backport of PEP 3129 class decorators
Christian Heimes <christian@cheimes.de>
parents:
40936
diff
changeset
|
1067 p->v.ClassDef.decorator_list = decorator_list; |
| 35742 | 1068 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
|
1069 p->col_offset = col_offset; |
| 35742 | 1070 return p; |
| 1071 } | |
| 1072 | |
| 1073 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
|
1074 Return(expr_ty value, int lineno, int col_offset, PyArena *arena) |
| 35742 | 1075 { |
| 1076 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
|
1077 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
|
1078 if (!p) |
| 35742 | 1079 return NULL; |
| 1080 p->kind = Return_kind; | |
| 1081 p->v.Return.value = value; | |
| 1082 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
|
1083 p->col_offset = col_offset; |
| 35742 | 1084 return p; |
| 1085 } | |
| 1086 | |
| 1087 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
|
1088 Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena) |
| 35742 | 1089 { |
| 1090 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
|
1091 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
|
1092 if (!p) |
| 35742 | 1093 return NULL; |
| 1094 p->kind = Delete_kind; | |
| 1095 p->v.Delete.targets = targets; | |
| 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 | 1098 return p; |
| 1099 } | |
| 1100 | |
| 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 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
|
1103 *arena) |
| 35742 | 1104 { |
| 1105 stmt_ty p; | |
| 1106 if (!value) { | |
| 1107 PyErr_SetString(PyExc_ValueError, | |
| 1108 "field value is required for Assign"); | |
| 1109 return NULL; | |
| 1110 } | |
|
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
|
1111 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
|
1112 if (!p) |
| 35742 | 1113 return NULL; |
| 1114 p->kind = Assign_kind; | |
| 1115 p->v.Assign.targets = targets; | |
| 1116 p->v.Assign.value = value; | |
| 1117 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
|
1118 p->col_offset = col_offset; |
| 35742 | 1119 return p; |
| 1120 } | |
| 1121 | |
| 1122 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
|
1123 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
|
1124 col_offset, PyArena *arena) |
| 35742 | 1125 { |
| 1126 stmt_ty p; | |
| 1127 if (!target) { | |
| 1128 PyErr_SetString(PyExc_ValueError, | |
| 1129 "field target is required for AugAssign"); | |
| 1130 return NULL; | |
| 1131 } | |
| 1132 if (!op) { | |
| 1133 PyErr_SetString(PyExc_ValueError, | |
| 1134 "field op is required for AugAssign"); | |
| 1135 return NULL; | |
| 1136 } | |
| 1137 if (!value) { | |
| 1138 PyErr_SetString(PyExc_ValueError, | |
| 1139 "field value is required for AugAssign"); | |
| 1140 return NULL; | |
| 1141 } | |
|
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
|
1142 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
|
1143 if (!p) |
| 35742 | 1144 return NULL; |
| 1145 p->kind = AugAssign_kind; | |
| 1146 p->v.AugAssign.target = target; | |
| 1147 p->v.AugAssign.op = op; | |
| 1148 p->v.AugAssign.value = value; | |
| 1149 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
|
1150 p->col_offset = col_offset; |
| 35742 | 1151 return p; |
| 1152 } | |
| 1153 | |
| 1154 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
|
1155 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
|
1156 PyArena *arena) |
| 35742 | 1157 { |
| 1158 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
|
1159 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
|
1160 if (!p) |
| 35742 | 1161 return NULL; |
| 1162 p->kind = Print_kind; | |
| 1163 p->v.Print.dest = dest; | |
| 1164 p->v.Print.values = values; | |
| 1165 p->v.Print.nl = nl; | |
| 1166 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
|
1167 p->col_offset = col_offset; |
| 35742 | 1168 return p; |
| 1169 } | |
| 1170 | |
| 1171 stmt_ty | |
| 1172 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
|
1173 lineno, int col_offset, PyArena *arena) |
| 35742 | 1174 { |
| 1175 stmt_ty p; | |
| 1176 if (!target) { | |
| 1177 PyErr_SetString(PyExc_ValueError, | |
| 1178 "field target is required for For"); | |
| 1179 return NULL; | |
| 1180 } | |
| 1181 if (!iter) { | |
| 1182 PyErr_SetString(PyExc_ValueError, | |
| 1183 "field iter is required for For"); | |
| 1184 return NULL; | |
| 1185 } | |
|
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
|
1186 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
|
1187 if (!p) |
| 35742 | 1188 return NULL; |
| 1189 p->kind = For_kind; | |
| 1190 p->v.For.target = target; | |
| 1191 p->v.For.iter = iter; | |
| 1192 p->v.For.body = body; | |
| 1193 p->v.For.orelse = orelse; | |
| 1194 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
|
1195 p->col_offset = col_offset; |
| 35742 | 1196 return p; |
| 1197 } | |
| 1198 | |
| 1199 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
|
1200 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
|
1201 col_offset, PyArena *arena) |
| 35742 | 1202 { |
| 1203 stmt_ty p; | |
| 1204 if (!test) { | |
| 1205 PyErr_SetString(PyExc_ValueError, | |
| 1206 "field test is required for While"); | |
| 1207 return NULL; | |
| 1208 } | |
|
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
|
1209 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
|
1210 if (!p) |
| 35742 | 1211 return NULL; |
| 1212 p->kind = While_kind; | |
| 1213 p->v.While.test = test; | |
| 1214 p->v.While.body = body; | |
| 1215 p->v.While.orelse = orelse; | |
| 1216 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
|
1217 p->col_offset = col_offset; |
| 35742 | 1218 return p; |
| 1219 } | |
| 1220 | |
| 1221 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
|
1222 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
|
1223 col_offset, PyArena *arena) |
| 35742 | 1224 { |
| 1225 stmt_ty p; | |
| 1226 if (!test) { | |
| 1227 PyErr_SetString(PyExc_ValueError, | |
| 1228 "field test is required for If"); | |
| 1229 return NULL; | |
| 1230 } | |
|
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
|
1231 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
|
1232 if (!p) |
| 35742 | 1233 return NULL; |
| 1234 p->kind = If_kind; | |
| 1235 p->v.If.test = test; | |
| 1236 p->v.If.body = body; | |
| 1237 p->v.If.orelse = orelse; | |
| 1238 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
|
1239 p->col_offset = col_offset; |
| 35742 | 1240 return p; |
| 1241 } | |
| 1242 | |
| 1243 stmt_ty | |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36669
diff
changeset
|
1244 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
|
1245 int col_offset, PyArena *arena) |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36669
diff
changeset
|
1246 { |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36669
diff
changeset
|
1247 stmt_ty p; |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36669
diff
changeset
|
1248 if (!context_expr) { |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36669
diff
changeset
|
1249 PyErr_SetString(PyExc_ValueError, |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36669
diff
changeset
|
1250 "field context_expr is required for With"); |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36669
diff
changeset
|
1251 return NULL; |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36669
diff
changeset
|
1252 } |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36669
diff
changeset
|
1253 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
|
1254 if (!p) |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36669
diff
changeset
|
1255 return NULL; |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36669
diff
changeset
|
1256 p->kind = With_kind; |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36669
diff
changeset
|
1257 p->v.With.context_expr = context_expr; |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36669
diff
changeset
|
1258 p->v.With.optional_vars = optional_vars; |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36669
diff
changeset
|
1259 p->v.With.body = body; |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36669
diff
changeset
|
1260 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
|
1261 p->col_offset = col_offset; |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36669
diff
changeset
|
1262 return p; |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36669
diff
changeset
|
1263 } |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36669
diff
changeset
|
1264 |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36669
diff
changeset
|
1265 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
|
1266 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
|
1267 PyArena *arena) |
| 35742 | 1268 { |
| 1269 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
|
1270 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
|
1271 if (!p) |
| 35742 | 1272 return NULL; |
| 1273 p->kind = Raise_kind; | |
| 1274 p->v.Raise.type = type; | |
| 1275 p->v.Raise.inst = inst; | |
| 1276 p->v.Raise.tback = tback; | |
| 1277 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
|
1278 p->col_offset = col_offset; |
| 35742 | 1279 return p; |
| 1280 } | |
| 1281 | |
| 1282 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
|
1283 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
|
1284 int col_offset, PyArena *arena) |
| 35742 | 1285 { |
| 1286 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
|
1287 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
|
1288 if (!p) |
| 35742 | 1289 return NULL; |
| 1290 p->kind = TryExcept_kind; | |
| 1291 p->v.TryExcept.body = body; | |
| 1292 p->v.TryExcept.handlers = handlers; | |
| 1293 p->v.TryExcept.orelse = orelse; | |
| 1294 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
|
1295 p->col_offset = col_offset; |
| 35742 | 1296 return p; |
| 1297 } | |
| 1298 | |
| 1299 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
|
1300 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
|
1301 PyArena *arena) |
| 35742 | 1302 { |
| 1303 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
|
1304 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
|
1305 if (!p) |
| 35742 | 1306 return NULL; |
| 1307 p->kind = TryFinally_kind; | |
| 1308 p->v.TryFinally.body = body; | |
| 1309 p->v.TryFinally.finalbody = finalbody; | |
| 1310 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
|
1311 p->col_offset = col_offset; |
| 35742 | 1312 return p; |
| 1313 } | |
| 1314 | |
| 1315 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
|
1316 Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, PyArena *arena) |
| 35742 | 1317 { |
| 1318 stmt_ty p; | |
| 1319 if (!test) { | |
| 1320 PyErr_SetString(PyExc_ValueError, | |
| 1321 "field test is required for Assert"); | |
| 1322 return NULL; | |
| 1323 } | |
|
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
|
1324 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
|
1325 if (!p) |
| 35742 | 1326 return NULL; |
| 1327 p->kind = Assert_kind; | |
| 1328 p->v.Assert.test = test; | |
| 1329 p->v.Assert.msg = msg; | |
| 1330 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
|
1331 p->col_offset = col_offset; |
| 35742 | 1332 return p; |
| 1333 } | |
| 1334 | |
| 1335 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
|
1336 Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
| 35742 | 1337 { |
| 1338 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
|
1339 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
|
1340 if (!p) |
| 35742 | 1341 return NULL; |
| 1342 p->kind = Import_kind; | |
| 1343 p->v.Import.names = names; | |
| 1344 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
|
1345 p->col_offset = col_offset; |
| 35742 | 1346 return p; |
| 1347 } | |
| 1348 | |
| 1349 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
|
1350 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
|
1351 col_offset, PyArena *arena) |
| 35742 | 1352 { |
| 1353 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
|
1354 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
|
1355 if (!p) |
| 35742 | 1356 return NULL; |
| 1357 p->kind = ImportFrom_kind; | |
| 1358 p->v.ImportFrom.module = module; | |
| 1359 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
|
1360 p->v.ImportFrom.level = level; |
| 35742 | 1361 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
|
1362 p->col_offset = col_offset; |
| 35742 | 1363 return p; |
| 1364 } | |
| 1365 | |
| 1366 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
|
1367 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
|
1368 PyArena *arena) |
| 35742 | 1369 { |
| 1370 stmt_ty p; | |
| 1371 if (!body) { | |
| 1372 PyErr_SetString(PyExc_ValueError, | |
| 1373 "field body is required for Exec"); | |
| 1374 return NULL; | |
| 1375 } | |
|
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
|
1376 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
|
1377 if (!p) |
| 35742 | 1378 return NULL; |
| 1379 p->kind = Exec_kind; | |
| 1380 p->v.Exec.body = body; | |
| 1381 p->v.Exec.globals = globals; | |
| 1382 p->v.Exec.locals = locals; | |
| 1383 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
|
1384 p->col_offset = col_offset; |
| 35742 | 1385 return p; |
| 1386 } | |
| 1387 | |
| 1388 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
|
1389 Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
| 35742 | 1390 { |
| 1391 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
|
1392 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
|
1393 if (!p) |
| 35742 | 1394 return NULL; |
| 1395 p->kind = Global_kind; | |
| 1396 p->v.Global.names = names; | |
| 1397 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
|
1398 p->col_offset = col_offset; |
| 35742 | 1399 return p; |
| 1400 } | |
| 1401 | |
| 1402 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
|
1403 Expr(expr_ty value, int lineno, int col_offset, PyArena *arena) |
| 35742 | 1404 { |
| 1405 stmt_ty p; | |
| 1406 if (!value) { | |
| 1407 PyErr_SetString(PyExc_ValueError, | |
| 1408 "field value is required for Expr"); | |
| 1409 return NULL; | |
| 1410 } | |
|
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
|
1411 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
|
1412 if (!p) |
| 35742 | 1413 return NULL; |
| 1414 p->kind = Expr_kind; | |
| 1415 p->v.Expr.value = value; | |
| 1416 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
|
1417 p->col_offset = col_offset; |
| 35742 | 1418 return p; |
| 1419 } | |
| 1420 | |
| 1421 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
|
1422 Pass(int lineno, int col_offset, PyArena *arena) |
| 35742 | 1423 { |
| 1424 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
|
1425 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
|
1426 if (!p) |
| 35742 | 1427 return NULL; |
| 1428 p->kind = Pass_kind; | |
| 1429 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
|
1430 p->col_offset = col_offset; |
| 35742 | 1431 return p; |
| 1432 } | |
| 1433 | |
| 1434 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
|
1435 Break(int lineno, int col_offset, PyArena *arena) |
| 35742 | 1436 { |
| 1437 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
|
1438 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
|
1439 if (!p) |
| 35742 | 1440 return NULL; |
| 1441 p->kind = Break_kind; | |
| 1442 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
|
1443 p->col_offset = col_offset; |
| 35742 | 1444 return p; |
| 1445 } | |
| 1446 | |
| 1447 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
|
1448 Continue(int lineno, int col_offset, PyArena *arena) |
| 35742 | 1449 { |
| 1450 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
|
1451 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
|
1452 if (!p) |
| 35742 | 1453 return NULL; |
| 1454 p->kind = Continue_kind; | |
| 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 | 1457 return p; |
| 1458 } | |
| 1459 | |
| 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 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
|
1462 *arena) |
| 35742 | 1463 { |
| 1464 expr_ty p; | |
| 1465 if (!op) { | |
| 1466 PyErr_SetString(PyExc_ValueError, | |
| 1467 "field op is required for BoolOp"); | |
| 1468 return NULL; | |
| 1469 } | |
|
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
|
1470 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
|
1471 if (!p) |
| 35742 | 1472 return NULL; |
| 1473 p->kind = BoolOp_kind; | |
| 1474 p->v.BoolOp.op = op; | |
| 1475 p->v.BoolOp.values = values; | |
| 1476 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
|
1477 p->col_offset = col_offset; |
| 35742 | 1478 return p; |
| 1479 } | |
| 1480 | |
| 1481 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
|
1482 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
|
1483 PyArena *arena) |
| 35742 | 1484 { |
| 1485 expr_ty p; | |
| 1486 if (!left) { | |
| 1487 PyErr_SetString(PyExc_ValueError, | |
| 1488 "field left is required for BinOp"); | |
| 1489 return NULL; | |
| 1490 } | |
| 1491 if (!op) { | |
| 1492 PyErr_SetString(PyExc_ValueError, | |
| 1493 "field op is required for BinOp"); | |
| 1494 return NULL; | |
| 1495 } | |
| 1496 if (!right) { | |
| 1497 PyErr_SetString(PyExc_ValueError, | |
| 1498 "field right is required for BinOp"); | |
| 1499 return NULL; | |
| 1500 } | |
|
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
|
1501 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
|
1502 if (!p) |
| 35742 | 1503 return NULL; |
| 1504 p->kind = BinOp_kind; | |
| 1505 p->v.BinOp.left = left; | |
| 1506 p->v.BinOp.op = op; | |
| 1507 p->v.BinOp.right = right; | |
| 1508 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
|
1509 p->col_offset = col_offset; |
| 35742 | 1510 return p; |
| 1511 } | |
| 1512 | |
| 1513 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
|
1514 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
|
1515 *arena) |
| 35742 | 1516 { |
| 1517 expr_ty p; | |
| 1518 if (!op) { | |
| 1519 PyErr_SetString(PyExc_ValueError, | |
| 1520 "field op is required for UnaryOp"); | |
| 1521 return NULL; | |
| 1522 } | |
| 1523 if (!operand) { | |
| 1524 PyErr_SetString(PyExc_ValueError, | |
| 1525 "field operand is required for UnaryOp"); | |
| 1526 return NULL; | |
| 1527 } | |
|
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
|
1528 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
|
1529 if (!p) |
| 35742 | 1530 return NULL; |
| 1531 p->kind = UnaryOp_kind; | |
| 1532 p->v.UnaryOp.op = op; | |
| 1533 p->v.UnaryOp.operand = operand; | |
| 1534 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
|
1535 p->col_offset = col_offset; |
| 35742 | 1536 return p; |
| 1537 } | |
| 1538 | |
| 1539 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
|
1540 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
|
1541 *arena) |
| 35742 | 1542 { |
| 1543 expr_ty p; | |
| 1544 if (!args) { | |
| 1545 PyErr_SetString(PyExc_ValueError, | |
| 1546 "field args is required for Lambda"); | |
| 1547 return NULL; | |
| 1548 } | |
| 1549 if (!body) { | |
| 1550 PyErr_SetString(PyExc_ValueError, | |
| 1551 "field body is required for Lambda"); | |
| 1552 return NULL; | |
| 1553 } | |
|
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
|
1554 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
|
1555 if (!p) |
| 35742 | 1556 return NULL; |
| 1557 p->kind = Lambda_kind; | |
| 1558 p->v.Lambda.args = args; | |
| 1559 p->v.Lambda.body = body; | |
| 1560 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
|
1561 p->col_offset = col_offset; |
| 35742 | 1562 return p; |
| 1563 } | |
| 1564 | |
| 1565 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
|
1566 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
|
1567 PyArena *arena) |
|
36666
6165927431d6
PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents:
36665
diff
changeset
|
1568 { |
|
6165927431d6
PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents:
36665
diff
changeset
|
1569 expr_ty p; |
|
6165927431d6
PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents:
36665
diff
changeset
|
1570 if (!test) { |
|
6165927431d6
PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents:
36665
diff
changeset
|
1571 PyErr_SetString(PyExc_ValueError, |
|
6165927431d6
PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents:
36665
diff
changeset
|
1572 "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
|
1573 return NULL; |
|
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 if (!body) { |
|
6165927431d6
PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents:
36665
diff
changeset
|
1576 PyErr_SetString(PyExc_ValueError, |
|
6165927431d6
PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents:
36665
diff
changeset
|
1577 "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
|
1578 return NULL; |
|
6165927431d6
PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents:
36665
diff
changeset
|
1579 } |
|
6165927431d6
PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents:
36665
diff
changeset
|
1580 if (!orelse) { |
|
6165927431d6
PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents:
36665
diff
changeset
|
1581 PyErr_SetString(PyExc_ValueError, |
|
6165927431d6
PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents:
36665
diff
changeset
|
1582 "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
|
1583 return NULL; |
|
6165927431d6
PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents:
36665
diff
changeset
|
1584 } |
|
6165927431d6
PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents:
36665
diff
changeset
|
1585 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
|
1586 if (!p) |
|
36666
6165927431d6
PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents:
36665
diff
changeset
|
1587 return NULL; |
|
6165927431d6
PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents:
36665
diff
changeset
|
1588 p->kind = IfExp_kind; |
|
6165927431d6
PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents:
36665
diff
changeset
|
1589 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
|
1590 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
|
1591 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
|
1592 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
|
1593 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
|
1594 return p; |
|
6165927431d6
PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents:
36665
diff
changeset
|
1595 } |
|
6165927431d6
PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents:
36665
diff
changeset
|
1596 |
|
6165927431d6
PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents:
36665
diff
changeset
|
1597 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
|
1598 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
|
1599 *arena) |
| 35742 | 1600 { |
| 1601 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
|
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 | 1604 return NULL; |
| 1605 p->kind = Dict_kind; | |
| 1606 p->v.Dict.keys = keys; | |
| 1607 p->v.Dict.values = values; | |
| 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 | 1610 return p; |
| 1611 } | |
| 1612 | |
| 1613 expr_ty | |
|
58229
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
1614 Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena) |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
1615 { |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
1616 expr_ty p; |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
1617 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
1618 if (!p) |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
1619 return NULL; |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
1620 p->kind = Set_kind; |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
1621 p->v.Set.elts = elts; |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
1622 p->lineno = lineno; |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
1623 p->col_offset = col_offset; |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
1624 return p; |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
1625 } |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
1626 |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
1627 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
|
1628 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
|
1629 PyArena *arena) |
| 35742 | 1630 { |
| 1631 expr_ty p; | |
| 1632 if (!elt) { | |
| 1633 PyErr_SetString(PyExc_ValueError, | |
| 1634 "field elt is required for ListComp"); | |
| 1635 return NULL; | |
| 1636 } | |
|
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
|
1637 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
|
1638 if (!p) |
| 35742 | 1639 return NULL; |
| 1640 p->kind = ListComp_kind; | |
| 1641 p->v.ListComp.elt = elt; | |
| 1642 p->v.ListComp.generators = generators; | |
| 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 | 1645 return p; |
| 1646 } | |
| 1647 | |
| 1648 expr_ty | |
|
58250
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
1649 SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, PyArena |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
1650 *arena) |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
1651 { |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
1652 expr_ty p; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
1653 if (!elt) { |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
1654 PyErr_SetString(PyExc_ValueError, |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
1655 "field elt is required for SetComp"); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
1656 return NULL; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
1657 } |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
1658 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
1659 if (!p) |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
1660 return NULL; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
1661 p->kind = SetComp_kind; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
1662 p->v.SetComp.elt = elt; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
1663 p->v.SetComp.generators = generators; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
1664 p->lineno = lineno; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
1665 p->col_offset = col_offset; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
1666 return p; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
1667 } |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
1668 |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
1669 expr_ty |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
1670 DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int lineno, int |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
1671 col_offset, PyArena *arena) |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
1672 { |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
1673 expr_ty p; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
1674 if (!key) { |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
1675 PyErr_SetString(PyExc_ValueError, |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
1676 "field key is required for DictComp"); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
1677 return NULL; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
1678 } |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
1679 if (!value) { |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
1680 PyErr_SetString(PyExc_ValueError, |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
1681 "field value is required for DictComp"); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
1682 return NULL; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
1683 } |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
1684 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
1685 if (!p) |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
1686 return NULL; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
1687 p->kind = DictComp_kind; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
1688 p->v.DictComp.key = key; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
1689 p->v.DictComp.value = value; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
1690 p->v.DictComp.generators = generators; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
1691 p->lineno = lineno; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
1692 p->col_offset = col_offset; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
1693 return p; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
1694 } |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
1695 |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
1696 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
|
1697 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
|
1698 PyArena *arena) |
| 35742 | 1699 { |
| 1700 expr_ty p; | |
| 1701 if (!elt) { | |
| 1702 PyErr_SetString(PyExc_ValueError, | |
| 1703 "field elt is required for GeneratorExp"); | |
| 1704 return NULL; | |
| 1705 } | |
|
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
|
1706 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
|
1707 if (!p) |
| 35742 | 1708 return NULL; |
| 1709 p->kind = GeneratorExp_kind; | |
| 1710 p->v.GeneratorExp.elt = elt; | |
| 1711 p->v.GeneratorExp.generators = generators; | |
| 1712 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
|
1713 p->col_offset = col_offset; |
| 35742 | 1714 return p; |
| 1715 } | |
| 1716 | |
| 1717 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
|
1718 Yield(expr_ty value, int lineno, int col_offset, PyArena *arena) |
| 35742 | 1719 { |
| 1720 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
|
1721 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
|
1722 if (!p) |
| 35742 | 1723 return NULL; |
| 1724 p->kind = Yield_kind; | |
| 1725 p->v.Yield.value = value; | |
| 1726 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
|
1727 p->col_offset = col_offset; |
| 35742 | 1728 return p; |
| 1729 } | |
| 1730 | |
| 1731 expr_ty | |
|
37685
5e72b0c74100
Introduce asdl_int_seq, to hold cmpop_ty.
Martin v. Löwis <martin@v.loewis.de>
parents:
37601
diff
changeset
|
1732 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
|
1733 int col_offset, PyArena *arena) |
| 35742 | 1734 { |
| 1735 expr_ty p; | |
| 1736 if (!left) { | |
| 1737 PyErr_SetString(PyExc_ValueError, | |
| 1738 "field left is required for Compare"); | |
| 1739 return NULL; | |
| 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 | 1743 return NULL; |
| 1744 p->kind = Compare_kind; | |
| 1745 p->v.Compare.left = left; | |
| 1746 p->v.Compare.ops = ops; | |
| 1747 p->v.Compare.comparators = comparators; | |
| 1748 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
|
1749 p->col_offset = col_offset; |
| 35742 | 1750 return p; |
| 1751 } | |
| 1752 | |
| 1753 expr_ty | |
| 1754 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
|
1755 expr_ty kwargs, int lineno, int col_offset, PyArena *arena) |
| 35742 | 1756 { |
| 1757 expr_ty p; | |
| 1758 if (!func) { | |
| 1759 PyErr_SetString(PyExc_ValueError, | |
| 1760 "field func is required for Call"); | |
| 1761 return NULL; | |
| 1762 } | |
|
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
|
1763 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
|
1764 if (!p) |
| 35742 | 1765 return NULL; |
| 1766 p->kind = Call_kind; | |
| 1767 p->v.Call.func = func; | |
| 1768 p->v.Call.args = args; | |
| 1769 p->v.Call.keywords = keywords; | |
| 1770 p->v.Call.starargs = starargs; | |
| 1771 p->v.Call.kwargs = kwargs; | |
| 1772 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
|
1773 p->col_offset = col_offset; |
| 35742 | 1774 return p; |
| 1775 } | |
| 1776 | |
| 1777 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
|
1778 Repr(expr_ty value, int lineno, int col_offset, PyArena *arena) |
| 35742 | 1779 { |
| 1780 expr_ty p; | |
| 1781 if (!value) { | |
| 1782 PyErr_SetString(PyExc_ValueError, | |
| 1783 "field value is required for Repr"); | |
| 1784 return NULL; | |
| 1785 } | |
|
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
|
1786 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
|
1787 if (!p) |
| 35742 | 1788 return NULL; |
| 1789 p->kind = Repr_kind; | |
| 1790 p->v.Repr.value = value; | |
| 1791 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
|
1792 p->col_offset = col_offset; |
| 35742 | 1793 return p; |
| 1794 } | |
| 1795 | |
| 1796 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
|
1797 Num(object n, int lineno, int col_offset, PyArena *arena) |
| 35742 | 1798 { |
| 1799 expr_ty p; | |
| 1800 if (!n) { | |
| 1801 PyErr_SetString(PyExc_ValueError, | |
| 1802 "field n is required for Num"); | |
| 1803 return NULL; | |
| 1804 } | |
|
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
|
1805 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
|
1806 if (!p) |
| 35742 | 1807 return NULL; |
| 1808 p->kind = Num_kind; | |
| 1809 p->v.Num.n = n; | |
| 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 | 1812 return p; |
| 1813 } | |
| 1814 | |
| 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 Str(string s, int lineno, int col_offset, PyArena *arena) |
| 35742 | 1817 { |
| 1818 expr_ty p; | |
| 1819 if (!s) { | |
| 1820 PyErr_SetString(PyExc_ValueError, | |
| 1821 "field s is required for Str"); | |
| 1822 return NULL; | |
| 1823 } | |
|
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
|
1824 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
|
1825 if (!p) |
| 35742 | 1826 return NULL; |
| 1827 p->kind = Str_kind; | |
| 1828 p->v.Str.s = s; | |
| 1829 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
|
1830 p->col_offset = col_offset; |
| 35742 | 1831 return p; |
| 1832 } | |
| 1833 | |
| 1834 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
|
1835 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
|
1836 col_offset, PyArena *arena) |
| 35742 | 1837 { |
| 1838 expr_ty p; | |
| 1839 if (!value) { | |
| 1840 PyErr_SetString(PyExc_ValueError, | |
| 1841 "field value is required for Attribute"); | |
| 1842 return NULL; | |
| 1843 } | |
| 1844 if (!attr) { | |
| 1845 PyErr_SetString(PyExc_ValueError, | |
| 1846 "field attr is required for Attribute"); | |
| 1847 return NULL; | |
| 1848 } | |
| 1849 if (!ctx) { | |
| 1850 PyErr_SetString(PyExc_ValueError, | |
| 1851 "field ctx is required for Attribute"); | |
| 1852 return NULL; | |
| 1853 } | |
|
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
|
1854 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
|
1855 if (!p) |
| 35742 | 1856 return NULL; |
| 1857 p->kind = Attribute_kind; | |
| 1858 p->v.Attribute.value = value; | |
| 1859 p->v.Attribute.attr = attr; | |
| 1860 p->v.Attribute.ctx = ctx; | |
| 1861 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
|
1862 p->col_offset = col_offset; |
| 35742 | 1863 return p; |
| 1864 } | |
| 1865 | |
| 1866 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
|
1867 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
|
1868 col_offset, PyArena *arena) |
| 35742 | 1869 { |
| 1870 expr_ty p; | |
| 1871 if (!value) { | |
| 1872 PyErr_SetString(PyExc_ValueError, | |
| 1873 "field value is required for Subscript"); | |
| 1874 return NULL; | |
| 1875 } | |
| 1876 if (!slice) { | |
| 1877 PyErr_SetString(PyExc_ValueError, | |
| 1878 "field slice is required for Subscript"); | |
| 1879 return NULL; | |
| 1880 } | |
| 1881 if (!ctx) { | |
| 1882 PyErr_SetString(PyExc_ValueError, | |
| 1883 "field ctx is required for Subscript"); | |
| 1884 return NULL; | |
| 1885 } | |
|
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
|
1886 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
|
1887 if (!p) |
| 35742 | 1888 return NULL; |
| 1889 p->kind = Subscript_kind; | |
| 1890 p->v.Subscript.value = value; | |
| 1891 p->v.Subscript.slice = slice; | |
| 1892 p->v.Subscript.ctx = ctx; | |
| 1893 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
|
1894 p->col_offset = col_offset; |
| 35742 | 1895 return p; |
| 1896 } | |
| 1897 | |
| 1898 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
|
1899 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
|
1900 *arena) |
| 35742 | 1901 { |
| 1902 expr_ty p; | |
| 1903 if (!id) { | |
| 1904 PyErr_SetString(PyExc_ValueError, | |
| 1905 "field id is required for Name"); | |
| 1906 return NULL; | |
| 1907 } | |
| 1908 if (!ctx) { | |
| 1909 PyErr_SetString(PyExc_ValueError, | |
| 1910 "field ctx is required for Name"); | |
| 1911 return NULL; | |
| 1912 } | |
|
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
|
1913 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
|
1914 if (!p) |
| 35742 | 1915 return NULL; |
| 1916 p->kind = Name_kind; | |
| 1917 p->v.Name.id = id; | |
| 1918 p->v.Name.ctx = ctx; | |
| 1919 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
|
1920 p->col_offset = col_offset; |
| 35742 | 1921 return p; |
| 1922 } | |
| 1923 | |
| 1924 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
|
1925 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
|
1926 *arena) |
| 35742 | 1927 { |
| 1928 expr_ty p; | |
| 1929 if (!ctx) { | |
| 1930 PyErr_SetString(PyExc_ValueError, | |
| 1931 "field ctx is required for List"); | |
| 1932 return NULL; | |
| 1933 } | |
|
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
|
1934 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
|
1935 if (!p) |
| 35742 | 1936 return NULL; |
| 1937 p->kind = List_kind; | |
| 1938 p->v.List.elts = elts; | |
| 1939 p->v.List.ctx = ctx; | |
| 1940 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
|
1941 p->col_offset = col_offset; |
| 35742 | 1942 return p; |
| 1943 } | |
| 1944 | |
| 1945 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
|
1946 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
|
1947 *arena) |
| 35742 | 1948 { |
| 1949 expr_ty p; | |
| 1950 if (!ctx) { | |
| 1951 PyErr_SetString(PyExc_ValueError, | |
| 1952 "field ctx is required for Tuple"); | |
| 1953 return NULL; | |
| 1954 } | |
|
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
|
1955 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
|
1956 if (!p) |
| 35742 | 1957 return NULL; |
| 1958 p->kind = Tuple_kind; | |
| 1959 p->v.Tuple.elts = elts; | |
| 1960 p->v.Tuple.ctx = ctx; | |
| 1961 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
|
1962 p->col_offset = col_offset; |
| 35742 | 1963 return p; |
| 1964 } | |
| 1965 | |
| 1966 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
|
1967 Ellipsis(PyArena *arena) |
| 35742 | 1968 { |
| 1969 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
|
1970 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
|
1971 if (!p) |
| 35742 | 1972 return NULL; |
| 1973 p->kind = Ellipsis_kind; | |
| 1974 return p; | |
| 1975 } | |
| 1976 | |
| 1977 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
|
1978 Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena) |
| 35742 | 1979 { |
| 1980 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
|
1981 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
|
1982 if (!p) |
| 35742 | 1983 return NULL; |
| 1984 p->kind = Slice_kind; | |
| 1985 p->v.Slice.lower = lower; | |
| 1986 p->v.Slice.upper = upper; | |
| 1987 p->v.Slice.step = step; | |
| 1988 return p; | |
| 1989 } | |
| 1990 | |
| 1991 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
|
1992 ExtSlice(asdl_seq * dims, PyArena *arena) |
| 35742 | 1993 { |
| 1994 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
|
1995 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
|
1996 if (!p) |
| 35742 | 1997 return NULL; |
| 1998 p->kind = ExtSlice_kind; | |
| 1999 p->v.ExtSlice.dims = dims; | |
| 2000 return p; | |
| 2001 } | |
| 2002 | |
| 2003 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
|
2004 Index(expr_ty value, PyArena *arena) |
| 35742 | 2005 { |
| 2006 slice_ty p; | |
| 2007 if (!value) { | |
| 2008 PyErr_SetString(PyExc_ValueError, | |
| 2009 "field value is required for Index"); | |
| 2010 return NULL; | |
| 2011 } | |
|
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
|
2012 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
|
2013 if (!p) |
| 35742 | 2014 return NULL; |
| 2015 p->kind = Index_kind; | |
| 2016 p->v.Index.value = value; | |
| 2017 return p; | |
| 2018 } | |
| 2019 | |
| 2020 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
|
2021 comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena) |
| 35742 | 2022 { |
| 2023 comprehension_ty p; | |
| 2024 if (!target) { | |
| 2025 PyErr_SetString(PyExc_ValueError, | |
| 2026 "field target is required for comprehension"); | |
| 2027 return NULL; | |
| 2028 } | |
| 2029 if (!iter) { | |
| 2030 PyErr_SetString(PyExc_ValueError, | |
| 2031 "field iter is required for comprehension"); | |
| 2032 return NULL; | |
| 2033 } | |
|
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
|
2034 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
|
2035 if (!p) |
| 35742 | 2036 return NULL; |
| 2037 p->target = target; | |
| 2038 p->iter = iter; | |
| 2039 p->ifs = ifs; | |
| 2040 return p; | |
| 2041 } | |
| 2042 | |
| 2043 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
|
2044 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
|
2045 col_offset, PyArena *arena) |
| 35742 | 2046 { |
| 2047 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
|
2048 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
|
2049 if (!p) |
| 35742 | 2050 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
|
2051 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
|
2052 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
|
2053 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
|
2054 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
|
2055 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
|
2056 p->col_offset = col_offset; |
| 35742 | 2057 return p; |
| 2058 } | |
| 2059 | |
| 2060 arguments_ty | |
| 2061 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
|
2062 defaults, PyArena *arena) |
| 35742 | 2063 { |
| 2064 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
|
2065 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
|
2066 if (!p) |
| 35742 | 2067 return NULL; |
| 2068 p->args = args; | |
| 2069 p->vararg = vararg; | |
| 2070 p->kwarg = kwarg; | |
| 2071 p->defaults = defaults; | |
| 2072 return p; | |
| 2073 } | |
| 2074 | |
| 2075 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
|
2076 keyword(identifier arg, expr_ty value, PyArena *arena) |
| 35742 | 2077 { |
| 2078 keyword_ty p; | |
| 2079 if (!arg) { | |
| 2080 PyErr_SetString(PyExc_ValueError, | |
| 2081 "field arg is required for keyword"); | |
| 2082 return NULL; | |
| 2083 } | |
| 2084 if (!value) { | |
| 2085 PyErr_SetString(PyExc_ValueError, | |
| 2086 "field value is required for keyword"); | |
| 2087 return NULL; | |
| 2088 } | |
|
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
|
2089 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
|
2090 if (!p) |
| 35742 | 2091 return NULL; |
| 2092 p->arg = arg; | |
| 2093 p->value = value; | |
| 2094 return p; | |
| 2095 } | |
| 2096 | |
| 2097 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
|
2098 alias(identifier name, identifier asname, PyArena *arena) |
| 35742 | 2099 { |
| 2100 alias_ty p; | |
| 2101 if (!name) { | |
| 2102 PyErr_SetString(PyExc_ValueError, | |
| 2103 "field name is required for alias"); | |
| 2104 return NULL; | |
| 2105 } | |
|
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
|
2106 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
|
2107 if (!p) |
| 35742 | 2108 return NULL; |
| 2109 p->name = name; | |
| 2110 p->asname = asname; | |
| 2111 return p; | |
| 2112 } | |
| 2113 | |
|
35866
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
2114 |
|
36660
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2115 PyObject* |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2116 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
|
2117 { |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2118 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
|
2119 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
|
2120 if (!o) { |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2121 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
|
2122 return Py_None; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2123 } |
|
35866
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
2124 |
|
36660
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2125 switch (o->kind) { |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2126 case Module_kind: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2127 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
|
2128 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
|
2129 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
|
2130 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
|
2131 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
|
2132 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2133 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2134 break; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2135 case Interactive_kind: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2136 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
|
2137 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
|
2138 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
|
2139 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
|
2140 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
|
2141 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2142 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2143 break; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2144 case Expression_kind: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2145 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
|
2146 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
|
2147 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
|
2148 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
|
2149 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
|
2150 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2151 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2152 break; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2153 case Suite_kind: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2154 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
|
2155 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
|
2156 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
|
2157 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
|
2158 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
|
2159 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2160 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2161 break; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2162 } |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2163 return result; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2164 failed: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2165 Py_XDECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2166 Py_XDECREF(result); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2167 return NULL; |
| 36174 | 2168 } |
|
35866
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
2169 |
|
36660
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2170 PyObject* |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2171 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
|
2172 { |
|
36660
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2173 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
|
2174 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
|
2175 if (!o) { |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2176 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
|
2177 return Py_None; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2178 } |
|
35866
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
2179 |
|
36660
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2180 switch (o->kind) { |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2181 case FunctionDef_kind: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2182 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
|
2183 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
|
2184 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
|
2185 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
|
2186 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
|
2187 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2188 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2189 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
|
2190 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
|
2191 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
|
2192 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2193 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2194 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
|
2195 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
|
2196 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
|
2197 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2198 Py_DECREF(value); |
|
45447
393822f2ef90
Patch #1759: Backport of PEP 3129 class decorators
Christian Heimes <christian@cheimes.de>
parents:
40936
diff
changeset
|
2199 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
|
2200 ast2obj_expr); |
|
36660
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2201 if (!value) goto failed; |
|
45447
393822f2ef90
Patch #1759: Backport of PEP 3129 class decorators
Christian Heimes <christian@cheimes.de>
parents:
40936
diff
changeset
|
2202 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
|
2203 -1) |
|
36660
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2204 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2205 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2206 break; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2207 case ClassDef_kind: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2208 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
|
2209 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
|
2210 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
|
2211 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
|
2212 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
|
2213 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2214 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2215 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
|
2216 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
|
2217 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
|
2218 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2219 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2220 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
|
2221 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
|
2222 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
|
2223 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2224 Py_DECREF(value); |
|
45447
393822f2ef90
Patch #1759: Backport of PEP 3129 class decorators
Christian Heimes <christian@cheimes.de>
parents:
40936
diff
changeset
|
2225 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
|
2226 ast2obj_expr); |
|
393822f2ef90
Patch #1759: Backport of PEP 3129 class decorators
Christian Heimes <christian@cheimes.de>
parents:
40936
diff
changeset
|
2227 if (!value) goto failed; |
|
393822f2ef90
Patch #1759: Backport of PEP 3129 class decorators
Christian Heimes <christian@cheimes.de>
parents:
40936
diff
changeset
|
2228 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
|
2229 -1) |
|
393822f2ef90
Patch #1759: Backport of PEP 3129 class decorators
Christian Heimes <christian@cheimes.de>
parents:
40936
diff
changeset
|
2230 goto failed; |
|
393822f2ef90
Patch #1759: Backport of PEP 3129 class decorators
Christian Heimes <christian@cheimes.de>
parents:
40936
diff
changeset
|
2231 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
|
2232 break; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2233 case Return_kind: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2234 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
|
2235 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
|
2236 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
|
2237 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
|
2238 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
|
2239 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2240 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2241 break; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2242 case Delete_kind: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2243 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
|
2244 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
|
2245 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
|
2246 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
|
2247 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
|
2248 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2249 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2250 break; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2251 case Assign_kind: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2252 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
|
2253 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
|
2254 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
|
2255 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
|
2256 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
|
2257 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2258 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2259 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
|
2260 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
|
2261 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
|
2262 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2263 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2264 break; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2265 case AugAssign_kind: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2266 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
|
2267 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
|
2268 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
|
2269 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
|
2270 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
|
2271 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2272 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2273 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
|
2274 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
|
2275 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
|
2276 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2277 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2278 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
|
2279 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
|
2280 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
|
2281 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2282 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2283 break; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2284 case Print_kind: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2285 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
|
2286 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
|
2287 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
|
2288 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
|
2289 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
|
2290 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2291 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2292 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
|
2293 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
|
2294 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
|
2295 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2296 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2297 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
|
2298 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
|
2299 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
|
2300 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2301 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2302 break; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2303 case For_kind: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2304 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
|
2305 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
|
2306 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
|
2307 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
|
2308 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
|
2309 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2310 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2311 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
|
2312 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
|
2313 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
|
2314 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2315 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2316 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
|
2317 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
|
2318 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
|
2319 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2320 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2321 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
|
2322 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
|
2323 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
|
2324 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2325 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2326 break; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2327 case While_kind: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2328 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
|
2329 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
|
2330 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
|
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, "test", 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.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
|
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, "body", 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 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
|
2341 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
|
2342 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
|
2343 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2344 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2345 break; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2346 case If_kind: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2347 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
|
2348 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
|
2349 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
|
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, "test", 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 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
|
2355 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
|
2356 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
|
2357 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2358 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2359 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
|
2360 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
|
2361 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
|
2362 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2363 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2364 break; |
|
36695
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36669
diff
changeset
|
2365 case With_kind: |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36669
diff
changeset
|
2366 result = PyType_GenericNew(With_type, NULL, NULL); |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36669
diff
changeset
|
2367 if (!result) goto failed; |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36669
diff
changeset
|
2368 value = ast2obj_expr(o->v.With.context_expr); |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36669
diff
changeset
|
2369 if (!value) goto failed; |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36669
diff
changeset
|
2370 if (PyObject_SetAttrString(result, "context_expr", value) == -1) |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36669
diff
changeset
|
2371 goto failed; |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36669
diff
changeset
|
2372 Py_DECREF(value); |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36669
diff
changeset
|
2373 value = ast2obj_expr(o->v.With.optional_vars); |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36669
diff
changeset
|
2374 if (!value) goto failed; |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36669
diff
changeset
|
2375 if (PyObject_SetAttrString(result, "optional_vars", value) == |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36669
diff
changeset
|
2376 -1) |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36669
diff
changeset
|
2377 goto failed; |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36669
diff
changeset
|
2378 Py_DECREF(value); |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36669
diff
changeset
|
2379 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
|
2380 if (!value) goto failed; |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36669
diff
changeset
|
2381 if (PyObject_SetAttrString(result, "body", value) == -1) |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36669
diff
changeset
|
2382 goto failed; |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36669
diff
changeset
|
2383 Py_DECREF(value); |
|
b6d2f6fd3e11
PEP 343 -- the with-statement.
Guido van Rossum <guido@python.org>
parents:
36669
diff
changeset
|
2384 break; |
|
36660
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2385 case Raise_kind: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2386 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
|
2387 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
|
2388 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
|
2389 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
|
2390 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
|
2391 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2392 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2393 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
|
2394 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
|
2395 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
|
2396 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2397 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2398 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
|
2399 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
|
2400 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
|
2401 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2402 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2403 break; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2404 case TryExcept_kind: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2405 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
|
2406 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
|
2407 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
|
2408 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
|
2409 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
|
2410 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2411 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2412 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
|
2413 ast2obj_excepthandler); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2414 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
|
2415 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
|
2416 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2417 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2418 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
|
2419 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
|
2420 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
|
2421 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2422 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2423 break; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2424 case TryFinally_kind: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2425 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
|
2426 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
|
2427 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
|
2428 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
|
2429 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
|
2430 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2431 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2432 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
|
2433 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
|
2434 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
|
2435 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2436 Py_DECREF(value); |
|
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 Assert_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(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
|
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 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
|
2442 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
|
2443 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
|
2444 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2445 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2446 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
|
2447 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
|
2448 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
|
2449 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2450 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2451 break; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2452 case Import_kind: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2453 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
|
2454 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
|
2455 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
|
2456 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
|
2457 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
|
2458 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2459 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2460 break; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2461 case ImportFrom_kind: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2462 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
|
2463 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
|
2464 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
|
2465 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
|
2466 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
|
2467 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2468 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2469 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
|
2470 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
|
2471 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
|
2472 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2473 Py_DECREF(value); |
|
36712
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36707
diff
changeset
|
2474 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
|
2475 if (!value) goto failed; |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36707
diff
changeset
|
2476 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
|
2477 goto failed; |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36707
diff
changeset
|
2478 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
|
2479 break; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2480 case Exec_kind: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2481 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
|
2482 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
|
2483 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
|
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, "body", 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 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
|
2489 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
|
2490 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
|
2491 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2492 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2493 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
|
2494 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
|
2495 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
|
2496 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2497 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2498 break; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2499 case Global_kind: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2500 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
|
2501 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
|
2502 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
|
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, "names", 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 Expr_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(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
|
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_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
|
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, "value", 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 break; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2517 case Pass_kind: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2518 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
|
2519 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
|
2520 break; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2521 case Break_kind: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2522 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
|
2523 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
|
2524 break; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2525 case Continue_kind: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2526 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
|
2527 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
|
2528 break; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2529 } |
| 36669 | 2530 value = ast2obj_int(o->lineno); |
| 2531 if (!value) goto failed; | |
|
36794
df843b07f5fe
Fix memory leak on attributes.
Martin v. Löwis <martin@v.loewis.de>
parents:
36786
diff
changeset
|
2532 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
|
2533 goto failed; |
|
df843b07f5fe
Fix memory leak on attributes.
Martin v. Löwis <martin@v.loewis.de>
parents:
36786
diff
changeset
|
2534 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
|
2535 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
|
2536 if (!value) goto failed; |
|
36794
df843b07f5fe
Fix memory leak on attributes.
Martin v. Löwis <martin@v.loewis.de>
parents:
36786
diff
changeset
|
2537 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
|
2538 goto failed; |
|
df843b07f5fe
Fix memory leak on attributes.
Martin v. Löwis <martin@v.loewis.de>
parents:
36786
diff
changeset
|
2539 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
|
2540 return result; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2541 failed: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2542 Py_XDECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2543 Py_XDECREF(result); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2544 return NULL; |
|
35866
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
2545 } |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
2546 |
|
36660
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2547 PyObject* |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2548 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
|
2549 { |
|
36660
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2550 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
|
2551 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
|
2552 if (!o) { |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2553 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
|
2554 return Py_None; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2555 } |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2556 |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2557 switch (o->kind) { |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2558 case BoolOp_kind: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2559 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
|
2560 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
|
2561 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
|
2562 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
|
2563 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
|
2564 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2565 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2566 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
|
2567 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
|
2568 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
|
2569 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2570 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2571 break; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2572 case BinOp_kind: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2573 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
|
2574 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
|
2575 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
|
2576 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
|
2577 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
|
2578 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2579 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2580 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
|
2581 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
|
2582 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
|
2583 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2584 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2585 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
|
2586 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
|
2587 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
|
2588 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2589 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2590 break; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2591 case UnaryOp_kind: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2592 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
|
2593 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
|
2594 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
|
2595 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
|
2596 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
|
2597 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2598 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2599 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
|
2600 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
|
2601 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
|
2602 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2603 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2604 break; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2605 case Lambda_kind: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2606 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
|
2607 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
|
2608 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
|
2609 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
|
2610 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
|
2611 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2612 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2613 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
|
2614 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
|
2615 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
|
2616 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2617 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2618 break; |
|
36666
6165927431d6
PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents:
36665
diff
changeset
|
2619 case IfExp_kind: |
|
6165927431d6
PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents:
36665
diff
changeset
|
2620 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
|
2621 if (!result) goto failed; |
|
6165927431d6
PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents:
36665
diff
changeset
|
2622 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
|
2623 if (!value) goto failed; |
|
6165927431d6
PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents:
36665
diff
changeset
|
2624 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
|
2625 goto failed; |
|
6165927431d6
PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents:
36665
diff
changeset
|
2626 Py_DECREF(value); |
|
6165927431d6
PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents:
36665
diff
changeset
|
2627 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
|
2628 if (!value) goto failed; |
|
6165927431d6
PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents:
36665
diff
changeset
|
2629 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
|
2630 goto failed; |
|
6165927431d6
PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents:
36665
diff
changeset
|
2631 Py_DECREF(value); |
|
6165927431d6
PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents:
36665
diff
changeset
|
2632 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
|
2633 if (!value) goto failed; |
|
6165927431d6
PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents:
36665
diff
changeset
|
2634 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
|
2635 goto failed; |
|
6165927431d6
PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents:
36665
diff
changeset
|
2636 Py_DECREF(value); |
|
6165927431d6
PEP 308 implementation, including minor refdocs and some testcases. It
Thomas Wouters <thomas@python.org>
parents:
36665
diff
changeset
|
2637 break; |
|
36660
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2638 case Dict_kind: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2639 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
|
2640 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
|
2641 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
|
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, "keys", 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.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
|
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, "values", 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 break; |
|
58229
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
2652 case Set_kind: |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
2653 result = PyType_GenericNew(Set_type, NULL, NULL); |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
2654 if (!result) goto failed; |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
2655 value = ast2obj_list(o->v.Set.elts, ast2obj_expr); |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
2656 if (!value) goto failed; |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
2657 if (PyObject_SetAttrString(result, "elts", value) == -1) |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
2658 goto failed; |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
2659 Py_DECREF(value); |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
2660 break; |
|
36660
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2661 case ListComp_kind: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2662 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
|
2663 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
|
2664 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
|
2665 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
|
2666 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
|
2667 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2668 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2669 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
|
2670 ast2obj_comprehension); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2671 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
|
2672 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
|
2673 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2674 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2675 break; |
|
58250
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
2676 case SetComp_kind: |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
2677 result = PyType_GenericNew(SetComp_type, NULL, NULL); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
2678 if (!result) goto failed; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
2679 value = ast2obj_expr(o->v.SetComp.elt); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
2680 if (!value) goto failed; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
2681 if (PyObject_SetAttrString(result, "elt", value) == -1) |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
2682 goto failed; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
2683 Py_DECREF(value); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
2684 value = ast2obj_list(o->v.SetComp.generators, |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
2685 ast2obj_comprehension); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
2686 if (!value) goto failed; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
2687 if (PyObject_SetAttrString(result, "generators", value) == -1) |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
2688 goto failed; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
2689 Py_DECREF(value); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
2690 break; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
2691 case DictComp_kind: |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
2692 result = PyType_GenericNew(DictComp_type, NULL, NULL); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
2693 if (!result) goto failed; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
2694 value = ast2obj_expr(o->v.DictComp.key); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
2695 if (!value) goto failed; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
2696 if (PyObject_SetAttrString(result, "key", value) == -1) |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
2697 goto failed; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
2698 Py_DECREF(value); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
2699 value = ast2obj_expr(o->v.DictComp.value); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
2700 if (!value) goto failed; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
2701 if (PyObject_SetAttrString(result, "value", value) == -1) |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
2702 goto failed; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
2703 Py_DECREF(value); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
2704 value = ast2obj_list(o->v.DictComp.generators, |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
2705 ast2obj_comprehension); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
2706 if (!value) goto failed; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
2707 if (PyObject_SetAttrString(result, "generators", value) == -1) |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
2708 goto failed; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
2709 Py_DECREF(value); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
2710 break; |
|
36660
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2711 case GeneratorExp_kind: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2712 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
|
2713 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
|
2714 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
|
2715 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
|
2716 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
|
2717 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2718 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2719 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
|
2720 ast2obj_comprehension); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2721 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
|
2722 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
|
2723 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2724 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2725 break; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2726 case Yield_kind: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2727 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
|
2728 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
|
2729 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
|
2730 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
|
2731 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
|
2732 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2733 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2734 break; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2735 case Compare_kind: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2736 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
|
2737 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
|
2738 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
|
2739 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
|
2740 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
|
2741 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2742 Py_DECREF(value); |
|
36661
710cbdd478a8
Fix iterating over cmpop_ty lists.
Martin v. Löwis <martin@v.loewis.de>
parents:
36660
diff
changeset
|
2743 { |
|
710cbdd478a8
Fix iterating over cmpop_ty lists.
Martin v. Löwis <martin@v.loewis.de>
parents:
36660
diff
changeset
|
2744 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
|
2745 value = PyList_New(n); |
|
710cbdd478a8
Fix iterating over cmpop_ty lists.
Martin v. Löwis <martin@v.loewis.de>
parents:
36660
diff
changeset
|
2746 if (!value) goto failed; |
|
710cbdd478a8
Fix iterating over cmpop_ty lists.
Martin v. Löwis <martin@v.loewis.de>
parents:
36660
diff
changeset
|
2747 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
|
2748 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
|
2749 } |
|
36660
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, "ops", 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 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
|
2755 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
|
2756 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
|
2757 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2758 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2759 break; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2760 case Call_kind: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2761 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
|
2762 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
|
2763 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
|
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, "func", 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 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
|
2769 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
|
2770 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
|
2771 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2772 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2773 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
|
2774 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
|
2775 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
|
2776 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2777 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2778 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
|
2779 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
|
2780 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
|
2781 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2782 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2783 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
|
2784 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
|
2785 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
|
2786 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2787 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2788 break; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2789 case Repr_kind: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2790 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
|
2791 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
|
2792 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
|
2793 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
|
2794 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
|
2795 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2796 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2797 break; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2798 case Num_kind: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2799 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
|
2800 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
|
2801 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
|
2802 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
|
2803 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
|
2804 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2805 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2806 break; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2807 case Str_kind: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2808 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
|
2809 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
|
2810 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
|
2811 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
|
2812 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
|
2813 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2814 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2815 break; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2816 case Attribute_kind: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2817 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
|
2818 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
|
2819 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
|
2820 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
|
2821 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
|
2822 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2823 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2824 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
|
2825 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
|
2826 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
|
2827 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2828 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2829 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
|
2830 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
|
2831 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
|
2832 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2833 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2834 break; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2835 case Subscript_kind: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2836 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
|
2837 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
|
2838 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
|
2839 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
|
2840 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
|
2841 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2842 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2843 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
|
2844 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
|
2845 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
|
2846 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2847 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2848 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
|
2849 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
|
2850 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
|
2851 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2852 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2853 break; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2854 case Name_kind: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2855 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
|
2856 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
|
2857 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
|
2858 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
|
2859 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
|
2860 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2861 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2862 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
|
2863 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
|
2864 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
|
2865 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2866 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2867 break; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2868 case List_kind: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2869 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
|
2870 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
|
2871 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
|
2872 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
|
2873 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
|
2874 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2875 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2876 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
|
2877 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
|
2878 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
|
2879 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2880 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2881 break; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2882 case Tuple_kind: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2883 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
|
2884 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
|
2885 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
|
2886 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
|
2887 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
|
2888 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2889 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2890 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
|
2891 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
|
2892 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
|
2893 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2894 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2895 break; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2896 } |
| 36669 | 2897 value = ast2obj_int(o->lineno); |
| 2898 if (!value) goto failed; | |
|
36794
df843b07f5fe
Fix memory leak on attributes.
Martin v. Löwis <martin@v.loewis.de>
parents:
36786
diff
changeset
|
2899 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
|
2900 goto failed; |
|
df843b07f5fe
Fix memory leak on attributes.
Martin v. Löwis <martin@v.loewis.de>
parents:
36786
diff
changeset
|
2901 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
|
2902 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
|
2903 if (!value) goto failed; |
|
36794
df843b07f5fe
Fix memory leak on attributes.
Martin v. Löwis <martin@v.loewis.de>
parents:
36786
diff
changeset
|
2904 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
|
2905 goto failed; |
|
df843b07f5fe
Fix memory leak on attributes.
Martin v. Löwis <martin@v.loewis.de>
parents:
36786
diff
changeset
|
2906 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
|
2907 return result; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2908 failed: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2909 Py_XDECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2910 Py_XDECREF(result); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2911 return NULL; |
|
35866
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
2912 } |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
2913 |
|
36660
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2914 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
|
2915 { |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2916 switch(o) { |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2917 case Load: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2918 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
|
2919 return Load_singleton; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2920 case Store: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2921 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
|
2922 return Store_singleton; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2923 case Del: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2924 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
|
2925 return Del_singleton; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2926 case AugLoad: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2927 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
|
2928 return AugLoad_singleton; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2929 case AugStore: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2930 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
|
2931 return AugStore_singleton; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2932 case Param: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2933 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
|
2934 return Param_singleton; |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
2935 default: |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
2936 /* 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
|
2937 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
|
2938 return NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
2939 } |
|
36660
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2940 } |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2941 PyObject* |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2942 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
|
2943 { |
|
36660
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2944 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
|
2945 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
|
2946 if (!o) { |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2947 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
|
2948 return Py_None; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2949 } |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2950 |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2951 switch (o->kind) { |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2952 case Ellipsis_kind: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2953 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
|
2954 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
|
2955 break; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2956 case Slice_kind: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2957 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
|
2958 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
|
2959 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
|
2960 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
|
2961 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
|
2962 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2963 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2964 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
|
2965 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
|
2966 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
|
2967 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2968 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2969 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
|
2970 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
|
2971 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
|
2972 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2973 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2974 break; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2975 case ExtSlice_kind: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2976 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
|
2977 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
|
2978 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
|
2979 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
|
2980 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
|
2981 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2982 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2983 break; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2984 case Index_kind: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2985 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
|
2986 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
|
2987 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
|
2988 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
|
2989 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
|
2990 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2991 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2992 break; |
|
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 return result; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2995 failed: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2996 Py_XDECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2997 Py_XDECREF(result); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
2998 return NULL; |
|
35866
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
2999 } |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
3000 |
|
36660
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3001 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
|
3002 { |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3003 switch(o) { |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3004 case And: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3005 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
|
3006 return And_singleton; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3007 case Or: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3008 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
|
3009 return Or_singleton; |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3010 default: |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3011 /* 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
|
3012 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
|
3013 return NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3014 } |
|
36660
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3015 } |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3016 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
|
3017 { |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3018 switch(o) { |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3019 case Add: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3020 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
|
3021 return Add_singleton; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3022 case Sub: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3023 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
|
3024 return Sub_singleton; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3025 case Mult: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3026 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
|
3027 return Mult_singleton; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3028 case Div: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3029 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
|
3030 return Div_singleton; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3031 case Mod: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3032 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
|
3033 return Mod_singleton; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3034 case Pow: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3035 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
|
3036 return Pow_singleton; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3037 case LShift: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3038 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
|
3039 return LShift_singleton; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3040 case RShift: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3041 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
|
3042 return RShift_singleton; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3043 case BitOr: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3044 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
|
3045 return BitOr_singleton; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3046 case BitXor: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3047 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
|
3048 return BitXor_singleton; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3049 case BitAnd: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3050 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
|
3051 return BitAnd_singleton; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3052 case FloorDiv: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3053 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
|
3054 return FloorDiv_singleton; |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3055 default: |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3056 /* 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
|
3057 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
|
3058 return NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3059 } |
|
36660
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3060 } |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3061 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
|
3062 { |
|
36660
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3063 switch(o) { |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3064 case Invert: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3065 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
|
3066 return Invert_singleton; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3067 case Not: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3068 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
|
3069 return Not_singleton; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3070 case UAdd: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3071 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
|
3072 return UAdd_singleton; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3073 case USub: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3074 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
|
3075 return USub_singleton; |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3076 default: |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3077 /* 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
|
3078 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
|
3079 return NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3080 } |
|
36660
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3081 } |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3082 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
|
3083 { |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3084 switch(o) { |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3085 case Eq: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3086 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
|
3087 return Eq_singleton; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3088 case NotEq: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3089 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
|
3090 return NotEq_singleton; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3091 case Lt: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3092 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
|
3093 return Lt_singleton; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3094 case LtE: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3095 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
|
3096 return LtE_singleton; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3097 case Gt: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3098 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
|
3099 return Gt_singleton; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3100 case GtE: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3101 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
|
3102 return GtE_singleton; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3103 case Is: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3104 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
|
3105 return Is_singleton; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3106 case IsNot: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3107 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
|
3108 return IsNot_singleton; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3109 case In: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3110 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
|
3111 return In_singleton; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3112 case NotIn: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3113 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
|
3114 return NotIn_singleton; |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3115 default: |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3116 /* 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
|
3117 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
|
3118 return NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3119 } |
|
36660
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3120 } |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3121 PyObject* |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3122 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
|
3123 { |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3124 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
|
3125 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
|
3126 if (!o) { |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3127 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
|
3128 return Py_None; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3129 } |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3130 |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3131 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
|
3132 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
|
3133 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
|
3134 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
|
3135 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
|
3136 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3137 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3138 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
|
3139 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
|
3140 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
|
3141 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3142 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3143 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
|
3144 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
|
3145 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
|
3146 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3147 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3148 return result; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3149 failed: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3150 Py_XDECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3151 Py_XDECREF(result); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3152 return NULL; |
|
35866
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
3153 } |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
3154 |
|
36660
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3155 PyObject* |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3156 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
|
3157 { |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3158 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
|
3159 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
|
3160 if (!o) { |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3161 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
|
3162 return Py_None; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3163 } |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3164 |
|
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
|
3165 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
|
3166 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
|
3167 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
|
3168 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
|
3169 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
|
3170 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
|
3171 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
|
3172 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
|
3173 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
|
3174 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
|
3175 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
|
3176 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
|
3177 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
|
3178 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
|
3179 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
|
3180 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
|
3181 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
|
3182 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
|
3183 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
|
3184 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
|
3185 } |
|
37453
16a64e394602
Add lineno, col_offset to excephandler to enable future fix for
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37412
diff
changeset
|
3186 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
|
3187 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
|
3188 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
|
3189 goto failed; |
|
16a64e394602
Add lineno, col_offset to excephandler to enable future fix for
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37412
diff
changeset
|
3190 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
|
3191 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
|
3192 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
|
3193 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
|
3194 goto failed; |
|
16a64e394602
Add lineno, col_offset to excephandler to enable future fix for
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
37412
diff
changeset
|
3195 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
|
3196 return result; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3197 failed: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3198 Py_XDECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3199 Py_XDECREF(result); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3200 return NULL; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3201 } |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3202 |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3203 PyObject* |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3204 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
|
3205 { |
|
36660
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3206 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
|
3207 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
|
3208 if (!o) { |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3209 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
|
3210 return Py_None; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3211 } |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3212 |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3213 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
|
3214 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
|
3215 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
|
3216 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
|
3217 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
|
3218 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3219 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3220 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
|
3221 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
|
3222 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
|
3223 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3224 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3225 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
|
3226 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
|
3227 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
|
3228 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3229 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3230 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
|
3231 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
|
3232 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
|
3233 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3234 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3235 return result; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3236 failed: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3237 Py_XDECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3238 Py_XDECREF(result); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3239 return NULL; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3240 } |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3241 |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3242 PyObject* |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3243 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
|
3244 { |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3245 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
|
3246 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
|
3247 if (!o) { |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3248 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
|
3249 return Py_None; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3250 } |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3251 |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3252 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
|
3253 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
|
3254 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
|
3255 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
|
3256 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
|
3257 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3258 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3259 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
|
3260 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
|
3261 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
|
3262 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3263 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3264 return result; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3265 failed: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3266 Py_XDECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3267 Py_XDECREF(result); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3268 return NULL; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3269 } |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3270 |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3271 PyObject* |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3272 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
|
3273 { |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3274 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
|
3275 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
|
3276 if (!o) { |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3277 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
|
3278 return Py_None; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3279 } |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3280 |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3281 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
|
3282 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
|
3283 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
|
3284 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
|
3285 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
|
3286 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3287 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3288 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
|
3289 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
|
3290 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
|
3291 goto failed; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3292 Py_DECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3293 return result; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3294 failed: |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3295 Py_XDECREF(value); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3296 Py_XDECREF(result); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
3297 return NULL; |
|
35866
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
3298 } |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
3299 |
|
9f73dc0953d2
Whoops, checkin consistent versions of *all* files to stop polluting
Neal Norwitz <nnorwitz@gmail.com>
parents:
35862
diff
changeset
|
3300 |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3301 int |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3302 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
|
3303 { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3304 PyObject* tmp = NULL; |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3305 int isinstance; |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3306 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3307 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3308 if (obj == Py_None) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3309 *out = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3310 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3311 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3312 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
|
3313 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3314 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3315 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3316 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3317 asdl_seq* body; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3318 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3319 if (PyObject_HasAttrString(obj, "body")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3320 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3321 Py_ssize_t len; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3322 Py_ssize_t i; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3323 tmp = PyObject_GetAttrString(obj, "body"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3324 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3325 if (!PyList_Check(tmp)) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3326 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
|
3327 goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3328 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3329 len = PyList_GET_SIZE(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3330 body = asdl_seq_new(len, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3331 if (body == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3332 for (i = 0; i < len; i++) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3333 stmt_ty value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3334 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
|
3335 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3336 asdl_seq_SET(body, i, value); |
|
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 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3339 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3340 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3341 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
|
3342 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3343 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3344 *out = Module(body, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3345 if (*out == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3346 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3347 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3348 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
|
3349 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3350 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3351 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3352 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3353 asdl_seq* body; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3354 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3355 if (PyObject_HasAttrString(obj, "body")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3356 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3357 Py_ssize_t len; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3358 Py_ssize_t i; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3359 tmp = PyObject_GetAttrString(obj, "body"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3360 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3361 if (!PyList_Check(tmp)) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3362 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
|
3363 goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3364 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3365 len = PyList_GET_SIZE(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3366 body = asdl_seq_new(len, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3367 if (body == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3368 for (i = 0; i < len; i++) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3369 stmt_ty value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3370 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
|
3371 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3372 asdl_seq_SET(body, i, value); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3373 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3374 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3375 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3376 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3377 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
|
3378 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3379 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3380 *out = Interactive(body, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3381 if (*out == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3382 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3383 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3384 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
|
3385 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3386 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3387 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3388 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3389 expr_ty body; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3390 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3391 if (PyObject_HasAttrString(obj, "body")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3392 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3393 tmp = PyObject_GetAttrString(obj, "body"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3394 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3395 res = obj2ast_expr(tmp, &body, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3396 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3397 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3398 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3399 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3400 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
|
3401 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3402 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3403 *out = Expression(body, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3404 if (*out == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3405 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3406 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3407 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
|
3408 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3409 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3410 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3411 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3412 asdl_seq* body; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3413 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3414 if (PyObject_HasAttrString(obj, "body")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3415 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3416 Py_ssize_t len; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3417 Py_ssize_t i; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3418 tmp = PyObject_GetAttrString(obj, "body"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3419 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3420 if (!PyList_Check(tmp)) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3421 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
|
3422 goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3423 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3424 len = PyList_GET_SIZE(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3425 body = asdl_seq_new(len, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3426 if (body == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3427 for (i = 0; i < len; i++) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3428 stmt_ty value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3429 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
|
3430 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3431 asdl_seq_SET(body, i, value); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3432 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3433 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3434 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3435 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3436 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
|
3437 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3438 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3439 *out = Suite(body, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3440 if (*out == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3441 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3442 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3443 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3444 tmp = PyObject_Repr(obj); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3445 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
|
3446 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
|
3447 failed: |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3448 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3449 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3450 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3451 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3452 int |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3453 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
|
3454 { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3455 PyObject* tmp = NULL; |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3456 int isinstance; |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3457 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3458 int lineno; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3459 int col_offset; |
|
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 (obj == Py_None) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3462 *out = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3463 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3464 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3465 if (PyObject_HasAttrString(obj, "lineno")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3466 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3467 tmp = PyObject_GetAttrString(obj, "lineno"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3468 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3469 res = obj2ast_int(tmp, &lineno, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3470 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3471 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3472 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3473 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3474 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
|
3475 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3476 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3477 if (PyObject_HasAttrString(obj, "col_offset")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3478 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3479 tmp = PyObject_GetAttrString(obj, "col_offset"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3480 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3481 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
|
3482 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3483 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3484 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3485 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3486 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
|
3487 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3488 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3489 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
|
3490 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3491 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3492 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3493 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3494 identifier name; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3495 arguments_ty args; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3496 asdl_seq* body; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3497 asdl_seq* decorator_list; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3498 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3499 if (PyObject_HasAttrString(obj, "name")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3500 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3501 tmp = PyObject_GetAttrString(obj, "name"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3502 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3503 res = obj2ast_identifier(tmp, &name, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3504 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3505 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3506 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3507 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3508 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
|
3509 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3510 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3511 if (PyObject_HasAttrString(obj, "args")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3512 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3513 tmp = PyObject_GetAttrString(obj, "args"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3514 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3515 res = obj2ast_arguments(tmp, &args, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3516 if (res != 0) goto failed; |
|
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 \"args\" missing from FunctionDef"); |
|
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, "body")) { |
|
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, "body"); |
|
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, "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
|
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 body = 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 (body == 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 stmt_ty value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3538 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
|
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(body, 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 \"body\" missing from FunctionDef"); |
|
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 if (PyObject_HasAttrString(obj, "decorator_list")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3549 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3550 Py_ssize_t len; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3551 Py_ssize_t i; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3552 tmp = PyObject_GetAttrString(obj, "decorator_list"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3553 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3554 if (!PyList_Check(tmp)) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3555 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
|
3556 goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3557 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3558 len = PyList_GET_SIZE(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3559 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
|
3560 if (decorator_list == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3561 for (i = 0; i < len; i++) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3562 expr_ty value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3563 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
|
3564 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3565 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
|
3566 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3567 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3568 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3569 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3570 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
|
3571 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3572 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3573 *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
|
3574 col_offset, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3575 if (*out == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3576 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3577 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3578 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
|
3579 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3580 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3581 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3582 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3583 identifier name; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3584 asdl_seq* bases; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3585 asdl_seq* body; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3586 asdl_seq* decorator_list; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3587 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3588 if (PyObject_HasAttrString(obj, "name")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3589 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3590 tmp = PyObject_GetAttrString(obj, "name"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3591 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3592 res = obj2ast_identifier(tmp, &name, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3593 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3594 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3595 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3596 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3597 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
|
3598 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3599 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3600 if (PyObject_HasAttrString(obj, "bases")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3601 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3602 Py_ssize_t len; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3603 Py_ssize_t i; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3604 tmp = PyObject_GetAttrString(obj, "bases"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3605 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3606 if (!PyList_Check(tmp)) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3607 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
|
3608 goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3609 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3610 len = PyList_GET_SIZE(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3611 bases = asdl_seq_new(len, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3612 if (bases == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3613 for (i = 0; i < len; i++) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3614 expr_ty value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3615 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
|
3616 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3617 asdl_seq_SET(bases, i, 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 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3620 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3621 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3622 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
|
3623 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3624 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3625 if (PyObject_HasAttrString(obj, "body")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3626 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3627 Py_ssize_t len; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3628 Py_ssize_t i; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3629 tmp = PyObject_GetAttrString(obj, "body"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3630 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3631 if (!PyList_Check(tmp)) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3632 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
|
3633 goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3634 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3635 len = PyList_GET_SIZE(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3636 body = asdl_seq_new(len, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3637 if (body == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3638 for (i = 0; i < len; i++) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3639 stmt_ty value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3640 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
|
3641 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3642 asdl_seq_SET(body, i, value); |
|
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 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3645 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3646 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3647 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
|
3648 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3649 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3650 if (PyObject_HasAttrString(obj, "decorator_list")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3651 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3652 Py_ssize_t len; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3653 Py_ssize_t i; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3654 tmp = PyObject_GetAttrString(obj, "decorator_list"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3655 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3656 if (!PyList_Check(tmp)) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3657 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
|
3658 goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3659 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3660 len = PyList_GET_SIZE(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3661 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
|
3662 if (decorator_list == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3663 for (i = 0; i < len; i++) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3664 expr_ty value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3665 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
|
3666 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3667 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
|
3668 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3669 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3670 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3671 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3672 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
|
3673 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3674 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3675 *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
|
3676 col_offset, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3677 if (*out == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3678 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3679 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3680 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
|
3681 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3682 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3683 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3684 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3685 expr_ty value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3686 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3687 if (PyObject_HasAttrString(obj, "value")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3688 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3689 tmp = PyObject_GetAttrString(obj, "value"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3690 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3691 res = obj2ast_expr(tmp, &value, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3692 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3693 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3694 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3695 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3696 value = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3697 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3698 *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
|
3699 if (*out == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3700 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3701 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3702 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
|
3703 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3704 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3705 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3706 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3707 asdl_seq* targets; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3708 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3709 if (PyObject_HasAttrString(obj, "targets")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3710 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3711 Py_ssize_t len; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3712 Py_ssize_t i; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3713 tmp = PyObject_GetAttrString(obj, "targets"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3714 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3715 if (!PyList_Check(tmp)) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3716 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
|
3717 goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3718 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3719 len = PyList_GET_SIZE(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3720 targets = asdl_seq_new(len, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3721 if (targets == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3722 for (i = 0; i < len; i++) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3723 expr_ty value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3724 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
|
3725 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3726 asdl_seq_SET(targets, i, value); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3727 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3728 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3729 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3730 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3731 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
|
3732 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3733 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3734 *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
|
3735 if (*out == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3736 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3737 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3738 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
|
3739 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3740 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3741 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3742 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3743 asdl_seq* targets; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3744 expr_ty value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3745 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3746 if (PyObject_HasAttrString(obj, "targets")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3747 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3748 Py_ssize_t len; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3749 Py_ssize_t i; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3750 tmp = PyObject_GetAttrString(obj, "targets"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3751 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3752 if (!PyList_Check(tmp)) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3753 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
|
3754 goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3755 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3756 len = PyList_GET_SIZE(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3757 targets = asdl_seq_new(len, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3758 if (targets == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3759 for (i = 0; i < len; i++) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3760 expr_ty value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3761 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
|
3762 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3763 asdl_seq_SET(targets, i, value); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3764 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3765 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3766 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3767 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3768 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
|
3769 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3770 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3771 if (PyObject_HasAttrString(obj, "value")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3772 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3773 tmp = PyObject_GetAttrString(obj, "value"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3774 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3775 res = obj2ast_expr(tmp, &value, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3776 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3777 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3778 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3779 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3780 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
|
3781 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3782 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3783 *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
|
3784 if (*out == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3785 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3786 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3787 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
|
3788 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3789 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3790 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3791 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3792 expr_ty target; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3793 operator_ty op; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3794 expr_ty value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3795 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3796 if (PyObject_HasAttrString(obj, "target")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3797 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3798 tmp = PyObject_GetAttrString(obj, "target"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3799 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3800 res = obj2ast_expr(tmp, &target, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3801 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3802 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3803 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3804 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3805 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
|
3806 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3807 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3808 if (PyObject_HasAttrString(obj, "op")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3809 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3810 tmp = PyObject_GetAttrString(obj, "op"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3811 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3812 res = obj2ast_operator(tmp, &op, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3813 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3814 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3815 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3816 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3817 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
|
3818 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3819 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3820 if (PyObject_HasAttrString(obj, "value")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3821 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3822 tmp = PyObject_GetAttrString(obj, "value"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3823 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3824 res = obj2ast_expr(tmp, &value, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3825 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3826 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3827 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3828 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3829 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
|
3830 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3831 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3832 *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
|
3833 if (*out == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3834 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3835 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3836 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
|
3837 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3838 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3839 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3840 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3841 expr_ty dest; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3842 asdl_seq* values; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3843 bool nl; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3844 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3845 if (PyObject_HasAttrString(obj, "dest")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3846 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3847 tmp = PyObject_GetAttrString(obj, "dest"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3848 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3849 res = obj2ast_expr(tmp, &dest, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3850 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3851 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3852 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3853 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3854 dest = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3855 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3856 if (PyObject_HasAttrString(obj, "values")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3857 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3858 Py_ssize_t len; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3859 Py_ssize_t i; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3860 tmp = PyObject_GetAttrString(obj, "values"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3861 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3862 if (!PyList_Check(tmp)) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3863 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
|
3864 goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3865 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3866 len = PyList_GET_SIZE(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3867 values = asdl_seq_new(len, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3868 if (values == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3869 for (i = 0; i < len; i++) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3870 expr_ty value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3871 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
|
3872 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3873 asdl_seq_SET(values, i, value); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3874 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3875 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3876 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3877 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3878 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
|
3879 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3880 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3881 if (PyObject_HasAttrString(obj, "nl")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3882 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3883 tmp = PyObject_GetAttrString(obj, "nl"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3884 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3885 res = obj2ast_bool(tmp, &nl, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3886 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3887 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3888 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3889 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3890 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
|
3891 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3892 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3893 *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
|
3894 if (*out == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3895 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3896 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3897 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
|
3898 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3899 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3900 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3901 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3902 expr_ty target; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3903 expr_ty iter; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3904 asdl_seq* body; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3905 asdl_seq* orelse; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3906 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3907 if (PyObject_HasAttrString(obj, "target")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3908 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3909 tmp = PyObject_GetAttrString(obj, "target"); |
|
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 res = obj2ast_expr(tmp, &target, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3912 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3913 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3914 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3915 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3916 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
|
3917 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3918 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3919 if (PyObject_HasAttrString(obj, "iter")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3920 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3921 tmp = PyObject_GetAttrString(obj, "iter"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3922 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3923 res = obj2ast_expr(tmp, &iter, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3924 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3925 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3926 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3927 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3928 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
|
3929 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3930 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3931 if (PyObject_HasAttrString(obj, "body")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3932 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3933 Py_ssize_t len; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3934 Py_ssize_t i; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3935 tmp = PyObject_GetAttrString(obj, "body"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3936 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3937 if (!PyList_Check(tmp)) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3938 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
|
3939 goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3940 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3941 len = PyList_GET_SIZE(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3942 body = asdl_seq_new(len, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3943 if (body == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3944 for (i = 0; i < len; i++) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3945 stmt_ty value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3946 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
|
3947 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3948 asdl_seq_SET(body, i, value); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3949 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3950 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3951 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3952 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3953 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
|
3954 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3955 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3956 if (PyObject_HasAttrString(obj, "orelse")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3957 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3958 Py_ssize_t len; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3959 Py_ssize_t i; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3960 tmp = PyObject_GetAttrString(obj, "orelse"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3961 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3962 if (!PyList_Check(tmp)) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3963 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
|
3964 goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3965 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3966 len = PyList_GET_SIZE(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3967 orelse = asdl_seq_new(len, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3968 if (orelse == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3969 for (i = 0; i < len; i++) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3970 stmt_ty value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3971 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
|
3972 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3973 asdl_seq_SET(orelse, i, value); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3974 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3975 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3976 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3977 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3978 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
|
3979 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3980 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3981 *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
|
3982 arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3983 if (*out == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3984 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3985 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3986 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
|
3987 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3988 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3989 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
3990 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3991 expr_ty test; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3992 asdl_seq* body; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3993 asdl_seq* orelse; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3994 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3995 if (PyObject_HasAttrString(obj, "test")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3996 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3997 tmp = PyObject_GetAttrString(obj, "test"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3998 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
3999 res = obj2ast_expr(tmp, &test, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4000 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4001 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4002 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4003 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4004 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
|
4005 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4006 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4007 if (PyObject_HasAttrString(obj, "body")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4008 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4009 Py_ssize_t len; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4010 Py_ssize_t i; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4011 tmp = PyObject_GetAttrString(obj, "body"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4012 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4013 if (!PyList_Check(tmp)) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4014 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
|
4015 goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4016 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4017 len = PyList_GET_SIZE(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4018 body = asdl_seq_new(len, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4019 if (body == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4020 for (i = 0; i < len; i++) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4021 stmt_ty value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4022 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
|
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 asdl_seq_SET(body, i, value); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4025 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4026 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4027 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4028 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4029 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
|
4030 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4031 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4032 if (PyObject_HasAttrString(obj, "orelse")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4033 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4034 Py_ssize_t len; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4035 Py_ssize_t i; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4036 tmp = PyObject_GetAttrString(obj, "orelse"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4037 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4038 if (!PyList_Check(tmp)) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4039 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
|
4040 goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4041 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4042 len = PyList_GET_SIZE(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4043 orelse = asdl_seq_new(len, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4044 if (orelse == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4045 for (i = 0; i < len; i++) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4046 stmt_ty value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4047 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
|
4048 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4049 asdl_seq_SET(orelse, i, value); |
|
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 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4052 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4053 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4054 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
|
4055 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4056 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4057 *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
|
4058 if (*out == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4059 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4060 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4061 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
|
4062 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4063 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4064 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4065 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4066 expr_ty test; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4067 asdl_seq* body; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4068 asdl_seq* orelse; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4069 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4070 if (PyObject_HasAttrString(obj, "test")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4071 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4072 tmp = PyObject_GetAttrString(obj, "test"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4073 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4074 res = obj2ast_expr(tmp, &test, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4075 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4076 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4077 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4078 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4079 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
|
4080 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4081 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4082 if (PyObject_HasAttrString(obj, "body")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4083 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4084 Py_ssize_t len; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4085 Py_ssize_t i; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4086 tmp = PyObject_GetAttrString(obj, "body"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4087 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4088 if (!PyList_Check(tmp)) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4089 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
|
4090 goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4091 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4092 len = PyList_GET_SIZE(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4093 body = asdl_seq_new(len, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4094 if (body == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4095 for (i = 0; i < len; i++) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4096 stmt_ty value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4097 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
|
4098 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4099 asdl_seq_SET(body, i, value); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4100 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4101 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4102 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4103 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4104 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
|
4105 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4106 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4107 if (PyObject_HasAttrString(obj, "orelse")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4108 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4109 Py_ssize_t len; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4110 Py_ssize_t i; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4111 tmp = PyObject_GetAttrString(obj, "orelse"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4112 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4113 if (!PyList_Check(tmp)) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4114 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
|
4115 goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4116 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4117 len = PyList_GET_SIZE(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4118 orelse = asdl_seq_new(len, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4119 if (orelse == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4120 for (i = 0; i < len; i++) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4121 stmt_ty value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4122 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
|
4123 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4124 asdl_seq_SET(orelse, i, value); |
|
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 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4127 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4128 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4129 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
|
4130 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4131 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4132 *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
|
4133 if (*out == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4134 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4135 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4136 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
|
4137 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4138 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4139 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4140 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4141 expr_ty context_expr; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4142 expr_ty optional_vars; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4143 asdl_seq* body; |
|
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 if (PyObject_HasAttrString(obj, "context_expr")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4146 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4147 tmp = PyObject_GetAttrString(obj, "context_expr"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4148 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4149 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
|
4150 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4151 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4152 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4153 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4154 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
|
4155 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4156 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4157 if (PyObject_HasAttrString(obj, "optional_vars")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4158 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4159 tmp = PyObject_GetAttrString(obj, "optional_vars"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4160 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4161 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
|
4162 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4163 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4164 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4165 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4166 optional_vars = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4167 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4168 if (PyObject_HasAttrString(obj, "body")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4169 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4170 Py_ssize_t len; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4171 Py_ssize_t i; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4172 tmp = PyObject_GetAttrString(obj, "body"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4173 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4174 if (!PyList_Check(tmp)) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4175 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
|
4176 goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4177 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4178 len = PyList_GET_SIZE(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4179 body = asdl_seq_new(len, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4180 if (body == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4181 for (i = 0; i < len; i++) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4182 stmt_ty value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4183 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
|
4184 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4185 asdl_seq_SET(body, i, value); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4186 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4187 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4188 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4189 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4190 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
|
4191 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4192 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4193 *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
|
4194 col_offset, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4195 if (*out == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4196 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4197 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4198 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
|
4199 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4200 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4201 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4202 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4203 expr_ty type; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4204 expr_ty inst; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4205 expr_ty tback; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4206 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4207 if (PyObject_HasAttrString(obj, "type")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4208 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4209 tmp = PyObject_GetAttrString(obj, "type"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4210 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4211 res = obj2ast_expr(tmp, &type, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4212 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4213 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4214 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4215 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4216 type = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4217 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4218 if (PyObject_HasAttrString(obj, "inst")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4219 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4220 tmp = PyObject_GetAttrString(obj, "inst"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4221 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4222 res = obj2ast_expr(tmp, &inst, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4223 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4224 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4225 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4226 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4227 inst = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4228 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4229 if (PyObject_HasAttrString(obj, "tback")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4230 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4231 tmp = PyObject_GetAttrString(obj, "tback"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4232 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4233 res = obj2ast_expr(tmp, &tback, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4234 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4235 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4236 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4237 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4238 tback = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4239 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4240 *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
|
4241 if (*out == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4242 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4243 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4244 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
|
4245 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4246 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4247 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4248 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4249 asdl_seq* body; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4250 asdl_seq* handlers; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4251 asdl_seq* orelse; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4252 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4253 if (PyObject_HasAttrString(obj, "body")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4254 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4255 Py_ssize_t len; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4256 Py_ssize_t i; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4257 tmp = PyObject_GetAttrString(obj, "body"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4258 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4259 if (!PyList_Check(tmp)) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4260 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
|
4261 goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4262 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4263 len = PyList_GET_SIZE(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4264 body = asdl_seq_new(len, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4265 if (body == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4266 for (i = 0; i < len; i++) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4267 stmt_ty value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4268 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
|
4269 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4270 asdl_seq_SET(body, i, value); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4271 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4272 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4273 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4274 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4275 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
|
4276 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4277 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4278 if (PyObject_HasAttrString(obj, "handlers")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4279 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4280 Py_ssize_t len; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4281 Py_ssize_t i; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4282 tmp = PyObject_GetAttrString(obj, "handlers"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4283 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4284 if (!PyList_Check(tmp)) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4285 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
|
4286 goto failed; |
|
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 len = PyList_GET_SIZE(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4289 handlers = asdl_seq_new(len, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4290 if (handlers == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4291 for (i = 0; i < len; i++) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4292 excepthandler_ty value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4293 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
|
4294 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4295 asdl_seq_SET(handlers, i, value); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4296 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4297 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4298 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4299 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4300 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
|
4301 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4302 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4303 if (PyObject_HasAttrString(obj, "orelse")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4304 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4305 Py_ssize_t len; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4306 Py_ssize_t i; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4307 tmp = PyObject_GetAttrString(obj, "orelse"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4308 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4309 if (!PyList_Check(tmp)) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4310 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
|
4311 goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4312 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4313 len = PyList_GET_SIZE(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4314 orelse = asdl_seq_new(len, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4315 if (orelse == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4316 for (i = 0; i < len; i++) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4317 stmt_ty value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4318 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
|
4319 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4320 asdl_seq_SET(orelse, i, value); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4321 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4322 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4323 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4324 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4325 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
|
4326 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4327 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4328 *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
|
4329 arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4330 if (*out == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4331 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4332 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4333 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
|
4334 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4335 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4336 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4337 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4338 asdl_seq* body; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4339 asdl_seq* finalbody; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4340 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4341 if (PyObject_HasAttrString(obj, "body")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4342 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4343 Py_ssize_t len; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4344 Py_ssize_t i; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4345 tmp = PyObject_GetAttrString(obj, "body"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4346 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4347 if (!PyList_Check(tmp)) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4348 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
|
4349 goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4350 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4351 len = PyList_GET_SIZE(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4352 body = asdl_seq_new(len, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4353 if (body == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4354 for (i = 0; i < len; i++) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4355 stmt_ty value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4356 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
|
4357 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4358 asdl_seq_SET(body, i, value); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4359 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4360 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4361 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4362 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4363 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
|
4364 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4365 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4366 if (PyObject_HasAttrString(obj, "finalbody")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4367 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4368 Py_ssize_t len; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4369 Py_ssize_t i; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4370 tmp = PyObject_GetAttrString(obj, "finalbody"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4371 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4372 if (!PyList_Check(tmp)) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4373 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
|
4374 goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4375 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4376 len = PyList_GET_SIZE(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4377 finalbody = asdl_seq_new(len, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4378 if (finalbody == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4379 for (i = 0; i < len; i++) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4380 stmt_ty value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4381 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
|
4382 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4383 asdl_seq_SET(finalbody, i, value); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4384 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4385 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4386 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4387 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4388 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
|
4389 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4390 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4391 *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
|
4392 if (*out == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4393 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4394 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4395 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
|
4396 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4397 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4398 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4399 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4400 expr_ty test; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4401 expr_ty msg; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4402 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4403 if (PyObject_HasAttrString(obj, "test")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4404 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4405 tmp = PyObject_GetAttrString(obj, "test"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4406 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4407 res = obj2ast_expr(tmp, &test, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4408 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4409 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4410 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4411 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4412 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
|
4413 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4414 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4415 if (PyObject_HasAttrString(obj, "msg")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4416 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4417 tmp = PyObject_GetAttrString(obj, "msg"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4418 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4419 res = obj2ast_expr(tmp, &msg, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4420 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4421 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4422 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4423 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4424 msg = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4425 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4426 *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
|
4427 if (*out == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4428 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4429 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4430 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
|
4431 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4432 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4433 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4434 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4435 asdl_seq* names; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4436 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4437 if (PyObject_HasAttrString(obj, "names")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4438 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4439 Py_ssize_t len; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4440 Py_ssize_t i; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4441 tmp = PyObject_GetAttrString(obj, "names"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4442 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4443 if (!PyList_Check(tmp)) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4444 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
|
4445 goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4446 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4447 len = PyList_GET_SIZE(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4448 names = asdl_seq_new(len, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4449 if (names == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4450 for (i = 0; i < len; i++) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4451 alias_ty value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4452 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
|
4453 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4454 asdl_seq_SET(names, i, value); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4455 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4456 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4457 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4458 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4459 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
|
4460 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4461 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4462 *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
|
4463 if (*out == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4464 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4465 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4466 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
|
4467 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4468 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4469 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4470 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4471 identifier module; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4472 asdl_seq* names; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4473 int level; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4474 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4475 if (PyObject_HasAttrString(obj, "module")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4476 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4477 tmp = PyObject_GetAttrString(obj, "module"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4478 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4479 res = obj2ast_identifier(tmp, &module, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4480 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4481 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4482 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4483 } 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
|
4484 module = NULL; |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4485 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4486 if (PyObject_HasAttrString(obj, "names")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4487 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4488 Py_ssize_t len; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4489 Py_ssize_t i; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4490 tmp = PyObject_GetAttrString(obj, "names"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4491 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4492 if (!PyList_Check(tmp)) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4493 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
|
4494 goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4495 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4496 len = PyList_GET_SIZE(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4497 names = asdl_seq_new(len, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4498 if (names == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4499 for (i = 0; i < len; i++) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4500 alias_ty value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4501 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
|
4502 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4503 asdl_seq_SET(names, i, value); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4504 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4505 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4506 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4507 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4508 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
|
4509 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4510 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4511 if (PyObject_HasAttrString(obj, "level")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4512 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4513 tmp = PyObject_GetAttrString(obj, "level"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4514 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4515 res = obj2ast_int(tmp, &level, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4516 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4517 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4518 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4519 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4520 level = 0; |
|
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 = 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
|
4523 arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4524 if (*out == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4525 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4526 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4527 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
|
4528 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4529 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4530 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4531 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4532 expr_ty body; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4533 expr_ty globals; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4534 expr_ty locals; |
|
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 if (PyObject_HasAttrString(obj, "body")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4537 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4538 tmp = PyObject_GetAttrString(obj, "body"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4539 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4540 res = obj2ast_expr(tmp, &body, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4541 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4542 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4543 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4544 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4545 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
|
4546 return 1; |
|
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 if (PyObject_HasAttrString(obj, "globals")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4549 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4550 tmp = PyObject_GetAttrString(obj, "globals"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4551 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4552 res = obj2ast_expr(tmp, &globals, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4553 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4554 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4555 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4556 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4557 globals = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4558 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4559 if (PyObject_HasAttrString(obj, "locals")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4560 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4561 tmp = PyObject_GetAttrString(obj, "locals"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4562 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4563 res = obj2ast_expr(tmp, &locals, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4564 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4565 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4566 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4567 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4568 locals = NULL; |
|
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 *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
|
4571 if (*out == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4572 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4573 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4574 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
|
4575 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4576 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4577 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4578 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4579 asdl_seq* names; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4580 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4581 if (PyObject_HasAttrString(obj, "names")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4582 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4583 Py_ssize_t len; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4584 Py_ssize_t i; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4585 tmp = PyObject_GetAttrString(obj, "names"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4586 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4587 if (!PyList_Check(tmp)) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4588 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
|
4589 goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4590 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4591 len = PyList_GET_SIZE(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4592 names = asdl_seq_new(len, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4593 if (names == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4594 for (i = 0; i < len; i++) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4595 identifier value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4596 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
|
4597 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4598 asdl_seq_SET(names, i, value); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4599 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4600 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4601 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4602 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4603 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
|
4604 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4605 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4606 *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
|
4607 if (*out == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4608 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4609 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4610 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
|
4611 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4612 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4613 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4614 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4615 expr_ty value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4616 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4617 if (PyObject_HasAttrString(obj, "value")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4618 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4619 tmp = PyObject_GetAttrString(obj, "value"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4620 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4621 res = obj2ast_expr(tmp, &value, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4622 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4623 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4624 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4625 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4626 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
|
4627 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4628 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4629 *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
|
4630 if (*out == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4631 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4632 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4633 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
|
4634 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4635 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4636 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4637 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4638 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4639 *out = Pass(lineno, col_offset, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4640 if (*out == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4641 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4642 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4643 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
|
4644 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4645 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4646 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4647 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4648 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4649 *out = Break(lineno, col_offset, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4650 if (*out == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4651 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4652 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4653 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
|
4654 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4655 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4656 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4657 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4658 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4659 *out = Continue(lineno, col_offset, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4660 if (*out == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4661 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4662 } |
|
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 tmp = PyObject_Repr(obj); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4665 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
|
4666 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
|
4667 failed: |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4668 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4669 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4670 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4671 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4672 int |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4673 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
|
4674 { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4675 PyObject* tmp = NULL; |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4676 int isinstance; |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4677 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4678 int lineno; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4679 int col_offset; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4680 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4681 if (obj == Py_None) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4682 *out = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4683 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4684 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4685 if (PyObject_HasAttrString(obj, "lineno")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4686 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4687 tmp = PyObject_GetAttrString(obj, "lineno"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4688 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4689 res = obj2ast_int(tmp, &lineno, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4690 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4691 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4692 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4693 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4694 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
|
4695 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4696 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4697 if (PyObject_HasAttrString(obj, "col_offset")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4698 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4699 tmp = PyObject_GetAttrString(obj, "col_offset"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4700 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4701 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
|
4702 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4703 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4704 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4705 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4706 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
|
4707 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4708 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4709 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
|
4710 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4711 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4712 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4713 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4714 boolop_ty op; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4715 asdl_seq* values; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4716 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4717 if (PyObject_HasAttrString(obj, "op")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4718 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4719 tmp = PyObject_GetAttrString(obj, "op"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4720 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4721 res = obj2ast_boolop(tmp, &op, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4722 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4723 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4724 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4725 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4726 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
|
4727 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4728 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4729 if (PyObject_HasAttrString(obj, "values")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4730 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4731 Py_ssize_t len; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4732 Py_ssize_t i; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4733 tmp = PyObject_GetAttrString(obj, "values"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4734 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4735 if (!PyList_Check(tmp)) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4736 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
|
4737 goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4738 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4739 len = PyList_GET_SIZE(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4740 values = asdl_seq_new(len, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4741 if (values == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4742 for (i = 0; i < len; i++) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4743 expr_ty value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4744 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
|
4745 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4746 asdl_seq_SET(values, i, value); |
|
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 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4749 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4750 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4751 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
|
4752 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4753 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4754 *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
|
4755 if (*out == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4756 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4757 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4758 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
|
4759 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4760 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4761 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4762 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4763 expr_ty left; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4764 operator_ty op; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4765 expr_ty right; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4766 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4767 if (PyObject_HasAttrString(obj, "left")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4768 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4769 tmp = PyObject_GetAttrString(obj, "left"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4770 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4771 res = obj2ast_expr(tmp, &left, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4772 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4773 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4774 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4775 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4776 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
|
4777 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4778 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4779 if (PyObject_HasAttrString(obj, "op")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4780 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4781 tmp = PyObject_GetAttrString(obj, "op"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4782 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4783 res = obj2ast_operator(tmp, &op, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4784 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4785 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4786 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4787 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4788 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
|
4789 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4790 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4791 if (PyObject_HasAttrString(obj, "right")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4792 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4793 tmp = PyObject_GetAttrString(obj, "right"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4794 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4795 res = obj2ast_expr(tmp, &right, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4796 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4797 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4798 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4799 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4800 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
|
4801 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4802 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4803 *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
|
4804 if (*out == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4805 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4806 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4807 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
|
4808 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4809 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4810 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4811 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4812 unaryop_ty op; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4813 expr_ty operand; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4814 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4815 if (PyObject_HasAttrString(obj, "op")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4816 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4817 tmp = PyObject_GetAttrString(obj, "op"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4818 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4819 res = obj2ast_unaryop(tmp, &op, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4820 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4821 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4822 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4823 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4824 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
|
4825 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4826 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4827 if (PyObject_HasAttrString(obj, "operand")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4828 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4829 tmp = PyObject_GetAttrString(obj, "operand"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4830 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4831 res = obj2ast_expr(tmp, &operand, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4832 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4833 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4834 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4835 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4836 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
|
4837 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4838 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4839 *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
|
4840 if (*out == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4841 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4842 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4843 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
|
4844 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4845 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4846 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4847 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4848 arguments_ty args; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4849 expr_ty body; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4850 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4851 if (PyObject_HasAttrString(obj, "args")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4852 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4853 tmp = PyObject_GetAttrString(obj, "args"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4854 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4855 res = obj2ast_arguments(tmp, &args, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4856 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4857 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4858 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4859 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4860 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
|
4861 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4862 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4863 if (PyObject_HasAttrString(obj, "body")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4864 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4865 tmp = PyObject_GetAttrString(obj, "body"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4866 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4867 res = obj2ast_expr(tmp, &body, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4868 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4869 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4870 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4871 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4872 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
|
4873 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4874 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4875 *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
|
4876 if (*out == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4877 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4878 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4879 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
|
4880 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4881 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4882 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4883 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4884 expr_ty test; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4885 expr_ty body; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4886 expr_ty orelse; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4887 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4888 if (PyObject_HasAttrString(obj, "test")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4889 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4890 tmp = PyObject_GetAttrString(obj, "test"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4891 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4892 res = obj2ast_expr(tmp, &test, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4893 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4894 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4895 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4896 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4897 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
|
4898 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4899 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4900 if (PyObject_HasAttrString(obj, "body")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4901 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4902 tmp = PyObject_GetAttrString(obj, "body"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4903 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4904 res = obj2ast_expr(tmp, &body, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4905 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4906 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4907 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4908 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4909 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
|
4910 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4911 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4912 if (PyObject_HasAttrString(obj, "orelse")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4913 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4914 tmp = PyObject_GetAttrString(obj, "orelse"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4915 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4916 res = obj2ast_expr(tmp, &orelse, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4917 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4918 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4919 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4920 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4921 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
|
4922 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4923 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4924 *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
|
4925 if (*out == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4926 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4927 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4928 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
|
4929 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4930 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4931 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
4932 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4933 asdl_seq* keys; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4934 asdl_seq* values; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4935 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4936 if (PyObject_HasAttrString(obj, "keys")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4937 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4938 Py_ssize_t len; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4939 Py_ssize_t i; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4940 tmp = PyObject_GetAttrString(obj, "keys"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4941 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4942 if (!PyList_Check(tmp)) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4943 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
|
4944 goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4945 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4946 len = PyList_GET_SIZE(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4947 keys = asdl_seq_new(len, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4948 if (keys == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4949 for (i = 0; i < len; i++) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4950 expr_ty value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4951 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
|
4952 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4953 asdl_seq_SET(keys, i, value); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4954 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4955 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4956 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4957 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4958 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
|
4959 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4960 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4961 if (PyObject_HasAttrString(obj, "values")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4962 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4963 Py_ssize_t len; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4964 Py_ssize_t i; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4965 tmp = PyObject_GetAttrString(obj, "values"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4966 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4967 if (!PyList_Check(tmp)) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4968 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
|
4969 goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4970 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4971 len = PyList_GET_SIZE(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4972 values = asdl_seq_new(len, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4973 if (values == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4974 for (i = 0; i < len; i++) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4975 expr_ty value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4976 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
|
4977 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4978 asdl_seq_SET(values, i, value); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4979 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4980 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4981 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4982 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4983 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
|
4984 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4985 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4986 *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
|
4987 if (*out == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4988 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
4989 } |
|
58229
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
4990 isinstance = PyObject_IsInstance(obj, (PyObject*)Set_type); |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
4991 if (isinstance == -1) { |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
4992 return 1; |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
4993 } |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
4994 if (isinstance) { |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
4995 asdl_seq* elts; |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
4996 |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
4997 if (PyObject_HasAttrString(obj, "elts")) { |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
4998 int res; |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
4999 Py_ssize_t len; |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
5000 Py_ssize_t i; |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
5001 tmp = PyObject_GetAttrString(obj, "elts"); |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
5002 if (tmp == NULL) goto failed; |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
5003 if (!PyList_Check(tmp)) { |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
5004 PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
5005 goto failed; |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
5006 } |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
5007 len = PyList_GET_SIZE(tmp); |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
5008 elts = asdl_seq_new(len, arena); |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
5009 if (elts == NULL) goto failed; |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
5010 for (i = 0; i < len; i++) { |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
5011 expr_ty value; |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
5012 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
5013 if (res != 0) goto failed; |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
5014 asdl_seq_SET(elts, i, value); |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
5015 } |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
5016 Py_XDECREF(tmp); |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
5017 tmp = NULL; |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
5018 } else { |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
5019 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set"); |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
5020 return 1; |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
5021 } |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
5022 *out = Set(elts, lineno, col_offset, arena); |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
5023 if (*out == NULL) goto failed; |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
5024 return 0; |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
5025 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5026 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
|
5027 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5028 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5029 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5030 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5031 expr_ty elt; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5032 asdl_seq* generators; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5033 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5034 if (PyObject_HasAttrString(obj, "elt")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5035 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5036 tmp = PyObject_GetAttrString(obj, "elt"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5037 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5038 res = obj2ast_expr(tmp, &elt, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5039 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5040 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5041 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5042 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5043 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
|
5044 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5045 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5046 if (PyObject_HasAttrString(obj, "generators")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5047 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5048 Py_ssize_t len; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5049 Py_ssize_t i; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5050 tmp = PyObject_GetAttrString(obj, "generators"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5051 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5052 if (!PyList_Check(tmp)) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5053 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
|
5054 goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5055 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5056 len = PyList_GET_SIZE(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5057 generators = asdl_seq_new(len, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5058 if (generators == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5059 for (i = 0; i < len; i++) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5060 comprehension_ty value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5061 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
|
5062 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5063 asdl_seq_SET(generators, i, value); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5064 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5065 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5066 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5067 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5068 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
|
5069 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5070 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5071 *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
|
5072 if (*out == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5073 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5074 } |
|
58250
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5075 isinstance = PyObject_IsInstance(obj, (PyObject*)SetComp_type); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5076 if (isinstance == -1) { |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5077 return 1; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5078 } |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5079 if (isinstance) { |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5080 expr_ty elt; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5081 asdl_seq* generators; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5082 |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5083 if (PyObject_HasAttrString(obj, "elt")) { |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5084 int res; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5085 tmp = PyObject_GetAttrString(obj, "elt"); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5086 if (tmp == NULL) goto failed; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5087 res = obj2ast_expr(tmp, &elt, arena); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5088 if (res != 0) goto failed; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5089 Py_XDECREF(tmp); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5090 tmp = NULL; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5091 } else { |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5092 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp"); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5093 return 1; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5094 } |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5095 if (PyObject_HasAttrString(obj, "generators")) { |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5096 int res; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5097 Py_ssize_t len; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5098 Py_ssize_t i; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5099 tmp = PyObject_GetAttrString(obj, "generators"); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5100 if (tmp == NULL) goto failed; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5101 if (!PyList_Check(tmp)) { |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5102 PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5103 goto failed; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5104 } |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5105 len = PyList_GET_SIZE(tmp); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5106 generators = asdl_seq_new(len, arena); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5107 if (generators == NULL) goto failed; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5108 for (i = 0; i < len; i++) { |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5109 comprehension_ty value; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5110 res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5111 if (res != 0) goto failed; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5112 asdl_seq_SET(generators, i, value); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5113 } |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5114 Py_XDECREF(tmp); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5115 tmp = NULL; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5116 } else { |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5117 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp"); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5118 return 1; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5119 } |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5120 *out = SetComp(elt, generators, lineno, col_offset, arena); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5121 if (*out == NULL) goto failed; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5122 return 0; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5123 } |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5124 isinstance = PyObject_IsInstance(obj, (PyObject*)DictComp_type); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5125 if (isinstance == -1) { |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5126 return 1; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5127 } |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5128 if (isinstance) { |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5129 expr_ty key; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5130 expr_ty value; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5131 asdl_seq* generators; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5132 |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5133 if (PyObject_HasAttrString(obj, "key")) { |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5134 int res; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5135 tmp = PyObject_GetAttrString(obj, "key"); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5136 if (tmp == NULL) goto failed; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5137 res = obj2ast_expr(tmp, &key, arena); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5138 if (res != 0) goto failed; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5139 Py_XDECREF(tmp); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5140 tmp = NULL; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5141 } else { |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5142 PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp"); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5143 return 1; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5144 } |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5145 if (PyObject_HasAttrString(obj, "value")) { |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5146 int res; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5147 tmp = PyObject_GetAttrString(obj, "value"); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5148 if (tmp == NULL) goto failed; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5149 res = obj2ast_expr(tmp, &value, arena); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5150 if (res != 0) goto failed; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5151 Py_XDECREF(tmp); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5152 tmp = NULL; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5153 } else { |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5154 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp"); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5155 return 1; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5156 } |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5157 if (PyObject_HasAttrString(obj, "generators")) { |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5158 int res; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5159 Py_ssize_t len; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5160 Py_ssize_t i; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5161 tmp = PyObject_GetAttrString(obj, "generators"); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5162 if (tmp == NULL) goto failed; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5163 if (!PyList_Check(tmp)) { |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5164 PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5165 goto failed; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5166 } |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5167 len = PyList_GET_SIZE(tmp); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5168 generators = asdl_seq_new(len, arena); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5169 if (generators == NULL) goto failed; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5170 for (i = 0; i < len; i++) { |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5171 comprehension_ty value; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5172 res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5173 if (res != 0) goto failed; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5174 asdl_seq_SET(generators, i, value); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5175 } |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5176 Py_XDECREF(tmp); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5177 tmp = NULL; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5178 } else { |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5179 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp"); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5180 return 1; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5181 } |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5182 *out = DictComp(key, value, generators, lineno, col_offset, |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5183 arena); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5184 if (*out == NULL) goto failed; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5185 return 0; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
5186 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5187 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
|
5188 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5189 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5190 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5191 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5192 expr_ty elt; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5193 asdl_seq* generators; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5194 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5195 if (PyObject_HasAttrString(obj, "elt")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5196 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5197 tmp = PyObject_GetAttrString(obj, "elt"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5198 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5199 res = obj2ast_expr(tmp, &elt, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5200 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5201 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5202 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5203 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5204 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
|
5205 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5206 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5207 if (PyObject_HasAttrString(obj, "generators")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5208 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5209 Py_ssize_t len; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5210 Py_ssize_t i; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5211 tmp = PyObject_GetAttrString(obj, "generators"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5212 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5213 if (!PyList_Check(tmp)) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5214 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
|
5215 goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5216 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5217 len = PyList_GET_SIZE(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5218 generators = asdl_seq_new(len, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5219 if (generators == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5220 for (i = 0; i < len; i++) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5221 comprehension_ty value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5222 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
|
5223 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5224 asdl_seq_SET(generators, i, value); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5225 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5226 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5227 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5228 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5229 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
|
5230 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5231 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5232 *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
|
5233 if (*out == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5234 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5235 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5236 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
|
5237 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5238 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5239 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5240 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5241 expr_ty value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5242 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5243 if (PyObject_HasAttrString(obj, "value")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5244 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5245 tmp = PyObject_GetAttrString(obj, "value"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5246 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5247 res = obj2ast_expr(tmp, &value, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5248 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5249 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5250 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5251 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5252 value = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5253 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5254 *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
|
5255 if (*out == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5256 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5257 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5258 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
|
5259 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5260 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5261 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5262 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5263 expr_ty left; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5264 asdl_int_seq* ops; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5265 asdl_seq* comparators; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5266 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5267 if (PyObject_HasAttrString(obj, "left")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5268 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5269 tmp = PyObject_GetAttrString(obj, "left"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5270 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5271 res = obj2ast_expr(tmp, &left, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5272 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5273 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5274 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5275 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5276 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
|
5277 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5278 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5279 if (PyObject_HasAttrString(obj, "ops")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5280 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5281 Py_ssize_t len; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5282 Py_ssize_t i; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5283 tmp = PyObject_GetAttrString(obj, "ops"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5284 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5285 if (!PyList_Check(tmp)) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5286 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
|
5287 goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5288 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5289 len = PyList_GET_SIZE(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5290 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
|
5291 if (ops == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5292 for (i = 0; i < len; i++) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5293 cmpop_ty value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5294 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
|
5295 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5296 asdl_seq_SET(ops, i, value); |
|
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 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5299 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5300 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5301 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
|
5302 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5303 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5304 if (PyObject_HasAttrString(obj, "comparators")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5305 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5306 Py_ssize_t len; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5307 Py_ssize_t i; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5308 tmp = PyObject_GetAttrString(obj, "comparators"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5309 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5310 if (!PyList_Check(tmp)) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5311 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
|
5312 goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5313 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5314 len = PyList_GET_SIZE(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5315 comparators = asdl_seq_new(len, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5316 if (comparators == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5317 for (i = 0; i < len; i++) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5318 expr_ty value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5319 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
|
5320 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5321 asdl_seq_SET(comparators, i, value); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5322 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5323 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5324 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5325 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5326 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
|
5327 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5328 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5329 *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
|
5330 arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5331 if (*out == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5332 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5333 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5334 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
|
5335 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5336 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5337 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5338 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5339 expr_ty func; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5340 asdl_seq* args; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5341 asdl_seq* keywords; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5342 expr_ty starargs; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5343 expr_ty kwargs; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5344 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5345 if (PyObject_HasAttrString(obj, "func")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5346 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5347 tmp = PyObject_GetAttrString(obj, "func"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5348 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5349 res = obj2ast_expr(tmp, &func, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5350 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5351 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5352 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5353 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5354 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
|
5355 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5356 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5357 if (PyObject_HasAttrString(obj, "args")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5358 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5359 Py_ssize_t len; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5360 Py_ssize_t i; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5361 tmp = PyObject_GetAttrString(obj, "args"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5362 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5363 if (!PyList_Check(tmp)) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5364 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
|
5365 goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5366 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5367 len = PyList_GET_SIZE(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5368 args = asdl_seq_new(len, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5369 if (args == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5370 for (i = 0; i < len; i++) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5371 expr_ty value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5372 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
|
5373 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5374 asdl_seq_SET(args, i, value); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5375 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5376 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5377 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5378 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5379 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
|
5380 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5381 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5382 if (PyObject_HasAttrString(obj, "keywords")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5383 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5384 Py_ssize_t len; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5385 Py_ssize_t i; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5386 tmp = PyObject_GetAttrString(obj, "keywords"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5387 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5388 if (!PyList_Check(tmp)) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5389 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
|
5390 goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5391 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5392 len = PyList_GET_SIZE(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5393 keywords = asdl_seq_new(len, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5394 if (keywords == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5395 for (i = 0; i < len; i++) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5396 keyword_ty value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5397 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
|
5398 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5399 asdl_seq_SET(keywords, i, value); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5400 } |
|
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 \"keywords\" missing from Call"); |
|
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 if (PyObject_HasAttrString(obj, "starargs")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5408 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5409 tmp = PyObject_GetAttrString(obj, "starargs"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5410 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5411 res = obj2ast_expr(tmp, &starargs, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5412 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5413 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5414 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5415 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5416 starargs = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5417 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5418 if (PyObject_HasAttrString(obj, "kwargs")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5419 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5420 tmp = PyObject_GetAttrString(obj, "kwargs"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5421 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5422 res = obj2ast_expr(tmp, &kwargs, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5423 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5424 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5425 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5426 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5427 kwargs = NULL; |
|
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 *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
|
5430 col_offset, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5431 if (*out == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5432 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5433 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5434 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
|
5435 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5436 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5437 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5438 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5439 expr_ty value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5440 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5441 if (PyObject_HasAttrString(obj, "value")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5442 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5443 tmp = PyObject_GetAttrString(obj, "value"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5444 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5445 res = obj2ast_expr(tmp, &value, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5446 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5447 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5448 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5449 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5450 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
|
5451 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5452 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5453 *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
|
5454 if (*out == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5455 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5456 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5457 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
|
5458 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5459 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5460 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5461 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5462 object n; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5463 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5464 if (PyObject_HasAttrString(obj, "n")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5465 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5466 tmp = PyObject_GetAttrString(obj, "n"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5467 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5468 res = obj2ast_object(tmp, &n, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5469 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5470 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5471 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5472 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5473 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
|
5474 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5475 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5476 *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
|
5477 if (*out == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5478 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5479 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5480 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
|
5481 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5482 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5483 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5484 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5485 string s; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5486 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5487 if (PyObject_HasAttrString(obj, "s")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5488 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5489 tmp = PyObject_GetAttrString(obj, "s"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5490 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5491 res = obj2ast_string(tmp, &s, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5492 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5493 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5494 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5495 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5496 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
|
5497 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5498 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5499 *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
|
5500 if (*out == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5501 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5502 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5503 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
|
5504 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5505 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5506 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5507 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5508 expr_ty value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5509 identifier attr; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5510 expr_context_ty ctx; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5511 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5512 if (PyObject_HasAttrString(obj, "value")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5513 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5514 tmp = PyObject_GetAttrString(obj, "value"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5515 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5516 res = obj2ast_expr(tmp, &value, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5517 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5518 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5519 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5520 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5521 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
|
5522 return 1; |
|
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 if (PyObject_HasAttrString(obj, "attr")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5525 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5526 tmp = PyObject_GetAttrString(obj, "attr"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5527 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5528 res = obj2ast_identifier(tmp, &attr, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5529 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5530 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5531 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5532 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5533 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
|
5534 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5535 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5536 if (PyObject_HasAttrString(obj, "ctx")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5537 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5538 tmp = PyObject_GetAttrString(obj, "ctx"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5539 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5540 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
|
5541 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5542 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5543 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5544 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5545 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
|
5546 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5547 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5548 *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
|
5549 if (*out == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5550 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5551 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5552 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
|
5553 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5554 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5555 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5556 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5557 expr_ty value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5558 slice_ty slice; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5559 expr_context_ty ctx; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5560 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5561 if (PyObject_HasAttrString(obj, "value")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5562 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5563 tmp = PyObject_GetAttrString(obj, "value"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5564 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5565 res = obj2ast_expr(tmp, &value, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5566 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5567 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5568 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5569 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5570 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
|
5571 return 1; |
|
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, "slice")) { |
|
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, "slice"); |
|
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_slice(tmp, &slice, 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 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
|
5583 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5584 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5585 if (PyObject_HasAttrString(obj, "ctx")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5586 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5587 tmp = PyObject_GetAttrString(obj, "ctx"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5588 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5589 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
|
5590 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5591 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5592 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5593 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5594 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
|
5595 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5596 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5597 *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
|
5598 if (*out == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5599 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5600 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5601 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
|
5602 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5603 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5604 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5605 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5606 identifier id; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5607 expr_context_ty ctx; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5608 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5609 if (PyObject_HasAttrString(obj, "id")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5610 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5611 tmp = PyObject_GetAttrString(obj, "id"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5612 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5613 res = obj2ast_identifier(tmp, &id, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5614 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5615 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5616 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5617 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5618 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
|
5619 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5620 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5621 if (PyObject_HasAttrString(obj, "ctx")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5622 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5623 tmp = PyObject_GetAttrString(obj, "ctx"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5624 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5625 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
|
5626 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5627 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5628 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5629 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5630 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
|
5631 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5632 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5633 *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
|
5634 if (*out == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5635 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5636 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5637 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
|
5638 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5639 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5640 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5641 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5642 asdl_seq* elts; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5643 expr_context_ty ctx; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5644 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5645 if (PyObject_HasAttrString(obj, "elts")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5646 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5647 Py_ssize_t len; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5648 Py_ssize_t i; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5649 tmp = PyObject_GetAttrString(obj, "elts"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5650 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5651 if (!PyList_Check(tmp)) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5652 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
|
5653 goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5654 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5655 len = PyList_GET_SIZE(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5656 elts = asdl_seq_new(len, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5657 if (elts == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5658 for (i = 0; i < len; i++) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5659 expr_ty value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5660 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
|
5661 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5662 asdl_seq_SET(elts, i, value); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5663 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5664 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5665 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5666 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5667 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
|
5668 return 1; |
|
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 if (PyObject_HasAttrString(obj, "ctx")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5671 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5672 tmp = PyObject_GetAttrString(obj, "ctx"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5673 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5674 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
|
5675 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5676 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5677 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5678 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5679 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
|
5680 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5681 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5682 *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
|
5683 if (*out == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5684 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5685 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5686 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
|
5687 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5688 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5689 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5690 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5691 asdl_seq* elts; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5692 expr_context_ty ctx; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5693 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5694 if (PyObject_HasAttrString(obj, "elts")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5695 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5696 Py_ssize_t len; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5697 Py_ssize_t i; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5698 tmp = PyObject_GetAttrString(obj, "elts"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5699 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5700 if (!PyList_Check(tmp)) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5701 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
|
5702 goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5703 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5704 len = PyList_GET_SIZE(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5705 elts = asdl_seq_new(len, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5706 if (elts == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5707 for (i = 0; i < len; i++) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5708 expr_ty value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5709 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
|
5710 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5711 asdl_seq_SET(elts, i, value); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5712 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5713 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5714 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5715 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5716 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
|
5717 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5718 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5719 if (PyObject_HasAttrString(obj, "ctx")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5720 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5721 tmp = PyObject_GetAttrString(obj, "ctx"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5722 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5723 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
|
5724 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5725 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5726 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5727 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5728 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
|
5729 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5730 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5731 *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
|
5732 if (*out == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5733 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5734 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5735 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5736 tmp = PyObject_Repr(obj); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5737 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
|
5738 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
|
5739 failed: |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5740 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5741 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5742 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5743 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5744 int |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5745 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
|
5746 { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5747 PyObject* tmp = NULL; |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5748 int isinstance; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5749 |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5750 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
|
5751 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5752 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5753 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5754 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5755 *out = Load; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5756 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5757 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5758 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
|
5759 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5760 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5761 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5762 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5763 *out = Store; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5764 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5765 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5766 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
|
5767 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5768 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5769 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5770 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5771 *out = Del; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5772 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5773 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5774 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
|
5775 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5776 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5777 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5778 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5779 *out = AugLoad; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5780 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5781 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5782 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
|
5783 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5784 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5785 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5786 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5787 *out = AugStore; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5788 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5789 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5790 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
|
5791 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5792 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5793 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5794 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5795 *out = Param; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5796 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5797 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5798 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5799 tmp = PyObject_Repr(obj); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5800 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
|
5801 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
|
5802 failed: |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5803 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5804 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5805 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5806 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5807 int |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5808 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
|
5809 { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5810 PyObject* tmp = NULL; |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5811 int isinstance; |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5812 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5813 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5814 if (obj == Py_None) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5815 *out = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5816 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5817 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5818 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
|
5819 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5820 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5821 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5822 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5823 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5824 *out = Ellipsis(arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5825 if (*out == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5826 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5827 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5828 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
|
5829 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5830 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5831 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5832 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5833 expr_ty lower; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5834 expr_ty upper; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5835 expr_ty step; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5836 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5837 if (PyObject_HasAttrString(obj, "lower")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5838 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5839 tmp = PyObject_GetAttrString(obj, "lower"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5840 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5841 res = obj2ast_expr(tmp, &lower, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5842 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5843 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5844 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5845 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5846 lower = NULL; |
|
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 if (PyObject_HasAttrString(obj, "upper")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5849 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5850 tmp = PyObject_GetAttrString(obj, "upper"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5851 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5852 res = obj2ast_expr(tmp, &upper, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5853 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5854 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5855 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5856 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5857 upper = NULL; |
|
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 if (PyObject_HasAttrString(obj, "step")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5860 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5861 tmp = PyObject_GetAttrString(obj, "step"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5862 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5863 res = obj2ast_expr(tmp, &step, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5864 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5865 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5866 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5867 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5868 step = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5869 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5870 *out = Slice(lower, upper, step, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5871 if (*out == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5872 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5873 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5874 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
|
5875 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5876 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5877 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5878 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5879 asdl_seq* dims; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5880 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5881 if (PyObject_HasAttrString(obj, "dims")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5882 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5883 Py_ssize_t len; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5884 Py_ssize_t i; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5885 tmp = PyObject_GetAttrString(obj, "dims"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5886 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5887 if (!PyList_Check(tmp)) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5888 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
|
5889 goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5890 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5891 len = PyList_GET_SIZE(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5892 dims = asdl_seq_new(len, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5893 if (dims == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5894 for (i = 0; i < len; i++) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5895 slice_ty value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5896 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
|
5897 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5898 asdl_seq_SET(dims, i, value); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5899 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5900 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5901 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5902 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5903 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
|
5904 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5905 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5906 *out = ExtSlice(dims, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5907 if (*out == NULL) goto failed; |
|
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*)Index_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 expr_ty value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5916 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5917 if (PyObject_HasAttrString(obj, "value")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5918 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5919 tmp = PyObject_GetAttrString(obj, "value"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5920 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5921 res = obj2ast_expr(tmp, &value, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5922 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5923 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5924 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5925 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5926 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
|
5927 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5928 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5929 *out = Index(value, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5930 if (*out == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5931 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5932 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5933 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5934 tmp = PyObject_Repr(obj); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5935 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
|
5936 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
|
5937 failed: |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5938 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5939 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5940 } |
|
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 int |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5943 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
|
5944 { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5945 PyObject* tmp = NULL; |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5946 int isinstance; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5947 |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5948 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
|
5949 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5950 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5951 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5952 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5953 *out = And; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5954 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5955 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5956 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
|
5957 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5958 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5959 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5960 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5961 *out = Or; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5962 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5963 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5964 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5965 tmp = PyObject_Repr(obj); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5966 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
|
5967 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
|
5968 failed: |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5969 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5970 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5971 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5972 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5973 int |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5974 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
|
5975 { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5976 PyObject* tmp = NULL; |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5977 int isinstance; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5978 |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5979 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
|
5980 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5981 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5982 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5983 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5984 *out = Add; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5985 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5986 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5987 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
|
5988 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5989 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5990 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5991 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5992 *out = Sub; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5993 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
5994 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5995 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
|
5996 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5997 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5998 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
5999 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6000 *out = Mult; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6001 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6002 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6003 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
|
6004 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6005 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6006 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6007 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6008 *out = Div; |
|
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 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6011 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
|
6012 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6013 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6014 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6015 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6016 *out = Mod; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6017 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6018 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6019 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
|
6020 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6021 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6022 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6023 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6024 *out = Pow; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6025 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6026 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6027 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
|
6028 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6029 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6030 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6031 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6032 *out = LShift; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6033 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6034 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6035 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
|
6036 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6037 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6038 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6039 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6040 *out = RShift; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6041 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6042 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6043 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
|
6044 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6045 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6046 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6047 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6048 *out = BitOr; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6049 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6050 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6051 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
|
6052 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6053 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6054 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6055 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6056 *out = BitXor; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6057 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6058 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6059 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
|
6060 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6061 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6062 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6063 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6064 *out = BitAnd; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6065 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6066 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6067 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
|
6068 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6069 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6070 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6071 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6072 *out = FloorDiv; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6073 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6074 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6075 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6076 tmp = PyObject_Repr(obj); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6077 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
|
6078 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
|
6079 failed: |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6080 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6081 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6082 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6083 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6084 int |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6085 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
|
6086 { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6087 PyObject* tmp = NULL; |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6088 int isinstance; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6089 |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6090 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
|
6091 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6092 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6093 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6094 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6095 *out = Invert; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6096 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6097 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6098 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
|
6099 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6100 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6101 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6102 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6103 *out = Not; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6104 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6105 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6106 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
|
6107 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6108 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6109 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6110 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6111 *out = UAdd; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6112 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6113 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6114 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
|
6115 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6116 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6117 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6118 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6119 *out = USub; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6120 return 0; |
|
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 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6123 tmp = PyObject_Repr(obj); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6124 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
|
6125 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
|
6126 failed: |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6127 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6128 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6129 } |
|
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 int |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6132 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
|
6133 { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6134 PyObject* tmp = NULL; |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6135 int isinstance; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6136 |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6137 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
|
6138 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6139 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6140 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6141 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6142 *out = Eq; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6143 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6144 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6145 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
|
6146 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6147 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6148 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6149 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6150 *out = NotEq; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6151 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6152 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6153 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
|
6154 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6155 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6156 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6157 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6158 *out = Lt; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6159 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6160 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6161 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
|
6162 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6163 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6164 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6165 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6166 *out = LtE; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6167 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6168 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6169 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
|
6170 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6171 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6172 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6173 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6174 *out = Gt; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6175 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6176 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6177 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
|
6178 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6179 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6180 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6181 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6182 *out = GtE; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6183 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6184 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6185 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
|
6186 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6187 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6188 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6189 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6190 *out = Is; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6191 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6192 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6193 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
|
6194 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6195 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6196 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6197 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6198 *out = IsNot; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6199 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6200 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6201 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
|
6202 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6203 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6204 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6205 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6206 *out = In; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6207 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6208 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6209 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
|
6210 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6211 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6212 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6213 if (isinstance) { |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6214 *out = NotIn; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6215 return 0; |
|
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 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6218 tmp = PyObject_Repr(obj); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6219 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
|
6220 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
|
6221 failed: |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6222 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6223 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6224 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6225 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6226 int |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6227 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
|
6228 { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6229 PyObject* tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6230 expr_ty target; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6231 expr_ty iter; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6232 asdl_seq* ifs; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6233 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6234 if (PyObject_HasAttrString(obj, "target")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6235 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6236 tmp = PyObject_GetAttrString(obj, "target"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6237 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6238 res = obj2ast_expr(tmp, &target, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6239 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6240 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6241 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6242 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6243 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
|
6244 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6245 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6246 if (PyObject_HasAttrString(obj, "iter")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6247 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6248 tmp = PyObject_GetAttrString(obj, "iter"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6249 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6250 res = obj2ast_expr(tmp, &iter, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6251 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6252 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6253 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6254 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6255 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
|
6256 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6257 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6258 if (PyObject_HasAttrString(obj, "ifs")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6259 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6260 Py_ssize_t len; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6261 Py_ssize_t i; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6262 tmp = PyObject_GetAttrString(obj, "ifs"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6263 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6264 if (!PyList_Check(tmp)) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6265 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
|
6266 goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6267 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6268 len = PyList_GET_SIZE(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6269 ifs = asdl_seq_new(len, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6270 if (ifs == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6271 for (i = 0; i < len; i++) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6272 expr_ty value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6273 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
|
6274 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6275 asdl_seq_SET(ifs, i, value); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6276 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6277 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6278 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6279 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6280 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
|
6281 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6282 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6283 *out = comprehension(target, iter, ifs, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6284 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6285 failed: |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6286 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6287 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6288 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6289 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6290 int |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6291 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
|
6292 { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6293 PyObject* tmp = NULL; |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6294 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
|
6295 |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6296 int lineno; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6297 int col_offset; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6298 |
|
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
|
6299 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
|
6300 *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
|
6301 return 0; |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6302 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6303 if (PyObject_HasAttrString(obj, "lineno")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6304 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6305 tmp = PyObject_GetAttrString(obj, "lineno"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6306 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6307 res = obj2ast_int(tmp, &lineno, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6308 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6309 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6310 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6311 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6312 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
|
6313 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6314 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6315 if (PyObject_HasAttrString(obj, "col_offset")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6316 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6317 tmp = PyObject_GetAttrString(obj, "col_offset"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6318 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6319 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
|
6320 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6321 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6322 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6323 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6324 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
|
6325 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6326 } |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6327 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
|
6328 if (isinstance == -1) { |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6329 return 1; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6330 } |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6331 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
|
6332 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
|
6333 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
|
6334 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
|
6335 |
|
2ff88ae9850c
Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents:
46193
diff
changeset
|
6336 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
|
6337 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
|
6338 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
|
6339 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
|
6340 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
|
6341 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
|
6342 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
|
6343 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
|
6344 } 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
|
6345 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
|
6346 } |
|
2ff88ae9850c
Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents:
46193
diff
changeset
|
6347 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
|
6348 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
|
6349 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
|
6350 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
|
6351 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
|
6352 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
|
6353 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
|
6354 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
|
6355 } 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
|
6356 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
|
6357 } |
|
2ff88ae9850c
Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents:
46193
diff
changeset
|
6358 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
|
6359 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
|
6360 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
|
6361 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
|
6362 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
|
6363 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
|
6364 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
|
6365 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
|
6366 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
|
6367 } |
|
2ff88ae9850c
Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents:
46193
diff
changeset
|
6368 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
|
6369 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
|
6370 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
|
6371 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
|
6372 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
|
6373 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
|
6374 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
|
6375 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
|
6376 } |
|
2ff88ae9850c
Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents:
46193
diff
changeset
|
6377 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
|
6378 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
|
6379 } 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
|
6380 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
|
6381 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
|
6382 } |
|
2ff88ae9850c
Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents:
46193
diff
changeset
|
6383 *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
|
6384 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
|
6385 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
|
6386 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
|
6387 } |
|
2ff88ae9850c
Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents:
46193
diff
changeset
|
6388 |
|
2ff88ae9850c
Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum.
Georg Brandl <georg@python.org>
parents:
46193
diff
changeset
|
6389 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
|
6390 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
|
6391 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
|
6392 failed: |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6393 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6394 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6395 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6396 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6397 int |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6398 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
|
6399 { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6400 PyObject* tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6401 asdl_seq* args; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6402 identifier vararg; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6403 identifier kwarg; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6404 asdl_seq* defaults; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6405 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6406 if (PyObject_HasAttrString(obj, "args")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6407 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6408 Py_ssize_t len; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6409 Py_ssize_t i; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6410 tmp = PyObject_GetAttrString(obj, "args"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6411 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6412 if (!PyList_Check(tmp)) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6413 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
|
6414 goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6415 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6416 len = PyList_GET_SIZE(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6417 args = asdl_seq_new(len, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6418 if (args == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6419 for (i = 0; i < len; i++) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6420 expr_ty value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6421 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
|
6422 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6423 asdl_seq_SET(args, i, value); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6424 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6425 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6426 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6427 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6428 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
|
6429 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6430 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6431 if (PyObject_HasAttrString(obj, "vararg")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6432 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6433 tmp = PyObject_GetAttrString(obj, "vararg"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6434 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6435 res = obj2ast_identifier(tmp, &vararg, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6436 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6437 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6438 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6439 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6440 vararg = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6441 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6442 if (PyObject_HasAttrString(obj, "kwarg")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6443 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6444 tmp = PyObject_GetAttrString(obj, "kwarg"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6445 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6446 res = obj2ast_identifier(tmp, &kwarg, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6447 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6448 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6449 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6450 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6451 kwarg = NULL; |
|
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 if (PyObject_HasAttrString(obj, "defaults")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6454 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6455 Py_ssize_t len; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6456 Py_ssize_t i; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6457 tmp = PyObject_GetAttrString(obj, "defaults"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6458 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6459 if (!PyList_Check(tmp)) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6460 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
|
6461 goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6462 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6463 len = PyList_GET_SIZE(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6464 defaults = asdl_seq_new(len, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6465 if (defaults == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6466 for (i = 0; i < len; i++) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6467 expr_ty value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6468 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
|
6469 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6470 asdl_seq_SET(defaults, i, value); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6471 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6472 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6473 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6474 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6475 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
|
6476 return 1; |
|
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 *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
|
6479 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6480 failed: |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6481 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6482 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6483 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6484 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6485 int |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6486 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
|
6487 { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6488 PyObject* tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6489 identifier arg; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6490 expr_ty value; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6491 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6492 if (PyObject_HasAttrString(obj, "arg")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6493 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6494 tmp = PyObject_GetAttrString(obj, "arg"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6495 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6496 res = obj2ast_identifier(tmp, &arg, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6497 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6498 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6499 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6500 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6501 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
|
6502 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6503 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6504 if (PyObject_HasAttrString(obj, "value")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6505 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6506 tmp = PyObject_GetAttrString(obj, "value"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6507 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6508 res = obj2ast_expr(tmp, &value, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6509 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6510 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6511 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6512 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6513 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
|
6514 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6515 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6516 *out = keyword(arg, value, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6517 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6518 failed: |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6519 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6520 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6521 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6522 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6523 int |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6524 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
|
6525 { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6526 PyObject* tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6527 identifier name; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6528 identifier asname; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6529 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6530 if (PyObject_HasAttrString(obj, "name")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6531 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6532 tmp = PyObject_GetAttrString(obj, "name"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6533 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6534 res = obj2ast_identifier(tmp, &name, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6535 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6536 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6537 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6538 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6539 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
|
6540 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6541 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6542 if (PyObject_HasAttrString(obj, "asname")) { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6543 int res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6544 tmp = PyObject_GetAttrString(obj, "asname"); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6545 if (tmp == NULL) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6546 res = obj2ast_identifier(tmp, &asname, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6547 if (res != 0) goto failed; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6548 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6549 tmp = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6550 } else { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6551 asname = NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6552 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6553 *out = alias(name, asname, arena); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6554 return 0; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6555 failed: |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6556 Py_XDECREF(tmp); |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6557 return 1; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6558 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6559 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6560 |
| 36669 | 6561 PyMODINIT_FUNC |
| 6562 init_ast(void) | |
| 6563 { | |
| 6564 PyObject *m, *d; | |
| 6565 if (!init_types()) return; | |
| 6566 m = Py_InitModule3("_ast", NULL, NULL); | |
| 6567 if (!m) return; | |
| 6568 d = PyModule_GetDict(m); | |
|
46202
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
6569 if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return; |
| 36669 | 6570 if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0) |
| 6571 return; | |
|
58251
8a5ac9ff5057
Update version information for AST changes in r77422.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58250
diff
changeset
|
6572 if (PyModule_AddStringConstant(m, "__version__", "77422") < 0) |
| 36707 | 6573 return; |
|
37412
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6574 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
|
6575 if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0) |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6576 return; |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6577 if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type) |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6578 < 0) return; |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6579 if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) < |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6580 0) return; |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6581 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
|
6582 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
|
6583 if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type) |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6584 < 0) return; |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6585 if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0) |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6586 return; |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6587 if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0) |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6588 return; |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6589 if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0) |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6590 return; |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6591 if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0) |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6592 return; |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6593 if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) < |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6594 0) return; |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6595 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
|
6596 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
|
6597 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
|
6598 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
|
6599 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
|
6600 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
|
6601 if (PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) < |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6602 0) return; |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6603 if (PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) < |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6604 0) return; |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6605 if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0) |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6606 return; |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6607 if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0) |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6608 return; |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6609 if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) < |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6610 0) return; |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6611 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
|
6612 if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0) |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6613 return; |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6614 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
|
6615 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
|
6616 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
|
6617 if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0) |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6618 return; |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6619 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
|
6620 if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0) |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6621 return; |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6622 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
|
6623 if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0) |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6624 return; |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6625 if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0) |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6626 return; |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6627 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
|
6628 if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return; |
|
58229
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
57673
diff
changeset
|
6629 if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return; |
|
37412
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6630 if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0) |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6631 return; |
|
58250
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
6632 if (PyDict_SetItemString(d, "SetComp", (PyObject*)SetComp_type) < 0) |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
6633 return; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
6634 if (PyDict_SetItemString(d, "DictComp", (PyObject*)DictComp_type) < 0) |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58230
diff
changeset
|
6635 return; |
|
37412
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6636 if (PyDict_SetItemString(d, "GeneratorExp", |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6637 (PyObject*)GeneratorExp_type) < 0) return; |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6638 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
|
6639 if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0) |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6640 return; |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6641 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
|
6642 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
|
6643 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
|
6644 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
|
6645 if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) < |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6646 0) return; |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6647 if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) < |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6648 0) return; |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6649 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
|
6650 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
|
6651 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
|
6652 if (PyDict_SetItemString(d, "expr_context", |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6653 (PyObject*)expr_context_type) < 0) return; |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6654 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
|
6655 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
|
6656 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
|
6657 if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0) |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6658 return; |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6659 if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0) |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6660 return; |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6661 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
|
6662 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
|
6663 if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0) |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6664 return; |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6665 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
|
6666 if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0) |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6667 return; |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6668 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
|
6669 if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0) |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6670 return; |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6671 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
|
6672 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
|
6673 if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0) |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6674 return; |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6675 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
|
6676 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
|
6677 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
|
6678 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
|
6679 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
|
6680 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
|
6681 if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0) |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6682 return; |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6683 if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0) |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6684 return; |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6685 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
|
6686 if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0) |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6687 return; |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6688 if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0) |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6689 return; |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6690 if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0) |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6691 return; |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6692 if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0) |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6693 return; |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6694 if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0) |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6695 return; |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6696 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
|
6697 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
|
6698 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
|
6699 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
|
6700 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
|
6701 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
|
6702 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
|
6703 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
|
6704 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
|
6705 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
|
6706 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
|
6707 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
|
6708 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
|
6709 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
|
6710 if (PyDict_SetItemString(d, "comprehension", |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6711 (PyObject*)comprehension_type) < 0) return; |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6712 if (PyDict_SetItemString(d, "excepthandler", |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6713 (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
|
6714 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
|
6715 (PyObject*)ExceptHandler_type) < 0) return; |
|
37412
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6716 if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) < |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6717 0) return; |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6718 if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0) |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6719 return; |
|
dfc33ec7f73a
* Fix a refleak of *_attributes.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36794
diff
changeset
|
6720 if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return; |
| 36669 | 6721 } |
| 6722 | |
| 35742 | 6723 |
|
36660
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
6724 PyObject* PyAST_mod2obj(mod_ty t) |
| 35742 | 6725 { |
|
36660
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
6726 init_types(); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36174
diff
changeset
|
6727 return ast2obj_mod(t); |
| 35742 | 6728 } |
| 6729 | |
|
46193
b0bf06d49647
Properly check for consistency with the third argument of
Georg Brandl <georg@python.org>
parents:
46168
diff
changeset
|
6730 /* 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
|
6731 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
|
6732 { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6733 mod_ty res; |
|
46193
b0bf06d49647
Properly check for consistency with the third argument of
Georg Brandl <georg@python.org>
parents:
46168
diff
changeset
|
6734 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
|
6735 (PyObject*)Interactive_type}; |
|
b0bf06d49647
Properly check for consistency with the third argument of
Georg Brandl <georg@python.org>
parents:
46168
diff
changeset
|
6736 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
|
6737 int isinstance; |
|
46193
b0bf06d49647
Properly check for consistency with the third argument of
Georg Brandl <georg@python.org>
parents:
46168
diff
changeset
|
6738 assert(0 <= mode && mode <= 2); |
|
b0bf06d49647
Properly check for consistency with the third argument of
Georg Brandl <georg@python.org>
parents:
46168
diff
changeset
|
6739 |
|
46162
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6740 init_types(); |
|
46193
b0bf06d49647
Properly check for consistency with the third argument of
Georg Brandl <georg@python.org>
parents:
46168
diff
changeset
|
6741 |
|
57673
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6742 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
|
6743 if (isinstance == -1) |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6744 return NULL; |
|
20b7deb53d4e
account for PyObject_IsInstance's new ability to fail
Benjamin Peterson <benjamin@python.org>
parents:
54744
diff
changeset
|
6745 if (!isinstance) { |
|
46193
b0bf06d49647
Properly check for consistency with the third argument of
Georg Brandl <georg@python.org>
parents:
46168
diff
changeset
|
6746 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
|
6747 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
|
6748 return NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6749 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6750 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
|
6751 return NULL; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6752 else |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6753 return res; |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6754 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6755 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6756 int PyAST_Check(PyObject* obj) |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6757 { |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6758 init_types(); |
|
46202
42c5d287a852
#2505: allow easier creation of AST nodes.
Georg Brandl <georg@python.org>
parents:
46200
diff
changeset
|
6759 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
|
6760 } |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6761 |
|
ca38f7a4b4c9
Patch #1810 by Thomas Lee, reviewed by myself:
Georg Brandl <georg@python.org>
parents:
45470
diff
changeset
|
6762 |
