• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* File automatically generated by Parser/asdl_c.py. */
2 
3 #include <stddef.h>
4 
5 #include "Python.h"
6 #include "Python-ast.h"
7 
8 static PyTypeObject AST_type;
9 static PyTypeObject *mod_type;
10 static PyObject* ast2obj_mod(void*);
11 static PyTypeObject *Module_type;
12 _Py_IDENTIFIER(body);
13 _Py_IDENTIFIER(type_ignores);
14 static char *Module_fields[]={
15     "body",
16     "type_ignores",
17 };
18 static PyTypeObject *Interactive_type;
19 static char *Interactive_fields[]={
20     "body",
21 };
22 static PyTypeObject *Expression_type;
23 static char *Expression_fields[]={
24     "body",
25 };
26 static PyTypeObject *FunctionType_type;
27 _Py_IDENTIFIER(argtypes);
28 _Py_IDENTIFIER(returns);
29 static char *FunctionType_fields[]={
30     "argtypes",
31     "returns",
32 };
33 static PyTypeObject *Suite_type;
34 static char *Suite_fields[]={
35     "body",
36 };
37 static PyTypeObject *stmt_type;
38 _Py_IDENTIFIER(lineno);
39 _Py_IDENTIFIER(col_offset);
40 _Py_IDENTIFIER(end_lineno);
41 _Py_IDENTIFIER(end_col_offset);
42 static char *stmt_attributes[] = {
43     "lineno",
44     "col_offset",
45     "end_lineno",
46     "end_col_offset",
47 };
48 static PyObject* ast2obj_stmt(void*);
49 static PyTypeObject *FunctionDef_type;
50 _Py_IDENTIFIER(name);
51 _Py_IDENTIFIER(args);
52 _Py_IDENTIFIER(decorator_list);
53 _Py_IDENTIFIER(type_comment);
54 static char *FunctionDef_fields[]={
55     "name",
56     "args",
57     "body",
58     "decorator_list",
59     "returns",
60     "type_comment",
61 };
62 static PyTypeObject *AsyncFunctionDef_type;
63 static char *AsyncFunctionDef_fields[]={
64     "name",
65     "args",
66     "body",
67     "decorator_list",
68     "returns",
69     "type_comment",
70 };
71 static PyTypeObject *ClassDef_type;
72 _Py_IDENTIFIER(bases);
73 _Py_IDENTIFIER(keywords);
74 static char *ClassDef_fields[]={
75     "name",
76     "bases",
77     "keywords",
78     "body",
79     "decorator_list",
80 };
81 static PyTypeObject *Return_type;
82 _Py_IDENTIFIER(value);
83 static char *Return_fields[]={
84     "value",
85 };
86 static PyTypeObject *Delete_type;
87 _Py_IDENTIFIER(targets);
88 static char *Delete_fields[]={
89     "targets",
90 };
91 static PyTypeObject *Assign_type;
92 static char *Assign_fields[]={
93     "targets",
94     "value",
95     "type_comment",
96 };
97 static PyTypeObject *AugAssign_type;
98 _Py_IDENTIFIER(target);
99 _Py_IDENTIFIER(op);
100 static char *AugAssign_fields[]={
101     "target",
102     "op",
103     "value",
104 };
105 static PyTypeObject *AnnAssign_type;
106 _Py_IDENTIFIER(annotation);
107 _Py_IDENTIFIER(simple);
108 static char *AnnAssign_fields[]={
109     "target",
110     "annotation",
111     "value",
112     "simple",
113 };
114 static PyTypeObject *For_type;
115 _Py_IDENTIFIER(iter);
116 _Py_IDENTIFIER(orelse);
117 static char *For_fields[]={
118     "target",
119     "iter",
120     "body",
121     "orelse",
122     "type_comment",
123 };
124 static PyTypeObject *AsyncFor_type;
125 static char *AsyncFor_fields[]={
126     "target",
127     "iter",
128     "body",
129     "orelse",
130     "type_comment",
131 };
132 static PyTypeObject *While_type;
133 _Py_IDENTIFIER(test);
134 static char *While_fields[]={
135     "test",
136     "body",
137     "orelse",
138 };
139 static PyTypeObject *If_type;
140 static char *If_fields[]={
141     "test",
142     "body",
143     "orelse",
144 };
145 static PyTypeObject *With_type;
146 _Py_IDENTIFIER(items);
147 static char *With_fields[]={
148     "items",
149     "body",
150     "type_comment",
151 };
152 static PyTypeObject *AsyncWith_type;
153 static char *AsyncWith_fields[]={
154     "items",
155     "body",
156     "type_comment",
157 };
158 static PyTypeObject *Raise_type;
159 _Py_IDENTIFIER(exc);
160 _Py_IDENTIFIER(cause);
161 static char *Raise_fields[]={
162     "exc",
163     "cause",
164 };
165 static PyTypeObject *Try_type;
166 _Py_IDENTIFIER(handlers);
167 _Py_IDENTIFIER(finalbody);
168 static char *Try_fields[]={
169     "body",
170     "handlers",
171     "orelse",
172     "finalbody",
173 };
174 static PyTypeObject *Assert_type;
175 _Py_IDENTIFIER(msg);
176 static char *Assert_fields[]={
177     "test",
178     "msg",
179 };
180 static PyTypeObject *Import_type;
181 _Py_IDENTIFIER(names);
182 static char *Import_fields[]={
183     "names",
184 };
185 static PyTypeObject *ImportFrom_type;
186 _Py_IDENTIFIER(module);
187 _Py_IDENTIFIER(level);
188 static char *ImportFrom_fields[]={
189     "module",
190     "names",
191     "level",
192 };
193 static PyTypeObject *Global_type;
194 static char *Global_fields[]={
195     "names",
196 };
197 static PyTypeObject *Nonlocal_type;
198 static char *Nonlocal_fields[]={
199     "names",
200 };
201 static PyTypeObject *Expr_type;
202 static char *Expr_fields[]={
203     "value",
204 };
205 static PyTypeObject *Pass_type;
206 static PyTypeObject *Break_type;
207 static PyTypeObject *Continue_type;
208 static PyTypeObject *expr_type;
209 static char *expr_attributes[] = {
210     "lineno",
211     "col_offset",
212     "end_lineno",
213     "end_col_offset",
214 };
215 static PyObject* ast2obj_expr(void*);
216 static PyTypeObject *BoolOp_type;
217 _Py_IDENTIFIER(values);
218 static char *BoolOp_fields[]={
219     "op",
220     "values",
221 };
222 static PyTypeObject *NamedExpr_type;
223 static char *NamedExpr_fields[]={
224     "target",
225     "value",
226 };
227 static PyTypeObject *BinOp_type;
228 _Py_IDENTIFIER(left);
229 _Py_IDENTIFIER(right);
230 static char *BinOp_fields[]={
231     "left",
232     "op",
233     "right",
234 };
235 static PyTypeObject *UnaryOp_type;
236 _Py_IDENTIFIER(operand);
237 static char *UnaryOp_fields[]={
238     "op",
239     "operand",
240 };
241 static PyTypeObject *Lambda_type;
242 static char *Lambda_fields[]={
243     "args",
244     "body",
245 };
246 static PyTypeObject *IfExp_type;
247 static char *IfExp_fields[]={
248     "test",
249     "body",
250     "orelse",
251 };
252 static PyTypeObject *Dict_type;
253 _Py_IDENTIFIER(keys);
254 static char *Dict_fields[]={
255     "keys",
256     "values",
257 };
258 static PyTypeObject *Set_type;
259 _Py_IDENTIFIER(elts);
260 static char *Set_fields[]={
261     "elts",
262 };
263 static PyTypeObject *ListComp_type;
264 _Py_IDENTIFIER(elt);
265 _Py_IDENTIFIER(generators);
266 static char *ListComp_fields[]={
267     "elt",
268     "generators",
269 };
270 static PyTypeObject *SetComp_type;
271 static char *SetComp_fields[]={
272     "elt",
273     "generators",
274 };
275 static PyTypeObject *DictComp_type;
276 _Py_IDENTIFIER(key);
277 static char *DictComp_fields[]={
278     "key",
279     "value",
280     "generators",
281 };
282 static PyTypeObject *GeneratorExp_type;
283 static char *GeneratorExp_fields[]={
284     "elt",
285     "generators",
286 };
287 static PyTypeObject *Await_type;
288 static char *Await_fields[]={
289     "value",
290 };
291 static PyTypeObject *Yield_type;
292 static char *Yield_fields[]={
293     "value",
294 };
295 static PyTypeObject *YieldFrom_type;
296 static char *YieldFrom_fields[]={
297     "value",
298 };
299 static PyTypeObject *Compare_type;
300 _Py_IDENTIFIER(ops);
301 _Py_IDENTIFIER(comparators);
302 static char *Compare_fields[]={
303     "left",
304     "ops",
305     "comparators",
306 };
307 static PyTypeObject *Call_type;
308 _Py_IDENTIFIER(func);
309 static char *Call_fields[]={
310     "func",
311     "args",
312     "keywords",
313 };
314 static PyTypeObject *FormattedValue_type;
315 _Py_IDENTIFIER(conversion);
316 _Py_IDENTIFIER(format_spec);
317 static char *FormattedValue_fields[]={
318     "value",
319     "conversion",
320     "format_spec",
321 };
322 static PyTypeObject *JoinedStr_type;
323 static char *JoinedStr_fields[]={
324     "values",
325 };
326 static PyTypeObject *Constant_type;
327 _Py_IDENTIFIER(kind);
328 static char *Constant_fields[]={
329     "value",
330     "kind",
331 };
332 static PyTypeObject *Attribute_type;
333 _Py_IDENTIFIER(attr);
334 _Py_IDENTIFIER(ctx);
335 static char *Attribute_fields[]={
336     "value",
337     "attr",
338     "ctx",
339 };
340 static PyTypeObject *Subscript_type;
341 _Py_IDENTIFIER(slice);
342 static char *Subscript_fields[]={
343     "value",
344     "slice",
345     "ctx",
346 };
347 static PyTypeObject *Starred_type;
348 static char *Starred_fields[]={
349     "value",
350     "ctx",
351 };
352 static PyTypeObject *Name_type;
353 _Py_IDENTIFIER(id);
354 static char *Name_fields[]={
355     "id",
356     "ctx",
357 };
358 static PyTypeObject *List_type;
359 static char *List_fields[]={
360     "elts",
361     "ctx",
362 };
363 static PyTypeObject *Tuple_type;
364 static char *Tuple_fields[]={
365     "elts",
366     "ctx",
367 };
368 static PyTypeObject *expr_context_type;
369 static PyObject *Load_singleton, *Store_singleton, *Del_singleton,
370 *AugLoad_singleton, *AugStore_singleton, *Param_singleton;
371 static PyObject* ast2obj_expr_context(expr_context_ty);
372 static PyTypeObject *Load_type;
373 static PyTypeObject *Store_type;
374 static PyTypeObject *Del_type;
375 static PyTypeObject *AugLoad_type;
376 static PyTypeObject *AugStore_type;
377 static PyTypeObject *Param_type;
378 static PyTypeObject *slice_type;
379 static PyObject* ast2obj_slice(void*);
380 static PyTypeObject *Slice_type;
381 _Py_IDENTIFIER(lower);
382 _Py_IDENTIFIER(upper);
383 _Py_IDENTIFIER(step);
384 static char *Slice_fields[]={
385     "lower",
386     "upper",
387     "step",
388 };
389 static PyTypeObject *ExtSlice_type;
390 _Py_IDENTIFIER(dims);
391 static char *ExtSlice_fields[]={
392     "dims",
393 };
394 static PyTypeObject *Index_type;
395 static char *Index_fields[]={
396     "value",
397 };
398 static PyTypeObject *boolop_type;
399 static PyObject *And_singleton, *Or_singleton;
400 static PyObject* ast2obj_boolop(boolop_ty);
401 static PyTypeObject *And_type;
402 static PyTypeObject *Or_type;
403 static PyTypeObject *operator_type;
404 static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton,
405 *MatMult_singleton, *Div_singleton, *Mod_singleton, *Pow_singleton,
406 *LShift_singleton, *RShift_singleton, *BitOr_singleton, *BitXor_singleton,
407 *BitAnd_singleton, *FloorDiv_singleton;
408 static PyObject* ast2obj_operator(operator_ty);
409 static PyTypeObject *Add_type;
410 static PyTypeObject *Sub_type;
411 static PyTypeObject *Mult_type;
412 static PyTypeObject *MatMult_type;
413 static PyTypeObject *Div_type;
414 static PyTypeObject *Mod_type;
415 static PyTypeObject *Pow_type;
416 static PyTypeObject *LShift_type;
417 static PyTypeObject *RShift_type;
418 static PyTypeObject *BitOr_type;
419 static PyTypeObject *BitXor_type;
420 static PyTypeObject *BitAnd_type;
421 static PyTypeObject *FloorDiv_type;
422 static PyTypeObject *unaryop_type;
423 static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton,
424 *USub_singleton;
425 static PyObject* ast2obj_unaryop(unaryop_ty);
426 static PyTypeObject *Invert_type;
427 static PyTypeObject *Not_type;
428 static PyTypeObject *UAdd_type;
429 static PyTypeObject *USub_type;
430 static PyTypeObject *cmpop_type;
431 static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton,
432 *Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton,
433 *NotIn_singleton;
434 static PyObject* ast2obj_cmpop(cmpop_ty);
435 static PyTypeObject *Eq_type;
436 static PyTypeObject *NotEq_type;
437 static PyTypeObject *Lt_type;
438 static PyTypeObject *LtE_type;
439 static PyTypeObject *Gt_type;
440 static PyTypeObject *GtE_type;
441 static PyTypeObject *Is_type;
442 static PyTypeObject *IsNot_type;
443 static PyTypeObject *In_type;
444 static PyTypeObject *NotIn_type;
445 static PyTypeObject *comprehension_type;
446 static PyObject* ast2obj_comprehension(void*);
447 _Py_IDENTIFIER(ifs);
448 _Py_IDENTIFIER(is_async);
449 static char *comprehension_fields[]={
450     "target",
451     "iter",
452     "ifs",
453     "is_async",
454 };
455 static PyTypeObject *excepthandler_type;
456 static char *excepthandler_attributes[] = {
457     "lineno",
458     "col_offset",
459     "end_lineno",
460     "end_col_offset",
461 };
462 static PyObject* ast2obj_excepthandler(void*);
463 static PyTypeObject *ExceptHandler_type;
464 _Py_IDENTIFIER(type);
465 static char *ExceptHandler_fields[]={
466     "type",
467     "name",
468     "body",
469 };
470 static PyTypeObject *arguments_type;
471 static PyObject* ast2obj_arguments(void*);
472 _Py_IDENTIFIER(posonlyargs);
473 _Py_IDENTIFIER(vararg);
474 _Py_IDENTIFIER(kwonlyargs);
475 _Py_IDENTIFIER(kw_defaults);
476 _Py_IDENTIFIER(kwarg);
477 _Py_IDENTIFIER(defaults);
478 static char *arguments_fields[]={
479     "posonlyargs",
480     "args",
481     "vararg",
482     "kwonlyargs",
483     "kw_defaults",
484     "kwarg",
485     "defaults",
486 };
487 static PyTypeObject *arg_type;
488 static PyObject* ast2obj_arg(void*);
489 static char *arg_attributes[] = {
490     "lineno",
491     "col_offset",
492     "end_lineno",
493     "end_col_offset",
494 };
495 _Py_IDENTIFIER(arg);
496 static char *arg_fields[]={
497     "arg",
498     "annotation",
499     "type_comment",
500 };
501 static PyTypeObject *keyword_type;
502 static PyObject* ast2obj_keyword(void*);
503 static char *keyword_fields[]={
504     "arg",
505     "value",
506 };
507 static PyTypeObject *alias_type;
508 static PyObject* ast2obj_alias(void*);
509 _Py_IDENTIFIER(asname);
510 static char *alias_fields[]={
511     "name",
512     "asname",
513 };
514 static PyTypeObject *withitem_type;
515 static PyObject* ast2obj_withitem(void*);
516 _Py_IDENTIFIER(context_expr);
517 _Py_IDENTIFIER(optional_vars);
518 static char *withitem_fields[]={
519     "context_expr",
520     "optional_vars",
521 };
522 static PyTypeObject *type_ignore_type;
523 static PyObject* ast2obj_type_ignore(void*);
524 static PyTypeObject *TypeIgnore_type;
525 _Py_IDENTIFIER(tag);
526 static char *TypeIgnore_fields[]={
527     "lineno",
528     "tag",
529 };
530 
531 
532 _Py_IDENTIFIER(_fields);
533 _Py_IDENTIFIER(_attributes);
534 
535 typedef struct {
536     PyObject_HEAD
537     PyObject *dict;
538 } AST_object;
539 
540 static void
ast_dealloc(AST_object * self)541 ast_dealloc(AST_object *self)
542 {
543     /* bpo-31095: UnTrack is needed before calling any callbacks */
544     PyObject_GC_UnTrack(self);
545     Py_CLEAR(self->dict);
546     Py_TYPE(self)->tp_free(self);
547 }
548 
549 static int
ast_traverse(AST_object * self,visitproc visit,void * arg)550 ast_traverse(AST_object *self, visitproc visit, void *arg)
551 {
552     Py_VISIT(self->dict);
553     return 0;
554 }
555 
556 static int
ast_clear(AST_object * self)557 ast_clear(AST_object *self)
558 {
559     Py_CLEAR(self->dict);
560     return 0;
561 }
562 
563 static int
ast_type_init(PyObject * self,PyObject * args,PyObject * kw)564 ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
565 {
566     Py_ssize_t i, numfields = 0;
567     int res = -1;
568     PyObject *key, *value, *fields;
569     if (_PyObject_LookupAttrId((PyObject*)Py_TYPE(self), &PyId__fields, &fields) < 0) {
570         goto cleanup;
571     }
572     if (fields) {
573         numfields = PySequence_Size(fields);
574         if (numfields == -1) {
575             goto cleanup;
576         }
577     }
578 
579     res = 0; /* if no error occurs, this stays 0 to the end */
580     if (numfields < PyTuple_GET_SIZE(args)) {
581         PyErr_Format(PyExc_TypeError, "%.400s constructor takes at most "
582                      "%zd positional argument%s",
583                      Py_TYPE(self)->tp_name,
584                      numfields, numfields == 1 ? "" : "s");
585         res = -1;
586         goto cleanup;
587     }
588     for (i = 0; i < PyTuple_GET_SIZE(args); i++) {
589         /* cannot be reached when fields is NULL */
590         PyObject *name = PySequence_GetItem(fields, i);
591         if (!name) {
592             res = -1;
593             goto cleanup;
594         }
595         res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i));
596         Py_DECREF(name);
597         if (res < 0) {
598             goto cleanup;
599         }
600     }
601     if (kw) {
602         i = 0;  /* needed by PyDict_Next */
603         while (PyDict_Next(kw, &i, &key, &value)) {
604             int contains = PySequence_Contains(fields, key);
605             if (contains == -1) {
606                 res = -1;
607                 goto cleanup;
608             } else if (contains == 1) {
609                 Py_ssize_t p = PySequence_Index(fields, key);
610                 if (p == -1) {
611                     res = -1;
612                     goto cleanup;
613                 }
614                 if (p < PyTuple_GET_SIZE(args)) {
615                     PyErr_Format(PyExc_TypeError,
616                         "%.400s got multiple values for argument '%U'",
617                         Py_TYPE(self)->tp_name, key);
618                     res = -1;
619                     goto cleanup;
620                 }
621             }
622             res = PyObject_SetAttr(self, key, value);
623             if (res < 0) {
624                 goto cleanup;
625             }
626         }
627     }
628   cleanup:
629     Py_XDECREF(fields);
630     return res;
631 }
632 
633 /* Pickling support */
634 static PyObject *
ast_type_reduce(PyObject * self,PyObject * unused)635 ast_type_reduce(PyObject *self, PyObject *unused)
636 {
637     _Py_IDENTIFIER(__dict__);
638     PyObject *dict;
639     if (_PyObject_LookupAttrId(self, &PyId___dict__, &dict) < 0) {
640         return NULL;
641     }
642     if (dict) {
643         return Py_BuildValue("O()N", Py_TYPE(self), dict);
644     }
645     return Py_BuildValue("O()", Py_TYPE(self));
646 }
647 
648 static PyMethodDef ast_type_methods[] = {
649     {"__reduce__", ast_type_reduce, METH_NOARGS, NULL},
650     {NULL}
651 };
652 
653 static PyGetSetDef ast_type_getsets[] = {
654     {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict},
655     {NULL}
656 };
657 
658 static PyTypeObject AST_type = {
659     PyVarObject_HEAD_INIT(&PyType_Type, 0)
660     "_ast.AST",
661     sizeof(AST_object),
662     0,
663     (destructor)ast_dealloc, /* tp_dealloc */
664     0,                       /* tp_vectorcall_offset */
665     0,                       /* tp_getattr */
666     0,                       /* tp_setattr */
667     0,                       /* tp_as_async */
668     0,                       /* tp_repr */
669     0,                       /* tp_as_number */
670     0,                       /* tp_as_sequence */
671     0,                       /* tp_as_mapping */
672     0,                       /* tp_hash */
673     0,                       /* tp_call */
674     0,                       /* tp_str */
675     PyObject_GenericGetAttr, /* tp_getattro */
676     PyObject_GenericSetAttr, /* tp_setattro */
677     0,                       /* tp_as_buffer */
678     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /* tp_flags */
679     0,                       /* tp_doc */
680     (traverseproc)ast_traverse, /* tp_traverse */
681     (inquiry)ast_clear,      /* tp_clear */
682     0,                       /* tp_richcompare */
683     0,                       /* tp_weaklistoffset */
684     0,                       /* tp_iter */
685     0,                       /* tp_iternext */
686     ast_type_methods,        /* tp_methods */
687     0,                       /* tp_members */
688     ast_type_getsets,        /* tp_getset */
689     0,                       /* tp_base */
690     0,                       /* tp_dict */
691     0,                       /* tp_descr_get */
692     0,                       /* tp_descr_set */
693     offsetof(AST_object, dict),/* tp_dictoffset */
694     (initproc)ast_type_init, /* tp_init */
695     PyType_GenericAlloc,     /* tp_alloc */
696     PyType_GenericNew,       /* tp_new */
697     PyObject_GC_Del,         /* tp_free */
698 };
699 
700 
make_type(char * type,PyTypeObject * base,char ** fields,int num_fields)701 static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields)
702 {
703     _Py_IDENTIFIER(__module__);
704     _Py_IDENTIFIER(_ast);
705     PyObject *fnames, *result;
706     int i;
707     fnames = PyTuple_New(num_fields);
708     if (!fnames) return NULL;
709     for (i = 0; i < num_fields; i++) {
710         PyObject *field = PyUnicode_FromString(fields[i]);
711         if (!field) {
712             Py_DECREF(fnames);
713             return NULL;
714         }
715         PyTuple_SET_ITEM(fnames, i, field);
716     }
717     result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){OOOO}",
718                     type, base,
719                     _PyUnicode_FromId(&PyId__fields), fnames,
720                     _PyUnicode_FromId(&PyId___module__),
721                     _PyUnicode_FromId(&PyId__ast));
722     Py_DECREF(fnames);
723     return (PyTypeObject*)result;
724 }
725 
add_attributes(PyTypeObject * type,char ** attrs,int num_fields)726 static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)
727 {
728     int i, result;
729     PyObject *s, *l = PyTuple_New(num_fields);
730     if (!l)
731         return 0;
732     for (i = 0; i < num_fields; i++) {
733         s = PyUnicode_FromString(attrs[i]);
734         if (!s) {
735             Py_DECREF(l);
736             return 0;
737         }
738         PyTuple_SET_ITEM(l, i, s);
739     }
740     result = _PyObject_SetAttrId((PyObject*)type, &PyId__attributes, l) >= 0;
741     Py_DECREF(l);
742     return result;
743 }
744 
745 /* Conversion AST -> Python */
746 
ast2obj_list(asdl_seq * seq,PyObject * (* func)(void *))747 static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
748 {
749     Py_ssize_t i, n = asdl_seq_LEN(seq);
750     PyObject *result = PyList_New(n);
751     PyObject *value;
752     if (!result)
753         return NULL;
754     for (i = 0; i < n; i++) {
755         value = func(asdl_seq_GET(seq, i));
756         if (!value) {
757             Py_DECREF(result);
758             return NULL;
759         }
760         PyList_SET_ITEM(result, i, value);
761     }
762     return result;
763 }
764 
ast2obj_object(void * o)765 static PyObject* ast2obj_object(void *o)
766 {
767     if (!o)
768         o = Py_None;
769     Py_INCREF((PyObject*)o);
770     return (PyObject*)o;
771 }
772 #define ast2obj_singleton ast2obj_object
773 #define ast2obj_constant ast2obj_object
774 #define ast2obj_identifier ast2obj_object
775 #define ast2obj_string ast2obj_object
776 #define ast2obj_bytes ast2obj_object
777 
ast2obj_int(long b)778 static PyObject* ast2obj_int(long b)
779 {
780     return PyLong_FromLong(b);
781 }
782 
783 /* Conversion Python -> AST */
784 
obj2ast_object(PyObject * obj,PyObject ** out,PyArena * arena)785 static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena)
786 {
787     if (obj == Py_None)
788         obj = NULL;
789     if (obj) {
790         if (PyArena_AddPyObject(arena, obj) < 0) {
791             *out = NULL;
792             return -1;
793         }
794         Py_INCREF(obj);
795     }
796     *out = obj;
797     return 0;
798 }
799 
obj2ast_constant(PyObject * obj,PyObject ** out,PyArena * arena)800 static int obj2ast_constant(PyObject* obj, PyObject** out, PyArena* arena)
801 {
802     if (PyArena_AddPyObject(arena, obj) < 0) {
803         *out = NULL;
804         return -1;
805     }
806     Py_INCREF(obj);
807     *out = obj;
808     return 0;
809 }
810 
obj2ast_identifier(PyObject * obj,PyObject ** out,PyArena * arena)811 static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena)
812 {
813     if (!PyUnicode_CheckExact(obj) && obj != Py_None) {
814         PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str");
815         return 1;
816     }
817     return obj2ast_object(obj, out, arena);
818 }
819 
obj2ast_string(PyObject * obj,PyObject ** out,PyArena * arena)820 static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena)
821 {
822     if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) {
823         PyErr_SetString(PyExc_TypeError, "AST string must be of type str");
824         return 1;
825     }
826     return obj2ast_object(obj, out, arena);
827 }
828 
obj2ast_int(PyObject * obj,int * out,PyArena * arena)829 static int obj2ast_int(PyObject* obj, int* out, PyArena* arena)
830 {
831     int i;
832     if (!PyLong_Check(obj)) {
833         PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj);
834         return 1;
835     }
836 
837     i = _PyLong_AsInt(obj);
838     if (i == -1 && PyErr_Occurred())
839         return 1;
840     *out = i;
841     return 0;
842 }
843 
add_ast_fields(void)844 static int add_ast_fields(void)
845 {
846     PyObject *empty_tuple, *d;
847     if (PyType_Ready(&AST_type) < 0)
848         return -1;
849     d = AST_type.tp_dict;
850     empty_tuple = PyTuple_New(0);
851     if (!empty_tuple ||
852         _PyDict_SetItemId(d, &PyId__fields, empty_tuple) < 0 ||
853         _PyDict_SetItemId(d, &PyId__attributes, empty_tuple) < 0) {
854         Py_XDECREF(empty_tuple);
855         return -1;
856     }
857     Py_DECREF(empty_tuple);
858     return 0;
859 }
860 
861 
init_types(void)862 static int init_types(void)
863 {
864     static int initialized;
865     if (initialized) return 1;
866     if (add_ast_fields() < 0) return 0;
867     mod_type = make_type("mod", &AST_type, NULL, 0);
868     if (!mod_type) return 0;
869     if (!add_attributes(mod_type, NULL, 0)) return 0;
870     Module_type = make_type("Module", mod_type, Module_fields, 2);
871     if (!Module_type) return 0;
872     Interactive_type = make_type("Interactive", mod_type, Interactive_fields,
873                                  1);
874     if (!Interactive_type) return 0;
875     Expression_type = make_type("Expression", mod_type, Expression_fields, 1);
876     if (!Expression_type) return 0;
877     FunctionType_type = make_type("FunctionType", mod_type,
878                                   FunctionType_fields, 2);
879     if (!FunctionType_type) return 0;
880     Suite_type = make_type("Suite", mod_type, Suite_fields, 1);
881     if (!Suite_type) return 0;
882     stmt_type = make_type("stmt", &AST_type, NULL, 0);
883     if (!stmt_type) return 0;
884     if (!add_attributes(stmt_type, stmt_attributes, 4)) return 0;
885     FunctionDef_type = make_type("FunctionDef", stmt_type, FunctionDef_fields,
886                                  6);
887     if (!FunctionDef_type) return 0;
888     AsyncFunctionDef_type = make_type("AsyncFunctionDef", stmt_type,
889                                       AsyncFunctionDef_fields, 6);
890     if (!AsyncFunctionDef_type) return 0;
891     ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 5);
892     if (!ClassDef_type) return 0;
893     Return_type = make_type("Return", stmt_type, Return_fields, 1);
894     if (!Return_type) return 0;
895     Delete_type = make_type("Delete", stmt_type, Delete_fields, 1);
896     if (!Delete_type) return 0;
897     Assign_type = make_type("Assign", stmt_type, Assign_fields, 3);
898     if (!Assign_type) return 0;
899     AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3);
900     if (!AugAssign_type) return 0;
901     AnnAssign_type = make_type("AnnAssign", stmt_type, AnnAssign_fields, 4);
902     if (!AnnAssign_type) return 0;
903     For_type = make_type("For", stmt_type, For_fields, 5);
904     if (!For_type) return 0;
905     AsyncFor_type = make_type("AsyncFor", stmt_type, AsyncFor_fields, 5);
906     if (!AsyncFor_type) return 0;
907     While_type = make_type("While", stmt_type, While_fields, 3);
908     if (!While_type) return 0;
909     If_type = make_type("If", stmt_type, If_fields, 3);
910     if (!If_type) return 0;
911     With_type = make_type("With", stmt_type, With_fields, 3);
912     if (!With_type) return 0;
913     AsyncWith_type = make_type("AsyncWith", stmt_type, AsyncWith_fields, 3);
914     if (!AsyncWith_type) return 0;
915     Raise_type = make_type("Raise", stmt_type, Raise_fields, 2);
916     if (!Raise_type) return 0;
917     Try_type = make_type("Try", stmt_type, Try_fields, 4);
918     if (!Try_type) return 0;
919     Assert_type = make_type("Assert", stmt_type, Assert_fields, 2);
920     if (!Assert_type) return 0;
921     Import_type = make_type("Import", stmt_type, Import_fields, 1);
922     if (!Import_type) return 0;
923     ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields, 3);
924     if (!ImportFrom_type) return 0;
925     Global_type = make_type("Global", stmt_type, Global_fields, 1);
926     if (!Global_type) return 0;
927     Nonlocal_type = make_type("Nonlocal", stmt_type, Nonlocal_fields, 1);
928     if (!Nonlocal_type) return 0;
929     Expr_type = make_type("Expr", stmt_type, Expr_fields, 1);
930     if (!Expr_type) return 0;
931     Pass_type = make_type("Pass", stmt_type, NULL, 0);
932     if (!Pass_type) return 0;
933     Break_type = make_type("Break", stmt_type, NULL, 0);
934     if (!Break_type) return 0;
935     Continue_type = make_type("Continue", stmt_type, NULL, 0);
936     if (!Continue_type) return 0;
937     expr_type = make_type("expr", &AST_type, NULL, 0);
938     if (!expr_type) return 0;
939     if (!add_attributes(expr_type, expr_attributes, 4)) return 0;
940     BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2);
941     if (!BoolOp_type) return 0;
942     NamedExpr_type = make_type("NamedExpr", expr_type, NamedExpr_fields, 2);
943     if (!NamedExpr_type) return 0;
944     BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3);
945     if (!BinOp_type) return 0;
946     UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2);
947     if (!UnaryOp_type) return 0;
948     Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2);
949     if (!Lambda_type) return 0;
950     IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3);
951     if (!IfExp_type) return 0;
952     Dict_type = make_type("Dict", expr_type, Dict_fields, 2);
953     if (!Dict_type) return 0;
954     Set_type = make_type("Set", expr_type, Set_fields, 1);
955     if (!Set_type) return 0;
956     ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2);
957     if (!ListComp_type) return 0;
958     SetComp_type = make_type("SetComp", expr_type, SetComp_fields, 2);
959     if (!SetComp_type) return 0;
960     DictComp_type = make_type("DictComp", expr_type, DictComp_fields, 3);
961     if (!DictComp_type) return 0;
962     GeneratorExp_type = make_type("GeneratorExp", expr_type,
963                                   GeneratorExp_fields, 2);
964     if (!GeneratorExp_type) return 0;
965     Await_type = make_type("Await", expr_type, Await_fields, 1);
966     if (!Await_type) return 0;
967     Yield_type = make_type("Yield", expr_type, Yield_fields, 1);
968     if (!Yield_type) return 0;
969     YieldFrom_type = make_type("YieldFrom", expr_type, YieldFrom_fields, 1);
970     if (!YieldFrom_type) return 0;
971     Compare_type = make_type("Compare", expr_type, Compare_fields, 3);
972     if (!Compare_type) return 0;
973     Call_type = make_type("Call", expr_type, Call_fields, 3);
974     if (!Call_type) return 0;
975     FormattedValue_type = make_type("FormattedValue", expr_type,
976                                     FormattedValue_fields, 3);
977     if (!FormattedValue_type) return 0;
978     JoinedStr_type = make_type("JoinedStr", expr_type, JoinedStr_fields, 1);
979     if (!JoinedStr_type) return 0;
980     Constant_type = make_type("Constant", expr_type, Constant_fields, 2);
981     if (!Constant_type) return 0;
982     Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3);
983     if (!Attribute_type) return 0;
984     Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3);
985     if (!Subscript_type) return 0;
986     Starred_type = make_type("Starred", expr_type, Starred_fields, 2);
987     if (!Starred_type) return 0;
988     Name_type = make_type("Name", expr_type, Name_fields, 2);
989     if (!Name_type) return 0;
990     List_type = make_type("List", expr_type, List_fields, 2);
991     if (!List_type) return 0;
992     Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2);
993     if (!Tuple_type) return 0;
994     expr_context_type = make_type("expr_context", &AST_type, NULL, 0);
995     if (!expr_context_type) return 0;
996     if (!add_attributes(expr_context_type, NULL, 0)) return 0;
997     Load_type = make_type("Load", expr_context_type, NULL, 0);
998     if (!Load_type) return 0;
999     Load_singleton = PyType_GenericNew(Load_type, NULL, NULL);
1000     if (!Load_singleton) return 0;
1001     Store_type = make_type("Store", expr_context_type, NULL, 0);
1002     if (!Store_type) return 0;
1003     Store_singleton = PyType_GenericNew(Store_type, NULL, NULL);
1004     if (!Store_singleton) return 0;
1005     Del_type = make_type("Del", expr_context_type, NULL, 0);
1006     if (!Del_type) return 0;
1007     Del_singleton = PyType_GenericNew(Del_type, NULL, NULL);
1008     if (!Del_singleton) return 0;
1009     AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0);
1010     if (!AugLoad_type) return 0;
1011     AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL);
1012     if (!AugLoad_singleton) return 0;
1013     AugStore_type = make_type("AugStore", expr_context_type, NULL, 0);
1014     if (!AugStore_type) return 0;
1015     AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL);
1016     if (!AugStore_singleton) return 0;
1017     Param_type = make_type("Param", expr_context_type, NULL, 0);
1018     if (!Param_type) return 0;
1019     Param_singleton = PyType_GenericNew(Param_type, NULL, NULL);
1020     if (!Param_singleton) return 0;
1021     slice_type = make_type("slice", &AST_type, NULL, 0);
1022     if (!slice_type) return 0;
1023     if (!add_attributes(slice_type, NULL, 0)) return 0;
1024     Slice_type = make_type("Slice", slice_type, Slice_fields, 3);
1025     if (!Slice_type) return 0;
1026     ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1);
1027     if (!ExtSlice_type) return 0;
1028     Index_type = make_type("Index", slice_type, Index_fields, 1);
1029     if (!Index_type) return 0;
1030     boolop_type = make_type("boolop", &AST_type, NULL, 0);
1031     if (!boolop_type) return 0;
1032     if (!add_attributes(boolop_type, NULL, 0)) return 0;
1033     And_type = make_type("And", boolop_type, NULL, 0);
1034     if (!And_type) return 0;
1035     And_singleton = PyType_GenericNew(And_type, NULL, NULL);
1036     if (!And_singleton) return 0;
1037     Or_type = make_type("Or", boolop_type, NULL, 0);
1038     if (!Or_type) return 0;
1039     Or_singleton = PyType_GenericNew(Or_type, NULL, NULL);
1040     if (!Or_singleton) return 0;
1041     operator_type = make_type("operator", &AST_type, NULL, 0);
1042     if (!operator_type) return 0;
1043     if (!add_attributes(operator_type, NULL, 0)) return 0;
1044     Add_type = make_type("Add", operator_type, NULL, 0);
1045     if (!Add_type) return 0;
1046     Add_singleton = PyType_GenericNew(Add_type, NULL, NULL);
1047     if (!Add_singleton) return 0;
1048     Sub_type = make_type("Sub", operator_type, NULL, 0);
1049     if (!Sub_type) return 0;
1050     Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL);
1051     if (!Sub_singleton) return 0;
1052     Mult_type = make_type("Mult", operator_type, NULL, 0);
1053     if (!Mult_type) return 0;
1054     Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL);
1055     if (!Mult_singleton) return 0;
1056     MatMult_type = make_type("MatMult", operator_type, NULL, 0);
1057     if (!MatMult_type) return 0;
1058     MatMult_singleton = PyType_GenericNew(MatMult_type, NULL, NULL);
1059     if (!MatMult_singleton) return 0;
1060     Div_type = make_type("Div", operator_type, NULL, 0);
1061     if (!Div_type) return 0;
1062     Div_singleton = PyType_GenericNew(Div_type, NULL, NULL);
1063     if (!Div_singleton) return 0;
1064     Mod_type = make_type("Mod", operator_type, NULL, 0);
1065     if (!Mod_type) return 0;
1066     Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL);
1067     if (!Mod_singleton) return 0;
1068     Pow_type = make_type("Pow", operator_type, NULL, 0);
1069     if (!Pow_type) return 0;
1070     Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL);
1071     if (!Pow_singleton) return 0;
1072     LShift_type = make_type("LShift", operator_type, NULL, 0);
1073     if (!LShift_type) return 0;
1074     LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL);
1075     if (!LShift_singleton) return 0;
1076     RShift_type = make_type("RShift", operator_type, NULL, 0);
1077     if (!RShift_type) return 0;
1078     RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL);
1079     if (!RShift_singleton) return 0;
1080     BitOr_type = make_type("BitOr", operator_type, NULL, 0);
1081     if (!BitOr_type) return 0;
1082     BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL);
1083     if (!BitOr_singleton) return 0;
1084     BitXor_type = make_type("BitXor", operator_type, NULL, 0);
1085     if (!BitXor_type) return 0;
1086     BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL);
1087     if (!BitXor_singleton) return 0;
1088     BitAnd_type = make_type("BitAnd", operator_type, NULL, 0);
1089     if (!BitAnd_type) return 0;
1090     BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL);
1091     if (!BitAnd_singleton) return 0;
1092     FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0);
1093     if (!FloorDiv_type) return 0;
1094     FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL);
1095     if (!FloorDiv_singleton) return 0;
1096     unaryop_type = make_type("unaryop", &AST_type, NULL, 0);
1097     if (!unaryop_type) return 0;
1098     if (!add_attributes(unaryop_type, NULL, 0)) return 0;
1099     Invert_type = make_type("Invert", unaryop_type, NULL, 0);
1100     if (!Invert_type) return 0;
1101     Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL);
1102     if (!Invert_singleton) return 0;
1103     Not_type = make_type("Not", unaryop_type, NULL, 0);
1104     if (!Not_type) return 0;
1105     Not_singleton = PyType_GenericNew(Not_type, NULL, NULL);
1106     if (!Not_singleton) return 0;
1107     UAdd_type = make_type("UAdd", unaryop_type, NULL, 0);
1108     if (!UAdd_type) return 0;
1109     UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL);
1110     if (!UAdd_singleton) return 0;
1111     USub_type = make_type("USub", unaryop_type, NULL, 0);
1112     if (!USub_type) return 0;
1113     USub_singleton = PyType_GenericNew(USub_type, NULL, NULL);
1114     if (!USub_singleton) return 0;
1115     cmpop_type = make_type("cmpop", &AST_type, NULL, 0);
1116     if (!cmpop_type) return 0;
1117     if (!add_attributes(cmpop_type, NULL, 0)) return 0;
1118     Eq_type = make_type("Eq", cmpop_type, NULL, 0);
1119     if (!Eq_type) return 0;
1120     Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL);
1121     if (!Eq_singleton) return 0;
1122     NotEq_type = make_type("NotEq", cmpop_type, NULL, 0);
1123     if (!NotEq_type) return 0;
1124     NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL);
1125     if (!NotEq_singleton) return 0;
1126     Lt_type = make_type("Lt", cmpop_type, NULL, 0);
1127     if (!Lt_type) return 0;
1128     Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL);
1129     if (!Lt_singleton) return 0;
1130     LtE_type = make_type("LtE", cmpop_type, NULL, 0);
1131     if (!LtE_type) return 0;
1132     LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL);
1133     if (!LtE_singleton) return 0;
1134     Gt_type = make_type("Gt", cmpop_type, NULL, 0);
1135     if (!Gt_type) return 0;
1136     Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL);
1137     if (!Gt_singleton) return 0;
1138     GtE_type = make_type("GtE", cmpop_type, NULL, 0);
1139     if (!GtE_type) return 0;
1140     GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL);
1141     if (!GtE_singleton) return 0;
1142     Is_type = make_type("Is", cmpop_type, NULL, 0);
1143     if (!Is_type) return 0;
1144     Is_singleton = PyType_GenericNew(Is_type, NULL, NULL);
1145     if (!Is_singleton) return 0;
1146     IsNot_type = make_type("IsNot", cmpop_type, NULL, 0);
1147     if (!IsNot_type) return 0;
1148     IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL);
1149     if (!IsNot_singleton) return 0;
1150     In_type = make_type("In", cmpop_type, NULL, 0);
1151     if (!In_type) return 0;
1152     In_singleton = PyType_GenericNew(In_type, NULL, NULL);
1153     if (!In_singleton) return 0;
1154     NotIn_type = make_type("NotIn", cmpop_type, NULL, 0);
1155     if (!NotIn_type) return 0;
1156     NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL);
1157     if (!NotIn_singleton) return 0;
1158     comprehension_type = make_type("comprehension", &AST_type,
1159                                    comprehension_fields, 4);
1160     if (!comprehension_type) return 0;
1161     if (!add_attributes(comprehension_type, NULL, 0)) return 0;
1162     excepthandler_type = make_type("excepthandler", &AST_type, NULL, 0);
1163     if (!excepthandler_type) return 0;
1164     if (!add_attributes(excepthandler_type, excepthandler_attributes, 4))
1165         return 0;
1166     ExceptHandler_type = make_type("ExceptHandler", excepthandler_type,
1167                                    ExceptHandler_fields, 3);
1168     if (!ExceptHandler_type) return 0;
1169     arguments_type = make_type("arguments", &AST_type, arguments_fields, 7);
1170     if (!arguments_type) return 0;
1171     if (!add_attributes(arguments_type, NULL, 0)) return 0;
1172     arg_type = make_type("arg", &AST_type, arg_fields, 3);
1173     if (!arg_type) return 0;
1174     if (!add_attributes(arg_type, arg_attributes, 4)) return 0;
1175     keyword_type = make_type("keyword", &AST_type, keyword_fields, 2);
1176     if (!keyword_type) return 0;
1177     if (!add_attributes(keyword_type, NULL, 0)) return 0;
1178     alias_type = make_type("alias", &AST_type, alias_fields, 2);
1179     if (!alias_type) return 0;
1180     if (!add_attributes(alias_type, NULL, 0)) return 0;
1181     withitem_type = make_type("withitem", &AST_type, withitem_fields, 2);
1182     if (!withitem_type) return 0;
1183     if (!add_attributes(withitem_type, NULL, 0)) return 0;
1184     type_ignore_type = make_type("type_ignore", &AST_type, NULL, 0);
1185     if (!type_ignore_type) return 0;
1186     if (!add_attributes(type_ignore_type, NULL, 0)) return 0;
1187     TypeIgnore_type = make_type("TypeIgnore", type_ignore_type,
1188                                 TypeIgnore_fields, 2);
1189     if (!TypeIgnore_type) return 0;
1190     initialized = 1;
1191     return 1;
1192 }
1193 
1194 static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena);
1195 static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena);
1196 static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena);
1197 static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena*
1198                                 arena);
1199 static int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena);
1200 static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena);
1201 static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena);
1202 static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena);
1203 static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena);
1204 static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena*
1205                                  arena);
1206 static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena*
1207                                  arena);
1208 static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena);
1209 static int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena);
1210 static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena);
1211 static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena);
1212 static int obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena);
1213 static int obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena*
1214                                arena);
1215 
1216 mod_ty
Module(asdl_seq * body,asdl_seq * type_ignores,PyArena * arena)1217 Module(asdl_seq * body, asdl_seq * type_ignores, PyArena *arena)
1218 {
1219     mod_ty p;
1220     p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
1221     if (!p)
1222         return NULL;
1223     p->kind = Module_kind;
1224     p->v.Module.body = body;
1225     p->v.Module.type_ignores = type_ignores;
1226     return p;
1227 }
1228 
1229 mod_ty
Interactive(asdl_seq * body,PyArena * arena)1230 Interactive(asdl_seq * body, PyArena *arena)
1231 {
1232     mod_ty p;
1233     p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
1234     if (!p)
1235         return NULL;
1236     p->kind = Interactive_kind;
1237     p->v.Interactive.body = body;
1238     return p;
1239 }
1240 
1241 mod_ty
Expression(expr_ty body,PyArena * arena)1242 Expression(expr_ty body, PyArena *arena)
1243 {
1244     mod_ty p;
1245     if (!body) {
1246         PyErr_SetString(PyExc_ValueError,
1247                         "field body is required for Expression");
1248         return NULL;
1249     }
1250     p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
1251     if (!p)
1252         return NULL;
1253     p->kind = Expression_kind;
1254     p->v.Expression.body = body;
1255     return p;
1256 }
1257 
1258 mod_ty
FunctionType(asdl_seq * argtypes,expr_ty returns,PyArena * arena)1259 FunctionType(asdl_seq * argtypes, expr_ty returns, PyArena *arena)
1260 {
1261     mod_ty p;
1262     if (!returns) {
1263         PyErr_SetString(PyExc_ValueError,
1264                         "field returns is required for FunctionType");
1265         return NULL;
1266     }
1267     p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
1268     if (!p)
1269         return NULL;
1270     p->kind = FunctionType_kind;
1271     p->v.FunctionType.argtypes = argtypes;
1272     p->v.FunctionType.returns = returns;
1273     return p;
1274 }
1275 
1276 mod_ty
Suite(asdl_seq * body,PyArena * arena)1277 Suite(asdl_seq * body, PyArena *arena)
1278 {
1279     mod_ty p;
1280     p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
1281     if (!p)
1282         return NULL;
1283     p->kind = Suite_kind;
1284     p->v.Suite.body = body;
1285     return p;
1286 }
1287 
1288 stmt_ty
FunctionDef(identifier name,arguments_ty args,asdl_seq * body,asdl_seq * decorator_list,expr_ty returns,string type_comment,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)1289 FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
1290             decorator_list, expr_ty returns, string type_comment, int lineno,
1291             int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
1292 {
1293     stmt_ty p;
1294     if (!name) {
1295         PyErr_SetString(PyExc_ValueError,
1296                         "field name is required for FunctionDef");
1297         return NULL;
1298     }
1299     if (!args) {
1300         PyErr_SetString(PyExc_ValueError,
1301                         "field args is required for FunctionDef");
1302         return NULL;
1303     }
1304     p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1305     if (!p)
1306         return NULL;
1307     p->kind = FunctionDef_kind;
1308     p->v.FunctionDef.name = name;
1309     p->v.FunctionDef.args = args;
1310     p->v.FunctionDef.body = body;
1311     p->v.FunctionDef.decorator_list = decorator_list;
1312     p->v.FunctionDef.returns = returns;
1313     p->v.FunctionDef.type_comment = type_comment;
1314     p->lineno = lineno;
1315     p->col_offset = col_offset;
1316     p->end_lineno = end_lineno;
1317     p->end_col_offset = end_col_offset;
1318     return p;
1319 }
1320 
1321 stmt_ty
AsyncFunctionDef(identifier name,arguments_ty args,asdl_seq * body,asdl_seq * decorator_list,expr_ty returns,string type_comment,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)1322 AsyncFunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq
1323                  * decorator_list, expr_ty returns, string type_comment, int
1324                  lineno, int col_offset, int end_lineno, int end_col_offset,
1325                  PyArena *arena)
1326 {
1327     stmt_ty p;
1328     if (!name) {
1329         PyErr_SetString(PyExc_ValueError,
1330                         "field name is required for AsyncFunctionDef");
1331         return NULL;
1332     }
1333     if (!args) {
1334         PyErr_SetString(PyExc_ValueError,
1335                         "field args is required for AsyncFunctionDef");
1336         return NULL;
1337     }
1338     p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1339     if (!p)
1340         return NULL;
1341     p->kind = AsyncFunctionDef_kind;
1342     p->v.AsyncFunctionDef.name = name;
1343     p->v.AsyncFunctionDef.args = args;
1344     p->v.AsyncFunctionDef.body = body;
1345     p->v.AsyncFunctionDef.decorator_list = decorator_list;
1346     p->v.AsyncFunctionDef.returns = returns;
1347     p->v.AsyncFunctionDef.type_comment = type_comment;
1348     p->lineno = lineno;
1349     p->col_offset = col_offset;
1350     p->end_lineno = end_lineno;
1351     p->end_col_offset = end_col_offset;
1352     return p;
1353 }
1354 
1355 stmt_ty
ClassDef(identifier name,asdl_seq * bases,asdl_seq * keywords,asdl_seq * body,asdl_seq * decorator_list,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)1356 ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, asdl_seq *
1357          body, asdl_seq * decorator_list, int lineno, int col_offset, int
1358          end_lineno, int end_col_offset, PyArena *arena)
1359 {
1360     stmt_ty p;
1361     if (!name) {
1362         PyErr_SetString(PyExc_ValueError,
1363                         "field name is required for ClassDef");
1364         return NULL;
1365     }
1366     p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1367     if (!p)
1368         return NULL;
1369     p->kind = ClassDef_kind;
1370     p->v.ClassDef.name = name;
1371     p->v.ClassDef.bases = bases;
1372     p->v.ClassDef.keywords = keywords;
1373     p->v.ClassDef.body = body;
1374     p->v.ClassDef.decorator_list = decorator_list;
1375     p->lineno = lineno;
1376     p->col_offset = col_offset;
1377     p->end_lineno = end_lineno;
1378     p->end_col_offset = end_col_offset;
1379     return p;
1380 }
1381 
1382 stmt_ty
Return(expr_ty value,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)1383 Return(expr_ty value, int lineno, int col_offset, int end_lineno, int
1384        end_col_offset, PyArena *arena)
1385 {
1386     stmt_ty p;
1387     p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1388     if (!p)
1389         return NULL;
1390     p->kind = Return_kind;
1391     p->v.Return.value = value;
1392     p->lineno = lineno;
1393     p->col_offset = col_offset;
1394     p->end_lineno = end_lineno;
1395     p->end_col_offset = end_col_offset;
1396     return p;
1397 }
1398 
1399 stmt_ty
Delete(asdl_seq * targets,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)1400 Delete(asdl_seq * targets, int lineno, int col_offset, int end_lineno, int
1401        end_col_offset, PyArena *arena)
1402 {
1403     stmt_ty p;
1404     p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1405     if (!p)
1406         return NULL;
1407     p->kind = Delete_kind;
1408     p->v.Delete.targets = targets;
1409     p->lineno = lineno;
1410     p->col_offset = col_offset;
1411     p->end_lineno = end_lineno;
1412     p->end_col_offset = end_col_offset;
1413     return p;
1414 }
1415 
1416 stmt_ty
Assign(asdl_seq * targets,expr_ty value,string type_comment,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)1417 Assign(asdl_seq * targets, expr_ty value, string type_comment, int lineno, int
1418        col_offset, int end_lineno, int end_col_offset, PyArena *arena)
1419 {
1420     stmt_ty p;
1421     if (!value) {
1422         PyErr_SetString(PyExc_ValueError,
1423                         "field value is required for Assign");
1424         return NULL;
1425     }
1426     p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1427     if (!p)
1428         return NULL;
1429     p->kind = Assign_kind;
1430     p->v.Assign.targets = targets;
1431     p->v.Assign.value = value;
1432     p->v.Assign.type_comment = type_comment;
1433     p->lineno = lineno;
1434     p->col_offset = col_offset;
1435     p->end_lineno = end_lineno;
1436     p->end_col_offset = end_col_offset;
1437     return p;
1438 }
1439 
1440 stmt_ty
AugAssign(expr_ty target,operator_ty op,expr_ty value,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)1441 AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
1442           col_offset, int end_lineno, int end_col_offset, PyArena *arena)
1443 {
1444     stmt_ty p;
1445     if (!target) {
1446         PyErr_SetString(PyExc_ValueError,
1447                         "field target is required for AugAssign");
1448         return NULL;
1449     }
1450     if (!op) {
1451         PyErr_SetString(PyExc_ValueError,
1452                         "field op is required for AugAssign");
1453         return NULL;
1454     }
1455     if (!value) {
1456         PyErr_SetString(PyExc_ValueError,
1457                         "field value is required for AugAssign");
1458         return NULL;
1459     }
1460     p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1461     if (!p)
1462         return NULL;
1463     p->kind = AugAssign_kind;
1464     p->v.AugAssign.target = target;
1465     p->v.AugAssign.op = op;
1466     p->v.AugAssign.value = value;
1467     p->lineno = lineno;
1468     p->col_offset = col_offset;
1469     p->end_lineno = end_lineno;
1470     p->end_col_offset = end_col_offset;
1471     return p;
1472 }
1473 
1474 stmt_ty
AnnAssign(expr_ty target,expr_ty annotation,expr_ty value,int simple,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)1475 AnnAssign(expr_ty target, expr_ty annotation, expr_ty value, int simple, int
1476           lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
1477           *arena)
1478 {
1479     stmt_ty p;
1480     if (!target) {
1481         PyErr_SetString(PyExc_ValueError,
1482                         "field target is required for AnnAssign");
1483         return NULL;
1484     }
1485     if (!annotation) {
1486         PyErr_SetString(PyExc_ValueError,
1487                         "field annotation is required for AnnAssign");
1488         return NULL;
1489     }
1490     p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1491     if (!p)
1492         return NULL;
1493     p->kind = AnnAssign_kind;
1494     p->v.AnnAssign.target = target;
1495     p->v.AnnAssign.annotation = annotation;
1496     p->v.AnnAssign.value = value;
1497     p->v.AnnAssign.simple = simple;
1498     p->lineno = lineno;
1499     p->col_offset = col_offset;
1500     p->end_lineno = end_lineno;
1501     p->end_col_offset = end_col_offset;
1502     return p;
1503 }
1504 
1505 stmt_ty
For(expr_ty target,expr_ty iter,asdl_seq * body,asdl_seq * orelse,string type_comment,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)1506 For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, string
1507     type_comment, int lineno, int col_offset, int end_lineno, int
1508     end_col_offset, PyArena *arena)
1509 {
1510     stmt_ty p;
1511     if (!target) {
1512         PyErr_SetString(PyExc_ValueError,
1513                         "field target is required for For");
1514         return NULL;
1515     }
1516     if (!iter) {
1517         PyErr_SetString(PyExc_ValueError,
1518                         "field iter is required for For");
1519         return NULL;
1520     }
1521     p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1522     if (!p)
1523         return NULL;
1524     p->kind = For_kind;
1525     p->v.For.target = target;
1526     p->v.For.iter = iter;
1527     p->v.For.body = body;
1528     p->v.For.orelse = orelse;
1529     p->v.For.type_comment = type_comment;
1530     p->lineno = lineno;
1531     p->col_offset = col_offset;
1532     p->end_lineno = end_lineno;
1533     p->end_col_offset = end_col_offset;
1534     return p;
1535 }
1536 
1537 stmt_ty
AsyncFor(expr_ty target,expr_ty iter,asdl_seq * body,asdl_seq * orelse,string type_comment,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)1538 AsyncFor(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse,
1539          string type_comment, int lineno, int col_offset, int end_lineno, int
1540          end_col_offset, PyArena *arena)
1541 {
1542     stmt_ty p;
1543     if (!target) {
1544         PyErr_SetString(PyExc_ValueError,
1545                         "field target is required for AsyncFor");
1546         return NULL;
1547     }
1548     if (!iter) {
1549         PyErr_SetString(PyExc_ValueError,
1550                         "field iter is required for AsyncFor");
1551         return NULL;
1552     }
1553     p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1554     if (!p)
1555         return NULL;
1556     p->kind = AsyncFor_kind;
1557     p->v.AsyncFor.target = target;
1558     p->v.AsyncFor.iter = iter;
1559     p->v.AsyncFor.body = body;
1560     p->v.AsyncFor.orelse = orelse;
1561     p->v.AsyncFor.type_comment = type_comment;
1562     p->lineno = lineno;
1563     p->col_offset = col_offset;
1564     p->end_lineno = end_lineno;
1565     p->end_col_offset = end_col_offset;
1566     return p;
1567 }
1568 
1569 stmt_ty
While(expr_ty test,asdl_seq * body,asdl_seq * orelse,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)1570 While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
1571       col_offset, int end_lineno, int end_col_offset, PyArena *arena)
1572 {
1573     stmt_ty p;
1574     if (!test) {
1575         PyErr_SetString(PyExc_ValueError,
1576                         "field test is required for While");
1577         return NULL;
1578     }
1579     p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1580     if (!p)
1581         return NULL;
1582     p->kind = While_kind;
1583     p->v.While.test = test;
1584     p->v.While.body = body;
1585     p->v.While.orelse = orelse;
1586     p->lineno = lineno;
1587     p->col_offset = col_offset;
1588     p->end_lineno = end_lineno;
1589     p->end_col_offset = end_col_offset;
1590     return p;
1591 }
1592 
1593 stmt_ty
If(expr_ty test,asdl_seq * body,asdl_seq * orelse,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)1594 If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
1595    col_offset, int end_lineno, int end_col_offset, PyArena *arena)
1596 {
1597     stmt_ty p;
1598     if (!test) {
1599         PyErr_SetString(PyExc_ValueError,
1600                         "field test is required for If");
1601         return NULL;
1602     }
1603     p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1604     if (!p)
1605         return NULL;
1606     p->kind = If_kind;
1607     p->v.If.test = test;
1608     p->v.If.body = body;
1609     p->v.If.orelse = orelse;
1610     p->lineno = lineno;
1611     p->col_offset = col_offset;
1612     p->end_lineno = end_lineno;
1613     p->end_col_offset = end_col_offset;
1614     return p;
1615 }
1616 
1617 stmt_ty
With(asdl_seq * items,asdl_seq * body,string type_comment,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)1618 With(asdl_seq * items, asdl_seq * body, string type_comment, int lineno, int
1619      col_offset, int end_lineno, int end_col_offset, PyArena *arena)
1620 {
1621     stmt_ty p;
1622     p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1623     if (!p)
1624         return NULL;
1625     p->kind = With_kind;
1626     p->v.With.items = items;
1627     p->v.With.body = body;
1628     p->v.With.type_comment = type_comment;
1629     p->lineno = lineno;
1630     p->col_offset = col_offset;
1631     p->end_lineno = end_lineno;
1632     p->end_col_offset = end_col_offset;
1633     return p;
1634 }
1635 
1636 stmt_ty
AsyncWith(asdl_seq * items,asdl_seq * body,string type_comment,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)1637 AsyncWith(asdl_seq * items, asdl_seq * body, string type_comment, int lineno,
1638           int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
1639 {
1640     stmt_ty p;
1641     p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1642     if (!p)
1643         return NULL;
1644     p->kind = AsyncWith_kind;
1645     p->v.AsyncWith.items = items;
1646     p->v.AsyncWith.body = body;
1647     p->v.AsyncWith.type_comment = type_comment;
1648     p->lineno = lineno;
1649     p->col_offset = col_offset;
1650     p->end_lineno = end_lineno;
1651     p->end_col_offset = end_col_offset;
1652     return p;
1653 }
1654 
1655 stmt_ty
Raise(expr_ty exc,expr_ty cause,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)1656 Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, int end_lineno,
1657       int end_col_offset, PyArena *arena)
1658 {
1659     stmt_ty p;
1660     p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1661     if (!p)
1662         return NULL;
1663     p->kind = Raise_kind;
1664     p->v.Raise.exc = exc;
1665     p->v.Raise.cause = cause;
1666     p->lineno = lineno;
1667     p->col_offset = col_offset;
1668     p->end_lineno = end_lineno;
1669     p->end_col_offset = end_col_offset;
1670     return p;
1671 }
1672 
1673 stmt_ty
Try(asdl_seq * body,asdl_seq * handlers,asdl_seq * orelse,asdl_seq * finalbody,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)1674 Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, asdl_seq *
1675     finalbody, int lineno, int col_offset, int end_lineno, int end_col_offset,
1676     PyArena *arena)
1677 {
1678     stmt_ty p;
1679     p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1680     if (!p)
1681         return NULL;
1682     p->kind = Try_kind;
1683     p->v.Try.body = body;
1684     p->v.Try.handlers = handlers;
1685     p->v.Try.orelse = orelse;
1686     p->v.Try.finalbody = finalbody;
1687     p->lineno = lineno;
1688     p->col_offset = col_offset;
1689     p->end_lineno = end_lineno;
1690     p->end_col_offset = end_col_offset;
1691     return p;
1692 }
1693 
1694 stmt_ty
Assert(expr_ty test,expr_ty msg,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)1695 Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, int end_lineno,
1696        int end_col_offset, PyArena *arena)
1697 {
1698     stmt_ty p;
1699     if (!test) {
1700         PyErr_SetString(PyExc_ValueError,
1701                         "field test is required for Assert");
1702         return NULL;
1703     }
1704     p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1705     if (!p)
1706         return NULL;
1707     p->kind = Assert_kind;
1708     p->v.Assert.test = test;
1709     p->v.Assert.msg = msg;
1710     p->lineno = lineno;
1711     p->col_offset = col_offset;
1712     p->end_lineno = end_lineno;
1713     p->end_col_offset = end_col_offset;
1714     return p;
1715 }
1716 
1717 stmt_ty
Import(asdl_seq * names,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)1718 Import(asdl_seq * names, int lineno, int col_offset, int end_lineno, int
1719        end_col_offset, PyArena *arena)
1720 {
1721     stmt_ty p;
1722     p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1723     if (!p)
1724         return NULL;
1725     p->kind = Import_kind;
1726     p->v.Import.names = names;
1727     p->lineno = lineno;
1728     p->col_offset = col_offset;
1729     p->end_lineno = end_lineno;
1730     p->end_col_offset = end_col_offset;
1731     return p;
1732 }
1733 
1734 stmt_ty
ImportFrom(identifier module,asdl_seq * names,int level,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)1735 ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int
1736            col_offset, int end_lineno, int end_col_offset, PyArena *arena)
1737 {
1738     stmt_ty p;
1739     p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1740     if (!p)
1741         return NULL;
1742     p->kind = ImportFrom_kind;
1743     p->v.ImportFrom.module = module;
1744     p->v.ImportFrom.names = names;
1745     p->v.ImportFrom.level = level;
1746     p->lineno = lineno;
1747     p->col_offset = col_offset;
1748     p->end_lineno = end_lineno;
1749     p->end_col_offset = end_col_offset;
1750     return p;
1751 }
1752 
1753 stmt_ty
Global(asdl_seq * names,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)1754 Global(asdl_seq * names, int lineno, int col_offset, int end_lineno, int
1755        end_col_offset, PyArena *arena)
1756 {
1757     stmt_ty p;
1758     p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1759     if (!p)
1760         return NULL;
1761     p->kind = Global_kind;
1762     p->v.Global.names = names;
1763     p->lineno = lineno;
1764     p->col_offset = col_offset;
1765     p->end_lineno = end_lineno;
1766     p->end_col_offset = end_col_offset;
1767     return p;
1768 }
1769 
1770 stmt_ty
Nonlocal(asdl_seq * names,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)1771 Nonlocal(asdl_seq * names, int lineno, int col_offset, int end_lineno, int
1772          end_col_offset, PyArena *arena)
1773 {
1774     stmt_ty p;
1775     p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1776     if (!p)
1777         return NULL;
1778     p->kind = Nonlocal_kind;
1779     p->v.Nonlocal.names = names;
1780     p->lineno = lineno;
1781     p->col_offset = col_offset;
1782     p->end_lineno = end_lineno;
1783     p->end_col_offset = end_col_offset;
1784     return p;
1785 }
1786 
1787 stmt_ty
Expr(expr_ty value,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)1788 Expr(expr_ty value, int lineno, int col_offset, int end_lineno, int
1789      end_col_offset, PyArena *arena)
1790 {
1791     stmt_ty p;
1792     if (!value) {
1793         PyErr_SetString(PyExc_ValueError,
1794                         "field value is required for Expr");
1795         return NULL;
1796     }
1797     p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1798     if (!p)
1799         return NULL;
1800     p->kind = Expr_kind;
1801     p->v.Expr.value = value;
1802     p->lineno = lineno;
1803     p->col_offset = col_offset;
1804     p->end_lineno = end_lineno;
1805     p->end_col_offset = end_col_offset;
1806     return p;
1807 }
1808 
1809 stmt_ty
Pass(int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)1810 Pass(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
1811      *arena)
1812 {
1813     stmt_ty p;
1814     p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1815     if (!p)
1816         return NULL;
1817     p->kind = Pass_kind;
1818     p->lineno = lineno;
1819     p->col_offset = col_offset;
1820     p->end_lineno = end_lineno;
1821     p->end_col_offset = end_col_offset;
1822     return p;
1823 }
1824 
1825 stmt_ty
Break(int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)1826 Break(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
1827       *arena)
1828 {
1829     stmt_ty p;
1830     p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1831     if (!p)
1832         return NULL;
1833     p->kind = Break_kind;
1834     p->lineno = lineno;
1835     p->col_offset = col_offset;
1836     p->end_lineno = end_lineno;
1837     p->end_col_offset = end_col_offset;
1838     return p;
1839 }
1840 
1841 stmt_ty
Continue(int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)1842 Continue(int lineno, int col_offset, int end_lineno, int end_col_offset,
1843          PyArena *arena)
1844 {
1845     stmt_ty p;
1846     p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1847     if (!p)
1848         return NULL;
1849     p->kind = Continue_kind;
1850     p->lineno = lineno;
1851     p->col_offset = col_offset;
1852     p->end_lineno = end_lineno;
1853     p->end_col_offset = end_col_offset;
1854     return p;
1855 }
1856 
1857 expr_ty
BoolOp(boolop_ty op,asdl_seq * values,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)1858 BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, int
1859        end_lineno, int end_col_offset, PyArena *arena)
1860 {
1861     expr_ty p;
1862     if (!op) {
1863         PyErr_SetString(PyExc_ValueError,
1864                         "field op is required for BoolOp");
1865         return NULL;
1866     }
1867     p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1868     if (!p)
1869         return NULL;
1870     p->kind = BoolOp_kind;
1871     p->v.BoolOp.op = op;
1872     p->v.BoolOp.values = values;
1873     p->lineno = lineno;
1874     p->col_offset = col_offset;
1875     p->end_lineno = end_lineno;
1876     p->end_col_offset = end_col_offset;
1877     return p;
1878 }
1879 
1880 expr_ty
NamedExpr(expr_ty target,expr_ty value,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)1881 NamedExpr(expr_ty target, expr_ty value, int lineno, int col_offset, int
1882           end_lineno, int end_col_offset, PyArena *arena)
1883 {
1884     expr_ty p;
1885     if (!target) {
1886         PyErr_SetString(PyExc_ValueError,
1887                         "field target is required for NamedExpr");
1888         return NULL;
1889     }
1890     if (!value) {
1891         PyErr_SetString(PyExc_ValueError,
1892                         "field value is required for NamedExpr");
1893         return NULL;
1894     }
1895     p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1896     if (!p)
1897         return NULL;
1898     p->kind = NamedExpr_kind;
1899     p->v.NamedExpr.target = target;
1900     p->v.NamedExpr.value = value;
1901     p->lineno = lineno;
1902     p->col_offset = col_offset;
1903     p->end_lineno = end_lineno;
1904     p->end_col_offset = end_col_offset;
1905     return p;
1906 }
1907 
1908 expr_ty
BinOp(expr_ty left,operator_ty op,expr_ty right,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)1909 BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset,
1910       int end_lineno, int end_col_offset, PyArena *arena)
1911 {
1912     expr_ty p;
1913     if (!left) {
1914         PyErr_SetString(PyExc_ValueError,
1915                         "field left is required for BinOp");
1916         return NULL;
1917     }
1918     if (!op) {
1919         PyErr_SetString(PyExc_ValueError,
1920                         "field op is required for BinOp");
1921         return NULL;
1922     }
1923     if (!right) {
1924         PyErr_SetString(PyExc_ValueError,
1925                         "field right is required for BinOp");
1926         return NULL;
1927     }
1928     p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1929     if (!p)
1930         return NULL;
1931     p->kind = BinOp_kind;
1932     p->v.BinOp.left = left;
1933     p->v.BinOp.op = op;
1934     p->v.BinOp.right = right;
1935     p->lineno = lineno;
1936     p->col_offset = col_offset;
1937     p->end_lineno = end_lineno;
1938     p->end_col_offset = end_col_offset;
1939     return p;
1940 }
1941 
1942 expr_ty
UnaryOp(unaryop_ty op,expr_ty operand,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)1943 UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, int
1944         end_lineno, int end_col_offset, PyArena *arena)
1945 {
1946     expr_ty p;
1947     if (!op) {
1948         PyErr_SetString(PyExc_ValueError,
1949                         "field op is required for UnaryOp");
1950         return NULL;
1951     }
1952     if (!operand) {
1953         PyErr_SetString(PyExc_ValueError,
1954                         "field operand is required for UnaryOp");
1955         return NULL;
1956     }
1957     p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1958     if (!p)
1959         return NULL;
1960     p->kind = UnaryOp_kind;
1961     p->v.UnaryOp.op = op;
1962     p->v.UnaryOp.operand = operand;
1963     p->lineno = lineno;
1964     p->col_offset = col_offset;
1965     p->end_lineno = end_lineno;
1966     p->end_col_offset = end_col_offset;
1967     return p;
1968 }
1969 
1970 expr_ty
Lambda(arguments_ty args,expr_ty body,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)1971 Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, int
1972        end_lineno, int end_col_offset, PyArena *arena)
1973 {
1974     expr_ty p;
1975     if (!args) {
1976         PyErr_SetString(PyExc_ValueError,
1977                         "field args is required for Lambda");
1978         return NULL;
1979     }
1980     if (!body) {
1981         PyErr_SetString(PyExc_ValueError,
1982                         "field body is required for Lambda");
1983         return NULL;
1984     }
1985     p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1986     if (!p)
1987         return NULL;
1988     p->kind = Lambda_kind;
1989     p->v.Lambda.args = args;
1990     p->v.Lambda.body = body;
1991     p->lineno = lineno;
1992     p->col_offset = col_offset;
1993     p->end_lineno = end_lineno;
1994     p->end_col_offset = end_col_offset;
1995     return p;
1996 }
1997 
1998 expr_ty
IfExp(expr_ty test,expr_ty body,expr_ty orelse,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)1999 IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset,
2000       int end_lineno, int end_col_offset, PyArena *arena)
2001 {
2002     expr_ty p;
2003     if (!test) {
2004         PyErr_SetString(PyExc_ValueError,
2005                         "field test is required for IfExp");
2006         return NULL;
2007     }
2008     if (!body) {
2009         PyErr_SetString(PyExc_ValueError,
2010                         "field body is required for IfExp");
2011         return NULL;
2012     }
2013     if (!orelse) {
2014         PyErr_SetString(PyExc_ValueError,
2015                         "field orelse is required for IfExp");
2016         return NULL;
2017     }
2018     p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2019     if (!p)
2020         return NULL;
2021     p->kind = IfExp_kind;
2022     p->v.IfExp.test = test;
2023     p->v.IfExp.body = body;
2024     p->v.IfExp.orelse = orelse;
2025     p->lineno = lineno;
2026     p->col_offset = col_offset;
2027     p->end_lineno = end_lineno;
2028     p->end_col_offset = end_col_offset;
2029     return p;
2030 }
2031 
2032 expr_ty
Dict(asdl_seq * keys,asdl_seq * values,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2033 Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, int
2034      end_lineno, int end_col_offset, PyArena *arena)
2035 {
2036     expr_ty p;
2037     p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2038     if (!p)
2039         return NULL;
2040     p->kind = Dict_kind;
2041     p->v.Dict.keys = keys;
2042     p->v.Dict.values = values;
2043     p->lineno = lineno;
2044     p->col_offset = col_offset;
2045     p->end_lineno = end_lineno;
2046     p->end_col_offset = end_col_offset;
2047     return p;
2048 }
2049 
2050 expr_ty
Set(asdl_seq * elts,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2051 Set(asdl_seq * elts, int lineno, int col_offset, int end_lineno, int
2052     end_col_offset, PyArena *arena)
2053 {
2054     expr_ty p;
2055     p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2056     if (!p)
2057         return NULL;
2058     p->kind = Set_kind;
2059     p->v.Set.elts = elts;
2060     p->lineno = lineno;
2061     p->col_offset = col_offset;
2062     p->end_lineno = end_lineno;
2063     p->end_col_offset = end_col_offset;
2064     return p;
2065 }
2066 
2067 expr_ty
ListComp(expr_ty elt,asdl_seq * generators,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2068 ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int
2069          end_lineno, int end_col_offset, PyArena *arena)
2070 {
2071     expr_ty p;
2072     if (!elt) {
2073         PyErr_SetString(PyExc_ValueError,
2074                         "field elt is required for ListComp");
2075         return NULL;
2076     }
2077     p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2078     if (!p)
2079         return NULL;
2080     p->kind = ListComp_kind;
2081     p->v.ListComp.elt = elt;
2082     p->v.ListComp.generators = generators;
2083     p->lineno = lineno;
2084     p->col_offset = col_offset;
2085     p->end_lineno = end_lineno;
2086     p->end_col_offset = end_col_offset;
2087     return p;
2088 }
2089 
2090 expr_ty
SetComp(expr_ty elt,asdl_seq * generators,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2091 SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int
2092         end_lineno, int end_col_offset, PyArena *arena)
2093 {
2094     expr_ty p;
2095     if (!elt) {
2096         PyErr_SetString(PyExc_ValueError,
2097                         "field elt is required for SetComp");
2098         return NULL;
2099     }
2100     p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2101     if (!p)
2102         return NULL;
2103     p->kind = SetComp_kind;
2104     p->v.SetComp.elt = elt;
2105     p->v.SetComp.generators = generators;
2106     p->lineno = lineno;
2107     p->col_offset = col_offset;
2108     p->end_lineno = end_lineno;
2109     p->end_col_offset = end_col_offset;
2110     return p;
2111 }
2112 
2113 expr_ty
DictComp(expr_ty key,expr_ty value,asdl_seq * generators,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2114 DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int lineno, int
2115          col_offset, int end_lineno, int end_col_offset, PyArena *arena)
2116 {
2117     expr_ty p;
2118     if (!key) {
2119         PyErr_SetString(PyExc_ValueError,
2120                         "field key is required for DictComp");
2121         return NULL;
2122     }
2123     if (!value) {
2124         PyErr_SetString(PyExc_ValueError,
2125                         "field value is required for DictComp");
2126         return NULL;
2127     }
2128     p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2129     if (!p)
2130         return NULL;
2131     p->kind = DictComp_kind;
2132     p->v.DictComp.key = key;
2133     p->v.DictComp.value = value;
2134     p->v.DictComp.generators = generators;
2135     p->lineno = lineno;
2136     p->col_offset = col_offset;
2137     p->end_lineno = end_lineno;
2138     p->end_col_offset = end_col_offset;
2139     return p;
2140 }
2141 
2142 expr_ty
GeneratorExp(expr_ty elt,asdl_seq * generators,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2143 GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
2144              int end_lineno, int end_col_offset, PyArena *arena)
2145 {
2146     expr_ty p;
2147     if (!elt) {
2148         PyErr_SetString(PyExc_ValueError,
2149                         "field elt is required for GeneratorExp");
2150         return NULL;
2151     }
2152     p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2153     if (!p)
2154         return NULL;
2155     p->kind = GeneratorExp_kind;
2156     p->v.GeneratorExp.elt = elt;
2157     p->v.GeneratorExp.generators = generators;
2158     p->lineno = lineno;
2159     p->col_offset = col_offset;
2160     p->end_lineno = end_lineno;
2161     p->end_col_offset = end_col_offset;
2162     return p;
2163 }
2164 
2165 expr_ty
Await(expr_ty value,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2166 Await(expr_ty value, int lineno, int col_offset, int end_lineno, int
2167       end_col_offset, PyArena *arena)
2168 {
2169     expr_ty p;
2170     if (!value) {
2171         PyErr_SetString(PyExc_ValueError,
2172                         "field value is required for Await");
2173         return NULL;
2174     }
2175     p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2176     if (!p)
2177         return NULL;
2178     p->kind = Await_kind;
2179     p->v.Await.value = value;
2180     p->lineno = lineno;
2181     p->col_offset = col_offset;
2182     p->end_lineno = end_lineno;
2183     p->end_col_offset = end_col_offset;
2184     return p;
2185 }
2186 
2187 expr_ty
Yield(expr_ty value,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2188 Yield(expr_ty value, int lineno, int col_offset, int end_lineno, int
2189       end_col_offset, PyArena *arena)
2190 {
2191     expr_ty p;
2192     p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2193     if (!p)
2194         return NULL;
2195     p->kind = Yield_kind;
2196     p->v.Yield.value = value;
2197     p->lineno = lineno;
2198     p->col_offset = col_offset;
2199     p->end_lineno = end_lineno;
2200     p->end_col_offset = end_col_offset;
2201     return p;
2202 }
2203 
2204 expr_ty
YieldFrom(expr_ty value,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2205 YieldFrom(expr_ty value, int lineno, int col_offset, int end_lineno, int
2206           end_col_offset, PyArena *arena)
2207 {
2208     expr_ty p;
2209     if (!value) {
2210         PyErr_SetString(PyExc_ValueError,
2211                         "field value is required for YieldFrom");
2212         return NULL;
2213     }
2214     p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2215     if (!p)
2216         return NULL;
2217     p->kind = YieldFrom_kind;
2218     p->v.YieldFrom.value = value;
2219     p->lineno = lineno;
2220     p->col_offset = col_offset;
2221     p->end_lineno = end_lineno;
2222     p->end_col_offset = end_col_offset;
2223     return p;
2224 }
2225 
2226 expr_ty
Compare(expr_ty left,asdl_int_seq * ops,asdl_seq * comparators,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2227 Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno,
2228         int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
2229 {
2230     expr_ty p;
2231     if (!left) {
2232         PyErr_SetString(PyExc_ValueError,
2233                         "field left is required for Compare");
2234         return NULL;
2235     }
2236     p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2237     if (!p)
2238         return NULL;
2239     p->kind = Compare_kind;
2240     p->v.Compare.left = left;
2241     p->v.Compare.ops = ops;
2242     p->v.Compare.comparators = comparators;
2243     p->lineno = lineno;
2244     p->col_offset = col_offset;
2245     p->end_lineno = end_lineno;
2246     p->end_col_offset = end_col_offset;
2247     return p;
2248 }
2249 
2250 expr_ty
Call(expr_ty func,asdl_seq * args,asdl_seq * keywords,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2251 Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, int lineno, int
2252      col_offset, int end_lineno, int end_col_offset, PyArena *arena)
2253 {
2254     expr_ty p;
2255     if (!func) {
2256         PyErr_SetString(PyExc_ValueError,
2257                         "field func is required for Call");
2258         return NULL;
2259     }
2260     p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2261     if (!p)
2262         return NULL;
2263     p->kind = Call_kind;
2264     p->v.Call.func = func;
2265     p->v.Call.args = args;
2266     p->v.Call.keywords = keywords;
2267     p->lineno = lineno;
2268     p->col_offset = col_offset;
2269     p->end_lineno = end_lineno;
2270     p->end_col_offset = end_col_offset;
2271     return p;
2272 }
2273 
2274 expr_ty
FormattedValue(expr_ty value,int conversion,expr_ty format_spec,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2275 FormattedValue(expr_ty value, int conversion, expr_ty format_spec, int lineno,
2276                int col_offset, int end_lineno, int end_col_offset, PyArena
2277                *arena)
2278 {
2279     expr_ty p;
2280     if (!value) {
2281         PyErr_SetString(PyExc_ValueError,
2282                         "field value is required for FormattedValue");
2283         return NULL;
2284     }
2285     p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2286     if (!p)
2287         return NULL;
2288     p->kind = FormattedValue_kind;
2289     p->v.FormattedValue.value = value;
2290     p->v.FormattedValue.conversion = conversion;
2291     p->v.FormattedValue.format_spec = format_spec;
2292     p->lineno = lineno;
2293     p->col_offset = col_offset;
2294     p->end_lineno = end_lineno;
2295     p->end_col_offset = end_col_offset;
2296     return p;
2297 }
2298 
2299 expr_ty
JoinedStr(asdl_seq * values,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2300 JoinedStr(asdl_seq * values, int lineno, int col_offset, int end_lineno, int
2301           end_col_offset, PyArena *arena)
2302 {
2303     expr_ty p;
2304     p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2305     if (!p)
2306         return NULL;
2307     p->kind = JoinedStr_kind;
2308     p->v.JoinedStr.values = values;
2309     p->lineno = lineno;
2310     p->col_offset = col_offset;
2311     p->end_lineno = end_lineno;
2312     p->end_col_offset = end_col_offset;
2313     return p;
2314 }
2315 
2316 expr_ty
Constant(constant value,string kind,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2317 Constant(constant value, string kind, int lineno, int col_offset, int
2318          end_lineno, int end_col_offset, PyArena *arena)
2319 {
2320     expr_ty p;
2321     if (!value) {
2322         PyErr_SetString(PyExc_ValueError,
2323                         "field value is required for Constant");
2324         return NULL;
2325     }
2326     p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2327     if (!p)
2328         return NULL;
2329     p->kind = Constant_kind;
2330     p->v.Constant.value = value;
2331     p->v.Constant.kind = kind;
2332     p->lineno = lineno;
2333     p->col_offset = col_offset;
2334     p->end_lineno = end_lineno;
2335     p->end_col_offset = end_col_offset;
2336     return p;
2337 }
2338 
2339 expr_ty
Attribute(expr_ty value,identifier attr,expr_context_ty ctx,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2340 Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int
2341           col_offset, int end_lineno, int end_col_offset, PyArena *arena)
2342 {
2343     expr_ty p;
2344     if (!value) {
2345         PyErr_SetString(PyExc_ValueError,
2346                         "field value is required for Attribute");
2347         return NULL;
2348     }
2349     if (!attr) {
2350         PyErr_SetString(PyExc_ValueError,
2351                         "field attr is required for Attribute");
2352         return NULL;
2353     }
2354     if (!ctx) {
2355         PyErr_SetString(PyExc_ValueError,
2356                         "field ctx is required for Attribute");
2357         return NULL;
2358     }
2359     p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2360     if (!p)
2361         return NULL;
2362     p->kind = Attribute_kind;
2363     p->v.Attribute.value = value;
2364     p->v.Attribute.attr = attr;
2365     p->v.Attribute.ctx = ctx;
2366     p->lineno = lineno;
2367     p->col_offset = col_offset;
2368     p->end_lineno = end_lineno;
2369     p->end_col_offset = end_col_offset;
2370     return p;
2371 }
2372 
2373 expr_ty
Subscript(expr_ty value,slice_ty slice,expr_context_ty ctx,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2374 Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int
2375           col_offset, int end_lineno, int end_col_offset, PyArena *arena)
2376 {
2377     expr_ty p;
2378     if (!value) {
2379         PyErr_SetString(PyExc_ValueError,
2380                         "field value is required for Subscript");
2381         return NULL;
2382     }
2383     if (!slice) {
2384         PyErr_SetString(PyExc_ValueError,
2385                         "field slice is required for Subscript");
2386         return NULL;
2387     }
2388     if (!ctx) {
2389         PyErr_SetString(PyExc_ValueError,
2390                         "field ctx is required for Subscript");
2391         return NULL;
2392     }
2393     p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2394     if (!p)
2395         return NULL;
2396     p->kind = Subscript_kind;
2397     p->v.Subscript.value = value;
2398     p->v.Subscript.slice = slice;
2399     p->v.Subscript.ctx = ctx;
2400     p->lineno = lineno;
2401     p->col_offset = col_offset;
2402     p->end_lineno = end_lineno;
2403     p->end_col_offset = end_col_offset;
2404     return p;
2405 }
2406 
2407 expr_ty
Starred(expr_ty value,expr_context_ty ctx,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2408 Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, int
2409         end_lineno, int end_col_offset, PyArena *arena)
2410 {
2411     expr_ty p;
2412     if (!value) {
2413         PyErr_SetString(PyExc_ValueError,
2414                         "field value is required for Starred");
2415         return NULL;
2416     }
2417     if (!ctx) {
2418         PyErr_SetString(PyExc_ValueError,
2419                         "field ctx is required for Starred");
2420         return NULL;
2421     }
2422     p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2423     if (!p)
2424         return NULL;
2425     p->kind = Starred_kind;
2426     p->v.Starred.value = value;
2427     p->v.Starred.ctx = ctx;
2428     p->lineno = lineno;
2429     p->col_offset = col_offset;
2430     p->end_lineno = end_lineno;
2431     p->end_col_offset = end_col_offset;
2432     return p;
2433 }
2434 
2435 expr_ty
Name(identifier id,expr_context_ty ctx,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2436 Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, int
2437      end_lineno, int end_col_offset, PyArena *arena)
2438 {
2439     expr_ty p;
2440     if (!id) {
2441         PyErr_SetString(PyExc_ValueError,
2442                         "field id is required for Name");
2443         return NULL;
2444     }
2445     if (!ctx) {
2446         PyErr_SetString(PyExc_ValueError,
2447                         "field ctx is required for Name");
2448         return NULL;
2449     }
2450     p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2451     if (!p)
2452         return NULL;
2453     p->kind = Name_kind;
2454     p->v.Name.id = id;
2455     p->v.Name.ctx = ctx;
2456     p->lineno = lineno;
2457     p->col_offset = col_offset;
2458     p->end_lineno = end_lineno;
2459     p->end_col_offset = end_col_offset;
2460     return p;
2461 }
2462 
2463 expr_ty
List(asdl_seq * elts,expr_context_ty ctx,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2464 List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int
2465      end_lineno, int end_col_offset, PyArena *arena)
2466 {
2467     expr_ty p;
2468     if (!ctx) {
2469         PyErr_SetString(PyExc_ValueError,
2470                         "field ctx is required for List");
2471         return NULL;
2472     }
2473     p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2474     if (!p)
2475         return NULL;
2476     p->kind = List_kind;
2477     p->v.List.elts = elts;
2478     p->v.List.ctx = ctx;
2479     p->lineno = lineno;
2480     p->col_offset = col_offset;
2481     p->end_lineno = end_lineno;
2482     p->end_col_offset = end_col_offset;
2483     return p;
2484 }
2485 
2486 expr_ty
Tuple(asdl_seq * elts,expr_context_ty ctx,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2487 Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int
2488       end_lineno, int end_col_offset, PyArena *arena)
2489 {
2490     expr_ty p;
2491     if (!ctx) {
2492         PyErr_SetString(PyExc_ValueError,
2493                         "field ctx is required for Tuple");
2494         return NULL;
2495     }
2496     p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2497     if (!p)
2498         return NULL;
2499     p->kind = Tuple_kind;
2500     p->v.Tuple.elts = elts;
2501     p->v.Tuple.ctx = ctx;
2502     p->lineno = lineno;
2503     p->col_offset = col_offset;
2504     p->end_lineno = end_lineno;
2505     p->end_col_offset = end_col_offset;
2506     return p;
2507 }
2508 
2509 slice_ty
Slice(expr_ty lower,expr_ty upper,expr_ty step,PyArena * arena)2510 Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena)
2511 {
2512     slice_ty p;
2513     p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
2514     if (!p)
2515         return NULL;
2516     p->kind = Slice_kind;
2517     p->v.Slice.lower = lower;
2518     p->v.Slice.upper = upper;
2519     p->v.Slice.step = step;
2520     return p;
2521 }
2522 
2523 slice_ty
ExtSlice(asdl_seq * dims,PyArena * arena)2524 ExtSlice(asdl_seq * dims, PyArena *arena)
2525 {
2526     slice_ty p;
2527     p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
2528     if (!p)
2529         return NULL;
2530     p->kind = ExtSlice_kind;
2531     p->v.ExtSlice.dims = dims;
2532     return p;
2533 }
2534 
2535 slice_ty
Index(expr_ty value,PyArena * arena)2536 Index(expr_ty value, PyArena *arena)
2537 {
2538     slice_ty p;
2539     if (!value) {
2540         PyErr_SetString(PyExc_ValueError,
2541                         "field value is required for Index");
2542         return NULL;
2543     }
2544     p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
2545     if (!p)
2546         return NULL;
2547     p->kind = Index_kind;
2548     p->v.Index.value = value;
2549     return p;
2550 }
2551 
2552 comprehension_ty
comprehension(expr_ty target,expr_ty iter,asdl_seq * ifs,int is_async,PyArena * arena)2553 comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, int is_async,
2554               PyArena *arena)
2555 {
2556     comprehension_ty p;
2557     if (!target) {
2558         PyErr_SetString(PyExc_ValueError,
2559                         "field target is required for comprehension");
2560         return NULL;
2561     }
2562     if (!iter) {
2563         PyErr_SetString(PyExc_ValueError,
2564                         "field iter is required for comprehension");
2565         return NULL;
2566     }
2567     p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));
2568     if (!p)
2569         return NULL;
2570     p->target = target;
2571     p->iter = iter;
2572     p->ifs = ifs;
2573     p->is_async = is_async;
2574     return p;
2575 }
2576 
2577 excepthandler_ty
ExceptHandler(expr_ty type,identifier name,asdl_seq * body,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2578 ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int
2579               col_offset, int end_lineno, int end_col_offset, PyArena *arena)
2580 {
2581     excepthandler_ty p;
2582     p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
2583     if (!p)
2584         return NULL;
2585     p->kind = ExceptHandler_kind;
2586     p->v.ExceptHandler.type = type;
2587     p->v.ExceptHandler.name = name;
2588     p->v.ExceptHandler.body = body;
2589     p->lineno = lineno;
2590     p->col_offset = col_offset;
2591     p->end_lineno = end_lineno;
2592     p->end_col_offset = end_col_offset;
2593     return p;
2594 }
2595 
2596 arguments_ty
arguments(asdl_seq * posonlyargs,asdl_seq * args,arg_ty vararg,asdl_seq * kwonlyargs,asdl_seq * kw_defaults,arg_ty kwarg,asdl_seq * defaults,PyArena * arena)2597 arguments(asdl_seq * posonlyargs, asdl_seq * args, arg_ty vararg, asdl_seq *
2598           kwonlyargs, asdl_seq * kw_defaults, arg_ty kwarg, asdl_seq *
2599           defaults, PyArena *arena)
2600 {
2601     arguments_ty p;
2602     p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
2603     if (!p)
2604         return NULL;
2605     p->posonlyargs = posonlyargs;
2606     p->args = args;
2607     p->vararg = vararg;
2608     p->kwonlyargs = kwonlyargs;
2609     p->kw_defaults = kw_defaults;
2610     p->kwarg = kwarg;
2611     p->defaults = defaults;
2612     return p;
2613 }
2614 
2615 arg_ty
arg(identifier arg,expr_ty annotation,string type_comment,int lineno,int col_offset,int end_lineno,int end_col_offset,PyArena * arena)2616 arg(identifier arg, expr_ty annotation, string type_comment, int lineno, int
2617     col_offset, int end_lineno, int end_col_offset, PyArena *arena)
2618 {
2619     arg_ty p;
2620     if (!arg) {
2621         PyErr_SetString(PyExc_ValueError,
2622                         "field arg is required for arg");
2623         return NULL;
2624     }
2625     p = (arg_ty)PyArena_Malloc(arena, sizeof(*p));
2626     if (!p)
2627         return NULL;
2628     p->arg = arg;
2629     p->annotation = annotation;
2630     p->type_comment = type_comment;
2631     p->lineno = lineno;
2632     p->col_offset = col_offset;
2633     p->end_lineno = end_lineno;
2634     p->end_col_offset = end_col_offset;
2635     return p;
2636 }
2637 
2638 keyword_ty
keyword(identifier arg,expr_ty value,PyArena * arena)2639 keyword(identifier arg, expr_ty value, PyArena *arena)
2640 {
2641     keyword_ty p;
2642     if (!value) {
2643         PyErr_SetString(PyExc_ValueError,
2644                         "field value is required for keyword");
2645         return NULL;
2646     }
2647     p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));
2648     if (!p)
2649         return NULL;
2650     p->arg = arg;
2651     p->value = value;
2652     return p;
2653 }
2654 
2655 alias_ty
alias(identifier name,identifier asname,PyArena * arena)2656 alias(identifier name, identifier asname, PyArena *arena)
2657 {
2658     alias_ty p;
2659     if (!name) {
2660         PyErr_SetString(PyExc_ValueError,
2661                         "field name is required for alias");
2662         return NULL;
2663     }
2664     p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));
2665     if (!p)
2666         return NULL;
2667     p->name = name;
2668     p->asname = asname;
2669     return p;
2670 }
2671 
2672 withitem_ty
withitem(expr_ty context_expr,expr_ty optional_vars,PyArena * arena)2673 withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena)
2674 {
2675     withitem_ty p;
2676     if (!context_expr) {
2677         PyErr_SetString(PyExc_ValueError,
2678                         "field context_expr is required for withitem");
2679         return NULL;
2680     }
2681     p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p));
2682     if (!p)
2683         return NULL;
2684     p->context_expr = context_expr;
2685     p->optional_vars = optional_vars;
2686     return p;
2687 }
2688 
2689 type_ignore_ty
TypeIgnore(int lineno,string tag,PyArena * arena)2690 TypeIgnore(int lineno, string tag, PyArena *arena)
2691 {
2692     type_ignore_ty p;
2693     if (!tag) {
2694         PyErr_SetString(PyExc_ValueError,
2695                         "field tag is required for TypeIgnore");
2696         return NULL;
2697     }
2698     p = (type_ignore_ty)PyArena_Malloc(arena, sizeof(*p));
2699     if (!p)
2700         return NULL;
2701     p->kind = TypeIgnore_kind;
2702     p->v.TypeIgnore.lineno = lineno;
2703     p->v.TypeIgnore.tag = tag;
2704     return p;
2705 }
2706 
2707 
2708 PyObject*
ast2obj_mod(void * _o)2709 ast2obj_mod(void* _o)
2710 {
2711     mod_ty o = (mod_ty)_o;
2712     PyObject *result = NULL, *value = NULL;
2713     if (!o) {
2714         Py_RETURN_NONE;
2715     }
2716 
2717     switch (o->kind) {
2718     case Module_kind:
2719         result = PyType_GenericNew(Module_type, NULL, NULL);
2720         if (!result) goto failed;
2721         value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
2722         if (!value) goto failed;
2723         if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
2724             goto failed;
2725         Py_DECREF(value);
2726         value = ast2obj_list(o->v.Module.type_ignores, ast2obj_type_ignore);
2727         if (!value) goto failed;
2728         if (_PyObject_SetAttrId(result, &PyId_type_ignores, value) == -1)
2729             goto failed;
2730         Py_DECREF(value);
2731         break;
2732     case Interactive_kind:
2733         result = PyType_GenericNew(Interactive_type, NULL, NULL);
2734         if (!result) goto failed;
2735         value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
2736         if (!value) goto failed;
2737         if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
2738             goto failed;
2739         Py_DECREF(value);
2740         break;
2741     case Expression_kind:
2742         result = PyType_GenericNew(Expression_type, NULL, NULL);
2743         if (!result) goto failed;
2744         value = ast2obj_expr(o->v.Expression.body);
2745         if (!value) goto failed;
2746         if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
2747             goto failed;
2748         Py_DECREF(value);
2749         break;
2750     case FunctionType_kind:
2751         result = PyType_GenericNew(FunctionType_type, NULL, NULL);
2752         if (!result) goto failed;
2753         value = ast2obj_list(o->v.FunctionType.argtypes, ast2obj_expr);
2754         if (!value) goto failed;
2755         if (_PyObject_SetAttrId(result, &PyId_argtypes, value) == -1)
2756             goto failed;
2757         Py_DECREF(value);
2758         value = ast2obj_expr(o->v.FunctionType.returns);
2759         if (!value) goto failed;
2760         if (_PyObject_SetAttrId(result, &PyId_returns, value) == -1)
2761             goto failed;
2762         Py_DECREF(value);
2763         break;
2764     case Suite_kind:
2765         result = PyType_GenericNew(Suite_type, NULL, NULL);
2766         if (!result) goto failed;
2767         value = ast2obj_list(o->v.Suite.body, ast2obj_stmt);
2768         if (!value) goto failed;
2769         if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
2770             goto failed;
2771         Py_DECREF(value);
2772         break;
2773     }
2774     return result;
2775 failed:
2776     Py_XDECREF(value);
2777     Py_XDECREF(result);
2778     return NULL;
2779 }
2780 
2781 PyObject*
ast2obj_stmt(void * _o)2782 ast2obj_stmt(void* _o)
2783 {
2784     stmt_ty o = (stmt_ty)_o;
2785     PyObject *result = NULL, *value = NULL;
2786     if (!o) {
2787         Py_RETURN_NONE;
2788     }
2789 
2790     switch (o->kind) {
2791     case FunctionDef_kind:
2792         result = PyType_GenericNew(FunctionDef_type, NULL, NULL);
2793         if (!result) goto failed;
2794         value = ast2obj_identifier(o->v.FunctionDef.name);
2795         if (!value) goto failed;
2796         if (_PyObject_SetAttrId(result, &PyId_name, value) == -1)
2797             goto failed;
2798         Py_DECREF(value);
2799         value = ast2obj_arguments(o->v.FunctionDef.args);
2800         if (!value) goto failed;
2801         if (_PyObject_SetAttrId(result, &PyId_args, value) == -1)
2802             goto failed;
2803         Py_DECREF(value);
2804         value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
2805         if (!value) goto failed;
2806         if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
2807             goto failed;
2808         Py_DECREF(value);
2809         value = ast2obj_list(o->v.FunctionDef.decorator_list, ast2obj_expr);
2810         if (!value) goto failed;
2811         if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1)
2812             goto failed;
2813         Py_DECREF(value);
2814         value = ast2obj_expr(o->v.FunctionDef.returns);
2815         if (!value) goto failed;
2816         if (_PyObject_SetAttrId(result, &PyId_returns, value) == -1)
2817             goto failed;
2818         Py_DECREF(value);
2819         value = ast2obj_string(o->v.FunctionDef.type_comment);
2820         if (!value) goto failed;
2821         if (_PyObject_SetAttrId(result, &PyId_type_comment, value) == -1)
2822             goto failed;
2823         Py_DECREF(value);
2824         break;
2825     case AsyncFunctionDef_kind:
2826         result = PyType_GenericNew(AsyncFunctionDef_type, NULL, NULL);
2827         if (!result) goto failed;
2828         value = ast2obj_identifier(o->v.AsyncFunctionDef.name);
2829         if (!value) goto failed;
2830         if (_PyObject_SetAttrId(result, &PyId_name, value) == -1)
2831             goto failed;
2832         Py_DECREF(value);
2833         value = ast2obj_arguments(o->v.AsyncFunctionDef.args);
2834         if (!value) goto failed;
2835         if (_PyObject_SetAttrId(result, &PyId_args, value) == -1)
2836             goto failed;
2837         Py_DECREF(value);
2838         value = ast2obj_list(o->v.AsyncFunctionDef.body, ast2obj_stmt);
2839         if (!value) goto failed;
2840         if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
2841             goto failed;
2842         Py_DECREF(value);
2843         value = ast2obj_list(o->v.AsyncFunctionDef.decorator_list,
2844                              ast2obj_expr);
2845         if (!value) goto failed;
2846         if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1)
2847             goto failed;
2848         Py_DECREF(value);
2849         value = ast2obj_expr(o->v.AsyncFunctionDef.returns);
2850         if (!value) goto failed;
2851         if (_PyObject_SetAttrId(result, &PyId_returns, value) == -1)
2852             goto failed;
2853         Py_DECREF(value);
2854         value = ast2obj_string(o->v.AsyncFunctionDef.type_comment);
2855         if (!value) goto failed;
2856         if (_PyObject_SetAttrId(result, &PyId_type_comment, value) == -1)
2857             goto failed;
2858         Py_DECREF(value);
2859         break;
2860     case ClassDef_kind:
2861         result = PyType_GenericNew(ClassDef_type, NULL, NULL);
2862         if (!result) goto failed;
2863         value = ast2obj_identifier(o->v.ClassDef.name);
2864         if (!value) goto failed;
2865         if (_PyObject_SetAttrId(result, &PyId_name, value) == -1)
2866             goto failed;
2867         Py_DECREF(value);
2868         value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
2869         if (!value) goto failed;
2870         if (_PyObject_SetAttrId(result, &PyId_bases, value) == -1)
2871             goto failed;
2872         Py_DECREF(value);
2873         value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword);
2874         if (!value) goto failed;
2875         if (_PyObject_SetAttrId(result, &PyId_keywords, value) == -1)
2876             goto failed;
2877         Py_DECREF(value);
2878         value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
2879         if (!value) goto failed;
2880         if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
2881             goto failed;
2882         Py_DECREF(value);
2883         value = ast2obj_list(o->v.ClassDef.decorator_list, ast2obj_expr);
2884         if (!value) goto failed;
2885         if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1)
2886             goto failed;
2887         Py_DECREF(value);
2888         break;
2889     case Return_kind:
2890         result = PyType_GenericNew(Return_type, NULL, NULL);
2891         if (!result) goto failed;
2892         value = ast2obj_expr(o->v.Return.value);
2893         if (!value) goto failed;
2894         if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
2895             goto failed;
2896         Py_DECREF(value);
2897         break;
2898     case Delete_kind:
2899         result = PyType_GenericNew(Delete_type, NULL, NULL);
2900         if (!result) goto failed;
2901         value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
2902         if (!value) goto failed;
2903         if (_PyObject_SetAttrId(result, &PyId_targets, value) == -1)
2904             goto failed;
2905         Py_DECREF(value);
2906         break;
2907     case Assign_kind:
2908         result = PyType_GenericNew(Assign_type, NULL, NULL);
2909         if (!result) goto failed;
2910         value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
2911         if (!value) goto failed;
2912         if (_PyObject_SetAttrId(result, &PyId_targets, value) == -1)
2913             goto failed;
2914         Py_DECREF(value);
2915         value = ast2obj_expr(o->v.Assign.value);
2916         if (!value) goto failed;
2917         if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
2918             goto failed;
2919         Py_DECREF(value);
2920         value = ast2obj_string(o->v.Assign.type_comment);
2921         if (!value) goto failed;
2922         if (_PyObject_SetAttrId(result, &PyId_type_comment, value) == -1)
2923             goto failed;
2924         Py_DECREF(value);
2925         break;
2926     case AugAssign_kind:
2927         result = PyType_GenericNew(AugAssign_type, NULL, NULL);
2928         if (!result) goto failed;
2929         value = ast2obj_expr(o->v.AugAssign.target);
2930         if (!value) goto failed;
2931         if (_PyObject_SetAttrId(result, &PyId_target, value) == -1)
2932             goto failed;
2933         Py_DECREF(value);
2934         value = ast2obj_operator(o->v.AugAssign.op);
2935         if (!value) goto failed;
2936         if (_PyObject_SetAttrId(result, &PyId_op, value) == -1)
2937             goto failed;
2938         Py_DECREF(value);
2939         value = ast2obj_expr(o->v.AugAssign.value);
2940         if (!value) goto failed;
2941         if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
2942             goto failed;
2943         Py_DECREF(value);
2944         break;
2945     case AnnAssign_kind:
2946         result = PyType_GenericNew(AnnAssign_type, NULL, NULL);
2947         if (!result) goto failed;
2948         value = ast2obj_expr(o->v.AnnAssign.target);
2949         if (!value) goto failed;
2950         if (_PyObject_SetAttrId(result, &PyId_target, value) == -1)
2951             goto failed;
2952         Py_DECREF(value);
2953         value = ast2obj_expr(o->v.AnnAssign.annotation);
2954         if (!value) goto failed;
2955         if (_PyObject_SetAttrId(result, &PyId_annotation, value) == -1)
2956             goto failed;
2957         Py_DECREF(value);
2958         value = ast2obj_expr(o->v.AnnAssign.value);
2959         if (!value) goto failed;
2960         if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
2961             goto failed;
2962         Py_DECREF(value);
2963         value = ast2obj_int(o->v.AnnAssign.simple);
2964         if (!value) goto failed;
2965         if (_PyObject_SetAttrId(result, &PyId_simple, value) == -1)
2966             goto failed;
2967         Py_DECREF(value);
2968         break;
2969     case For_kind:
2970         result = PyType_GenericNew(For_type, NULL, NULL);
2971         if (!result) goto failed;
2972         value = ast2obj_expr(o->v.For.target);
2973         if (!value) goto failed;
2974         if (_PyObject_SetAttrId(result, &PyId_target, value) == -1)
2975             goto failed;
2976         Py_DECREF(value);
2977         value = ast2obj_expr(o->v.For.iter);
2978         if (!value) goto failed;
2979         if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1)
2980             goto failed;
2981         Py_DECREF(value);
2982         value = ast2obj_list(o->v.For.body, ast2obj_stmt);
2983         if (!value) goto failed;
2984         if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
2985             goto failed;
2986         Py_DECREF(value);
2987         value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
2988         if (!value) goto failed;
2989         if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1)
2990             goto failed;
2991         Py_DECREF(value);
2992         value = ast2obj_string(o->v.For.type_comment);
2993         if (!value) goto failed;
2994         if (_PyObject_SetAttrId(result, &PyId_type_comment, value) == -1)
2995             goto failed;
2996         Py_DECREF(value);
2997         break;
2998     case AsyncFor_kind:
2999         result = PyType_GenericNew(AsyncFor_type, NULL, NULL);
3000         if (!result) goto failed;
3001         value = ast2obj_expr(o->v.AsyncFor.target);
3002         if (!value) goto failed;
3003         if (_PyObject_SetAttrId(result, &PyId_target, value) == -1)
3004             goto failed;
3005         Py_DECREF(value);
3006         value = ast2obj_expr(o->v.AsyncFor.iter);
3007         if (!value) goto failed;
3008         if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1)
3009             goto failed;
3010         Py_DECREF(value);
3011         value = ast2obj_list(o->v.AsyncFor.body, ast2obj_stmt);
3012         if (!value) goto failed;
3013         if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
3014             goto failed;
3015         Py_DECREF(value);
3016         value = ast2obj_list(o->v.AsyncFor.orelse, ast2obj_stmt);
3017         if (!value) goto failed;
3018         if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1)
3019             goto failed;
3020         Py_DECREF(value);
3021         value = ast2obj_string(o->v.AsyncFor.type_comment);
3022         if (!value) goto failed;
3023         if (_PyObject_SetAttrId(result, &PyId_type_comment, value) == -1)
3024             goto failed;
3025         Py_DECREF(value);
3026         break;
3027     case While_kind:
3028         result = PyType_GenericNew(While_type, NULL, NULL);
3029         if (!result) goto failed;
3030         value = ast2obj_expr(o->v.While.test);
3031         if (!value) goto failed;
3032         if (_PyObject_SetAttrId(result, &PyId_test, value) == -1)
3033             goto failed;
3034         Py_DECREF(value);
3035         value = ast2obj_list(o->v.While.body, ast2obj_stmt);
3036         if (!value) goto failed;
3037         if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
3038             goto failed;
3039         Py_DECREF(value);
3040         value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);
3041         if (!value) goto failed;
3042         if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1)
3043             goto failed;
3044         Py_DECREF(value);
3045         break;
3046     case If_kind:
3047         result = PyType_GenericNew(If_type, NULL, NULL);
3048         if (!result) goto failed;
3049         value = ast2obj_expr(o->v.If.test);
3050         if (!value) goto failed;
3051         if (_PyObject_SetAttrId(result, &PyId_test, value) == -1)
3052             goto failed;
3053         Py_DECREF(value);
3054         value = ast2obj_list(o->v.If.body, ast2obj_stmt);
3055         if (!value) goto failed;
3056         if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
3057             goto failed;
3058         Py_DECREF(value);
3059         value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
3060         if (!value) goto failed;
3061         if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1)
3062             goto failed;
3063         Py_DECREF(value);
3064         break;
3065     case With_kind:
3066         result = PyType_GenericNew(With_type, NULL, NULL);
3067         if (!result) goto failed;
3068         value = ast2obj_list(o->v.With.items, ast2obj_withitem);
3069         if (!value) goto failed;
3070         if (_PyObject_SetAttrId(result, &PyId_items, value) == -1)
3071             goto failed;
3072         Py_DECREF(value);
3073         value = ast2obj_list(o->v.With.body, ast2obj_stmt);
3074         if (!value) goto failed;
3075         if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
3076             goto failed;
3077         Py_DECREF(value);
3078         value = ast2obj_string(o->v.With.type_comment);
3079         if (!value) goto failed;
3080         if (_PyObject_SetAttrId(result, &PyId_type_comment, value) == -1)
3081             goto failed;
3082         Py_DECREF(value);
3083         break;
3084     case AsyncWith_kind:
3085         result = PyType_GenericNew(AsyncWith_type, NULL, NULL);
3086         if (!result) goto failed;
3087         value = ast2obj_list(o->v.AsyncWith.items, ast2obj_withitem);
3088         if (!value) goto failed;
3089         if (_PyObject_SetAttrId(result, &PyId_items, value) == -1)
3090             goto failed;
3091         Py_DECREF(value);
3092         value = ast2obj_list(o->v.AsyncWith.body, ast2obj_stmt);
3093         if (!value) goto failed;
3094         if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
3095             goto failed;
3096         Py_DECREF(value);
3097         value = ast2obj_string(o->v.AsyncWith.type_comment);
3098         if (!value) goto failed;
3099         if (_PyObject_SetAttrId(result, &PyId_type_comment, value) == -1)
3100             goto failed;
3101         Py_DECREF(value);
3102         break;
3103     case Raise_kind:
3104         result = PyType_GenericNew(Raise_type, NULL, NULL);
3105         if (!result) goto failed;
3106         value = ast2obj_expr(o->v.Raise.exc);
3107         if (!value) goto failed;
3108         if (_PyObject_SetAttrId(result, &PyId_exc, value) == -1)
3109             goto failed;
3110         Py_DECREF(value);
3111         value = ast2obj_expr(o->v.Raise.cause);
3112         if (!value) goto failed;
3113         if (_PyObject_SetAttrId(result, &PyId_cause, value) == -1)
3114             goto failed;
3115         Py_DECREF(value);
3116         break;
3117     case Try_kind:
3118         result = PyType_GenericNew(Try_type, NULL, NULL);
3119         if (!result) goto failed;
3120         value = ast2obj_list(o->v.Try.body, ast2obj_stmt);
3121         if (!value) goto failed;
3122         if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
3123             goto failed;
3124         Py_DECREF(value);
3125         value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler);
3126         if (!value) goto failed;
3127         if (_PyObject_SetAttrId(result, &PyId_handlers, value) == -1)
3128             goto failed;
3129         Py_DECREF(value);
3130         value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt);
3131         if (!value) goto failed;
3132         if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1)
3133             goto failed;
3134         Py_DECREF(value);
3135         value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt);
3136         if (!value) goto failed;
3137         if (_PyObject_SetAttrId(result, &PyId_finalbody, value) == -1)
3138             goto failed;
3139         Py_DECREF(value);
3140         break;
3141     case Assert_kind:
3142         result = PyType_GenericNew(Assert_type, NULL, NULL);
3143         if (!result) goto failed;
3144         value = ast2obj_expr(o->v.Assert.test);
3145         if (!value) goto failed;
3146         if (_PyObject_SetAttrId(result, &PyId_test, value) == -1)
3147             goto failed;
3148         Py_DECREF(value);
3149         value = ast2obj_expr(o->v.Assert.msg);
3150         if (!value) goto failed;
3151         if (_PyObject_SetAttrId(result, &PyId_msg, value) == -1)
3152             goto failed;
3153         Py_DECREF(value);
3154         break;
3155     case Import_kind:
3156         result = PyType_GenericNew(Import_type, NULL, NULL);
3157         if (!result) goto failed;
3158         value = ast2obj_list(o->v.Import.names, ast2obj_alias);
3159         if (!value) goto failed;
3160         if (_PyObject_SetAttrId(result, &PyId_names, value) == -1)
3161             goto failed;
3162         Py_DECREF(value);
3163         break;
3164     case ImportFrom_kind:
3165         result = PyType_GenericNew(ImportFrom_type, NULL, NULL);
3166         if (!result) goto failed;
3167         value = ast2obj_identifier(o->v.ImportFrom.module);
3168         if (!value) goto failed;
3169         if (_PyObject_SetAttrId(result, &PyId_module, value) == -1)
3170             goto failed;
3171         Py_DECREF(value);
3172         value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
3173         if (!value) goto failed;
3174         if (_PyObject_SetAttrId(result, &PyId_names, value) == -1)
3175             goto failed;
3176         Py_DECREF(value);
3177         value = ast2obj_int(o->v.ImportFrom.level);
3178         if (!value) goto failed;
3179         if (_PyObject_SetAttrId(result, &PyId_level, value) == -1)
3180             goto failed;
3181         Py_DECREF(value);
3182         break;
3183     case Global_kind:
3184         result = PyType_GenericNew(Global_type, NULL, NULL);
3185         if (!result) goto failed;
3186         value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
3187         if (!value) goto failed;
3188         if (_PyObject_SetAttrId(result, &PyId_names, value) == -1)
3189             goto failed;
3190         Py_DECREF(value);
3191         break;
3192     case Nonlocal_kind:
3193         result = PyType_GenericNew(Nonlocal_type, NULL, NULL);
3194         if (!result) goto failed;
3195         value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier);
3196         if (!value) goto failed;
3197         if (_PyObject_SetAttrId(result, &PyId_names, value) == -1)
3198             goto failed;
3199         Py_DECREF(value);
3200         break;
3201     case Expr_kind:
3202         result = PyType_GenericNew(Expr_type, NULL, NULL);
3203         if (!result) goto failed;
3204         value = ast2obj_expr(o->v.Expr.value);
3205         if (!value) goto failed;
3206         if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
3207             goto failed;
3208         Py_DECREF(value);
3209         break;
3210     case Pass_kind:
3211         result = PyType_GenericNew(Pass_type, NULL, NULL);
3212         if (!result) goto failed;
3213         break;
3214     case Break_kind:
3215         result = PyType_GenericNew(Break_type, NULL, NULL);
3216         if (!result) goto failed;
3217         break;
3218     case Continue_kind:
3219         result = PyType_GenericNew(Continue_type, NULL, NULL);
3220         if (!result) goto failed;
3221         break;
3222     }
3223     value = ast2obj_int(o->lineno);
3224     if (!value) goto failed;
3225     if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0)
3226         goto failed;
3227     Py_DECREF(value);
3228     value = ast2obj_int(o->col_offset);
3229     if (!value) goto failed;
3230     if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0)
3231         goto failed;
3232     Py_DECREF(value);
3233     value = ast2obj_int(o->end_lineno);
3234     if (!value) goto failed;
3235     if (_PyObject_SetAttrId(result, &PyId_end_lineno, value) < 0)
3236         goto failed;
3237     Py_DECREF(value);
3238     value = ast2obj_int(o->end_col_offset);
3239     if (!value) goto failed;
3240     if (_PyObject_SetAttrId(result, &PyId_end_col_offset, value) < 0)
3241         goto failed;
3242     Py_DECREF(value);
3243     return result;
3244 failed:
3245     Py_XDECREF(value);
3246     Py_XDECREF(result);
3247     return NULL;
3248 }
3249 
3250 PyObject*
ast2obj_expr(void * _o)3251 ast2obj_expr(void* _o)
3252 {
3253     expr_ty o = (expr_ty)_o;
3254     PyObject *result = NULL, *value = NULL;
3255     if (!o) {
3256         Py_RETURN_NONE;
3257     }
3258 
3259     switch (o->kind) {
3260     case BoolOp_kind:
3261         result = PyType_GenericNew(BoolOp_type, NULL, NULL);
3262         if (!result) goto failed;
3263         value = ast2obj_boolop(o->v.BoolOp.op);
3264         if (!value) goto failed;
3265         if (_PyObject_SetAttrId(result, &PyId_op, value) == -1)
3266             goto failed;
3267         Py_DECREF(value);
3268         value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
3269         if (!value) goto failed;
3270         if (_PyObject_SetAttrId(result, &PyId_values, value) == -1)
3271             goto failed;
3272         Py_DECREF(value);
3273         break;
3274     case NamedExpr_kind:
3275         result = PyType_GenericNew(NamedExpr_type, NULL, NULL);
3276         if (!result) goto failed;
3277         value = ast2obj_expr(o->v.NamedExpr.target);
3278         if (!value) goto failed;
3279         if (_PyObject_SetAttrId(result, &PyId_target, value) == -1)
3280             goto failed;
3281         Py_DECREF(value);
3282         value = ast2obj_expr(o->v.NamedExpr.value);
3283         if (!value) goto failed;
3284         if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
3285             goto failed;
3286         Py_DECREF(value);
3287         break;
3288     case BinOp_kind:
3289         result = PyType_GenericNew(BinOp_type, NULL, NULL);
3290         if (!result) goto failed;
3291         value = ast2obj_expr(o->v.BinOp.left);
3292         if (!value) goto failed;
3293         if (_PyObject_SetAttrId(result, &PyId_left, value) == -1)
3294             goto failed;
3295         Py_DECREF(value);
3296         value = ast2obj_operator(o->v.BinOp.op);
3297         if (!value) goto failed;
3298         if (_PyObject_SetAttrId(result, &PyId_op, value) == -1)
3299             goto failed;
3300         Py_DECREF(value);
3301         value = ast2obj_expr(o->v.BinOp.right);
3302         if (!value) goto failed;
3303         if (_PyObject_SetAttrId(result, &PyId_right, value) == -1)
3304             goto failed;
3305         Py_DECREF(value);
3306         break;
3307     case UnaryOp_kind:
3308         result = PyType_GenericNew(UnaryOp_type, NULL, NULL);
3309         if (!result) goto failed;
3310         value = ast2obj_unaryop(o->v.UnaryOp.op);
3311         if (!value) goto failed;
3312         if (_PyObject_SetAttrId(result, &PyId_op, value) == -1)
3313             goto failed;
3314         Py_DECREF(value);
3315         value = ast2obj_expr(o->v.UnaryOp.operand);
3316         if (!value) goto failed;
3317         if (_PyObject_SetAttrId(result, &PyId_operand, value) == -1)
3318             goto failed;
3319         Py_DECREF(value);
3320         break;
3321     case Lambda_kind:
3322         result = PyType_GenericNew(Lambda_type, NULL, NULL);
3323         if (!result) goto failed;
3324         value = ast2obj_arguments(o->v.Lambda.args);
3325         if (!value) goto failed;
3326         if (_PyObject_SetAttrId(result, &PyId_args, value) == -1)
3327             goto failed;
3328         Py_DECREF(value);
3329         value = ast2obj_expr(o->v.Lambda.body);
3330         if (!value) goto failed;
3331         if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
3332             goto failed;
3333         Py_DECREF(value);
3334         break;
3335     case IfExp_kind:
3336         result = PyType_GenericNew(IfExp_type, NULL, NULL);
3337         if (!result) goto failed;
3338         value = ast2obj_expr(o->v.IfExp.test);
3339         if (!value) goto failed;
3340         if (_PyObject_SetAttrId(result, &PyId_test, value) == -1)
3341             goto failed;
3342         Py_DECREF(value);
3343         value = ast2obj_expr(o->v.IfExp.body);
3344         if (!value) goto failed;
3345         if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
3346             goto failed;
3347         Py_DECREF(value);
3348         value = ast2obj_expr(o->v.IfExp.orelse);
3349         if (!value) goto failed;
3350         if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1)
3351             goto failed;
3352         Py_DECREF(value);
3353         break;
3354     case Dict_kind:
3355         result = PyType_GenericNew(Dict_type, NULL, NULL);
3356         if (!result) goto failed;
3357         value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
3358         if (!value) goto failed;
3359         if (_PyObject_SetAttrId(result, &PyId_keys, value) == -1)
3360             goto failed;
3361         Py_DECREF(value);
3362         value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
3363         if (!value) goto failed;
3364         if (_PyObject_SetAttrId(result, &PyId_values, value) == -1)
3365             goto failed;
3366         Py_DECREF(value);
3367         break;
3368     case Set_kind:
3369         result = PyType_GenericNew(Set_type, NULL, NULL);
3370         if (!result) goto failed;
3371         value = ast2obj_list(o->v.Set.elts, ast2obj_expr);
3372         if (!value) goto failed;
3373         if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1)
3374             goto failed;
3375         Py_DECREF(value);
3376         break;
3377     case ListComp_kind:
3378         result = PyType_GenericNew(ListComp_type, NULL, NULL);
3379         if (!result) goto failed;
3380         value = ast2obj_expr(o->v.ListComp.elt);
3381         if (!value) goto failed;
3382         if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1)
3383             goto failed;
3384         Py_DECREF(value);
3385         value = ast2obj_list(o->v.ListComp.generators, ast2obj_comprehension);
3386         if (!value) goto failed;
3387         if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1)
3388             goto failed;
3389         Py_DECREF(value);
3390         break;
3391     case SetComp_kind:
3392         result = PyType_GenericNew(SetComp_type, NULL, NULL);
3393         if (!result) goto failed;
3394         value = ast2obj_expr(o->v.SetComp.elt);
3395         if (!value) goto failed;
3396         if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1)
3397             goto failed;
3398         Py_DECREF(value);
3399         value = ast2obj_list(o->v.SetComp.generators, ast2obj_comprehension);
3400         if (!value) goto failed;
3401         if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1)
3402             goto failed;
3403         Py_DECREF(value);
3404         break;
3405     case DictComp_kind:
3406         result = PyType_GenericNew(DictComp_type, NULL, NULL);
3407         if (!result) goto failed;
3408         value = ast2obj_expr(o->v.DictComp.key);
3409         if (!value) goto failed;
3410         if (_PyObject_SetAttrId(result, &PyId_key, value) == -1)
3411             goto failed;
3412         Py_DECREF(value);
3413         value = ast2obj_expr(o->v.DictComp.value);
3414         if (!value) goto failed;
3415         if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
3416             goto failed;
3417         Py_DECREF(value);
3418         value = ast2obj_list(o->v.DictComp.generators, ast2obj_comprehension);
3419         if (!value) goto failed;
3420         if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1)
3421             goto failed;
3422         Py_DECREF(value);
3423         break;
3424     case GeneratorExp_kind:
3425         result = PyType_GenericNew(GeneratorExp_type, NULL, NULL);
3426         if (!result) goto failed;
3427         value = ast2obj_expr(o->v.GeneratorExp.elt);
3428         if (!value) goto failed;
3429         if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1)
3430             goto failed;
3431         Py_DECREF(value);
3432         value = ast2obj_list(o->v.GeneratorExp.generators,
3433                              ast2obj_comprehension);
3434         if (!value) goto failed;
3435         if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1)
3436             goto failed;
3437         Py_DECREF(value);
3438         break;
3439     case Await_kind:
3440         result = PyType_GenericNew(Await_type, NULL, NULL);
3441         if (!result) goto failed;
3442         value = ast2obj_expr(o->v.Await.value);
3443         if (!value) goto failed;
3444         if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
3445             goto failed;
3446         Py_DECREF(value);
3447         break;
3448     case Yield_kind:
3449         result = PyType_GenericNew(Yield_type, NULL, NULL);
3450         if (!result) goto failed;
3451         value = ast2obj_expr(o->v.Yield.value);
3452         if (!value) goto failed;
3453         if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
3454             goto failed;
3455         Py_DECREF(value);
3456         break;
3457     case YieldFrom_kind:
3458         result = PyType_GenericNew(YieldFrom_type, NULL, NULL);
3459         if (!result) goto failed;
3460         value = ast2obj_expr(o->v.YieldFrom.value);
3461         if (!value) goto failed;
3462         if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
3463             goto failed;
3464         Py_DECREF(value);
3465         break;
3466     case Compare_kind:
3467         result = PyType_GenericNew(Compare_type, NULL, NULL);
3468         if (!result) goto failed;
3469         value = ast2obj_expr(o->v.Compare.left);
3470         if (!value) goto failed;
3471         if (_PyObject_SetAttrId(result, &PyId_left, value) == -1)
3472             goto failed;
3473         Py_DECREF(value);
3474         {
3475             Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops);
3476             value = PyList_New(n);
3477             if (!value) goto failed;
3478             for(i = 0; i < n; i++)
3479                 PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
3480         }
3481         if (!value) goto failed;
3482         if (_PyObject_SetAttrId(result, &PyId_ops, value) == -1)
3483             goto failed;
3484         Py_DECREF(value);
3485         value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
3486         if (!value) goto failed;
3487         if (_PyObject_SetAttrId(result, &PyId_comparators, value) == -1)
3488             goto failed;
3489         Py_DECREF(value);
3490         break;
3491     case Call_kind:
3492         result = PyType_GenericNew(Call_type, NULL, NULL);
3493         if (!result) goto failed;
3494         value = ast2obj_expr(o->v.Call.func);
3495         if (!value) goto failed;
3496         if (_PyObject_SetAttrId(result, &PyId_func, value) == -1)
3497             goto failed;
3498         Py_DECREF(value);
3499         value = ast2obj_list(o->v.Call.args, ast2obj_expr);
3500         if (!value) goto failed;
3501         if (_PyObject_SetAttrId(result, &PyId_args, value) == -1)
3502             goto failed;
3503         Py_DECREF(value);
3504         value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
3505         if (!value) goto failed;
3506         if (_PyObject_SetAttrId(result, &PyId_keywords, value) == -1)
3507             goto failed;
3508         Py_DECREF(value);
3509         break;
3510     case FormattedValue_kind:
3511         result = PyType_GenericNew(FormattedValue_type, NULL, NULL);
3512         if (!result) goto failed;
3513         value = ast2obj_expr(o->v.FormattedValue.value);
3514         if (!value) goto failed;
3515         if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
3516             goto failed;
3517         Py_DECREF(value);
3518         value = ast2obj_int(o->v.FormattedValue.conversion);
3519         if (!value) goto failed;
3520         if (_PyObject_SetAttrId(result, &PyId_conversion, value) == -1)
3521             goto failed;
3522         Py_DECREF(value);
3523         value = ast2obj_expr(o->v.FormattedValue.format_spec);
3524         if (!value) goto failed;
3525         if (_PyObject_SetAttrId(result, &PyId_format_spec, value) == -1)
3526             goto failed;
3527         Py_DECREF(value);
3528         break;
3529     case JoinedStr_kind:
3530         result = PyType_GenericNew(JoinedStr_type, NULL, NULL);
3531         if (!result) goto failed;
3532         value = ast2obj_list(o->v.JoinedStr.values, ast2obj_expr);
3533         if (!value) goto failed;
3534         if (_PyObject_SetAttrId(result, &PyId_values, value) == -1)
3535             goto failed;
3536         Py_DECREF(value);
3537         break;
3538     case Constant_kind:
3539         result = PyType_GenericNew(Constant_type, NULL, NULL);
3540         if (!result) goto failed;
3541         value = ast2obj_constant(o->v.Constant.value);
3542         if (!value) goto failed;
3543         if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
3544             goto failed;
3545         Py_DECREF(value);
3546         value = ast2obj_string(o->v.Constant.kind);
3547         if (!value) goto failed;
3548         if (_PyObject_SetAttrId(result, &PyId_kind, value) == -1)
3549             goto failed;
3550         Py_DECREF(value);
3551         break;
3552     case Attribute_kind:
3553         result = PyType_GenericNew(Attribute_type, NULL, NULL);
3554         if (!result) goto failed;
3555         value = ast2obj_expr(o->v.Attribute.value);
3556         if (!value) goto failed;
3557         if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
3558             goto failed;
3559         Py_DECREF(value);
3560         value = ast2obj_identifier(o->v.Attribute.attr);
3561         if (!value) goto failed;
3562         if (_PyObject_SetAttrId(result, &PyId_attr, value) == -1)
3563             goto failed;
3564         Py_DECREF(value);
3565         value = ast2obj_expr_context(o->v.Attribute.ctx);
3566         if (!value) goto failed;
3567         if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1)
3568             goto failed;
3569         Py_DECREF(value);
3570         break;
3571     case Subscript_kind:
3572         result = PyType_GenericNew(Subscript_type, NULL, NULL);
3573         if (!result) goto failed;
3574         value = ast2obj_expr(o->v.Subscript.value);
3575         if (!value) goto failed;
3576         if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
3577             goto failed;
3578         Py_DECREF(value);
3579         value = ast2obj_slice(o->v.Subscript.slice);
3580         if (!value) goto failed;
3581         if (_PyObject_SetAttrId(result, &PyId_slice, value) == -1)
3582             goto failed;
3583         Py_DECREF(value);
3584         value = ast2obj_expr_context(o->v.Subscript.ctx);
3585         if (!value) goto failed;
3586         if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1)
3587             goto failed;
3588         Py_DECREF(value);
3589         break;
3590     case Starred_kind:
3591         result = PyType_GenericNew(Starred_type, NULL, NULL);
3592         if (!result) goto failed;
3593         value = ast2obj_expr(o->v.Starred.value);
3594         if (!value) goto failed;
3595         if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
3596             goto failed;
3597         Py_DECREF(value);
3598         value = ast2obj_expr_context(o->v.Starred.ctx);
3599         if (!value) goto failed;
3600         if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1)
3601             goto failed;
3602         Py_DECREF(value);
3603         break;
3604     case Name_kind:
3605         result = PyType_GenericNew(Name_type, NULL, NULL);
3606         if (!result) goto failed;
3607         value = ast2obj_identifier(o->v.Name.id);
3608         if (!value) goto failed;
3609         if (_PyObject_SetAttrId(result, &PyId_id, value) == -1)
3610             goto failed;
3611         Py_DECREF(value);
3612         value = ast2obj_expr_context(o->v.Name.ctx);
3613         if (!value) goto failed;
3614         if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1)
3615             goto failed;
3616         Py_DECREF(value);
3617         break;
3618     case List_kind:
3619         result = PyType_GenericNew(List_type, NULL, NULL);
3620         if (!result) goto failed;
3621         value = ast2obj_list(o->v.List.elts, ast2obj_expr);
3622         if (!value) goto failed;
3623         if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1)
3624             goto failed;
3625         Py_DECREF(value);
3626         value = ast2obj_expr_context(o->v.List.ctx);
3627         if (!value) goto failed;
3628         if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1)
3629             goto failed;
3630         Py_DECREF(value);
3631         break;
3632     case Tuple_kind:
3633         result = PyType_GenericNew(Tuple_type, NULL, NULL);
3634         if (!result) goto failed;
3635         value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
3636         if (!value) goto failed;
3637         if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1)
3638             goto failed;
3639         Py_DECREF(value);
3640         value = ast2obj_expr_context(o->v.Tuple.ctx);
3641         if (!value) goto failed;
3642         if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1)
3643             goto failed;
3644         Py_DECREF(value);
3645         break;
3646     }
3647     value = ast2obj_int(o->lineno);
3648     if (!value) goto failed;
3649     if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0)
3650         goto failed;
3651     Py_DECREF(value);
3652     value = ast2obj_int(o->col_offset);
3653     if (!value) goto failed;
3654     if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0)
3655         goto failed;
3656     Py_DECREF(value);
3657     value = ast2obj_int(o->end_lineno);
3658     if (!value) goto failed;
3659     if (_PyObject_SetAttrId(result, &PyId_end_lineno, value) < 0)
3660         goto failed;
3661     Py_DECREF(value);
3662     value = ast2obj_int(o->end_col_offset);
3663     if (!value) goto failed;
3664     if (_PyObject_SetAttrId(result, &PyId_end_col_offset, value) < 0)
3665         goto failed;
3666     Py_DECREF(value);
3667     return result;
3668 failed:
3669     Py_XDECREF(value);
3670     Py_XDECREF(result);
3671     return NULL;
3672 }
3673 
ast2obj_expr_context(expr_context_ty o)3674 PyObject* ast2obj_expr_context(expr_context_ty o)
3675 {
3676     switch(o) {
3677         case Load:
3678             Py_INCREF(Load_singleton);
3679             return Load_singleton;
3680         case Store:
3681             Py_INCREF(Store_singleton);
3682             return Store_singleton;
3683         case Del:
3684             Py_INCREF(Del_singleton);
3685             return Del_singleton;
3686         case AugLoad:
3687             Py_INCREF(AugLoad_singleton);
3688             return AugLoad_singleton;
3689         case AugStore:
3690             Py_INCREF(AugStore_singleton);
3691             return AugStore_singleton;
3692         case Param:
3693             Py_INCREF(Param_singleton);
3694             return Param_singleton;
3695         default:
3696             /* should never happen, but just in case ... */
3697             PyErr_Format(PyExc_SystemError, "unknown expr_context found");
3698             return NULL;
3699     }
3700 }
3701 PyObject*
ast2obj_slice(void * _o)3702 ast2obj_slice(void* _o)
3703 {
3704     slice_ty o = (slice_ty)_o;
3705     PyObject *result = NULL, *value = NULL;
3706     if (!o) {
3707         Py_RETURN_NONE;
3708     }
3709 
3710     switch (o->kind) {
3711     case Slice_kind:
3712         result = PyType_GenericNew(Slice_type, NULL, NULL);
3713         if (!result) goto failed;
3714         value = ast2obj_expr(o->v.Slice.lower);
3715         if (!value) goto failed;
3716         if (_PyObject_SetAttrId(result, &PyId_lower, value) == -1)
3717             goto failed;
3718         Py_DECREF(value);
3719         value = ast2obj_expr(o->v.Slice.upper);
3720         if (!value) goto failed;
3721         if (_PyObject_SetAttrId(result, &PyId_upper, value) == -1)
3722             goto failed;
3723         Py_DECREF(value);
3724         value = ast2obj_expr(o->v.Slice.step);
3725         if (!value) goto failed;
3726         if (_PyObject_SetAttrId(result, &PyId_step, value) == -1)
3727             goto failed;
3728         Py_DECREF(value);
3729         break;
3730     case ExtSlice_kind:
3731         result = PyType_GenericNew(ExtSlice_type, NULL, NULL);
3732         if (!result) goto failed;
3733         value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice);
3734         if (!value) goto failed;
3735         if (_PyObject_SetAttrId(result, &PyId_dims, value) == -1)
3736             goto failed;
3737         Py_DECREF(value);
3738         break;
3739     case Index_kind:
3740         result = PyType_GenericNew(Index_type, NULL, NULL);
3741         if (!result) goto failed;
3742         value = ast2obj_expr(o->v.Index.value);
3743         if (!value) goto failed;
3744         if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
3745             goto failed;
3746         Py_DECREF(value);
3747         break;
3748     }
3749     return result;
3750 failed:
3751     Py_XDECREF(value);
3752     Py_XDECREF(result);
3753     return NULL;
3754 }
3755 
ast2obj_boolop(boolop_ty o)3756 PyObject* ast2obj_boolop(boolop_ty o)
3757 {
3758     switch(o) {
3759         case And:
3760             Py_INCREF(And_singleton);
3761             return And_singleton;
3762         case Or:
3763             Py_INCREF(Or_singleton);
3764             return Or_singleton;
3765         default:
3766             /* should never happen, but just in case ... */
3767             PyErr_Format(PyExc_SystemError, "unknown boolop found");
3768             return NULL;
3769     }
3770 }
ast2obj_operator(operator_ty o)3771 PyObject* ast2obj_operator(operator_ty o)
3772 {
3773     switch(o) {
3774         case Add:
3775             Py_INCREF(Add_singleton);
3776             return Add_singleton;
3777         case Sub:
3778             Py_INCREF(Sub_singleton);
3779             return Sub_singleton;
3780         case Mult:
3781             Py_INCREF(Mult_singleton);
3782             return Mult_singleton;
3783         case MatMult:
3784             Py_INCREF(MatMult_singleton);
3785             return MatMult_singleton;
3786         case Div:
3787             Py_INCREF(Div_singleton);
3788             return Div_singleton;
3789         case Mod:
3790             Py_INCREF(Mod_singleton);
3791             return Mod_singleton;
3792         case Pow:
3793             Py_INCREF(Pow_singleton);
3794             return Pow_singleton;
3795         case LShift:
3796             Py_INCREF(LShift_singleton);
3797             return LShift_singleton;
3798         case RShift:
3799             Py_INCREF(RShift_singleton);
3800             return RShift_singleton;
3801         case BitOr:
3802             Py_INCREF(BitOr_singleton);
3803             return BitOr_singleton;
3804         case BitXor:
3805             Py_INCREF(BitXor_singleton);
3806             return BitXor_singleton;
3807         case BitAnd:
3808             Py_INCREF(BitAnd_singleton);
3809             return BitAnd_singleton;
3810         case FloorDiv:
3811             Py_INCREF(FloorDiv_singleton);
3812             return FloorDiv_singleton;
3813         default:
3814             /* should never happen, but just in case ... */
3815             PyErr_Format(PyExc_SystemError, "unknown operator found");
3816             return NULL;
3817     }
3818 }
ast2obj_unaryop(unaryop_ty o)3819 PyObject* ast2obj_unaryop(unaryop_ty o)
3820 {
3821     switch(o) {
3822         case Invert:
3823             Py_INCREF(Invert_singleton);
3824             return Invert_singleton;
3825         case Not:
3826             Py_INCREF(Not_singleton);
3827             return Not_singleton;
3828         case UAdd:
3829             Py_INCREF(UAdd_singleton);
3830             return UAdd_singleton;
3831         case USub:
3832             Py_INCREF(USub_singleton);
3833             return USub_singleton;
3834         default:
3835             /* should never happen, but just in case ... */
3836             PyErr_Format(PyExc_SystemError, "unknown unaryop found");
3837             return NULL;
3838     }
3839 }
ast2obj_cmpop(cmpop_ty o)3840 PyObject* ast2obj_cmpop(cmpop_ty o)
3841 {
3842     switch(o) {
3843         case Eq:
3844             Py_INCREF(Eq_singleton);
3845             return Eq_singleton;
3846         case NotEq:
3847             Py_INCREF(NotEq_singleton);
3848             return NotEq_singleton;
3849         case Lt:
3850             Py_INCREF(Lt_singleton);
3851             return Lt_singleton;
3852         case LtE:
3853             Py_INCREF(LtE_singleton);
3854             return LtE_singleton;
3855         case Gt:
3856             Py_INCREF(Gt_singleton);
3857             return Gt_singleton;
3858         case GtE:
3859             Py_INCREF(GtE_singleton);
3860             return GtE_singleton;
3861         case Is:
3862             Py_INCREF(Is_singleton);
3863             return Is_singleton;
3864         case IsNot:
3865             Py_INCREF(IsNot_singleton);
3866             return IsNot_singleton;
3867         case In:
3868             Py_INCREF(In_singleton);
3869             return In_singleton;
3870         case NotIn:
3871             Py_INCREF(NotIn_singleton);
3872             return NotIn_singleton;
3873         default:
3874             /* should never happen, but just in case ... */
3875             PyErr_Format(PyExc_SystemError, "unknown cmpop found");
3876             return NULL;
3877     }
3878 }
3879 PyObject*
ast2obj_comprehension(void * _o)3880 ast2obj_comprehension(void* _o)
3881 {
3882     comprehension_ty o = (comprehension_ty)_o;
3883     PyObject *result = NULL, *value = NULL;
3884     if (!o) {
3885         Py_RETURN_NONE;
3886     }
3887 
3888     result = PyType_GenericNew(comprehension_type, NULL, NULL);
3889     if (!result) return NULL;
3890     value = ast2obj_expr(o->target);
3891     if (!value) goto failed;
3892     if (_PyObject_SetAttrId(result, &PyId_target, value) == -1)
3893         goto failed;
3894     Py_DECREF(value);
3895     value = ast2obj_expr(o->iter);
3896     if (!value) goto failed;
3897     if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1)
3898         goto failed;
3899     Py_DECREF(value);
3900     value = ast2obj_list(o->ifs, ast2obj_expr);
3901     if (!value) goto failed;
3902     if (_PyObject_SetAttrId(result, &PyId_ifs, value) == -1)
3903         goto failed;
3904     Py_DECREF(value);
3905     value = ast2obj_int(o->is_async);
3906     if (!value) goto failed;
3907     if (_PyObject_SetAttrId(result, &PyId_is_async, value) == -1)
3908         goto failed;
3909     Py_DECREF(value);
3910     return result;
3911 failed:
3912     Py_XDECREF(value);
3913     Py_XDECREF(result);
3914     return NULL;
3915 }
3916 
3917 PyObject*
ast2obj_excepthandler(void * _o)3918 ast2obj_excepthandler(void* _o)
3919 {
3920     excepthandler_ty o = (excepthandler_ty)_o;
3921     PyObject *result = NULL, *value = NULL;
3922     if (!o) {
3923         Py_RETURN_NONE;
3924     }
3925 
3926     switch (o->kind) {
3927     case ExceptHandler_kind:
3928         result = PyType_GenericNew(ExceptHandler_type, NULL, NULL);
3929         if (!result) goto failed;
3930         value = ast2obj_expr(o->v.ExceptHandler.type);
3931         if (!value) goto failed;
3932         if (_PyObject_SetAttrId(result, &PyId_type, value) == -1)
3933             goto failed;
3934         Py_DECREF(value);
3935         value = ast2obj_identifier(o->v.ExceptHandler.name);
3936         if (!value) goto failed;
3937         if (_PyObject_SetAttrId(result, &PyId_name, value) == -1)
3938             goto failed;
3939         Py_DECREF(value);
3940         value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt);
3941         if (!value) goto failed;
3942         if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
3943             goto failed;
3944         Py_DECREF(value);
3945         break;
3946     }
3947     value = ast2obj_int(o->lineno);
3948     if (!value) goto failed;
3949     if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0)
3950         goto failed;
3951     Py_DECREF(value);
3952     value = ast2obj_int(o->col_offset);
3953     if (!value) goto failed;
3954     if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0)
3955         goto failed;
3956     Py_DECREF(value);
3957     value = ast2obj_int(o->end_lineno);
3958     if (!value) goto failed;
3959     if (_PyObject_SetAttrId(result, &PyId_end_lineno, value) < 0)
3960         goto failed;
3961     Py_DECREF(value);
3962     value = ast2obj_int(o->end_col_offset);
3963     if (!value) goto failed;
3964     if (_PyObject_SetAttrId(result, &PyId_end_col_offset, value) < 0)
3965         goto failed;
3966     Py_DECREF(value);
3967     return result;
3968 failed:
3969     Py_XDECREF(value);
3970     Py_XDECREF(result);
3971     return NULL;
3972 }
3973 
3974 PyObject*
ast2obj_arguments(void * _o)3975 ast2obj_arguments(void* _o)
3976 {
3977     arguments_ty o = (arguments_ty)_o;
3978     PyObject *result = NULL, *value = NULL;
3979     if (!o) {
3980         Py_RETURN_NONE;
3981     }
3982 
3983     result = PyType_GenericNew(arguments_type, NULL, NULL);
3984     if (!result) return NULL;
3985     value = ast2obj_list(o->posonlyargs, ast2obj_arg);
3986     if (!value) goto failed;
3987     if (_PyObject_SetAttrId(result, &PyId_posonlyargs, value) == -1)
3988         goto failed;
3989     Py_DECREF(value);
3990     value = ast2obj_list(o->args, ast2obj_arg);
3991     if (!value) goto failed;
3992     if (_PyObject_SetAttrId(result, &PyId_args, value) == -1)
3993         goto failed;
3994     Py_DECREF(value);
3995     value = ast2obj_arg(o->vararg);
3996     if (!value) goto failed;
3997     if (_PyObject_SetAttrId(result, &PyId_vararg, value) == -1)
3998         goto failed;
3999     Py_DECREF(value);
4000     value = ast2obj_list(o->kwonlyargs, ast2obj_arg);
4001     if (!value) goto failed;
4002     if (_PyObject_SetAttrId(result, &PyId_kwonlyargs, value) == -1)
4003         goto failed;
4004     Py_DECREF(value);
4005     value = ast2obj_list(o->kw_defaults, ast2obj_expr);
4006     if (!value) goto failed;
4007     if (_PyObject_SetAttrId(result, &PyId_kw_defaults, value) == -1)
4008         goto failed;
4009     Py_DECREF(value);
4010     value = ast2obj_arg(o->kwarg);
4011     if (!value) goto failed;
4012     if (_PyObject_SetAttrId(result, &PyId_kwarg, value) == -1)
4013         goto failed;
4014     Py_DECREF(value);
4015     value = ast2obj_list(o->defaults, ast2obj_expr);
4016     if (!value) goto failed;
4017     if (_PyObject_SetAttrId(result, &PyId_defaults, value) == -1)
4018         goto failed;
4019     Py_DECREF(value);
4020     return result;
4021 failed:
4022     Py_XDECREF(value);
4023     Py_XDECREF(result);
4024     return NULL;
4025 }
4026 
4027 PyObject*
ast2obj_arg(void * _o)4028 ast2obj_arg(void* _o)
4029 {
4030     arg_ty o = (arg_ty)_o;
4031     PyObject *result = NULL, *value = NULL;
4032     if (!o) {
4033         Py_RETURN_NONE;
4034     }
4035 
4036     result = PyType_GenericNew(arg_type, NULL, NULL);
4037     if (!result) return NULL;
4038     value = ast2obj_identifier(o->arg);
4039     if (!value) goto failed;
4040     if (_PyObject_SetAttrId(result, &PyId_arg, value) == -1)
4041         goto failed;
4042     Py_DECREF(value);
4043     value = ast2obj_expr(o->annotation);
4044     if (!value) goto failed;
4045     if (_PyObject_SetAttrId(result, &PyId_annotation, value) == -1)
4046         goto failed;
4047     Py_DECREF(value);
4048     value = ast2obj_string(o->type_comment);
4049     if (!value) goto failed;
4050     if (_PyObject_SetAttrId(result, &PyId_type_comment, value) == -1)
4051         goto failed;
4052     Py_DECREF(value);
4053     value = ast2obj_int(o->lineno);
4054     if (!value) goto failed;
4055     if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0)
4056         goto failed;
4057     Py_DECREF(value);
4058     value = ast2obj_int(o->col_offset);
4059     if (!value) goto failed;
4060     if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0)
4061         goto failed;
4062     Py_DECREF(value);
4063     value = ast2obj_int(o->end_lineno);
4064     if (!value) goto failed;
4065     if (_PyObject_SetAttrId(result, &PyId_end_lineno, value) < 0)
4066         goto failed;
4067     Py_DECREF(value);
4068     value = ast2obj_int(o->end_col_offset);
4069     if (!value) goto failed;
4070     if (_PyObject_SetAttrId(result, &PyId_end_col_offset, value) < 0)
4071         goto failed;
4072     Py_DECREF(value);
4073     return result;
4074 failed:
4075     Py_XDECREF(value);
4076     Py_XDECREF(result);
4077     return NULL;
4078 }
4079 
4080 PyObject*
ast2obj_keyword(void * _o)4081 ast2obj_keyword(void* _o)
4082 {
4083     keyword_ty o = (keyword_ty)_o;
4084     PyObject *result = NULL, *value = NULL;
4085     if (!o) {
4086         Py_RETURN_NONE;
4087     }
4088 
4089     result = PyType_GenericNew(keyword_type, NULL, NULL);
4090     if (!result) return NULL;
4091     value = ast2obj_identifier(o->arg);
4092     if (!value) goto failed;
4093     if (_PyObject_SetAttrId(result, &PyId_arg, value) == -1)
4094         goto failed;
4095     Py_DECREF(value);
4096     value = ast2obj_expr(o->value);
4097     if (!value) goto failed;
4098     if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
4099         goto failed;
4100     Py_DECREF(value);
4101     return result;
4102 failed:
4103     Py_XDECREF(value);
4104     Py_XDECREF(result);
4105     return NULL;
4106 }
4107 
4108 PyObject*
ast2obj_alias(void * _o)4109 ast2obj_alias(void* _o)
4110 {
4111     alias_ty o = (alias_ty)_o;
4112     PyObject *result = NULL, *value = NULL;
4113     if (!o) {
4114         Py_RETURN_NONE;
4115     }
4116 
4117     result = PyType_GenericNew(alias_type, NULL, NULL);
4118     if (!result) return NULL;
4119     value = ast2obj_identifier(o->name);
4120     if (!value) goto failed;
4121     if (_PyObject_SetAttrId(result, &PyId_name, value) == -1)
4122         goto failed;
4123     Py_DECREF(value);
4124     value = ast2obj_identifier(o->asname);
4125     if (!value) goto failed;
4126     if (_PyObject_SetAttrId(result, &PyId_asname, value) == -1)
4127         goto failed;
4128     Py_DECREF(value);
4129     return result;
4130 failed:
4131     Py_XDECREF(value);
4132     Py_XDECREF(result);
4133     return NULL;
4134 }
4135 
4136 PyObject*
ast2obj_withitem(void * _o)4137 ast2obj_withitem(void* _o)
4138 {
4139     withitem_ty o = (withitem_ty)_o;
4140     PyObject *result = NULL, *value = NULL;
4141     if (!o) {
4142         Py_RETURN_NONE;
4143     }
4144 
4145     result = PyType_GenericNew(withitem_type, NULL, NULL);
4146     if (!result) return NULL;
4147     value = ast2obj_expr(o->context_expr);
4148     if (!value) goto failed;
4149     if (_PyObject_SetAttrId(result, &PyId_context_expr, value) == -1)
4150         goto failed;
4151     Py_DECREF(value);
4152     value = ast2obj_expr(o->optional_vars);
4153     if (!value) goto failed;
4154     if (_PyObject_SetAttrId(result, &PyId_optional_vars, value) == -1)
4155         goto failed;
4156     Py_DECREF(value);
4157     return result;
4158 failed:
4159     Py_XDECREF(value);
4160     Py_XDECREF(result);
4161     return NULL;
4162 }
4163 
4164 PyObject*
ast2obj_type_ignore(void * _o)4165 ast2obj_type_ignore(void* _o)
4166 {
4167     type_ignore_ty o = (type_ignore_ty)_o;
4168     PyObject *result = NULL, *value = NULL;
4169     if (!o) {
4170         Py_RETURN_NONE;
4171     }
4172 
4173     switch (o->kind) {
4174     case TypeIgnore_kind:
4175         result = PyType_GenericNew(TypeIgnore_type, NULL, NULL);
4176         if (!result) goto failed;
4177         value = ast2obj_int(o->v.TypeIgnore.lineno);
4178         if (!value) goto failed;
4179         if (_PyObject_SetAttrId(result, &PyId_lineno, value) == -1)
4180             goto failed;
4181         Py_DECREF(value);
4182         value = ast2obj_string(o->v.TypeIgnore.tag);
4183         if (!value) goto failed;
4184         if (_PyObject_SetAttrId(result, &PyId_tag, value) == -1)
4185             goto failed;
4186         Py_DECREF(value);
4187         break;
4188     }
4189     return result;
4190 failed:
4191     Py_XDECREF(value);
4192     Py_XDECREF(result);
4193     return NULL;
4194 }
4195 
4196 
4197 int
obj2ast_mod(PyObject * obj,mod_ty * out,PyArena * arena)4198 obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena)
4199 {
4200     int isinstance;
4201 
4202     PyObject *tmp = NULL;
4203 
4204     if (obj == Py_None) {
4205         *out = NULL;
4206         return 0;
4207     }
4208     isinstance = PyObject_IsInstance(obj, (PyObject*)Module_type);
4209     if (isinstance == -1) {
4210         return 1;
4211     }
4212     if (isinstance) {
4213         asdl_seq* body;
4214         asdl_seq* type_ignores;
4215 
4216         if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) {
4217             return 1;
4218         }
4219         if (tmp == NULL) {
4220             PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module");
4221             return 1;
4222         }
4223         else {
4224             int res;
4225             Py_ssize_t len;
4226             Py_ssize_t i;
4227             if (!PyList_Check(tmp)) {
4228                 PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4229                 goto failed;
4230             }
4231             len = PyList_GET_SIZE(tmp);
4232             body = _Py_asdl_seq_new(len, arena);
4233             if (body == NULL) goto failed;
4234             for (i = 0; i < len; i++) {
4235                 stmt_ty val;
4236                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
4237                 if (res != 0) goto failed;
4238                 if (len != PyList_GET_SIZE(tmp)) {
4239                     PyErr_SetString(PyExc_RuntimeError, "Module field \"body\" changed size during iteration");
4240                     goto failed;
4241                 }
4242                 asdl_seq_SET(body, i, val);
4243             }
4244             Py_CLEAR(tmp);
4245         }
4246         if (_PyObject_LookupAttrId(obj, &PyId_type_ignores, &tmp) < 0) {
4247             return 1;
4248         }
4249         if (tmp == NULL) {
4250             PyErr_SetString(PyExc_TypeError, "required field \"type_ignores\" missing from Module");
4251             return 1;
4252         }
4253         else {
4254             int res;
4255             Py_ssize_t len;
4256             Py_ssize_t i;
4257             if (!PyList_Check(tmp)) {
4258                 PyErr_Format(PyExc_TypeError, "Module field \"type_ignores\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4259                 goto failed;
4260             }
4261             len = PyList_GET_SIZE(tmp);
4262             type_ignores = _Py_asdl_seq_new(len, arena);
4263             if (type_ignores == NULL) goto failed;
4264             for (i = 0; i < len; i++) {
4265                 type_ignore_ty val;
4266                 res = obj2ast_type_ignore(PyList_GET_ITEM(tmp, i), &val, arena);
4267                 if (res != 0) goto failed;
4268                 if (len != PyList_GET_SIZE(tmp)) {
4269                     PyErr_SetString(PyExc_RuntimeError, "Module field \"type_ignores\" changed size during iteration");
4270                     goto failed;
4271                 }
4272                 asdl_seq_SET(type_ignores, i, val);
4273             }
4274             Py_CLEAR(tmp);
4275         }
4276         *out = Module(body, type_ignores, arena);
4277         if (*out == NULL) goto failed;
4278         return 0;
4279     }
4280     isinstance = PyObject_IsInstance(obj, (PyObject*)Interactive_type);
4281     if (isinstance == -1) {
4282         return 1;
4283     }
4284     if (isinstance) {
4285         asdl_seq* body;
4286 
4287         if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) {
4288             return 1;
4289         }
4290         if (tmp == NULL) {
4291             PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive");
4292             return 1;
4293         }
4294         else {
4295             int res;
4296             Py_ssize_t len;
4297             Py_ssize_t i;
4298             if (!PyList_Check(tmp)) {
4299                 PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4300                 goto failed;
4301             }
4302             len = PyList_GET_SIZE(tmp);
4303             body = _Py_asdl_seq_new(len, arena);
4304             if (body == NULL) goto failed;
4305             for (i = 0; i < len; i++) {
4306                 stmt_ty val;
4307                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
4308                 if (res != 0) goto failed;
4309                 if (len != PyList_GET_SIZE(tmp)) {
4310                     PyErr_SetString(PyExc_RuntimeError, "Interactive field \"body\" changed size during iteration");
4311                     goto failed;
4312                 }
4313                 asdl_seq_SET(body, i, val);
4314             }
4315             Py_CLEAR(tmp);
4316         }
4317         *out = Interactive(body, arena);
4318         if (*out == NULL) goto failed;
4319         return 0;
4320     }
4321     isinstance = PyObject_IsInstance(obj, (PyObject*)Expression_type);
4322     if (isinstance == -1) {
4323         return 1;
4324     }
4325     if (isinstance) {
4326         expr_ty body;
4327 
4328         if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) {
4329             return 1;
4330         }
4331         if (tmp == NULL) {
4332             PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression");
4333             return 1;
4334         }
4335         else {
4336             int res;
4337             res = obj2ast_expr(tmp, &body, arena);
4338             if (res != 0) goto failed;
4339             Py_CLEAR(tmp);
4340         }
4341         *out = Expression(body, arena);
4342         if (*out == NULL) goto failed;
4343         return 0;
4344     }
4345     isinstance = PyObject_IsInstance(obj, (PyObject*)FunctionType_type);
4346     if (isinstance == -1) {
4347         return 1;
4348     }
4349     if (isinstance) {
4350         asdl_seq* argtypes;
4351         expr_ty returns;
4352 
4353         if (_PyObject_LookupAttrId(obj, &PyId_argtypes, &tmp) < 0) {
4354             return 1;
4355         }
4356         if (tmp == NULL) {
4357             PyErr_SetString(PyExc_TypeError, "required field \"argtypes\" missing from FunctionType");
4358             return 1;
4359         }
4360         else {
4361             int res;
4362             Py_ssize_t len;
4363             Py_ssize_t i;
4364             if (!PyList_Check(tmp)) {
4365                 PyErr_Format(PyExc_TypeError, "FunctionType field \"argtypes\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4366                 goto failed;
4367             }
4368             len = PyList_GET_SIZE(tmp);
4369             argtypes = _Py_asdl_seq_new(len, arena);
4370             if (argtypes == NULL) goto failed;
4371             for (i = 0; i < len; i++) {
4372                 expr_ty val;
4373                 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
4374                 if (res != 0) goto failed;
4375                 if (len != PyList_GET_SIZE(tmp)) {
4376                     PyErr_SetString(PyExc_RuntimeError, "FunctionType field \"argtypes\" changed size during iteration");
4377                     goto failed;
4378                 }
4379                 asdl_seq_SET(argtypes, i, val);
4380             }
4381             Py_CLEAR(tmp);
4382         }
4383         if (_PyObject_LookupAttrId(obj, &PyId_returns, &tmp) < 0) {
4384             return 1;
4385         }
4386         if (tmp == NULL) {
4387             PyErr_SetString(PyExc_TypeError, "required field \"returns\" missing from FunctionType");
4388             return 1;
4389         }
4390         else {
4391             int res;
4392             res = obj2ast_expr(tmp, &returns, arena);
4393             if (res != 0) goto failed;
4394             Py_CLEAR(tmp);
4395         }
4396         *out = FunctionType(argtypes, returns, arena);
4397         if (*out == NULL) goto failed;
4398         return 0;
4399     }
4400     isinstance = PyObject_IsInstance(obj, (PyObject*)Suite_type);
4401     if (isinstance == -1) {
4402         return 1;
4403     }
4404     if (isinstance) {
4405         asdl_seq* body;
4406 
4407         if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) {
4408             return 1;
4409         }
4410         if (tmp == NULL) {
4411             PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Suite");
4412             return 1;
4413         }
4414         else {
4415             int res;
4416             Py_ssize_t len;
4417             Py_ssize_t i;
4418             if (!PyList_Check(tmp)) {
4419                 PyErr_Format(PyExc_TypeError, "Suite field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4420                 goto failed;
4421             }
4422             len = PyList_GET_SIZE(tmp);
4423             body = _Py_asdl_seq_new(len, arena);
4424             if (body == NULL) goto failed;
4425             for (i = 0; i < len; i++) {
4426                 stmt_ty val;
4427                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
4428                 if (res != 0) goto failed;
4429                 if (len != PyList_GET_SIZE(tmp)) {
4430                     PyErr_SetString(PyExc_RuntimeError, "Suite field \"body\" changed size during iteration");
4431                     goto failed;
4432                 }
4433                 asdl_seq_SET(body, i, val);
4434             }
4435             Py_CLEAR(tmp);
4436         }
4437         *out = Suite(body, arena);
4438         if (*out == NULL) goto failed;
4439         return 0;
4440     }
4441 
4442     PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj);
4443     failed:
4444     Py_XDECREF(tmp);
4445     return 1;
4446 }
4447 
4448 int
obj2ast_stmt(PyObject * obj,stmt_ty * out,PyArena * arena)4449 obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
4450 {
4451     int isinstance;
4452 
4453     PyObject *tmp = NULL;
4454     int lineno;
4455     int col_offset;
4456     int end_lineno;
4457     int end_col_offset;
4458 
4459     if (obj == Py_None) {
4460         *out = NULL;
4461         return 0;
4462     }
4463     if (_PyObject_LookupAttrId(obj, &PyId_lineno, &tmp) < 0) {
4464         return 1;
4465     }
4466     if (tmp == NULL) {
4467         PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt");
4468         return 1;
4469     }
4470     else {
4471         int res;
4472         res = obj2ast_int(tmp, &lineno, arena);
4473         if (res != 0) goto failed;
4474         Py_CLEAR(tmp);
4475     }
4476     if (_PyObject_LookupAttrId(obj, &PyId_col_offset, &tmp) < 0) {
4477         return 1;
4478     }
4479     if (tmp == NULL) {
4480         PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt");
4481         return 1;
4482     }
4483     else {
4484         int res;
4485         res = obj2ast_int(tmp, &col_offset, arena);
4486         if (res != 0) goto failed;
4487         Py_CLEAR(tmp);
4488     }
4489     if (_PyObject_LookupAttrId(obj, &PyId_end_lineno, &tmp) < 0) {
4490         return 1;
4491     }
4492     if (tmp == NULL || tmp == Py_None) {
4493         Py_CLEAR(tmp);
4494         end_lineno = 0;
4495     }
4496     else {
4497         int res;
4498         res = obj2ast_int(tmp, &end_lineno, arena);
4499         if (res != 0) goto failed;
4500         Py_CLEAR(tmp);
4501     }
4502     if (_PyObject_LookupAttrId(obj, &PyId_end_col_offset, &tmp) < 0) {
4503         return 1;
4504     }
4505     if (tmp == NULL || tmp == Py_None) {
4506         Py_CLEAR(tmp);
4507         end_col_offset = 0;
4508     }
4509     else {
4510         int res;
4511         res = obj2ast_int(tmp, &end_col_offset, arena);
4512         if (res != 0) goto failed;
4513         Py_CLEAR(tmp);
4514     }
4515     isinstance = PyObject_IsInstance(obj, (PyObject*)FunctionDef_type);
4516     if (isinstance == -1) {
4517         return 1;
4518     }
4519     if (isinstance) {
4520         identifier name;
4521         arguments_ty args;
4522         asdl_seq* body;
4523         asdl_seq* decorator_list;
4524         expr_ty returns;
4525         string type_comment;
4526 
4527         if (_PyObject_LookupAttrId(obj, &PyId_name, &tmp) < 0) {
4528             return 1;
4529         }
4530         if (tmp == NULL) {
4531             PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef");
4532             return 1;
4533         }
4534         else {
4535             int res;
4536             res = obj2ast_identifier(tmp, &name, arena);
4537             if (res != 0) goto failed;
4538             Py_CLEAR(tmp);
4539         }
4540         if (_PyObject_LookupAttrId(obj, &PyId_args, &tmp) < 0) {
4541             return 1;
4542         }
4543         if (tmp == NULL) {
4544             PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef");
4545             return 1;
4546         }
4547         else {
4548             int res;
4549             res = obj2ast_arguments(tmp, &args, arena);
4550             if (res != 0) goto failed;
4551             Py_CLEAR(tmp);
4552         }
4553         if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) {
4554             return 1;
4555         }
4556         if (tmp == NULL) {
4557             PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef");
4558             return 1;
4559         }
4560         else {
4561             int res;
4562             Py_ssize_t len;
4563             Py_ssize_t i;
4564             if (!PyList_Check(tmp)) {
4565                 PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4566                 goto failed;
4567             }
4568             len = PyList_GET_SIZE(tmp);
4569             body = _Py_asdl_seq_new(len, arena);
4570             if (body == NULL) goto failed;
4571             for (i = 0; i < len; i++) {
4572                 stmt_ty val;
4573                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
4574                 if (res != 0) goto failed;
4575                 if (len != PyList_GET_SIZE(tmp)) {
4576                     PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"body\" changed size during iteration");
4577                     goto failed;
4578                 }
4579                 asdl_seq_SET(body, i, val);
4580             }
4581             Py_CLEAR(tmp);
4582         }
4583         if (_PyObject_LookupAttrId(obj, &PyId_decorator_list, &tmp) < 0) {
4584             return 1;
4585         }
4586         if (tmp == NULL) {
4587             PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef");
4588             return 1;
4589         }
4590         else {
4591             int res;
4592             Py_ssize_t len;
4593             Py_ssize_t i;
4594             if (!PyList_Check(tmp)) {
4595                 PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4596                 goto failed;
4597             }
4598             len = PyList_GET_SIZE(tmp);
4599             decorator_list = _Py_asdl_seq_new(len, arena);
4600             if (decorator_list == NULL) goto failed;
4601             for (i = 0; i < len; i++) {
4602                 expr_ty val;
4603                 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
4604                 if (res != 0) goto failed;
4605                 if (len != PyList_GET_SIZE(tmp)) {
4606                     PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"decorator_list\" changed size during iteration");
4607                     goto failed;
4608                 }
4609                 asdl_seq_SET(decorator_list, i, val);
4610             }
4611             Py_CLEAR(tmp);
4612         }
4613         if (_PyObject_LookupAttrId(obj, &PyId_returns, &tmp) < 0) {
4614             return 1;
4615         }
4616         if (tmp == NULL || tmp == Py_None) {
4617             Py_CLEAR(tmp);
4618             returns = NULL;
4619         }
4620         else {
4621             int res;
4622             res = obj2ast_expr(tmp, &returns, arena);
4623             if (res != 0) goto failed;
4624             Py_CLEAR(tmp);
4625         }
4626         if (_PyObject_LookupAttrId(obj, &PyId_type_comment, &tmp) < 0) {
4627             return 1;
4628         }
4629         if (tmp == NULL || tmp == Py_None) {
4630             Py_CLEAR(tmp);
4631             type_comment = NULL;
4632         }
4633         else {
4634             int res;
4635             res = obj2ast_string(tmp, &type_comment, arena);
4636             if (res != 0) goto failed;
4637             Py_CLEAR(tmp);
4638         }
4639         *out = FunctionDef(name, args, body, decorator_list, returns,
4640                            type_comment, lineno, col_offset, end_lineno,
4641                            end_col_offset, arena);
4642         if (*out == NULL) goto failed;
4643         return 0;
4644     }
4645     isinstance = PyObject_IsInstance(obj, (PyObject*)AsyncFunctionDef_type);
4646     if (isinstance == -1) {
4647         return 1;
4648     }
4649     if (isinstance) {
4650         identifier name;
4651         arguments_ty args;
4652         asdl_seq* body;
4653         asdl_seq* decorator_list;
4654         expr_ty returns;
4655         string type_comment;
4656 
4657         if (_PyObject_LookupAttrId(obj, &PyId_name, &tmp) < 0) {
4658             return 1;
4659         }
4660         if (tmp == NULL) {
4661             PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from AsyncFunctionDef");
4662             return 1;
4663         }
4664         else {
4665             int res;
4666             res = obj2ast_identifier(tmp, &name, arena);
4667             if (res != 0) goto failed;
4668             Py_CLEAR(tmp);
4669         }
4670         if (_PyObject_LookupAttrId(obj, &PyId_args, &tmp) < 0) {
4671             return 1;
4672         }
4673         if (tmp == NULL) {
4674             PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from AsyncFunctionDef");
4675             return 1;
4676         }
4677         else {
4678             int res;
4679             res = obj2ast_arguments(tmp, &args, arena);
4680             if (res != 0) goto failed;
4681             Py_CLEAR(tmp);
4682         }
4683         if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) {
4684             return 1;
4685         }
4686         if (tmp == NULL) {
4687             PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFunctionDef");
4688             return 1;
4689         }
4690         else {
4691             int res;
4692             Py_ssize_t len;
4693             Py_ssize_t i;
4694             if (!PyList_Check(tmp)) {
4695                 PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4696                 goto failed;
4697             }
4698             len = PyList_GET_SIZE(tmp);
4699             body = _Py_asdl_seq_new(len, arena);
4700             if (body == NULL) goto failed;
4701             for (i = 0; i < len; i++) {
4702                 stmt_ty val;
4703                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
4704                 if (res != 0) goto failed;
4705                 if (len != PyList_GET_SIZE(tmp)) {
4706                     PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"body\" changed size during iteration");
4707                     goto failed;
4708                 }
4709                 asdl_seq_SET(body, i, val);
4710             }
4711             Py_CLEAR(tmp);
4712         }
4713         if (_PyObject_LookupAttrId(obj, &PyId_decorator_list, &tmp) < 0) {
4714             return 1;
4715         }
4716         if (tmp == NULL) {
4717             PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from AsyncFunctionDef");
4718             return 1;
4719         }
4720         else {
4721             int res;
4722             Py_ssize_t len;
4723             Py_ssize_t i;
4724             if (!PyList_Check(tmp)) {
4725                 PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4726                 goto failed;
4727             }
4728             len = PyList_GET_SIZE(tmp);
4729             decorator_list = _Py_asdl_seq_new(len, arena);
4730             if (decorator_list == NULL) goto failed;
4731             for (i = 0; i < len; i++) {
4732                 expr_ty val;
4733                 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
4734                 if (res != 0) goto failed;
4735                 if (len != PyList_GET_SIZE(tmp)) {
4736                     PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"decorator_list\" changed size during iteration");
4737                     goto failed;
4738                 }
4739                 asdl_seq_SET(decorator_list, i, val);
4740             }
4741             Py_CLEAR(tmp);
4742         }
4743         if (_PyObject_LookupAttrId(obj, &PyId_returns, &tmp) < 0) {
4744             return 1;
4745         }
4746         if (tmp == NULL || tmp == Py_None) {
4747             Py_CLEAR(tmp);
4748             returns = NULL;
4749         }
4750         else {
4751             int res;
4752             res = obj2ast_expr(tmp, &returns, arena);
4753             if (res != 0) goto failed;
4754             Py_CLEAR(tmp);
4755         }
4756         if (_PyObject_LookupAttrId(obj, &PyId_type_comment, &tmp) < 0) {
4757             return 1;
4758         }
4759         if (tmp == NULL || tmp == Py_None) {
4760             Py_CLEAR(tmp);
4761             type_comment = NULL;
4762         }
4763         else {
4764             int res;
4765             res = obj2ast_string(tmp, &type_comment, arena);
4766             if (res != 0) goto failed;
4767             Py_CLEAR(tmp);
4768         }
4769         *out = AsyncFunctionDef(name, args, body, decorator_list, returns,
4770                                 type_comment, lineno, col_offset, end_lineno,
4771                                 end_col_offset, arena);
4772         if (*out == NULL) goto failed;
4773         return 0;
4774     }
4775     isinstance = PyObject_IsInstance(obj, (PyObject*)ClassDef_type);
4776     if (isinstance == -1) {
4777         return 1;
4778     }
4779     if (isinstance) {
4780         identifier name;
4781         asdl_seq* bases;
4782         asdl_seq* keywords;
4783         asdl_seq* body;
4784         asdl_seq* decorator_list;
4785 
4786         if (_PyObject_LookupAttrId(obj, &PyId_name, &tmp) < 0) {
4787             return 1;
4788         }
4789         if (tmp == NULL) {
4790             PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef");
4791             return 1;
4792         }
4793         else {
4794             int res;
4795             res = obj2ast_identifier(tmp, &name, arena);
4796             if (res != 0) goto failed;
4797             Py_CLEAR(tmp);
4798         }
4799         if (_PyObject_LookupAttrId(obj, &PyId_bases, &tmp) < 0) {
4800             return 1;
4801         }
4802         if (tmp == NULL) {
4803             PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef");
4804             return 1;
4805         }
4806         else {
4807             int res;
4808             Py_ssize_t len;
4809             Py_ssize_t i;
4810             if (!PyList_Check(tmp)) {
4811                 PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4812                 goto failed;
4813             }
4814             len = PyList_GET_SIZE(tmp);
4815             bases = _Py_asdl_seq_new(len, arena);
4816             if (bases == NULL) goto failed;
4817             for (i = 0; i < len; i++) {
4818                 expr_ty val;
4819                 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
4820                 if (res != 0) goto failed;
4821                 if (len != PyList_GET_SIZE(tmp)) {
4822                     PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"bases\" changed size during iteration");
4823                     goto failed;
4824                 }
4825                 asdl_seq_SET(bases, i, val);
4826             }
4827             Py_CLEAR(tmp);
4828         }
4829         if (_PyObject_LookupAttrId(obj, &PyId_keywords, &tmp) < 0) {
4830             return 1;
4831         }
4832         if (tmp == NULL) {
4833             PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef");
4834             return 1;
4835         }
4836         else {
4837             int res;
4838             Py_ssize_t len;
4839             Py_ssize_t i;
4840             if (!PyList_Check(tmp)) {
4841                 PyErr_Format(PyExc_TypeError, "ClassDef field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4842                 goto failed;
4843             }
4844             len = PyList_GET_SIZE(tmp);
4845             keywords = _Py_asdl_seq_new(len, arena);
4846             if (keywords == NULL) goto failed;
4847             for (i = 0; i < len; i++) {
4848                 keyword_ty val;
4849                 res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &val, arena);
4850                 if (res != 0) goto failed;
4851                 if (len != PyList_GET_SIZE(tmp)) {
4852                     PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"keywords\" changed size during iteration");
4853                     goto failed;
4854                 }
4855                 asdl_seq_SET(keywords, i, val);
4856             }
4857             Py_CLEAR(tmp);
4858         }
4859         if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) {
4860             return 1;
4861         }
4862         if (tmp == NULL) {
4863             PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef");
4864             return 1;
4865         }
4866         else {
4867             int res;
4868             Py_ssize_t len;
4869             Py_ssize_t i;
4870             if (!PyList_Check(tmp)) {
4871                 PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4872                 goto failed;
4873             }
4874             len = PyList_GET_SIZE(tmp);
4875             body = _Py_asdl_seq_new(len, arena);
4876             if (body == NULL) goto failed;
4877             for (i = 0; i < len; i++) {
4878                 stmt_ty val;
4879                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
4880                 if (res != 0) goto failed;
4881                 if (len != PyList_GET_SIZE(tmp)) {
4882                     PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"body\" changed size during iteration");
4883                     goto failed;
4884                 }
4885                 asdl_seq_SET(body, i, val);
4886             }
4887             Py_CLEAR(tmp);
4888         }
4889         if (_PyObject_LookupAttrId(obj, &PyId_decorator_list, &tmp) < 0) {
4890             return 1;
4891         }
4892         if (tmp == NULL) {
4893             PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef");
4894             return 1;
4895         }
4896         else {
4897             int res;
4898             Py_ssize_t len;
4899             Py_ssize_t i;
4900             if (!PyList_Check(tmp)) {
4901                 PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4902                 goto failed;
4903             }
4904             len = PyList_GET_SIZE(tmp);
4905             decorator_list = _Py_asdl_seq_new(len, arena);
4906             if (decorator_list == NULL) goto failed;
4907             for (i = 0; i < len; i++) {
4908                 expr_ty val;
4909                 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
4910                 if (res != 0) goto failed;
4911                 if (len != PyList_GET_SIZE(tmp)) {
4912                     PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"decorator_list\" changed size during iteration");
4913                     goto failed;
4914                 }
4915                 asdl_seq_SET(decorator_list, i, val);
4916             }
4917             Py_CLEAR(tmp);
4918         }
4919         *out = ClassDef(name, bases, keywords, body, decorator_list, lineno,
4920                         col_offset, end_lineno, end_col_offset, arena);
4921         if (*out == NULL) goto failed;
4922         return 0;
4923     }
4924     isinstance = PyObject_IsInstance(obj, (PyObject*)Return_type);
4925     if (isinstance == -1) {
4926         return 1;
4927     }
4928     if (isinstance) {
4929         expr_ty value;
4930 
4931         if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) {
4932             return 1;
4933         }
4934         if (tmp == NULL || tmp == Py_None) {
4935             Py_CLEAR(tmp);
4936             value = NULL;
4937         }
4938         else {
4939             int res;
4940             res = obj2ast_expr(tmp, &value, arena);
4941             if (res != 0) goto failed;
4942             Py_CLEAR(tmp);
4943         }
4944         *out = Return(value, lineno, col_offset, end_lineno, end_col_offset,
4945                       arena);
4946         if (*out == NULL) goto failed;
4947         return 0;
4948     }
4949     isinstance = PyObject_IsInstance(obj, (PyObject*)Delete_type);
4950     if (isinstance == -1) {
4951         return 1;
4952     }
4953     if (isinstance) {
4954         asdl_seq* targets;
4955 
4956         if (_PyObject_LookupAttrId(obj, &PyId_targets, &tmp) < 0) {
4957             return 1;
4958         }
4959         if (tmp == NULL) {
4960             PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete");
4961             return 1;
4962         }
4963         else {
4964             int res;
4965             Py_ssize_t len;
4966             Py_ssize_t i;
4967             if (!PyList_Check(tmp)) {
4968                 PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4969                 goto failed;
4970             }
4971             len = PyList_GET_SIZE(tmp);
4972             targets = _Py_asdl_seq_new(len, arena);
4973             if (targets == NULL) goto failed;
4974             for (i = 0; i < len; i++) {
4975                 expr_ty val;
4976                 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
4977                 if (res != 0) goto failed;
4978                 if (len != PyList_GET_SIZE(tmp)) {
4979                     PyErr_SetString(PyExc_RuntimeError, "Delete field \"targets\" changed size during iteration");
4980                     goto failed;
4981                 }
4982                 asdl_seq_SET(targets, i, val);
4983             }
4984             Py_CLEAR(tmp);
4985         }
4986         *out = Delete(targets, lineno, col_offset, end_lineno, end_col_offset,
4987                       arena);
4988         if (*out == NULL) goto failed;
4989         return 0;
4990     }
4991     isinstance = PyObject_IsInstance(obj, (PyObject*)Assign_type);
4992     if (isinstance == -1) {
4993         return 1;
4994     }
4995     if (isinstance) {
4996         asdl_seq* targets;
4997         expr_ty value;
4998         string type_comment;
4999 
5000         if (_PyObject_LookupAttrId(obj, &PyId_targets, &tmp) < 0) {
5001             return 1;
5002         }
5003         if (tmp == NULL) {
5004             PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign");
5005             return 1;
5006         }
5007         else {
5008             int res;
5009             Py_ssize_t len;
5010             Py_ssize_t i;
5011             if (!PyList_Check(tmp)) {
5012                 PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5013                 goto failed;
5014             }
5015             len = PyList_GET_SIZE(tmp);
5016             targets = _Py_asdl_seq_new(len, arena);
5017             if (targets == NULL) goto failed;
5018             for (i = 0; i < len; i++) {
5019                 expr_ty val;
5020                 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
5021                 if (res != 0) goto failed;
5022                 if (len != PyList_GET_SIZE(tmp)) {
5023                     PyErr_SetString(PyExc_RuntimeError, "Assign field \"targets\" changed size during iteration");
5024                     goto failed;
5025                 }
5026                 asdl_seq_SET(targets, i, val);
5027             }
5028             Py_CLEAR(tmp);
5029         }
5030         if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) {
5031             return 1;
5032         }
5033         if (tmp == NULL) {
5034             PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign");
5035             return 1;
5036         }
5037         else {
5038             int res;
5039             res = obj2ast_expr(tmp, &value, arena);
5040             if (res != 0) goto failed;
5041             Py_CLEAR(tmp);
5042         }
5043         if (_PyObject_LookupAttrId(obj, &PyId_type_comment, &tmp) < 0) {
5044             return 1;
5045         }
5046         if (tmp == NULL || tmp == Py_None) {
5047             Py_CLEAR(tmp);
5048             type_comment = NULL;
5049         }
5050         else {
5051             int res;
5052             res = obj2ast_string(tmp, &type_comment, arena);
5053             if (res != 0) goto failed;
5054             Py_CLEAR(tmp);
5055         }
5056         *out = Assign(targets, value, type_comment, lineno, col_offset,
5057                       end_lineno, end_col_offset, arena);
5058         if (*out == NULL) goto failed;
5059         return 0;
5060     }
5061     isinstance = PyObject_IsInstance(obj, (PyObject*)AugAssign_type);
5062     if (isinstance == -1) {
5063         return 1;
5064     }
5065     if (isinstance) {
5066         expr_ty target;
5067         operator_ty op;
5068         expr_ty value;
5069 
5070         if (_PyObject_LookupAttrId(obj, &PyId_target, &tmp) < 0) {
5071             return 1;
5072         }
5073         if (tmp == NULL) {
5074             PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign");
5075             return 1;
5076         }
5077         else {
5078             int res;
5079             res = obj2ast_expr(tmp, &target, arena);
5080             if (res != 0) goto failed;
5081             Py_CLEAR(tmp);
5082         }
5083         if (_PyObject_LookupAttrId(obj, &PyId_op, &tmp) < 0) {
5084             return 1;
5085         }
5086         if (tmp == NULL) {
5087             PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign");
5088             return 1;
5089         }
5090         else {
5091             int res;
5092             res = obj2ast_operator(tmp, &op, arena);
5093             if (res != 0) goto failed;
5094             Py_CLEAR(tmp);
5095         }
5096         if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) {
5097             return 1;
5098         }
5099         if (tmp == NULL) {
5100             PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign");
5101             return 1;
5102         }
5103         else {
5104             int res;
5105             res = obj2ast_expr(tmp, &value, arena);
5106             if (res != 0) goto failed;
5107             Py_CLEAR(tmp);
5108         }
5109         *out = AugAssign(target, op, value, lineno, col_offset, end_lineno,
5110                          end_col_offset, arena);
5111         if (*out == NULL) goto failed;
5112         return 0;
5113     }
5114     isinstance = PyObject_IsInstance(obj, (PyObject*)AnnAssign_type);
5115     if (isinstance == -1) {
5116         return 1;
5117     }
5118     if (isinstance) {
5119         expr_ty target;
5120         expr_ty annotation;
5121         expr_ty value;
5122         int simple;
5123 
5124         if (_PyObject_LookupAttrId(obj, &PyId_target, &tmp) < 0) {
5125             return 1;
5126         }
5127         if (tmp == NULL) {
5128             PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AnnAssign");
5129             return 1;
5130         }
5131         else {
5132             int res;
5133             res = obj2ast_expr(tmp, &target, arena);
5134             if (res != 0) goto failed;
5135             Py_CLEAR(tmp);
5136         }
5137         if (_PyObject_LookupAttrId(obj, &PyId_annotation, &tmp) < 0) {
5138             return 1;
5139         }
5140         if (tmp == NULL) {
5141             PyErr_SetString(PyExc_TypeError, "required field \"annotation\" missing from AnnAssign");
5142             return 1;
5143         }
5144         else {
5145             int res;
5146             res = obj2ast_expr(tmp, &annotation, arena);
5147             if (res != 0) goto failed;
5148             Py_CLEAR(tmp);
5149         }
5150         if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) {
5151             return 1;
5152         }
5153         if (tmp == NULL || tmp == Py_None) {
5154             Py_CLEAR(tmp);
5155             value = NULL;
5156         }
5157         else {
5158             int res;
5159             res = obj2ast_expr(tmp, &value, arena);
5160             if (res != 0) goto failed;
5161             Py_CLEAR(tmp);
5162         }
5163         if (_PyObject_LookupAttrId(obj, &PyId_simple, &tmp) < 0) {
5164             return 1;
5165         }
5166         if (tmp == NULL) {
5167             PyErr_SetString(PyExc_TypeError, "required field \"simple\" missing from AnnAssign");
5168             return 1;
5169         }
5170         else {
5171             int res;
5172             res = obj2ast_int(tmp, &simple, arena);
5173             if (res != 0) goto failed;
5174             Py_CLEAR(tmp);
5175         }
5176         *out = AnnAssign(target, annotation, value, simple, lineno, col_offset,
5177                          end_lineno, end_col_offset, arena);
5178         if (*out == NULL) goto failed;
5179         return 0;
5180     }
5181     isinstance = PyObject_IsInstance(obj, (PyObject*)For_type);
5182     if (isinstance == -1) {
5183         return 1;
5184     }
5185     if (isinstance) {
5186         expr_ty target;
5187         expr_ty iter;
5188         asdl_seq* body;
5189         asdl_seq* orelse;
5190         string type_comment;
5191 
5192         if (_PyObject_LookupAttrId(obj, &PyId_target, &tmp) < 0) {
5193             return 1;
5194         }
5195         if (tmp == NULL) {
5196             PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For");
5197             return 1;
5198         }
5199         else {
5200             int res;
5201             res = obj2ast_expr(tmp, &target, arena);
5202             if (res != 0) goto failed;
5203             Py_CLEAR(tmp);
5204         }
5205         if (_PyObject_LookupAttrId(obj, &PyId_iter, &tmp) < 0) {
5206             return 1;
5207         }
5208         if (tmp == NULL) {
5209             PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For");
5210             return 1;
5211         }
5212         else {
5213             int res;
5214             res = obj2ast_expr(tmp, &iter, arena);
5215             if (res != 0) goto failed;
5216             Py_CLEAR(tmp);
5217         }
5218         if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) {
5219             return 1;
5220         }
5221         if (tmp == NULL) {
5222             PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For");
5223             return 1;
5224         }
5225         else {
5226             int res;
5227             Py_ssize_t len;
5228             Py_ssize_t i;
5229             if (!PyList_Check(tmp)) {
5230                 PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5231                 goto failed;
5232             }
5233             len = PyList_GET_SIZE(tmp);
5234             body = _Py_asdl_seq_new(len, arena);
5235             if (body == NULL) goto failed;
5236             for (i = 0; i < len; i++) {
5237                 stmt_ty val;
5238                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
5239                 if (res != 0) goto failed;
5240                 if (len != PyList_GET_SIZE(tmp)) {
5241                     PyErr_SetString(PyExc_RuntimeError, "For field \"body\" changed size during iteration");
5242                     goto failed;
5243                 }
5244                 asdl_seq_SET(body, i, val);
5245             }
5246             Py_CLEAR(tmp);
5247         }
5248         if (_PyObject_LookupAttrId(obj, &PyId_orelse, &tmp) < 0) {
5249             return 1;
5250         }
5251         if (tmp == NULL) {
5252             PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For");
5253             return 1;
5254         }
5255         else {
5256             int res;
5257             Py_ssize_t len;
5258             Py_ssize_t i;
5259             if (!PyList_Check(tmp)) {
5260                 PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5261                 goto failed;
5262             }
5263             len = PyList_GET_SIZE(tmp);
5264             orelse = _Py_asdl_seq_new(len, arena);
5265             if (orelse == NULL) goto failed;
5266             for (i = 0; i < len; i++) {
5267                 stmt_ty val;
5268                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
5269                 if (res != 0) goto failed;
5270                 if (len != PyList_GET_SIZE(tmp)) {
5271                     PyErr_SetString(PyExc_RuntimeError, "For field \"orelse\" changed size during iteration");
5272                     goto failed;
5273                 }
5274                 asdl_seq_SET(orelse, i, val);
5275             }
5276             Py_CLEAR(tmp);
5277         }
5278         if (_PyObject_LookupAttrId(obj, &PyId_type_comment, &tmp) < 0) {
5279             return 1;
5280         }
5281         if (tmp == NULL || tmp == Py_None) {
5282             Py_CLEAR(tmp);
5283             type_comment = NULL;
5284         }
5285         else {
5286             int res;
5287             res = obj2ast_string(tmp, &type_comment, arena);
5288             if (res != 0) goto failed;
5289             Py_CLEAR(tmp);
5290         }
5291         *out = For(target, iter, body, orelse, type_comment, lineno,
5292                    col_offset, end_lineno, end_col_offset, arena);
5293         if (*out == NULL) goto failed;
5294         return 0;
5295     }
5296     isinstance = PyObject_IsInstance(obj, (PyObject*)AsyncFor_type);
5297     if (isinstance == -1) {
5298         return 1;
5299     }
5300     if (isinstance) {
5301         expr_ty target;
5302         expr_ty iter;
5303         asdl_seq* body;
5304         asdl_seq* orelse;
5305         string type_comment;
5306 
5307         if (_PyObject_LookupAttrId(obj, &PyId_target, &tmp) < 0) {
5308             return 1;
5309         }
5310         if (tmp == NULL) {
5311             PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AsyncFor");
5312             return 1;
5313         }
5314         else {
5315             int res;
5316             res = obj2ast_expr(tmp, &target, arena);
5317             if (res != 0) goto failed;
5318             Py_CLEAR(tmp);
5319         }
5320         if (_PyObject_LookupAttrId(obj, &PyId_iter, &tmp) < 0) {
5321             return 1;
5322         }
5323         if (tmp == NULL) {
5324             PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from AsyncFor");
5325             return 1;
5326         }
5327         else {
5328             int res;
5329             res = obj2ast_expr(tmp, &iter, arena);
5330             if (res != 0) goto failed;
5331             Py_CLEAR(tmp);
5332         }
5333         if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) {
5334             return 1;
5335         }
5336         if (tmp == NULL) {
5337             PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFor");
5338             return 1;
5339         }
5340         else {
5341             int res;
5342             Py_ssize_t len;
5343             Py_ssize_t i;
5344             if (!PyList_Check(tmp)) {
5345                 PyErr_Format(PyExc_TypeError, "AsyncFor field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5346                 goto failed;
5347             }
5348             len = PyList_GET_SIZE(tmp);
5349             body = _Py_asdl_seq_new(len, arena);
5350             if (body == NULL) goto failed;
5351             for (i = 0; i < len; i++) {
5352                 stmt_ty val;
5353                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
5354                 if (res != 0) goto failed;
5355                 if (len != PyList_GET_SIZE(tmp)) {
5356                     PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"body\" changed size during iteration");
5357                     goto failed;
5358                 }
5359                 asdl_seq_SET(body, i, val);
5360             }
5361             Py_CLEAR(tmp);
5362         }
5363         if (_PyObject_LookupAttrId(obj, &PyId_orelse, &tmp) < 0) {
5364             return 1;
5365         }
5366         if (tmp == NULL) {
5367             PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from AsyncFor");
5368             return 1;
5369         }
5370         else {
5371             int res;
5372             Py_ssize_t len;
5373             Py_ssize_t i;
5374             if (!PyList_Check(tmp)) {
5375                 PyErr_Format(PyExc_TypeError, "AsyncFor field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5376                 goto failed;
5377             }
5378             len = PyList_GET_SIZE(tmp);
5379             orelse = _Py_asdl_seq_new(len, arena);
5380             if (orelse == NULL) goto failed;
5381             for (i = 0; i < len; i++) {
5382                 stmt_ty val;
5383                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
5384                 if (res != 0) goto failed;
5385                 if (len != PyList_GET_SIZE(tmp)) {
5386                     PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"orelse\" changed size during iteration");
5387                     goto failed;
5388                 }
5389                 asdl_seq_SET(orelse, i, val);
5390             }
5391             Py_CLEAR(tmp);
5392         }
5393         if (_PyObject_LookupAttrId(obj, &PyId_type_comment, &tmp) < 0) {
5394             return 1;
5395         }
5396         if (tmp == NULL || tmp == Py_None) {
5397             Py_CLEAR(tmp);
5398             type_comment = NULL;
5399         }
5400         else {
5401             int res;
5402             res = obj2ast_string(tmp, &type_comment, arena);
5403             if (res != 0) goto failed;
5404             Py_CLEAR(tmp);
5405         }
5406         *out = AsyncFor(target, iter, body, orelse, type_comment, lineno,
5407                         col_offset, end_lineno, end_col_offset, arena);
5408         if (*out == NULL) goto failed;
5409         return 0;
5410     }
5411     isinstance = PyObject_IsInstance(obj, (PyObject*)While_type);
5412     if (isinstance == -1) {
5413         return 1;
5414     }
5415     if (isinstance) {
5416         expr_ty test;
5417         asdl_seq* body;
5418         asdl_seq* orelse;
5419 
5420         if (_PyObject_LookupAttrId(obj, &PyId_test, &tmp) < 0) {
5421             return 1;
5422         }
5423         if (tmp == NULL) {
5424             PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While");
5425             return 1;
5426         }
5427         else {
5428             int res;
5429             res = obj2ast_expr(tmp, &test, arena);
5430             if (res != 0) goto failed;
5431             Py_CLEAR(tmp);
5432         }
5433         if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) {
5434             return 1;
5435         }
5436         if (tmp == NULL) {
5437             PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While");
5438             return 1;
5439         }
5440         else {
5441             int res;
5442             Py_ssize_t len;
5443             Py_ssize_t i;
5444             if (!PyList_Check(tmp)) {
5445                 PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5446                 goto failed;
5447             }
5448             len = PyList_GET_SIZE(tmp);
5449             body = _Py_asdl_seq_new(len, arena);
5450             if (body == NULL) goto failed;
5451             for (i = 0; i < len; i++) {
5452                 stmt_ty val;
5453                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
5454                 if (res != 0) goto failed;
5455                 if (len != PyList_GET_SIZE(tmp)) {
5456                     PyErr_SetString(PyExc_RuntimeError, "While field \"body\" changed size during iteration");
5457                     goto failed;
5458                 }
5459                 asdl_seq_SET(body, i, val);
5460             }
5461             Py_CLEAR(tmp);
5462         }
5463         if (_PyObject_LookupAttrId(obj, &PyId_orelse, &tmp) < 0) {
5464             return 1;
5465         }
5466         if (tmp == NULL) {
5467             PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While");
5468             return 1;
5469         }
5470         else {
5471             int res;
5472             Py_ssize_t len;
5473             Py_ssize_t i;
5474             if (!PyList_Check(tmp)) {
5475                 PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5476                 goto failed;
5477             }
5478             len = PyList_GET_SIZE(tmp);
5479             orelse = _Py_asdl_seq_new(len, arena);
5480             if (orelse == NULL) goto failed;
5481             for (i = 0; i < len; i++) {
5482                 stmt_ty val;
5483                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
5484                 if (res != 0) goto failed;
5485                 if (len != PyList_GET_SIZE(tmp)) {
5486                     PyErr_SetString(PyExc_RuntimeError, "While field \"orelse\" changed size during iteration");
5487                     goto failed;
5488                 }
5489                 asdl_seq_SET(orelse, i, val);
5490             }
5491             Py_CLEAR(tmp);
5492         }
5493         *out = While(test, body, orelse, lineno, col_offset, end_lineno,
5494                      end_col_offset, arena);
5495         if (*out == NULL) goto failed;
5496         return 0;
5497     }
5498     isinstance = PyObject_IsInstance(obj, (PyObject*)If_type);
5499     if (isinstance == -1) {
5500         return 1;
5501     }
5502     if (isinstance) {
5503         expr_ty test;
5504         asdl_seq* body;
5505         asdl_seq* orelse;
5506 
5507         if (_PyObject_LookupAttrId(obj, &PyId_test, &tmp) < 0) {
5508             return 1;
5509         }
5510         if (tmp == NULL) {
5511             PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If");
5512             return 1;
5513         }
5514         else {
5515             int res;
5516             res = obj2ast_expr(tmp, &test, arena);
5517             if (res != 0) goto failed;
5518             Py_CLEAR(tmp);
5519         }
5520         if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) {
5521             return 1;
5522         }
5523         if (tmp == NULL) {
5524             PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If");
5525             return 1;
5526         }
5527         else {
5528             int res;
5529             Py_ssize_t len;
5530             Py_ssize_t i;
5531             if (!PyList_Check(tmp)) {
5532                 PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5533                 goto failed;
5534             }
5535             len = PyList_GET_SIZE(tmp);
5536             body = _Py_asdl_seq_new(len, arena);
5537             if (body == NULL) goto failed;
5538             for (i = 0; i < len; i++) {
5539                 stmt_ty val;
5540                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
5541                 if (res != 0) goto failed;
5542                 if (len != PyList_GET_SIZE(tmp)) {
5543                     PyErr_SetString(PyExc_RuntimeError, "If field \"body\" changed size during iteration");
5544                     goto failed;
5545                 }
5546                 asdl_seq_SET(body, i, val);
5547             }
5548             Py_CLEAR(tmp);
5549         }
5550         if (_PyObject_LookupAttrId(obj, &PyId_orelse, &tmp) < 0) {
5551             return 1;
5552         }
5553         if (tmp == NULL) {
5554             PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If");
5555             return 1;
5556         }
5557         else {
5558             int res;
5559             Py_ssize_t len;
5560             Py_ssize_t i;
5561             if (!PyList_Check(tmp)) {
5562                 PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5563                 goto failed;
5564             }
5565             len = PyList_GET_SIZE(tmp);
5566             orelse = _Py_asdl_seq_new(len, arena);
5567             if (orelse == NULL) goto failed;
5568             for (i = 0; i < len; i++) {
5569                 stmt_ty val;
5570                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
5571                 if (res != 0) goto failed;
5572                 if (len != PyList_GET_SIZE(tmp)) {
5573                     PyErr_SetString(PyExc_RuntimeError, "If field \"orelse\" changed size during iteration");
5574                     goto failed;
5575                 }
5576                 asdl_seq_SET(orelse, i, val);
5577             }
5578             Py_CLEAR(tmp);
5579         }
5580         *out = If(test, body, orelse, lineno, col_offset, end_lineno,
5581                   end_col_offset, arena);
5582         if (*out == NULL) goto failed;
5583         return 0;
5584     }
5585     isinstance = PyObject_IsInstance(obj, (PyObject*)With_type);
5586     if (isinstance == -1) {
5587         return 1;
5588     }
5589     if (isinstance) {
5590         asdl_seq* items;
5591         asdl_seq* body;
5592         string type_comment;
5593 
5594         if (_PyObject_LookupAttrId(obj, &PyId_items, &tmp) < 0) {
5595             return 1;
5596         }
5597         if (tmp == NULL) {
5598             PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With");
5599             return 1;
5600         }
5601         else {
5602             int res;
5603             Py_ssize_t len;
5604             Py_ssize_t i;
5605             if (!PyList_Check(tmp)) {
5606                 PyErr_Format(PyExc_TypeError, "With field \"items\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5607                 goto failed;
5608             }
5609             len = PyList_GET_SIZE(tmp);
5610             items = _Py_asdl_seq_new(len, arena);
5611             if (items == NULL) goto failed;
5612             for (i = 0; i < len; i++) {
5613                 withitem_ty val;
5614                 res = obj2ast_withitem(PyList_GET_ITEM(tmp, i), &val, arena);
5615                 if (res != 0) goto failed;
5616                 if (len != PyList_GET_SIZE(tmp)) {
5617                     PyErr_SetString(PyExc_RuntimeError, "With field \"items\" changed size during iteration");
5618                     goto failed;
5619                 }
5620                 asdl_seq_SET(items, i, val);
5621             }
5622             Py_CLEAR(tmp);
5623         }
5624         if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) {
5625             return 1;
5626         }
5627         if (tmp == NULL) {
5628             PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With");
5629             return 1;
5630         }
5631         else {
5632             int res;
5633             Py_ssize_t len;
5634             Py_ssize_t i;
5635             if (!PyList_Check(tmp)) {
5636                 PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5637                 goto failed;
5638             }
5639             len = PyList_GET_SIZE(tmp);
5640             body = _Py_asdl_seq_new(len, arena);
5641             if (body == NULL) goto failed;
5642             for (i = 0; i < len; i++) {
5643                 stmt_ty val;
5644                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
5645                 if (res != 0) goto failed;
5646                 if (len != PyList_GET_SIZE(tmp)) {
5647                     PyErr_SetString(PyExc_RuntimeError, "With field \"body\" changed size during iteration");
5648                     goto failed;
5649                 }
5650                 asdl_seq_SET(body, i, val);
5651             }
5652             Py_CLEAR(tmp);
5653         }
5654         if (_PyObject_LookupAttrId(obj, &PyId_type_comment, &tmp) < 0) {
5655             return 1;
5656         }
5657         if (tmp == NULL || tmp == Py_None) {
5658             Py_CLEAR(tmp);
5659             type_comment = NULL;
5660         }
5661         else {
5662             int res;
5663             res = obj2ast_string(tmp, &type_comment, arena);
5664             if (res != 0) goto failed;
5665             Py_CLEAR(tmp);
5666         }
5667         *out = With(items, body, type_comment, lineno, col_offset, end_lineno,
5668                     end_col_offset, arena);
5669         if (*out == NULL) goto failed;
5670         return 0;
5671     }
5672     isinstance = PyObject_IsInstance(obj, (PyObject*)AsyncWith_type);
5673     if (isinstance == -1) {
5674         return 1;
5675     }
5676     if (isinstance) {
5677         asdl_seq* items;
5678         asdl_seq* body;
5679         string type_comment;
5680 
5681         if (_PyObject_LookupAttrId(obj, &PyId_items, &tmp) < 0) {
5682             return 1;
5683         }
5684         if (tmp == NULL) {
5685             PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from AsyncWith");
5686             return 1;
5687         }
5688         else {
5689             int res;
5690             Py_ssize_t len;
5691             Py_ssize_t i;
5692             if (!PyList_Check(tmp)) {
5693                 PyErr_Format(PyExc_TypeError, "AsyncWith field \"items\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5694                 goto failed;
5695             }
5696             len = PyList_GET_SIZE(tmp);
5697             items = _Py_asdl_seq_new(len, arena);
5698             if (items == NULL) goto failed;
5699             for (i = 0; i < len; i++) {
5700                 withitem_ty val;
5701                 res = obj2ast_withitem(PyList_GET_ITEM(tmp, i), &val, arena);
5702                 if (res != 0) goto failed;
5703                 if (len != PyList_GET_SIZE(tmp)) {
5704                     PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"items\" changed size during iteration");
5705                     goto failed;
5706                 }
5707                 asdl_seq_SET(items, i, val);
5708             }
5709             Py_CLEAR(tmp);
5710         }
5711         if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) {
5712             return 1;
5713         }
5714         if (tmp == NULL) {
5715             PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncWith");
5716             return 1;
5717         }
5718         else {
5719             int res;
5720             Py_ssize_t len;
5721             Py_ssize_t i;
5722             if (!PyList_Check(tmp)) {
5723                 PyErr_Format(PyExc_TypeError, "AsyncWith field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5724                 goto failed;
5725             }
5726             len = PyList_GET_SIZE(tmp);
5727             body = _Py_asdl_seq_new(len, arena);
5728             if (body == NULL) goto failed;
5729             for (i = 0; i < len; i++) {
5730                 stmt_ty val;
5731                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
5732                 if (res != 0) goto failed;
5733                 if (len != PyList_GET_SIZE(tmp)) {
5734                     PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"body\" changed size during iteration");
5735                     goto failed;
5736                 }
5737                 asdl_seq_SET(body, i, val);
5738             }
5739             Py_CLEAR(tmp);
5740         }
5741         if (_PyObject_LookupAttrId(obj, &PyId_type_comment, &tmp) < 0) {
5742             return 1;
5743         }
5744         if (tmp == NULL || tmp == Py_None) {
5745             Py_CLEAR(tmp);
5746             type_comment = NULL;
5747         }
5748         else {
5749             int res;
5750             res = obj2ast_string(tmp, &type_comment, arena);
5751             if (res != 0) goto failed;
5752             Py_CLEAR(tmp);
5753         }
5754         *out = AsyncWith(items, body, type_comment, lineno, col_offset,
5755                          end_lineno, end_col_offset, arena);
5756         if (*out == NULL) goto failed;
5757         return 0;
5758     }
5759     isinstance = PyObject_IsInstance(obj, (PyObject*)Raise_type);
5760     if (isinstance == -1) {
5761         return 1;
5762     }
5763     if (isinstance) {
5764         expr_ty exc;
5765         expr_ty cause;
5766 
5767         if (_PyObject_LookupAttrId(obj, &PyId_exc, &tmp) < 0) {
5768             return 1;
5769         }
5770         if (tmp == NULL || tmp == Py_None) {
5771             Py_CLEAR(tmp);
5772             exc = NULL;
5773         }
5774         else {
5775             int res;
5776             res = obj2ast_expr(tmp, &exc, arena);
5777             if (res != 0) goto failed;
5778             Py_CLEAR(tmp);
5779         }
5780         if (_PyObject_LookupAttrId(obj, &PyId_cause, &tmp) < 0) {
5781             return 1;
5782         }
5783         if (tmp == NULL || tmp == Py_None) {
5784             Py_CLEAR(tmp);
5785             cause = NULL;
5786         }
5787         else {
5788             int res;
5789             res = obj2ast_expr(tmp, &cause, arena);
5790             if (res != 0) goto failed;
5791             Py_CLEAR(tmp);
5792         }
5793         *out = Raise(exc, cause, lineno, col_offset, end_lineno,
5794                      end_col_offset, arena);
5795         if (*out == NULL) goto failed;
5796         return 0;
5797     }
5798     isinstance = PyObject_IsInstance(obj, (PyObject*)Try_type);
5799     if (isinstance == -1) {
5800         return 1;
5801     }
5802     if (isinstance) {
5803         asdl_seq* body;
5804         asdl_seq* handlers;
5805         asdl_seq* orelse;
5806         asdl_seq* finalbody;
5807 
5808         if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) {
5809             return 1;
5810         }
5811         if (tmp == NULL) {
5812             PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try");
5813             return 1;
5814         }
5815         else {
5816             int res;
5817             Py_ssize_t len;
5818             Py_ssize_t i;
5819             if (!PyList_Check(tmp)) {
5820                 PyErr_Format(PyExc_TypeError, "Try field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5821                 goto failed;
5822             }
5823             len = PyList_GET_SIZE(tmp);
5824             body = _Py_asdl_seq_new(len, arena);
5825             if (body == NULL) goto failed;
5826             for (i = 0; i < len; i++) {
5827                 stmt_ty val;
5828                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
5829                 if (res != 0) goto failed;
5830                 if (len != PyList_GET_SIZE(tmp)) {
5831                     PyErr_SetString(PyExc_RuntimeError, "Try field \"body\" changed size during iteration");
5832                     goto failed;
5833                 }
5834                 asdl_seq_SET(body, i, val);
5835             }
5836             Py_CLEAR(tmp);
5837         }
5838         if (_PyObject_LookupAttrId(obj, &PyId_handlers, &tmp) < 0) {
5839             return 1;
5840         }
5841         if (tmp == NULL) {
5842             PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try");
5843             return 1;
5844         }
5845         else {
5846             int res;
5847             Py_ssize_t len;
5848             Py_ssize_t i;
5849             if (!PyList_Check(tmp)) {
5850                 PyErr_Format(PyExc_TypeError, "Try field \"handlers\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5851                 goto failed;
5852             }
5853             len = PyList_GET_SIZE(tmp);
5854             handlers = _Py_asdl_seq_new(len, arena);
5855             if (handlers == NULL) goto failed;
5856             for (i = 0; i < len; i++) {
5857                 excepthandler_ty val;
5858                 res = obj2ast_excepthandler(PyList_GET_ITEM(tmp, i), &val, arena);
5859                 if (res != 0) goto failed;
5860                 if (len != PyList_GET_SIZE(tmp)) {
5861                     PyErr_SetString(PyExc_RuntimeError, "Try field \"handlers\" changed size during iteration");
5862                     goto failed;
5863                 }
5864                 asdl_seq_SET(handlers, i, val);
5865             }
5866             Py_CLEAR(tmp);
5867         }
5868         if (_PyObject_LookupAttrId(obj, &PyId_orelse, &tmp) < 0) {
5869             return 1;
5870         }
5871         if (tmp == NULL) {
5872             PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try");
5873             return 1;
5874         }
5875         else {
5876             int res;
5877             Py_ssize_t len;
5878             Py_ssize_t i;
5879             if (!PyList_Check(tmp)) {
5880                 PyErr_Format(PyExc_TypeError, "Try field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5881                 goto failed;
5882             }
5883             len = PyList_GET_SIZE(tmp);
5884             orelse = _Py_asdl_seq_new(len, arena);
5885             if (orelse == NULL) goto failed;
5886             for (i = 0; i < len; i++) {
5887                 stmt_ty val;
5888                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
5889                 if (res != 0) goto failed;
5890                 if (len != PyList_GET_SIZE(tmp)) {
5891                     PyErr_SetString(PyExc_RuntimeError, "Try field \"orelse\" changed size during iteration");
5892                     goto failed;
5893                 }
5894                 asdl_seq_SET(orelse, i, val);
5895             }
5896             Py_CLEAR(tmp);
5897         }
5898         if (_PyObject_LookupAttrId(obj, &PyId_finalbody, &tmp) < 0) {
5899             return 1;
5900         }
5901         if (tmp == NULL) {
5902             PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try");
5903             return 1;
5904         }
5905         else {
5906             int res;
5907             Py_ssize_t len;
5908             Py_ssize_t i;
5909             if (!PyList_Check(tmp)) {
5910                 PyErr_Format(PyExc_TypeError, "Try field \"finalbody\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5911                 goto failed;
5912             }
5913             len = PyList_GET_SIZE(tmp);
5914             finalbody = _Py_asdl_seq_new(len, arena);
5915             if (finalbody == NULL) goto failed;
5916             for (i = 0; i < len; i++) {
5917                 stmt_ty val;
5918                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
5919                 if (res != 0) goto failed;
5920                 if (len != PyList_GET_SIZE(tmp)) {
5921                     PyErr_SetString(PyExc_RuntimeError, "Try field \"finalbody\" changed size during iteration");
5922                     goto failed;
5923                 }
5924                 asdl_seq_SET(finalbody, i, val);
5925             }
5926             Py_CLEAR(tmp);
5927         }
5928         *out = Try(body, handlers, orelse, finalbody, lineno, col_offset,
5929                    end_lineno, end_col_offset, arena);
5930         if (*out == NULL) goto failed;
5931         return 0;
5932     }
5933     isinstance = PyObject_IsInstance(obj, (PyObject*)Assert_type);
5934     if (isinstance == -1) {
5935         return 1;
5936     }
5937     if (isinstance) {
5938         expr_ty test;
5939         expr_ty msg;
5940 
5941         if (_PyObject_LookupAttrId(obj, &PyId_test, &tmp) < 0) {
5942             return 1;
5943         }
5944         if (tmp == NULL) {
5945             PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert");
5946             return 1;
5947         }
5948         else {
5949             int res;
5950             res = obj2ast_expr(tmp, &test, arena);
5951             if (res != 0) goto failed;
5952             Py_CLEAR(tmp);
5953         }
5954         if (_PyObject_LookupAttrId(obj, &PyId_msg, &tmp) < 0) {
5955             return 1;
5956         }
5957         if (tmp == NULL || tmp == Py_None) {
5958             Py_CLEAR(tmp);
5959             msg = NULL;
5960         }
5961         else {
5962             int res;
5963             res = obj2ast_expr(tmp, &msg, arena);
5964             if (res != 0) goto failed;
5965             Py_CLEAR(tmp);
5966         }
5967         *out = Assert(test, msg, lineno, col_offset, end_lineno,
5968                       end_col_offset, arena);
5969         if (*out == NULL) goto failed;
5970         return 0;
5971     }
5972     isinstance = PyObject_IsInstance(obj, (PyObject*)Import_type);
5973     if (isinstance == -1) {
5974         return 1;
5975     }
5976     if (isinstance) {
5977         asdl_seq* names;
5978 
5979         if (_PyObject_LookupAttrId(obj, &PyId_names, &tmp) < 0) {
5980             return 1;
5981         }
5982         if (tmp == NULL) {
5983             PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import");
5984             return 1;
5985         }
5986         else {
5987             int res;
5988             Py_ssize_t len;
5989             Py_ssize_t i;
5990             if (!PyList_Check(tmp)) {
5991                 PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5992                 goto failed;
5993             }
5994             len = PyList_GET_SIZE(tmp);
5995             names = _Py_asdl_seq_new(len, arena);
5996             if (names == NULL) goto failed;
5997             for (i = 0; i < len; i++) {
5998                 alias_ty val;
5999                 res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &val, arena);
6000                 if (res != 0) goto failed;
6001                 if (len != PyList_GET_SIZE(tmp)) {
6002                     PyErr_SetString(PyExc_RuntimeError, "Import field \"names\" changed size during iteration");
6003                     goto failed;
6004                 }
6005                 asdl_seq_SET(names, i, val);
6006             }
6007             Py_CLEAR(tmp);
6008         }
6009         *out = Import(names, lineno, col_offset, end_lineno, end_col_offset,
6010                       arena);
6011         if (*out == NULL) goto failed;
6012         return 0;
6013     }
6014     isinstance = PyObject_IsInstance(obj, (PyObject*)ImportFrom_type);
6015     if (isinstance == -1) {
6016         return 1;
6017     }
6018     if (isinstance) {
6019         identifier module;
6020         asdl_seq* names;
6021         int level;
6022 
6023         if (_PyObject_LookupAttrId(obj, &PyId_module, &tmp) < 0) {
6024             return 1;
6025         }
6026         if (tmp == NULL || tmp == Py_None) {
6027             Py_CLEAR(tmp);
6028             module = NULL;
6029         }
6030         else {
6031             int res;
6032             res = obj2ast_identifier(tmp, &module, arena);
6033             if (res != 0) goto failed;
6034             Py_CLEAR(tmp);
6035         }
6036         if (_PyObject_LookupAttrId(obj, &PyId_names, &tmp) < 0) {
6037             return 1;
6038         }
6039         if (tmp == NULL) {
6040             PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom");
6041             return 1;
6042         }
6043         else {
6044             int res;
6045             Py_ssize_t len;
6046             Py_ssize_t i;
6047             if (!PyList_Check(tmp)) {
6048                 PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name);
6049                 goto failed;
6050             }
6051             len = PyList_GET_SIZE(tmp);
6052             names = _Py_asdl_seq_new(len, arena);
6053             if (names == NULL) goto failed;
6054             for (i = 0; i < len; i++) {
6055                 alias_ty val;
6056                 res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &val, arena);
6057                 if (res != 0) goto failed;
6058                 if (len != PyList_GET_SIZE(tmp)) {
6059                     PyErr_SetString(PyExc_RuntimeError, "ImportFrom field \"names\" changed size during iteration");
6060                     goto failed;
6061                 }
6062                 asdl_seq_SET(names, i, val);
6063             }
6064             Py_CLEAR(tmp);
6065         }
6066         if (_PyObject_LookupAttrId(obj, &PyId_level, &tmp) < 0) {
6067             return 1;
6068         }
6069         if (tmp == NULL || tmp == Py_None) {
6070             Py_CLEAR(tmp);
6071             level = 0;
6072         }
6073         else {
6074             int res;
6075             res = obj2ast_int(tmp, &level, arena);
6076             if (res != 0) goto failed;
6077             Py_CLEAR(tmp);
6078         }
6079         *out = ImportFrom(module, names, level, lineno, col_offset, end_lineno,
6080                           end_col_offset, arena);
6081         if (*out == NULL) goto failed;
6082         return 0;
6083     }
6084     isinstance = PyObject_IsInstance(obj, (PyObject*)Global_type);
6085     if (isinstance == -1) {
6086         return 1;
6087     }
6088     if (isinstance) {
6089         asdl_seq* names;
6090 
6091         if (_PyObject_LookupAttrId(obj, &PyId_names, &tmp) < 0) {
6092             return 1;
6093         }
6094         if (tmp == NULL) {
6095             PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global");
6096             return 1;
6097         }
6098         else {
6099             int res;
6100             Py_ssize_t len;
6101             Py_ssize_t i;
6102             if (!PyList_Check(tmp)) {
6103                 PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name);
6104                 goto failed;
6105             }
6106             len = PyList_GET_SIZE(tmp);
6107             names = _Py_asdl_seq_new(len, arena);
6108             if (names == NULL) goto failed;
6109             for (i = 0; i < len; i++) {
6110                 identifier val;
6111                 res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &val, arena);
6112                 if (res != 0) goto failed;
6113                 if (len != PyList_GET_SIZE(tmp)) {
6114                     PyErr_SetString(PyExc_RuntimeError, "Global field \"names\" changed size during iteration");
6115                     goto failed;
6116                 }
6117                 asdl_seq_SET(names, i, val);
6118             }
6119             Py_CLEAR(tmp);
6120         }
6121         *out = Global(names, lineno, col_offset, end_lineno, end_col_offset,
6122                       arena);
6123         if (*out == NULL) goto failed;
6124         return 0;
6125     }
6126     isinstance = PyObject_IsInstance(obj, (PyObject*)Nonlocal_type);
6127     if (isinstance == -1) {
6128         return 1;
6129     }
6130     if (isinstance) {
6131         asdl_seq* names;
6132 
6133         if (_PyObject_LookupAttrId(obj, &PyId_names, &tmp) < 0) {
6134             return 1;
6135         }
6136         if (tmp == NULL) {
6137             PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal");
6138             return 1;
6139         }
6140         else {
6141             int res;
6142             Py_ssize_t len;
6143             Py_ssize_t i;
6144             if (!PyList_Check(tmp)) {
6145                 PyErr_Format(PyExc_TypeError, "Nonlocal field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name);
6146                 goto failed;
6147             }
6148             len = PyList_GET_SIZE(tmp);
6149             names = _Py_asdl_seq_new(len, arena);
6150             if (names == NULL) goto failed;
6151             for (i = 0; i < len; i++) {
6152                 identifier val;
6153                 res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &val, arena);
6154                 if (res != 0) goto failed;
6155                 if (len != PyList_GET_SIZE(tmp)) {
6156                     PyErr_SetString(PyExc_RuntimeError, "Nonlocal field \"names\" changed size during iteration");
6157                     goto failed;
6158                 }
6159                 asdl_seq_SET(names, i, val);
6160             }
6161             Py_CLEAR(tmp);
6162         }
6163         *out = Nonlocal(names, lineno, col_offset, end_lineno, end_col_offset,
6164                         arena);
6165         if (*out == NULL) goto failed;
6166         return 0;
6167     }
6168     isinstance = PyObject_IsInstance(obj, (PyObject*)Expr_type);
6169     if (isinstance == -1) {
6170         return 1;
6171     }
6172     if (isinstance) {
6173         expr_ty value;
6174 
6175         if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) {
6176             return 1;
6177         }
6178         if (tmp == NULL) {
6179             PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr");
6180             return 1;
6181         }
6182         else {
6183             int res;
6184             res = obj2ast_expr(tmp, &value, arena);
6185             if (res != 0) goto failed;
6186             Py_CLEAR(tmp);
6187         }
6188         *out = Expr(value, lineno, col_offset, end_lineno, end_col_offset,
6189                     arena);
6190         if (*out == NULL) goto failed;
6191         return 0;
6192     }
6193     isinstance = PyObject_IsInstance(obj, (PyObject*)Pass_type);
6194     if (isinstance == -1) {
6195         return 1;
6196     }
6197     if (isinstance) {
6198 
6199         *out = Pass(lineno, col_offset, end_lineno, end_col_offset, arena);
6200         if (*out == NULL) goto failed;
6201         return 0;
6202     }
6203     isinstance = PyObject_IsInstance(obj, (PyObject*)Break_type);
6204     if (isinstance == -1) {
6205         return 1;
6206     }
6207     if (isinstance) {
6208 
6209         *out = Break(lineno, col_offset, end_lineno, end_col_offset, arena);
6210         if (*out == NULL) goto failed;
6211         return 0;
6212     }
6213     isinstance = PyObject_IsInstance(obj, (PyObject*)Continue_type);
6214     if (isinstance == -1) {
6215         return 1;
6216     }
6217     if (isinstance) {
6218 
6219         *out = Continue(lineno, col_offset, end_lineno, end_col_offset, arena);
6220         if (*out == NULL) goto failed;
6221         return 0;
6222     }
6223 
6224     PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj);
6225     failed:
6226     Py_XDECREF(tmp);
6227     return 1;
6228 }
6229 
6230 int
obj2ast_expr(PyObject * obj,expr_ty * out,PyArena * arena)6231 obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
6232 {
6233     int isinstance;
6234 
6235     PyObject *tmp = NULL;
6236     int lineno;
6237     int col_offset;
6238     int end_lineno;
6239     int end_col_offset;
6240 
6241     if (obj == Py_None) {
6242         *out = NULL;
6243         return 0;
6244     }
6245     if (_PyObject_LookupAttrId(obj, &PyId_lineno, &tmp) < 0) {
6246         return 1;
6247     }
6248     if (tmp == NULL) {
6249         PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr");
6250         return 1;
6251     }
6252     else {
6253         int res;
6254         res = obj2ast_int(tmp, &lineno, arena);
6255         if (res != 0) goto failed;
6256         Py_CLEAR(tmp);
6257     }
6258     if (_PyObject_LookupAttrId(obj, &PyId_col_offset, &tmp) < 0) {
6259         return 1;
6260     }
6261     if (tmp == NULL) {
6262         PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr");
6263         return 1;
6264     }
6265     else {
6266         int res;
6267         res = obj2ast_int(tmp, &col_offset, arena);
6268         if (res != 0) goto failed;
6269         Py_CLEAR(tmp);
6270     }
6271     if (_PyObject_LookupAttrId(obj, &PyId_end_lineno, &tmp) < 0) {
6272         return 1;
6273     }
6274     if (tmp == NULL || tmp == Py_None) {
6275         Py_CLEAR(tmp);
6276         end_lineno = 0;
6277     }
6278     else {
6279         int res;
6280         res = obj2ast_int(tmp, &end_lineno, arena);
6281         if (res != 0) goto failed;
6282         Py_CLEAR(tmp);
6283     }
6284     if (_PyObject_LookupAttrId(obj, &PyId_end_col_offset, &tmp) < 0) {
6285         return 1;
6286     }
6287     if (tmp == NULL || tmp == Py_None) {
6288         Py_CLEAR(tmp);
6289         end_col_offset = 0;
6290     }
6291     else {
6292         int res;
6293         res = obj2ast_int(tmp, &end_col_offset, arena);
6294         if (res != 0) goto failed;
6295         Py_CLEAR(tmp);
6296     }
6297     isinstance = PyObject_IsInstance(obj, (PyObject*)BoolOp_type);
6298     if (isinstance == -1) {
6299         return 1;
6300     }
6301     if (isinstance) {
6302         boolop_ty op;
6303         asdl_seq* values;
6304 
6305         if (_PyObject_LookupAttrId(obj, &PyId_op, &tmp) < 0) {
6306             return 1;
6307         }
6308         if (tmp == NULL) {
6309             PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp");
6310             return 1;
6311         }
6312         else {
6313             int res;
6314             res = obj2ast_boolop(tmp, &op, arena);
6315             if (res != 0) goto failed;
6316             Py_CLEAR(tmp);
6317         }
6318         if (_PyObject_LookupAttrId(obj, &PyId_values, &tmp) < 0) {
6319             return 1;
6320         }
6321         if (tmp == NULL) {
6322             PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp");
6323             return 1;
6324         }
6325         else {
6326             int res;
6327             Py_ssize_t len;
6328             Py_ssize_t i;
6329             if (!PyList_Check(tmp)) {
6330                 PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name);
6331                 goto failed;
6332             }
6333             len = PyList_GET_SIZE(tmp);
6334             values = _Py_asdl_seq_new(len, arena);
6335             if (values == NULL) goto failed;
6336             for (i = 0; i < len; i++) {
6337                 expr_ty val;
6338                 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
6339                 if (res != 0) goto failed;
6340                 if (len != PyList_GET_SIZE(tmp)) {
6341                     PyErr_SetString(PyExc_RuntimeError, "BoolOp field \"values\" changed size during iteration");
6342                     goto failed;
6343                 }
6344                 asdl_seq_SET(values, i, val);
6345             }
6346             Py_CLEAR(tmp);
6347         }
6348         *out = BoolOp(op, values, lineno, col_offset, end_lineno,
6349                       end_col_offset, arena);
6350         if (*out == NULL) goto failed;
6351         return 0;
6352     }
6353     isinstance = PyObject_IsInstance(obj, (PyObject*)NamedExpr_type);
6354     if (isinstance == -1) {
6355         return 1;
6356     }
6357     if (isinstance) {
6358         expr_ty target;
6359         expr_ty value;
6360 
6361         if (_PyObject_LookupAttrId(obj, &PyId_target, &tmp) < 0) {
6362             return 1;
6363         }
6364         if (tmp == NULL) {
6365             PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from NamedExpr");
6366             return 1;
6367         }
6368         else {
6369             int res;
6370             res = obj2ast_expr(tmp, &target, arena);
6371             if (res != 0) goto failed;
6372             Py_CLEAR(tmp);
6373         }
6374         if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) {
6375             return 1;
6376         }
6377         if (tmp == NULL) {
6378             PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NamedExpr");
6379             return 1;
6380         }
6381         else {
6382             int res;
6383             res = obj2ast_expr(tmp, &value, arena);
6384             if (res != 0) goto failed;
6385             Py_CLEAR(tmp);
6386         }
6387         *out = NamedExpr(target, value, lineno, col_offset, end_lineno,
6388                          end_col_offset, arena);
6389         if (*out == NULL) goto failed;
6390         return 0;
6391     }
6392     isinstance = PyObject_IsInstance(obj, (PyObject*)BinOp_type);
6393     if (isinstance == -1) {
6394         return 1;
6395     }
6396     if (isinstance) {
6397         expr_ty left;
6398         operator_ty op;
6399         expr_ty right;
6400 
6401         if (_PyObject_LookupAttrId(obj, &PyId_left, &tmp) < 0) {
6402             return 1;
6403         }
6404         if (tmp == NULL) {
6405             PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp");
6406             return 1;
6407         }
6408         else {
6409             int res;
6410             res = obj2ast_expr(tmp, &left, arena);
6411             if (res != 0) goto failed;
6412             Py_CLEAR(tmp);
6413         }
6414         if (_PyObject_LookupAttrId(obj, &PyId_op, &tmp) < 0) {
6415             return 1;
6416         }
6417         if (tmp == NULL) {
6418             PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp");
6419             return 1;
6420         }
6421         else {
6422             int res;
6423             res = obj2ast_operator(tmp, &op, arena);
6424             if (res != 0) goto failed;
6425             Py_CLEAR(tmp);
6426         }
6427         if (_PyObject_LookupAttrId(obj, &PyId_right, &tmp) < 0) {
6428             return 1;
6429         }
6430         if (tmp == NULL) {
6431             PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp");
6432             return 1;
6433         }
6434         else {
6435             int res;
6436             res = obj2ast_expr(tmp, &right, arena);
6437             if (res != 0) goto failed;
6438             Py_CLEAR(tmp);
6439         }
6440         *out = BinOp(left, op, right, lineno, col_offset, end_lineno,
6441                      end_col_offset, arena);
6442         if (*out == NULL) goto failed;
6443         return 0;
6444     }
6445     isinstance = PyObject_IsInstance(obj, (PyObject*)UnaryOp_type);
6446     if (isinstance == -1) {
6447         return 1;
6448     }
6449     if (isinstance) {
6450         unaryop_ty op;
6451         expr_ty operand;
6452 
6453         if (_PyObject_LookupAttrId(obj, &PyId_op, &tmp) < 0) {
6454             return 1;
6455         }
6456         if (tmp == NULL) {
6457             PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp");
6458             return 1;
6459         }
6460         else {
6461             int res;
6462             res = obj2ast_unaryop(tmp, &op, arena);
6463             if (res != 0) goto failed;
6464             Py_CLEAR(tmp);
6465         }
6466         if (_PyObject_LookupAttrId(obj, &PyId_operand, &tmp) < 0) {
6467             return 1;
6468         }
6469         if (tmp == NULL) {
6470             PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp");
6471             return 1;
6472         }
6473         else {
6474             int res;
6475             res = obj2ast_expr(tmp, &operand, arena);
6476             if (res != 0) goto failed;
6477             Py_CLEAR(tmp);
6478         }
6479         *out = UnaryOp(op, operand, lineno, col_offset, end_lineno,
6480                        end_col_offset, arena);
6481         if (*out == NULL) goto failed;
6482         return 0;
6483     }
6484     isinstance = PyObject_IsInstance(obj, (PyObject*)Lambda_type);
6485     if (isinstance == -1) {
6486         return 1;
6487     }
6488     if (isinstance) {
6489         arguments_ty args;
6490         expr_ty body;
6491 
6492         if (_PyObject_LookupAttrId(obj, &PyId_args, &tmp) < 0) {
6493             return 1;
6494         }
6495         if (tmp == NULL) {
6496             PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda");
6497             return 1;
6498         }
6499         else {
6500             int res;
6501             res = obj2ast_arguments(tmp, &args, arena);
6502             if (res != 0) goto failed;
6503             Py_CLEAR(tmp);
6504         }
6505         if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) {
6506             return 1;
6507         }
6508         if (tmp == NULL) {
6509             PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda");
6510             return 1;
6511         }
6512         else {
6513             int res;
6514             res = obj2ast_expr(tmp, &body, arena);
6515             if (res != 0) goto failed;
6516             Py_CLEAR(tmp);
6517         }
6518         *out = Lambda(args, body, lineno, col_offset, end_lineno,
6519                       end_col_offset, arena);
6520         if (*out == NULL) goto failed;
6521         return 0;
6522     }
6523     isinstance = PyObject_IsInstance(obj, (PyObject*)IfExp_type);
6524     if (isinstance == -1) {
6525         return 1;
6526     }
6527     if (isinstance) {
6528         expr_ty test;
6529         expr_ty body;
6530         expr_ty orelse;
6531 
6532         if (_PyObject_LookupAttrId(obj, &PyId_test, &tmp) < 0) {
6533             return 1;
6534         }
6535         if (tmp == NULL) {
6536             PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp");
6537             return 1;
6538         }
6539         else {
6540             int res;
6541             res = obj2ast_expr(tmp, &test, arena);
6542             if (res != 0) goto failed;
6543             Py_CLEAR(tmp);
6544         }
6545         if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) {
6546             return 1;
6547         }
6548         if (tmp == NULL) {
6549             PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp");
6550             return 1;
6551         }
6552         else {
6553             int res;
6554             res = obj2ast_expr(tmp, &body, arena);
6555             if (res != 0) goto failed;
6556             Py_CLEAR(tmp);
6557         }
6558         if (_PyObject_LookupAttrId(obj, &PyId_orelse, &tmp) < 0) {
6559             return 1;
6560         }
6561         if (tmp == NULL) {
6562             PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp");
6563             return 1;
6564         }
6565         else {
6566             int res;
6567             res = obj2ast_expr(tmp, &orelse, arena);
6568             if (res != 0) goto failed;
6569             Py_CLEAR(tmp);
6570         }
6571         *out = IfExp(test, body, orelse, lineno, col_offset, end_lineno,
6572                      end_col_offset, arena);
6573         if (*out == NULL) goto failed;
6574         return 0;
6575     }
6576     isinstance = PyObject_IsInstance(obj, (PyObject*)Dict_type);
6577     if (isinstance == -1) {
6578         return 1;
6579     }
6580     if (isinstance) {
6581         asdl_seq* keys;
6582         asdl_seq* values;
6583 
6584         if (_PyObject_LookupAttrId(obj, &PyId_keys, &tmp) < 0) {
6585             return 1;
6586         }
6587         if (tmp == NULL) {
6588             PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict");
6589             return 1;
6590         }
6591         else {
6592             int res;
6593             Py_ssize_t len;
6594             Py_ssize_t i;
6595             if (!PyList_Check(tmp)) {
6596                 PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", tmp->ob_type->tp_name);
6597                 goto failed;
6598             }
6599             len = PyList_GET_SIZE(tmp);
6600             keys = _Py_asdl_seq_new(len, arena);
6601             if (keys == NULL) goto failed;
6602             for (i = 0; i < len; i++) {
6603                 expr_ty val;
6604                 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
6605                 if (res != 0) goto failed;
6606                 if (len != PyList_GET_SIZE(tmp)) {
6607                     PyErr_SetString(PyExc_RuntimeError, "Dict field \"keys\" changed size during iteration");
6608                     goto failed;
6609                 }
6610                 asdl_seq_SET(keys, i, val);
6611             }
6612             Py_CLEAR(tmp);
6613         }
6614         if (_PyObject_LookupAttrId(obj, &PyId_values, &tmp) < 0) {
6615             return 1;
6616         }
6617         if (tmp == NULL) {
6618             PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict");
6619             return 1;
6620         }
6621         else {
6622             int res;
6623             Py_ssize_t len;
6624             Py_ssize_t i;
6625             if (!PyList_Check(tmp)) {
6626                 PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name);
6627                 goto failed;
6628             }
6629             len = PyList_GET_SIZE(tmp);
6630             values = _Py_asdl_seq_new(len, arena);
6631             if (values == NULL) goto failed;
6632             for (i = 0; i < len; i++) {
6633                 expr_ty val;
6634                 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
6635                 if (res != 0) goto failed;
6636                 if (len != PyList_GET_SIZE(tmp)) {
6637                     PyErr_SetString(PyExc_RuntimeError, "Dict field \"values\" changed size during iteration");
6638                     goto failed;
6639                 }
6640                 asdl_seq_SET(values, i, val);
6641             }
6642             Py_CLEAR(tmp);
6643         }
6644         *out = Dict(keys, values, lineno, col_offset, end_lineno,
6645                     end_col_offset, arena);
6646         if (*out == NULL) goto failed;
6647         return 0;
6648     }
6649     isinstance = PyObject_IsInstance(obj, (PyObject*)Set_type);
6650     if (isinstance == -1) {
6651         return 1;
6652     }
6653     if (isinstance) {
6654         asdl_seq* elts;
6655 
6656         if (_PyObject_LookupAttrId(obj, &PyId_elts, &tmp) < 0) {
6657             return 1;
6658         }
6659         if (tmp == NULL) {
6660             PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set");
6661             return 1;
6662         }
6663         else {
6664             int res;
6665             Py_ssize_t len;
6666             Py_ssize_t i;
6667             if (!PyList_Check(tmp)) {
6668                 PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name);
6669                 goto failed;
6670             }
6671             len = PyList_GET_SIZE(tmp);
6672             elts = _Py_asdl_seq_new(len, arena);
6673             if (elts == NULL) goto failed;
6674             for (i = 0; i < len; i++) {
6675                 expr_ty val;
6676                 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
6677                 if (res != 0) goto failed;
6678                 if (len != PyList_GET_SIZE(tmp)) {
6679                     PyErr_SetString(PyExc_RuntimeError, "Set field \"elts\" changed size during iteration");
6680                     goto failed;
6681                 }
6682                 asdl_seq_SET(elts, i, val);
6683             }
6684             Py_CLEAR(tmp);
6685         }
6686         *out = Set(elts, lineno, col_offset, end_lineno, end_col_offset, arena);
6687         if (*out == NULL) goto failed;
6688         return 0;
6689     }
6690     isinstance = PyObject_IsInstance(obj, (PyObject*)ListComp_type);
6691     if (isinstance == -1) {
6692         return 1;
6693     }
6694     if (isinstance) {
6695         expr_ty elt;
6696         asdl_seq* generators;
6697 
6698         if (_PyObject_LookupAttrId(obj, &PyId_elt, &tmp) < 0) {
6699             return 1;
6700         }
6701         if (tmp == NULL) {
6702             PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp");
6703             return 1;
6704         }
6705         else {
6706             int res;
6707             res = obj2ast_expr(tmp, &elt, arena);
6708             if (res != 0) goto failed;
6709             Py_CLEAR(tmp);
6710         }
6711         if (_PyObject_LookupAttrId(obj, &PyId_generators, &tmp) < 0) {
6712             return 1;
6713         }
6714         if (tmp == NULL) {
6715             PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp");
6716             return 1;
6717         }
6718         else {
6719             int res;
6720             Py_ssize_t len;
6721             Py_ssize_t i;
6722             if (!PyList_Check(tmp)) {
6723                 PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name);
6724                 goto failed;
6725             }
6726             len = PyList_GET_SIZE(tmp);
6727             generators = _Py_asdl_seq_new(len, arena);
6728             if (generators == NULL) goto failed;
6729             for (i = 0; i < len; i++) {
6730                 comprehension_ty val;
6731                 res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &val, arena);
6732                 if (res != 0) goto failed;
6733                 if (len != PyList_GET_SIZE(tmp)) {
6734                     PyErr_SetString(PyExc_RuntimeError, "ListComp field \"generators\" changed size during iteration");
6735                     goto failed;
6736                 }
6737                 asdl_seq_SET(generators, i, val);
6738             }
6739             Py_CLEAR(tmp);
6740         }
6741         *out = ListComp(elt, generators, lineno, col_offset, end_lineno,
6742                         end_col_offset, arena);
6743         if (*out == NULL) goto failed;
6744         return 0;
6745     }
6746     isinstance = PyObject_IsInstance(obj, (PyObject*)SetComp_type);
6747     if (isinstance == -1) {
6748         return 1;
6749     }
6750     if (isinstance) {
6751         expr_ty elt;
6752         asdl_seq* generators;
6753 
6754         if (_PyObject_LookupAttrId(obj, &PyId_elt, &tmp) < 0) {
6755             return 1;
6756         }
6757         if (tmp == NULL) {
6758             PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp");
6759             return 1;
6760         }
6761         else {
6762             int res;
6763             res = obj2ast_expr(tmp, &elt, arena);
6764             if (res != 0) goto failed;
6765             Py_CLEAR(tmp);
6766         }
6767         if (_PyObject_LookupAttrId(obj, &PyId_generators, &tmp) < 0) {
6768             return 1;
6769         }
6770         if (tmp == NULL) {
6771             PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp");
6772             return 1;
6773         }
6774         else {
6775             int res;
6776             Py_ssize_t len;
6777             Py_ssize_t i;
6778             if (!PyList_Check(tmp)) {
6779                 PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name);
6780                 goto failed;
6781             }
6782             len = PyList_GET_SIZE(tmp);
6783             generators = _Py_asdl_seq_new(len, arena);
6784             if (generators == NULL) goto failed;
6785             for (i = 0; i < len; i++) {
6786                 comprehension_ty val;
6787                 res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &val, arena);
6788                 if (res != 0) goto failed;
6789                 if (len != PyList_GET_SIZE(tmp)) {
6790                     PyErr_SetString(PyExc_RuntimeError, "SetComp field \"generators\" changed size during iteration");
6791                     goto failed;
6792                 }
6793                 asdl_seq_SET(generators, i, val);
6794             }
6795             Py_CLEAR(tmp);
6796         }
6797         *out = SetComp(elt, generators, lineno, col_offset, end_lineno,
6798                        end_col_offset, arena);
6799         if (*out == NULL) goto failed;
6800         return 0;
6801     }
6802     isinstance = PyObject_IsInstance(obj, (PyObject*)DictComp_type);
6803     if (isinstance == -1) {
6804         return 1;
6805     }
6806     if (isinstance) {
6807         expr_ty key;
6808         expr_ty value;
6809         asdl_seq* generators;
6810 
6811         if (_PyObject_LookupAttrId(obj, &PyId_key, &tmp) < 0) {
6812             return 1;
6813         }
6814         if (tmp == NULL) {
6815             PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp");
6816             return 1;
6817         }
6818         else {
6819             int res;
6820             res = obj2ast_expr(tmp, &key, arena);
6821             if (res != 0) goto failed;
6822             Py_CLEAR(tmp);
6823         }
6824         if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) {
6825             return 1;
6826         }
6827         if (tmp == NULL) {
6828             PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp");
6829             return 1;
6830         }
6831         else {
6832             int res;
6833             res = obj2ast_expr(tmp, &value, arena);
6834             if (res != 0) goto failed;
6835             Py_CLEAR(tmp);
6836         }
6837         if (_PyObject_LookupAttrId(obj, &PyId_generators, &tmp) < 0) {
6838             return 1;
6839         }
6840         if (tmp == NULL) {
6841             PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp");
6842             return 1;
6843         }
6844         else {
6845             int res;
6846             Py_ssize_t len;
6847             Py_ssize_t i;
6848             if (!PyList_Check(tmp)) {
6849                 PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name);
6850                 goto failed;
6851             }
6852             len = PyList_GET_SIZE(tmp);
6853             generators = _Py_asdl_seq_new(len, arena);
6854             if (generators == NULL) goto failed;
6855             for (i = 0; i < len; i++) {
6856                 comprehension_ty val;
6857                 res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &val, arena);
6858                 if (res != 0) goto failed;
6859                 if (len != PyList_GET_SIZE(tmp)) {
6860                     PyErr_SetString(PyExc_RuntimeError, "DictComp field \"generators\" changed size during iteration");
6861                     goto failed;
6862                 }
6863                 asdl_seq_SET(generators, i, val);
6864             }
6865             Py_CLEAR(tmp);
6866         }
6867         *out = DictComp(key, value, generators, lineno, col_offset, end_lineno,
6868                         end_col_offset, arena);
6869         if (*out == NULL) goto failed;
6870         return 0;
6871     }
6872     isinstance = PyObject_IsInstance(obj, (PyObject*)GeneratorExp_type);
6873     if (isinstance == -1) {
6874         return 1;
6875     }
6876     if (isinstance) {
6877         expr_ty elt;
6878         asdl_seq* generators;
6879 
6880         if (_PyObject_LookupAttrId(obj, &PyId_elt, &tmp) < 0) {
6881             return 1;
6882         }
6883         if (tmp == NULL) {
6884             PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp");
6885             return 1;
6886         }
6887         else {
6888             int res;
6889             res = obj2ast_expr(tmp, &elt, arena);
6890             if (res != 0) goto failed;
6891             Py_CLEAR(tmp);
6892         }
6893         if (_PyObject_LookupAttrId(obj, &PyId_generators, &tmp) < 0) {
6894             return 1;
6895         }
6896         if (tmp == NULL) {
6897             PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp");
6898             return 1;
6899         }
6900         else {
6901             int res;
6902             Py_ssize_t len;
6903             Py_ssize_t i;
6904             if (!PyList_Check(tmp)) {
6905                 PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name);
6906                 goto failed;
6907             }
6908             len = PyList_GET_SIZE(tmp);
6909             generators = _Py_asdl_seq_new(len, arena);
6910             if (generators == NULL) goto failed;
6911             for (i = 0; i < len; i++) {
6912                 comprehension_ty val;
6913                 res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &val, arena);
6914                 if (res != 0) goto failed;
6915                 if (len != PyList_GET_SIZE(tmp)) {
6916                     PyErr_SetString(PyExc_RuntimeError, "GeneratorExp field \"generators\" changed size during iteration");
6917                     goto failed;
6918                 }
6919                 asdl_seq_SET(generators, i, val);
6920             }
6921             Py_CLEAR(tmp);
6922         }
6923         *out = GeneratorExp(elt, generators, lineno, col_offset, end_lineno,
6924                             end_col_offset, arena);
6925         if (*out == NULL) goto failed;
6926         return 0;
6927     }
6928     isinstance = PyObject_IsInstance(obj, (PyObject*)Await_type);
6929     if (isinstance == -1) {
6930         return 1;
6931     }
6932     if (isinstance) {
6933         expr_ty value;
6934 
6935         if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) {
6936             return 1;
6937         }
6938         if (tmp == NULL) {
6939             PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Await");
6940             return 1;
6941         }
6942         else {
6943             int res;
6944             res = obj2ast_expr(tmp, &value, arena);
6945             if (res != 0) goto failed;
6946             Py_CLEAR(tmp);
6947         }
6948         *out = Await(value, lineno, col_offset, end_lineno, end_col_offset,
6949                      arena);
6950         if (*out == NULL) goto failed;
6951         return 0;
6952     }
6953     isinstance = PyObject_IsInstance(obj, (PyObject*)Yield_type);
6954     if (isinstance == -1) {
6955         return 1;
6956     }
6957     if (isinstance) {
6958         expr_ty value;
6959 
6960         if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) {
6961             return 1;
6962         }
6963         if (tmp == NULL || tmp == Py_None) {
6964             Py_CLEAR(tmp);
6965             value = NULL;
6966         }
6967         else {
6968             int res;
6969             res = obj2ast_expr(tmp, &value, arena);
6970             if (res != 0) goto failed;
6971             Py_CLEAR(tmp);
6972         }
6973         *out = Yield(value, lineno, col_offset, end_lineno, end_col_offset,
6974                      arena);
6975         if (*out == NULL) goto failed;
6976         return 0;
6977     }
6978     isinstance = PyObject_IsInstance(obj, (PyObject*)YieldFrom_type);
6979     if (isinstance == -1) {
6980         return 1;
6981     }
6982     if (isinstance) {
6983         expr_ty value;
6984 
6985         if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) {
6986             return 1;
6987         }
6988         if (tmp == NULL) {
6989             PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom");
6990             return 1;
6991         }
6992         else {
6993             int res;
6994             res = obj2ast_expr(tmp, &value, arena);
6995             if (res != 0) goto failed;
6996             Py_CLEAR(tmp);
6997         }
6998         *out = YieldFrom(value, lineno, col_offset, end_lineno, end_col_offset,
6999                          arena);
7000         if (*out == NULL) goto failed;
7001         return 0;
7002     }
7003     isinstance = PyObject_IsInstance(obj, (PyObject*)Compare_type);
7004     if (isinstance == -1) {
7005         return 1;
7006     }
7007     if (isinstance) {
7008         expr_ty left;
7009         asdl_int_seq* ops;
7010         asdl_seq* comparators;
7011 
7012         if (_PyObject_LookupAttrId(obj, &PyId_left, &tmp) < 0) {
7013             return 1;
7014         }
7015         if (tmp == NULL) {
7016             PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare");
7017             return 1;
7018         }
7019         else {
7020             int res;
7021             res = obj2ast_expr(tmp, &left, arena);
7022             if (res != 0) goto failed;
7023             Py_CLEAR(tmp);
7024         }
7025         if (_PyObject_LookupAttrId(obj, &PyId_ops, &tmp) < 0) {
7026             return 1;
7027         }
7028         if (tmp == NULL) {
7029             PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare");
7030             return 1;
7031         }
7032         else {
7033             int res;
7034             Py_ssize_t len;
7035             Py_ssize_t i;
7036             if (!PyList_Check(tmp)) {
7037                 PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", tmp->ob_type->tp_name);
7038                 goto failed;
7039             }
7040             len = PyList_GET_SIZE(tmp);
7041             ops = _Py_asdl_int_seq_new(len, arena);
7042             if (ops == NULL) goto failed;
7043             for (i = 0; i < len; i++) {
7044                 cmpop_ty val;
7045                 res = obj2ast_cmpop(PyList_GET_ITEM(tmp, i), &val, arena);
7046                 if (res != 0) goto failed;
7047                 if (len != PyList_GET_SIZE(tmp)) {
7048                     PyErr_SetString(PyExc_RuntimeError, "Compare field \"ops\" changed size during iteration");
7049                     goto failed;
7050                 }
7051                 asdl_seq_SET(ops, i, val);
7052             }
7053             Py_CLEAR(tmp);
7054         }
7055         if (_PyObject_LookupAttrId(obj, &PyId_comparators, &tmp) < 0) {
7056             return 1;
7057         }
7058         if (tmp == NULL) {
7059             PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare");
7060             return 1;
7061         }
7062         else {
7063             int res;
7064             Py_ssize_t len;
7065             Py_ssize_t i;
7066             if (!PyList_Check(tmp)) {
7067                 PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", tmp->ob_type->tp_name);
7068                 goto failed;
7069             }
7070             len = PyList_GET_SIZE(tmp);
7071             comparators = _Py_asdl_seq_new(len, arena);
7072             if (comparators == NULL) goto failed;
7073             for (i = 0; i < len; i++) {
7074                 expr_ty val;
7075                 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
7076                 if (res != 0) goto failed;
7077                 if (len != PyList_GET_SIZE(tmp)) {
7078                     PyErr_SetString(PyExc_RuntimeError, "Compare field \"comparators\" changed size during iteration");
7079                     goto failed;
7080                 }
7081                 asdl_seq_SET(comparators, i, val);
7082             }
7083             Py_CLEAR(tmp);
7084         }
7085         *out = Compare(left, ops, comparators, lineno, col_offset, end_lineno,
7086                        end_col_offset, arena);
7087         if (*out == NULL) goto failed;
7088         return 0;
7089     }
7090     isinstance = PyObject_IsInstance(obj, (PyObject*)Call_type);
7091     if (isinstance == -1) {
7092         return 1;
7093     }
7094     if (isinstance) {
7095         expr_ty func;
7096         asdl_seq* args;
7097         asdl_seq* keywords;
7098 
7099         if (_PyObject_LookupAttrId(obj, &PyId_func, &tmp) < 0) {
7100             return 1;
7101         }
7102         if (tmp == NULL) {
7103             PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call");
7104             return 1;
7105         }
7106         else {
7107             int res;
7108             res = obj2ast_expr(tmp, &func, arena);
7109             if (res != 0) goto failed;
7110             Py_CLEAR(tmp);
7111         }
7112         if (_PyObject_LookupAttrId(obj, &PyId_args, &tmp) < 0) {
7113             return 1;
7114         }
7115         if (tmp == NULL) {
7116             PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call");
7117             return 1;
7118         }
7119         else {
7120             int res;
7121             Py_ssize_t len;
7122             Py_ssize_t i;
7123             if (!PyList_Check(tmp)) {
7124                 PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name);
7125                 goto failed;
7126             }
7127             len = PyList_GET_SIZE(tmp);
7128             args = _Py_asdl_seq_new(len, arena);
7129             if (args == NULL) goto failed;
7130             for (i = 0; i < len; i++) {
7131                 expr_ty val;
7132                 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
7133                 if (res != 0) goto failed;
7134                 if (len != PyList_GET_SIZE(tmp)) {
7135                     PyErr_SetString(PyExc_RuntimeError, "Call field \"args\" changed size during iteration");
7136                     goto failed;
7137                 }
7138                 asdl_seq_SET(args, i, val);
7139             }
7140             Py_CLEAR(tmp);
7141         }
7142         if (_PyObject_LookupAttrId(obj, &PyId_keywords, &tmp) < 0) {
7143             return 1;
7144         }
7145         if (tmp == NULL) {
7146             PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call");
7147             return 1;
7148         }
7149         else {
7150             int res;
7151             Py_ssize_t len;
7152             Py_ssize_t i;
7153             if (!PyList_Check(tmp)) {
7154                 PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name);
7155                 goto failed;
7156             }
7157             len = PyList_GET_SIZE(tmp);
7158             keywords = _Py_asdl_seq_new(len, arena);
7159             if (keywords == NULL) goto failed;
7160             for (i = 0; i < len; i++) {
7161                 keyword_ty val;
7162                 res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &val, arena);
7163                 if (res != 0) goto failed;
7164                 if (len != PyList_GET_SIZE(tmp)) {
7165                     PyErr_SetString(PyExc_RuntimeError, "Call field \"keywords\" changed size during iteration");
7166                     goto failed;
7167                 }
7168                 asdl_seq_SET(keywords, i, val);
7169             }
7170             Py_CLEAR(tmp);
7171         }
7172         *out = Call(func, args, keywords, lineno, col_offset, end_lineno,
7173                     end_col_offset, arena);
7174         if (*out == NULL) goto failed;
7175         return 0;
7176     }
7177     isinstance = PyObject_IsInstance(obj, (PyObject*)FormattedValue_type);
7178     if (isinstance == -1) {
7179         return 1;
7180     }
7181     if (isinstance) {
7182         expr_ty value;
7183         int conversion;
7184         expr_ty format_spec;
7185 
7186         if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) {
7187             return 1;
7188         }
7189         if (tmp == NULL) {
7190             PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from FormattedValue");
7191             return 1;
7192         }
7193         else {
7194             int res;
7195             res = obj2ast_expr(tmp, &value, arena);
7196             if (res != 0) goto failed;
7197             Py_CLEAR(tmp);
7198         }
7199         if (_PyObject_LookupAttrId(obj, &PyId_conversion, &tmp) < 0) {
7200             return 1;
7201         }
7202         if (tmp == NULL || tmp == Py_None) {
7203             Py_CLEAR(tmp);
7204             conversion = 0;
7205         }
7206         else {
7207             int res;
7208             res = obj2ast_int(tmp, &conversion, arena);
7209             if (res != 0) goto failed;
7210             Py_CLEAR(tmp);
7211         }
7212         if (_PyObject_LookupAttrId(obj, &PyId_format_spec, &tmp) < 0) {
7213             return 1;
7214         }
7215         if (tmp == NULL || tmp == Py_None) {
7216             Py_CLEAR(tmp);
7217             format_spec = NULL;
7218         }
7219         else {
7220             int res;
7221             res = obj2ast_expr(tmp, &format_spec, arena);
7222             if (res != 0) goto failed;
7223             Py_CLEAR(tmp);
7224         }
7225         *out = FormattedValue(value, conversion, format_spec, lineno,
7226                               col_offset, end_lineno, end_col_offset, arena);
7227         if (*out == NULL) goto failed;
7228         return 0;
7229     }
7230     isinstance = PyObject_IsInstance(obj, (PyObject*)JoinedStr_type);
7231     if (isinstance == -1) {
7232         return 1;
7233     }
7234     if (isinstance) {
7235         asdl_seq* values;
7236 
7237         if (_PyObject_LookupAttrId(obj, &PyId_values, &tmp) < 0) {
7238             return 1;
7239         }
7240         if (tmp == NULL) {
7241             PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from JoinedStr");
7242             return 1;
7243         }
7244         else {
7245             int res;
7246             Py_ssize_t len;
7247             Py_ssize_t i;
7248             if (!PyList_Check(tmp)) {
7249                 PyErr_Format(PyExc_TypeError, "JoinedStr field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name);
7250                 goto failed;
7251             }
7252             len = PyList_GET_SIZE(tmp);
7253             values = _Py_asdl_seq_new(len, arena);
7254             if (values == NULL) goto failed;
7255             for (i = 0; i < len; i++) {
7256                 expr_ty val;
7257                 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
7258                 if (res != 0) goto failed;
7259                 if (len != PyList_GET_SIZE(tmp)) {
7260                     PyErr_SetString(PyExc_RuntimeError, "JoinedStr field \"values\" changed size during iteration");
7261                     goto failed;
7262                 }
7263                 asdl_seq_SET(values, i, val);
7264             }
7265             Py_CLEAR(tmp);
7266         }
7267         *out = JoinedStr(values, lineno, col_offset, end_lineno,
7268                          end_col_offset, arena);
7269         if (*out == NULL) goto failed;
7270         return 0;
7271     }
7272     isinstance = PyObject_IsInstance(obj, (PyObject*)Constant_type);
7273     if (isinstance == -1) {
7274         return 1;
7275     }
7276     if (isinstance) {
7277         constant value;
7278         string kind;
7279 
7280         if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) {
7281             return 1;
7282         }
7283         if (tmp == NULL) {
7284             PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Constant");
7285             return 1;
7286         }
7287         else {
7288             int res;
7289             res = obj2ast_constant(tmp, &value, arena);
7290             if (res != 0) goto failed;
7291             Py_CLEAR(tmp);
7292         }
7293         if (_PyObject_LookupAttrId(obj, &PyId_kind, &tmp) < 0) {
7294             return 1;
7295         }
7296         if (tmp == NULL || tmp == Py_None) {
7297             Py_CLEAR(tmp);
7298             kind = NULL;
7299         }
7300         else {
7301             int res;
7302             res = obj2ast_string(tmp, &kind, arena);
7303             if (res != 0) goto failed;
7304             Py_CLEAR(tmp);
7305         }
7306         *out = Constant(value, kind, lineno, col_offset, end_lineno,
7307                         end_col_offset, arena);
7308         if (*out == NULL) goto failed;
7309         return 0;
7310     }
7311     isinstance = PyObject_IsInstance(obj, (PyObject*)Attribute_type);
7312     if (isinstance == -1) {
7313         return 1;
7314     }
7315     if (isinstance) {
7316         expr_ty value;
7317         identifier attr;
7318         expr_context_ty ctx;
7319 
7320         if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) {
7321             return 1;
7322         }
7323         if (tmp == NULL) {
7324             PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute");
7325             return 1;
7326         }
7327         else {
7328             int res;
7329             res = obj2ast_expr(tmp, &value, arena);
7330             if (res != 0) goto failed;
7331             Py_CLEAR(tmp);
7332         }
7333         if (_PyObject_LookupAttrId(obj, &PyId_attr, &tmp) < 0) {
7334             return 1;
7335         }
7336         if (tmp == NULL) {
7337             PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute");
7338             return 1;
7339         }
7340         else {
7341             int res;
7342             res = obj2ast_identifier(tmp, &attr, arena);
7343             if (res != 0) goto failed;
7344             Py_CLEAR(tmp);
7345         }
7346         if (_PyObject_LookupAttrId(obj, &PyId_ctx, &tmp) < 0) {
7347             return 1;
7348         }
7349         if (tmp == NULL) {
7350             PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute");
7351             return 1;
7352         }
7353         else {
7354             int res;
7355             res = obj2ast_expr_context(tmp, &ctx, arena);
7356             if (res != 0) goto failed;
7357             Py_CLEAR(tmp);
7358         }
7359         *out = Attribute(value, attr, ctx, lineno, col_offset, end_lineno,
7360                          end_col_offset, arena);
7361         if (*out == NULL) goto failed;
7362         return 0;
7363     }
7364     isinstance = PyObject_IsInstance(obj, (PyObject*)Subscript_type);
7365     if (isinstance == -1) {
7366         return 1;
7367     }
7368     if (isinstance) {
7369         expr_ty value;
7370         slice_ty slice;
7371         expr_context_ty ctx;
7372 
7373         if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) {
7374             return 1;
7375         }
7376         if (tmp == NULL) {
7377             PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript");
7378             return 1;
7379         }
7380         else {
7381             int res;
7382             res = obj2ast_expr(tmp, &value, arena);
7383             if (res != 0) goto failed;
7384             Py_CLEAR(tmp);
7385         }
7386         if (_PyObject_LookupAttrId(obj, &PyId_slice, &tmp) < 0) {
7387             return 1;
7388         }
7389         if (tmp == NULL) {
7390             PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript");
7391             return 1;
7392         }
7393         else {
7394             int res;
7395             res = obj2ast_slice(tmp, &slice, arena);
7396             if (res != 0) goto failed;
7397             Py_CLEAR(tmp);
7398         }
7399         if (_PyObject_LookupAttrId(obj, &PyId_ctx, &tmp) < 0) {
7400             return 1;
7401         }
7402         if (tmp == NULL) {
7403             PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript");
7404             return 1;
7405         }
7406         else {
7407             int res;
7408             res = obj2ast_expr_context(tmp, &ctx, arena);
7409             if (res != 0) goto failed;
7410             Py_CLEAR(tmp);
7411         }
7412         *out = Subscript(value, slice, ctx, lineno, col_offset, end_lineno,
7413                          end_col_offset, arena);
7414         if (*out == NULL) goto failed;
7415         return 0;
7416     }
7417     isinstance = PyObject_IsInstance(obj, (PyObject*)Starred_type);
7418     if (isinstance == -1) {
7419         return 1;
7420     }
7421     if (isinstance) {
7422         expr_ty value;
7423         expr_context_ty ctx;
7424 
7425         if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) {
7426             return 1;
7427         }
7428         if (tmp == NULL) {
7429             PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred");
7430             return 1;
7431         }
7432         else {
7433             int res;
7434             res = obj2ast_expr(tmp, &value, arena);
7435             if (res != 0) goto failed;
7436             Py_CLEAR(tmp);
7437         }
7438         if (_PyObject_LookupAttrId(obj, &PyId_ctx, &tmp) < 0) {
7439             return 1;
7440         }
7441         if (tmp == NULL) {
7442             PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred");
7443             return 1;
7444         }
7445         else {
7446             int res;
7447             res = obj2ast_expr_context(tmp, &ctx, arena);
7448             if (res != 0) goto failed;
7449             Py_CLEAR(tmp);
7450         }
7451         *out = Starred(value, ctx, lineno, col_offset, end_lineno,
7452                        end_col_offset, arena);
7453         if (*out == NULL) goto failed;
7454         return 0;
7455     }
7456     isinstance = PyObject_IsInstance(obj, (PyObject*)Name_type);
7457     if (isinstance == -1) {
7458         return 1;
7459     }
7460     if (isinstance) {
7461         identifier id;
7462         expr_context_ty ctx;
7463 
7464         if (_PyObject_LookupAttrId(obj, &PyId_id, &tmp) < 0) {
7465             return 1;
7466         }
7467         if (tmp == NULL) {
7468             PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name");
7469             return 1;
7470         }
7471         else {
7472             int res;
7473             res = obj2ast_identifier(tmp, &id, arena);
7474             if (res != 0) goto failed;
7475             Py_CLEAR(tmp);
7476         }
7477         if (_PyObject_LookupAttrId(obj, &PyId_ctx, &tmp) < 0) {
7478             return 1;
7479         }
7480         if (tmp == NULL) {
7481             PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name");
7482             return 1;
7483         }
7484         else {
7485             int res;
7486             res = obj2ast_expr_context(tmp, &ctx, arena);
7487             if (res != 0) goto failed;
7488             Py_CLEAR(tmp);
7489         }
7490         *out = Name(id, ctx, lineno, col_offset, end_lineno, end_col_offset,
7491                     arena);
7492         if (*out == NULL) goto failed;
7493         return 0;
7494     }
7495     isinstance = PyObject_IsInstance(obj, (PyObject*)List_type);
7496     if (isinstance == -1) {
7497         return 1;
7498     }
7499     if (isinstance) {
7500         asdl_seq* elts;
7501         expr_context_ty ctx;
7502 
7503         if (_PyObject_LookupAttrId(obj, &PyId_elts, &tmp) < 0) {
7504             return 1;
7505         }
7506         if (tmp == NULL) {
7507             PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List");
7508             return 1;
7509         }
7510         else {
7511             int res;
7512             Py_ssize_t len;
7513             Py_ssize_t i;
7514             if (!PyList_Check(tmp)) {
7515                 PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name);
7516                 goto failed;
7517             }
7518             len = PyList_GET_SIZE(tmp);
7519             elts = _Py_asdl_seq_new(len, arena);
7520             if (elts == NULL) goto failed;
7521             for (i = 0; i < len; i++) {
7522                 expr_ty val;
7523                 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
7524                 if (res != 0) goto failed;
7525                 if (len != PyList_GET_SIZE(tmp)) {
7526                     PyErr_SetString(PyExc_RuntimeError, "List field \"elts\" changed size during iteration");
7527                     goto failed;
7528                 }
7529                 asdl_seq_SET(elts, i, val);
7530             }
7531             Py_CLEAR(tmp);
7532         }
7533         if (_PyObject_LookupAttrId(obj, &PyId_ctx, &tmp) < 0) {
7534             return 1;
7535         }
7536         if (tmp == NULL) {
7537             PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List");
7538             return 1;
7539         }
7540         else {
7541             int res;
7542             res = obj2ast_expr_context(tmp, &ctx, arena);
7543             if (res != 0) goto failed;
7544             Py_CLEAR(tmp);
7545         }
7546         *out = List(elts, ctx, lineno, col_offset, end_lineno, end_col_offset,
7547                     arena);
7548         if (*out == NULL) goto failed;
7549         return 0;
7550     }
7551     isinstance = PyObject_IsInstance(obj, (PyObject*)Tuple_type);
7552     if (isinstance == -1) {
7553         return 1;
7554     }
7555     if (isinstance) {
7556         asdl_seq* elts;
7557         expr_context_ty ctx;
7558 
7559         if (_PyObject_LookupAttrId(obj, &PyId_elts, &tmp) < 0) {
7560             return 1;
7561         }
7562         if (tmp == NULL) {
7563             PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple");
7564             return 1;
7565         }
7566         else {
7567             int res;
7568             Py_ssize_t len;
7569             Py_ssize_t i;
7570             if (!PyList_Check(tmp)) {
7571                 PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name);
7572                 goto failed;
7573             }
7574             len = PyList_GET_SIZE(tmp);
7575             elts = _Py_asdl_seq_new(len, arena);
7576             if (elts == NULL) goto failed;
7577             for (i = 0; i < len; i++) {
7578                 expr_ty val;
7579                 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
7580                 if (res != 0) goto failed;
7581                 if (len != PyList_GET_SIZE(tmp)) {
7582                     PyErr_SetString(PyExc_RuntimeError, "Tuple field \"elts\" changed size during iteration");
7583                     goto failed;
7584                 }
7585                 asdl_seq_SET(elts, i, val);
7586             }
7587             Py_CLEAR(tmp);
7588         }
7589         if (_PyObject_LookupAttrId(obj, &PyId_ctx, &tmp) < 0) {
7590             return 1;
7591         }
7592         if (tmp == NULL) {
7593             PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple");
7594             return 1;
7595         }
7596         else {
7597             int res;
7598             res = obj2ast_expr_context(tmp, &ctx, arena);
7599             if (res != 0) goto failed;
7600             Py_CLEAR(tmp);
7601         }
7602         *out = Tuple(elts, ctx, lineno, col_offset, end_lineno, end_col_offset,
7603                      arena);
7604         if (*out == NULL) goto failed;
7605         return 0;
7606     }
7607 
7608     PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj);
7609     failed:
7610     Py_XDECREF(tmp);
7611     return 1;
7612 }
7613 
7614 int
obj2ast_expr_context(PyObject * obj,expr_context_ty * out,PyArena * arena)7615 obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena)
7616 {
7617     int isinstance;
7618 
7619     isinstance = PyObject_IsInstance(obj, (PyObject *)Load_type);
7620     if (isinstance == -1) {
7621         return 1;
7622     }
7623     if (isinstance) {
7624         *out = Load;
7625         return 0;
7626     }
7627     isinstance = PyObject_IsInstance(obj, (PyObject *)Store_type);
7628     if (isinstance == -1) {
7629         return 1;
7630     }
7631     if (isinstance) {
7632         *out = Store;
7633         return 0;
7634     }
7635     isinstance = PyObject_IsInstance(obj, (PyObject *)Del_type);
7636     if (isinstance == -1) {
7637         return 1;
7638     }
7639     if (isinstance) {
7640         *out = Del;
7641         return 0;
7642     }
7643     isinstance = PyObject_IsInstance(obj, (PyObject *)AugLoad_type);
7644     if (isinstance == -1) {
7645         return 1;
7646     }
7647     if (isinstance) {
7648         *out = AugLoad;
7649         return 0;
7650     }
7651     isinstance = PyObject_IsInstance(obj, (PyObject *)AugStore_type);
7652     if (isinstance == -1) {
7653         return 1;
7654     }
7655     if (isinstance) {
7656         *out = AugStore;
7657         return 0;
7658     }
7659     isinstance = PyObject_IsInstance(obj, (PyObject *)Param_type);
7660     if (isinstance == -1) {
7661         return 1;
7662     }
7663     if (isinstance) {
7664         *out = Param;
7665         return 0;
7666     }
7667 
7668     PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj);
7669     return 1;
7670 }
7671 
7672 int
obj2ast_slice(PyObject * obj,slice_ty * out,PyArena * arena)7673 obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena)
7674 {
7675     int isinstance;
7676 
7677     PyObject *tmp = NULL;
7678 
7679     if (obj == Py_None) {
7680         *out = NULL;
7681         return 0;
7682     }
7683     isinstance = PyObject_IsInstance(obj, (PyObject*)Slice_type);
7684     if (isinstance == -1) {
7685         return 1;
7686     }
7687     if (isinstance) {
7688         expr_ty lower;
7689         expr_ty upper;
7690         expr_ty step;
7691 
7692         if (_PyObject_LookupAttrId(obj, &PyId_lower, &tmp) < 0) {
7693             return 1;
7694         }
7695         if (tmp == NULL || tmp == Py_None) {
7696             Py_CLEAR(tmp);
7697             lower = NULL;
7698         }
7699         else {
7700             int res;
7701             res = obj2ast_expr(tmp, &lower, arena);
7702             if (res != 0) goto failed;
7703             Py_CLEAR(tmp);
7704         }
7705         if (_PyObject_LookupAttrId(obj, &PyId_upper, &tmp) < 0) {
7706             return 1;
7707         }
7708         if (tmp == NULL || tmp == Py_None) {
7709             Py_CLEAR(tmp);
7710             upper = NULL;
7711         }
7712         else {
7713             int res;
7714             res = obj2ast_expr(tmp, &upper, arena);
7715             if (res != 0) goto failed;
7716             Py_CLEAR(tmp);
7717         }
7718         if (_PyObject_LookupAttrId(obj, &PyId_step, &tmp) < 0) {
7719             return 1;
7720         }
7721         if (tmp == NULL || tmp == Py_None) {
7722             Py_CLEAR(tmp);
7723             step = NULL;
7724         }
7725         else {
7726             int res;
7727             res = obj2ast_expr(tmp, &step, arena);
7728             if (res != 0) goto failed;
7729             Py_CLEAR(tmp);
7730         }
7731         *out = Slice(lower, upper, step, arena);
7732         if (*out == NULL) goto failed;
7733         return 0;
7734     }
7735     isinstance = PyObject_IsInstance(obj, (PyObject*)ExtSlice_type);
7736     if (isinstance == -1) {
7737         return 1;
7738     }
7739     if (isinstance) {
7740         asdl_seq* dims;
7741 
7742         if (_PyObject_LookupAttrId(obj, &PyId_dims, &tmp) < 0) {
7743             return 1;
7744         }
7745         if (tmp == NULL) {
7746             PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice");
7747             return 1;
7748         }
7749         else {
7750             int res;
7751             Py_ssize_t len;
7752             Py_ssize_t i;
7753             if (!PyList_Check(tmp)) {
7754                 PyErr_Format(PyExc_TypeError, "ExtSlice field \"dims\" must be a list, not a %.200s", tmp->ob_type->tp_name);
7755                 goto failed;
7756             }
7757             len = PyList_GET_SIZE(tmp);
7758             dims = _Py_asdl_seq_new(len, arena);
7759             if (dims == NULL) goto failed;
7760             for (i = 0; i < len; i++) {
7761                 slice_ty val;
7762                 res = obj2ast_slice(PyList_GET_ITEM(tmp, i), &val, arena);
7763                 if (res != 0) goto failed;
7764                 if (len != PyList_GET_SIZE(tmp)) {
7765                     PyErr_SetString(PyExc_RuntimeError, "ExtSlice field \"dims\" changed size during iteration");
7766                     goto failed;
7767                 }
7768                 asdl_seq_SET(dims, i, val);
7769             }
7770             Py_CLEAR(tmp);
7771         }
7772         *out = ExtSlice(dims, arena);
7773         if (*out == NULL) goto failed;
7774         return 0;
7775     }
7776     isinstance = PyObject_IsInstance(obj, (PyObject*)Index_type);
7777     if (isinstance == -1) {
7778         return 1;
7779     }
7780     if (isinstance) {
7781         expr_ty value;
7782 
7783         if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) {
7784             return 1;
7785         }
7786         if (tmp == NULL) {
7787             PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index");
7788             return 1;
7789         }
7790         else {
7791             int res;
7792             res = obj2ast_expr(tmp, &value, arena);
7793             if (res != 0) goto failed;
7794             Py_CLEAR(tmp);
7795         }
7796         *out = Index(value, arena);
7797         if (*out == NULL) goto failed;
7798         return 0;
7799     }
7800 
7801     PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %R", obj);
7802     failed:
7803     Py_XDECREF(tmp);
7804     return 1;
7805 }
7806 
7807 int
obj2ast_boolop(PyObject * obj,boolop_ty * out,PyArena * arena)7808 obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena)
7809 {
7810     int isinstance;
7811 
7812     isinstance = PyObject_IsInstance(obj, (PyObject *)And_type);
7813     if (isinstance == -1) {
7814         return 1;
7815     }
7816     if (isinstance) {
7817         *out = And;
7818         return 0;
7819     }
7820     isinstance = PyObject_IsInstance(obj, (PyObject *)Or_type);
7821     if (isinstance == -1) {
7822         return 1;
7823     }
7824     if (isinstance) {
7825         *out = Or;
7826         return 0;
7827     }
7828 
7829     PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj);
7830     return 1;
7831 }
7832 
7833 int
obj2ast_operator(PyObject * obj,operator_ty * out,PyArena * arena)7834 obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena)
7835 {
7836     int isinstance;
7837 
7838     isinstance = PyObject_IsInstance(obj, (PyObject *)Add_type);
7839     if (isinstance == -1) {
7840         return 1;
7841     }
7842     if (isinstance) {
7843         *out = Add;
7844         return 0;
7845     }
7846     isinstance = PyObject_IsInstance(obj, (PyObject *)Sub_type);
7847     if (isinstance == -1) {
7848         return 1;
7849     }
7850     if (isinstance) {
7851         *out = Sub;
7852         return 0;
7853     }
7854     isinstance = PyObject_IsInstance(obj, (PyObject *)Mult_type);
7855     if (isinstance == -1) {
7856         return 1;
7857     }
7858     if (isinstance) {
7859         *out = Mult;
7860         return 0;
7861     }
7862     isinstance = PyObject_IsInstance(obj, (PyObject *)MatMult_type);
7863     if (isinstance == -1) {
7864         return 1;
7865     }
7866     if (isinstance) {
7867         *out = MatMult;
7868         return 0;
7869     }
7870     isinstance = PyObject_IsInstance(obj, (PyObject *)Div_type);
7871     if (isinstance == -1) {
7872         return 1;
7873     }
7874     if (isinstance) {
7875         *out = Div;
7876         return 0;
7877     }
7878     isinstance = PyObject_IsInstance(obj, (PyObject *)Mod_type);
7879     if (isinstance == -1) {
7880         return 1;
7881     }
7882     if (isinstance) {
7883         *out = Mod;
7884         return 0;
7885     }
7886     isinstance = PyObject_IsInstance(obj, (PyObject *)Pow_type);
7887     if (isinstance == -1) {
7888         return 1;
7889     }
7890     if (isinstance) {
7891         *out = Pow;
7892         return 0;
7893     }
7894     isinstance = PyObject_IsInstance(obj, (PyObject *)LShift_type);
7895     if (isinstance == -1) {
7896         return 1;
7897     }
7898     if (isinstance) {
7899         *out = LShift;
7900         return 0;
7901     }
7902     isinstance = PyObject_IsInstance(obj, (PyObject *)RShift_type);
7903     if (isinstance == -1) {
7904         return 1;
7905     }
7906     if (isinstance) {
7907         *out = RShift;
7908         return 0;
7909     }
7910     isinstance = PyObject_IsInstance(obj, (PyObject *)BitOr_type);
7911     if (isinstance == -1) {
7912         return 1;
7913     }
7914     if (isinstance) {
7915         *out = BitOr;
7916         return 0;
7917     }
7918     isinstance = PyObject_IsInstance(obj, (PyObject *)BitXor_type);
7919     if (isinstance == -1) {
7920         return 1;
7921     }
7922     if (isinstance) {
7923         *out = BitXor;
7924         return 0;
7925     }
7926     isinstance = PyObject_IsInstance(obj, (PyObject *)BitAnd_type);
7927     if (isinstance == -1) {
7928         return 1;
7929     }
7930     if (isinstance) {
7931         *out = BitAnd;
7932         return 0;
7933     }
7934     isinstance = PyObject_IsInstance(obj, (PyObject *)FloorDiv_type);
7935     if (isinstance == -1) {
7936         return 1;
7937     }
7938     if (isinstance) {
7939         *out = FloorDiv;
7940         return 0;
7941     }
7942 
7943     PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj);
7944     return 1;
7945 }
7946 
7947 int
obj2ast_unaryop(PyObject * obj,unaryop_ty * out,PyArena * arena)7948 obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena)
7949 {
7950     int isinstance;
7951 
7952     isinstance = PyObject_IsInstance(obj, (PyObject *)Invert_type);
7953     if (isinstance == -1) {
7954         return 1;
7955     }
7956     if (isinstance) {
7957         *out = Invert;
7958         return 0;
7959     }
7960     isinstance = PyObject_IsInstance(obj, (PyObject *)Not_type);
7961     if (isinstance == -1) {
7962         return 1;
7963     }
7964     if (isinstance) {
7965         *out = Not;
7966         return 0;
7967     }
7968     isinstance = PyObject_IsInstance(obj, (PyObject *)UAdd_type);
7969     if (isinstance == -1) {
7970         return 1;
7971     }
7972     if (isinstance) {
7973         *out = UAdd;
7974         return 0;
7975     }
7976     isinstance = PyObject_IsInstance(obj, (PyObject *)USub_type);
7977     if (isinstance == -1) {
7978         return 1;
7979     }
7980     if (isinstance) {
7981         *out = USub;
7982         return 0;
7983     }
7984 
7985     PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj);
7986     return 1;
7987 }
7988 
7989 int
obj2ast_cmpop(PyObject * obj,cmpop_ty * out,PyArena * arena)7990 obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena)
7991 {
7992     int isinstance;
7993 
7994     isinstance = PyObject_IsInstance(obj, (PyObject *)Eq_type);
7995     if (isinstance == -1) {
7996         return 1;
7997     }
7998     if (isinstance) {
7999         *out = Eq;
8000         return 0;
8001     }
8002     isinstance = PyObject_IsInstance(obj, (PyObject *)NotEq_type);
8003     if (isinstance == -1) {
8004         return 1;
8005     }
8006     if (isinstance) {
8007         *out = NotEq;
8008         return 0;
8009     }
8010     isinstance = PyObject_IsInstance(obj, (PyObject *)Lt_type);
8011     if (isinstance == -1) {
8012         return 1;
8013     }
8014     if (isinstance) {
8015         *out = Lt;
8016         return 0;
8017     }
8018     isinstance = PyObject_IsInstance(obj, (PyObject *)LtE_type);
8019     if (isinstance == -1) {
8020         return 1;
8021     }
8022     if (isinstance) {
8023         *out = LtE;
8024         return 0;
8025     }
8026     isinstance = PyObject_IsInstance(obj, (PyObject *)Gt_type);
8027     if (isinstance == -1) {
8028         return 1;
8029     }
8030     if (isinstance) {
8031         *out = Gt;
8032         return 0;
8033     }
8034     isinstance = PyObject_IsInstance(obj, (PyObject *)GtE_type);
8035     if (isinstance == -1) {
8036         return 1;
8037     }
8038     if (isinstance) {
8039         *out = GtE;
8040         return 0;
8041     }
8042     isinstance = PyObject_IsInstance(obj, (PyObject *)Is_type);
8043     if (isinstance == -1) {
8044         return 1;
8045     }
8046     if (isinstance) {
8047         *out = Is;
8048         return 0;
8049     }
8050     isinstance = PyObject_IsInstance(obj, (PyObject *)IsNot_type);
8051     if (isinstance == -1) {
8052         return 1;
8053     }
8054     if (isinstance) {
8055         *out = IsNot;
8056         return 0;
8057     }
8058     isinstance = PyObject_IsInstance(obj, (PyObject *)In_type);
8059     if (isinstance == -1) {
8060         return 1;
8061     }
8062     if (isinstance) {
8063         *out = In;
8064         return 0;
8065     }
8066     isinstance = PyObject_IsInstance(obj, (PyObject *)NotIn_type);
8067     if (isinstance == -1) {
8068         return 1;
8069     }
8070     if (isinstance) {
8071         *out = NotIn;
8072         return 0;
8073     }
8074 
8075     PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj);
8076     return 1;
8077 }
8078 
8079 int
obj2ast_comprehension(PyObject * obj,comprehension_ty * out,PyArena * arena)8080 obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena)
8081 {
8082     PyObject* tmp = NULL;
8083     expr_ty target;
8084     expr_ty iter;
8085     asdl_seq* ifs;
8086     int is_async;
8087 
8088     if (_PyObject_LookupAttrId(obj, &PyId_target, &tmp) < 0) {
8089         return 1;
8090     }
8091     if (tmp == NULL) {
8092         PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension");
8093         return 1;
8094     }
8095     else {
8096         int res;
8097         res = obj2ast_expr(tmp, &target, arena);
8098         if (res != 0) goto failed;
8099         Py_CLEAR(tmp);
8100     }
8101     if (_PyObject_LookupAttrId(obj, &PyId_iter, &tmp) < 0) {
8102         return 1;
8103     }
8104     if (tmp == NULL) {
8105         PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension");
8106         return 1;
8107     }
8108     else {
8109         int res;
8110         res = obj2ast_expr(tmp, &iter, arena);
8111         if (res != 0) goto failed;
8112         Py_CLEAR(tmp);
8113     }
8114     if (_PyObject_LookupAttrId(obj, &PyId_ifs, &tmp) < 0) {
8115         return 1;
8116     }
8117     if (tmp == NULL) {
8118         PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension");
8119         return 1;
8120     }
8121     else {
8122         int res;
8123         Py_ssize_t len;
8124         Py_ssize_t i;
8125         if (!PyList_Check(tmp)) {
8126             PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", tmp->ob_type->tp_name);
8127             goto failed;
8128         }
8129         len = PyList_GET_SIZE(tmp);
8130         ifs = _Py_asdl_seq_new(len, arena);
8131         if (ifs == NULL) goto failed;
8132         for (i = 0; i < len; i++) {
8133             expr_ty val;
8134             res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
8135             if (res != 0) goto failed;
8136             if (len != PyList_GET_SIZE(tmp)) {
8137                 PyErr_SetString(PyExc_RuntimeError, "comprehension field \"ifs\" changed size during iteration");
8138                 goto failed;
8139             }
8140             asdl_seq_SET(ifs, i, val);
8141         }
8142         Py_CLEAR(tmp);
8143     }
8144     if (_PyObject_LookupAttrId(obj, &PyId_is_async, &tmp) < 0) {
8145         return 1;
8146     }
8147     if (tmp == NULL) {
8148         PyErr_SetString(PyExc_TypeError, "required field \"is_async\" missing from comprehension");
8149         return 1;
8150     }
8151     else {
8152         int res;
8153         res = obj2ast_int(tmp, &is_async, arena);
8154         if (res != 0) goto failed;
8155         Py_CLEAR(tmp);
8156     }
8157     *out = comprehension(target, iter, ifs, is_async, arena);
8158     return 0;
8159 failed:
8160     Py_XDECREF(tmp);
8161     return 1;
8162 }
8163 
8164 int
obj2ast_excepthandler(PyObject * obj,excepthandler_ty * out,PyArena * arena)8165 obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena)
8166 {
8167     int isinstance;
8168 
8169     PyObject *tmp = NULL;
8170     int lineno;
8171     int col_offset;
8172     int end_lineno;
8173     int end_col_offset;
8174 
8175     if (obj == Py_None) {
8176         *out = NULL;
8177         return 0;
8178     }
8179     if (_PyObject_LookupAttrId(obj, &PyId_lineno, &tmp) < 0) {
8180         return 1;
8181     }
8182     if (tmp == NULL) {
8183         PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler");
8184         return 1;
8185     }
8186     else {
8187         int res;
8188         res = obj2ast_int(tmp, &lineno, arena);
8189         if (res != 0) goto failed;
8190         Py_CLEAR(tmp);
8191     }
8192     if (_PyObject_LookupAttrId(obj, &PyId_col_offset, &tmp) < 0) {
8193         return 1;
8194     }
8195     if (tmp == NULL) {
8196         PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler");
8197         return 1;
8198     }
8199     else {
8200         int res;
8201         res = obj2ast_int(tmp, &col_offset, arena);
8202         if (res != 0) goto failed;
8203         Py_CLEAR(tmp);
8204     }
8205     if (_PyObject_LookupAttrId(obj, &PyId_end_lineno, &tmp) < 0) {
8206         return 1;
8207     }
8208     if (tmp == NULL || tmp == Py_None) {
8209         Py_CLEAR(tmp);
8210         end_lineno = 0;
8211     }
8212     else {
8213         int res;
8214         res = obj2ast_int(tmp, &end_lineno, arena);
8215         if (res != 0) goto failed;
8216         Py_CLEAR(tmp);
8217     }
8218     if (_PyObject_LookupAttrId(obj, &PyId_end_col_offset, &tmp) < 0) {
8219         return 1;
8220     }
8221     if (tmp == NULL || tmp == Py_None) {
8222         Py_CLEAR(tmp);
8223         end_col_offset = 0;
8224     }
8225     else {
8226         int res;
8227         res = obj2ast_int(tmp, &end_col_offset, arena);
8228         if (res != 0) goto failed;
8229         Py_CLEAR(tmp);
8230     }
8231     isinstance = PyObject_IsInstance(obj, (PyObject*)ExceptHandler_type);
8232     if (isinstance == -1) {
8233         return 1;
8234     }
8235     if (isinstance) {
8236         expr_ty type;
8237         identifier name;
8238         asdl_seq* body;
8239 
8240         if (_PyObject_LookupAttrId(obj, &PyId_type, &tmp) < 0) {
8241             return 1;
8242         }
8243         if (tmp == NULL || tmp == Py_None) {
8244             Py_CLEAR(tmp);
8245             type = NULL;
8246         }
8247         else {
8248             int res;
8249             res = obj2ast_expr(tmp, &type, arena);
8250             if (res != 0) goto failed;
8251             Py_CLEAR(tmp);
8252         }
8253         if (_PyObject_LookupAttrId(obj, &PyId_name, &tmp) < 0) {
8254             return 1;
8255         }
8256         if (tmp == NULL || tmp == Py_None) {
8257             Py_CLEAR(tmp);
8258             name = NULL;
8259         }
8260         else {
8261             int res;
8262             res = obj2ast_identifier(tmp, &name, arena);
8263             if (res != 0) goto failed;
8264             Py_CLEAR(tmp);
8265         }
8266         if (_PyObject_LookupAttrId(obj, &PyId_body, &tmp) < 0) {
8267             return 1;
8268         }
8269         if (tmp == NULL) {
8270             PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler");
8271             return 1;
8272         }
8273         else {
8274             int res;
8275             Py_ssize_t len;
8276             Py_ssize_t i;
8277             if (!PyList_Check(tmp)) {
8278                 PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
8279                 goto failed;
8280             }
8281             len = PyList_GET_SIZE(tmp);
8282             body = _Py_asdl_seq_new(len, arena);
8283             if (body == NULL) goto failed;
8284             for (i = 0; i < len; i++) {
8285                 stmt_ty val;
8286                 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &val, arena);
8287                 if (res != 0) goto failed;
8288                 if (len != PyList_GET_SIZE(tmp)) {
8289                     PyErr_SetString(PyExc_RuntimeError, "ExceptHandler field \"body\" changed size during iteration");
8290                     goto failed;
8291                 }
8292                 asdl_seq_SET(body, i, val);
8293             }
8294             Py_CLEAR(tmp);
8295         }
8296         *out = ExceptHandler(type, name, body, lineno, col_offset, end_lineno,
8297                              end_col_offset, arena);
8298         if (*out == NULL) goto failed;
8299         return 0;
8300     }
8301 
8302     PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj);
8303     failed:
8304     Py_XDECREF(tmp);
8305     return 1;
8306 }
8307 
8308 int
obj2ast_arguments(PyObject * obj,arguments_ty * out,PyArena * arena)8309 obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena)
8310 {
8311     PyObject* tmp = NULL;
8312     asdl_seq* posonlyargs;
8313     asdl_seq* args;
8314     arg_ty vararg;
8315     asdl_seq* kwonlyargs;
8316     asdl_seq* kw_defaults;
8317     arg_ty kwarg;
8318     asdl_seq* defaults;
8319 
8320     if (_PyObject_LookupAttrId(obj, &PyId_posonlyargs, &tmp) < 0) {
8321         return 1;
8322     }
8323     if (tmp == NULL) {
8324         PyErr_SetString(PyExc_TypeError, "required field \"posonlyargs\" missing from arguments");
8325         return 1;
8326     }
8327     else {
8328         int res;
8329         Py_ssize_t len;
8330         Py_ssize_t i;
8331         if (!PyList_Check(tmp)) {
8332             PyErr_Format(PyExc_TypeError, "arguments field \"posonlyargs\" must be a list, not a %.200s", tmp->ob_type->tp_name);
8333             goto failed;
8334         }
8335         len = PyList_GET_SIZE(tmp);
8336         posonlyargs = _Py_asdl_seq_new(len, arena);
8337         if (posonlyargs == NULL) goto failed;
8338         for (i = 0; i < len; i++) {
8339             arg_ty val;
8340             res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &val, arena);
8341             if (res != 0) goto failed;
8342             if (len != PyList_GET_SIZE(tmp)) {
8343                 PyErr_SetString(PyExc_RuntimeError, "arguments field \"posonlyargs\" changed size during iteration");
8344                 goto failed;
8345             }
8346             asdl_seq_SET(posonlyargs, i, val);
8347         }
8348         Py_CLEAR(tmp);
8349     }
8350     if (_PyObject_LookupAttrId(obj, &PyId_args, &tmp) < 0) {
8351         return 1;
8352     }
8353     if (tmp == NULL) {
8354         PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments");
8355         return 1;
8356     }
8357     else {
8358         int res;
8359         Py_ssize_t len;
8360         Py_ssize_t i;
8361         if (!PyList_Check(tmp)) {
8362             PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name);
8363             goto failed;
8364         }
8365         len = PyList_GET_SIZE(tmp);
8366         args = _Py_asdl_seq_new(len, arena);
8367         if (args == NULL) goto failed;
8368         for (i = 0; i < len; i++) {
8369             arg_ty val;
8370             res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &val, arena);
8371             if (res != 0) goto failed;
8372             if (len != PyList_GET_SIZE(tmp)) {
8373                 PyErr_SetString(PyExc_RuntimeError, "arguments field \"args\" changed size during iteration");
8374                 goto failed;
8375             }
8376             asdl_seq_SET(args, i, val);
8377         }
8378         Py_CLEAR(tmp);
8379     }
8380     if (_PyObject_LookupAttrId(obj, &PyId_vararg, &tmp) < 0) {
8381         return 1;
8382     }
8383     if (tmp == NULL || tmp == Py_None) {
8384         Py_CLEAR(tmp);
8385         vararg = NULL;
8386     }
8387     else {
8388         int res;
8389         res = obj2ast_arg(tmp, &vararg, arena);
8390         if (res != 0) goto failed;
8391         Py_CLEAR(tmp);
8392     }
8393     if (_PyObject_LookupAttrId(obj, &PyId_kwonlyargs, &tmp) < 0) {
8394         return 1;
8395     }
8396     if (tmp == NULL) {
8397         PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments");
8398         return 1;
8399     }
8400     else {
8401         int res;
8402         Py_ssize_t len;
8403         Py_ssize_t i;
8404         if (!PyList_Check(tmp)) {
8405             PyErr_Format(PyExc_TypeError, "arguments field \"kwonlyargs\" must be a list, not a %.200s", tmp->ob_type->tp_name);
8406             goto failed;
8407         }
8408         len = PyList_GET_SIZE(tmp);
8409         kwonlyargs = _Py_asdl_seq_new(len, arena);
8410         if (kwonlyargs == NULL) goto failed;
8411         for (i = 0; i < len; i++) {
8412             arg_ty val;
8413             res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &val, arena);
8414             if (res != 0) goto failed;
8415             if (len != PyList_GET_SIZE(tmp)) {
8416                 PyErr_SetString(PyExc_RuntimeError, "arguments field \"kwonlyargs\" changed size during iteration");
8417                 goto failed;
8418             }
8419             asdl_seq_SET(kwonlyargs, i, val);
8420         }
8421         Py_CLEAR(tmp);
8422     }
8423     if (_PyObject_LookupAttrId(obj, &PyId_kw_defaults, &tmp) < 0) {
8424         return 1;
8425     }
8426     if (tmp == NULL) {
8427         PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments");
8428         return 1;
8429     }
8430     else {
8431         int res;
8432         Py_ssize_t len;
8433         Py_ssize_t i;
8434         if (!PyList_Check(tmp)) {
8435             PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name);
8436             goto failed;
8437         }
8438         len = PyList_GET_SIZE(tmp);
8439         kw_defaults = _Py_asdl_seq_new(len, arena);
8440         if (kw_defaults == NULL) goto failed;
8441         for (i = 0; i < len; i++) {
8442             expr_ty val;
8443             res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
8444             if (res != 0) goto failed;
8445             if (len != PyList_GET_SIZE(tmp)) {
8446                 PyErr_SetString(PyExc_RuntimeError, "arguments field \"kw_defaults\" changed size during iteration");
8447                 goto failed;
8448             }
8449             asdl_seq_SET(kw_defaults, i, val);
8450         }
8451         Py_CLEAR(tmp);
8452     }
8453     if (_PyObject_LookupAttrId(obj, &PyId_kwarg, &tmp) < 0) {
8454         return 1;
8455     }
8456     if (tmp == NULL || tmp == Py_None) {
8457         Py_CLEAR(tmp);
8458         kwarg = NULL;
8459     }
8460     else {
8461         int res;
8462         res = obj2ast_arg(tmp, &kwarg, arena);
8463         if (res != 0) goto failed;
8464         Py_CLEAR(tmp);
8465     }
8466     if (_PyObject_LookupAttrId(obj, &PyId_defaults, &tmp) < 0) {
8467         return 1;
8468     }
8469     if (tmp == NULL) {
8470         PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments");
8471         return 1;
8472     }
8473     else {
8474         int res;
8475         Py_ssize_t len;
8476         Py_ssize_t i;
8477         if (!PyList_Check(tmp)) {
8478             PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name);
8479             goto failed;
8480         }
8481         len = PyList_GET_SIZE(tmp);
8482         defaults = _Py_asdl_seq_new(len, arena);
8483         if (defaults == NULL) goto failed;
8484         for (i = 0; i < len; i++) {
8485             expr_ty val;
8486             res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &val, arena);
8487             if (res != 0) goto failed;
8488             if (len != PyList_GET_SIZE(tmp)) {
8489                 PyErr_SetString(PyExc_RuntimeError, "arguments field \"defaults\" changed size during iteration");
8490                 goto failed;
8491             }
8492             asdl_seq_SET(defaults, i, val);
8493         }
8494         Py_CLEAR(tmp);
8495     }
8496     *out = arguments(posonlyargs, args, vararg, kwonlyargs, kw_defaults, kwarg,
8497                      defaults, arena);
8498     return 0;
8499 failed:
8500     Py_XDECREF(tmp);
8501     return 1;
8502 }
8503 
8504 int
obj2ast_arg(PyObject * obj,arg_ty * out,PyArena * arena)8505 obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena)
8506 {
8507     PyObject* tmp = NULL;
8508     identifier arg;
8509     expr_ty annotation;
8510     string type_comment;
8511     int lineno;
8512     int col_offset;
8513     int end_lineno;
8514     int end_col_offset;
8515 
8516     if (_PyObject_LookupAttrId(obj, &PyId_arg, &tmp) < 0) {
8517         return 1;
8518     }
8519     if (tmp == NULL) {
8520         PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg");
8521         return 1;
8522     }
8523     else {
8524         int res;
8525         res = obj2ast_identifier(tmp, &arg, arena);
8526         if (res != 0) goto failed;
8527         Py_CLEAR(tmp);
8528     }
8529     if (_PyObject_LookupAttrId(obj, &PyId_annotation, &tmp) < 0) {
8530         return 1;
8531     }
8532     if (tmp == NULL || tmp == Py_None) {
8533         Py_CLEAR(tmp);
8534         annotation = NULL;
8535     }
8536     else {
8537         int res;
8538         res = obj2ast_expr(tmp, &annotation, arena);
8539         if (res != 0) goto failed;
8540         Py_CLEAR(tmp);
8541     }
8542     if (_PyObject_LookupAttrId(obj, &PyId_type_comment, &tmp) < 0) {
8543         return 1;
8544     }
8545     if (tmp == NULL || tmp == Py_None) {
8546         Py_CLEAR(tmp);
8547         type_comment = NULL;
8548     }
8549     else {
8550         int res;
8551         res = obj2ast_string(tmp, &type_comment, arena);
8552         if (res != 0) goto failed;
8553         Py_CLEAR(tmp);
8554     }
8555     if (_PyObject_LookupAttrId(obj, &PyId_lineno, &tmp) < 0) {
8556         return 1;
8557     }
8558     if (tmp == NULL) {
8559         PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from arg");
8560         return 1;
8561     }
8562     else {
8563         int res;
8564         res = obj2ast_int(tmp, &lineno, arena);
8565         if (res != 0) goto failed;
8566         Py_CLEAR(tmp);
8567     }
8568     if (_PyObject_LookupAttrId(obj, &PyId_col_offset, &tmp) < 0) {
8569         return 1;
8570     }
8571     if (tmp == NULL) {
8572         PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from arg");
8573         return 1;
8574     }
8575     else {
8576         int res;
8577         res = obj2ast_int(tmp, &col_offset, arena);
8578         if (res != 0) goto failed;
8579         Py_CLEAR(tmp);
8580     }
8581     if (_PyObject_LookupAttrId(obj, &PyId_end_lineno, &tmp) < 0) {
8582         return 1;
8583     }
8584     if (tmp == NULL || tmp == Py_None) {
8585         Py_CLEAR(tmp);
8586         end_lineno = 0;
8587     }
8588     else {
8589         int res;
8590         res = obj2ast_int(tmp, &end_lineno, arena);
8591         if (res != 0) goto failed;
8592         Py_CLEAR(tmp);
8593     }
8594     if (_PyObject_LookupAttrId(obj, &PyId_end_col_offset, &tmp) < 0) {
8595         return 1;
8596     }
8597     if (tmp == NULL || tmp == Py_None) {
8598         Py_CLEAR(tmp);
8599         end_col_offset = 0;
8600     }
8601     else {
8602         int res;
8603         res = obj2ast_int(tmp, &end_col_offset, arena);
8604         if (res != 0) goto failed;
8605         Py_CLEAR(tmp);
8606     }
8607     *out = arg(arg, annotation, type_comment, lineno, col_offset, end_lineno,
8608                end_col_offset, arena);
8609     return 0;
8610 failed:
8611     Py_XDECREF(tmp);
8612     return 1;
8613 }
8614 
8615 int
obj2ast_keyword(PyObject * obj,keyword_ty * out,PyArena * arena)8616 obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena)
8617 {
8618     PyObject* tmp = NULL;
8619     identifier arg;
8620     expr_ty value;
8621 
8622     if (_PyObject_LookupAttrId(obj, &PyId_arg, &tmp) < 0) {
8623         return 1;
8624     }
8625     if (tmp == NULL || tmp == Py_None) {
8626         Py_CLEAR(tmp);
8627         arg = NULL;
8628     }
8629     else {
8630         int res;
8631         res = obj2ast_identifier(tmp, &arg, arena);
8632         if (res != 0) goto failed;
8633         Py_CLEAR(tmp);
8634     }
8635     if (_PyObject_LookupAttrId(obj, &PyId_value, &tmp) < 0) {
8636         return 1;
8637     }
8638     if (tmp == NULL) {
8639         PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword");
8640         return 1;
8641     }
8642     else {
8643         int res;
8644         res = obj2ast_expr(tmp, &value, arena);
8645         if (res != 0) goto failed;
8646         Py_CLEAR(tmp);
8647     }
8648     *out = keyword(arg, value, arena);
8649     return 0;
8650 failed:
8651     Py_XDECREF(tmp);
8652     return 1;
8653 }
8654 
8655 int
obj2ast_alias(PyObject * obj,alias_ty * out,PyArena * arena)8656 obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena)
8657 {
8658     PyObject* tmp = NULL;
8659     identifier name;
8660     identifier asname;
8661 
8662     if (_PyObject_LookupAttrId(obj, &PyId_name, &tmp) < 0) {
8663         return 1;
8664     }
8665     if (tmp == NULL) {
8666         PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias");
8667         return 1;
8668     }
8669     else {
8670         int res;
8671         res = obj2ast_identifier(tmp, &name, arena);
8672         if (res != 0) goto failed;
8673         Py_CLEAR(tmp);
8674     }
8675     if (_PyObject_LookupAttrId(obj, &PyId_asname, &tmp) < 0) {
8676         return 1;
8677     }
8678     if (tmp == NULL || tmp == Py_None) {
8679         Py_CLEAR(tmp);
8680         asname = NULL;
8681     }
8682     else {
8683         int res;
8684         res = obj2ast_identifier(tmp, &asname, arena);
8685         if (res != 0) goto failed;
8686         Py_CLEAR(tmp);
8687     }
8688     *out = alias(name, asname, arena);
8689     return 0;
8690 failed:
8691     Py_XDECREF(tmp);
8692     return 1;
8693 }
8694 
8695 int
obj2ast_withitem(PyObject * obj,withitem_ty * out,PyArena * arena)8696 obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena)
8697 {
8698     PyObject* tmp = NULL;
8699     expr_ty context_expr;
8700     expr_ty optional_vars;
8701 
8702     if (_PyObject_LookupAttrId(obj, &PyId_context_expr, &tmp) < 0) {
8703         return 1;
8704     }
8705     if (tmp == NULL) {
8706         PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem");
8707         return 1;
8708     }
8709     else {
8710         int res;
8711         res = obj2ast_expr(tmp, &context_expr, arena);
8712         if (res != 0) goto failed;
8713         Py_CLEAR(tmp);
8714     }
8715     if (_PyObject_LookupAttrId(obj, &PyId_optional_vars, &tmp) < 0) {
8716         return 1;
8717     }
8718     if (tmp == NULL || tmp == Py_None) {
8719         Py_CLEAR(tmp);
8720         optional_vars = NULL;
8721     }
8722     else {
8723         int res;
8724         res = obj2ast_expr(tmp, &optional_vars, arena);
8725         if (res != 0) goto failed;
8726         Py_CLEAR(tmp);
8727     }
8728     *out = withitem(context_expr, optional_vars, arena);
8729     return 0;
8730 failed:
8731     Py_XDECREF(tmp);
8732     return 1;
8733 }
8734 
8735 int
obj2ast_type_ignore(PyObject * obj,type_ignore_ty * out,PyArena * arena)8736 obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* arena)
8737 {
8738     int isinstance;
8739 
8740     PyObject *tmp = NULL;
8741 
8742     if (obj == Py_None) {
8743         *out = NULL;
8744         return 0;
8745     }
8746     isinstance = PyObject_IsInstance(obj, (PyObject*)TypeIgnore_type);
8747     if (isinstance == -1) {
8748         return 1;
8749     }
8750     if (isinstance) {
8751         int lineno;
8752         string tag;
8753 
8754         if (_PyObject_LookupAttrId(obj, &PyId_lineno, &tmp) < 0) {
8755             return 1;
8756         }
8757         if (tmp == NULL) {
8758             PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from TypeIgnore");
8759             return 1;
8760         }
8761         else {
8762             int res;
8763             res = obj2ast_int(tmp, &lineno, arena);
8764             if (res != 0) goto failed;
8765             Py_CLEAR(tmp);
8766         }
8767         if (_PyObject_LookupAttrId(obj, &PyId_tag, &tmp) < 0) {
8768             return 1;
8769         }
8770         if (tmp == NULL) {
8771             PyErr_SetString(PyExc_TypeError, "required field \"tag\" missing from TypeIgnore");
8772             return 1;
8773         }
8774         else {
8775             int res;
8776             res = obj2ast_string(tmp, &tag, arena);
8777             if (res != 0) goto failed;
8778             Py_CLEAR(tmp);
8779         }
8780         *out = TypeIgnore(lineno, tag, arena);
8781         if (*out == NULL) goto failed;
8782         return 0;
8783     }
8784 
8785     PyErr_Format(PyExc_TypeError, "expected some sort of type_ignore, but got %R", obj);
8786     failed:
8787     Py_XDECREF(tmp);
8788     return 1;
8789 }
8790 
8791 
8792 static struct PyModuleDef _astmodule = {
8793   PyModuleDef_HEAD_INIT, "_ast"
8794 };
8795 PyMODINIT_FUNC
PyInit__ast(void)8796 PyInit__ast(void)
8797 {
8798     PyObject *m, *d;
8799     if (!init_types()) return NULL;
8800     m = PyModule_Create(&_astmodule);
8801     if (!m) return NULL;
8802     d = PyModule_GetDict(m);
8803     if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return NULL;
8804     if (PyModule_AddIntMacro(m, PyCF_ALLOW_TOP_LEVEL_AWAIT) < 0)
8805         return NULL;
8806     if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0)
8807         return NULL;
8808     if (PyModule_AddIntMacro(m, PyCF_TYPE_COMMENTS) < 0)
8809         return NULL;
8810     if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return NULL;
8811     if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0) return
8812         NULL;
8813     if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type) <
8814         0) return NULL;
8815     if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) < 0)
8816         return NULL;
8817     if (PyDict_SetItemString(d, "FunctionType", (PyObject*)FunctionType_type) <
8818         0) return NULL;
8819     if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return
8820         NULL;
8821     if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return NULL;
8822     if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type) <
8823         0) return NULL;
8824     if (PyDict_SetItemString(d, "AsyncFunctionDef",
8825         (PyObject*)AsyncFunctionDef_type) < 0) return NULL;
8826     if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0)
8827         return NULL;
8828     if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0) return
8829         NULL;
8830     if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0) return
8831         NULL;
8832     if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0) return
8833         NULL;
8834     if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) < 0)
8835         return NULL;
8836     if (PyDict_SetItemString(d, "AnnAssign", (PyObject*)AnnAssign_type) < 0)
8837         return NULL;
8838     if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return NULL;
8839     if (PyDict_SetItemString(d, "AsyncFor", (PyObject*)AsyncFor_type) < 0)
8840         return NULL;
8841     if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return
8842         NULL;
8843     if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return NULL;
8844     if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return NULL;
8845     if (PyDict_SetItemString(d, "AsyncWith", (PyObject*)AsyncWith_type) < 0)
8846         return NULL;
8847     if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return
8848         NULL;
8849     if (PyDict_SetItemString(d, "Try", (PyObject*)Try_type) < 0) return NULL;
8850     if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0) return
8851         NULL;
8852     if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0) return
8853         NULL;
8854     if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) < 0)
8855         return NULL;
8856     if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0) return
8857         NULL;
8858     if (PyDict_SetItemString(d, "Nonlocal", (PyObject*)Nonlocal_type) < 0)
8859         return NULL;
8860     if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return NULL;
8861     if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return NULL;
8862     if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return
8863         NULL;
8864     if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0)
8865         return NULL;
8866     if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return NULL;
8867     if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0) return
8868         NULL;
8869     if (PyDict_SetItemString(d, "NamedExpr", (PyObject*)NamedExpr_type) < 0)
8870         return NULL;
8871     if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return
8872         NULL;
8873     if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0) return
8874         NULL;
8875     if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0) return
8876         NULL;
8877     if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return
8878         NULL;
8879     if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return NULL;
8880     if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return NULL;
8881     if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0)
8882         return NULL;
8883     if (PyDict_SetItemString(d, "SetComp", (PyObject*)SetComp_type) < 0) return
8884         NULL;
8885     if (PyDict_SetItemString(d, "DictComp", (PyObject*)DictComp_type) < 0)
8886         return NULL;
8887     if (PyDict_SetItemString(d, "GeneratorExp", (PyObject*)GeneratorExp_type) <
8888         0) return NULL;
8889     if (PyDict_SetItemString(d, "Await", (PyObject*)Await_type) < 0) return
8890         NULL;
8891     if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return
8892         NULL;
8893     if (PyDict_SetItemString(d, "YieldFrom", (PyObject*)YieldFrom_type) < 0)
8894         return NULL;
8895     if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0) return
8896         NULL;
8897     if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return NULL;
8898     if (PyDict_SetItemString(d, "FormattedValue",
8899         (PyObject*)FormattedValue_type) < 0) return NULL;
8900     if (PyDict_SetItemString(d, "JoinedStr", (PyObject*)JoinedStr_type) < 0)
8901         return NULL;
8902     if (PyDict_SetItemString(d, "Constant", (PyObject*)Constant_type) < 0)
8903         return NULL;
8904     if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) < 0)
8905         return NULL;
8906     if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) < 0)
8907         return NULL;
8908     if (PyDict_SetItemString(d, "Starred", (PyObject*)Starred_type) < 0) return
8909         NULL;
8910     if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return NULL;
8911     if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return NULL;
8912     if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return
8913         NULL;
8914     if (PyDict_SetItemString(d, "expr_context", (PyObject*)expr_context_type) <
8915         0) return NULL;
8916     if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return NULL;
8917     if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return
8918         NULL;
8919     if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return NULL;
8920     if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0) return
8921         NULL;
8922     if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0)
8923         return NULL;
8924     if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return
8925         NULL;
8926     if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return
8927         NULL;
8928     if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return
8929         NULL;
8930     if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0)
8931         return NULL;
8932     if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return
8933         NULL;
8934     if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0) return
8935         NULL;
8936     if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return NULL;
8937     if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return NULL;
8938     if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0)
8939         return NULL;
8940     if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return NULL;
8941     if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return NULL;
8942     if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return NULL;
8943     if (PyDict_SetItemString(d, "MatMult", (PyObject*)MatMult_type) < 0) return
8944         NULL;
8945     if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return NULL;
8946     if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return NULL;
8947     if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return NULL;
8948     if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0) return
8949         NULL;
8950     if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0) return
8951         NULL;
8952     if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return
8953         NULL;
8954     if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0) return
8955         NULL;
8956     if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0) return
8957         NULL;
8958     if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0)
8959         return NULL;
8960     if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0) return
8961         NULL;
8962     if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0) return
8963         NULL;
8964     if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return NULL;
8965     if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return NULL;
8966     if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return NULL;
8967     if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return
8968         NULL;
8969     if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return NULL;
8970     if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return
8971         NULL;
8972     if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return NULL;
8973     if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return NULL;
8974     if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return NULL;
8975     if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return NULL;
8976     if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return NULL;
8977     if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return
8978         NULL;
8979     if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return NULL;
8980     if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return
8981         NULL;
8982     if (PyDict_SetItemString(d, "comprehension", (PyObject*)comprehension_type)
8983         < 0) return NULL;
8984     if (PyDict_SetItemString(d, "excepthandler", (PyObject*)excepthandler_type)
8985         < 0) return NULL;
8986     if (PyDict_SetItemString(d, "ExceptHandler", (PyObject*)ExceptHandler_type)
8987         < 0) return NULL;
8988     if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) < 0)
8989         return NULL;
8990     if (PyDict_SetItemString(d, "arg", (PyObject*)arg_type) < 0) return NULL;
8991     if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0) return
8992         NULL;
8993     if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return
8994         NULL;
8995     if (PyDict_SetItemString(d, "withitem", (PyObject*)withitem_type) < 0)
8996         return NULL;
8997     if (PyDict_SetItemString(d, "type_ignore", (PyObject*)type_ignore_type) <
8998         0) return NULL;
8999     if (PyDict_SetItemString(d, "TypeIgnore", (PyObject*)TypeIgnore_type) < 0)
9000         return NULL;
9001     return m;
9002 }
9003 
9004 
PyAST_mod2obj(mod_ty t)9005 PyObject* PyAST_mod2obj(mod_ty t)
9006 {
9007     if (!init_types())
9008         return NULL;
9009     return ast2obj_mod(t);
9010 }
9011 
9012 /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */
PyAST_obj2mod(PyObject * ast,PyArena * arena,int mode)9013 mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode)
9014 {
9015     PyObject *req_type[3];
9016     char *req_name[] = {"Module", "Expression", "Interactive"};
9017     int isinstance;
9018 
9019     if (PySys_Audit("compile", "OO", ast, Py_None) < 0) {
9020         return NULL;
9021     }
9022 
9023     req_type[0] = (PyObject*)Module_type;
9024     req_type[1] = (PyObject*)Expression_type;
9025     req_type[2] = (PyObject*)Interactive_type;
9026 
9027     assert(0 <= mode && mode <= 2);
9028 
9029     if (!init_types())
9030         return NULL;
9031 
9032     isinstance = PyObject_IsInstance(ast, req_type[mode]);
9033     if (isinstance == -1)
9034         return NULL;
9035     if (!isinstance) {
9036         PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s",
9037                      req_name[mode], Py_TYPE(ast)->tp_name);
9038         return NULL;
9039     }
9040 
9041     mod_ty res = NULL;
9042     if (obj2ast_mod(ast, &res, arena) != 0)
9043         return NULL;
9044     else
9045         return res;
9046 }
9047 
PyAST_Check(PyObject * obj)9048 int PyAST_Check(PyObject* obj)
9049 {
9050     if (!init_types())
9051         return -1;
9052     return PyObject_IsInstance(obj, (PyObject*)&AST_type);
9053 }
9054 
9055 
9056