blob: 212211c5f435cfaf5eac133ce886f1f1ed0e7e9f [file] [log] [blame]
Thomas Wouterscf297e42007-02-23 15:07:44 +00001/* File automatically generated by Parser/asdl_c.py. */
2
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -07003#include <stddef.h>
4
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00005#include "Python.h"
6#include "Python-ast.h"
7
Neal Norwitz207c9f32008-03-31 04:42:11 +00008static PyTypeObject AST_type;
Neal Norwitz53d960c2006-02-28 22:47:29 +00009static PyTypeObject *mod_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +000010static PyObject* ast2obj_mod(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +000011static PyTypeObject *Module_type;
Martin v. Löwisbd928fe2011-10-14 10:20:37 +020012_Py_IDENTIFIER(body);
Neal Norwitz53d960c2006-02-28 22:47:29 +000013static char *Module_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +020014 "body",
Martin v. Löwisbd260da2006-02-26 19:42:26 +000015};
Neal Norwitz53d960c2006-02-28 22:47:29 +000016static PyTypeObject *Interactive_type;
17static char *Interactive_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +020018 "body",
Martin v. Löwisbd260da2006-02-26 19:42:26 +000019};
Neal Norwitz53d960c2006-02-28 22:47:29 +000020static PyTypeObject *Expression_type;
21static char *Expression_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +020022 "body",
Martin v. Löwisbd260da2006-02-26 19:42:26 +000023};
Neal Norwitz53d960c2006-02-28 22:47:29 +000024static PyTypeObject *Suite_type;
25static char *Suite_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +020026 "body",
Martin v. Löwisbd260da2006-02-26 19:42:26 +000027};
Neal Norwitz53d960c2006-02-28 22:47:29 +000028static PyTypeObject *stmt_type;
Martin v. Löwisbd928fe2011-10-14 10:20:37 +020029_Py_IDENTIFIER(lineno);
30_Py_IDENTIFIER(col_offset);
Neal Norwitz53d960c2006-02-28 22:47:29 +000031static char *stmt_attributes[] = {
Victor Stinnerce72e1c2013-07-27 00:00:36 +020032 "lineno",
33 "col_offset",
Martin v. Löwis577b5b92006-02-27 15:23:19 +000034};
Martin v. Löwisbd260da2006-02-26 19:42:26 +000035static PyObject* ast2obj_stmt(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +000036static PyTypeObject *FunctionDef_type;
Martin v. Löwisbd928fe2011-10-14 10:20:37 +020037_Py_IDENTIFIER(name);
38_Py_IDENTIFIER(args);
39_Py_IDENTIFIER(decorator_list);
40_Py_IDENTIFIER(returns);
Neal Norwitz53d960c2006-02-28 22:47:29 +000041static char *FunctionDef_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +020042 "name",
43 "args",
44 "body",
45 "decorator_list",
46 "returns",
Martin v. Löwisbd260da2006-02-26 19:42:26 +000047};
Yury Selivanov75445082015-05-11 22:57:16 -040048static PyTypeObject *AsyncFunctionDef_type;
49static char *AsyncFunctionDef_fields[]={
50 "name",
51 "args",
52 "body",
53 "decorator_list",
54 "returns",
55};
Neal Norwitz53d960c2006-02-28 22:47:29 +000056static PyTypeObject *ClassDef_type;
Martin v. Löwisbd928fe2011-10-14 10:20:37 +020057_Py_IDENTIFIER(bases);
58_Py_IDENTIFIER(keywords);
Neal Norwitz53d960c2006-02-28 22:47:29 +000059static char *ClassDef_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +020060 "name",
61 "bases",
62 "keywords",
Victor Stinnerce72e1c2013-07-27 00:00:36 +020063 "body",
64 "decorator_list",
Martin v. Löwisbd260da2006-02-26 19:42:26 +000065};
Neal Norwitz53d960c2006-02-28 22:47:29 +000066static PyTypeObject *Return_type;
Martin v. Löwisbd928fe2011-10-14 10:20:37 +020067_Py_IDENTIFIER(value);
Neal Norwitz53d960c2006-02-28 22:47:29 +000068static char *Return_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +020069 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +000070};
Neal Norwitz53d960c2006-02-28 22:47:29 +000071static PyTypeObject *Delete_type;
Martin v. Löwisbd928fe2011-10-14 10:20:37 +020072_Py_IDENTIFIER(targets);
Neal Norwitz53d960c2006-02-28 22:47:29 +000073static char *Delete_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +020074 "targets",
Martin v. Löwisbd260da2006-02-26 19:42:26 +000075};
Neal Norwitz53d960c2006-02-28 22:47:29 +000076static PyTypeObject *Assign_type;
77static char *Assign_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +020078 "targets",
79 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +000080};
Neal Norwitz53d960c2006-02-28 22:47:29 +000081static PyTypeObject *AugAssign_type;
Martin v. Löwisbd928fe2011-10-14 10:20:37 +020082_Py_IDENTIFIER(target);
83_Py_IDENTIFIER(op);
Neal Norwitz53d960c2006-02-28 22:47:29 +000084static char *AugAssign_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +020085 "target",
86 "op",
87 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +000088};
Yury Selivanovf8cb8a12016-09-08 20:50:03 -070089static PyTypeObject *AnnAssign_type;
90_Py_IDENTIFIER(annotation);
91_Py_IDENTIFIER(simple);
92static char *AnnAssign_fields[]={
93 "target",
94 "annotation",
95 "value",
96 "simple",
97};
Neal Norwitz53d960c2006-02-28 22:47:29 +000098static PyTypeObject *For_type;
Martin v. Löwisbd928fe2011-10-14 10:20:37 +020099_Py_IDENTIFIER(iter);
100_Py_IDENTIFIER(orelse);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000101static char *For_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200102 "target",
103 "iter",
104 "body",
105 "orelse",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000106};
Yury Selivanov75445082015-05-11 22:57:16 -0400107static PyTypeObject *AsyncFor_type;
108static char *AsyncFor_fields[]={
109 "target",
110 "iter",
111 "body",
112 "orelse",
113};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000114static PyTypeObject *While_type;
Martin v. Löwisbd928fe2011-10-14 10:20:37 +0200115_Py_IDENTIFIER(test);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000116static char *While_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200117 "test",
118 "body",
119 "orelse",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000120};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000121static PyTypeObject *If_type;
122static char *If_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200123 "test",
124 "body",
125 "orelse",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000126};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000127static PyTypeObject *With_type;
Martin v. Löwisbd928fe2011-10-14 10:20:37 +0200128_Py_IDENTIFIER(items);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000129static char *With_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200130 "items",
131 "body",
Guido van Rossumc2e20742006-02-27 22:32:47 +0000132};
Yury Selivanov75445082015-05-11 22:57:16 -0400133static PyTypeObject *AsyncWith_type;
134static char *AsyncWith_fields[]={
135 "items",
136 "body",
137};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000138static PyTypeObject *Raise_type;
Martin v. Löwisbd928fe2011-10-14 10:20:37 +0200139_Py_IDENTIFIER(exc);
140_Py_IDENTIFIER(cause);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000141static char *Raise_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200142 "exc",
143 "cause",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000144};
Benjamin Peterson43af12b2011-05-29 11:43:10 -0500145static PyTypeObject *Try_type;
Martin v. Löwisbd928fe2011-10-14 10:20:37 +0200146_Py_IDENTIFIER(handlers);
147_Py_IDENTIFIER(finalbody);
Benjamin Peterson43af12b2011-05-29 11:43:10 -0500148static char *Try_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200149 "body",
150 "handlers",
151 "orelse",
152 "finalbody",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000153};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000154static PyTypeObject *Assert_type;
Martin v. Löwisbd928fe2011-10-14 10:20:37 +0200155_Py_IDENTIFIER(msg);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000156static char *Assert_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200157 "test",
158 "msg",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000159};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000160static PyTypeObject *Import_type;
Martin v. Löwisbd928fe2011-10-14 10:20:37 +0200161_Py_IDENTIFIER(names);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000162static char *Import_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200163 "names",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000164};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000165static PyTypeObject *ImportFrom_type;
Martin v. Löwisbd928fe2011-10-14 10:20:37 +0200166_Py_IDENTIFIER(module);
167_Py_IDENTIFIER(level);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000168static char *ImportFrom_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200169 "module",
170 "names",
171 "level",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000172};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000173static PyTypeObject *Global_type;
174static char *Global_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200175 "names",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000176};
Jeremy Hylton81e95022007-02-27 06:50:52 +0000177static PyTypeObject *Nonlocal_type;
178static char *Nonlocal_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200179 "names",
Jeremy Hylton81e95022007-02-27 06:50:52 +0000180};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000181static PyTypeObject *Expr_type;
182static char *Expr_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200183 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000184};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000185static PyTypeObject *Pass_type;
186static PyTypeObject *Break_type;
187static PyTypeObject *Continue_type;
188static PyTypeObject *expr_type;
189static char *expr_attributes[] = {
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200190 "lineno",
191 "col_offset",
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000192};
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000193static PyObject* ast2obj_expr(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000194static PyTypeObject *BoolOp_type;
Martin v. Löwisbd928fe2011-10-14 10:20:37 +0200195_Py_IDENTIFIER(values);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000196static char *BoolOp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200197 "op",
198 "values",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000199};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000200static PyTypeObject *BinOp_type;
Martin v. Löwisbd928fe2011-10-14 10:20:37 +0200201_Py_IDENTIFIER(left);
202_Py_IDENTIFIER(right);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000203static char *BinOp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200204 "left",
205 "op",
206 "right",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000207};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000208static PyTypeObject *UnaryOp_type;
Martin v. Löwisbd928fe2011-10-14 10:20:37 +0200209_Py_IDENTIFIER(operand);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000210static char *UnaryOp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200211 "op",
212 "operand",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000213};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000214static PyTypeObject *Lambda_type;
215static char *Lambda_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200216 "args",
217 "body",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000218};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000219static PyTypeObject *IfExp_type;
220static char *IfExp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200221 "test",
222 "body",
223 "orelse",
Thomas Woutersdca3b9c2006-02-27 00:24:13 +0000224};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000225static PyTypeObject *Dict_type;
Martin v. Löwisbd928fe2011-10-14 10:20:37 +0200226_Py_IDENTIFIER(keys);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000227static char *Dict_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200228 "keys",
229 "values",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000230};
Guido van Rossum86e58e22006-08-28 15:27:34 +0000231static PyTypeObject *Set_type;
Martin v. Löwisbd928fe2011-10-14 10:20:37 +0200232_Py_IDENTIFIER(elts);
Guido van Rossum86e58e22006-08-28 15:27:34 +0000233static char *Set_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200234 "elts",
Guido van Rossum86e58e22006-08-28 15:27:34 +0000235};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000236static PyTypeObject *ListComp_type;
Martin v. Löwisbd928fe2011-10-14 10:20:37 +0200237_Py_IDENTIFIER(elt);
238_Py_IDENTIFIER(generators);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000239static char *ListComp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200240 "elt",
241 "generators",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000242};
Nick Coghlan650f0d02007-04-15 12:05:43 +0000243static PyTypeObject *SetComp_type;
244static char *SetComp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200245 "elt",
246 "generators",
Nick Coghlan650f0d02007-04-15 12:05:43 +0000247};
Guido van Rossum992d4a32007-07-11 13:09:30 +0000248static PyTypeObject *DictComp_type;
Martin v. Löwisbd928fe2011-10-14 10:20:37 +0200249_Py_IDENTIFIER(key);
Guido van Rossum992d4a32007-07-11 13:09:30 +0000250static char *DictComp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200251 "key",
252 "value",
253 "generators",
Guido van Rossum992d4a32007-07-11 13:09:30 +0000254};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000255static PyTypeObject *GeneratorExp_type;
256static char *GeneratorExp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200257 "elt",
258 "generators",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000259};
Yury Selivanov75445082015-05-11 22:57:16 -0400260static PyTypeObject *Await_type;
261static char *Await_fields[]={
262 "value",
263};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000264static PyTypeObject *Yield_type;
265static char *Yield_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200266 "value",
Benjamin Peterson527c6222012-01-14 08:58:23 -0500267};
268static PyTypeObject *YieldFrom_type;
269static char *YieldFrom_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200270 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000271};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000272static PyTypeObject *Compare_type;
Martin v. Löwisbd928fe2011-10-14 10:20:37 +0200273_Py_IDENTIFIER(ops);
274_Py_IDENTIFIER(comparators);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000275static char *Compare_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200276 "left",
277 "ops",
278 "comparators",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000279};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000280static PyTypeObject *Call_type;
Martin v. Löwisbd928fe2011-10-14 10:20:37 +0200281_Py_IDENTIFIER(func);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000282static char *Call_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200283 "func",
284 "args",
285 "keywords",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000286};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000287static PyTypeObject *Num_type;
Martin v. Löwisbd928fe2011-10-14 10:20:37 +0200288_Py_IDENTIFIER(n);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000289static char *Num_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200290 "n",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000291};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000292static PyTypeObject *Str_type;
Martin v. Löwisbd928fe2011-10-14 10:20:37 +0200293_Py_IDENTIFIER(s);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000294static char *Str_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200295 "s",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000296};
Eric V. Smith235a6f02015-09-19 14:51:32 -0400297static PyTypeObject *FormattedValue_type;
298_Py_IDENTIFIER(conversion);
299_Py_IDENTIFIER(format_spec);
300static char *FormattedValue_fields[]={
301 "value",
302 "conversion",
303 "format_spec",
304};
305static PyTypeObject *JoinedStr_type;
306static char *JoinedStr_fields[]={
307 "values",
308};
Thomas Wouters00e41de2007-02-23 19:56:57 +0000309static PyTypeObject *Bytes_type;
310static char *Bytes_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200311 "s",
Thomas Wouters00e41de2007-02-23 19:56:57 +0000312};
Benjamin Peterson442f2092012-12-06 17:41:04 -0500313static PyTypeObject *NameConstant_type;
314static char *NameConstant_fields[]={
Victor Stinneree4b59c2013-07-27 00:01:35 +0200315 "value",
Benjamin Peterson442f2092012-12-06 17:41:04 -0500316};
Georg Brandl52318d62006-09-06 07:06:08 +0000317static PyTypeObject *Ellipsis_type;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +0100318static PyTypeObject *Constant_type;
319static char *Constant_fields[]={
320 "value",
321};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000322static PyTypeObject *Attribute_type;
Martin v. Löwisbd928fe2011-10-14 10:20:37 +0200323_Py_IDENTIFIER(attr);
324_Py_IDENTIFIER(ctx);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000325static char *Attribute_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200326 "value",
327 "attr",
328 "ctx",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000329};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000330static PyTypeObject *Subscript_type;
Martin v. Löwisbd928fe2011-10-14 10:20:37 +0200331_Py_IDENTIFIER(slice);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000332static char *Subscript_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200333 "value",
334 "slice",
335 "ctx",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000336};
Guido van Rossum0368b722007-05-11 16:50:42 +0000337static PyTypeObject *Starred_type;
338static char *Starred_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200339 "value",
340 "ctx",
Guido van Rossum0368b722007-05-11 16:50:42 +0000341};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000342static PyTypeObject *Name_type;
Martin v. Löwisbd928fe2011-10-14 10:20:37 +0200343_Py_IDENTIFIER(id);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000344static char *Name_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200345 "id",
346 "ctx",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000347};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000348static PyTypeObject *List_type;
349static char *List_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200350 "elts",
351 "ctx",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000352};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000353static PyTypeObject *Tuple_type;
354static char *Tuple_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200355 "elts",
356 "ctx",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000357};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000358static PyTypeObject *expr_context_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000359static PyObject *Load_singleton, *Store_singleton, *Del_singleton,
360*AugLoad_singleton, *AugStore_singleton, *Param_singleton;
361static PyObject* ast2obj_expr_context(expr_context_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000362static PyTypeObject *Load_type;
363static PyTypeObject *Store_type;
364static PyTypeObject *Del_type;
365static PyTypeObject *AugLoad_type;
366static PyTypeObject *AugStore_type;
367static PyTypeObject *Param_type;
368static PyTypeObject *slice_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000369static PyObject* ast2obj_slice(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000370static PyTypeObject *Slice_type;
Martin v. Löwisbd928fe2011-10-14 10:20:37 +0200371_Py_IDENTIFIER(lower);
372_Py_IDENTIFIER(upper);
373_Py_IDENTIFIER(step);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000374static char *Slice_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200375 "lower",
376 "upper",
377 "step",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000378};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000379static PyTypeObject *ExtSlice_type;
Martin v. Löwisbd928fe2011-10-14 10:20:37 +0200380_Py_IDENTIFIER(dims);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000381static char *ExtSlice_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200382 "dims",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000383};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000384static PyTypeObject *Index_type;
385static char *Index_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200386 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000387};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000388static PyTypeObject *boolop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000389static PyObject *And_singleton, *Or_singleton;
390static PyObject* ast2obj_boolop(boolop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000391static PyTypeObject *And_type;
392static PyTypeObject *Or_type;
393static PyTypeObject *operator_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000394static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton,
Benjamin Petersond51374e2014-04-09 23:55:56 -0400395*MatMult_singleton, *Div_singleton, *Mod_singleton, *Pow_singleton,
396*LShift_singleton, *RShift_singleton, *BitOr_singleton, *BitXor_singleton,
397*BitAnd_singleton, *FloorDiv_singleton;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000398static PyObject* ast2obj_operator(operator_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000399static PyTypeObject *Add_type;
400static PyTypeObject *Sub_type;
401static PyTypeObject *Mult_type;
Benjamin Petersond51374e2014-04-09 23:55:56 -0400402static PyTypeObject *MatMult_type;
Neal Norwitz53d960c2006-02-28 22:47:29 +0000403static PyTypeObject *Div_type;
404static PyTypeObject *Mod_type;
405static PyTypeObject *Pow_type;
406static PyTypeObject *LShift_type;
407static PyTypeObject *RShift_type;
408static PyTypeObject *BitOr_type;
409static PyTypeObject *BitXor_type;
410static PyTypeObject *BitAnd_type;
411static PyTypeObject *FloorDiv_type;
412static PyTypeObject *unaryop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000413static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton,
414*USub_singleton;
415static PyObject* ast2obj_unaryop(unaryop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000416static PyTypeObject *Invert_type;
417static PyTypeObject *Not_type;
418static PyTypeObject *UAdd_type;
419static PyTypeObject *USub_type;
420static PyTypeObject *cmpop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000421static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton,
422*Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton,
423*NotIn_singleton;
424static PyObject* ast2obj_cmpop(cmpop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000425static PyTypeObject *Eq_type;
426static PyTypeObject *NotEq_type;
427static PyTypeObject *Lt_type;
428static PyTypeObject *LtE_type;
429static PyTypeObject *Gt_type;
430static PyTypeObject *GtE_type;
431static PyTypeObject *Is_type;
432static PyTypeObject *IsNot_type;
433static PyTypeObject *In_type;
434static PyTypeObject *NotIn_type;
435static PyTypeObject *comprehension_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000436static PyObject* ast2obj_comprehension(void*);
Martin v. Löwisbd928fe2011-10-14 10:20:37 +0200437_Py_IDENTIFIER(ifs);
Yury Selivanov52c4e7c2016-09-09 10:36:01 -0700438_Py_IDENTIFIER(is_async);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000439static char *comprehension_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200440 "target",
441 "iter",
442 "ifs",
Yury Selivanov52c4e7c2016-09-09 10:36:01 -0700443 "is_async",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000444};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000445static PyTypeObject *excepthandler_type;
Neal Norwitzad74aa82008-03-31 05:14:30 +0000446static char *excepthandler_attributes[] = {
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200447 "lineno",
448 "col_offset",
Neal Norwitzad74aa82008-03-31 05:14:30 +0000449};
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000450static PyObject* ast2obj_excepthandler(void*);
Neal Norwitzad74aa82008-03-31 05:14:30 +0000451static PyTypeObject *ExceptHandler_type;
Martin v. Löwisbd928fe2011-10-14 10:20:37 +0200452_Py_IDENTIFIER(type);
Neal Norwitzad74aa82008-03-31 05:14:30 +0000453static char *ExceptHandler_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200454 "type",
455 "name",
456 "body",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000457};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000458static PyTypeObject *arguments_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000459static PyObject* ast2obj_arguments(void*);
Martin v. Löwisbd928fe2011-10-14 10:20:37 +0200460_Py_IDENTIFIER(vararg);
Martin v. Löwisbd928fe2011-10-14 10:20:37 +0200461_Py_IDENTIFIER(kwonlyargs);
Martin v. Löwisbd928fe2011-10-14 10:20:37 +0200462_Py_IDENTIFIER(kw_defaults);
Benjamin Petersoncda75be2013-03-18 10:48:58 -0700463_Py_IDENTIFIER(kwarg);
464_Py_IDENTIFIER(defaults);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000465static char *arguments_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200466 "args",
467 "vararg",
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200468 "kwonlyargs",
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200469 "kw_defaults",
Victor Stinneree4b59c2013-07-27 00:01:35 +0200470 "kwarg",
471 "defaults",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000472};
Neal Norwitzc1505362006-12-28 06:47:50 +0000473static PyTypeObject *arg_type;
474static PyObject* ast2obj_arg(void*);
Benjamin Petersoncda75be2013-03-18 10:48:58 -0700475static char *arg_attributes[] = {
Victor Stinneree4b59c2013-07-27 00:01:35 +0200476 "lineno",
477 "col_offset",
Benjamin Petersoncda75be2013-03-18 10:48:58 -0700478};
Martin v. Löwisbd928fe2011-10-14 10:20:37 +0200479_Py_IDENTIFIER(arg);
Guido van Rossum1bc535d2007-05-15 18:46:22 +0000480static char *arg_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200481 "arg",
482 "annotation",
Neal Norwitzc1505362006-12-28 06:47:50 +0000483};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000484static PyTypeObject *keyword_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000485static PyObject* ast2obj_keyword(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000486static char *keyword_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200487 "arg",
488 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000489};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000490static PyTypeObject *alias_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000491static PyObject* ast2obj_alias(void*);
Martin v. Löwisbd928fe2011-10-14 10:20:37 +0200492_Py_IDENTIFIER(asname);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000493static char *alias_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200494 "name",
495 "asname",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000496};
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -0500497static PyTypeObject *withitem_type;
498static PyObject* ast2obj_withitem(void*);
Martin v. Löwisbd928fe2011-10-14 10:20:37 +0200499_Py_IDENTIFIER(context_expr);
500_Py_IDENTIFIER(optional_vars);
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -0500501static char *withitem_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200502 "context_expr",
503 "optional_vars",
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -0500504};
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000505
506
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -0700507typedef struct {
Victor Stinner45e50de2012-03-13 01:17:31 +0100508 PyObject_HEAD
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -0700509 PyObject *dict;
510} AST_object;
511
Benjamin Peterson1767e022012-03-14 21:50:29 -0500512static void
513ast_dealloc(AST_object *self)
514{
INADA Naoki2eea9522017-09-04 12:31:09 +0900515 /* bpo-31095: UnTrack is needed before calling any callbacks */
516 PyObject_GC_UnTrack(self);
Benjamin Peterson1767e022012-03-14 21:50:29 -0500517 Py_CLEAR(self->dict);
Antoine Pitrou50750742012-07-08 12:43:32 +0200518 Py_TYPE(self)->tp_free(self);
Benjamin Peterson1767e022012-03-14 21:50:29 -0500519}
520
Neal Norwitz207c9f32008-03-31 04:42:11 +0000521static int
Benjamin Peterson81071762012-07-08 11:03:46 -0700522ast_traverse(AST_object *self, visitproc visit, void *arg)
523{
524 Py_VISIT(self->dict);
525 return 0;
526}
527
528static void
529ast_clear(AST_object *self)
530{
531 Py_CLEAR(self->dict);
532}
533
534static int
Neal Norwitz207c9f32008-03-31 04:42:11 +0000535ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
536{
Martin v. Löwisbd928fe2011-10-14 10:20:37 +0200537 _Py_IDENTIFIER(_fields);
Neal Norwitz207c9f32008-03-31 04:42:11 +0000538 Py_ssize_t i, numfields = 0;
539 int res = -1;
540 PyObject *key, *value, *fields;
Martin v. Löwis1ee1b6f2011-10-10 18:11:30 +0200541 fields = _PyObject_GetAttrId((PyObject*)Py_TYPE(self), &PyId__fields);
Neal Norwitz207c9f32008-03-31 04:42:11 +0000542 if (!fields)
543 PyErr_Clear();
544 if (fields) {
545 numfields = PySequence_Size(fields);
546 if (numfields == -1)
547 goto cleanup;
548 }
549 res = 0; /* if no error occurs, this stays 0 to the end */
550 if (PyTuple_GET_SIZE(args) > 0) {
551 if (numfields != PyTuple_GET_SIZE(args)) {
552 PyErr_Format(PyExc_TypeError, "%.400s constructor takes %s"
Amaury Forgeot d'Arc245c70b2008-09-10 22:24:24 +0000553 "%zd positional argument%s",
Neal Norwitz207c9f32008-03-31 04:42:11 +0000554 Py_TYPE(self)->tp_name,
555 numfields == 0 ? "" : "either 0 or ",
556 numfields, numfields == 1 ? "" : "s");
557 res = -1;
558 goto cleanup;
559 }
560 for (i = 0; i < PyTuple_GET_SIZE(args); i++) {
561 /* cannot be reached when fields is NULL */
562 PyObject *name = PySequence_GetItem(fields, i);
563 if (!name) {
564 res = -1;
565 goto cleanup;
566 }
567 res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i));
568 Py_DECREF(name);
569 if (res < 0)
570 goto cleanup;
571 }
572 }
573 if (kw) {
574 i = 0; /* needed by PyDict_Next */
575 while (PyDict_Next(kw, &i, &key, &value)) {
576 res = PyObject_SetAttr(self, key, value);
577 if (res < 0)
578 goto cleanup;
579 }
580 }
581 cleanup:
582 Py_XDECREF(fields);
583 return res;
584}
585
Neal Norwitzee9b10a2008-03-31 05:29:39 +0000586/* Pickling support */
587static PyObject *
588ast_type_reduce(PyObject *self, PyObject *unused)
589{
590 PyObject *res;
Martin v. Löwisbd928fe2011-10-14 10:20:37 +0200591 _Py_IDENTIFIER(__dict__);
Martin v. Löwis1ee1b6f2011-10-10 18:11:30 +0200592 PyObject *dict = _PyObject_GetAttrId(self, &PyId___dict__);
Neal Norwitzee9b10a2008-03-31 05:29:39 +0000593 if (dict == NULL) {
594 if (PyErr_ExceptionMatches(PyExc_AttributeError))
595 PyErr_Clear();
596 else
597 return NULL;
598 }
599 if (dict) {
600 res = Py_BuildValue("O()O", Py_TYPE(self), dict);
601 Py_DECREF(dict);
602 return res;
603 }
604 return Py_BuildValue("O()", Py_TYPE(self));
605}
606
607static PyMethodDef ast_type_methods[] = {
608 {"__reduce__", ast_type_reduce, METH_NOARGS, NULL},
609 {NULL}
610};
611
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -0700612static PyGetSetDef ast_type_getsets[] = {
613 {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict},
614 {NULL}
615};
616
Neal Norwitz207c9f32008-03-31 04:42:11 +0000617static PyTypeObject AST_type = {
618 PyVarObject_HEAD_INIT(&PyType_Type, 0)
Neal Norwitzee9b10a2008-03-31 05:29:39 +0000619 "_ast.AST",
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -0700620 sizeof(AST_object),
Neal Norwitz207c9f32008-03-31 04:42:11 +0000621 0,
Benjamin Peterson1767e022012-03-14 21:50:29 -0500622 (destructor)ast_dealloc, /* tp_dealloc */
Neal Norwitz207c9f32008-03-31 04:42:11 +0000623 0, /* tp_print */
624 0, /* tp_getattr */
625 0, /* tp_setattr */
Mark Dickinsone94c6792009-02-02 20:36:42 +0000626 0, /* tp_reserved */
Neal Norwitz207c9f32008-03-31 04:42:11 +0000627 0, /* tp_repr */
628 0, /* tp_as_number */
629 0, /* tp_as_sequence */
630 0, /* tp_as_mapping */
631 0, /* tp_hash */
632 0, /* tp_call */
633 0, /* tp_str */
634 PyObject_GenericGetAttr, /* tp_getattro */
635 PyObject_GenericSetAttr, /* tp_setattro */
636 0, /* tp_as_buffer */
Benjamin Peterson81071762012-07-08 11:03:46 -0700637 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /* tp_flags */
Neal Norwitz207c9f32008-03-31 04:42:11 +0000638 0, /* tp_doc */
Benjamin Peterson81071762012-07-08 11:03:46 -0700639 (traverseproc)ast_traverse, /* tp_traverse */
640 (inquiry)ast_clear, /* tp_clear */
Neal Norwitz207c9f32008-03-31 04:42:11 +0000641 0, /* tp_richcompare */
642 0, /* tp_weaklistoffset */
643 0, /* tp_iter */
644 0, /* tp_iternext */
Neal Norwitzee9b10a2008-03-31 05:29:39 +0000645 ast_type_methods, /* tp_methods */
Neal Norwitz207c9f32008-03-31 04:42:11 +0000646 0, /* tp_members */
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -0700647 ast_type_getsets, /* tp_getset */
Neal Norwitz207c9f32008-03-31 04:42:11 +0000648 0, /* tp_base */
649 0, /* tp_dict */
650 0, /* tp_descr_get */
651 0, /* tp_descr_set */
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -0700652 offsetof(AST_object, dict),/* tp_dictoffset */
Neal Norwitz207c9f32008-03-31 04:42:11 +0000653 (initproc)ast_type_init, /* tp_init */
654 PyType_GenericAlloc, /* tp_alloc */
655 PyType_GenericNew, /* tp_new */
Benjamin Peterson81071762012-07-08 11:03:46 -0700656 PyObject_GC_Del, /* tp_free */
Neal Norwitz207c9f32008-03-31 04:42:11 +0000657};
658
659
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000660static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields)
661{
662 PyObject *fnames, *result;
663 int i;
Neal Norwitzee9b10a2008-03-31 05:29:39 +0000664 fnames = PyTuple_New(num_fields);
665 if (!fnames) return NULL;
666 for (i = 0; i < num_fields; i++) {
Neal Norwitze4dc3242007-08-25 01:33:49 +0000667 PyObject *field = PyUnicode_FromString(fields[i]);
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000668 if (!field) {
669 Py_DECREF(fnames);
670 return NULL;
671 }
672 PyTuple_SET_ITEM(fnames, i, field);
673 }
Victor Stinner7eeb5b52010-06-07 19:57:46 +0000674 result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}",
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000675 type, base, "_fields", fnames, "__module__", "_ast");
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000676 Py_DECREF(fnames);
677 return (PyTypeObject*)result;
678}
679
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000680static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)
681{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000682 int i, result;
Martin v. Löwis1c67dd92011-10-14 15:16:45 +0200683 _Py_IDENTIFIER(_attributes);
Neal Norwitz207c9f32008-03-31 04:42:11 +0000684 PyObject *s, *l = PyTuple_New(num_fields);
Benjamin Peterson3e5cd1d2010-06-27 21:45:24 +0000685 if (!l)
686 return 0;
687 for (i = 0; i < num_fields; i++) {
Neal Norwitze4dc3242007-08-25 01:33:49 +0000688 s = PyUnicode_FromString(attrs[i]);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000689 if (!s) {
690 Py_DECREF(l);
691 return 0;
692 }
Neal Norwitz207c9f32008-03-31 04:42:11 +0000693 PyTuple_SET_ITEM(l, i, s);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000694 }
Martin v. Löwis1c67dd92011-10-14 15:16:45 +0200695 result = _PyObject_SetAttrId((PyObject*)type, &PyId__attributes, l) >= 0;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000696 Py_DECREF(l);
697 return result;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000698}
699
Martin v. Löwis618dc5e2008-03-30 20:03:44 +0000700/* Conversion AST -> Python */
701
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000702static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
703{
Benjamin Peterson77fa9372012-05-15 10:10:27 -0700704 Py_ssize_t i, n = asdl_seq_LEN(seq);
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000705 PyObject *result = PyList_New(n);
706 PyObject *value;
707 if (!result)
708 return NULL;
709 for (i = 0; i < n; i++) {
710 value = func(asdl_seq_GET(seq, i));
711 if (!value) {
712 Py_DECREF(result);
713 return NULL;
714 }
715 PyList_SET_ITEM(result, i, value);
716 }
717 return result;
718}
719
720static PyObject* ast2obj_object(void *o)
721{
722 if (!o)
723 o = Py_None;
724 Py_INCREF((PyObject*)o);
725 return (PyObject*)o;
726}
Benjamin Peterson442f2092012-12-06 17:41:04 -0500727#define ast2obj_singleton ast2obj_object
Victor Stinnerf2c1aa12016-01-26 00:40:57 +0100728#define ast2obj_constant ast2obj_object
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000729#define ast2obj_identifier ast2obj_object
730#define ast2obj_string ast2obj_object
Benjamin Petersone2498412011-08-09 16:08:39 -0500731#define ast2obj_bytes ast2obj_object
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000732
Thomas Woutersa44f3a32007-02-26 18:20:15 +0000733static PyObject* ast2obj_int(long b)
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000734{
Christian Heimes217cfd12007-12-02 14:31:20 +0000735 return PyLong_FromLong(b);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000736}
737
Martin v. Löwis618dc5e2008-03-30 20:03:44 +0000738/* Conversion Python -> AST */
739
Benjamin Peterson442f2092012-12-06 17:41:04 -0500740static int obj2ast_singleton(PyObject *obj, PyObject** out, PyArena* arena)
741{
742 if (obj != Py_None && obj != Py_True && obj != Py_False) {
743 PyErr_SetString(PyExc_ValueError,
744 "AST singleton must be True, False, or None");
745 return 1;
746 }
747 *out = obj;
748 return 0;
749}
750
Martin v. Löwis618dc5e2008-03-30 20:03:44 +0000751static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena)
752{
753 if (obj == Py_None)
754 obj = NULL;
Christian Heimes70c94e72013-07-27 00:33:13 +0200755 if (obj) {
756 if (PyArena_AddPyObject(arena, obj) < 0) {
757 *out = NULL;
758 return -1;
759 }
760 Py_INCREF(obj);
761 }
Martin v. Löwis618dc5e2008-03-30 20:03:44 +0000762 *out = obj;
763 return 0;
764}
765
Victor Stinnerf2c1aa12016-01-26 00:40:57 +0100766static int obj2ast_constant(PyObject* obj, PyObject** out, PyArena* arena)
767{
Victor Stinnerf2c1aa12016-01-26 00:40:57 +0100768 if (obj) {
769 if (PyArena_AddPyObject(arena, obj) < 0) {
770 *out = NULL;
771 return -1;
772 }
773 Py_INCREF(obj);
774 }
775 *out = obj;
776 return 0;
777}
778
Benjamin Peterson180e6352011-07-22 11:09:07 -0500779static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena)
Benjamin Peterson2193d2b2011-07-22 10:50:23 -0500780{
Benjamin Peterson180e6352011-07-22 11:09:07 -0500781 if (!PyUnicode_CheckExact(obj) && obj != Py_None) {
782 PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str");
Benjamin Peterson2193d2b2011-07-22 10:50:23 -0500783 return 1;
784 }
785 return obj2ast_object(obj, out, arena);
786}
787
Benjamin Peterson2193d2b2011-07-22 10:50:23 -0500788static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena)
789{
Benjamin Peterson0224d4e2011-08-31 22:13:03 -0400790 if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) {
Benjamin Peterson180e6352011-07-22 11:09:07 -0500791 PyErr_SetString(PyExc_TypeError, "AST string must be of type str");
792 return 1;
793 }
794 return obj2ast_object(obj, out, arena);
Benjamin Peterson2193d2b2011-07-22 10:50:23 -0500795}
Martin v. Löwis618dc5e2008-03-30 20:03:44 +0000796
Benjamin Petersone2498412011-08-09 16:08:39 -0500797static int obj2ast_bytes(PyObject* obj, PyObject** out, PyArena* arena)
798{
799 if (!PyBytes_CheckExact(obj)) {
800 PyErr_SetString(PyExc_TypeError, "AST bytes must be of type bytes");
801 return 1;
802 }
803 return obj2ast_object(obj, out, arena);
804}
805
Martin v. Löwis618dc5e2008-03-30 20:03:44 +0000806static int obj2ast_int(PyObject* obj, int* out, PyArena* arena)
807{
808 int i;
809 if (!PyLong_Check(obj)) {
Amaury Forgeot d'Arc5e8f8102011-11-22 21:52:30 +0100810 PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +0000811 return 1;
812 }
813
Serhiy Storchaka56f6e762015-09-06 21:25:30 +0300814 i = _PyLong_AsInt(obj);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +0000815 if (i == -1 && PyErr_Occurred())
816 return 1;
817 *out = i;
818 return 0;
819}
820
Benjamin Peterson1a6e0d02008-10-25 15:49:17 +0000821static int add_ast_fields(void)
Benjamin Petersonce825f12008-10-24 23:11:02 +0000822{
823 PyObject *empty_tuple, *d;
824 if (PyType_Ready(&AST_type) < 0)
825 return -1;
826 d = AST_type.tp_dict;
827 empty_tuple = PyTuple_New(0);
828 if (!empty_tuple ||
829 PyDict_SetItemString(d, "_fields", empty_tuple) < 0 ||
830 PyDict_SetItemString(d, "_attributes", empty_tuple) < 0) {
831 Py_XDECREF(empty_tuple);
832 return -1;
833 }
834 Py_DECREF(empty_tuple);
835 return 0;
836}
837
Benjamin Petersonb72406b2013-03-18 23:24:41 -0700838static int exists_not_none(PyObject *obj, _Py_Identifier *id)
839{
Benjamin Peterson3a619432013-03-18 23:40:53 -0700840 int isnone;
Benjamin Petersonb72406b2013-03-18 23:24:41 -0700841 PyObject *attr = _PyObject_GetAttrId(obj, id);
842 if (!attr) {
843 PyErr_Clear();
844 return 0;
845 }
Benjamin Peterson3a619432013-03-18 23:40:53 -0700846 isnone = attr == Py_None;
Benjamin Petersonb72406b2013-03-18 23:24:41 -0700847 Py_DECREF(attr);
848 return !isnone;
849}
850
Martin v. Löwis618dc5e2008-03-30 20:03:44 +0000851
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000852static int init_types(void)
853{
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200854 static int initialized;
855 if (initialized) return 1;
856 if (add_ast_fields() < 0) return 0;
857 mod_type = make_type("mod", &AST_type, NULL, 0);
858 if (!mod_type) return 0;
859 if (!add_attributes(mod_type, NULL, 0)) return 0;
860 Module_type = make_type("Module", mod_type, Module_fields, 1);
861 if (!Module_type) return 0;
862 Interactive_type = make_type("Interactive", mod_type, Interactive_fields,
863 1);
864 if (!Interactive_type) return 0;
865 Expression_type = make_type("Expression", mod_type, Expression_fields, 1);
866 if (!Expression_type) return 0;
867 Suite_type = make_type("Suite", mod_type, Suite_fields, 1);
868 if (!Suite_type) return 0;
869 stmt_type = make_type("stmt", &AST_type, NULL, 0);
870 if (!stmt_type) return 0;
871 if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0;
872 FunctionDef_type = make_type("FunctionDef", stmt_type, FunctionDef_fields,
873 5);
874 if (!FunctionDef_type) return 0;
Yury Selivanov75445082015-05-11 22:57:16 -0400875 AsyncFunctionDef_type = make_type("AsyncFunctionDef", stmt_type,
876 AsyncFunctionDef_fields, 5);
877 if (!AsyncFunctionDef_type) return 0;
Benjamin Peterson025e9eb2015-05-05 20:16:41 -0400878 ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 5);
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200879 if (!ClassDef_type) return 0;
880 Return_type = make_type("Return", stmt_type, Return_fields, 1);
881 if (!Return_type) return 0;
882 Delete_type = make_type("Delete", stmt_type, Delete_fields, 1);
883 if (!Delete_type) return 0;
884 Assign_type = make_type("Assign", stmt_type, Assign_fields, 2);
885 if (!Assign_type) return 0;
886 AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3);
887 if (!AugAssign_type) return 0;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -0700888 AnnAssign_type = make_type("AnnAssign", stmt_type, AnnAssign_fields, 4);
889 if (!AnnAssign_type) return 0;
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200890 For_type = make_type("For", stmt_type, For_fields, 4);
891 if (!For_type) return 0;
Yury Selivanov75445082015-05-11 22:57:16 -0400892 AsyncFor_type = make_type("AsyncFor", stmt_type, AsyncFor_fields, 4);
893 if (!AsyncFor_type) return 0;
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200894 While_type = make_type("While", stmt_type, While_fields, 3);
895 if (!While_type) return 0;
896 If_type = make_type("If", stmt_type, If_fields, 3);
897 if (!If_type) return 0;
898 With_type = make_type("With", stmt_type, With_fields, 2);
899 if (!With_type) return 0;
Yury Selivanov75445082015-05-11 22:57:16 -0400900 AsyncWith_type = make_type("AsyncWith", stmt_type, AsyncWith_fields, 2);
901 if (!AsyncWith_type) return 0;
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200902 Raise_type = make_type("Raise", stmt_type, Raise_fields, 2);
903 if (!Raise_type) return 0;
904 Try_type = make_type("Try", stmt_type, Try_fields, 4);
905 if (!Try_type) return 0;
906 Assert_type = make_type("Assert", stmt_type, Assert_fields, 2);
907 if (!Assert_type) return 0;
908 Import_type = make_type("Import", stmt_type, Import_fields, 1);
909 if (!Import_type) return 0;
910 ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields, 3);
911 if (!ImportFrom_type) return 0;
912 Global_type = make_type("Global", stmt_type, Global_fields, 1);
913 if (!Global_type) return 0;
914 Nonlocal_type = make_type("Nonlocal", stmt_type, Nonlocal_fields, 1);
915 if (!Nonlocal_type) return 0;
916 Expr_type = make_type("Expr", stmt_type, Expr_fields, 1);
917 if (!Expr_type) return 0;
918 Pass_type = make_type("Pass", stmt_type, NULL, 0);
919 if (!Pass_type) return 0;
920 Break_type = make_type("Break", stmt_type, NULL, 0);
921 if (!Break_type) return 0;
922 Continue_type = make_type("Continue", stmt_type, NULL, 0);
923 if (!Continue_type) return 0;
924 expr_type = make_type("expr", &AST_type, NULL, 0);
925 if (!expr_type) return 0;
926 if (!add_attributes(expr_type, expr_attributes, 2)) return 0;
927 BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2);
928 if (!BoolOp_type) return 0;
929 BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3);
930 if (!BinOp_type) return 0;
931 UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2);
932 if (!UnaryOp_type) return 0;
933 Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2);
934 if (!Lambda_type) return 0;
935 IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3);
936 if (!IfExp_type) return 0;
937 Dict_type = make_type("Dict", expr_type, Dict_fields, 2);
938 if (!Dict_type) return 0;
939 Set_type = make_type("Set", expr_type, Set_fields, 1);
940 if (!Set_type) return 0;
941 ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2);
942 if (!ListComp_type) return 0;
943 SetComp_type = make_type("SetComp", expr_type, SetComp_fields, 2);
944 if (!SetComp_type) return 0;
945 DictComp_type = make_type("DictComp", expr_type, DictComp_fields, 3);
946 if (!DictComp_type) return 0;
947 GeneratorExp_type = make_type("GeneratorExp", expr_type,
948 GeneratorExp_fields, 2);
949 if (!GeneratorExp_type) return 0;
Yury Selivanov75445082015-05-11 22:57:16 -0400950 Await_type = make_type("Await", expr_type, Await_fields, 1);
951 if (!Await_type) return 0;
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200952 Yield_type = make_type("Yield", expr_type, Yield_fields, 1);
953 if (!Yield_type) return 0;
954 YieldFrom_type = make_type("YieldFrom", expr_type, YieldFrom_fields, 1);
955 if (!YieldFrom_type) return 0;
956 Compare_type = make_type("Compare", expr_type, Compare_fields, 3);
957 if (!Compare_type) return 0;
Benjamin Peterson025e9eb2015-05-05 20:16:41 -0400958 Call_type = make_type("Call", expr_type, Call_fields, 3);
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200959 if (!Call_type) return 0;
960 Num_type = make_type("Num", expr_type, Num_fields, 1);
961 if (!Num_type) return 0;
962 Str_type = make_type("Str", expr_type, Str_fields, 1);
963 if (!Str_type) return 0;
Eric V. Smith235a6f02015-09-19 14:51:32 -0400964 FormattedValue_type = make_type("FormattedValue", expr_type,
965 FormattedValue_fields, 3);
966 if (!FormattedValue_type) return 0;
967 JoinedStr_type = make_type("JoinedStr", expr_type, JoinedStr_fields, 1);
968 if (!JoinedStr_type) return 0;
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200969 Bytes_type = make_type("Bytes", expr_type, Bytes_fields, 1);
970 if (!Bytes_type) return 0;
Victor Stinneree4b59c2013-07-27 00:01:35 +0200971 NameConstant_type = make_type("NameConstant", expr_type,
972 NameConstant_fields, 1);
973 if (!NameConstant_type) return 0;
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200974 Ellipsis_type = make_type("Ellipsis", expr_type, NULL, 0);
975 if (!Ellipsis_type) return 0;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +0100976 Constant_type = make_type("Constant", expr_type, Constant_fields, 1);
977 if (!Constant_type) return 0;
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200978 Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3);
979 if (!Attribute_type) return 0;
980 Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3);
981 if (!Subscript_type) return 0;
982 Starred_type = make_type("Starred", expr_type, Starred_fields, 2);
983 if (!Starred_type) return 0;
984 Name_type = make_type("Name", expr_type, Name_fields, 2);
985 if (!Name_type) return 0;
986 List_type = make_type("List", expr_type, List_fields, 2);
987 if (!List_type) return 0;
988 Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2);
989 if (!Tuple_type) return 0;
990 expr_context_type = make_type("expr_context", &AST_type, NULL, 0);
991 if (!expr_context_type) return 0;
992 if (!add_attributes(expr_context_type, NULL, 0)) return 0;
993 Load_type = make_type("Load", expr_context_type, NULL, 0);
994 if (!Load_type) return 0;
995 Load_singleton = PyType_GenericNew(Load_type, NULL, NULL);
996 if (!Load_singleton) return 0;
997 Store_type = make_type("Store", expr_context_type, NULL, 0);
998 if (!Store_type) return 0;
999 Store_singleton = PyType_GenericNew(Store_type, NULL, NULL);
1000 if (!Store_singleton) return 0;
1001 Del_type = make_type("Del", expr_context_type, NULL, 0);
1002 if (!Del_type) return 0;
1003 Del_singleton = PyType_GenericNew(Del_type, NULL, NULL);
1004 if (!Del_singleton) return 0;
1005 AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0);
1006 if (!AugLoad_type) return 0;
1007 AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL);
1008 if (!AugLoad_singleton) return 0;
1009 AugStore_type = make_type("AugStore", expr_context_type, NULL, 0);
1010 if (!AugStore_type) return 0;
1011 AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL);
1012 if (!AugStore_singleton) return 0;
1013 Param_type = make_type("Param", expr_context_type, NULL, 0);
1014 if (!Param_type) return 0;
1015 Param_singleton = PyType_GenericNew(Param_type, NULL, NULL);
1016 if (!Param_singleton) return 0;
1017 slice_type = make_type("slice", &AST_type, NULL, 0);
1018 if (!slice_type) return 0;
1019 if (!add_attributes(slice_type, NULL, 0)) return 0;
1020 Slice_type = make_type("Slice", slice_type, Slice_fields, 3);
1021 if (!Slice_type) return 0;
1022 ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1);
1023 if (!ExtSlice_type) return 0;
1024 Index_type = make_type("Index", slice_type, Index_fields, 1);
1025 if (!Index_type) return 0;
1026 boolop_type = make_type("boolop", &AST_type, NULL, 0);
1027 if (!boolop_type) return 0;
1028 if (!add_attributes(boolop_type, NULL, 0)) return 0;
1029 And_type = make_type("And", boolop_type, NULL, 0);
1030 if (!And_type) return 0;
1031 And_singleton = PyType_GenericNew(And_type, NULL, NULL);
1032 if (!And_singleton) return 0;
1033 Or_type = make_type("Or", boolop_type, NULL, 0);
1034 if (!Or_type) return 0;
1035 Or_singleton = PyType_GenericNew(Or_type, NULL, NULL);
1036 if (!Or_singleton) return 0;
1037 operator_type = make_type("operator", &AST_type, NULL, 0);
1038 if (!operator_type) return 0;
1039 if (!add_attributes(operator_type, NULL, 0)) return 0;
1040 Add_type = make_type("Add", operator_type, NULL, 0);
1041 if (!Add_type) return 0;
1042 Add_singleton = PyType_GenericNew(Add_type, NULL, NULL);
1043 if (!Add_singleton) return 0;
1044 Sub_type = make_type("Sub", operator_type, NULL, 0);
1045 if (!Sub_type) return 0;
1046 Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL);
1047 if (!Sub_singleton) return 0;
1048 Mult_type = make_type("Mult", operator_type, NULL, 0);
1049 if (!Mult_type) return 0;
1050 Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL);
1051 if (!Mult_singleton) return 0;
Benjamin Petersond51374e2014-04-09 23:55:56 -04001052 MatMult_type = make_type("MatMult", operator_type, NULL, 0);
1053 if (!MatMult_type) return 0;
1054 MatMult_singleton = PyType_GenericNew(MatMult_type, NULL, NULL);
1055 if (!MatMult_singleton) return 0;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001056 Div_type = make_type("Div", operator_type, NULL, 0);
1057 if (!Div_type) return 0;
1058 Div_singleton = PyType_GenericNew(Div_type, NULL, NULL);
1059 if (!Div_singleton) return 0;
1060 Mod_type = make_type("Mod", operator_type, NULL, 0);
1061 if (!Mod_type) return 0;
1062 Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL);
1063 if (!Mod_singleton) return 0;
1064 Pow_type = make_type("Pow", operator_type, NULL, 0);
1065 if (!Pow_type) return 0;
1066 Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL);
1067 if (!Pow_singleton) return 0;
1068 LShift_type = make_type("LShift", operator_type, NULL, 0);
1069 if (!LShift_type) return 0;
1070 LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL);
1071 if (!LShift_singleton) return 0;
1072 RShift_type = make_type("RShift", operator_type, NULL, 0);
1073 if (!RShift_type) return 0;
1074 RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL);
1075 if (!RShift_singleton) return 0;
1076 BitOr_type = make_type("BitOr", operator_type, NULL, 0);
1077 if (!BitOr_type) return 0;
1078 BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL);
1079 if (!BitOr_singleton) return 0;
1080 BitXor_type = make_type("BitXor", operator_type, NULL, 0);
1081 if (!BitXor_type) return 0;
1082 BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL);
1083 if (!BitXor_singleton) return 0;
1084 BitAnd_type = make_type("BitAnd", operator_type, NULL, 0);
1085 if (!BitAnd_type) return 0;
1086 BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL);
1087 if (!BitAnd_singleton) return 0;
1088 FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0);
1089 if (!FloorDiv_type) return 0;
1090 FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL);
1091 if (!FloorDiv_singleton) return 0;
1092 unaryop_type = make_type("unaryop", &AST_type, NULL, 0);
1093 if (!unaryop_type) return 0;
1094 if (!add_attributes(unaryop_type, NULL, 0)) return 0;
1095 Invert_type = make_type("Invert", unaryop_type, NULL, 0);
1096 if (!Invert_type) return 0;
1097 Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL);
1098 if (!Invert_singleton) return 0;
1099 Not_type = make_type("Not", unaryop_type, NULL, 0);
1100 if (!Not_type) return 0;
1101 Not_singleton = PyType_GenericNew(Not_type, NULL, NULL);
1102 if (!Not_singleton) return 0;
1103 UAdd_type = make_type("UAdd", unaryop_type, NULL, 0);
1104 if (!UAdd_type) return 0;
1105 UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL);
1106 if (!UAdd_singleton) return 0;
1107 USub_type = make_type("USub", unaryop_type, NULL, 0);
1108 if (!USub_type) return 0;
1109 USub_singleton = PyType_GenericNew(USub_type, NULL, NULL);
1110 if (!USub_singleton) return 0;
1111 cmpop_type = make_type("cmpop", &AST_type, NULL, 0);
1112 if (!cmpop_type) return 0;
1113 if (!add_attributes(cmpop_type, NULL, 0)) return 0;
1114 Eq_type = make_type("Eq", cmpop_type, NULL, 0);
1115 if (!Eq_type) return 0;
1116 Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL);
1117 if (!Eq_singleton) return 0;
1118 NotEq_type = make_type("NotEq", cmpop_type, NULL, 0);
1119 if (!NotEq_type) return 0;
1120 NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL);
1121 if (!NotEq_singleton) return 0;
1122 Lt_type = make_type("Lt", cmpop_type, NULL, 0);
1123 if (!Lt_type) return 0;
1124 Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL);
1125 if (!Lt_singleton) return 0;
1126 LtE_type = make_type("LtE", cmpop_type, NULL, 0);
1127 if (!LtE_type) return 0;
1128 LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL);
1129 if (!LtE_singleton) return 0;
1130 Gt_type = make_type("Gt", cmpop_type, NULL, 0);
1131 if (!Gt_type) return 0;
1132 Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL);
1133 if (!Gt_singleton) return 0;
1134 GtE_type = make_type("GtE", cmpop_type, NULL, 0);
1135 if (!GtE_type) return 0;
1136 GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL);
1137 if (!GtE_singleton) return 0;
1138 Is_type = make_type("Is", cmpop_type, NULL, 0);
1139 if (!Is_type) return 0;
1140 Is_singleton = PyType_GenericNew(Is_type, NULL, NULL);
1141 if (!Is_singleton) return 0;
1142 IsNot_type = make_type("IsNot", cmpop_type, NULL, 0);
1143 if (!IsNot_type) return 0;
1144 IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL);
1145 if (!IsNot_singleton) return 0;
1146 In_type = make_type("In", cmpop_type, NULL, 0);
1147 if (!In_type) return 0;
1148 In_singleton = PyType_GenericNew(In_type, NULL, NULL);
1149 if (!In_singleton) return 0;
1150 NotIn_type = make_type("NotIn", cmpop_type, NULL, 0);
1151 if (!NotIn_type) return 0;
1152 NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL);
1153 if (!NotIn_singleton) return 0;
1154 comprehension_type = make_type("comprehension", &AST_type,
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07001155 comprehension_fields, 4);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001156 if (!comprehension_type) return 0;
Victor Stinneree4b59c2013-07-27 00:01:35 +02001157 if (!add_attributes(comprehension_type, NULL, 0)) return 0;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001158 excepthandler_type = make_type("excepthandler", &AST_type, NULL, 0);
1159 if (!excepthandler_type) return 0;
1160 if (!add_attributes(excepthandler_type, excepthandler_attributes, 2))
1161 return 0;
1162 ExceptHandler_type = make_type("ExceptHandler", excepthandler_type,
1163 ExceptHandler_fields, 3);
1164 if (!ExceptHandler_type) return 0;
Victor Stinneree4b59c2013-07-27 00:01:35 +02001165 arguments_type = make_type("arguments", &AST_type, arguments_fields, 6);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001166 if (!arguments_type) return 0;
Victor Stinneree4b59c2013-07-27 00:01:35 +02001167 if (!add_attributes(arguments_type, NULL, 0)) return 0;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001168 arg_type = make_type("arg", &AST_type, arg_fields, 2);
1169 if (!arg_type) return 0;
Victor Stinneree4b59c2013-07-27 00:01:35 +02001170 if (!add_attributes(arg_type, arg_attributes, 2)) return 0;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001171 keyword_type = make_type("keyword", &AST_type, keyword_fields, 2);
1172 if (!keyword_type) return 0;
Victor Stinneree4b59c2013-07-27 00:01:35 +02001173 if (!add_attributes(keyword_type, NULL, 0)) return 0;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001174 alias_type = make_type("alias", &AST_type, alias_fields, 2);
1175 if (!alias_type) return 0;
Victor Stinneree4b59c2013-07-27 00:01:35 +02001176 if (!add_attributes(alias_type, NULL, 0)) return 0;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001177 withitem_type = make_type("withitem", &AST_type, withitem_fields, 2);
1178 if (!withitem_type) return 0;
Victor Stinneree4b59c2013-07-27 00:01:35 +02001179 if (!add_attributes(withitem_type, NULL, 0)) return 0;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001180 initialized = 1;
1181 return 1;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001182}
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001183
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001184static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena);
1185static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena);
1186static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena);
1187static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena*
1188 arena);
1189static int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena);
1190static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena);
1191static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena);
1192static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena);
1193static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena);
1194static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena*
1195 arena);
1196static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena*
1197 arena);
1198static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena);
1199static int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena);
1200static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena);
1201static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena);
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05001202static int obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001203
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001204mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001205Module(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001206{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001207 mod_ty p;
1208 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
1209 if (!p)
1210 return NULL;
1211 p->kind = Module_kind;
1212 p->v.Module.body = body;
1213 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001214}
1215
1216mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001217Interactive(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001218{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001219 mod_ty p;
1220 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
1221 if (!p)
1222 return NULL;
1223 p->kind = Interactive_kind;
1224 p->v.Interactive.body = body;
1225 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001226}
1227
1228mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001229Expression(expr_ty body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001230{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001231 mod_ty p;
1232 if (!body) {
1233 PyErr_SetString(PyExc_ValueError,
1234 "field body is required for Expression");
1235 return NULL;
1236 }
1237 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
1238 if (!p)
1239 return NULL;
1240 p->kind = Expression_kind;
1241 p->v.Expression.body = body;
1242 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001243}
1244
1245mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001246Suite(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001247{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001248 mod_ty p;
1249 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
1250 if (!p)
1251 return NULL;
1252 p->kind = Suite_kind;
1253 p->v.Suite.body = body;
1254 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001255}
1256
1257stmt_ty
1258FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
Guido van Rossumd59da4b2007-05-22 18:11:13 +00001259 decorator_list, expr_ty returns, int lineno, int col_offset,
1260 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001261{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001262 stmt_ty p;
1263 if (!name) {
1264 PyErr_SetString(PyExc_ValueError,
1265 "field name is required for FunctionDef");
1266 return NULL;
1267 }
1268 if (!args) {
1269 PyErr_SetString(PyExc_ValueError,
1270 "field args is required for FunctionDef");
1271 return NULL;
1272 }
1273 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1274 if (!p)
1275 return NULL;
1276 p->kind = FunctionDef_kind;
1277 p->v.FunctionDef.name = name;
1278 p->v.FunctionDef.args = args;
1279 p->v.FunctionDef.body = body;
1280 p->v.FunctionDef.decorator_list = decorator_list;
1281 p->v.FunctionDef.returns = returns;
1282 p->lineno = lineno;
1283 p->col_offset = col_offset;
1284 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001285}
1286
1287stmt_ty
Yury Selivanov75445082015-05-11 22:57:16 -04001288AsyncFunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq
1289 * decorator_list, expr_ty returns, int lineno, int col_offset,
1290 PyArena *arena)
1291{
1292 stmt_ty p;
1293 if (!name) {
1294 PyErr_SetString(PyExc_ValueError,
1295 "field name is required for AsyncFunctionDef");
1296 return NULL;
1297 }
1298 if (!args) {
1299 PyErr_SetString(PyExc_ValueError,
1300 "field args is required for AsyncFunctionDef");
1301 return NULL;
1302 }
1303 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1304 if (!p)
1305 return NULL;
1306 p->kind = AsyncFunctionDef_kind;
1307 p->v.AsyncFunctionDef.name = name;
1308 p->v.AsyncFunctionDef.args = args;
1309 p->v.AsyncFunctionDef.body = body;
1310 p->v.AsyncFunctionDef.decorator_list = decorator_list;
1311 p->v.AsyncFunctionDef.returns = returns;
1312 p->lineno = lineno;
1313 p->col_offset = col_offset;
1314 return p;
1315}
1316
1317stmt_ty
Benjamin Peterson025e9eb2015-05-05 20:16:41 -04001318ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, asdl_seq *
1319 body, asdl_seq * decorator_list, int lineno, int col_offset, PyArena
1320 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001321{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001322 stmt_ty p;
1323 if (!name) {
1324 PyErr_SetString(PyExc_ValueError,
1325 "field name is required for ClassDef");
1326 return NULL;
1327 }
1328 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1329 if (!p)
1330 return NULL;
1331 p->kind = ClassDef_kind;
1332 p->v.ClassDef.name = name;
1333 p->v.ClassDef.bases = bases;
1334 p->v.ClassDef.keywords = keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001335 p->v.ClassDef.body = body;
1336 p->v.ClassDef.decorator_list = decorator_list;
1337 p->lineno = lineno;
1338 p->col_offset = col_offset;
1339 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001340}
1341
1342stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001343Return(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001344{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001345 stmt_ty p;
1346 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1347 if (!p)
1348 return NULL;
1349 p->kind = Return_kind;
1350 p->v.Return.value = value;
1351 p->lineno = lineno;
1352 p->col_offset = col_offset;
1353 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001354}
1355
1356stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001357Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001358{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001359 stmt_ty p;
1360 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1361 if (!p)
1362 return NULL;
1363 p->kind = Delete_kind;
1364 p->v.Delete.targets = targets;
1365 p->lineno = lineno;
1366 p->col_offset = col_offset;
1367 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001368}
1369
1370stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001371Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena
1372 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001373{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001374 stmt_ty p;
1375 if (!value) {
1376 PyErr_SetString(PyExc_ValueError,
1377 "field value is required for Assign");
1378 return NULL;
1379 }
1380 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1381 if (!p)
1382 return NULL;
1383 p->kind = Assign_kind;
1384 p->v.Assign.targets = targets;
1385 p->v.Assign.value = value;
1386 p->lineno = lineno;
1387 p->col_offset = col_offset;
1388 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001389}
1390
1391stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001392AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
1393 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001394{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001395 stmt_ty p;
1396 if (!target) {
1397 PyErr_SetString(PyExc_ValueError,
1398 "field target is required for AugAssign");
1399 return NULL;
1400 }
1401 if (!op) {
1402 PyErr_SetString(PyExc_ValueError,
1403 "field op is required for AugAssign");
1404 return NULL;
1405 }
1406 if (!value) {
1407 PyErr_SetString(PyExc_ValueError,
1408 "field value is required for AugAssign");
1409 return NULL;
1410 }
1411 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1412 if (!p)
1413 return NULL;
1414 p->kind = AugAssign_kind;
1415 p->v.AugAssign.target = target;
1416 p->v.AugAssign.op = op;
1417 p->v.AugAssign.value = value;
1418 p->lineno = lineno;
1419 p->col_offset = col_offset;
1420 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001421}
1422
1423stmt_ty
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07001424AnnAssign(expr_ty target, expr_ty annotation, expr_ty value, int simple, int
1425 lineno, int col_offset, PyArena *arena)
1426{
1427 stmt_ty p;
1428 if (!target) {
1429 PyErr_SetString(PyExc_ValueError,
1430 "field target is required for AnnAssign");
1431 return NULL;
1432 }
1433 if (!annotation) {
1434 PyErr_SetString(PyExc_ValueError,
1435 "field annotation is required for AnnAssign");
1436 return NULL;
1437 }
1438 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1439 if (!p)
1440 return NULL;
1441 p->kind = AnnAssign_kind;
1442 p->v.AnnAssign.target = target;
1443 p->v.AnnAssign.annotation = annotation;
1444 p->v.AnnAssign.value = value;
1445 p->v.AnnAssign.simple = simple;
1446 p->lineno = lineno;
1447 p->col_offset = col_offset;
1448 return p;
1449}
1450
1451stmt_ty
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001452For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001453 lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001454{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001455 stmt_ty p;
1456 if (!target) {
1457 PyErr_SetString(PyExc_ValueError,
1458 "field target is required for For");
1459 return NULL;
1460 }
1461 if (!iter) {
1462 PyErr_SetString(PyExc_ValueError,
1463 "field iter is required for For");
1464 return NULL;
1465 }
1466 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1467 if (!p)
1468 return NULL;
1469 p->kind = For_kind;
1470 p->v.For.target = target;
1471 p->v.For.iter = iter;
1472 p->v.For.body = body;
1473 p->v.For.orelse = orelse;
1474 p->lineno = lineno;
1475 p->col_offset = col_offset;
1476 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001477}
1478
1479stmt_ty
Yury Selivanov75445082015-05-11 22:57:16 -04001480AsyncFor(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int
1481 lineno, int col_offset, PyArena *arena)
1482{
1483 stmt_ty p;
1484 if (!target) {
1485 PyErr_SetString(PyExc_ValueError,
1486 "field target is required for AsyncFor");
1487 return NULL;
1488 }
1489 if (!iter) {
1490 PyErr_SetString(PyExc_ValueError,
1491 "field iter is required for AsyncFor");
1492 return NULL;
1493 }
1494 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1495 if (!p)
1496 return NULL;
1497 p->kind = AsyncFor_kind;
1498 p->v.AsyncFor.target = target;
1499 p->v.AsyncFor.iter = iter;
1500 p->v.AsyncFor.body = body;
1501 p->v.AsyncFor.orelse = orelse;
1502 p->lineno = lineno;
1503 p->col_offset = col_offset;
1504 return p;
1505}
1506
1507stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001508While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
1509 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001510{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001511 stmt_ty p;
1512 if (!test) {
1513 PyErr_SetString(PyExc_ValueError,
1514 "field test is required for While");
1515 return NULL;
1516 }
1517 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1518 if (!p)
1519 return NULL;
1520 p->kind = While_kind;
1521 p->v.While.test = test;
1522 p->v.While.body = body;
1523 p->v.While.orelse = orelse;
1524 p->lineno = lineno;
1525 p->col_offset = col_offset;
1526 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001527}
1528
1529stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001530If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
1531 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001532{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001533 stmt_ty p;
1534 if (!test) {
1535 PyErr_SetString(PyExc_ValueError,
1536 "field test is required for If");
1537 return NULL;
1538 }
1539 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1540 if (!p)
1541 return NULL;
1542 p->kind = If_kind;
1543 p->v.If.test = test;
1544 p->v.If.body = body;
1545 p->v.If.orelse = orelse;
1546 p->lineno = lineno;
1547 p->col_offset = col_offset;
1548 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001549}
1550
1551stmt_ty
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05001552With(asdl_seq * items, asdl_seq * body, int lineno, int col_offset, PyArena
1553 *arena)
Guido van Rossumc2e20742006-02-27 22:32:47 +00001554{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001555 stmt_ty p;
1556 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1557 if (!p)
1558 return NULL;
1559 p->kind = With_kind;
1560 p->v.With.items = items;
1561 p->v.With.body = body;
1562 p->lineno = lineno;
1563 p->col_offset = col_offset;
1564 return p;
Guido van Rossumc2e20742006-02-27 22:32:47 +00001565}
1566
1567stmt_ty
Yury Selivanov75445082015-05-11 22:57:16 -04001568AsyncWith(asdl_seq * items, asdl_seq * body, int lineno, int col_offset,
1569 PyArena *arena)
1570{
1571 stmt_ty p;
1572 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1573 if (!p)
1574 return NULL;
1575 p->kind = AsyncWith_kind;
1576 p->v.AsyncWith.items = items;
1577 p->v.AsyncWith.body = body;
1578 p->lineno = lineno;
1579 p->col_offset = col_offset;
1580 return p;
1581}
1582
1583stmt_ty
Collin Winter828f04a2007-08-31 00:04:24 +00001584Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001585{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001586 stmt_ty p;
1587 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1588 if (!p)
1589 return NULL;
1590 p->kind = Raise_kind;
1591 p->v.Raise.exc = exc;
1592 p->v.Raise.cause = cause;
1593 p->lineno = lineno;
1594 p->col_offset = col_offset;
1595 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001596}
1597
1598stmt_ty
Benjamin Peterson43af12b2011-05-29 11:43:10 -05001599Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, asdl_seq *
1600 finalbody, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001601{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001602 stmt_ty p;
1603 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1604 if (!p)
1605 return NULL;
1606 p->kind = Try_kind;
1607 p->v.Try.body = body;
1608 p->v.Try.handlers = handlers;
1609 p->v.Try.orelse = orelse;
1610 p->v.Try.finalbody = finalbody;
1611 p->lineno = lineno;
1612 p->col_offset = col_offset;
1613 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001614}
1615
1616stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001617Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001618{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001619 stmt_ty p;
1620 if (!test) {
1621 PyErr_SetString(PyExc_ValueError,
1622 "field test is required for Assert");
1623 return NULL;
1624 }
1625 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1626 if (!p)
1627 return NULL;
1628 p->kind = Assert_kind;
1629 p->v.Assert.test = test;
1630 p->v.Assert.msg = msg;
1631 p->lineno = lineno;
1632 p->col_offset = col_offset;
1633 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001634}
1635
1636stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001637Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001638{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001639 stmt_ty p;
1640 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1641 if (!p)
1642 return NULL;
1643 p->kind = Import_kind;
1644 p->v.Import.names = names;
1645 p->lineno = lineno;
1646 p->col_offset = col_offset;
1647 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001648}
1649
1650stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001651ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int
1652 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001653{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001654 stmt_ty p;
1655 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1656 if (!p)
1657 return NULL;
1658 p->kind = ImportFrom_kind;
1659 p->v.ImportFrom.module = module;
1660 p->v.ImportFrom.names = names;
1661 p->v.ImportFrom.level = level;
1662 p->lineno = lineno;
1663 p->col_offset = col_offset;
1664 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001665}
1666
1667stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001668Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001669{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001670 stmt_ty p;
1671 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1672 if (!p)
1673 return NULL;
1674 p->kind = Global_kind;
1675 p->v.Global.names = names;
1676 p->lineno = lineno;
1677 p->col_offset = col_offset;
1678 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001679}
1680
1681stmt_ty
Jeremy Hylton81e95022007-02-27 06:50:52 +00001682Nonlocal(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
1683{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001684 stmt_ty p;
1685 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1686 if (!p)
1687 return NULL;
1688 p->kind = Nonlocal_kind;
1689 p->v.Nonlocal.names = names;
1690 p->lineno = lineno;
1691 p->col_offset = col_offset;
1692 return p;
Jeremy Hylton81e95022007-02-27 06:50:52 +00001693}
1694
1695stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001696Expr(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001697{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001698 stmt_ty p;
1699 if (!value) {
1700 PyErr_SetString(PyExc_ValueError,
1701 "field value is required for Expr");
1702 return NULL;
1703 }
1704 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1705 if (!p)
1706 return NULL;
1707 p->kind = Expr_kind;
1708 p->v.Expr.value = value;
1709 p->lineno = lineno;
1710 p->col_offset = col_offset;
1711 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001712}
1713
1714stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001715Pass(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001716{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001717 stmt_ty p;
1718 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1719 if (!p)
1720 return NULL;
1721 p->kind = Pass_kind;
1722 p->lineno = lineno;
1723 p->col_offset = col_offset;
1724 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001725}
1726
1727stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001728Break(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001729{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001730 stmt_ty p;
1731 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1732 if (!p)
1733 return NULL;
1734 p->kind = Break_kind;
1735 p->lineno = lineno;
1736 p->col_offset = col_offset;
1737 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001738}
1739
1740stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001741Continue(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001742{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001743 stmt_ty p;
1744 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1745 if (!p)
1746 return NULL;
1747 p->kind = Continue_kind;
1748 p->lineno = lineno;
1749 p->col_offset = col_offset;
1750 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001751}
1752
1753expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001754BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena
1755 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001756{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001757 expr_ty p;
1758 if (!op) {
1759 PyErr_SetString(PyExc_ValueError,
1760 "field op is required for BoolOp");
1761 return NULL;
1762 }
1763 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1764 if (!p)
1765 return NULL;
1766 p->kind = BoolOp_kind;
1767 p->v.BoolOp.op = op;
1768 p->v.BoolOp.values = values;
1769 p->lineno = lineno;
1770 p->col_offset = col_offset;
1771 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001772}
1773
1774expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001775BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset,
1776 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001777{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001778 expr_ty p;
1779 if (!left) {
1780 PyErr_SetString(PyExc_ValueError,
1781 "field left is required for BinOp");
1782 return NULL;
1783 }
1784 if (!op) {
1785 PyErr_SetString(PyExc_ValueError,
1786 "field op is required for BinOp");
1787 return NULL;
1788 }
1789 if (!right) {
1790 PyErr_SetString(PyExc_ValueError,
1791 "field right is required for BinOp");
1792 return NULL;
1793 }
1794 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1795 if (!p)
1796 return NULL;
1797 p->kind = BinOp_kind;
1798 p->v.BinOp.left = left;
1799 p->v.BinOp.op = op;
1800 p->v.BinOp.right = right;
1801 p->lineno = lineno;
1802 p->col_offset = col_offset;
1803 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001804}
1805
1806expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001807UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena
1808 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001809{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001810 expr_ty p;
1811 if (!op) {
1812 PyErr_SetString(PyExc_ValueError,
1813 "field op is required for UnaryOp");
1814 return NULL;
1815 }
1816 if (!operand) {
1817 PyErr_SetString(PyExc_ValueError,
1818 "field operand is required for UnaryOp");
1819 return NULL;
1820 }
1821 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1822 if (!p)
1823 return NULL;
1824 p->kind = UnaryOp_kind;
1825 p->v.UnaryOp.op = op;
1826 p->v.UnaryOp.operand = operand;
1827 p->lineno = lineno;
1828 p->col_offset = col_offset;
1829 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001830}
1831
1832expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001833Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena
1834 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001835{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001836 expr_ty p;
1837 if (!args) {
1838 PyErr_SetString(PyExc_ValueError,
1839 "field args is required for Lambda");
1840 return NULL;
1841 }
1842 if (!body) {
1843 PyErr_SetString(PyExc_ValueError,
1844 "field body is required for Lambda");
1845 return NULL;
1846 }
1847 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1848 if (!p)
1849 return NULL;
1850 p->kind = Lambda_kind;
1851 p->v.Lambda.args = args;
1852 p->v.Lambda.body = body;
1853 p->lineno = lineno;
1854 p->col_offset = col_offset;
1855 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001856}
1857
1858expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001859IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset,
1860 PyArena *arena)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001861{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001862 expr_ty p;
1863 if (!test) {
1864 PyErr_SetString(PyExc_ValueError,
1865 "field test is required for IfExp");
1866 return NULL;
1867 }
1868 if (!body) {
1869 PyErr_SetString(PyExc_ValueError,
1870 "field body is required for IfExp");
1871 return NULL;
1872 }
1873 if (!orelse) {
1874 PyErr_SetString(PyExc_ValueError,
1875 "field orelse is required for IfExp");
1876 return NULL;
1877 }
1878 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1879 if (!p)
1880 return NULL;
1881 p->kind = IfExp_kind;
1882 p->v.IfExp.test = test;
1883 p->v.IfExp.body = body;
1884 p->v.IfExp.orelse = orelse;
1885 p->lineno = lineno;
1886 p->col_offset = col_offset;
1887 return p;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001888}
1889
1890expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001891Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena
1892 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001893{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001894 expr_ty p;
1895 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1896 if (!p)
1897 return NULL;
1898 p->kind = Dict_kind;
1899 p->v.Dict.keys = keys;
1900 p->v.Dict.values = values;
1901 p->lineno = lineno;
1902 p->col_offset = col_offset;
1903 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001904}
1905
1906expr_ty
Guido van Rossum86e58e22006-08-28 15:27:34 +00001907Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena)
1908{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001909 expr_ty p;
1910 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1911 if (!p)
1912 return NULL;
1913 p->kind = Set_kind;
1914 p->v.Set.elts = elts;
1915 p->lineno = lineno;
1916 p->col_offset = col_offset;
1917 return p;
Guido van Rossum86e58e22006-08-28 15:27:34 +00001918}
1919
1920expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001921ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1922 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001923{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001924 expr_ty p;
1925 if (!elt) {
1926 PyErr_SetString(PyExc_ValueError,
1927 "field elt is required for ListComp");
1928 return NULL;
1929 }
1930 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1931 if (!p)
1932 return NULL;
1933 p->kind = ListComp_kind;
1934 p->v.ListComp.elt = elt;
1935 p->v.ListComp.generators = generators;
1936 p->lineno = lineno;
1937 p->col_offset = col_offset;
1938 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001939}
1940
1941expr_ty
Nick Coghlan650f0d02007-04-15 12:05:43 +00001942SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, PyArena
1943 *arena)
1944{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001945 expr_ty p;
1946 if (!elt) {
1947 PyErr_SetString(PyExc_ValueError,
1948 "field elt is required for SetComp");
1949 return NULL;
1950 }
1951 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1952 if (!p)
1953 return NULL;
1954 p->kind = SetComp_kind;
1955 p->v.SetComp.elt = elt;
1956 p->v.SetComp.generators = generators;
1957 p->lineno = lineno;
1958 p->col_offset = col_offset;
1959 return p;
Nick Coghlan650f0d02007-04-15 12:05:43 +00001960}
1961
1962expr_ty
Guido van Rossum992d4a32007-07-11 13:09:30 +00001963DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int lineno, int
1964 col_offset, PyArena *arena)
1965{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001966 expr_ty p;
1967 if (!key) {
1968 PyErr_SetString(PyExc_ValueError,
1969 "field key is required for DictComp");
1970 return NULL;
1971 }
1972 if (!value) {
1973 PyErr_SetString(PyExc_ValueError,
1974 "field value is required for DictComp");
1975 return NULL;
1976 }
1977 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1978 if (!p)
1979 return NULL;
1980 p->kind = DictComp_kind;
1981 p->v.DictComp.key = key;
1982 p->v.DictComp.value = value;
1983 p->v.DictComp.generators = generators;
1984 p->lineno = lineno;
1985 p->col_offset = col_offset;
1986 return p;
Guido van Rossum992d4a32007-07-11 13:09:30 +00001987}
1988
1989expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001990GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1991 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001992{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001993 expr_ty p;
1994 if (!elt) {
1995 PyErr_SetString(PyExc_ValueError,
1996 "field elt is required for GeneratorExp");
1997 return NULL;
1998 }
1999 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2000 if (!p)
2001 return NULL;
2002 p->kind = GeneratorExp_kind;
2003 p->v.GeneratorExp.elt = elt;
2004 p->v.GeneratorExp.generators = generators;
2005 p->lineno = lineno;
2006 p->col_offset = col_offset;
2007 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002008}
2009
2010expr_ty
Yury Selivanov75445082015-05-11 22:57:16 -04002011Await(expr_ty value, int lineno, int col_offset, PyArena *arena)
2012{
2013 expr_ty p;
2014 if (!value) {
2015 PyErr_SetString(PyExc_ValueError,
2016 "field value is required for Await");
2017 return NULL;
2018 }
2019 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2020 if (!p)
2021 return NULL;
2022 p->kind = Await_kind;
2023 p->v.Await.value = value;
2024 p->lineno = lineno;
2025 p->col_offset = col_offset;
2026 return p;
2027}
2028
2029expr_ty
Benjamin Peterson527c6222012-01-14 08:58:23 -05002030Yield(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002031{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002032 expr_ty p;
2033 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2034 if (!p)
2035 return NULL;
2036 p->kind = Yield_kind;
2037 p->v.Yield.value = value;
2038 p->lineno = lineno;
2039 p->col_offset = col_offset;
2040 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002041}
2042
2043expr_ty
Benjamin Peterson527c6222012-01-14 08:58:23 -05002044YieldFrom(expr_ty value, int lineno, int col_offset, PyArena *arena)
2045{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002046 expr_ty p;
2047 if (!value) {
2048 PyErr_SetString(PyExc_ValueError,
2049 "field value is required for YieldFrom");
2050 return NULL;
2051 }
2052 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2053 if (!p)
2054 return NULL;
2055 p->kind = YieldFrom_kind;
2056 p->v.YieldFrom.value = value;
2057 p->lineno = lineno;
2058 p->col_offset = col_offset;
2059 return p;
Benjamin Peterson527c6222012-01-14 08:58:23 -05002060}
2061
2062expr_ty
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002063Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno,
2064 int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002065{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002066 expr_ty p;
2067 if (!left) {
2068 PyErr_SetString(PyExc_ValueError,
2069 "field left is required for Compare");
2070 return NULL;
2071 }
2072 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2073 if (!p)
2074 return NULL;
2075 p->kind = Compare_kind;
2076 p->v.Compare.left = left;
2077 p->v.Compare.ops = ops;
2078 p->v.Compare.comparators = comparators;
2079 p->lineno = lineno;
2080 p->col_offset = col_offset;
2081 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002082}
2083
2084expr_ty
Benjamin Peterson025e9eb2015-05-05 20:16:41 -04002085Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, int lineno, int
2086 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002087{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002088 expr_ty p;
2089 if (!func) {
2090 PyErr_SetString(PyExc_ValueError,
2091 "field func is required for Call");
2092 return NULL;
2093 }
2094 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2095 if (!p)
2096 return NULL;
2097 p->kind = Call_kind;
2098 p->v.Call.func = func;
2099 p->v.Call.args = args;
2100 p->v.Call.keywords = keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002101 p->lineno = lineno;
2102 p->col_offset = col_offset;
2103 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002104}
2105
2106expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002107Num(object n, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002108{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002109 expr_ty p;
2110 if (!n) {
2111 PyErr_SetString(PyExc_ValueError,
2112 "field n is required for Num");
2113 return NULL;
2114 }
2115 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2116 if (!p)
2117 return NULL;
2118 p->kind = Num_kind;
2119 p->v.Num.n = n;
2120 p->lineno = lineno;
2121 p->col_offset = col_offset;
2122 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002123}
2124
2125expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002126Str(string s, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002127{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002128 expr_ty p;
2129 if (!s) {
2130 PyErr_SetString(PyExc_ValueError,
2131 "field s is required for Str");
2132 return NULL;
2133 }
2134 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2135 if (!p)
2136 return NULL;
2137 p->kind = Str_kind;
2138 p->v.Str.s = s;
2139 p->lineno = lineno;
2140 p->col_offset = col_offset;
2141 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002142}
2143
2144expr_ty
Eric V. Smith235a6f02015-09-19 14:51:32 -04002145FormattedValue(expr_ty value, int conversion, expr_ty format_spec, int lineno,
2146 int col_offset, PyArena *arena)
2147{
2148 expr_ty p;
2149 if (!value) {
2150 PyErr_SetString(PyExc_ValueError,
2151 "field value is required for FormattedValue");
2152 return NULL;
2153 }
2154 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2155 if (!p)
2156 return NULL;
2157 p->kind = FormattedValue_kind;
2158 p->v.FormattedValue.value = value;
2159 p->v.FormattedValue.conversion = conversion;
2160 p->v.FormattedValue.format_spec = format_spec;
2161 p->lineno = lineno;
2162 p->col_offset = col_offset;
2163 return p;
2164}
2165
2166expr_ty
2167JoinedStr(asdl_seq * values, int lineno, int col_offset, PyArena *arena)
2168{
2169 expr_ty p;
2170 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2171 if (!p)
2172 return NULL;
2173 p->kind = JoinedStr_kind;
2174 p->v.JoinedStr.values = values;
2175 p->lineno = lineno;
2176 p->col_offset = col_offset;
2177 return p;
2178}
2179
2180expr_ty
Benjamin Petersone2498412011-08-09 16:08:39 -05002181Bytes(bytes s, int lineno, int col_offset, PyArena *arena)
Thomas Wouters00e41de2007-02-23 19:56:57 +00002182{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002183 expr_ty p;
2184 if (!s) {
2185 PyErr_SetString(PyExc_ValueError,
2186 "field s is required for Bytes");
2187 return NULL;
2188 }
2189 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2190 if (!p)
2191 return NULL;
2192 p->kind = Bytes_kind;
2193 p->v.Bytes.s = s;
2194 p->lineno = lineno;
2195 p->col_offset = col_offset;
2196 return p;
Thomas Wouters00e41de2007-02-23 19:56:57 +00002197}
2198
2199expr_ty
Benjamin Peterson442f2092012-12-06 17:41:04 -05002200NameConstant(singleton value, int lineno, int col_offset, PyArena *arena)
2201{
Victor Stinneree4b59c2013-07-27 00:01:35 +02002202 expr_ty p;
2203 if (!value) {
2204 PyErr_SetString(PyExc_ValueError,
2205 "field value is required for NameConstant");
2206 return NULL;
2207 }
2208 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2209 if (!p)
2210 return NULL;
2211 p->kind = NameConstant_kind;
2212 p->v.NameConstant.value = value;
2213 p->lineno = lineno;
2214 p->col_offset = col_offset;
2215 return p;
Benjamin Peterson442f2092012-12-06 17:41:04 -05002216}
2217
2218expr_ty
Georg Brandl52318d62006-09-06 07:06:08 +00002219Ellipsis(int lineno, int col_offset, PyArena *arena)
2220{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002221 expr_ty p;
2222 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2223 if (!p)
2224 return NULL;
2225 p->kind = Ellipsis_kind;
2226 p->lineno = lineno;
2227 p->col_offset = col_offset;
2228 return p;
Georg Brandl52318d62006-09-06 07:06:08 +00002229}
2230
2231expr_ty
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01002232Constant(constant value, int lineno, int col_offset, PyArena *arena)
2233{
2234 expr_ty p;
2235 if (!value) {
2236 PyErr_SetString(PyExc_ValueError,
2237 "field value is required for Constant");
2238 return NULL;
2239 }
2240 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2241 if (!p)
2242 return NULL;
2243 p->kind = Constant_kind;
2244 p->v.Constant.value = value;
2245 p->lineno = lineno;
2246 p->col_offset = col_offset;
2247 return p;
2248}
2249
2250expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002251Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int
2252 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002253{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002254 expr_ty p;
2255 if (!value) {
2256 PyErr_SetString(PyExc_ValueError,
2257 "field value is required for Attribute");
2258 return NULL;
2259 }
2260 if (!attr) {
2261 PyErr_SetString(PyExc_ValueError,
2262 "field attr is required for Attribute");
2263 return NULL;
2264 }
2265 if (!ctx) {
2266 PyErr_SetString(PyExc_ValueError,
2267 "field ctx is required for Attribute");
2268 return NULL;
2269 }
2270 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2271 if (!p)
2272 return NULL;
2273 p->kind = Attribute_kind;
2274 p->v.Attribute.value = value;
2275 p->v.Attribute.attr = attr;
2276 p->v.Attribute.ctx = ctx;
2277 p->lineno = lineno;
2278 p->col_offset = col_offset;
2279 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002280}
2281
2282expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002283Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int
2284 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002285{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002286 expr_ty p;
2287 if (!value) {
2288 PyErr_SetString(PyExc_ValueError,
2289 "field value is required for Subscript");
2290 return NULL;
2291 }
2292 if (!slice) {
2293 PyErr_SetString(PyExc_ValueError,
2294 "field slice is required for Subscript");
2295 return NULL;
2296 }
2297 if (!ctx) {
2298 PyErr_SetString(PyExc_ValueError,
2299 "field ctx is required for Subscript");
2300 return NULL;
2301 }
2302 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2303 if (!p)
2304 return NULL;
2305 p->kind = Subscript_kind;
2306 p->v.Subscript.value = value;
2307 p->v.Subscript.slice = slice;
2308 p->v.Subscript.ctx = ctx;
2309 p->lineno = lineno;
2310 p->col_offset = col_offset;
2311 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002312}
2313
2314expr_ty
Guido van Rossum0368b722007-05-11 16:50:42 +00002315Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, PyArena
2316 *arena)
2317{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002318 expr_ty p;
2319 if (!value) {
2320 PyErr_SetString(PyExc_ValueError,
2321 "field value is required for Starred");
2322 return NULL;
2323 }
2324 if (!ctx) {
2325 PyErr_SetString(PyExc_ValueError,
2326 "field ctx is required for Starred");
2327 return NULL;
2328 }
2329 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2330 if (!p)
2331 return NULL;
2332 p->kind = Starred_kind;
2333 p->v.Starred.value = value;
2334 p->v.Starred.ctx = ctx;
2335 p->lineno = lineno;
2336 p->col_offset = col_offset;
2337 return p;
Guido van Rossum0368b722007-05-11 16:50:42 +00002338}
2339
2340expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002341Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena
2342 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002343{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002344 expr_ty p;
2345 if (!id) {
2346 PyErr_SetString(PyExc_ValueError,
2347 "field id is required for Name");
2348 return NULL;
2349 }
2350 if (!ctx) {
2351 PyErr_SetString(PyExc_ValueError,
2352 "field ctx is required for Name");
2353 return NULL;
2354 }
2355 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2356 if (!p)
2357 return NULL;
2358 p->kind = Name_kind;
2359 p->v.Name.id = id;
2360 p->v.Name.ctx = ctx;
2361 p->lineno = lineno;
2362 p->col_offset = col_offset;
2363 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002364}
2365
2366expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002367List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
2368 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002369{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002370 expr_ty p;
2371 if (!ctx) {
2372 PyErr_SetString(PyExc_ValueError,
2373 "field ctx is required for List");
2374 return NULL;
2375 }
2376 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2377 if (!p)
2378 return NULL;
2379 p->kind = List_kind;
2380 p->v.List.elts = elts;
2381 p->v.List.ctx = ctx;
2382 p->lineno = lineno;
2383 p->col_offset = col_offset;
2384 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002385}
2386
2387expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002388Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
2389 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002390{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002391 expr_ty p;
2392 if (!ctx) {
2393 PyErr_SetString(PyExc_ValueError,
2394 "field ctx is required for Tuple");
2395 return NULL;
2396 }
2397 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2398 if (!p)
2399 return NULL;
2400 p->kind = Tuple_kind;
2401 p->v.Tuple.elts = elts;
2402 p->v.Tuple.ctx = ctx;
2403 p->lineno = lineno;
2404 p->col_offset = col_offset;
2405 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002406}
2407
2408slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00002409Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002410{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002411 slice_ty p;
2412 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
2413 if (!p)
2414 return NULL;
2415 p->kind = Slice_kind;
2416 p->v.Slice.lower = lower;
2417 p->v.Slice.upper = upper;
2418 p->v.Slice.step = step;
2419 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002420}
2421
2422slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00002423ExtSlice(asdl_seq * dims, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002424{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002425 slice_ty p;
2426 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
2427 if (!p)
2428 return NULL;
2429 p->kind = ExtSlice_kind;
2430 p->v.ExtSlice.dims = dims;
2431 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002432}
2433
2434slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00002435Index(expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002436{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002437 slice_ty p;
2438 if (!value) {
2439 PyErr_SetString(PyExc_ValueError,
2440 "field value is required for Index");
2441 return NULL;
2442 }
2443 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
2444 if (!p)
2445 return NULL;
2446 p->kind = Index_kind;
2447 p->v.Index.value = value;
2448 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002449}
2450
2451comprehension_ty
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07002452comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, int is_async,
2453 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002454{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002455 comprehension_ty p;
2456 if (!target) {
2457 PyErr_SetString(PyExc_ValueError,
2458 "field target is required for comprehension");
2459 return NULL;
2460 }
2461 if (!iter) {
2462 PyErr_SetString(PyExc_ValueError,
2463 "field iter is required for comprehension");
2464 return NULL;
2465 }
2466 p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));
2467 if (!p)
2468 return NULL;
2469 p->target = target;
2470 p->iter = iter;
2471 p->ifs = ifs;
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07002472 p->is_async = is_async;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002473 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002474}
2475
2476excepthandler_ty
Neal Norwitzad74aa82008-03-31 05:14:30 +00002477ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002478 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002479{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002480 excepthandler_ty p;
2481 p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
2482 if (!p)
2483 return NULL;
2484 p->kind = ExceptHandler_kind;
2485 p->v.ExceptHandler.type = type;
2486 p->v.ExceptHandler.name = name;
2487 p->v.ExceptHandler.body = body;
2488 p->lineno = lineno;
2489 p->col_offset = col_offset;
2490 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002491}
2492
2493arguments_ty
Benjamin Petersoncda75be2013-03-18 10:48:58 -07002494arguments(asdl_seq * args, arg_ty vararg, asdl_seq * kwonlyargs, asdl_seq *
2495 kw_defaults, arg_ty kwarg, asdl_seq * defaults, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002496{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002497 arguments_ty p;
2498 p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
2499 if (!p)
2500 return NULL;
2501 p->args = args;
2502 p->vararg = vararg;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002503 p->kwonlyargs = kwonlyargs;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002504 p->kw_defaults = kw_defaults;
Victor Stinneree4b59c2013-07-27 00:01:35 +02002505 p->kwarg = kwarg;
2506 p->defaults = defaults;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002507 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002508}
2509
Neal Norwitzc1505362006-12-28 06:47:50 +00002510arg_ty
Victor Stinnerc106c682015-11-06 17:01:48 +01002511arg(identifier arg, expr_ty annotation, int lineno, int col_offset, PyArena
2512 *arena)
Neal Norwitzc1505362006-12-28 06:47:50 +00002513{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002514 arg_ty p;
2515 if (!arg) {
2516 PyErr_SetString(PyExc_ValueError,
2517 "field arg is required for arg");
2518 return NULL;
2519 }
2520 p = (arg_ty)PyArena_Malloc(arena, sizeof(*p));
2521 if (!p)
2522 return NULL;
2523 p->arg = arg;
2524 p->annotation = annotation;
Victor Stinnerc106c682015-11-06 17:01:48 +01002525 p->lineno = lineno;
2526 p->col_offset = col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002527 return p;
Neal Norwitzc1505362006-12-28 06:47:50 +00002528}
2529
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002530keyword_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00002531keyword(identifier arg, expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002532{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002533 keyword_ty p;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002534 if (!value) {
2535 PyErr_SetString(PyExc_ValueError,
2536 "field value is required for keyword");
2537 return NULL;
2538 }
2539 p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));
2540 if (!p)
2541 return NULL;
2542 p->arg = arg;
2543 p->value = value;
2544 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002545}
2546
2547alias_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00002548alias(identifier name, identifier asname, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002549{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002550 alias_ty p;
2551 if (!name) {
2552 PyErr_SetString(PyExc_ValueError,
2553 "field name is required for alias");
2554 return NULL;
2555 }
2556 p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));
2557 if (!p)
2558 return NULL;
2559 p->name = name;
2560 p->asname = asname;
2561 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002562}
2563
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05002564withitem_ty
2565withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena)
2566{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002567 withitem_ty p;
2568 if (!context_expr) {
2569 PyErr_SetString(PyExc_ValueError,
2570 "field context_expr is required for withitem");
2571 return NULL;
2572 }
2573 p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p));
2574 if (!p)
2575 return NULL;
2576 p->context_expr = context_expr;
2577 p->optional_vars = optional_vars;
2578 return p;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05002579}
2580
Neal Norwitz7b5a6042005-11-13 19:14:20 +00002581
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002582PyObject*
2583ast2obj_mod(void* _o)
Neal Norwitz7b5a6042005-11-13 19:14:20 +00002584{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002585 mod_ty o = (mod_ty)_o;
2586 PyObject *result = NULL, *value = NULL;
2587 if (!o) {
2588 Py_INCREF(Py_None);
2589 return Py_None;
2590 }
Neal Norwitz7b5a6042005-11-13 19:14:20 +00002591
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002592 switch (o->kind) {
2593 case Module_kind:
2594 result = PyType_GenericNew(Module_type, NULL, NULL);
2595 if (!result) goto failed;
2596 value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
2597 if (!value) goto failed;
2598 if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
2599 goto failed;
2600 Py_DECREF(value);
2601 break;
2602 case Interactive_kind:
2603 result = PyType_GenericNew(Interactive_type, NULL, NULL);
2604 if (!result) goto failed;
2605 value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
2606 if (!value) goto failed;
2607 if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
2608 goto failed;
2609 Py_DECREF(value);
2610 break;
2611 case Expression_kind:
2612 result = PyType_GenericNew(Expression_type, NULL, NULL);
2613 if (!result) goto failed;
2614 value = ast2obj_expr(o->v.Expression.body);
2615 if (!value) goto failed;
2616 if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
2617 goto failed;
2618 Py_DECREF(value);
2619 break;
2620 case Suite_kind:
2621 result = PyType_GenericNew(Suite_type, NULL, NULL);
2622 if (!result) goto failed;
2623 value = ast2obj_list(o->v.Suite.body, ast2obj_stmt);
2624 if (!value) goto failed;
2625 if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
2626 goto failed;
2627 Py_DECREF(value);
2628 break;
2629 }
2630 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002631failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002632 Py_XDECREF(value);
2633 Py_XDECREF(result);
2634 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002635}
2636
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002637PyObject*
2638ast2obj_stmt(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002639{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002640 stmt_ty o = (stmt_ty)_o;
2641 PyObject *result = NULL, *value = NULL;
2642 if (!o) {
2643 Py_INCREF(Py_None);
2644 return Py_None;
2645 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002646
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002647 switch (o->kind) {
2648 case FunctionDef_kind:
2649 result = PyType_GenericNew(FunctionDef_type, NULL, NULL);
2650 if (!result) goto failed;
2651 value = ast2obj_identifier(o->v.FunctionDef.name);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002652 if (!value) goto failed;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002653 if (_PyObject_SetAttrId(result, &PyId_name, value) == -1)
2654 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002655 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002656 value = ast2obj_arguments(o->v.FunctionDef.args);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002657 if (!value) goto failed;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002658 if (_PyObject_SetAttrId(result, &PyId_args, value) == -1)
2659 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002660 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002661 value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
2662 if (!value) goto failed;
2663 if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
2664 goto failed;
2665 Py_DECREF(value);
2666 value = ast2obj_list(o->v.FunctionDef.decorator_list, ast2obj_expr);
2667 if (!value) goto failed;
2668 if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1)
2669 goto failed;
2670 Py_DECREF(value);
2671 value = ast2obj_expr(o->v.FunctionDef.returns);
2672 if (!value) goto failed;
2673 if (_PyObject_SetAttrId(result, &PyId_returns, value) == -1)
2674 goto failed;
2675 Py_DECREF(value);
2676 break;
Yury Selivanov75445082015-05-11 22:57:16 -04002677 case AsyncFunctionDef_kind:
2678 result = PyType_GenericNew(AsyncFunctionDef_type, NULL, NULL);
2679 if (!result) goto failed;
2680 value = ast2obj_identifier(o->v.AsyncFunctionDef.name);
2681 if (!value) goto failed;
2682 if (_PyObject_SetAttrId(result, &PyId_name, value) == -1)
2683 goto failed;
2684 Py_DECREF(value);
2685 value = ast2obj_arguments(o->v.AsyncFunctionDef.args);
2686 if (!value) goto failed;
2687 if (_PyObject_SetAttrId(result, &PyId_args, value) == -1)
2688 goto failed;
2689 Py_DECREF(value);
2690 value = ast2obj_list(o->v.AsyncFunctionDef.body, ast2obj_stmt);
2691 if (!value) goto failed;
2692 if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
2693 goto failed;
2694 Py_DECREF(value);
2695 value = ast2obj_list(o->v.AsyncFunctionDef.decorator_list,
2696 ast2obj_expr);
2697 if (!value) goto failed;
2698 if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1)
2699 goto failed;
2700 Py_DECREF(value);
2701 value = ast2obj_expr(o->v.AsyncFunctionDef.returns);
2702 if (!value) goto failed;
2703 if (_PyObject_SetAttrId(result, &PyId_returns, value) == -1)
2704 goto failed;
2705 Py_DECREF(value);
2706 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002707 case ClassDef_kind:
2708 result = PyType_GenericNew(ClassDef_type, NULL, NULL);
2709 if (!result) goto failed;
2710 value = ast2obj_identifier(o->v.ClassDef.name);
2711 if (!value) goto failed;
2712 if (_PyObject_SetAttrId(result, &PyId_name, value) == -1)
2713 goto failed;
2714 Py_DECREF(value);
2715 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
2716 if (!value) goto failed;
2717 if (_PyObject_SetAttrId(result, &PyId_bases, value) == -1)
2718 goto failed;
2719 Py_DECREF(value);
2720 value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword);
2721 if (!value) goto failed;
2722 if (_PyObject_SetAttrId(result, &PyId_keywords, value) == -1)
2723 goto failed;
2724 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002725 value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
2726 if (!value) goto failed;
2727 if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
2728 goto failed;
2729 Py_DECREF(value);
2730 value = ast2obj_list(o->v.ClassDef.decorator_list, ast2obj_expr);
2731 if (!value) goto failed;
2732 if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1)
2733 goto failed;
2734 Py_DECREF(value);
2735 break;
2736 case Return_kind:
2737 result = PyType_GenericNew(Return_type, NULL, NULL);
2738 if (!result) goto failed;
2739 value = ast2obj_expr(o->v.Return.value);
2740 if (!value) goto failed;
2741 if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
2742 goto failed;
2743 Py_DECREF(value);
2744 break;
2745 case Delete_kind:
2746 result = PyType_GenericNew(Delete_type, NULL, NULL);
2747 if (!result) goto failed;
2748 value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
2749 if (!value) goto failed;
2750 if (_PyObject_SetAttrId(result, &PyId_targets, value) == -1)
2751 goto failed;
2752 Py_DECREF(value);
2753 break;
2754 case Assign_kind:
2755 result = PyType_GenericNew(Assign_type, NULL, NULL);
2756 if (!result) goto failed;
2757 value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
2758 if (!value) goto failed;
2759 if (_PyObject_SetAttrId(result, &PyId_targets, value) == -1)
2760 goto failed;
2761 Py_DECREF(value);
2762 value = ast2obj_expr(o->v.Assign.value);
2763 if (!value) goto failed;
2764 if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
2765 goto failed;
2766 Py_DECREF(value);
2767 break;
2768 case AugAssign_kind:
2769 result = PyType_GenericNew(AugAssign_type, NULL, NULL);
2770 if (!result) goto failed;
2771 value = ast2obj_expr(o->v.AugAssign.target);
2772 if (!value) goto failed;
2773 if (_PyObject_SetAttrId(result, &PyId_target, value) == -1)
2774 goto failed;
2775 Py_DECREF(value);
2776 value = ast2obj_operator(o->v.AugAssign.op);
2777 if (!value) goto failed;
2778 if (_PyObject_SetAttrId(result, &PyId_op, value) == -1)
2779 goto failed;
2780 Py_DECREF(value);
2781 value = ast2obj_expr(o->v.AugAssign.value);
2782 if (!value) goto failed;
2783 if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
2784 goto failed;
2785 Py_DECREF(value);
2786 break;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002787 case AnnAssign_kind:
2788 result = PyType_GenericNew(AnnAssign_type, NULL, NULL);
2789 if (!result) goto failed;
2790 value = ast2obj_expr(o->v.AnnAssign.target);
2791 if (!value) goto failed;
2792 if (_PyObject_SetAttrId(result, &PyId_target, value) == -1)
2793 goto failed;
2794 Py_DECREF(value);
2795 value = ast2obj_expr(o->v.AnnAssign.annotation);
2796 if (!value) goto failed;
2797 if (_PyObject_SetAttrId(result, &PyId_annotation, value) == -1)
2798 goto failed;
2799 Py_DECREF(value);
2800 value = ast2obj_expr(o->v.AnnAssign.value);
2801 if (!value) goto failed;
2802 if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
2803 goto failed;
2804 Py_DECREF(value);
2805 value = ast2obj_int(o->v.AnnAssign.simple);
2806 if (!value) goto failed;
2807 if (_PyObject_SetAttrId(result, &PyId_simple, value) == -1)
2808 goto failed;
2809 Py_DECREF(value);
2810 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002811 case For_kind:
2812 result = PyType_GenericNew(For_type, NULL, NULL);
2813 if (!result) goto failed;
2814 value = ast2obj_expr(o->v.For.target);
2815 if (!value) goto failed;
2816 if (_PyObject_SetAttrId(result, &PyId_target, value) == -1)
2817 goto failed;
2818 Py_DECREF(value);
2819 value = ast2obj_expr(o->v.For.iter);
2820 if (!value) goto failed;
2821 if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1)
2822 goto failed;
2823 Py_DECREF(value);
2824 value = ast2obj_list(o->v.For.body, ast2obj_stmt);
2825 if (!value) goto failed;
2826 if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
2827 goto failed;
2828 Py_DECREF(value);
2829 value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
2830 if (!value) goto failed;
2831 if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1)
2832 goto failed;
2833 Py_DECREF(value);
2834 break;
Yury Selivanov75445082015-05-11 22:57:16 -04002835 case AsyncFor_kind:
2836 result = PyType_GenericNew(AsyncFor_type, NULL, NULL);
2837 if (!result) goto failed;
2838 value = ast2obj_expr(o->v.AsyncFor.target);
2839 if (!value) goto failed;
2840 if (_PyObject_SetAttrId(result, &PyId_target, value) == -1)
2841 goto failed;
2842 Py_DECREF(value);
2843 value = ast2obj_expr(o->v.AsyncFor.iter);
2844 if (!value) goto failed;
2845 if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1)
2846 goto failed;
2847 Py_DECREF(value);
2848 value = ast2obj_list(o->v.AsyncFor.body, ast2obj_stmt);
2849 if (!value) goto failed;
2850 if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
2851 goto failed;
2852 Py_DECREF(value);
2853 value = ast2obj_list(o->v.AsyncFor.orelse, ast2obj_stmt);
2854 if (!value) goto failed;
2855 if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1)
2856 goto failed;
2857 Py_DECREF(value);
2858 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002859 case While_kind:
2860 result = PyType_GenericNew(While_type, NULL, NULL);
2861 if (!result) goto failed;
2862 value = ast2obj_expr(o->v.While.test);
2863 if (!value) goto failed;
2864 if (_PyObject_SetAttrId(result, &PyId_test, value) == -1)
2865 goto failed;
2866 Py_DECREF(value);
2867 value = ast2obj_list(o->v.While.body, ast2obj_stmt);
2868 if (!value) goto failed;
2869 if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
2870 goto failed;
2871 Py_DECREF(value);
2872 value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);
2873 if (!value) goto failed;
2874 if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1)
2875 goto failed;
2876 Py_DECREF(value);
2877 break;
2878 case If_kind:
2879 result = PyType_GenericNew(If_type, NULL, NULL);
2880 if (!result) goto failed;
2881 value = ast2obj_expr(o->v.If.test);
2882 if (!value) goto failed;
2883 if (_PyObject_SetAttrId(result, &PyId_test, value) == -1)
2884 goto failed;
2885 Py_DECREF(value);
2886 value = ast2obj_list(o->v.If.body, ast2obj_stmt);
2887 if (!value) goto failed;
2888 if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
2889 goto failed;
2890 Py_DECREF(value);
2891 value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
2892 if (!value) goto failed;
2893 if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1)
2894 goto failed;
2895 Py_DECREF(value);
2896 break;
2897 case With_kind:
2898 result = PyType_GenericNew(With_type, NULL, NULL);
2899 if (!result) goto failed;
2900 value = ast2obj_list(o->v.With.items, ast2obj_withitem);
2901 if (!value) goto failed;
2902 if (_PyObject_SetAttrId(result, &PyId_items, value) == -1)
2903 goto failed;
2904 Py_DECREF(value);
2905 value = ast2obj_list(o->v.With.body, ast2obj_stmt);
2906 if (!value) goto failed;
2907 if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
2908 goto failed;
2909 Py_DECREF(value);
2910 break;
Yury Selivanov75445082015-05-11 22:57:16 -04002911 case AsyncWith_kind:
2912 result = PyType_GenericNew(AsyncWith_type, NULL, NULL);
2913 if (!result) goto failed;
2914 value = ast2obj_list(o->v.AsyncWith.items, ast2obj_withitem);
2915 if (!value) goto failed;
2916 if (_PyObject_SetAttrId(result, &PyId_items, value) == -1)
2917 goto failed;
2918 Py_DECREF(value);
2919 value = ast2obj_list(o->v.AsyncWith.body, ast2obj_stmt);
2920 if (!value) goto failed;
2921 if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
2922 goto failed;
2923 Py_DECREF(value);
2924 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002925 case Raise_kind:
2926 result = PyType_GenericNew(Raise_type, NULL, NULL);
2927 if (!result) goto failed;
2928 value = ast2obj_expr(o->v.Raise.exc);
2929 if (!value) goto failed;
2930 if (_PyObject_SetAttrId(result, &PyId_exc, value) == -1)
2931 goto failed;
2932 Py_DECREF(value);
2933 value = ast2obj_expr(o->v.Raise.cause);
2934 if (!value) goto failed;
2935 if (_PyObject_SetAttrId(result, &PyId_cause, value) == -1)
2936 goto failed;
2937 Py_DECREF(value);
2938 break;
2939 case Try_kind:
2940 result = PyType_GenericNew(Try_type, NULL, NULL);
2941 if (!result) goto failed;
2942 value = ast2obj_list(o->v.Try.body, ast2obj_stmt);
2943 if (!value) goto failed;
2944 if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
2945 goto failed;
2946 Py_DECREF(value);
2947 value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler);
2948 if (!value) goto failed;
2949 if (_PyObject_SetAttrId(result, &PyId_handlers, value) == -1)
2950 goto failed;
2951 Py_DECREF(value);
2952 value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt);
2953 if (!value) goto failed;
2954 if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1)
2955 goto failed;
2956 Py_DECREF(value);
2957 value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt);
2958 if (!value) goto failed;
2959 if (_PyObject_SetAttrId(result, &PyId_finalbody, value) == -1)
2960 goto failed;
2961 Py_DECREF(value);
2962 break;
2963 case Assert_kind:
2964 result = PyType_GenericNew(Assert_type, NULL, NULL);
2965 if (!result) goto failed;
2966 value = ast2obj_expr(o->v.Assert.test);
2967 if (!value) goto failed;
2968 if (_PyObject_SetAttrId(result, &PyId_test, value) == -1)
2969 goto failed;
2970 Py_DECREF(value);
2971 value = ast2obj_expr(o->v.Assert.msg);
2972 if (!value) goto failed;
2973 if (_PyObject_SetAttrId(result, &PyId_msg, value) == -1)
2974 goto failed;
2975 Py_DECREF(value);
2976 break;
2977 case Import_kind:
2978 result = PyType_GenericNew(Import_type, NULL, NULL);
2979 if (!result) goto failed;
2980 value = ast2obj_list(o->v.Import.names, ast2obj_alias);
2981 if (!value) goto failed;
2982 if (_PyObject_SetAttrId(result, &PyId_names, value) == -1)
2983 goto failed;
2984 Py_DECREF(value);
2985 break;
2986 case ImportFrom_kind:
2987 result = PyType_GenericNew(ImportFrom_type, NULL, NULL);
2988 if (!result) goto failed;
2989 value = ast2obj_identifier(o->v.ImportFrom.module);
2990 if (!value) goto failed;
2991 if (_PyObject_SetAttrId(result, &PyId_module, value) == -1)
2992 goto failed;
2993 Py_DECREF(value);
2994 value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
2995 if (!value) goto failed;
2996 if (_PyObject_SetAttrId(result, &PyId_names, value) == -1)
2997 goto failed;
2998 Py_DECREF(value);
2999 value = ast2obj_int(o->v.ImportFrom.level);
3000 if (!value) goto failed;
3001 if (_PyObject_SetAttrId(result, &PyId_level, value) == -1)
3002 goto failed;
3003 Py_DECREF(value);
3004 break;
3005 case Global_kind:
3006 result = PyType_GenericNew(Global_type, NULL, NULL);
3007 if (!result) goto failed;
3008 value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
3009 if (!value) goto failed;
3010 if (_PyObject_SetAttrId(result, &PyId_names, value) == -1)
3011 goto failed;
3012 Py_DECREF(value);
3013 break;
3014 case Nonlocal_kind:
3015 result = PyType_GenericNew(Nonlocal_type, NULL, NULL);
3016 if (!result) goto failed;
3017 value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier);
3018 if (!value) goto failed;
3019 if (_PyObject_SetAttrId(result, &PyId_names, value) == -1)
3020 goto failed;
3021 Py_DECREF(value);
3022 break;
3023 case Expr_kind:
3024 result = PyType_GenericNew(Expr_type, NULL, NULL);
3025 if (!result) goto failed;
3026 value = ast2obj_expr(o->v.Expr.value);
3027 if (!value) goto failed;
3028 if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
3029 goto failed;
3030 Py_DECREF(value);
3031 break;
3032 case Pass_kind:
3033 result = PyType_GenericNew(Pass_type, NULL, NULL);
3034 if (!result) goto failed;
3035 break;
3036 case Break_kind:
3037 result = PyType_GenericNew(Break_type, NULL, NULL);
3038 if (!result) goto failed;
3039 break;
3040 case Continue_kind:
3041 result = PyType_GenericNew(Continue_type, NULL, NULL);
3042 if (!result) goto failed;
3043 break;
3044 }
3045 value = ast2obj_int(o->lineno);
3046 if (!value) goto failed;
3047 if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0)
3048 goto failed;
3049 Py_DECREF(value);
3050 value = ast2obj_int(o->col_offset);
3051 if (!value) goto failed;
3052 if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0)
3053 goto failed;
3054 Py_DECREF(value);
3055 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003056failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003057 Py_XDECREF(value);
3058 Py_XDECREF(result);
3059 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003060}
3061
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003062PyObject*
3063ast2obj_expr(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003064{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003065 expr_ty o = (expr_ty)_o;
3066 PyObject *result = NULL, *value = NULL;
3067 if (!o) {
3068 Py_INCREF(Py_None);
3069 return Py_None;
3070 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003071
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003072 switch (o->kind) {
3073 case BoolOp_kind:
3074 result = PyType_GenericNew(BoolOp_type, NULL, NULL);
3075 if (!result) goto failed;
3076 value = ast2obj_boolop(o->v.BoolOp.op);
3077 if (!value) goto failed;
3078 if (_PyObject_SetAttrId(result, &PyId_op, value) == -1)
3079 goto failed;
3080 Py_DECREF(value);
3081 value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
3082 if (!value) goto failed;
3083 if (_PyObject_SetAttrId(result, &PyId_values, value) == -1)
3084 goto failed;
3085 Py_DECREF(value);
3086 break;
3087 case BinOp_kind:
3088 result = PyType_GenericNew(BinOp_type, NULL, NULL);
3089 if (!result) goto failed;
3090 value = ast2obj_expr(o->v.BinOp.left);
3091 if (!value) goto failed;
3092 if (_PyObject_SetAttrId(result, &PyId_left, value) == -1)
3093 goto failed;
3094 Py_DECREF(value);
3095 value = ast2obj_operator(o->v.BinOp.op);
3096 if (!value) goto failed;
3097 if (_PyObject_SetAttrId(result, &PyId_op, value) == -1)
3098 goto failed;
3099 Py_DECREF(value);
3100 value = ast2obj_expr(o->v.BinOp.right);
3101 if (!value) goto failed;
3102 if (_PyObject_SetAttrId(result, &PyId_right, value) == -1)
3103 goto failed;
3104 Py_DECREF(value);
3105 break;
3106 case UnaryOp_kind:
3107 result = PyType_GenericNew(UnaryOp_type, NULL, NULL);
3108 if (!result) goto failed;
3109 value = ast2obj_unaryop(o->v.UnaryOp.op);
3110 if (!value) goto failed;
3111 if (_PyObject_SetAttrId(result, &PyId_op, value) == -1)
3112 goto failed;
3113 Py_DECREF(value);
3114 value = ast2obj_expr(o->v.UnaryOp.operand);
3115 if (!value) goto failed;
3116 if (_PyObject_SetAttrId(result, &PyId_operand, value) == -1)
3117 goto failed;
3118 Py_DECREF(value);
3119 break;
3120 case Lambda_kind:
3121 result = PyType_GenericNew(Lambda_type, NULL, NULL);
3122 if (!result) goto failed;
3123 value = ast2obj_arguments(o->v.Lambda.args);
3124 if (!value) goto failed;
3125 if (_PyObject_SetAttrId(result, &PyId_args, value) == -1)
3126 goto failed;
3127 Py_DECREF(value);
3128 value = ast2obj_expr(o->v.Lambda.body);
3129 if (!value) goto failed;
3130 if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
3131 goto failed;
3132 Py_DECREF(value);
3133 break;
3134 case IfExp_kind:
3135 result = PyType_GenericNew(IfExp_type, NULL, NULL);
3136 if (!result) goto failed;
3137 value = ast2obj_expr(o->v.IfExp.test);
3138 if (!value) goto failed;
3139 if (_PyObject_SetAttrId(result, &PyId_test, value) == -1)
3140 goto failed;
3141 Py_DECREF(value);
3142 value = ast2obj_expr(o->v.IfExp.body);
3143 if (!value) goto failed;
3144 if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
3145 goto failed;
3146 Py_DECREF(value);
3147 value = ast2obj_expr(o->v.IfExp.orelse);
3148 if (!value) goto failed;
3149 if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1)
3150 goto failed;
3151 Py_DECREF(value);
3152 break;
3153 case Dict_kind:
3154 result = PyType_GenericNew(Dict_type, NULL, NULL);
3155 if (!result) goto failed;
3156 value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
3157 if (!value) goto failed;
3158 if (_PyObject_SetAttrId(result, &PyId_keys, value) == -1)
3159 goto failed;
3160 Py_DECREF(value);
3161 value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
3162 if (!value) goto failed;
3163 if (_PyObject_SetAttrId(result, &PyId_values, value) == -1)
3164 goto failed;
3165 Py_DECREF(value);
3166 break;
3167 case Set_kind:
3168 result = PyType_GenericNew(Set_type, NULL, NULL);
3169 if (!result) goto failed;
3170 value = ast2obj_list(o->v.Set.elts, ast2obj_expr);
3171 if (!value) goto failed;
3172 if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1)
3173 goto failed;
3174 Py_DECREF(value);
3175 break;
3176 case ListComp_kind:
3177 result = PyType_GenericNew(ListComp_type, NULL, NULL);
3178 if (!result) goto failed;
3179 value = ast2obj_expr(o->v.ListComp.elt);
3180 if (!value) goto failed;
3181 if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1)
3182 goto failed;
3183 Py_DECREF(value);
3184 value = ast2obj_list(o->v.ListComp.generators, ast2obj_comprehension);
3185 if (!value) goto failed;
3186 if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1)
3187 goto failed;
3188 Py_DECREF(value);
3189 break;
3190 case SetComp_kind:
3191 result = PyType_GenericNew(SetComp_type, NULL, NULL);
3192 if (!result) goto failed;
3193 value = ast2obj_expr(o->v.SetComp.elt);
3194 if (!value) goto failed;
3195 if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1)
3196 goto failed;
3197 Py_DECREF(value);
3198 value = ast2obj_list(o->v.SetComp.generators, ast2obj_comprehension);
3199 if (!value) goto failed;
3200 if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1)
3201 goto failed;
3202 Py_DECREF(value);
3203 break;
3204 case DictComp_kind:
3205 result = PyType_GenericNew(DictComp_type, NULL, NULL);
3206 if (!result) goto failed;
3207 value = ast2obj_expr(o->v.DictComp.key);
3208 if (!value) goto failed;
3209 if (_PyObject_SetAttrId(result, &PyId_key, value) == -1)
3210 goto failed;
3211 Py_DECREF(value);
3212 value = ast2obj_expr(o->v.DictComp.value);
3213 if (!value) goto failed;
3214 if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
3215 goto failed;
3216 Py_DECREF(value);
3217 value = ast2obj_list(o->v.DictComp.generators, ast2obj_comprehension);
3218 if (!value) goto failed;
3219 if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1)
3220 goto failed;
3221 Py_DECREF(value);
3222 break;
3223 case GeneratorExp_kind:
3224 result = PyType_GenericNew(GeneratorExp_type, NULL, NULL);
3225 if (!result) goto failed;
3226 value = ast2obj_expr(o->v.GeneratorExp.elt);
3227 if (!value) goto failed;
3228 if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1)
3229 goto failed;
3230 Py_DECREF(value);
3231 value = ast2obj_list(o->v.GeneratorExp.generators,
3232 ast2obj_comprehension);
3233 if (!value) goto failed;
3234 if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1)
3235 goto failed;
3236 Py_DECREF(value);
3237 break;
Yury Selivanov75445082015-05-11 22:57:16 -04003238 case Await_kind:
3239 result = PyType_GenericNew(Await_type, NULL, NULL);
3240 if (!result) goto failed;
3241 value = ast2obj_expr(o->v.Await.value);
3242 if (!value) goto failed;
3243 if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
3244 goto failed;
3245 Py_DECREF(value);
3246 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003247 case Yield_kind:
3248 result = PyType_GenericNew(Yield_type, NULL, NULL);
3249 if (!result) goto failed;
3250 value = ast2obj_expr(o->v.Yield.value);
3251 if (!value) goto failed;
3252 if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
3253 goto failed;
3254 Py_DECREF(value);
3255 break;
3256 case YieldFrom_kind:
3257 result = PyType_GenericNew(YieldFrom_type, NULL, NULL);
3258 if (!result) goto failed;
3259 value = ast2obj_expr(o->v.YieldFrom.value);
3260 if (!value) goto failed;
3261 if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
3262 goto failed;
3263 Py_DECREF(value);
3264 break;
3265 case Compare_kind:
3266 result = PyType_GenericNew(Compare_type, NULL, NULL);
3267 if (!result) goto failed;
3268 value = ast2obj_expr(o->v.Compare.left);
3269 if (!value) goto failed;
3270 if (_PyObject_SetAttrId(result, &PyId_left, value) == -1)
3271 goto failed;
3272 Py_DECREF(value);
3273 {
3274 Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops);
3275 value = PyList_New(n);
3276 if (!value) goto failed;
3277 for(i = 0; i < n; i++)
3278 PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003279 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003280 if (!value) goto failed;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003281 if (_PyObject_SetAttrId(result, &PyId_ops, value) == -1)
3282 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00003283 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003284 value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00003285 if (!value) goto failed;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003286 if (_PyObject_SetAttrId(result, &PyId_comparators, value) == -1)
3287 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00003288 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003289 break;
3290 case Call_kind:
3291 result = PyType_GenericNew(Call_type, NULL, NULL);
3292 if (!result) goto failed;
3293 value = ast2obj_expr(o->v.Call.func);
3294 if (!value) goto failed;
3295 if (_PyObject_SetAttrId(result, &PyId_func, value) == -1)
3296 goto failed;
3297 Py_DECREF(value);
3298 value = ast2obj_list(o->v.Call.args, ast2obj_expr);
3299 if (!value) goto failed;
3300 if (_PyObject_SetAttrId(result, &PyId_args, value) == -1)
3301 goto failed;
3302 Py_DECREF(value);
3303 value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
3304 if (!value) goto failed;
3305 if (_PyObject_SetAttrId(result, &PyId_keywords, value) == -1)
3306 goto failed;
3307 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003308 break;
3309 case Num_kind:
3310 result = PyType_GenericNew(Num_type, NULL, NULL);
3311 if (!result) goto failed;
3312 value = ast2obj_object(o->v.Num.n);
3313 if (!value) goto failed;
3314 if (_PyObject_SetAttrId(result, &PyId_n, value) == -1)
3315 goto failed;
3316 Py_DECREF(value);
3317 break;
3318 case Str_kind:
3319 result = PyType_GenericNew(Str_type, NULL, NULL);
3320 if (!result) goto failed;
3321 value = ast2obj_string(o->v.Str.s);
3322 if (!value) goto failed;
3323 if (_PyObject_SetAttrId(result, &PyId_s, value) == -1)
3324 goto failed;
3325 Py_DECREF(value);
3326 break;
Eric V. Smith235a6f02015-09-19 14:51:32 -04003327 case FormattedValue_kind:
3328 result = PyType_GenericNew(FormattedValue_type, NULL, NULL);
3329 if (!result) goto failed;
3330 value = ast2obj_expr(o->v.FormattedValue.value);
3331 if (!value) goto failed;
3332 if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
3333 goto failed;
3334 Py_DECREF(value);
3335 value = ast2obj_int(o->v.FormattedValue.conversion);
3336 if (!value) goto failed;
3337 if (_PyObject_SetAttrId(result, &PyId_conversion, value) == -1)
3338 goto failed;
3339 Py_DECREF(value);
3340 value = ast2obj_expr(o->v.FormattedValue.format_spec);
3341 if (!value) goto failed;
3342 if (_PyObject_SetAttrId(result, &PyId_format_spec, value) == -1)
3343 goto failed;
3344 Py_DECREF(value);
3345 break;
3346 case JoinedStr_kind:
3347 result = PyType_GenericNew(JoinedStr_type, NULL, NULL);
3348 if (!result) goto failed;
3349 value = ast2obj_list(o->v.JoinedStr.values, ast2obj_expr);
3350 if (!value) goto failed;
3351 if (_PyObject_SetAttrId(result, &PyId_values, value) == -1)
3352 goto failed;
3353 Py_DECREF(value);
3354 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003355 case Bytes_kind:
3356 result = PyType_GenericNew(Bytes_type, NULL, NULL);
3357 if (!result) goto failed;
3358 value = ast2obj_bytes(o->v.Bytes.s);
3359 if (!value) goto failed;
3360 if (_PyObject_SetAttrId(result, &PyId_s, value) == -1)
3361 goto failed;
3362 Py_DECREF(value);
3363 break;
Victor Stinneree4b59c2013-07-27 00:01:35 +02003364 case NameConstant_kind:
3365 result = PyType_GenericNew(NameConstant_type, NULL, NULL);
3366 if (!result) goto failed;
3367 value = ast2obj_singleton(o->v.NameConstant.value);
3368 if (!value) goto failed;
3369 if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
3370 goto failed;
3371 Py_DECREF(value);
3372 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003373 case Ellipsis_kind:
3374 result = PyType_GenericNew(Ellipsis_type, NULL, NULL);
3375 if (!result) goto failed;
3376 break;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01003377 case Constant_kind:
3378 result = PyType_GenericNew(Constant_type, NULL, NULL);
3379 if (!result) goto failed;
3380 value = ast2obj_constant(o->v.Constant.value);
3381 if (!value) goto failed;
3382 if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
3383 goto failed;
3384 Py_DECREF(value);
3385 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003386 case Attribute_kind:
3387 result = PyType_GenericNew(Attribute_type, NULL, NULL);
3388 if (!result) goto failed;
3389 value = ast2obj_expr(o->v.Attribute.value);
3390 if (!value) goto failed;
3391 if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
3392 goto failed;
3393 Py_DECREF(value);
3394 value = ast2obj_identifier(o->v.Attribute.attr);
3395 if (!value) goto failed;
3396 if (_PyObject_SetAttrId(result, &PyId_attr, value) == -1)
3397 goto failed;
3398 Py_DECREF(value);
3399 value = ast2obj_expr_context(o->v.Attribute.ctx);
3400 if (!value) goto failed;
3401 if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1)
3402 goto failed;
3403 Py_DECREF(value);
3404 break;
3405 case Subscript_kind:
3406 result = PyType_GenericNew(Subscript_type, NULL, NULL);
3407 if (!result) goto failed;
3408 value = ast2obj_expr(o->v.Subscript.value);
3409 if (!value) goto failed;
3410 if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
3411 goto failed;
3412 Py_DECREF(value);
3413 value = ast2obj_slice(o->v.Subscript.slice);
3414 if (!value) goto failed;
3415 if (_PyObject_SetAttrId(result, &PyId_slice, value) == -1)
3416 goto failed;
3417 Py_DECREF(value);
3418 value = ast2obj_expr_context(o->v.Subscript.ctx);
3419 if (!value) goto failed;
3420 if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1)
3421 goto failed;
3422 Py_DECREF(value);
3423 break;
3424 case Starred_kind:
3425 result = PyType_GenericNew(Starred_type, NULL, NULL);
3426 if (!result) goto failed;
3427 value = ast2obj_expr(o->v.Starred.value);
3428 if (!value) goto failed;
3429 if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
3430 goto failed;
3431 Py_DECREF(value);
3432 value = ast2obj_expr_context(o->v.Starred.ctx);
3433 if (!value) goto failed;
3434 if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1)
3435 goto failed;
3436 Py_DECREF(value);
3437 break;
3438 case Name_kind:
3439 result = PyType_GenericNew(Name_type, NULL, NULL);
3440 if (!result) goto failed;
3441 value = ast2obj_identifier(o->v.Name.id);
3442 if (!value) goto failed;
3443 if (_PyObject_SetAttrId(result, &PyId_id, value) == -1)
3444 goto failed;
3445 Py_DECREF(value);
3446 value = ast2obj_expr_context(o->v.Name.ctx);
3447 if (!value) goto failed;
3448 if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1)
3449 goto failed;
3450 Py_DECREF(value);
3451 break;
3452 case List_kind:
3453 result = PyType_GenericNew(List_type, NULL, NULL);
3454 if (!result) goto failed;
3455 value = ast2obj_list(o->v.List.elts, ast2obj_expr);
3456 if (!value) goto failed;
3457 if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1)
3458 goto failed;
3459 Py_DECREF(value);
3460 value = ast2obj_expr_context(o->v.List.ctx);
3461 if (!value) goto failed;
3462 if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1)
3463 goto failed;
3464 Py_DECREF(value);
3465 break;
3466 case Tuple_kind:
3467 result = PyType_GenericNew(Tuple_type, NULL, NULL);
3468 if (!result) goto failed;
3469 value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
3470 if (!value) goto failed;
3471 if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1)
3472 goto failed;
3473 Py_DECREF(value);
3474 value = ast2obj_expr_context(o->v.Tuple.ctx);
3475 if (!value) goto failed;
3476 if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1)
3477 goto failed;
3478 Py_DECREF(value);
3479 break;
3480 }
3481 value = ast2obj_int(o->lineno);
3482 if (!value) goto failed;
3483 if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0)
3484 goto failed;
3485 Py_DECREF(value);
3486 value = ast2obj_int(o->col_offset);
3487 if (!value) goto failed;
3488 if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0)
3489 goto failed;
3490 Py_DECREF(value);
3491 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003492failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003493 Py_XDECREF(value);
3494 Py_XDECREF(result);
3495 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003496}
3497
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003498PyObject* ast2obj_expr_context(expr_context_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003499{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003500 switch(o) {
3501 case Load:
3502 Py_INCREF(Load_singleton);
3503 return Load_singleton;
3504 case Store:
3505 Py_INCREF(Store_singleton);
3506 return Store_singleton;
3507 case Del:
3508 Py_INCREF(Del_singleton);
3509 return Del_singleton;
3510 case AugLoad:
3511 Py_INCREF(AugLoad_singleton);
3512 return AugLoad_singleton;
3513 case AugStore:
3514 Py_INCREF(AugStore_singleton);
3515 return AugStore_singleton;
3516 case Param:
3517 Py_INCREF(Param_singleton);
3518 return Param_singleton;
3519 default:
3520 /* should never happen, but just in case ... */
3521 PyErr_Format(PyExc_SystemError, "unknown expr_context found");
3522 return NULL;
3523 }
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003524}
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003525PyObject*
3526ast2obj_slice(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003527{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003528 slice_ty o = (slice_ty)_o;
3529 PyObject *result = NULL, *value = NULL;
3530 if (!o) {
3531 Py_INCREF(Py_None);
3532 return Py_None;
3533 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003534
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003535 switch (o->kind) {
3536 case Slice_kind:
3537 result = PyType_GenericNew(Slice_type, NULL, NULL);
3538 if (!result) goto failed;
3539 value = ast2obj_expr(o->v.Slice.lower);
3540 if (!value) goto failed;
3541 if (_PyObject_SetAttrId(result, &PyId_lower, value) == -1)
3542 goto failed;
3543 Py_DECREF(value);
3544 value = ast2obj_expr(o->v.Slice.upper);
3545 if (!value) goto failed;
3546 if (_PyObject_SetAttrId(result, &PyId_upper, value) == -1)
3547 goto failed;
3548 Py_DECREF(value);
3549 value = ast2obj_expr(o->v.Slice.step);
3550 if (!value) goto failed;
3551 if (_PyObject_SetAttrId(result, &PyId_step, value) == -1)
3552 goto failed;
3553 Py_DECREF(value);
3554 break;
3555 case ExtSlice_kind:
3556 result = PyType_GenericNew(ExtSlice_type, NULL, NULL);
3557 if (!result) goto failed;
3558 value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice);
3559 if (!value) goto failed;
3560 if (_PyObject_SetAttrId(result, &PyId_dims, value) == -1)
3561 goto failed;
3562 Py_DECREF(value);
3563 break;
3564 case Index_kind:
3565 result = PyType_GenericNew(Index_type, NULL, NULL);
3566 if (!result) goto failed;
3567 value = ast2obj_expr(o->v.Index.value);
3568 if (!value) goto failed;
3569 if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
3570 goto failed;
3571 Py_DECREF(value);
3572 break;
3573 }
3574 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003575failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003576 Py_XDECREF(value);
3577 Py_XDECREF(result);
3578 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003579}
3580
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003581PyObject* ast2obj_boolop(boolop_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003582{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003583 switch(o) {
3584 case And:
3585 Py_INCREF(And_singleton);
3586 return And_singleton;
3587 case Or:
3588 Py_INCREF(Or_singleton);
3589 return Or_singleton;
3590 default:
3591 /* should never happen, but just in case ... */
3592 PyErr_Format(PyExc_SystemError, "unknown boolop found");
3593 return NULL;
3594 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003595}
3596PyObject* ast2obj_operator(operator_ty o)
3597{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003598 switch(o) {
3599 case Add:
3600 Py_INCREF(Add_singleton);
3601 return Add_singleton;
3602 case Sub:
3603 Py_INCREF(Sub_singleton);
3604 return Sub_singleton;
3605 case Mult:
3606 Py_INCREF(Mult_singleton);
3607 return Mult_singleton;
Benjamin Petersond51374e2014-04-09 23:55:56 -04003608 case MatMult:
3609 Py_INCREF(MatMult_singleton);
3610 return MatMult_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003611 case Div:
3612 Py_INCREF(Div_singleton);
3613 return Div_singleton;
3614 case Mod:
3615 Py_INCREF(Mod_singleton);
3616 return Mod_singleton;
3617 case Pow:
3618 Py_INCREF(Pow_singleton);
3619 return Pow_singleton;
3620 case LShift:
3621 Py_INCREF(LShift_singleton);
3622 return LShift_singleton;
3623 case RShift:
3624 Py_INCREF(RShift_singleton);
3625 return RShift_singleton;
3626 case BitOr:
3627 Py_INCREF(BitOr_singleton);
3628 return BitOr_singleton;
3629 case BitXor:
3630 Py_INCREF(BitXor_singleton);
3631 return BitXor_singleton;
3632 case BitAnd:
3633 Py_INCREF(BitAnd_singleton);
3634 return BitAnd_singleton;
3635 case FloorDiv:
3636 Py_INCREF(FloorDiv_singleton);
3637 return FloorDiv_singleton;
3638 default:
3639 /* should never happen, but just in case ... */
3640 PyErr_Format(PyExc_SystemError, "unknown operator found");
3641 return NULL;
3642 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003643}
3644PyObject* ast2obj_unaryop(unaryop_ty o)
3645{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003646 switch(o) {
3647 case Invert:
3648 Py_INCREF(Invert_singleton);
3649 return Invert_singleton;
3650 case Not:
3651 Py_INCREF(Not_singleton);
3652 return Not_singleton;
3653 case UAdd:
3654 Py_INCREF(UAdd_singleton);
3655 return UAdd_singleton;
3656 case USub:
3657 Py_INCREF(USub_singleton);
3658 return USub_singleton;
3659 default:
3660 /* should never happen, but just in case ... */
3661 PyErr_Format(PyExc_SystemError, "unknown unaryop found");
3662 return NULL;
3663 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003664}
3665PyObject* ast2obj_cmpop(cmpop_ty o)
3666{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003667 switch(o) {
3668 case Eq:
3669 Py_INCREF(Eq_singleton);
3670 return Eq_singleton;
3671 case NotEq:
3672 Py_INCREF(NotEq_singleton);
3673 return NotEq_singleton;
3674 case Lt:
3675 Py_INCREF(Lt_singleton);
3676 return Lt_singleton;
3677 case LtE:
3678 Py_INCREF(LtE_singleton);
3679 return LtE_singleton;
3680 case Gt:
3681 Py_INCREF(Gt_singleton);
3682 return Gt_singleton;
3683 case GtE:
3684 Py_INCREF(GtE_singleton);
3685 return GtE_singleton;
3686 case Is:
3687 Py_INCREF(Is_singleton);
3688 return Is_singleton;
3689 case IsNot:
3690 Py_INCREF(IsNot_singleton);
3691 return IsNot_singleton;
3692 case In:
3693 Py_INCREF(In_singleton);
3694 return In_singleton;
3695 case NotIn:
3696 Py_INCREF(NotIn_singleton);
3697 return NotIn_singleton;
3698 default:
3699 /* should never happen, but just in case ... */
3700 PyErr_Format(PyExc_SystemError, "unknown cmpop found");
3701 return NULL;
3702 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003703}
3704PyObject*
3705ast2obj_comprehension(void* _o)
3706{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003707 comprehension_ty o = (comprehension_ty)_o;
3708 PyObject *result = NULL, *value = NULL;
3709 if (!o) {
3710 Py_INCREF(Py_None);
3711 return Py_None;
3712 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003713
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003714 result = PyType_GenericNew(comprehension_type, NULL, NULL);
3715 if (!result) return NULL;
3716 value = ast2obj_expr(o->target);
3717 if (!value) goto failed;
3718 if (_PyObject_SetAttrId(result, &PyId_target, value) == -1)
3719 goto failed;
3720 Py_DECREF(value);
3721 value = ast2obj_expr(o->iter);
3722 if (!value) goto failed;
3723 if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1)
3724 goto failed;
3725 Py_DECREF(value);
3726 value = ast2obj_list(o->ifs, ast2obj_expr);
3727 if (!value) goto failed;
3728 if (_PyObject_SetAttrId(result, &PyId_ifs, value) == -1)
3729 goto failed;
3730 Py_DECREF(value);
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07003731 value = ast2obj_int(o->is_async);
3732 if (!value) goto failed;
3733 if (_PyObject_SetAttrId(result, &PyId_is_async, value) == -1)
3734 goto failed;
3735 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003736 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003737failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003738 Py_XDECREF(value);
3739 Py_XDECREF(result);
3740 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003741}
3742
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003743PyObject*
3744ast2obj_excepthandler(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003745{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003746 excepthandler_ty o = (excepthandler_ty)_o;
3747 PyObject *result = NULL, *value = NULL;
3748 if (!o) {
3749 Py_INCREF(Py_None);
3750 return Py_None;
3751 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003752
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003753 switch (o->kind) {
3754 case ExceptHandler_kind:
3755 result = PyType_GenericNew(ExceptHandler_type, NULL, NULL);
3756 if (!result) goto failed;
3757 value = ast2obj_expr(o->v.ExceptHandler.type);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003758 if (!value) goto failed;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003759 if (_PyObject_SetAttrId(result, &PyId_type, value) == -1)
3760 goto failed;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003761 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003762 value = ast2obj_identifier(o->v.ExceptHandler.name);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003763 if (!value) goto failed;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003764 if (_PyObject_SetAttrId(result, &PyId_name, value) == -1)
3765 goto failed;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003766 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003767 value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt);
3768 if (!value) goto failed;
3769 if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
3770 goto failed;
3771 Py_DECREF(value);
3772 break;
3773 }
3774 value = ast2obj_int(o->lineno);
3775 if (!value) goto failed;
3776 if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0)
3777 goto failed;
3778 Py_DECREF(value);
3779 value = ast2obj_int(o->col_offset);
3780 if (!value) goto failed;
3781 if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0)
3782 goto failed;
3783 Py_DECREF(value);
3784 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003785failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003786 Py_XDECREF(value);
3787 Py_XDECREF(result);
3788 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003789}
3790
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003791PyObject*
3792ast2obj_arguments(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003793{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003794 arguments_ty o = (arguments_ty)_o;
3795 PyObject *result = NULL, *value = NULL;
3796 if (!o) {
3797 Py_INCREF(Py_None);
3798 return Py_None;
3799 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003800
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003801 result = PyType_GenericNew(arguments_type, NULL, NULL);
3802 if (!result) return NULL;
3803 value = ast2obj_list(o->args, ast2obj_arg);
3804 if (!value) goto failed;
3805 if (_PyObject_SetAttrId(result, &PyId_args, value) == -1)
3806 goto failed;
3807 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02003808 value = ast2obj_arg(o->vararg);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003809 if (!value) goto failed;
3810 if (_PyObject_SetAttrId(result, &PyId_vararg, value) == -1)
3811 goto failed;
3812 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003813 value = ast2obj_list(o->kwonlyargs, ast2obj_arg);
3814 if (!value) goto failed;
3815 if (_PyObject_SetAttrId(result, &PyId_kwonlyargs, value) == -1)
3816 goto failed;
3817 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02003818 value = ast2obj_list(o->kw_defaults, ast2obj_expr);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003819 if (!value) goto failed;
Victor Stinneree4b59c2013-07-27 00:01:35 +02003820 if (_PyObject_SetAttrId(result, &PyId_kw_defaults, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003821 goto failed;
3822 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02003823 value = ast2obj_arg(o->kwarg);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003824 if (!value) goto failed;
Victor Stinneree4b59c2013-07-27 00:01:35 +02003825 if (_PyObject_SetAttrId(result, &PyId_kwarg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003826 goto failed;
3827 Py_DECREF(value);
3828 value = ast2obj_list(o->defaults, ast2obj_expr);
3829 if (!value) goto failed;
3830 if (_PyObject_SetAttrId(result, &PyId_defaults, value) == -1)
3831 goto failed;
3832 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003833 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003834failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003835 Py_XDECREF(value);
3836 Py_XDECREF(result);
3837 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003838}
3839
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003840PyObject*
Neal Norwitzc1505362006-12-28 06:47:50 +00003841ast2obj_arg(void* _o)
3842{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003843 arg_ty o = (arg_ty)_o;
3844 PyObject *result = NULL, *value = NULL;
3845 if (!o) {
3846 Py_INCREF(Py_None);
3847 return Py_None;
3848 }
Neal Norwitzc1505362006-12-28 06:47:50 +00003849
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003850 result = PyType_GenericNew(arg_type, NULL, NULL);
3851 if (!result) return NULL;
3852 value = ast2obj_identifier(o->arg);
3853 if (!value) goto failed;
3854 if (_PyObject_SetAttrId(result, &PyId_arg, value) == -1)
3855 goto failed;
3856 Py_DECREF(value);
3857 value = ast2obj_expr(o->annotation);
3858 if (!value) goto failed;
3859 if (_PyObject_SetAttrId(result, &PyId_annotation, value) == -1)
3860 goto failed;
3861 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02003862 value = ast2obj_int(o->lineno);
3863 if (!value) goto failed;
3864 if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0)
3865 goto failed;
3866 Py_DECREF(value);
3867 value = ast2obj_int(o->col_offset);
3868 if (!value) goto failed;
3869 if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0)
3870 goto failed;
3871 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003872 return result;
Neal Norwitzc1505362006-12-28 06:47:50 +00003873failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003874 Py_XDECREF(value);
3875 Py_XDECREF(result);
3876 return NULL;
Neal Norwitzc1505362006-12-28 06:47:50 +00003877}
3878
3879PyObject*
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003880ast2obj_keyword(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003881{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003882 keyword_ty o = (keyword_ty)_o;
3883 PyObject *result = NULL, *value = NULL;
3884 if (!o) {
3885 Py_INCREF(Py_None);
3886 return Py_None;
3887 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003888
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003889 result = PyType_GenericNew(keyword_type, NULL, NULL);
3890 if (!result) return NULL;
3891 value = ast2obj_identifier(o->arg);
3892 if (!value) goto failed;
3893 if (_PyObject_SetAttrId(result, &PyId_arg, value) == -1)
3894 goto failed;
3895 Py_DECREF(value);
3896 value = ast2obj_expr(o->value);
3897 if (!value) goto failed;
3898 if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
3899 goto failed;
3900 Py_DECREF(value);
3901 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003902failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003903 Py_XDECREF(value);
3904 Py_XDECREF(result);
3905 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003906}
3907
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003908PyObject*
3909ast2obj_alias(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003910{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003911 alias_ty o = (alias_ty)_o;
3912 PyObject *result = NULL, *value = NULL;
3913 if (!o) {
3914 Py_INCREF(Py_None);
3915 return Py_None;
3916 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003917
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003918 result = PyType_GenericNew(alias_type, NULL, NULL);
3919 if (!result) return NULL;
3920 value = ast2obj_identifier(o->name);
3921 if (!value) goto failed;
3922 if (_PyObject_SetAttrId(result, &PyId_name, value) == -1)
3923 goto failed;
3924 Py_DECREF(value);
3925 value = ast2obj_identifier(o->asname);
3926 if (!value) goto failed;
3927 if (_PyObject_SetAttrId(result, &PyId_asname, value) == -1)
3928 goto failed;
3929 Py_DECREF(value);
3930 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003931failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003932 Py_XDECREF(value);
3933 Py_XDECREF(result);
3934 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003935}
3936
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05003937PyObject*
3938ast2obj_withitem(void* _o)
3939{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003940 withitem_ty o = (withitem_ty)_o;
3941 PyObject *result = NULL, *value = NULL;
3942 if (!o) {
3943 Py_INCREF(Py_None);
3944 return Py_None;
3945 }
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05003946
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003947 result = PyType_GenericNew(withitem_type, NULL, NULL);
3948 if (!result) return NULL;
3949 value = ast2obj_expr(o->context_expr);
3950 if (!value) goto failed;
3951 if (_PyObject_SetAttrId(result, &PyId_context_expr, value) == -1)
3952 goto failed;
3953 Py_DECREF(value);
3954 value = ast2obj_expr(o->optional_vars);
3955 if (!value) goto failed;
3956 if (_PyObject_SetAttrId(result, &PyId_optional_vars, value) == -1)
3957 goto failed;
3958 Py_DECREF(value);
3959 return result;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05003960failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003961 Py_XDECREF(value);
3962 Py_XDECREF(result);
3963 return NULL;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05003964}
3965
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003966
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00003967int
3968obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena)
3969{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003970 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00003971
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003972 PyObject *tmp = NULL;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00003973
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003974 if (obj == Py_None) {
3975 *out = NULL;
3976 return 0;
3977 }
3978 isinstance = PyObject_IsInstance(obj, (PyObject*)Module_type);
3979 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00003980 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003981 }
3982 if (isinstance) {
3983 asdl_seq* body;
3984
3985 if (_PyObject_HasAttrId(obj, &PyId_body)) {
3986 int res;
3987 Py_ssize_t len;
3988 Py_ssize_t i;
3989 tmp = _PyObject_GetAttrId(obj, &PyId_body);
3990 if (tmp == NULL) goto failed;
3991 if (!PyList_Check(tmp)) {
3992 PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3993 goto failed;
3994 }
3995 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02003996 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003997 if (body == NULL) goto failed;
3998 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07003999 stmt_ty val;
4000 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004001 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03004002 if (len != PyList_GET_SIZE(tmp)) {
4003 PyErr_SetString(PyExc_RuntimeError, "Module field \"body\" changed size during iteration");
4004 goto failed;
4005 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07004006 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004007 }
Victor Stinner1acc1292013-07-27 00:03:47 +02004008 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004009 } else {
4010 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module");
4011 return 1;
4012 }
4013 *out = Module(body, arena);
4014 if (*out == NULL) goto failed;
4015 return 0;
4016 }
4017 isinstance = PyObject_IsInstance(obj, (PyObject*)Interactive_type);
4018 if (isinstance == -1) {
4019 return 1;
4020 }
4021 if (isinstance) {
4022 asdl_seq* body;
4023
4024 if (_PyObject_HasAttrId(obj, &PyId_body)) {
4025 int res;
4026 Py_ssize_t len;
4027 Py_ssize_t i;
4028 tmp = _PyObject_GetAttrId(obj, &PyId_body);
4029 if (tmp == NULL) goto failed;
4030 if (!PyList_Check(tmp)) {
4031 PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4032 goto failed;
4033 }
4034 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02004035 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004036 if (body == NULL) goto failed;
4037 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07004038 stmt_ty val;
4039 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004040 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03004041 if (len != PyList_GET_SIZE(tmp)) {
4042 PyErr_SetString(PyExc_RuntimeError, "Interactive field \"body\" changed size during iteration");
4043 goto failed;
4044 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07004045 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004046 }
Victor Stinner1acc1292013-07-27 00:03:47 +02004047 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004048 } else {
4049 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive");
4050 return 1;
4051 }
4052 *out = Interactive(body, arena);
4053 if (*out == NULL) goto failed;
4054 return 0;
4055 }
4056 isinstance = PyObject_IsInstance(obj, (PyObject*)Expression_type);
4057 if (isinstance == -1) {
4058 return 1;
4059 }
4060 if (isinstance) {
4061 expr_ty body;
4062
4063 if (_PyObject_HasAttrId(obj, &PyId_body)) {
4064 int res;
4065 tmp = _PyObject_GetAttrId(obj, &PyId_body);
4066 if (tmp == NULL) goto failed;
4067 res = obj2ast_expr(tmp, &body, arena);
4068 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02004069 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004070 } else {
4071 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression");
4072 return 1;
4073 }
4074 *out = Expression(body, arena);
4075 if (*out == NULL) goto failed;
4076 return 0;
4077 }
4078 isinstance = PyObject_IsInstance(obj, (PyObject*)Suite_type);
4079 if (isinstance == -1) {
4080 return 1;
4081 }
4082 if (isinstance) {
4083 asdl_seq* body;
4084
4085 if (_PyObject_HasAttrId(obj, &PyId_body)) {
4086 int res;
4087 Py_ssize_t len;
4088 Py_ssize_t i;
4089 tmp = _PyObject_GetAttrId(obj, &PyId_body);
4090 if (tmp == NULL) goto failed;
4091 if (!PyList_Check(tmp)) {
4092 PyErr_Format(PyExc_TypeError, "Suite field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4093 goto failed;
4094 }
4095 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02004096 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004097 if (body == NULL) goto failed;
4098 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07004099 stmt_ty val;
4100 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004101 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03004102 if (len != PyList_GET_SIZE(tmp)) {
4103 PyErr_SetString(PyExc_RuntimeError, "Suite field \"body\" changed size during iteration");
4104 goto failed;
4105 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07004106 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004107 }
Victor Stinner1acc1292013-07-27 00:03:47 +02004108 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004109 } else {
4110 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Suite");
4111 return 1;
4112 }
4113 *out = Suite(body, arena);
4114 if (*out == NULL) goto failed;
4115 return 0;
4116 }
4117
4118 PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj);
4119 failed:
4120 Py_XDECREF(tmp);
4121 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00004122}
4123
4124int
4125obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
4126{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004127 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00004128
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004129 PyObject *tmp = NULL;
4130 int lineno;
4131 int col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00004132
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004133 if (obj == Py_None) {
4134 *out = NULL;
4135 return 0;
4136 }
4137 if (_PyObject_HasAttrId(obj, &PyId_lineno)) {
4138 int res;
4139 tmp = _PyObject_GetAttrId(obj, &PyId_lineno);
4140 if (tmp == NULL) goto failed;
4141 res = obj2ast_int(tmp, &lineno, arena);
4142 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02004143 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004144 } else {
4145 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt");
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00004146 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004147 }
4148 if (_PyObject_HasAttrId(obj, &PyId_col_offset)) {
4149 int res;
4150 tmp = _PyObject_GetAttrId(obj, &PyId_col_offset);
4151 if (tmp == NULL) goto failed;
4152 res = obj2ast_int(tmp, &col_offset, arena);
4153 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02004154 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004155 } else {
4156 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt");
4157 return 1;
4158 }
4159 isinstance = PyObject_IsInstance(obj, (PyObject*)FunctionDef_type);
4160 if (isinstance == -1) {
4161 return 1;
4162 }
4163 if (isinstance) {
4164 identifier name;
4165 arguments_ty args;
4166 asdl_seq* body;
4167 asdl_seq* decorator_list;
4168 expr_ty returns;
4169
4170 if (_PyObject_HasAttrId(obj, &PyId_name)) {
4171 int res;
4172 tmp = _PyObject_GetAttrId(obj, &PyId_name);
4173 if (tmp == NULL) goto failed;
4174 res = obj2ast_identifier(tmp, &name, arena);
4175 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02004176 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004177 } else {
4178 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef");
4179 return 1;
4180 }
4181 if (_PyObject_HasAttrId(obj, &PyId_args)) {
4182 int res;
4183 tmp = _PyObject_GetAttrId(obj, &PyId_args);
4184 if (tmp == NULL) goto failed;
4185 res = obj2ast_arguments(tmp, &args, arena);
4186 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02004187 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004188 } else {
4189 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef");
4190 return 1;
4191 }
4192 if (_PyObject_HasAttrId(obj, &PyId_body)) {
4193 int res;
4194 Py_ssize_t len;
4195 Py_ssize_t i;
4196 tmp = _PyObject_GetAttrId(obj, &PyId_body);
4197 if (tmp == NULL) goto failed;
4198 if (!PyList_Check(tmp)) {
4199 PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4200 goto failed;
4201 }
4202 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02004203 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004204 if (body == NULL) goto failed;
4205 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07004206 stmt_ty val;
4207 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004208 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03004209 if (len != PyList_GET_SIZE(tmp)) {
4210 PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"body\" changed size during iteration");
4211 goto failed;
4212 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07004213 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004214 }
Victor Stinner1acc1292013-07-27 00:03:47 +02004215 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004216 } else {
4217 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef");
4218 return 1;
4219 }
4220 if (_PyObject_HasAttrId(obj, &PyId_decorator_list)) {
4221 int res;
4222 Py_ssize_t len;
4223 Py_ssize_t i;
4224 tmp = _PyObject_GetAttrId(obj, &PyId_decorator_list);
4225 if (tmp == NULL) goto failed;
4226 if (!PyList_Check(tmp)) {
4227 PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4228 goto failed;
4229 }
4230 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02004231 decorator_list = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004232 if (decorator_list == NULL) goto failed;
4233 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07004234 expr_ty val;
4235 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004236 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03004237 if (len != PyList_GET_SIZE(tmp)) {
4238 PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"decorator_list\" changed size during iteration");
4239 goto failed;
4240 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07004241 asdl_seq_SET(decorator_list, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004242 }
Victor Stinner1acc1292013-07-27 00:03:47 +02004243 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004244 } else {
4245 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef");
4246 return 1;
4247 }
Victor Stinneree4b59c2013-07-27 00:01:35 +02004248 if (exists_not_none(obj, &PyId_returns)) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004249 int res;
4250 tmp = _PyObject_GetAttrId(obj, &PyId_returns);
4251 if (tmp == NULL) goto failed;
4252 res = obj2ast_expr(tmp, &returns, arena);
4253 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02004254 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004255 } else {
4256 returns = NULL;
4257 }
4258 *out = FunctionDef(name, args, body, decorator_list, returns, lineno,
4259 col_offset, arena);
4260 if (*out == NULL) goto failed;
4261 return 0;
4262 }
Yury Selivanov75445082015-05-11 22:57:16 -04004263 isinstance = PyObject_IsInstance(obj, (PyObject*)AsyncFunctionDef_type);
4264 if (isinstance == -1) {
4265 return 1;
4266 }
4267 if (isinstance) {
4268 identifier name;
4269 arguments_ty args;
4270 asdl_seq* body;
4271 asdl_seq* decorator_list;
4272 expr_ty returns;
4273
4274 if (_PyObject_HasAttrId(obj, &PyId_name)) {
4275 int res;
4276 tmp = _PyObject_GetAttrId(obj, &PyId_name);
4277 if (tmp == NULL) goto failed;
4278 res = obj2ast_identifier(tmp, &name, arena);
4279 if (res != 0) goto failed;
4280 Py_CLEAR(tmp);
4281 } else {
4282 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from AsyncFunctionDef");
4283 return 1;
4284 }
4285 if (_PyObject_HasAttrId(obj, &PyId_args)) {
4286 int res;
4287 tmp = _PyObject_GetAttrId(obj, &PyId_args);
4288 if (tmp == NULL) goto failed;
4289 res = obj2ast_arguments(tmp, &args, arena);
4290 if (res != 0) goto failed;
4291 Py_CLEAR(tmp);
4292 } else {
4293 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from AsyncFunctionDef");
4294 return 1;
4295 }
4296 if (_PyObject_HasAttrId(obj, &PyId_body)) {
4297 int res;
4298 Py_ssize_t len;
4299 Py_ssize_t i;
4300 tmp = _PyObject_GetAttrId(obj, &PyId_body);
4301 if (tmp == NULL) goto failed;
4302 if (!PyList_Check(tmp)) {
4303 PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4304 goto failed;
4305 }
4306 len = PyList_GET_SIZE(tmp);
4307 body = _Py_asdl_seq_new(len, arena);
4308 if (body == NULL) goto failed;
4309 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07004310 stmt_ty val;
4311 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04004312 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03004313 if (len != PyList_GET_SIZE(tmp)) {
4314 PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"body\" changed size during iteration");
4315 goto failed;
4316 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07004317 asdl_seq_SET(body, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04004318 }
4319 Py_CLEAR(tmp);
4320 } else {
4321 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFunctionDef");
4322 return 1;
4323 }
4324 if (_PyObject_HasAttrId(obj, &PyId_decorator_list)) {
4325 int res;
4326 Py_ssize_t len;
4327 Py_ssize_t i;
4328 tmp = _PyObject_GetAttrId(obj, &PyId_decorator_list);
4329 if (tmp == NULL) goto failed;
4330 if (!PyList_Check(tmp)) {
4331 PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4332 goto failed;
4333 }
4334 len = PyList_GET_SIZE(tmp);
4335 decorator_list = _Py_asdl_seq_new(len, arena);
4336 if (decorator_list == NULL) goto failed;
4337 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07004338 expr_ty val;
4339 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04004340 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03004341 if (len != PyList_GET_SIZE(tmp)) {
4342 PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"decorator_list\" changed size during iteration");
4343 goto failed;
4344 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07004345 asdl_seq_SET(decorator_list, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04004346 }
4347 Py_CLEAR(tmp);
4348 } else {
4349 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from AsyncFunctionDef");
4350 return 1;
4351 }
4352 if (exists_not_none(obj, &PyId_returns)) {
4353 int res;
4354 tmp = _PyObject_GetAttrId(obj, &PyId_returns);
4355 if (tmp == NULL) goto failed;
4356 res = obj2ast_expr(tmp, &returns, arena);
4357 if (res != 0) goto failed;
4358 Py_CLEAR(tmp);
4359 } else {
4360 returns = NULL;
4361 }
4362 *out = AsyncFunctionDef(name, args, body, decorator_list, returns,
4363 lineno, col_offset, arena);
4364 if (*out == NULL) goto failed;
4365 return 0;
4366 }
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004367 isinstance = PyObject_IsInstance(obj, (PyObject*)ClassDef_type);
4368 if (isinstance == -1) {
4369 return 1;
4370 }
4371 if (isinstance) {
4372 identifier name;
4373 asdl_seq* bases;
4374 asdl_seq* keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004375 asdl_seq* body;
4376 asdl_seq* decorator_list;
4377
4378 if (_PyObject_HasAttrId(obj, &PyId_name)) {
4379 int res;
4380 tmp = _PyObject_GetAttrId(obj, &PyId_name);
4381 if (tmp == NULL) goto failed;
4382 res = obj2ast_identifier(tmp, &name, arena);
4383 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02004384 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004385 } else {
4386 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef");
4387 return 1;
4388 }
4389 if (_PyObject_HasAttrId(obj, &PyId_bases)) {
4390 int res;
4391 Py_ssize_t len;
4392 Py_ssize_t i;
4393 tmp = _PyObject_GetAttrId(obj, &PyId_bases);
4394 if (tmp == NULL) goto failed;
4395 if (!PyList_Check(tmp)) {
4396 PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4397 goto failed;
4398 }
4399 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02004400 bases = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004401 if (bases == NULL) goto failed;
4402 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07004403 expr_ty val;
4404 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004405 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03004406 if (len != PyList_GET_SIZE(tmp)) {
4407 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"bases\" changed size during iteration");
4408 goto failed;
4409 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07004410 asdl_seq_SET(bases, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004411 }
Victor Stinner1acc1292013-07-27 00:03:47 +02004412 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004413 } else {
4414 PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef");
4415 return 1;
4416 }
4417 if (_PyObject_HasAttrId(obj, &PyId_keywords)) {
4418 int res;
4419 Py_ssize_t len;
4420 Py_ssize_t i;
4421 tmp = _PyObject_GetAttrId(obj, &PyId_keywords);
4422 if (tmp == NULL) goto failed;
4423 if (!PyList_Check(tmp)) {
4424 PyErr_Format(PyExc_TypeError, "ClassDef field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4425 goto failed;
4426 }
4427 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02004428 keywords = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004429 if (keywords == NULL) goto failed;
4430 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07004431 keyword_ty val;
4432 res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &val, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004433 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03004434 if (len != PyList_GET_SIZE(tmp)) {
4435 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"keywords\" changed size during iteration");
4436 goto failed;
4437 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07004438 asdl_seq_SET(keywords, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004439 }
Victor Stinner1acc1292013-07-27 00:03:47 +02004440 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004441 } else {
4442 PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef");
4443 return 1;
4444 }
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004445 if (_PyObject_HasAttrId(obj, &PyId_body)) {
4446 int res;
4447 Py_ssize_t len;
4448 Py_ssize_t i;
4449 tmp = _PyObject_GetAttrId(obj, &PyId_body);
4450 if (tmp == NULL) goto failed;
4451 if (!PyList_Check(tmp)) {
4452 PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4453 goto failed;
4454 }
4455 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02004456 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004457 if (body == NULL) goto failed;
4458 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07004459 stmt_ty val;
4460 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004461 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03004462 if (len != PyList_GET_SIZE(tmp)) {
4463 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"body\" changed size during iteration");
4464 goto failed;
4465 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07004466 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004467 }
Victor Stinner1acc1292013-07-27 00:03:47 +02004468 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004469 } else {
4470 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef");
4471 return 1;
4472 }
4473 if (_PyObject_HasAttrId(obj, &PyId_decorator_list)) {
4474 int res;
4475 Py_ssize_t len;
4476 Py_ssize_t i;
4477 tmp = _PyObject_GetAttrId(obj, &PyId_decorator_list);
4478 if (tmp == NULL) goto failed;
4479 if (!PyList_Check(tmp)) {
4480 PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4481 goto failed;
4482 }
4483 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02004484 decorator_list = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004485 if (decorator_list == NULL) goto failed;
4486 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07004487 expr_ty val;
4488 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004489 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03004490 if (len != PyList_GET_SIZE(tmp)) {
4491 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"decorator_list\" changed size during iteration");
4492 goto failed;
4493 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07004494 asdl_seq_SET(decorator_list, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004495 }
Victor Stinner1acc1292013-07-27 00:03:47 +02004496 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004497 } else {
4498 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef");
4499 return 1;
4500 }
Benjamin Peterson025e9eb2015-05-05 20:16:41 -04004501 *out = ClassDef(name, bases, keywords, body, decorator_list, lineno,
4502 col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004503 if (*out == NULL) goto failed;
4504 return 0;
4505 }
4506 isinstance = PyObject_IsInstance(obj, (PyObject*)Return_type);
4507 if (isinstance == -1) {
4508 return 1;
4509 }
4510 if (isinstance) {
4511 expr_ty value;
4512
Victor Stinneree4b59c2013-07-27 00:01:35 +02004513 if (exists_not_none(obj, &PyId_value)) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004514 int res;
4515 tmp = _PyObject_GetAttrId(obj, &PyId_value);
4516 if (tmp == NULL) goto failed;
4517 res = obj2ast_expr(tmp, &value, arena);
4518 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02004519 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004520 } else {
4521 value = NULL;
4522 }
4523 *out = Return(value, lineno, col_offset, arena);
4524 if (*out == NULL) goto failed;
4525 return 0;
4526 }
4527 isinstance = PyObject_IsInstance(obj, (PyObject*)Delete_type);
4528 if (isinstance == -1) {
4529 return 1;
4530 }
4531 if (isinstance) {
4532 asdl_seq* targets;
4533
4534 if (_PyObject_HasAttrId(obj, &PyId_targets)) {
4535 int res;
4536 Py_ssize_t len;
4537 Py_ssize_t i;
4538 tmp = _PyObject_GetAttrId(obj, &PyId_targets);
4539 if (tmp == NULL) goto failed;
4540 if (!PyList_Check(tmp)) {
4541 PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4542 goto failed;
4543 }
4544 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02004545 targets = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004546 if (targets == NULL) goto failed;
4547 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07004548 expr_ty val;
4549 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004550 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03004551 if (len != PyList_GET_SIZE(tmp)) {
4552 PyErr_SetString(PyExc_RuntimeError, "Delete field \"targets\" changed size during iteration");
4553 goto failed;
4554 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07004555 asdl_seq_SET(targets, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004556 }
Victor Stinner1acc1292013-07-27 00:03:47 +02004557 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004558 } else {
4559 PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete");
4560 return 1;
4561 }
4562 *out = Delete(targets, lineno, col_offset, arena);
4563 if (*out == NULL) goto failed;
4564 return 0;
4565 }
4566 isinstance = PyObject_IsInstance(obj, (PyObject*)Assign_type);
4567 if (isinstance == -1) {
4568 return 1;
4569 }
4570 if (isinstance) {
4571 asdl_seq* targets;
4572 expr_ty value;
4573
4574 if (_PyObject_HasAttrId(obj, &PyId_targets)) {
4575 int res;
4576 Py_ssize_t len;
4577 Py_ssize_t i;
4578 tmp = _PyObject_GetAttrId(obj, &PyId_targets);
4579 if (tmp == NULL) goto failed;
4580 if (!PyList_Check(tmp)) {
4581 PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4582 goto failed;
4583 }
4584 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02004585 targets = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004586 if (targets == NULL) goto failed;
4587 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07004588 expr_ty val;
4589 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004590 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03004591 if (len != PyList_GET_SIZE(tmp)) {
4592 PyErr_SetString(PyExc_RuntimeError, "Assign field \"targets\" changed size during iteration");
4593 goto failed;
4594 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07004595 asdl_seq_SET(targets, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004596 }
Victor Stinner1acc1292013-07-27 00:03:47 +02004597 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004598 } else {
4599 PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign");
4600 return 1;
4601 }
4602 if (_PyObject_HasAttrId(obj, &PyId_value)) {
4603 int res;
4604 tmp = _PyObject_GetAttrId(obj, &PyId_value);
4605 if (tmp == NULL) goto failed;
4606 res = obj2ast_expr(tmp, &value, arena);
4607 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02004608 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004609 } else {
4610 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign");
4611 return 1;
4612 }
4613 *out = Assign(targets, value, lineno, col_offset, arena);
4614 if (*out == NULL) goto failed;
4615 return 0;
4616 }
4617 isinstance = PyObject_IsInstance(obj, (PyObject*)AugAssign_type);
4618 if (isinstance == -1) {
4619 return 1;
4620 }
4621 if (isinstance) {
4622 expr_ty target;
4623 operator_ty op;
4624 expr_ty value;
4625
4626 if (_PyObject_HasAttrId(obj, &PyId_target)) {
4627 int res;
4628 tmp = _PyObject_GetAttrId(obj, &PyId_target);
4629 if (tmp == NULL) goto failed;
4630 res = obj2ast_expr(tmp, &target, arena);
4631 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02004632 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004633 } else {
4634 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign");
4635 return 1;
4636 }
4637 if (_PyObject_HasAttrId(obj, &PyId_op)) {
4638 int res;
4639 tmp = _PyObject_GetAttrId(obj, &PyId_op);
4640 if (tmp == NULL) goto failed;
4641 res = obj2ast_operator(tmp, &op, arena);
4642 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02004643 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004644 } else {
4645 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign");
4646 return 1;
4647 }
4648 if (_PyObject_HasAttrId(obj, &PyId_value)) {
4649 int res;
4650 tmp = _PyObject_GetAttrId(obj, &PyId_value);
4651 if (tmp == NULL) goto failed;
4652 res = obj2ast_expr(tmp, &value, arena);
4653 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02004654 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004655 } else {
4656 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign");
4657 return 1;
4658 }
4659 *out = AugAssign(target, op, value, lineno, col_offset, arena);
4660 if (*out == NULL) goto failed;
4661 return 0;
4662 }
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07004663 isinstance = PyObject_IsInstance(obj, (PyObject*)AnnAssign_type);
4664 if (isinstance == -1) {
4665 return 1;
4666 }
4667 if (isinstance) {
4668 expr_ty target;
4669 expr_ty annotation;
4670 expr_ty value;
4671 int simple;
4672
4673 if (_PyObject_HasAttrId(obj, &PyId_target)) {
4674 int res;
4675 tmp = _PyObject_GetAttrId(obj, &PyId_target);
4676 if (tmp == NULL) goto failed;
4677 res = obj2ast_expr(tmp, &target, arena);
4678 if (res != 0) goto failed;
4679 Py_CLEAR(tmp);
4680 } else {
4681 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AnnAssign");
4682 return 1;
4683 }
4684 if (_PyObject_HasAttrId(obj, &PyId_annotation)) {
4685 int res;
4686 tmp = _PyObject_GetAttrId(obj, &PyId_annotation);
4687 if (tmp == NULL) goto failed;
4688 res = obj2ast_expr(tmp, &annotation, arena);
4689 if (res != 0) goto failed;
4690 Py_CLEAR(tmp);
4691 } else {
4692 PyErr_SetString(PyExc_TypeError, "required field \"annotation\" missing from AnnAssign");
4693 return 1;
4694 }
4695 if (exists_not_none(obj, &PyId_value)) {
4696 int res;
4697 tmp = _PyObject_GetAttrId(obj, &PyId_value);
4698 if (tmp == NULL) goto failed;
4699 res = obj2ast_expr(tmp, &value, arena);
4700 if (res != 0) goto failed;
4701 Py_CLEAR(tmp);
4702 } else {
4703 value = NULL;
4704 }
4705 if (_PyObject_HasAttrId(obj, &PyId_simple)) {
4706 int res;
4707 tmp = _PyObject_GetAttrId(obj, &PyId_simple);
4708 if (tmp == NULL) goto failed;
4709 res = obj2ast_int(tmp, &simple, arena);
4710 if (res != 0) goto failed;
4711 Py_CLEAR(tmp);
4712 } else {
4713 PyErr_SetString(PyExc_TypeError, "required field \"simple\" missing from AnnAssign");
4714 return 1;
4715 }
4716 *out = AnnAssign(target, annotation, value, simple, lineno, col_offset,
4717 arena);
4718 if (*out == NULL) goto failed;
4719 return 0;
4720 }
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004721 isinstance = PyObject_IsInstance(obj, (PyObject*)For_type);
4722 if (isinstance == -1) {
4723 return 1;
4724 }
4725 if (isinstance) {
4726 expr_ty target;
4727 expr_ty iter;
4728 asdl_seq* body;
4729 asdl_seq* orelse;
4730
4731 if (_PyObject_HasAttrId(obj, &PyId_target)) {
4732 int res;
4733 tmp = _PyObject_GetAttrId(obj, &PyId_target);
4734 if (tmp == NULL) goto failed;
4735 res = obj2ast_expr(tmp, &target, arena);
4736 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02004737 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004738 } else {
4739 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For");
4740 return 1;
4741 }
4742 if (_PyObject_HasAttrId(obj, &PyId_iter)) {
4743 int res;
4744 tmp = _PyObject_GetAttrId(obj, &PyId_iter);
4745 if (tmp == NULL) goto failed;
4746 res = obj2ast_expr(tmp, &iter, arena);
4747 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02004748 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004749 } else {
4750 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For");
4751 return 1;
4752 }
4753 if (_PyObject_HasAttrId(obj, &PyId_body)) {
4754 int res;
4755 Py_ssize_t len;
4756 Py_ssize_t i;
4757 tmp = _PyObject_GetAttrId(obj, &PyId_body);
4758 if (tmp == NULL) goto failed;
4759 if (!PyList_Check(tmp)) {
4760 PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4761 goto failed;
4762 }
4763 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02004764 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004765 if (body == NULL) goto failed;
4766 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07004767 stmt_ty val;
4768 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004769 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03004770 if (len != PyList_GET_SIZE(tmp)) {
4771 PyErr_SetString(PyExc_RuntimeError, "For field \"body\" changed size during iteration");
4772 goto failed;
4773 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07004774 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004775 }
Victor Stinner1acc1292013-07-27 00:03:47 +02004776 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004777 } else {
4778 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For");
4779 return 1;
4780 }
4781 if (_PyObject_HasAttrId(obj, &PyId_orelse)) {
4782 int res;
4783 Py_ssize_t len;
4784 Py_ssize_t i;
4785 tmp = _PyObject_GetAttrId(obj, &PyId_orelse);
4786 if (tmp == NULL) goto failed;
4787 if (!PyList_Check(tmp)) {
4788 PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4789 goto failed;
4790 }
4791 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02004792 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004793 if (orelse == NULL) goto failed;
4794 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07004795 stmt_ty val;
4796 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004797 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03004798 if (len != PyList_GET_SIZE(tmp)) {
4799 PyErr_SetString(PyExc_RuntimeError, "For field \"orelse\" changed size during iteration");
4800 goto failed;
4801 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07004802 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004803 }
Victor Stinner1acc1292013-07-27 00:03:47 +02004804 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004805 } else {
4806 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For");
4807 return 1;
4808 }
4809 *out = For(target, iter, body, orelse, lineno, col_offset, arena);
4810 if (*out == NULL) goto failed;
4811 return 0;
4812 }
Yury Selivanov75445082015-05-11 22:57:16 -04004813 isinstance = PyObject_IsInstance(obj, (PyObject*)AsyncFor_type);
4814 if (isinstance == -1) {
4815 return 1;
4816 }
4817 if (isinstance) {
4818 expr_ty target;
4819 expr_ty iter;
4820 asdl_seq* body;
4821 asdl_seq* orelse;
4822
4823 if (_PyObject_HasAttrId(obj, &PyId_target)) {
4824 int res;
4825 tmp = _PyObject_GetAttrId(obj, &PyId_target);
4826 if (tmp == NULL) goto failed;
4827 res = obj2ast_expr(tmp, &target, arena);
4828 if (res != 0) goto failed;
4829 Py_CLEAR(tmp);
4830 } else {
4831 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AsyncFor");
4832 return 1;
4833 }
4834 if (_PyObject_HasAttrId(obj, &PyId_iter)) {
4835 int res;
4836 tmp = _PyObject_GetAttrId(obj, &PyId_iter);
4837 if (tmp == NULL) goto failed;
4838 res = obj2ast_expr(tmp, &iter, arena);
4839 if (res != 0) goto failed;
4840 Py_CLEAR(tmp);
4841 } else {
4842 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from AsyncFor");
4843 return 1;
4844 }
4845 if (_PyObject_HasAttrId(obj, &PyId_body)) {
4846 int res;
4847 Py_ssize_t len;
4848 Py_ssize_t i;
4849 tmp = _PyObject_GetAttrId(obj, &PyId_body);
4850 if (tmp == NULL) goto failed;
4851 if (!PyList_Check(tmp)) {
4852 PyErr_Format(PyExc_TypeError, "AsyncFor field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4853 goto failed;
4854 }
4855 len = PyList_GET_SIZE(tmp);
4856 body = _Py_asdl_seq_new(len, arena);
4857 if (body == NULL) goto failed;
4858 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07004859 stmt_ty val;
4860 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04004861 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03004862 if (len != PyList_GET_SIZE(tmp)) {
4863 PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"body\" changed size during iteration");
4864 goto failed;
4865 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07004866 asdl_seq_SET(body, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04004867 }
4868 Py_CLEAR(tmp);
4869 } else {
4870 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFor");
4871 return 1;
4872 }
4873 if (_PyObject_HasAttrId(obj, &PyId_orelse)) {
4874 int res;
4875 Py_ssize_t len;
4876 Py_ssize_t i;
4877 tmp = _PyObject_GetAttrId(obj, &PyId_orelse);
4878 if (tmp == NULL) goto failed;
4879 if (!PyList_Check(tmp)) {
4880 PyErr_Format(PyExc_TypeError, "AsyncFor field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4881 goto failed;
4882 }
4883 len = PyList_GET_SIZE(tmp);
4884 orelse = _Py_asdl_seq_new(len, arena);
4885 if (orelse == NULL) goto failed;
4886 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07004887 stmt_ty val;
4888 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04004889 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03004890 if (len != PyList_GET_SIZE(tmp)) {
4891 PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"orelse\" changed size during iteration");
4892 goto failed;
4893 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07004894 asdl_seq_SET(orelse, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04004895 }
4896 Py_CLEAR(tmp);
4897 } else {
4898 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from AsyncFor");
4899 return 1;
4900 }
4901 *out = AsyncFor(target, iter, body, orelse, lineno, col_offset, arena);
4902 if (*out == NULL) goto failed;
4903 return 0;
4904 }
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004905 isinstance = PyObject_IsInstance(obj, (PyObject*)While_type);
4906 if (isinstance == -1) {
4907 return 1;
4908 }
4909 if (isinstance) {
4910 expr_ty test;
4911 asdl_seq* body;
4912 asdl_seq* orelse;
4913
4914 if (_PyObject_HasAttrId(obj, &PyId_test)) {
4915 int res;
4916 tmp = _PyObject_GetAttrId(obj, &PyId_test);
4917 if (tmp == NULL) goto failed;
4918 res = obj2ast_expr(tmp, &test, arena);
4919 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02004920 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004921 } else {
4922 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While");
4923 return 1;
4924 }
4925 if (_PyObject_HasAttrId(obj, &PyId_body)) {
4926 int res;
4927 Py_ssize_t len;
4928 Py_ssize_t i;
4929 tmp = _PyObject_GetAttrId(obj, &PyId_body);
4930 if (tmp == NULL) goto failed;
4931 if (!PyList_Check(tmp)) {
4932 PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4933 goto failed;
4934 }
4935 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02004936 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004937 if (body == NULL) goto failed;
4938 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07004939 stmt_ty val;
4940 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004941 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03004942 if (len != PyList_GET_SIZE(tmp)) {
4943 PyErr_SetString(PyExc_RuntimeError, "While field \"body\" changed size during iteration");
4944 goto failed;
4945 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07004946 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004947 }
Victor Stinner1acc1292013-07-27 00:03:47 +02004948 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004949 } else {
4950 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While");
4951 return 1;
4952 }
4953 if (_PyObject_HasAttrId(obj, &PyId_orelse)) {
4954 int res;
4955 Py_ssize_t len;
4956 Py_ssize_t i;
4957 tmp = _PyObject_GetAttrId(obj, &PyId_orelse);
4958 if (tmp == NULL) goto failed;
4959 if (!PyList_Check(tmp)) {
4960 PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4961 goto failed;
4962 }
4963 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02004964 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004965 if (orelse == NULL) goto failed;
4966 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07004967 stmt_ty val;
4968 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004969 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03004970 if (len != PyList_GET_SIZE(tmp)) {
4971 PyErr_SetString(PyExc_RuntimeError, "While field \"orelse\" changed size during iteration");
4972 goto failed;
4973 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07004974 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004975 }
Victor Stinner1acc1292013-07-27 00:03:47 +02004976 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004977 } else {
4978 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While");
4979 return 1;
4980 }
4981 *out = While(test, body, orelse, lineno, col_offset, arena);
4982 if (*out == NULL) goto failed;
4983 return 0;
4984 }
4985 isinstance = PyObject_IsInstance(obj, (PyObject*)If_type);
4986 if (isinstance == -1) {
4987 return 1;
4988 }
4989 if (isinstance) {
4990 expr_ty test;
4991 asdl_seq* body;
4992 asdl_seq* orelse;
4993
4994 if (_PyObject_HasAttrId(obj, &PyId_test)) {
4995 int res;
4996 tmp = _PyObject_GetAttrId(obj, &PyId_test);
4997 if (tmp == NULL) goto failed;
4998 res = obj2ast_expr(tmp, &test, arena);
4999 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005000 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005001 } else {
5002 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If");
5003 return 1;
5004 }
5005 if (_PyObject_HasAttrId(obj, &PyId_body)) {
5006 int res;
5007 Py_ssize_t len;
5008 Py_ssize_t i;
5009 tmp = _PyObject_GetAttrId(obj, &PyId_body);
5010 if (tmp == NULL) goto failed;
5011 if (!PyList_Check(tmp)) {
5012 PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5013 goto failed;
5014 }
5015 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005016 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005017 if (body == NULL) goto failed;
5018 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07005019 stmt_ty val;
5020 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005021 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005022 if (len != PyList_GET_SIZE(tmp)) {
5023 PyErr_SetString(PyExc_RuntimeError, "If field \"body\" changed size during iteration");
5024 goto failed;
5025 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07005026 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005027 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005028 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005029 } else {
5030 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If");
5031 return 1;
5032 }
5033 if (_PyObject_HasAttrId(obj, &PyId_orelse)) {
5034 int res;
5035 Py_ssize_t len;
5036 Py_ssize_t i;
5037 tmp = _PyObject_GetAttrId(obj, &PyId_orelse);
5038 if (tmp == NULL) goto failed;
5039 if (!PyList_Check(tmp)) {
5040 PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5041 goto failed;
5042 }
5043 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005044 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005045 if (orelse == NULL) goto failed;
5046 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07005047 stmt_ty val;
5048 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005049 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005050 if (len != PyList_GET_SIZE(tmp)) {
5051 PyErr_SetString(PyExc_RuntimeError, "If field \"orelse\" changed size during iteration");
5052 goto failed;
5053 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07005054 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005055 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005056 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005057 } else {
5058 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If");
5059 return 1;
5060 }
5061 *out = If(test, body, orelse, lineno, col_offset, arena);
5062 if (*out == NULL) goto failed;
5063 return 0;
5064 }
5065 isinstance = PyObject_IsInstance(obj, (PyObject*)With_type);
5066 if (isinstance == -1) {
5067 return 1;
5068 }
5069 if (isinstance) {
5070 asdl_seq* items;
5071 asdl_seq* body;
5072
5073 if (_PyObject_HasAttrId(obj, &PyId_items)) {
5074 int res;
5075 Py_ssize_t len;
5076 Py_ssize_t i;
5077 tmp = _PyObject_GetAttrId(obj, &PyId_items);
5078 if (tmp == NULL) goto failed;
5079 if (!PyList_Check(tmp)) {
5080 PyErr_Format(PyExc_TypeError, "With field \"items\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5081 goto failed;
5082 }
5083 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005084 items = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005085 if (items == NULL) goto failed;
5086 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07005087 withitem_ty val;
5088 res = obj2ast_withitem(PyList_GET_ITEM(tmp, i), &val, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005089 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005090 if (len != PyList_GET_SIZE(tmp)) {
5091 PyErr_SetString(PyExc_RuntimeError, "With field \"items\" changed size during iteration");
5092 goto failed;
5093 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07005094 asdl_seq_SET(items, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005095 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005096 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005097 } else {
5098 PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With");
5099 return 1;
5100 }
5101 if (_PyObject_HasAttrId(obj, &PyId_body)) {
5102 int res;
5103 Py_ssize_t len;
5104 Py_ssize_t i;
5105 tmp = _PyObject_GetAttrId(obj, &PyId_body);
5106 if (tmp == NULL) goto failed;
5107 if (!PyList_Check(tmp)) {
5108 PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5109 goto failed;
5110 }
5111 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005112 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005113 if (body == NULL) goto failed;
5114 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07005115 stmt_ty val;
5116 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005117 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005118 if (len != PyList_GET_SIZE(tmp)) {
5119 PyErr_SetString(PyExc_RuntimeError, "With field \"body\" changed size during iteration");
5120 goto failed;
5121 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07005122 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005123 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005124 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005125 } else {
5126 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With");
5127 return 1;
5128 }
5129 *out = With(items, body, lineno, col_offset, arena);
5130 if (*out == NULL) goto failed;
5131 return 0;
5132 }
Yury Selivanov75445082015-05-11 22:57:16 -04005133 isinstance = PyObject_IsInstance(obj, (PyObject*)AsyncWith_type);
5134 if (isinstance == -1) {
5135 return 1;
5136 }
5137 if (isinstance) {
5138 asdl_seq* items;
5139 asdl_seq* body;
5140
5141 if (_PyObject_HasAttrId(obj, &PyId_items)) {
5142 int res;
5143 Py_ssize_t len;
5144 Py_ssize_t i;
5145 tmp = _PyObject_GetAttrId(obj, &PyId_items);
5146 if (tmp == NULL) goto failed;
5147 if (!PyList_Check(tmp)) {
5148 PyErr_Format(PyExc_TypeError, "AsyncWith field \"items\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5149 goto failed;
5150 }
5151 len = PyList_GET_SIZE(tmp);
5152 items = _Py_asdl_seq_new(len, arena);
5153 if (items == NULL) goto failed;
5154 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07005155 withitem_ty val;
5156 res = obj2ast_withitem(PyList_GET_ITEM(tmp, i), &val, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04005157 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005158 if (len != PyList_GET_SIZE(tmp)) {
5159 PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"items\" changed size during iteration");
5160 goto failed;
5161 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07005162 asdl_seq_SET(items, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04005163 }
5164 Py_CLEAR(tmp);
5165 } else {
5166 PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from AsyncWith");
5167 return 1;
5168 }
5169 if (_PyObject_HasAttrId(obj, &PyId_body)) {
5170 int res;
5171 Py_ssize_t len;
5172 Py_ssize_t i;
5173 tmp = _PyObject_GetAttrId(obj, &PyId_body);
5174 if (tmp == NULL) goto failed;
5175 if (!PyList_Check(tmp)) {
5176 PyErr_Format(PyExc_TypeError, "AsyncWith field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5177 goto failed;
5178 }
5179 len = PyList_GET_SIZE(tmp);
5180 body = _Py_asdl_seq_new(len, arena);
5181 if (body == NULL) goto failed;
5182 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07005183 stmt_ty val;
5184 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04005185 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005186 if (len != PyList_GET_SIZE(tmp)) {
5187 PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"body\" changed size during iteration");
5188 goto failed;
5189 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07005190 asdl_seq_SET(body, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04005191 }
5192 Py_CLEAR(tmp);
5193 } else {
5194 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncWith");
5195 return 1;
5196 }
5197 *out = AsyncWith(items, body, lineno, col_offset, arena);
5198 if (*out == NULL) goto failed;
5199 return 0;
5200 }
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005201 isinstance = PyObject_IsInstance(obj, (PyObject*)Raise_type);
5202 if (isinstance == -1) {
5203 return 1;
5204 }
5205 if (isinstance) {
5206 expr_ty exc;
5207 expr_ty cause;
5208
Victor Stinneree4b59c2013-07-27 00:01:35 +02005209 if (exists_not_none(obj, &PyId_exc)) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005210 int res;
5211 tmp = _PyObject_GetAttrId(obj, &PyId_exc);
5212 if (tmp == NULL) goto failed;
5213 res = obj2ast_expr(tmp, &exc, arena);
5214 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005215 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005216 } else {
5217 exc = NULL;
5218 }
Victor Stinneree4b59c2013-07-27 00:01:35 +02005219 if (exists_not_none(obj, &PyId_cause)) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005220 int res;
5221 tmp = _PyObject_GetAttrId(obj, &PyId_cause);
5222 if (tmp == NULL) goto failed;
5223 res = obj2ast_expr(tmp, &cause, arena);
5224 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005225 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005226 } else {
5227 cause = NULL;
5228 }
5229 *out = Raise(exc, cause, lineno, col_offset, arena);
5230 if (*out == NULL) goto failed;
5231 return 0;
5232 }
5233 isinstance = PyObject_IsInstance(obj, (PyObject*)Try_type);
5234 if (isinstance == -1) {
5235 return 1;
5236 }
5237 if (isinstance) {
5238 asdl_seq* body;
5239 asdl_seq* handlers;
5240 asdl_seq* orelse;
5241 asdl_seq* finalbody;
5242
5243 if (_PyObject_HasAttrId(obj, &PyId_body)) {
5244 int res;
5245 Py_ssize_t len;
5246 Py_ssize_t i;
5247 tmp = _PyObject_GetAttrId(obj, &PyId_body);
5248 if (tmp == NULL) goto failed;
5249 if (!PyList_Check(tmp)) {
5250 PyErr_Format(PyExc_TypeError, "Try field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5251 goto failed;
5252 }
5253 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005254 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005255 if (body == NULL) goto failed;
5256 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07005257 stmt_ty val;
5258 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005259 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005260 if (len != PyList_GET_SIZE(tmp)) {
5261 PyErr_SetString(PyExc_RuntimeError, "Try field \"body\" changed size during iteration");
5262 goto failed;
5263 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07005264 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005265 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005266 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005267 } else {
5268 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try");
5269 return 1;
5270 }
5271 if (_PyObject_HasAttrId(obj, &PyId_handlers)) {
5272 int res;
5273 Py_ssize_t len;
5274 Py_ssize_t i;
5275 tmp = _PyObject_GetAttrId(obj, &PyId_handlers);
5276 if (tmp == NULL) goto failed;
5277 if (!PyList_Check(tmp)) {
5278 PyErr_Format(PyExc_TypeError, "Try field \"handlers\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5279 goto failed;
5280 }
5281 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005282 handlers = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005283 if (handlers == NULL) goto failed;
5284 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07005285 excepthandler_ty val;
5286 res = obj2ast_excepthandler(PyList_GET_ITEM(tmp, i), &val, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005287 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005288 if (len != PyList_GET_SIZE(tmp)) {
5289 PyErr_SetString(PyExc_RuntimeError, "Try field \"handlers\" changed size during iteration");
5290 goto failed;
5291 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07005292 asdl_seq_SET(handlers, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005293 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005294 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005295 } else {
5296 PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try");
5297 return 1;
5298 }
5299 if (_PyObject_HasAttrId(obj, &PyId_orelse)) {
5300 int res;
5301 Py_ssize_t len;
5302 Py_ssize_t i;
5303 tmp = _PyObject_GetAttrId(obj, &PyId_orelse);
5304 if (tmp == NULL) goto failed;
5305 if (!PyList_Check(tmp)) {
5306 PyErr_Format(PyExc_TypeError, "Try field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5307 goto failed;
5308 }
5309 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005310 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005311 if (orelse == NULL) goto failed;
5312 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07005313 stmt_ty val;
5314 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005315 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005316 if (len != PyList_GET_SIZE(tmp)) {
5317 PyErr_SetString(PyExc_RuntimeError, "Try field \"orelse\" changed size during iteration");
5318 goto failed;
5319 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07005320 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005321 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005322 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005323 } else {
5324 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try");
5325 return 1;
5326 }
5327 if (_PyObject_HasAttrId(obj, &PyId_finalbody)) {
5328 int res;
5329 Py_ssize_t len;
5330 Py_ssize_t i;
5331 tmp = _PyObject_GetAttrId(obj, &PyId_finalbody);
5332 if (tmp == NULL) goto failed;
5333 if (!PyList_Check(tmp)) {
5334 PyErr_Format(PyExc_TypeError, "Try field \"finalbody\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5335 goto failed;
5336 }
5337 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005338 finalbody = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005339 if (finalbody == NULL) goto failed;
5340 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07005341 stmt_ty val;
5342 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005343 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005344 if (len != PyList_GET_SIZE(tmp)) {
5345 PyErr_SetString(PyExc_RuntimeError, "Try field \"finalbody\" changed size during iteration");
5346 goto failed;
5347 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07005348 asdl_seq_SET(finalbody, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005349 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005350 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005351 } else {
5352 PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try");
5353 return 1;
5354 }
5355 *out = Try(body, handlers, orelse, finalbody, lineno, col_offset,
5356 arena);
5357 if (*out == NULL) goto failed;
5358 return 0;
5359 }
5360 isinstance = PyObject_IsInstance(obj, (PyObject*)Assert_type);
5361 if (isinstance == -1) {
5362 return 1;
5363 }
5364 if (isinstance) {
5365 expr_ty test;
5366 expr_ty msg;
5367
5368 if (_PyObject_HasAttrId(obj, &PyId_test)) {
5369 int res;
5370 tmp = _PyObject_GetAttrId(obj, &PyId_test);
5371 if (tmp == NULL) goto failed;
5372 res = obj2ast_expr(tmp, &test, arena);
5373 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005374 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005375 } else {
5376 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert");
5377 return 1;
5378 }
Victor Stinneree4b59c2013-07-27 00:01:35 +02005379 if (exists_not_none(obj, &PyId_msg)) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005380 int res;
5381 tmp = _PyObject_GetAttrId(obj, &PyId_msg);
5382 if (tmp == NULL) goto failed;
5383 res = obj2ast_expr(tmp, &msg, arena);
5384 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005385 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005386 } else {
5387 msg = NULL;
5388 }
5389 *out = Assert(test, msg, lineno, col_offset, arena);
5390 if (*out == NULL) goto failed;
5391 return 0;
5392 }
5393 isinstance = PyObject_IsInstance(obj, (PyObject*)Import_type);
5394 if (isinstance == -1) {
5395 return 1;
5396 }
5397 if (isinstance) {
5398 asdl_seq* names;
5399
5400 if (_PyObject_HasAttrId(obj, &PyId_names)) {
5401 int res;
5402 Py_ssize_t len;
5403 Py_ssize_t i;
5404 tmp = _PyObject_GetAttrId(obj, &PyId_names);
5405 if (tmp == NULL) goto failed;
5406 if (!PyList_Check(tmp)) {
5407 PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5408 goto failed;
5409 }
5410 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005411 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005412 if (names == NULL) goto failed;
5413 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07005414 alias_ty val;
5415 res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &val, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005416 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005417 if (len != PyList_GET_SIZE(tmp)) {
5418 PyErr_SetString(PyExc_RuntimeError, "Import field \"names\" changed size during iteration");
5419 goto failed;
5420 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07005421 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005422 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005423 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005424 } else {
5425 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import");
5426 return 1;
5427 }
5428 *out = Import(names, lineno, col_offset, arena);
5429 if (*out == NULL) goto failed;
5430 return 0;
5431 }
5432 isinstance = PyObject_IsInstance(obj, (PyObject*)ImportFrom_type);
5433 if (isinstance == -1) {
5434 return 1;
5435 }
5436 if (isinstance) {
5437 identifier module;
5438 asdl_seq* names;
5439 int level;
5440
Victor Stinneree4b59c2013-07-27 00:01:35 +02005441 if (exists_not_none(obj, &PyId_module)) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005442 int res;
5443 tmp = _PyObject_GetAttrId(obj, &PyId_module);
5444 if (tmp == NULL) goto failed;
5445 res = obj2ast_identifier(tmp, &module, arena);
5446 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005447 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005448 } else {
5449 module = NULL;
5450 }
5451 if (_PyObject_HasAttrId(obj, &PyId_names)) {
5452 int res;
5453 Py_ssize_t len;
5454 Py_ssize_t i;
5455 tmp = _PyObject_GetAttrId(obj, &PyId_names);
5456 if (tmp == NULL) goto failed;
5457 if (!PyList_Check(tmp)) {
5458 PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5459 goto failed;
5460 }
5461 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005462 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005463 if (names == NULL) goto failed;
5464 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07005465 alias_ty val;
5466 res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &val, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005467 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005468 if (len != PyList_GET_SIZE(tmp)) {
5469 PyErr_SetString(PyExc_RuntimeError, "ImportFrom field \"names\" changed size during iteration");
5470 goto failed;
5471 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07005472 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005473 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005474 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005475 } else {
5476 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom");
5477 return 1;
5478 }
Victor Stinneree4b59c2013-07-27 00:01:35 +02005479 if (exists_not_none(obj, &PyId_level)) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005480 int res;
5481 tmp = _PyObject_GetAttrId(obj, &PyId_level);
5482 if (tmp == NULL) goto failed;
5483 res = obj2ast_int(tmp, &level, arena);
5484 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005485 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005486 } else {
5487 level = 0;
5488 }
5489 *out = ImportFrom(module, names, level, lineno, col_offset, arena);
5490 if (*out == NULL) goto failed;
5491 return 0;
5492 }
5493 isinstance = PyObject_IsInstance(obj, (PyObject*)Global_type);
5494 if (isinstance == -1) {
5495 return 1;
5496 }
5497 if (isinstance) {
5498 asdl_seq* names;
5499
5500 if (_PyObject_HasAttrId(obj, &PyId_names)) {
5501 int res;
5502 Py_ssize_t len;
5503 Py_ssize_t i;
5504 tmp = _PyObject_GetAttrId(obj, &PyId_names);
5505 if (tmp == NULL) goto failed;
5506 if (!PyList_Check(tmp)) {
5507 PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5508 goto failed;
5509 }
5510 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005511 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005512 if (names == NULL) goto failed;
5513 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07005514 identifier val;
5515 res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &val, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005516 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005517 if (len != PyList_GET_SIZE(tmp)) {
5518 PyErr_SetString(PyExc_RuntimeError, "Global field \"names\" changed size during iteration");
5519 goto failed;
5520 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07005521 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005522 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005523 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005524 } else {
5525 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global");
5526 return 1;
5527 }
5528 *out = Global(names, lineno, col_offset, arena);
5529 if (*out == NULL) goto failed;
5530 return 0;
5531 }
5532 isinstance = PyObject_IsInstance(obj, (PyObject*)Nonlocal_type);
5533 if (isinstance == -1) {
5534 return 1;
5535 }
5536 if (isinstance) {
5537 asdl_seq* names;
5538
5539 if (_PyObject_HasAttrId(obj, &PyId_names)) {
5540 int res;
5541 Py_ssize_t len;
5542 Py_ssize_t i;
5543 tmp = _PyObject_GetAttrId(obj, &PyId_names);
5544 if (tmp == NULL) goto failed;
5545 if (!PyList_Check(tmp)) {
5546 PyErr_Format(PyExc_TypeError, "Nonlocal field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5547 goto failed;
5548 }
5549 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005550 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005551 if (names == NULL) goto failed;
5552 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07005553 identifier val;
5554 res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &val, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005555 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005556 if (len != PyList_GET_SIZE(tmp)) {
5557 PyErr_SetString(PyExc_RuntimeError, "Nonlocal field \"names\" changed size during iteration");
5558 goto failed;
5559 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07005560 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005561 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005562 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005563 } else {
5564 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal");
5565 return 1;
5566 }
5567 *out = Nonlocal(names, lineno, col_offset, arena);
5568 if (*out == NULL) goto failed;
5569 return 0;
5570 }
5571 isinstance = PyObject_IsInstance(obj, (PyObject*)Expr_type);
5572 if (isinstance == -1) {
5573 return 1;
5574 }
5575 if (isinstance) {
5576 expr_ty value;
5577
5578 if (_PyObject_HasAttrId(obj, &PyId_value)) {
5579 int res;
5580 tmp = _PyObject_GetAttrId(obj, &PyId_value);
5581 if (tmp == NULL) goto failed;
5582 res = obj2ast_expr(tmp, &value, arena);
5583 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005584 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005585 } else {
5586 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr");
5587 return 1;
5588 }
5589 *out = Expr(value, lineno, col_offset, arena);
5590 if (*out == NULL) goto failed;
5591 return 0;
5592 }
5593 isinstance = PyObject_IsInstance(obj, (PyObject*)Pass_type);
5594 if (isinstance == -1) {
5595 return 1;
5596 }
5597 if (isinstance) {
5598
5599 *out = Pass(lineno, col_offset, arena);
5600 if (*out == NULL) goto failed;
5601 return 0;
5602 }
5603 isinstance = PyObject_IsInstance(obj, (PyObject*)Break_type);
5604 if (isinstance == -1) {
5605 return 1;
5606 }
5607 if (isinstance) {
5608
5609 *out = Break(lineno, col_offset, arena);
5610 if (*out == NULL) goto failed;
5611 return 0;
5612 }
5613 isinstance = PyObject_IsInstance(obj, (PyObject*)Continue_type);
5614 if (isinstance == -1) {
5615 return 1;
5616 }
5617 if (isinstance) {
5618
5619 *out = Continue(lineno, col_offset, arena);
5620 if (*out == NULL) goto failed;
5621 return 0;
5622 }
5623
5624 PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj);
5625 failed:
5626 Py_XDECREF(tmp);
5627 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005628}
5629
5630int
5631obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
5632{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005633 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005634
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005635 PyObject *tmp = NULL;
5636 int lineno;
5637 int col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005638
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005639 if (obj == Py_None) {
5640 *out = NULL;
5641 return 0;
5642 }
5643 if (_PyObject_HasAttrId(obj, &PyId_lineno)) {
5644 int res;
5645 tmp = _PyObject_GetAttrId(obj, &PyId_lineno);
5646 if (tmp == NULL) goto failed;
5647 res = obj2ast_int(tmp, &lineno, arena);
5648 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005649 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005650 } else {
5651 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr");
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005652 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005653 }
5654 if (_PyObject_HasAttrId(obj, &PyId_col_offset)) {
5655 int res;
5656 tmp = _PyObject_GetAttrId(obj, &PyId_col_offset);
5657 if (tmp == NULL) goto failed;
5658 res = obj2ast_int(tmp, &col_offset, arena);
5659 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005660 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005661 } else {
5662 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr");
5663 return 1;
5664 }
5665 isinstance = PyObject_IsInstance(obj, (PyObject*)BoolOp_type);
5666 if (isinstance == -1) {
5667 return 1;
5668 }
5669 if (isinstance) {
5670 boolop_ty op;
5671 asdl_seq* values;
5672
5673 if (_PyObject_HasAttrId(obj, &PyId_op)) {
5674 int res;
5675 tmp = _PyObject_GetAttrId(obj, &PyId_op);
5676 if (tmp == NULL) goto failed;
5677 res = obj2ast_boolop(tmp, &op, arena);
5678 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005679 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005680 } else {
5681 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp");
5682 return 1;
5683 }
5684 if (_PyObject_HasAttrId(obj, &PyId_values)) {
5685 int res;
5686 Py_ssize_t len;
5687 Py_ssize_t i;
5688 tmp = _PyObject_GetAttrId(obj, &PyId_values);
5689 if (tmp == NULL) goto failed;
5690 if (!PyList_Check(tmp)) {
5691 PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5692 goto failed;
5693 }
5694 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005695 values = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005696 if (values == NULL) goto failed;
5697 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07005698 expr_ty val;
5699 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005700 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005701 if (len != PyList_GET_SIZE(tmp)) {
5702 PyErr_SetString(PyExc_RuntimeError, "BoolOp field \"values\" changed size during iteration");
5703 goto failed;
5704 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07005705 asdl_seq_SET(values, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005706 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005707 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005708 } else {
5709 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp");
5710 return 1;
5711 }
5712 *out = BoolOp(op, values, lineno, col_offset, arena);
5713 if (*out == NULL) goto failed;
5714 return 0;
5715 }
5716 isinstance = PyObject_IsInstance(obj, (PyObject*)BinOp_type);
5717 if (isinstance == -1) {
5718 return 1;
5719 }
5720 if (isinstance) {
5721 expr_ty left;
5722 operator_ty op;
5723 expr_ty right;
5724
5725 if (_PyObject_HasAttrId(obj, &PyId_left)) {
5726 int res;
5727 tmp = _PyObject_GetAttrId(obj, &PyId_left);
5728 if (tmp == NULL) goto failed;
5729 res = obj2ast_expr(tmp, &left, arena);
5730 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005731 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005732 } else {
5733 PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp");
5734 return 1;
5735 }
5736 if (_PyObject_HasAttrId(obj, &PyId_op)) {
5737 int res;
5738 tmp = _PyObject_GetAttrId(obj, &PyId_op);
5739 if (tmp == NULL) goto failed;
5740 res = obj2ast_operator(tmp, &op, arena);
5741 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005742 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005743 } else {
5744 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp");
5745 return 1;
5746 }
5747 if (_PyObject_HasAttrId(obj, &PyId_right)) {
5748 int res;
5749 tmp = _PyObject_GetAttrId(obj, &PyId_right);
5750 if (tmp == NULL) goto failed;
5751 res = obj2ast_expr(tmp, &right, arena);
5752 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005753 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005754 } else {
5755 PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp");
5756 return 1;
5757 }
5758 *out = BinOp(left, op, right, lineno, col_offset, arena);
5759 if (*out == NULL) goto failed;
5760 return 0;
5761 }
5762 isinstance = PyObject_IsInstance(obj, (PyObject*)UnaryOp_type);
5763 if (isinstance == -1) {
5764 return 1;
5765 }
5766 if (isinstance) {
5767 unaryop_ty op;
5768 expr_ty operand;
5769
5770 if (_PyObject_HasAttrId(obj, &PyId_op)) {
5771 int res;
5772 tmp = _PyObject_GetAttrId(obj, &PyId_op);
5773 if (tmp == NULL) goto failed;
5774 res = obj2ast_unaryop(tmp, &op, arena);
5775 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005776 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005777 } else {
5778 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp");
5779 return 1;
5780 }
5781 if (_PyObject_HasAttrId(obj, &PyId_operand)) {
5782 int res;
5783 tmp = _PyObject_GetAttrId(obj, &PyId_operand);
5784 if (tmp == NULL) goto failed;
5785 res = obj2ast_expr(tmp, &operand, arena);
5786 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005787 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005788 } else {
5789 PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp");
5790 return 1;
5791 }
5792 *out = UnaryOp(op, operand, lineno, col_offset, arena);
5793 if (*out == NULL) goto failed;
5794 return 0;
5795 }
5796 isinstance = PyObject_IsInstance(obj, (PyObject*)Lambda_type);
5797 if (isinstance == -1) {
5798 return 1;
5799 }
5800 if (isinstance) {
5801 arguments_ty args;
5802 expr_ty body;
5803
5804 if (_PyObject_HasAttrId(obj, &PyId_args)) {
5805 int res;
5806 tmp = _PyObject_GetAttrId(obj, &PyId_args);
5807 if (tmp == NULL) goto failed;
5808 res = obj2ast_arguments(tmp, &args, arena);
5809 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005810 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005811 } else {
5812 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda");
5813 return 1;
5814 }
5815 if (_PyObject_HasAttrId(obj, &PyId_body)) {
5816 int res;
5817 tmp = _PyObject_GetAttrId(obj, &PyId_body);
5818 if (tmp == NULL) goto failed;
5819 res = obj2ast_expr(tmp, &body, arena);
5820 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005821 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005822 } else {
5823 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda");
5824 return 1;
5825 }
5826 *out = Lambda(args, body, lineno, col_offset, arena);
5827 if (*out == NULL) goto failed;
5828 return 0;
5829 }
5830 isinstance = PyObject_IsInstance(obj, (PyObject*)IfExp_type);
5831 if (isinstance == -1) {
5832 return 1;
5833 }
5834 if (isinstance) {
5835 expr_ty test;
5836 expr_ty body;
5837 expr_ty orelse;
5838
5839 if (_PyObject_HasAttrId(obj, &PyId_test)) {
5840 int res;
5841 tmp = _PyObject_GetAttrId(obj, &PyId_test);
5842 if (tmp == NULL) goto failed;
5843 res = obj2ast_expr(tmp, &test, arena);
5844 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005845 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005846 } else {
5847 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp");
5848 return 1;
5849 }
5850 if (_PyObject_HasAttrId(obj, &PyId_body)) {
5851 int res;
5852 tmp = _PyObject_GetAttrId(obj, &PyId_body);
5853 if (tmp == NULL) goto failed;
5854 res = obj2ast_expr(tmp, &body, arena);
5855 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005856 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005857 } else {
5858 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp");
5859 return 1;
5860 }
5861 if (_PyObject_HasAttrId(obj, &PyId_orelse)) {
5862 int res;
5863 tmp = _PyObject_GetAttrId(obj, &PyId_orelse);
5864 if (tmp == NULL) goto failed;
5865 res = obj2ast_expr(tmp, &orelse, arena);
5866 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005867 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005868 } else {
5869 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp");
5870 return 1;
5871 }
5872 *out = IfExp(test, body, orelse, lineno, col_offset, arena);
5873 if (*out == NULL) goto failed;
5874 return 0;
5875 }
5876 isinstance = PyObject_IsInstance(obj, (PyObject*)Dict_type);
5877 if (isinstance == -1) {
5878 return 1;
5879 }
5880 if (isinstance) {
5881 asdl_seq* keys;
5882 asdl_seq* values;
5883
5884 if (_PyObject_HasAttrId(obj, &PyId_keys)) {
5885 int res;
5886 Py_ssize_t len;
5887 Py_ssize_t i;
5888 tmp = _PyObject_GetAttrId(obj, &PyId_keys);
5889 if (tmp == NULL) goto failed;
5890 if (!PyList_Check(tmp)) {
5891 PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5892 goto failed;
5893 }
5894 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005895 keys = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005896 if (keys == NULL) goto failed;
5897 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07005898 expr_ty val;
5899 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005900 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005901 if (len != PyList_GET_SIZE(tmp)) {
5902 PyErr_SetString(PyExc_RuntimeError, "Dict field \"keys\" changed size during iteration");
5903 goto failed;
5904 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07005905 asdl_seq_SET(keys, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005906 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005907 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005908 } else {
5909 PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict");
5910 return 1;
5911 }
5912 if (_PyObject_HasAttrId(obj, &PyId_values)) {
5913 int res;
5914 Py_ssize_t len;
5915 Py_ssize_t i;
5916 tmp = _PyObject_GetAttrId(obj, &PyId_values);
5917 if (tmp == NULL) goto failed;
5918 if (!PyList_Check(tmp)) {
5919 PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5920 goto failed;
5921 }
5922 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005923 values = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005924 if (values == NULL) goto failed;
5925 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07005926 expr_ty val;
5927 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005928 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005929 if (len != PyList_GET_SIZE(tmp)) {
5930 PyErr_SetString(PyExc_RuntimeError, "Dict field \"values\" changed size during iteration");
5931 goto failed;
5932 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07005933 asdl_seq_SET(values, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005934 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005935 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005936 } else {
5937 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict");
5938 return 1;
5939 }
5940 *out = Dict(keys, values, lineno, col_offset, arena);
5941 if (*out == NULL) goto failed;
5942 return 0;
5943 }
5944 isinstance = PyObject_IsInstance(obj, (PyObject*)Set_type);
5945 if (isinstance == -1) {
5946 return 1;
5947 }
5948 if (isinstance) {
5949 asdl_seq* elts;
5950
5951 if (_PyObject_HasAttrId(obj, &PyId_elts)) {
5952 int res;
5953 Py_ssize_t len;
5954 Py_ssize_t i;
5955 tmp = _PyObject_GetAttrId(obj, &PyId_elts);
5956 if (tmp == NULL) goto failed;
5957 if (!PyList_Check(tmp)) {
5958 PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5959 goto failed;
5960 }
5961 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005962 elts = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005963 if (elts == NULL) goto failed;
5964 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07005965 expr_ty val;
5966 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005967 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005968 if (len != PyList_GET_SIZE(tmp)) {
5969 PyErr_SetString(PyExc_RuntimeError, "Set field \"elts\" changed size during iteration");
5970 goto failed;
5971 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07005972 asdl_seq_SET(elts, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005973 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005974 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005975 } else {
5976 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set");
5977 return 1;
5978 }
5979 *out = Set(elts, lineno, col_offset, arena);
5980 if (*out == NULL) goto failed;
5981 return 0;
5982 }
5983 isinstance = PyObject_IsInstance(obj, (PyObject*)ListComp_type);
5984 if (isinstance == -1) {
5985 return 1;
5986 }
5987 if (isinstance) {
5988 expr_ty elt;
5989 asdl_seq* generators;
5990
5991 if (_PyObject_HasAttrId(obj, &PyId_elt)) {
5992 int res;
5993 tmp = _PyObject_GetAttrId(obj, &PyId_elt);
5994 if (tmp == NULL) goto failed;
5995 res = obj2ast_expr(tmp, &elt, arena);
5996 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005997 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005998 } else {
5999 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp");
6000 return 1;
6001 }
6002 if (_PyObject_HasAttrId(obj, &PyId_generators)) {
6003 int res;
6004 Py_ssize_t len;
6005 Py_ssize_t i;
6006 tmp = _PyObject_GetAttrId(obj, &PyId_generators);
6007 if (tmp == NULL) goto failed;
6008 if (!PyList_Check(tmp)) {
6009 PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name);
6010 goto failed;
6011 }
6012 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006013 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006014 if (generators == NULL) goto failed;
6015 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07006016 comprehension_ty val;
6017 res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &val, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006018 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006019 if (len != PyList_GET_SIZE(tmp)) {
6020 PyErr_SetString(PyExc_RuntimeError, "ListComp field \"generators\" changed size during iteration");
6021 goto failed;
6022 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07006023 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006024 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006025 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006026 } else {
6027 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp");
6028 return 1;
6029 }
6030 *out = ListComp(elt, generators, lineno, col_offset, arena);
6031 if (*out == NULL) goto failed;
6032 return 0;
6033 }
6034 isinstance = PyObject_IsInstance(obj, (PyObject*)SetComp_type);
6035 if (isinstance == -1) {
6036 return 1;
6037 }
6038 if (isinstance) {
6039 expr_ty elt;
6040 asdl_seq* generators;
6041
6042 if (_PyObject_HasAttrId(obj, &PyId_elt)) {
6043 int res;
6044 tmp = _PyObject_GetAttrId(obj, &PyId_elt);
6045 if (tmp == NULL) goto failed;
6046 res = obj2ast_expr(tmp, &elt, arena);
6047 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006048 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006049 } else {
6050 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp");
6051 return 1;
6052 }
6053 if (_PyObject_HasAttrId(obj, &PyId_generators)) {
6054 int res;
6055 Py_ssize_t len;
6056 Py_ssize_t i;
6057 tmp = _PyObject_GetAttrId(obj, &PyId_generators);
6058 if (tmp == NULL) goto failed;
6059 if (!PyList_Check(tmp)) {
6060 PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name);
6061 goto failed;
6062 }
6063 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006064 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006065 if (generators == NULL) goto failed;
6066 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07006067 comprehension_ty val;
6068 res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &val, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006069 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006070 if (len != PyList_GET_SIZE(tmp)) {
6071 PyErr_SetString(PyExc_RuntimeError, "SetComp field \"generators\" changed size during iteration");
6072 goto failed;
6073 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07006074 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006075 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006076 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006077 } else {
6078 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp");
6079 return 1;
6080 }
6081 *out = SetComp(elt, generators, lineno, col_offset, arena);
6082 if (*out == NULL) goto failed;
6083 return 0;
6084 }
6085 isinstance = PyObject_IsInstance(obj, (PyObject*)DictComp_type);
6086 if (isinstance == -1) {
6087 return 1;
6088 }
6089 if (isinstance) {
6090 expr_ty key;
6091 expr_ty value;
6092 asdl_seq* generators;
6093
6094 if (_PyObject_HasAttrId(obj, &PyId_key)) {
6095 int res;
6096 tmp = _PyObject_GetAttrId(obj, &PyId_key);
6097 if (tmp == NULL) goto failed;
6098 res = obj2ast_expr(tmp, &key, arena);
6099 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006100 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006101 } else {
6102 PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp");
6103 return 1;
6104 }
6105 if (_PyObject_HasAttrId(obj, &PyId_value)) {
6106 int res;
6107 tmp = _PyObject_GetAttrId(obj, &PyId_value);
6108 if (tmp == NULL) goto failed;
6109 res = obj2ast_expr(tmp, &value, arena);
6110 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006111 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006112 } else {
6113 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp");
6114 return 1;
6115 }
6116 if (_PyObject_HasAttrId(obj, &PyId_generators)) {
6117 int res;
6118 Py_ssize_t len;
6119 Py_ssize_t i;
6120 tmp = _PyObject_GetAttrId(obj, &PyId_generators);
6121 if (tmp == NULL) goto failed;
6122 if (!PyList_Check(tmp)) {
6123 PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name);
6124 goto failed;
6125 }
6126 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006127 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006128 if (generators == NULL) goto failed;
6129 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07006130 comprehension_ty val;
6131 res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &val, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006132 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006133 if (len != PyList_GET_SIZE(tmp)) {
6134 PyErr_SetString(PyExc_RuntimeError, "DictComp field \"generators\" changed size during iteration");
6135 goto failed;
6136 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07006137 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006138 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006139 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006140 } else {
6141 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp");
6142 return 1;
6143 }
6144 *out = DictComp(key, value, generators, lineno, col_offset, arena);
6145 if (*out == NULL) goto failed;
6146 return 0;
6147 }
6148 isinstance = PyObject_IsInstance(obj, (PyObject*)GeneratorExp_type);
6149 if (isinstance == -1) {
6150 return 1;
6151 }
6152 if (isinstance) {
6153 expr_ty elt;
6154 asdl_seq* generators;
6155
6156 if (_PyObject_HasAttrId(obj, &PyId_elt)) {
6157 int res;
6158 tmp = _PyObject_GetAttrId(obj, &PyId_elt);
6159 if (tmp == NULL) goto failed;
6160 res = obj2ast_expr(tmp, &elt, arena);
6161 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006162 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006163 } else {
6164 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp");
6165 return 1;
6166 }
6167 if (_PyObject_HasAttrId(obj, &PyId_generators)) {
6168 int res;
6169 Py_ssize_t len;
6170 Py_ssize_t i;
6171 tmp = _PyObject_GetAttrId(obj, &PyId_generators);
6172 if (tmp == NULL) goto failed;
6173 if (!PyList_Check(tmp)) {
6174 PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name);
6175 goto failed;
6176 }
6177 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006178 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006179 if (generators == NULL) goto failed;
6180 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07006181 comprehension_ty val;
6182 res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &val, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006183 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006184 if (len != PyList_GET_SIZE(tmp)) {
6185 PyErr_SetString(PyExc_RuntimeError, "GeneratorExp field \"generators\" changed size during iteration");
6186 goto failed;
6187 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07006188 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006189 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006190 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006191 } else {
6192 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp");
6193 return 1;
6194 }
6195 *out = GeneratorExp(elt, generators, lineno, col_offset, arena);
6196 if (*out == NULL) goto failed;
6197 return 0;
6198 }
Yury Selivanov75445082015-05-11 22:57:16 -04006199 isinstance = PyObject_IsInstance(obj, (PyObject*)Await_type);
6200 if (isinstance == -1) {
6201 return 1;
6202 }
6203 if (isinstance) {
6204 expr_ty value;
6205
6206 if (_PyObject_HasAttrId(obj, &PyId_value)) {
6207 int res;
6208 tmp = _PyObject_GetAttrId(obj, &PyId_value);
6209 if (tmp == NULL) goto failed;
6210 res = obj2ast_expr(tmp, &value, arena);
6211 if (res != 0) goto failed;
6212 Py_CLEAR(tmp);
6213 } else {
6214 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Await");
6215 return 1;
6216 }
6217 *out = Await(value, lineno, col_offset, arena);
6218 if (*out == NULL) goto failed;
6219 return 0;
6220 }
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006221 isinstance = PyObject_IsInstance(obj, (PyObject*)Yield_type);
6222 if (isinstance == -1) {
6223 return 1;
6224 }
6225 if (isinstance) {
6226 expr_ty value;
6227
Victor Stinneree4b59c2013-07-27 00:01:35 +02006228 if (exists_not_none(obj, &PyId_value)) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006229 int res;
6230 tmp = _PyObject_GetAttrId(obj, &PyId_value);
6231 if (tmp == NULL) goto failed;
6232 res = obj2ast_expr(tmp, &value, arena);
6233 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006234 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006235 } else {
6236 value = NULL;
6237 }
6238 *out = Yield(value, lineno, col_offset, arena);
6239 if (*out == NULL) goto failed;
6240 return 0;
6241 }
6242 isinstance = PyObject_IsInstance(obj, (PyObject*)YieldFrom_type);
6243 if (isinstance == -1) {
6244 return 1;
6245 }
6246 if (isinstance) {
6247 expr_ty value;
6248
6249 if (_PyObject_HasAttrId(obj, &PyId_value)) {
6250 int res;
6251 tmp = _PyObject_GetAttrId(obj, &PyId_value);
6252 if (tmp == NULL) goto failed;
6253 res = obj2ast_expr(tmp, &value, arena);
6254 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006255 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006256 } else {
6257 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom");
6258 return 1;
6259 }
6260 *out = YieldFrom(value, lineno, col_offset, arena);
6261 if (*out == NULL) goto failed;
6262 return 0;
6263 }
6264 isinstance = PyObject_IsInstance(obj, (PyObject*)Compare_type);
6265 if (isinstance == -1) {
6266 return 1;
6267 }
6268 if (isinstance) {
6269 expr_ty left;
6270 asdl_int_seq* ops;
6271 asdl_seq* comparators;
6272
6273 if (_PyObject_HasAttrId(obj, &PyId_left)) {
6274 int res;
6275 tmp = _PyObject_GetAttrId(obj, &PyId_left);
6276 if (tmp == NULL) goto failed;
6277 res = obj2ast_expr(tmp, &left, arena);
6278 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006279 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006280 } else {
6281 PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare");
6282 return 1;
6283 }
6284 if (_PyObject_HasAttrId(obj, &PyId_ops)) {
6285 int res;
6286 Py_ssize_t len;
6287 Py_ssize_t i;
6288 tmp = _PyObject_GetAttrId(obj, &PyId_ops);
6289 if (tmp == NULL) goto failed;
6290 if (!PyList_Check(tmp)) {
6291 PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", tmp->ob_type->tp_name);
6292 goto failed;
6293 }
6294 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006295 ops = _Py_asdl_int_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006296 if (ops == NULL) goto failed;
6297 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07006298 cmpop_ty val;
6299 res = obj2ast_cmpop(PyList_GET_ITEM(tmp, i), &val, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006300 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006301 if (len != PyList_GET_SIZE(tmp)) {
6302 PyErr_SetString(PyExc_RuntimeError, "Compare field \"ops\" changed size during iteration");
6303 goto failed;
6304 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07006305 asdl_seq_SET(ops, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006306 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006307 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006308 } else {
6309 PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare");
6310 return 1;
6311 }
6312 if (_PyObject_HasAttrId(obj, &PyId_comparators)) {
6313 int res;
6314 Py_ssize_t len;
6315 Py_ssize_t i;
6316 tmp = _PyObject_GetAttrId(obj, &PyId_comparators);
6317 if (tmp == NULL) goto failed;
6318 if (!PyList_Check(tmp)) {
6319 PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", tmp->ob_type->tp_name);
6320 goto failed;
6321 }
6322 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006323 comparators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006324 if (comparators == NULL) goto failed;
6325 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07006326 expr_ty val;
6327 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006328 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006329 if (len != PyList_GET_SIZE(tmp)) {
6330 PyErr_SetString(PyExc_RuntimeError, "Compare field \"comparators\" changed size during iteration");
6331 goto failed;
6332 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07006333 asdl_seq_SET(comparators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006334 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006335 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006336 } else {
6337 PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare");
6338 return 1;
6339 }
6340 *out = Compare(left, ops, comparators, lineno, col_offset, arena);
6341 if (*out == NULL) goto failed;
6342 return 0;
6343 }
6344 isinstance = PyObject_IsInstance(obj, (PyObject*)Call_type);
6345 if (isinstance == -1) {
6346 return 1;
6347 }
6348 if (isinstance) {
6349 expr_ty func;
6350 asdl_seq* args;
6351 asdl_seq* keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006352
6353 if (_PyObject_HasAttrId(obj, &PyId_func)) {
6354 int res;
6355 tmp = _PyObject_GetAttrId(obj, &PyId_func);
6356 if (tmp == NULL) goto failed;
6357 res = obj2ast_expr(tmp, &func, arena);
6358 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006359 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006360 } else {
6361 PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call");
6362 return 1;
6363 }
6364 if (_PyObject_HasAttrId(obj, &PyId_args)) {
6365 int res;
6366 Py_ssize_t len;
6367 Py_ssize_t i;
6368 tmp = _PyObject_GetAttrId(obj, &PyId_args);
6369 if (tmp == NULL) goto failed;
6370 if (!PyList_Check(tmp)) {
6371 PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name);
6372 goto failed;
6373 }
6374 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006375 args = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006376 if (args == NULL) goto failed;
6377 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07006378 expr_ty val;
6379 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006380 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006381 if (len != PyList_GET_SIZE(tmp)) {
6382 PyErr_SetString(PyExc_RuntimeError, "Call field \"args\" changed size during iteration");
6383 goto failed;
6384 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07006385 asdl_seq_SET(args, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006386 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006387 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006388 } else {
6389 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call");
6390 return 1;
6391 }
6392 if (_PyObject_HasAttrId(obj, &PyId_keywords)) {
6393 int res;
6394 Py_ssize_t len;
6395 Py_ssize_t i;
6396 tmp = _PyObject_GetAttrId(obj, &PyId_keywords);
6397 if (tmp == NULL) goto failed;
6398 if (!PyList_Check(tmp)) {
6399 PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name);
6400 goto failed;
6401 }
6402 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006403 keywords = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006404 if (keywords == NULL) goto failed;
6405 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07006406 keyword_ty val;
6407 res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &val, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006408 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006409 if (len != PyList_GET_SIZE(tmp)) {
6410 PyErr_SetString(PyExc_RuntimeError, "Call field \"keywords\" changed size during iteration");
6411 goto failed;
6412 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07006413 asdl_seq_SET(keywords, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006414 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006415 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006416 } else {
6417 PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call");
6418 return 1;
6419 }
Benjamin Peterson025e9eb2015-05-05 20:16:41 -04006420 *out = Call(func, args, keywords, lineno, col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006421 if (*out == NULL) goto failed;
6422 return 0;
6423 }
6424 isinstance = PyObject_IsInstance(obj, (PyObject*)Num_type);
6425 if (isinstance == -1) {
6426 return 1;
6427 }
6428 if (isinstance) {
6429 object n;
6430
6431 if (_PyObject_HasAttrId(obj, &PyId_n)) {
6432 int res;
6433 tmp = _PyObject_GetAttrId(obj, &PyId_n);
6434 if (tmp == NULL) goto failed;
6435 res = obj2ast_object(tmp, &n, arena);
6436 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006437 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006438 } else {
6439 PyErr_SetString(PyExc_TypeError, "required field \"n\" missing from Num");
6440 return 1;
6441 }
6442 *out = Num(n, lineno, col_offset, arena);
6443 if (*out == NULL) goto failed;
6444 return 0;
6445 }
6446 isinstance = PyObject_IsInstance(obj, (PyObject*)Str_type);
6447 if (isinstance == -1) {
6448 return 1;
6449 }
6450 if (isinstance) {
6451 string s;
6452
6453 if (_PyObject_HasAttrId(obj, &PyId_s)) {
6454 int res;
6455 tmp = _PyObject_GetAttrId(obj, &PyId_s);
6456 if (tmp == NULL) goto failed;
6457 res = obj2ast_string(tmp, &s, arena);
6458 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006459 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006460 } else {
6461 PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Str");
6462 return 1;
6463 }
6464 *out = Str(s, lineno, col_offset, arena);
6465 if (*out == NULL) goto failed;
6466 return 0;
6467 }
Eric V. Smith235a6f02015-09-19 14:51:32 -04006468 isinstance = PyObject_IsInstance(obj, (PyObject*)FormattedValue_type);
6469 if (isinstance == -1) {
6470 return 1;
6471 }
6472 if (isinstance) {
6473 expr_ty value;
6474 int conversion;
6475 expr_ty format_spec;
6476
6477 if (_PyObject_HasAttrId(obj, &PyId_value)) {
6478 int res;
6479 tmp = _PyObject_GetAttrId(obj, &PyId_value);
6480 if (tmp == NULL) goto failed;
6481 res = obj2ast_expr(tmp, &value, arena);
6482 if (res != 0) goto failed;
6483 Py_CLEAR(tmp);
6484 } else {
6485 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from FormattedValue");
6486 return 1;
6487 }
6488 if (exists_not_none(obj, &PyId_conversion)) {
6489 int res;
6490 tmp = _PyObject_GetAttrId(obj, &PyId_conversion);
6491 if (tmp == NULL) goto failed;
6492 res = obj2ast_int(tmp, &conversion, arena);
6493 if (res != 0) goto failed;
6494 Py_CLEAR(tmp);
6495 } else {
6496 conversion = 0;
6497 }
6498 if (exists_not_none(obj, &PyId_format_spec)) {
6499 int res;
6500 tmp = _PyObject_GetAttrId(obj, &PyId_format_spec);
6501 if (tmp == NULL) goto failed;
6502 res = obj2ast_expr(tmp, &format_spec, arena);
6503 if (res != 0) goto failed;
6504 Py_CLEAR(tmp);
6505 } else {
6506 format_spec = NULL;
6507 }
6508 *out = FormattedValue(value, conversion, format_spec, lineno,
6509 col_offset, arena);
6510 if (*out == NULL) goto failed;
6511 return 0;
6512 }
6513 isinstance = PyObject_IsInstance(obj, (PyObject*)JoinedStr_type);
6514 if (isinstance == -1) {
6515 return 1;
6516 }
6517 if (isinstance) {
6518 asdl_seq* values;
6519
6520 if (_PyObject_HasAttrId(obj, &PyId_values)) {
6521 int res;
6522 Py_ssize_t len;
6523 Py_ssize_t i;
6524 tmp = _PyObject_GetAttrId(obj, &PyId_values);
6525 if (tmp == NULL) goto failed;
6526 if (!PyList_Check(tmp)) {
6527 PyErr_Format(PyExc_TypeError, "JoinedStr field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name);
6528 goto failed;
6529 }
6530 len = PyList_GET_SIZE(tmp);
6531 values = _Py_asdl_seq_new(len, arena);
6532 if (values == NULL) goto failed;
6533 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07006534 expr_ty val;
6535 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
Eric V. Smith235a6f02015-09-19 14:51:32 -04006536 if (res != 0) goto failed;
Serhiy Storchaka5e808552016-10-07 21:55:49 +03006537 if (len != PyList_GET_SIZE(tmp)) {
6538 PyErr_SetString(PyExc_RuntimeError, "JoinedStr field \"values\" changed size during iteration");
6539 goto failed;
6540 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07006541 asdl_seq_SET(values, i, val);
Eric V. Smith235a6f02015-09-19 14:51:32 -04006542 }
6543 Py_CLEAR(tmp);
6544 } else {
6545 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from JoinedStr");
6546 return 1;
6547 }
6548 *out = JoinedStr(values, lineno, col_offset, arena);
6549 if (*out == NULL) goto failed;
6550 return 0;
6551 }
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006552 isinstance = PyObject_IsInstance(obj, (PyObject*)Bytes_type);
6553 if (isinstance == -1) {
6554 return 1;
6555 }
6556 if (isinstance) {
6557 bytes s;
6558
6559 if (_PyObject_HasAttrId(obj, &PyId_s)) {
6560 int res;
6561 tmp = _PyObject_GetAttrId(obj, &PyId_s);
6562 if (tmp == NULL) goto failed;
6563 res = obj2ast_bytes(tmp, &s, arena);
6564 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006565 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006566 } else {
6567 PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Bytes");
6568 return 1;
6569 }
6570 *out = Bytes(s, lineno, col_offset, arena);
6571 if (*out == NULL) goto failed;
6572 return 0;
6573 }
Victor Stinneree4b59c2013-07-27 00:01:35 +02006574 isinstance = PyObject_IsInstance(obj, (PyObject*)NameConstant_type);
6575 if (isinstance == -1) {
6576 return 1;
6577 }
6578 if (isinstance) {
6579 singleton value;
6580
6581 if (_PyObject_HasAttrId(obj, &PyId_value)) {
6582 int res;
6583 tmp = _PyObject_GetAttrId(obj, &PyId_value);
6584 if (tmp == NULL) goto failed;
6585 res = obj2ast_singleton(tmp, &value, arena);
6586 if (res != 0) goto failed;
Victor Stinnerb3189902013-07-27 00:04:42 +02006587 Py_CLEAR(tmp);
Victor Stinneree4b59c2013-07-27 00:01:35 +02006588 } else {
6589 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NameConstant");
6590 return 1;
6591 }
6592 *out = NameConstant(value, lineno, col_offset, arena);
6593 if (*out == NULL) goto failed;
6594 return 0;
6595 }
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006596 isinstance = PyObject_IsInstance(obj, (PyObject*)Ellipsis_type);
6597 if (isinstance == -1) {
6598 return 1;
6599 }
6600 if (isinstance) {
6601
6602 *out = Ellipsis(lineno, col_offset, arena);
6603 if (*out == NULL) goto failed;
6604 return 0;
6605 }
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01006606 isinstance = PyObject_IsInstance(obj, (PyObject*)Constant_type);
6607 if (isinstance == -1) {
6608 return 1;
6609 }
6610 if (isinstance) {
6611 constant value;
6612
6613 if (_PyObject_HasAttrId(obj, &PyId_value)) {
6614 int res;
6615 tmp = _PyObject_GetAttrId(obj, &PyId_value);
6616 if (tmp == NULL) goto failed;
6617 res = obj2ast_constant(tmp, &value, arena);
6618 if (res != 0) goto failed;
6619 Py_CLEAR(tmp);
6620 } else {
6621 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Constant");
6622 return 1;
6623 }
6624 *out = Constant(value, lineno, col_offset, arena);
6625 if (*out == NULL) goto failed;
6626 return 0;
6627 }
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006628 isinstance = PyObject_IsInstance(obj, (PyObject*)Attribute_type);
6629 if (isinstance == -1) {
6630 return 1;
6631 }
6632 if (isinstance) {
6633 expr_ty value;
6634 identifier attr;
6635 expr_context_ty ctx;
6636
6637 if (_PyObject_HasAttrId(obj, &PyId_value)) {
6638 int res;
6639 tmp = _PyObject_GetAttrId(obj, &PyId_value);
6640 if (tmp == NULL) goto failed;
6641 res = obj2ast_expr(tmp, &value, arena);
6642 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006643 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006644 } else {
6645 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute");
6646 return 1;
6647 }
6648 if (_PyObject_HasAttrId(obj, &PyId_attr)) {
6649 int res;
6650 tmp = _PyObject_GetAttrId(obj, &PyId_attr);
6651 if (tmp == NULL) goto failed;
6652 res = obj2ast_identifier(tmp, &attr, arena);
6653 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006654 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006655 } else {
6656 PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute");
6657 return 1;
6658 }
6659 if (_PyObject_HasAttrId(obj, &PyId_ctx)) {
6660 int res;
6661 tmp = _PyObject_GetAttrId(obj, &PyId_ctx);
6662 if (tmp == NULL) goto failed;
6663 res = obj2ast_expr_context(tmp, &ctx, arena);
6664 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006665 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006666 } else {
6667 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute");
6668 return 1;
6669 }
6670 *out = Attribute(value, attr, ctx, lineno, col_offset, arena);
6671 if (*out == NULL) goto failed;
6672 return 0;
6673 }
6674 isinstance = PyObject_IsInstance(obj, (PyObject*)Subscript_type);
6675 if (isinstance == -1) {
6676 return 1;
6677 }
6678 if (isinstance) {
6679 expr_ty value;
6680 slice_ty slice;
6681 expr_context_ty ctx;
6682
6683 if (_PyObject_HasAttrId(obj, &PyId_value)) {
6684 int res;
6685 tmp = _PyObject_GetAttrId(obj, &PyId_value);
6686 if (tmp == NULL) goto failed;
6687 res = obj2ast_expr(tmp, &value, arena);
6688 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006689 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006690 } else {
6691 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript");
6692 return 1;
6693 }
6694 if (_PyObject_HasAttrId(obj, &PyId_slice)) {
6695 int res;
6696 tmp = _PyObject_GetAttrId(obj, &PyId_slice);
6697 if (tmp == NULL) goto failed;
6698 res = obj2ast_slice(tmp, &slice, arena);
6699 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006700 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006701 } else {
6702 PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript");
6703 return 1;
6704 }
6705 if (_PyObject_HasAttrId(obj, &PyId_ctx)) {
6706 int res;
6707 tmp = _PyObject_GetAttrId(obj, &PyId_ctx);
6708 if (tmp == NULL) goto failed;
6709 res = obj2ast_expr_context(tmp, &ctx, arena);
6710 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006711 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006712 } else {
6713 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript");
6714 return 1;
6715 }
6716 *out = Subscript(value, slice, ctx, lineno, col_offset, arena);
6717 if (*out == NULL) goto failed;
6718 return 0;
6719 }
6720 isinstance = PyObject_IsInstance(obj, (PyObject*)Starred_type);
6721 if (isinstance == -1) {
6722 return 1;
6723 }
6724 if (isinstance) {
6725 expr_ty value;
6726 expr_context_ty ctx;
6727
6728 if (_PyObject_HasAttrId(obj, &PyId_value)) {
6729 int res;
6730 tmp = _PyObject_GetAttrId(obj, &PyId_value);
6731 if (tmp == NULL) goto failed;
6732 res = obj2ast_expr(tmp, &value, arena);
6733 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006734 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006735 } else {
6736 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred");
6737 return 1;
6738 }
6739 if (_PyObject_HasAttrId(obj, &PyId_ctx)) {
6740 int res;
6741 tmp = _PyObject_GetAttrId(obj, &PyId_ctx);
6742 if (tmp == NULL) goto failed;
6743 res = obj2ast_expr_context(tmp, &ctx, arena);
6744 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006745 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006746 } else {
6747 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred");
6748 return 1;
6749 }
6750 *out = Starred(value, ctx, lineno, col_offset, arena);
6751 if (*out == NULL) goto failed;
6752 return 0;
6753 }
6754 isinstance = PyObject_IsInstance(obj, (PyObject*)Name_type);
6755 if (isinstance == -1) {
6756 return 1;
6757 }
6758 if (isinstance) {
6759 identifier id;
6760 expr_context_ty ctx;
6761
6762 if (_PyObject_HasAttrId(obj, &PyId_id)) {
6763 int res;
6764 tmp = _PyObject_GetAttrId(obj, &PyId_id);
6765 if (tmp == NULL) goto failed;
6766 res = obj2ast_identifier(tmp, &id, arena);
6767 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006768 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006769 } else {
6770 PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name");
6771 return 1;
6772 }
6773 if (_PyObject_HasAttrId(obj, &PyId_ctx)) {
6774 int res;
6775 tmp = _PyObject_GetAttrId(obj, &PyId_ctx);
6776 if (tmp == NULL) goto failed;
6777 res = obj2ast_expr_context(tmp, &ctx, arena);
6778 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006779 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006780 } else {
6781 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name");
6782 return 1;
6783 }
6784 *out = Name(id, ctx, lineno, col_offset, arena);
6785 if (*out == NULL) goto failed;
6786 return 0;
6787 }
6788 isinstance = PyObject_IsInstance(obj, (PyObject*)List_type);
6789 if (isinstance == -1) {
6790 return 1;
6791 }
6792 if (isinstance) {
6793 asdl_seq* elts;
6794 expr_context_ty ctx;
6795
6796 if (_PyObject_HasAttrId(obj, &PyId_elts)) {
6797 int res;
6798 Py_ssize_t len;
6799 Py_ssize_t i;
6800 tmp = _PyObject_GetAttrId(obj, &PyId_elts);
6801 if (tmp == NULL) goto failed;
6802 if (!PyList_Check(tmp)) {
6803 PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name);
6804 goto failed;
6805 }
6806 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006807 elts = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006808 if (elts == NULL) goto failed;
6809 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07006810 expr_ty val;
6811 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006812 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006813 if (len != PyList_GET_SIZE(tmp)) {
6814 PyErr_SetString(PyExc_RuntimeError, "List field \"elts\" changed size during iteration");
6815 goto failed;
6816 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07006817 asdl_seq_SET(elts, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006818 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006819 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006820 } else {
6821 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List");
6822 return 1;
6823 }
6824 if (_PyObject_HasAttrId(obj, &PyId_ctx)) {
6825 int res;
6826 tmp = _PyObject_GetAttrId(obj, &PyId_ctx);
6827 if (tmp == NULL) goto failed;
6828 res = obj2ast_expr_context(tmp, &ctx, arena);
6829 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006830 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006831 } else {
6832 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List");
6833 return 1;
6834 }
6835 *out = List(elts, ctx, lineno, col_offset, arena);
6836 if (*out == NULL) goto failed;
6837 return 0;
6838 }
6839 isinstance = PyObject_IsInstance(obj, (PyObject*)Tuple_type);
6840 if (isinstance == -1) {
6841 return 1;
6842 }
6843 if (isinstance) {
6844 asdl_seq* elts;
6845 expr_context_ty ctx;
6846
6847 if (_PyObject_HasAttrId(obj, &PyId_elts)) {
6848 int res;
6849 Py_ssize_t len;
6850 Py_ssize_t i;
6851 tmp = _PyObject_GetAttrId(obj, &PyId_elts);
6852 if (tmp == NULL) goto failed;
6853 if (!PyList_Check(tmp)) {
6854 PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name);
6855 goto failed;
6856 }
6857 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006858 elts = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006859 if (elts == NULL) goto failed;
6860 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07006861 expr_ty val;
6862 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006863 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006864 if (len != PyList_GET_SIZE(tmp)) {
6865 PyErr_SetString(PyExc_RuntimeError, "Tuple field \"elts\" changed size during iteration");
6866 goto failed;
6867 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07006868 asdl_seq_SET(elts, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006869 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006870 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006871 } else {
6872 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple");
6873 return 1;
6874 }
6875 if (_PyObject_HasAttrId(obj, &PyId_ctx)) {
6876 int res;
6877 tmp = _PyObject_GetAttrId(obj, &PyId_ctx);
6878 if (tmp == NULL) goto failed;
6879 res = obj2ast_expr_context(tmp, &ctx, arena);
6880 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006881 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006882 } else {
6883 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple");
6884 return 1;
6885 }
6886 *out = Tuple(elts, ctx, lineno, col_offset, arena);
6887 if (*out == NULL) goto failed;
6888 return 0;
6889 }
6890
6891 PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj);
6892 failed:
6893 Py_XDECREF(tmp);
6894 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00006895}
6896
6897int
6898obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena)
6899{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006900 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00006901
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006902 isinstance = PyObject_IsInstance(obj, (PyObject *)Load_type);
6903 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00006904 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006905 }
6906 if (isinstance) {
6907 *out = Load;
6908 return 0;
6909 }
6910 isinstance = PyObject_IsInstance(obj, (PyObject *)Store_type);
6911 if (isinstance == -1) {
6912 return 1;
6913 }
6914 if (isinstance) {
6915 *out = Store;
6916 return 0;
6917 }
6918 isinstance = PyObject_IsInstance(obj, (PyObject *)Del_type);
6919 if (isinstance == -1) {
6920 return 1;
6921 }
6922 if (isinstance) {
6923 *out = Del;
6924 return 0;
6925 }
6926 isinstance = PyObject_IsInstance(obj, (PyObject *)AugLoad_type);
6927 if (isinstance == -1) {
6928 return 1;
6929 }
6930 if (isinstance) {
6931 *out = AugLoad;
6932 return 0;
6933 }
6934 isinstance = PyObject_IsInstance(obj, (PyObject *)AugStore_type);
6935 if (isinstance == -1) {
6936 return 1;
6937 }
6938 if (isinstance) {
6939 *out = AugStore;
6940 return 0;
6941 }
6942 isinstance = PyObject_IsInstance(obj, (PyObject *)Param_type);
6943 if (isinstance == -1) {
6944 return 1;
6945 }
6946 if (isinstance) {
6947 *out = Param;
6948 return 0;
6949 }
6950
6951 PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj);
6952 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00006953}
6954
6955int
6956obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena)
6957{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006958 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00006959
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006960 PyObject *tmp = NULL;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00006961
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006962 if (obj == Py_None) {
6963 *out = NULL;
6964 return 0;
6965 }
6966 isinstance = PyObject_IsInstance(obj, (PyObject*)Slice_type);
6967 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00006968 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006969 }
6970 if (isinstance) {
6971 expr_ty lower;
6972 expr_ty upper;
6973 expr_ty step;
6974
Victor Stinneree4b59c2013-07-27 00:01:35 +02006975 if (exists_not_none(obj, &PyId_lower)) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006976 int res;
6977 tmp = _PyObject_GetAttrId(obj, &PyId_lower);
6978 if (tmp == NULL) goto failed;
6979 res = obj2ast_expr(tmp, &lower, arena);
6980 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006981 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006982 } else {
6983 lower = NULL;
6984 }
Victor Stinneree4b59c2013-07-27 00:01:35 +02006985 if (exists_not_none(obj, &PyId_upper)) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006986 int res;
6987 tmp = _PyObject_GetAttrId(obj, &PyId_upper);
6988 if (tmp == NULL) goto failed;
6989 res = obj2ast_expr(tmp, &upper, arena);
6990 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006991 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006992 } else {
6993 upper = NULL;
6994 }
Victor Stinneree4b59c2013-07-27 00:01:35 +02006995 if (exists_not_none(obj, &PyId_step)) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006996 int res;
6997 tmp = _PyObject_GetAttrId(obj, &PyId_step);
6998 if (tmp == NULL) goto failed;
6999 res = obj2ast_expr(tmp, &step, arena);
7000 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007001 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007002 } else {
7003 step = NULL;
7004 }
7005 *out = Slice(lower, upper, step, arena);
7006 if (*out == NULL) goto failed;
7007 return 0;
7008 }
7009 isinstance = PyObject_IsInstance(obj, (PyObject*)ExtSlice_type);
7010 if (isinstance == -1) {
7011 return 1;
7012 }
7013 if (isinstance) {
7014 asdl_seq* dims;
7015
7016 if (_PyObject_HasAttrId(obj, &PyId_dims)) {
7017 int res;
7018 Py_ssize_t len;
7019 Py_ssize_t i;
7020 tmp = _PyObject_GetAttrId(obj, &PyId_dims);
7021 if (tmp == NULL) goto failed;
7022 if (!PyList_Check(tmp)) {
7023 PyErr_Format(PyExc_TypeError, "ExtSlice field \"dims\" must be a list, not a %.200s", tmp->ob_type->tp_name);
7024 goto failed;
7025 }
7026 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007027 dims = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007028 if (dims == NULL) goto failed;
7029 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07007030 slice_ty val;
7031 res = obj2ast_slice(PyList_GET_ITEM(tmp, i), &val, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007032 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007033 if (len != PyList_GET_SIZE(tmp)) {
7034 PyErr_SetString(PyExc_RuntimeError, "ExtSlice field \"dims\" changed size during iteration");
7035 goto failed;
7036 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07007037 asdl_seq_SET(dims, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007038 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007039 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007040 } else {
7041 PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice");
7042 return 1;
7043 }
7044 *out = ExtSlice(dims, arena);
7045 if (*out == NULL) goto failed;
7046 return 0;
7047 }
7048 isinstance = PyObject_IsInstance(obj, (PyObject*)Index_type);
7049 if (isinstance == -1) {
7050 return 1;
7051 }
7052 if (isinstance) {
7053 expr_ty value;
7054
7055 if (_PyObject_HasAttrId(obj, &PyId_value)) {
7056 int res;
7057 tmp = _PyObject_GetAttrId(obj, &PyId_value);
7058 if (tmp == NULL) goto failed;
7059 res = obj2ast_expr(tmp, &value, arena);
7060 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007061 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007062 } else {
7063 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index");
7064 return 1;
7065 }
7066 *out = Index(value, arena);
7067 if (*out == NULL) goto failed;
7068 return 0;
7069 }
7070
7071 PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %R", obj);
7072 failed:
7073 Py_XDECREF(tmp);
7074 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007075}
7076
7077int
7078obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena)
7079{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007080 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007081
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007082 isinstance = PyObject_IsInstance(obj, (PyObject *)And_type);
7083 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007084 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007085 }
7086 if (isinstance) {
7087 *out = And;
7088 return 0;
7089 }
7090 isinstance = PyObject_IsInstance(obj, (PyObject *)Or_type);
7091 if (isinstance == -1) {
7092 return 1;
7093 }
7094 if (isinstance) {
7095 *out = Or;
7096 return 0;
7097 }
7098
7099 PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj);
7100 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007101}
7102
7103int
7104obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena)
7105{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007106 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007107
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007108 isinstance = PyObject_IsInstance(obj, (PyObject *)Add_type);
7109 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007110 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007111 }
7112 if (isinstance) {
7113 *out = Add;
7114 return 0;
7115 }
7116 isinstance = PyObject_IsInstance(obj, (PyObject *)Sub_type);
7117 if (isinstance == -1) {
7118 return 1;
7119 }
7120 if (isinstance) {
7121 *out = Sub;
7122 return 0;
7123 }
7124 isinstance = PyObject_IsInstance(obj, (PyObject *)Mult_type);
7125 if (isinstance == -1) {
7126 return 1;
7127 }
7128 if (isinstance) {
7129 *out = Mult;
7130 return 0;
7131 }
Benjamin Petersond51374e2014-04-09 23:55:56 -04007132 isinstance = PyObject_IsInstance(obj, (PyObject *)MatMult_type);
7133 if (isinstance == -1) {
7134 return 1;
7135 }
7136 if (isinstance) {
7137 *out = MatMult;
7138 return 0;
7139 }
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007140 isinstance = PyObject_IsInstance(obj, (PyObject *)Div_type);
7141 if (isinstance == -1) {
7142 return 1;
7143 }
7144 if (isinstance) {
7145 *out = Div;
7146 return 0;
7147 }
7148 isinstance = PyObject_IsInstance(obj, (PyObject *)Mod_type);
7149 if (isinstance == -1) {
7150 return 1;
7151 }
7152 if (isinstance) {
7153 *out = Mod;
7154 return 0;
7155 }
7156 isinstance = PyObject_IsInstance(obj, (PyObject *)Pow_type);
7157 if (isinstance == -1) {
7158 return 1;
7159 }
7160 if (isinstance) {
7161 *out = Pow;
7162 return 0;
7163 }
7164 isinstance = PyObject_IsInstance(obj, (PyObject *)LShift_type);
7165 if (isinstance == -1) {
7166 return 1;
7167 }
7168 if (isinstance) {
7169 *out = LShift;
7170 return 0;
7171 }
7172 isinstance = PyObject_IsInstance(obj, (PyObject *)RShift_type);
7173 if (isinstance == -1) {
7174 return 1;
7175 }
7176 if (isinstance) {
7177 *out = RShift;
7178 return 0;
7179 }
7180 isinstance = PyObject_IsInstance(obj, (PyObject *)BitOr_type);
7181 if (isinstance == -1) {
7182 return 1;
7183 }
7184 if (isinstance) {
7185 *out = BitOr;
7186 return 0;
7187 }
7188 isinstance = PyObject_IsInstance(obj, (PyObject *)BitXor_type);
7189 if (isinstance == -1) {
7190 return 1;
7191 }
7192 if (isinstance) {
7193 *out = BitXor;
7194 return 0;
7195 }
7196 isinstance = PyObject_IsInstance(obj, (PyObject *)BitAnd_type);
7197 if (isinstance == -1) {
7198 return 1;
7199 }
7200 if (isinstance) {
7201 *out = BitAnd;
7202 return 0;
7203 }
7204 isinstance = PyObject_IsInstance(obj, (PyObject *)FloorDiv_type);
7205 if (isinstance == -1) {
7206 return 1;
7207 }
7208 if (isinstance) {
7209 *out = FloorDiv;
7210 return 0;
7211 }
7212
7213 PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj);
7214 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007215}
7216
7217int
7218obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena)
7219{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007220 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007221
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007222 isinstance = PyObject_IsInstance(obj, (PyObject *)Invert_type);
7223 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007224 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007225 }
7226 if (isinstance) {
7227 *out = Invert;
7228 return 0;
7229 }
7230 isinstance = PyObject_IsInstance(obj, (PyObject *)Not_type);
7231 if (isinstance == -1) {
7232 return 1;
7233 }
7234 if (isinstance) {
7235 *out = Not;
7236 return 0;
7237 }
7238 isinstance = PyObject_IsInstance(obj, (PyObject *)UAdd_type);
7239 if (isinstance == -1) {
7240 return 1;
7241 }
7242 if (isinstance) {
7243 *out = UAdd;
7244 return 0;
7245 }
7246 isinstance = PyObject_IsInstance(obj, (PyObject *)USub_type);
7247 if (isinstance == -1) {
7248 return 1;
7249 }
7250 if (isinstance) {
7251 *out = USub;
7252 return 0;
7253 }
7254
7255 PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj);
7256 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007257}
7258
7259int
7260obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena)
7261{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007262 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007263
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007264 isinstance = PyObject_IsInstance(obj, (PyObject *)Eq_type);
7265 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007266 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007267 }
7268 if (isinstance) {
7269 *out = Eq;
7270 return 0;
7271 }
7272 isinstance = PyObject_IsInstance(obj, (PyObject *)NotEq_type);
7273 if (isinstance == -1) {
7274 return 1;
7275 }
7276 if (isinstance) {
7277 *out = NotEq;
7278 return 0;
7279 }
7280 isinstance = PyObject_IsInstance(obj, (PyObject *)Lt_type);
7281 if (isinstance == -1) {
7282 return 1;
7283 }
7284 if (isinstance) {
7285 *out = Lt;
7286 return 0;
7287 }
7288 isinstance = PyObject_IsInstance(obj, (PyObject *)LtE_type);
7289 if (isinstance == -1) {
7290 return 1;
7291 }
7292 if (isinstance) {
7293 *out = LtE;
7294 return 0;
7295 }
7296 isinstance = PyObject_IsInstance(obj, (PyObject *)Gt_type);
7297 if (isinstance == -1) {
7298 return 1;
7299 }
7300 if (isinstance) {
7301 *out = Gt;
7302 return 0;
7303 }
7304 isinstance = PyObject_IsInstance(obj, (PyObject *)GtE_type);
7305 if (isinstance == -1) {
7306 return 1;
7307 }
7308 if (isinstance) {
7309 *out = GtE;
7310 return 0;
7311 }
7312 isinstance = PyObject_IsInstance(obj, (PyObject *)Is_type);
7313 if (isinstance == -1) {
7314 return 1;
7315 }
7316 if (isinstance) {
7317 *out = Is;
7318 return 0;
7319 }
7320 isinstance = PyObject_IsInstance(obj, (PyObject *)IsNot_type);
7321 if (isinstance == -1) {
7322 return 1;
7323 }
7324 if (isinstance) {
7325 *out = IsNot;
7326 return 0;
7327 }
7328 isinstance = PyObject_IsInstance(obj, (PyObject *)In_type);
7329 if (isinstance == -1) {
7330 return 1;
7331 }
7332 if (isinstance) {
7333 *out = In;
7334 return 0;
7335 }
7336 isinstance = PyObject_IsInstance(obj, (PyObject *)NotIn_type);
7337 if (isinstance == -1) {
7338 return 1;
7339 }
7340 if (isinstance) {
7341 *out = NotIn;
7342 return 0;
7343 }
7344
7345 PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj);
7346 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007347}
7348
7349int
7350obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena)
7351{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007352 PyObject* tmp = NULL;
7353 expr_ty target;
7354 expr_ty iter;
7355 asdl_seq* ifs;
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07007356 int is_async;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007357
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007358 if (_PyObject_HasAttrId(obj, &PyId_target)) {
7359 int res;
7360 tmp = _PyObject_GetAttrId(obj, &PyId_target);
7361 if (tmp == NULL) goto failed;
7362 res = obj2ast_expr(tmp, &target, arena);
7363 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007364 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007365 } else {
7366 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension");
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007367 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007368 }
7369 if (_PyObject_HasAttrId(obj, &PyId_iter)) {
7370 int res;
7371 tmp = _PyObject_GetAttrId(obj, &PyId_iter);
7372 if (tmp == NULL) goto failed;
7373 res = obj2ast_expr(tmp, &iter, arena);
7374 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007375 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007376 } else {
7377 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension");
7378 return 1;
7379 }
7380 if (_PyObject_HasAttrId(obj, &PyId_ifs)) {
7381 int res;
7382 Py_ssize_t len;
7383 Py_ssize_t i;
7384 tmp = _PyObject_GetAttrId(obj, &PyId_ifs);
7385 if (tmp == NULL) goto failed;
7386 if (!PyList_Check(tmp)) {
7387 PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", tmp->ob_type->tp_name);
7388 goto failed;
7389 }
7390 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007391 ifs = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007392 if (ifs == NULL) goto failed;
7393 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07007394 expr_ty val;
7395 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007396 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007397 if (len != PyList_GET_SIZE(tmp)) {
7398 PyErr_SetString(PyExc_RuntimeError, "comprehension field \"ifs\" changed size during iteration");
7399 goto failed;
7400 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07007401 asdl_seq_SET(ifs, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007402 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007403 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007404 } else {
7405 PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension");
7406 return 1;
7407 }
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07007408 if (_PyObject_HasAttrId(obj, &PyId_is_async)) {
7409 int res;
7410 tmp = _PyObject_GetAttrId(obj, &PyId_is_async);
7411 if (tmp == NULL) goto failed;
7412 res = obj2ast_int(tmp, &is_async, arena);
7413 if (res != 0) goto failed;
7414 Py_CLEAR(tmp);
7415 } else {
7416 PyErr_SetString(PyExc_TypeError, "required field \"is_async\" missing from comprehension");
7417 return 1;
7418 }
7419 *out = comprehension(target, iter, ifs, is_async, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007420 return 0;
7421failed:
7422 Py_XDECREF(tmp);
7423 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007424}
7425
7426int
7427obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena)
7428{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007429 int isinstance;
Neal Norwitzad74aa82008-03-31 05:14:30 +00007430
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007431 PyObject *tmp = NULL;
7432 int lineno;
7433 int col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007434
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007435 if (obj == Py_None) {
7436 *out = NULL;
7437 return 0;
7438 }
7439 if (_PyObject_HasAttrId(obj, &PyId_lineno)) {
7440 int res;
7441 tmp = _PyObject_GetAttrId(obj, &PyId_lineno);
7442 if (tmp == NULL) goto failed;
7443 res = obj2ast_int(tmp, &lineno, arena);
7444 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007445 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007446 } else {
7447 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler");
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007448 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007449 }
7450 if (_PyObject_HasAttrId(obj, &PyId_col_offset)) {
7451 int res;
7452 tmp = _PyObject_GetAttrId(obj, &PyId_col_offset);
7453 if (tmp == NULL) goto failed;
7454 res = obj2ast_int(tmp, &col_offset, arena);
7455 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007456 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007457 } else {
7458 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler");
7459 return 1;
7460 }
7461 isinstance = PyObject_IsInstance(obj, (PyObject*)ExceptHandler_type);
7462 if (isinstance == -1) {
7463 return 1;
7464 }
7465 if (isinstance) {
7466 expr_ty type;
7467 identifier name;
7468 asdl_seq* body;
7469
Victor Stinneree4b59c2013-07-27 00:01:35 +02007470 if (exists_not_none(obj, &PyId_type)) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007471 int res;
7472 tmp = _PyObject_GetAttrId(obj, &PyId_type);
7473 if (tmp == NULL) goto failed;
7474 res = obj2ast_expr(tmp, &type, arena);
7475 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007476 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007477 } else {
7478 type = NULL;
7479 }
Victor Stinneree4b59c2013-07-27 00:01:35 +02007480 if (exists_not_none(obj, &PyId_name)) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007481 int res;
7482 tmp = _PyObject_GetAttrId(obj, &PyId_name);
7483 if (tmp == NULL) goto failed;
7484 res = obj2ast_identifier(tmp, &name, arena);
7485 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007486 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007487 } else {
7488 name = NULL;
7489 }
7490 if (_PyObject_HasAttrId(obj, &PyId_body)) {
7491 int res;
7492 Py_ssize_t len;
7493 Py_ssize_t i;
7494 tmp = _PyObject_GetAttrId(obj, &PyId_body);
7495 if (tmp == NULL) goto failed;
7496 if (!PyList_Check(tmp)) {
7497 PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
7498 goto failed;
7499 }
7500 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007501 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007502 if (body == NULL) goto failed;
7503 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07007504 stmt_ty val;
7505 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007506 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007507 if (len != PyList_GET_SIZE(tmp)) {
7508 PyErr_SetString(PyExc_RuntimeError, "ExceptHandler field \"body\" changed size during iteration");
7509 goto failed;
7510 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07007511 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007512 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007513 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007514 } else {
7515 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler");
7516 return 1;
7517 }
7518 *out = ExceptHandler(type, name, body, lineno, col_offset, arena);
7519 if (*out == NULL) goto failed;
7520 return 0;
7521 }
7522
7523 PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj);
7524 failed:
7525 Py_XDECREF(tmp);
7526 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007527}
7528
7529int
7530obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena)
7531{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007532 PyObject* tmp = NULL;
7533 asdl_seq* args;
Victor Stinneree4b59c2013-07-27 00:01:35 +02007534 arg_ty vararg;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007535 asdl_seq* kwonlyargs;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007536 asdl_seq* kw_defaults;
Victor Stinneree4b59c2013-07-27 00:01:35 +02007537 arg_ty kwarg;
7538 asdl_seq* defaults;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007539
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007540 if (_PyObject_HasAttrId(obj, &PyId_args)) {
7541 int res;
7542 Py_ssize_t len;
7543 Py_ssize_t i;
7544 tmp = _PyObject_GetAttrId(obj, &PyId_args);
7545 if (tmp == NULL) goto failed;
7546 if (!PyList_Check(tmp)) {
7547 PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name);
7548 goto failed;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007549 }
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007550 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007551 args = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007552 if (args == NULL) goto failed;
7553 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07007554 arg_ty val;
7555 res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &val, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007556 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007557 if (len != PyList_GET_SIZE(tmp)) {
7558 PyErr_SetString(PyExc_RuntimeError, "arguments field \"args\" changed size during iteration");
7559 goto failed;
7560 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07007561 asdl_seq_SET(args, i, val);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007562 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007563 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007564 } else {
7565 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments");
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007566 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007567 }
Victor Stinneree4b59c2013-07-27 00:01:35 +02007568 if (exists_not_none(obj, &PyId_vararg)) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007569 int res;
7570 tmp = _PyObject_GetAttrId(obj, &PyId_vararg);
7571 if (tmp == NULL) goto failed;
Victor Stinneree4b59c2013-07-27 00:01:35 +02007572 res = obj2ast_arg(tmp, &vararg, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007573 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007574 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007575 } else {
7576 vararg = NULL;
7577 }
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007578 if (_PyObject_HasAttrId(obj, &PyId_kwonlyargs)) {
7579 int res;
7580 Py_ssize_t len;
7581 Py_ssize_t i;
7582 tmp = _PyObject_GetAttrId(obj, &PyId_kwonlyargs);
7583 if (tmp == NULL) goto failed;
7584 if (!PyList_Check(tmp)) {
7585 PyErr_Format(PyExc_TypeError, "arguments field \"kwonlyargs\" must be a list, not a %.200s", tmp->ob_type->tp_name);
7586 goto failed;
7587 }
7588 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007589 kwonlyargs = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007590 if (kwonlyargs == NULL) goto failed;
7591 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07007592 arg_ty val;
7593 res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &val, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007594 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007595 if (len != PyList_GET_SIZE(tmp)) {
7596 PyErr_SetString(PyExc_RuntimeError, "arguments field \"kwonlyargs\" changed size during iteration");
7597 goto failed;
7598 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07007599 asdl_seq_SET(kwonlyargs, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007600 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007601 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007602 } else {
7603 PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments");
7604 return 1;
7605 }
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007606 if (_PyObject_HasAttrId(obj, &PyId_kw_defaults)) {
7607 int res;
7608 Py_ssize_t len;
7609 Py_ssize_t i;
7610 tmp = _PyObject_GetAttrId(obj, &PyId_kw_defaults);
7611 if (tmp == NULL) goto failed;
7612 if (!PyList_Check(tmp)) {
7613 PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name);
7614 goto failed;
7615 }
7616 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007617 kw_defaults = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007618 if (kw_defaults == NULL) goto failed;
7619 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07007620 expr_ty val;
7621 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007622 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007623 if (len != PyList_GET_SIZE(tmp)) {
7624 PyErr_SetString(PyExc_RuntimeError, "arguments field \"kw_defaults\" changed size during iteration");
7625 goto failed;
7626 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07007627 asdl_seq_SET(kw_defaults, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007628 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007629 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007630 } else {
7631 PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments");
7632 return 1;
7633 }
Victor Stinneree4b59c2013-07-27 00:01:35 +02007634 if (exists_not_none(obj, &PyId_kwarg)) {
7635 int res;
7636 tmp = _PyObject_GetAttrId(obj, &PyId_kwarg);
7637 if (tmp == NULL) goto failed;
7638 res = obj2ast_arg(tmp, &kwarg, arena);
7639 if (res != 0) goto failed;
Victor Stinnerb3189902013-07-27 00:04:42 +02007640 Py_CLEAR(tmp);
Victor Stinneree4b59c2013-07-27 00:01:35 +02007641 } else {
7642 kwarg = NULL;
7643 }
7644 if (_PyObject_HasAttrId(obj, &PyId_defaults)) {
7645 int res;
7646 Py_ssize_t len;
7647 Py_ssize_t i;
7648 tmp = _PyObject_GetAttrId(obj, &PyId_defaults);
7649 if (tmp == NULL) goto failed;
7650 if (!PyList_Check(tmp)) {
7651 PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name);
7652 goto failed;
7653 }
7654 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007655 defaults = _Py_asdl_seq_new(len, arena);
Victor Stinneree4b59c2013-07-27 00:01:35 +02007656 if (defaults == NULL) goto failed;
7657 for (i = 0; i < len; i++) {
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07007658 expr_ty val;
7659 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
Victor Stinneree4b59c2013-07-27 00:01:35 +02007660 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007661 if (len != PyList_GET_SIZE(tmp)) {
7662 PyErr_SetString(PyExc_RuntimeError, "arguments field \"defaults\" changed size during iteration");
7663 goto failed;
7664 }
Yuan Chao Choua0cb7db2017-08-04 10:53:42 -07007665 asdl_seq_SET(defaults, i, val);
Victor Stinneree4b59c2013-07-27 00:01:35 +02007666 }
Victor Stinnerb3189902013-07-27 00:04:42 +02007667 Py_CLEAR(tmp);
Victor Stinneree4b59c2013-07-27 00:01:35 +02007668 } else {
7669 PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments");
7670 return 1;
7671 }
7672 *out = arguments(args, vararg, kwonlyargs, kw_defaults, kwarg, defaults,
7673 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007674 return 0;
7675failed:
7676 Py_XDECREF(tmp);
7677 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007678}
7679
7680int
7681obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena)
7682{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007683 PyObject* tmp = NULL;
7684 identifier arg;
7685 expr_ty annotation;
Victor Stinnerc106c682015-11-06 17:01:48 +01007686 int lineno;
7687 int col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007688
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007689 if (_PyObject_HasAttrId(obj, &PyId_arg)) {
7690 int res;
7691 tmp = _PyObject_GetAttrId(obj, &PyId_arg);
7692 if (tmp == NULL) goto failed;
7693 res = obj2ast_identifier(tmp, &arg, arena);
7694 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007695 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007696 } else {
7697 PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg");
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007698 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007699 }
Victor Stinneree4b59c2013-07-27 00:01:35 +02007700 if (exists_not_none(obj, &PyId_annotation)) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007701 int res;
7702 tmp = _PyObject_GetAttrId(obj, &PyId_annotation);
7703 if (tmp == NULL) goto failed;
7704 res = obj2ast_expr(tmp, &annotation, arena);
7705 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007706 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007707 } else {
7708 annotation = NULL;
7709 }
Victor Stinnerc106c682015-11-06 17:01:48 +01007710 if (_PyObject_HasAttrId(obj, &PyId_lineno)) {
7711 int res;
7712 tmp = _PyObject_GetAttrId(obj, &PyId_lineno);
7713 if (tmp == NULL) goto failed;
7714 res = obj2ast_int(tmp, &lineno, arena);
7715 if (res != 0) goto failed;
7716 Py_CLEAR(tmp);
7717 } else {
7718 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from arg");
7719 return 1;
7720 }
7721 if (_PyObject_HasAttrId(obj, &PyId_col_offset)) {
7722 int res;
7723 tmp = _PyObject_GetAttrId(obj, &PyId_col_offset);
7724 if (tmp == NULL) goto failed;
7725 res = obj2ast_int(tmp, &col_offset, arena);
7726 if (res != 0) goto failed;
7727 Py_CLEAR(tmp);
7728 } else {
7729 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from arg");
7730 return 1;
7731 }
7732 *out = arg(arg, annotation, lineno, col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007733 return 0;
7734failed:
7735 Py_XDECREF(tmp);
7736 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007737}
7738
7739int
7740obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena)
7741{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007742 PyObject* tmp = NULL;
7743 identifier arg;
7744 expr_ty value;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007745
Benjamin Peterson025e9eb2015-05-05 20:16:41 -04007746 if (exists_not_none(obj, &PyId_arg)) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007747 int res;
7748 tmp = _PyObject_GetAttrId(obj, &PyId_arg);
7749 if (tmp == NULL) goto failed;
7750 res = obj2ast_identifier(tmp, &arg, arena);
7751 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007752 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007753 } else {
Benjamin Peterson025e9eb2015-05-05 20:16:41 -04007754 arg = NULL;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007755 }
7756 if (_PyObject_HasAttrId(obj, &PyId_value)) {
7757 int res;
7758 tmp = _PyObject_GetAttrId(obj, &PyId_value);
7759 if (tmp == NULL) goto failed;
7760 res = obj2ast_expr(tmp, &value, arena);
7761 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007762 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007763 } else {
7764 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword");
7765 return 1;
7766 }
7767 *out = keyword(arg, value, arena);
7768 return 0;
7769failed:
7770 Py_XDECREF(tmp);
7771 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007772}
7773
7774int
7775obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena)
7776{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007777 PyObject* tmp = NULL;
7778 identifier name;
7779 identifier asname;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007780
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007781 if (_PyObject_HasAttrId(obj, &PyId_name)) {
7782 int res;
7783 tmp = _PyObject_GetAttrId(obj, &PyId_name);
7784 if (tmp == NULL) goto failed;
7785 res = obj2ast_identifier(tmp, &name, arena);
7786 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007787 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007788 } else {
7789 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias");
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007790 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007791 }
Victor Stinneree4b59c2013-07-27 00:01:35 +02007792 if (exists_not_none(obj, &PyId_asname)) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007793 int res;
7794 tmp = _PyObject_GetAttrId(obj, &PyId_asname);
7795 if (tmp == NULL) goto failed;
7796 res = obj2ast_identifier(tmp, &asname, arena);
7797 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007798 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007799 } else {
7800 asname = NULL;
7801 }
7802 *out = alias(name, asname, arena);
7803 return 0;
7804failed:
7805 Py_XDECREF(tmp);
7806 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007807}
7808
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05007809int
7810obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena)
7811{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007812 PyObject* tmp = NULL;
7813 expr_ty context_expr;
7814 expr_ty optional_vars;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05007815
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007816 if (_PyObject_HasAttrId(obj, &PyId_context_expr)) {
7817 int res;
7818 tmp = _PyObject_GetAttrId(obj, &PyId_context_expr);
7819 if (tmp == NULL) goto failed;
7820 res = obj2ast_expr(tmp, &context_expr, arena);
7821 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007822 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007823 } else {
7824 PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem");
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05007825 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007826 }
Victor Stinneree4b59c2013-07-27 00:01:35 +02007827 if (exists_not_none(obj, &PyId_optional_vars)) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007828 int res;
7829 tmp = _PyObject_GetAttrId(obj, &PyId_optional_vars);
7830 if (tmp == NULL) goto failed;
7831 res = obj2ast_expr(tmp, &optional_vars, arena);
7832 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007833 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007834 } else {
7835 optional_vars = NULL;
7836 }
7837 *out = withitem(context_expr, optional_vars, arena);
7838 return 0;
7839failed:
7840 Py_XDECREF(tmp);
7841 return 1;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05007842}
7843
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007844
Martin v. Löwis1a214512008-06-11 05:26:20 +00007845static struct PyModuleDef _astmodule = {
7846 PyModuleDef_HEAD_INIT, "_ast"
7847};
Martin v. Löwis577b5b92006-02-27 15:23:19 +00007848PyMODINIT_FUNC
Martin v. Löwis1a214512008-06-11 05:26:20 +00007849PyInit__ast(void)
Martin v. Löwis577b5b92006-02-27 15:23:19 +00007850{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007851 PyObject *m, *d;
7852 if (!init_types()) return NULL;
7853 m = PyModule_Create(&_astmodule);
7854 if (!m) return NULL;
7855 d = PyModule_GetDict(m);
7856 if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return NULL;
Victor Stinneree4b59c2013-07-27 00:01:35 +02007857 if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007858 return NULL;
7859 if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return NULL;
7860 if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0) return
7861 NULL;
7862 if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type) <
7863 0) return NULL;
7864 if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) < 0)
7865 return NULL;
7866 if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return
7867 NULL;
7868 if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return NULL;
7869 if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type) <
7870 0) return NULL;
Yury Selivanov75445082015-05-11 22:57:16 -04007871 if (PyDict_SetItemString(d, "AsyncFunctionDef",
7872 (PyObject*)AsyncFunctionDef_type) < 0) return NULL;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007873 if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0)
7874 return NULL;
7875 if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0) return
7876 NULL;
7877 if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0) return
7878 NULL;
7879 if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0) return
7880 NULL;
7881 if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) < 0)
7882 return NULL;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07007883 if (PyDict_SetItemString(d, "AnnAssign", (PyObject*)AnnAssign_type) < 0)
7884 return NULL;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007885 if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return NULL;
Yury Selivanov75445082015-05-11 22:57:16 -04007886 if (PyDict_SetItemString(d, "AsyncFor", (PyObject*)AsyncFor_type) < 0)
7887 return NULL;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007888 if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return
7889 NULL;
7890 if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return NULL;
7891 if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return NULL;
Yury Selivanov75445082015-05-11 22:57:16 -04007892 if (PyDict_SetItemString(d, "AsyncWith", (PyObject*)AsyncWith_type) < 0)
7893 return NULL;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007894 if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return
7895 NULL;
7896 if (PyDict_SetItemString(d, "Try", (PyObject*)Try_type) < 0) return NULL;
7897 if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0) return
7898 NULL;
7899 if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0) return
7900 NULL;
7901 if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) < 0)
7902 return NULL;
7903 if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0) return
7904 NULL;
7905 if (PyDict_SetItemString(d, "Nonlocal", (PyObject*)Nonlocal_type) < 0)
7906 return NULL;
7907 if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return NULL;
7908 if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return NULL;
7909 if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return
7910 NULL;
7911 if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0)
7912 return NULL;
7913 if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return NULL;
7914 if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0) return
7915 NULL;
7916 if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return
7917 NULL;
7918 if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0) return
7919 NULL;
7920 if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0) return
7921 NULL;
7922 if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return
7923 NULL;
7924 if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return NULL;
7925 if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return NULL;
7926 if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0)
7927 return NULL;
7928 if (PyDict_SetItemString(d, "SetComp", (PyObject*)SetComp_type) < 0) return
7929 NULL;
7930 if (PyDict_SetItemString(d, "DictComp", (PyObject*)DictComp_type) < 0)
7931 return NULL;
7932 if (PyDict_SetItemString(d, "GeneratorExp", (PyObject*)GeneratorExp_type) <
7933 0) return NULL;
Yury Selivanov75445082015-05-11 22:57:16 -04007934 if (PyDict_SetItemString(d, "Await", (PyObject*)Await_type) < 0) return
7935 NULL;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007936 if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return
7937 NULL;
7938 if (PyDict_SetItemString(d, "YieldFrom", (PyObject*)YieldFrom_type) < 0)
7939 return NULL;
7940 if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0) return
7941 NULL;
7942 if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return NULL;
7943 if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return NULL;
7944 if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return NULL;
Eric V. Smith235a6f02015-09-19 14:51:32 -04007945 if (PyDict_SetItemString(d, "FormattedValue",
7946 (PyObject*)FormattedValue_type) < 0) return NULL;
7947 if (PyDict_SetItemString(d, "JoinedStr", (PyObject*)JoinedStr_type) < 0)
7948 return NULL;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007949 if (PyDict_SetItemString(d, "Bytes", (PyObject*)Bytes_type) < 0) return
7950 NULL;
Victor Stinneree4b59c2013-07-27 00:01:35 +02007951 if (PyDict_SetItemString(d, "NameConstant", (PyObject*)NameConstant_type) <
7952 0) return NULL;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007953 if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0)
7954 return NULL;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01007955 if (PyDict_SetItemString(d, "Constant", (PyObject*)Constant_type) < 0)
7956 return NULL;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007957 if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) < 0)
7958 return NULL;
7959 if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) < 0)
7960 return NULL;
7961 if (PyDict_SetItemString(d, "Starred", (PyObject*)Starred_type) < 0) return
7962 NULL;
7963 if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return NULL;
7964 if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return NULL;
7965 if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return
7966 NULL;
7967 if (PyDict_SetItemString(d, "expr_context", (PyObject*)expr_context_type) <
7968 0) return NULL;
7969 if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return NULL;
7970 if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return
7971 NULL;
7972 if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return NULL;
7973 if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0) return
7974 NULL;
7975 if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0)
7976 return NULL;
7977 if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return
7978 NULL;
7979 if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return
7980 NULL;
7981 if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return
7982 NULL;
7983 if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0)
7984 return NULL;
7985 if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return
7986 NULL;
7987 if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0) return
7988 NULL;
7989 if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return NULL;
7990 if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return NULL;
7991 if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0)
7992 return NULL;
7993 if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return NULL;
7994 if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return NULL;
7995 if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return NULL;
Benjamin Petersond51374e2014-04-09 23:55:56 -04007996 if (PyDict_SetItemString(d, "MatMult", (PyObject*)MatMult_type) < 0) return
7997 NULL;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007998 if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return NULL;
7999 if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return NULL;
8000 if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return NULL;
8001 if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0) return
8002 NULL;
8003 if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0) return
8004 NULL;
8005 if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return
8006 NULL;
8007 if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0) return
8008 NULL;
8009 if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0) return
8010 NULL;
8011 if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0)
8012 return NULL;
8013 if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0) return
8014 NULL;
8015 if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0) return
8016 NULL;
8017 if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return NULL;
8018 if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return NULL;
8019 if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return NULL;
8020 if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return
8021 NULL;
8022 if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return NULL;
8023 if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return
8024 NULL;
8025 if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return NULL;
8026 if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return NULL;
8027 if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return NULL;
8028 if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return NULL;
8029 if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return NULL;
8030 if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return
8031 NULL;
8032 if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return NULL;
8033 if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return
8034 NULL;
8035 if (PyDict_SetItemString(d, "comprehension", (PyObject*)comprehension_type)
8036 < 0) return NULL;
8037 if (PyDict_SetItemString(d, "excepthandler", (PyObject*)excepthandler_type)
8038 < 0) return NULL;
8039 if (PyDict_SetItemString(d, "ExceptHandler", (PyObject*)ExceptHandler_type)
8040 < 0) return NULL;
8041 if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) < 0)
8042 return NULL;
8043 if (PyDict_SetItemString(d, "arg", (PyObject*)arg_type) < 0) return NULL;
8044 if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0) return
8045 NULL;
8046 if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return
8047 NULL;
8048 if (PyDict_SetItemString(d, "withitem", (PyObject*)withitem_type) < 0)
8049 return NULL;
8050 return m;
Martin v. Löwis577b5b92006-02-27 15:23:19 +00008051}
8052
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00008053
Martin v. Löwisbd260da2006-02-26 19:42:26 +00008054PyObject* PyAST_mod2obj(mod_ty t)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00008055{
Victor Stinnerbdf630c2013-07-17 00:17:15 +02008056 if (!init_types())
8057 return NULL;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00008058 return ast2obj_mod(t);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00008059}
Martin v. Löwis5b222132007-06-10 09:51:05 +00008060
Neal Norwitzdb4115f2008-03-31 04:20:05 +00008061/* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */
8062mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode)
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008063{
8064 mod_ty res;
Benjamin Petersonc2f665e2014-02-10 22:19:02 -05008065 PyObject *req_type[3];
Neal Norwitzdb4115f2008-03-31 04:20:05 +00008066 char *req_name[] = {"Module", "Expression", "Interactive"};
Benjamin Peterson0496c9e2009-12-13 01:24:58 +00008067 int isinstance;
Benjamin Peterson42ec0312014-02-10 22:41:40 -05008068
Benjamin Petersonc2f665e2014-02-10 22:19:02 -05008069 req_type[0] = (PyObject*)Module_type;
8070 req_type[1] = (PyObject*)Expression_type;
8071 req_type[2] = (PyObject*)Interactive_type;
Benjamin Peterson42ec0312014-02-10 22:41:40 -05008072
Neal Norwitzdb4115f2008-03-31 04:20:05 +00008073 assert(0 <= mode && mode <= 2);
8074
Victor Stinnerbdf630c2013-07-17 00:17:15 +02008075 if (!init_types())
8076 return NULL;
Neal Norwitzdb4115f2008-03-31 04:20:05 +00008077
Benjamin Peterson0496c9e2009-12-13 01:24:58 +00008078 isinstance = PyObject_IsInstance(ast, req_type[mode]);
8079 if (isinstance == -1)
8080 return NULL;
8081 if (!isinstance) {
Neal Norwitzdb4115f2008-03-31 04:20:05 +00008082 PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s",
8083 req_name[mode], Py_TYPE(ast)->tp_name);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008084 return NULL;
8085 }
8086 if (obj2ast_mod(ast, &res, arena) != 0)
8087 return NULL;
8088 else
8089 return res;
8090}
8091
8092int PyAST_Check(PyObject* obj)
8093{
Victor Stinnerbdf630c2013-07-17 00:17:15 +02008094 if (!init_types())
8095 return -1;
Neal Norwitz207c9f32008-03-31 04:42:11 +00008096 return PyObject_IsInstance(obj, (PyObject*)&AST_type);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008097}
8098
Martin v. Löwis5b222132007-06-10 09:51:05 +00008099