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