move sections
[python/dscho.git] / Python / Python-ast.c
blob701ac4881d3a49b92d37489cc352595eee004749
1 /* File automatically generated by Parser/asdl_c.py. */
4 /*
5 __version__ 82160.
7 This module must be committed separately after each AST grammar change;
8 The __version__ number is set to the revision number of the commit
9 containing the grammar change.
12 #include "Python.h"
13 #include "Python-ast.h"
15 static PyTypeObject AST_type;
16 static PyTypeObject *mod_type;
17 static PyObject* ast2obj_mod(void*);
18 static PyTypeObject *Module_type;
19 static char *Module_fields[]={
20 "body",
22 static PyTypeObject *Interactive_type;
23 static char *Interactive_fields[]={
24 "body",
26 static PyTypeObject *Expression_type;
27 static char *Expression_fields[]={
28 "body",
30 static PyTypeObject *Suite_type;
31 static char *Suite_fields[]={
32 "body",
34 static PyTypeObject *stmt_type;
35 static char *stmt_attributes[] = {
36 "lineno",
37 "col_offset",
39 static PyObject* ast2obj_stmt(void*);
40 static PyTypeObject *FunctionDef_type;
41 static char *FunctionDef_fields[]={
42 "name",
43 "args",
44 "body",
45 "decorator_list",
47 static PyTypeObject *ClassDef_type;
48 static char *ClassDef_fields[]={
49 "name",
50 "bases",
51 "body",
52 "decorator_list",
54 static PyTypeObject *Return_type;
55 static char *Return_fields[]={
56 "value",
58 static PyTypeObject *Delete_type;
59 static char *Delete_fields[]={
60 "targets",
62 static PyTypeObject *Assign_type;
63 static char *Assign_fields[]={
64 "targets",
65 "value",
67 static PyTypeObject *AugAssign_type;
68 static char *AugAssign_fields[]={
69 "target",
70 "op",
71 "value",
73 static PyTypeObject *Print_type;
74 static char *Print_fields[]={
75 "dest",
76 "values",
77 "nl",
79 static PyTypeObject *For_type;
80 static char *For_fields[]={
81 "target",
82 "iter",
83 "body",
84 "orelse",
86 static PyTypeObject *While_type;
87 static char *While_fields[]={
88 "test",
89 "body",
90 "orelse",
92 static PyTypeObject *If_type;
93 static char *If_fields[]={
94 "test",
95 "body",
96 "orelse",
98 static PyTypeObject *With_type;
99 static char *With_fields[]={
100 "context_expr",
101 "optional_vars",
102 "body",
104 static PyTypeObject *Raise_type;
105 static char *Raise_fields[]={
106 "type",
107 "inst",
108 "tback",
110 static PyTypeObject *TryExcept_type;
111 static char *TryExcept_fields[]={
112 "body",
113 "handlers",
114 "orelse",
116 static PyTypeObject *TryFinally_type;
117 static char *TryFinally_fields[]={
118 "body",
119 "finalbody",
121 static PyTypeObject *Assert_type;
122 static char *Assert_fields[]={
123 "test",
124 "msg",
126 static PyTypeObject *Import_type;
127 static char *Import_fields[]={
128 "names",
130 static PyTypeObject *ImportFrom_type;
131 static char *ImportFrom_fields[]={
132 "module",
133 "names",
134 "level",
136 static PyTypeObject *Exec_type;
137 static char *Exec_fields[]={
138 "body",
139 "globals",
140 "locals",
142 static PyTypeObject *Global_type;
143 static char *Global_fields[]={
144 "names",
146 static PyTypeObject *Expr_type;
147 static char *Expr_fields[]={
148 "value",
150 static PyTypeObject *Pass_type;
151 static PyTypeObject *Break_type;
152 static PyTypeObject *Continue_type;
153 static PyTypeObject *expr_type;
154 static char *expr_attributes[] = {
155 "lineno",
156 "col_offset",
158 static PyObject* ast2obj_expr(void*);
159 static PyTypeObject *BoolOp_type;
160 static char *BoolOp_fields[]={
161 "op",
162 "values",
164 static PyTypeObject *BinOp_type;
165 static char *BinOp_fields[]={
166 "left",
167 "op",
168 "right",
170 static PyTypeObject *UnaryOp_type;
171 static char *UnaryOp_fields[]={
172 "op",
173 "operand",
175 static PyTypeObject *Lambda_type;
176 static char *Lambda_fields[]={
177 "args",
178 "body",
180 static PyTypeObject *IfExp_type;
181 static char *IfExp_fields[]={
182 "test",
183 "body",
184 "orelse",
186 static PyTypeObject *Dict_type;
187 static char *Dict_fields[]={
188 "keys",
189 "values",
191 static PyTypeObject *Set_type;
192 static char *Set_fields[]={
193 "elts",
195 static PyTypeObject *ListComp_type;
196 static char *ListComp_fields[]={
197 "elt",
198 "generators",
200 static PyTypeObject *SetComp_type;
201 static char *SetComp_fields[]={
202 "elt",
203 "generators",
205 static PyTypeObject *DictComp_type;
206 static char *DictComp_fields[]={
207 "key",
208 "value",
209 "generators",
211 static PyTypeObject *GeneratorExp_type;
212 static char *GeneratorExp_fields[]={
213 "elt",
214 "generators",
216 static PyTypeObject *Yield_type;
217 static char *Yield_fields[]={
218 "value",
220 static PyTypeObject *Compare_type;
221 static char *Compare_fields[]={
222 "left",
223 "ops",
224 "comparators",
226 static PyTypeObject *Call_type;
227 static char *Call_fields[]={
228 "func",
229 "args",
230 "keywords",
231 "starargs",
232 "kwargs",
234 static PyTypeObject *Repr_type;
235 static char *Repr_fields[]={
236 "value",
238 static PyTypeObject *Num_type;
239 static char *Num_fields[]={
240 "n",
242 static PyTypeObject *Str_type;
243 static char *Str_fields[]={
244 "s",
246 static PyTypeObject *Attribute_type;
247 static char *Attribute_fields[]={
248 "value",
249 "attr",
250 "ctx",
252 static PyTypeObject *Subscript_type;
253 static char *Subscript_fields[]={
254 "value",
255 "slice",
256 "ctx",
258 static PyTypeObject *Name_type;
259 static char *Name_fields[]={
260 "id",
261 "ctx",
263 static PyTypeObject *List_type;
264 static char *List_fields[]={
265 "elts",
266 "ctx",
268 static PyTypeObject *Tuple_type;
269 static char *Tuple_fields[]={
270 "elts",
271 "ctx",
273 static PyTypeObject *expr_context_type;
274 static PyObject *Load_singleton, *Store_singleton, *Del_singleton,
275 *AugLoad_singleton, *AugStore_singleton, *Param_singleton;
276 static PyObject* ast2obj_expr_context(expr_context_ty);
277 static PyTypeObject *Load_type;
278 static PyTypeObject *Store_type;
279 static PyTypeObject *Del_type;
280 static PyTypeObject *AugLoad_type;
281 static PyTypeObject *AugStore_type;
282 static PyTypeObject *Param_type;
283 static PyTypeObject *slice_type;
284 static PyObject* ast2obj_slice(void*);
285 static PyTypeObject *Ellipsis_type;
286 static PyTypeObject *Slice_type;
287 static char *Slice_fields[]={
288 "lower",
289 "upper",
290 "step",
292 static PyTypeObject *ExtSlice_type;
293 static char *ExtSlice_fields[]={
294 "dims",
296 static PyTypeObject *Index_type;
297 static char *Index_fields[]={
298 "value",
300 static PyTypeObject *boolop_type;
301 static PyObject *And_singleton, *Or_singleton;
302 static PyObject* ast2obj_boolop(boolop_ty);
303 static PyTypeObject *And_type;
304 static PyTypeObject *Or_type;
305 static PyTypeObject *operator_type;
306 static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton,
307 *Div_singleton, *Mod_singleton, *Pow_singleton, *LShift_singleton,
308 *RShift_singleton, *BitOr_singleton, *BitXor_singleton, *BitAnd_singleton,
309 *FloorDiv_singleton;
310 static PyObject* ast2obj_operator(operator_ty);
311 static PyTypeObject *Add_type;
312 static PyTypeObject *Sub_type;
313 static PyTypeObject *Mult_type;
314 static PyTypeObject *Div_type;
315 static PyTypeObject *Mod_type;
316 static PyTypeObject *Pow_type;
317 static PyTypeObject *LShift_type;
318 static PyTypeObject *RShift_type;
319 static PyTypeObject *BitOr_type;
320 static PyTypeObject *BitXor_type;
321 static PyTypeObject *BitAnd_type;
322 static PyTypeObject *FloorDiv_type;
323 static PyTypeObject *unaryop_type;
324 static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton,
325 *USub_singleton;
326 static PyObject* ast2obj_unaryop(unaryop_ty);
327 static PyTypeObject *Invert_type;
328 static PyTypeObject *Not_type;
329 static PyTypeObject *UAdd_type;
330 static PyTypeObject *USub_type;
331 static PyTypeObject *cmpop_type;
332 static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton,
333 *Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton,
334 *NotIn_singleton;
335 static PyObject* ast2obj_cmpop(cmpop_ty);
336 static PyTypeObject *Eq_type;
337 static PyTypeObject *NotEq_type;
338 static PyTypeObject *Lt_type;
339 static PyTypeObject *LtE_type;
340 static PyTypeObject *Gt_type;
341 static PyTypeObject *GtE_type;
342 static PyTypeObject *Is_type;
343 static PyTypeObject *IsNot_type;
344 static PyTypeObject *In_type;
345 static PyTypeObject *NotIn_type;
346 static PyTypeObject *comprehension_type;
347 static PyObject* ast2obj_comprehension(void*);
348 static char *comprehension_fields[]={
349 "target",
350 "iter",
351 "ifs",
353 static PyTypeObject *excepthandler_type;
354 static char *excepthandler_attributes[] = {
355 "lineno",
356 "col_offset",
358 static PyObject* ast2obj_excepthandler(void*);
359 static PyTypeObject *ExceptHandler_type;
360 static char *ExceptHandler_fields[]={
361 "type",
362 "name",
363 "body",
365 static PyTypeObject *arguments_type;
366 static PyObject* ast2obj_arguments(void*);
367 static char *arguments_fields[]={
368 "args",
369 "vararg",
370 "kwarg",
371 "defaults",
373 static PyTypeObject *keyword_type;
374 static PyObject* ast2obj_keyword(void*);
375 static char *keyword_fields[]={
376 "arg",
377 "value",
379 static PyTypeObject *alias_type;
380 static PyObject* ast2obj_alias(void*);
381 static char *alias_fields[]={
382 "name",
383 "asname",
387 static int
388 ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
390 Py_ssize_t i, numfields = 0;
391 int res = -1;
392 PyObject *key, *value, *fields;
393 fields = PyObject_GetAttrString((PyObject*)Py_TYPE(self), "_fields");
394 if (!fields)
395 PyErr_Clear();
396 if (fields) {
397 numfields = PySequence_Size(fields);
398 if (numfields == -1)
399 goto cleanup;
401 res = 0; /* if no error occurs, this stays 0 to the end */
402 if (PyTuple_GET_SIZE(args) > 0) {
403 if (numfields != PyTuple_GET_SIZE(args)) {
404 PyErr_Format(PyExc_TypeError, "%.400s constructor takes %s"
405 "%zd positional argument%s",
406 Py_TYPE(self)->tp_name,
407 numfields == 0 ? "" : "either 0 or ",
408 numfields, numfields == 1 ? "" : "s");
409 res = -1;
410 goto cleanup;
412 for (i = 0; i < PyTuple_GET_SIZE(args); i++) {
413 /* cannot be reached when fields is NULL */
414 PyObject *name = PySequence_GetItem(fields, i);
415 if (!name) {
416 res = -1;
417 goto cleanup;
419 res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i));
420 Py_DECREF(name);
421 if (res < 0)
422 goto cleanup;
425 if (kw) {
426 i = 0; /* needed by PyDict_Next */
427 while (PyDict_Next(kw, &i, &key, &value)) {
428 res = PyObject_SetAttr(self, key, value);
429 if (res < 0)
430 goto cleanup;
433 cleanup:
434 Py_XDECREF(fields);
435 return res;
438 /* Pickling support */
439 static PyObject *
440 ast_type_reduce(PyObject *self, PyObject *unused)
442 PyObject *res;
443 PyObject *dict = PyObject_GetAttrString(self, "__dict__");
444 if (dict == NULL) {
445 if (PyErr_ExceptionMatches(PyExc_AttributeError))
446 PyErr_Clear();
447 else
448 return NULL;
450 if (dict) {
451 res = Py_BuildValue("O()O", Py_TYPE(self), dict);
452 Py_DECREF(dict);
453 return res;
455 return Py_BuildValue("O()", Py_TYPE(self));
458 static PyMethodDef ast_type_methods[] = {
459 {"__reduce__", ast_type_reduce, METH_NOARGS, NULL},
460 {NULL}
463 static PyTypeObject AST_type = {
464 PyVarObject_HEAD_INIT(&PyType_Type, 0)
465 "_ast.AST",
466 sizeof(PyObject),
468 0, /* tp_dealloc */
469 0, /* tp_print */
470 0, /* tp_getattr */
471 0, /* tp_setattr */
472 0, /* tp_compare */
473 0, /* tp_repr */
474 0, /* tp_as_number */
475 0, /* tp_as_sequence */
476 0, /* tp_as_mapping */
477 0, /* tp_hash */
478 0, /* tp_call */
479 0, /* tp_str */
480 PyObject_GenericGetAttr, /* tp_getattro */
481 PyObject_GenericSetAttr, /* tp_setattro */
482 0, /* tp_as_buffer */
483 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
484 0, /* tp_doc */
485 0, /* tp_traverse */
486 0, /* tp_clear */
487 0, /* tp_richcompare */
488 0, /* tp_weaklistoffset */
489 0, /* tp_iter */
490 0, /* tp_iternext */
491 ast_type_methods, /* tp_methods */
492 0, /* tp_members */
493 0, /* tp_getset */
494 0, /* tp_base */
495 0, /* tp_dict */
496 0, /* tp_descr_get */
497 0, /* tp_descr_set */
498 0, /* tp_dictoffset */
499 (initproc)ast_type_init, /* tp_init */
500 PyType_GenericAlloc, /* tp_alloc */
501 PyType_GenericNew, /* tp_new */
502 PyObject_Del, /* tp_free */
506 static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields)
508 PyObject *fnames, *result;
509 int i;
510 fnames = PyTuple_New(num_fields);
511 if (!fnames) return NULL;
512 for (i = 0; i < num_fields; i++) {
513 PyObject *field = PyString_FromString(fields[i]);
514 if (!field) {
515 Py_DECREF(fnames);
516 return NULL;
518 PyTuple_SET_ITEM(fnames, i, field);
520 result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}",
521 type, base, "_fields", fnames, "__module__", "_ast");
522 Py_DECREF(fnames);
523 return (PyTypeObject*)result;
526 static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)
528 int i, result;
529 PyObject *s, *l = PyTuple_New(num_fields);
530 if (!l)
531 return 0;
532 for (i = 0; i < num_fields; i++) {
533 s = PyString_FromString(attrs[i]);
534 if (!s) {
535 Py_DECREF(l);
536 return 0;
538 PyTuple_SET_ITEM(l, i, s);
540 result = PyObject_SetAttrString((PyObject*)type, "_attributes", l) >= 0;
541 Py_DECREF(l);
542 return result;
545 /* Conversion AST -> Python */
547 static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
549 int i, n = asdl_seq_LEN(seq);
550 PyObject *result = PyList_New(n);
551 PyObject *value;
552 if (!result)
553 return NULL;
554 for (i = 0; i < n; i++) {
555 value = func(asdl_seq_GET(seq, i));
556 if (!value) {
557 Py_DECREF(result);
558 return NULL;
560 PyList_SET_ITEM(result, i, value);
562 return result;
565 static PyObject* ast2obj_object(void *o)
567 if (!o)
568 o = Py_None;
569 Py_INCREF((PyObject*)o);
570 return (PyObject*)o;
572 #define ast2obj_identifier ast2obj_object
573 #define ast2obj_string ast2obj_object
574 static PyObject* ast2obj_bool(bool b)
576 return PyBool_FromLong(b);
579 static PyObject* ast2obj_int(long b)
581 return PyInt_FromLong(b);
584 /* Conversion Python -> AST */
586 static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena)
588 if (obj == Py_None)
589 obj = NULL;
590 if (obj)
591 PyArena_AddPyObject(arena, obj);
592 Py_XINCREF(obj);
593 *out = obj;
594 return 0;
597 #define obj2ast_identifier obj2ast_object
598 #define obj2ast_string obj2ast_object
600 static int obj2ast_int(PyObject* obj, int* out, PyArena* arena)
602 int i;
603 if (!PyInt_Check(obj) && !PyLong_Check(obj)) {
604 PyObject *s = PyObject_Repr(obj);
605 if (s == NULL) return 1;
606 PyErr_Format(PyExc_ValueError, "invalid integer value: %.400s",
607 PyString_AS_STRING(s));
608 Py_DECREF(s);
609 return 1;
612 i = (int)PyLong_AsLong(obj);
613 if (i == -1 && PyErr_Occurred())
614 return 1;
615 *out = i;
616 return 0;
619 static int obj2ast_bool(PyObject* obj, bool* out, PyArena* arena)
621 if (!PyBool_Check(obj)) {
622 PyObject *s = PyObject_Repr(obj);
623 if (s == NULL) return 1;
624 PyErr_Format(PyExc_ValueError, "invalid boolean value: %.400s",
625 PyString_AS_STRING(s));
626 Py_DECREF(s);
627 return 1;
630 *out = (obj == Py_True);
631 return 0;
634 static int add_ast_fields(void)
636 PyObject *empty_tuple, *d;
637 if (PyType_Ready(&AST_type) < 0)
638 return -1;
639 d = AST_type.tp_dict;
640 empty_tuple = PyTuple_New(0);
641 if (!empty_tuple ||
642 PyDict_SetItemString(d, "_fields", empty_tuple) < 0 ||
643 PyDict_SetItemString(d, "_attributes", empty_tuple) < 0) {
644 Py_XDECREF(empty_tuple);
645 return -1;
647 Py_DECREF(empty_tuple);
648 return 0;
652 static int init_types(void)
654 static int initialized;
655 if (initialized) return 1;
656 if (add_ast_fields() < 0) return 0;
657 mod_type = make_type("mod", &AST_type, NULL, 0);
658 if (!mod_type) return 0;
659 if (!add_attributes(mod_type, NULL, 0)) return 0;
660 Module_type = make_type("Module", mod_type, Module_fields, 1);
661 if (!Module_type) return 0;
662 Interactive_type = make_type("Interactive", mod_type,
663 Interactive_fields, 1);
664 if (!Interactive_type) return 0;
665 Expression_type = make_type("Expression", mod_type, Expression_fields,
667 if (!Expression_type) return 0;
668 Suite_type = make_type("Suite", mod_type, Suite_fields, 1);
669 if (!Suite_type) return 0;
670 stmt_type = make_type("stmt", &AST_type, NULL, 0);
671 if (!stmt_type) return 0;
672 if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0;
673 FunctionDef_type = make_type("FunctionDef", stmt_type,
674 FunctionDef_fields, 4);
675 if (!FunctionDef_type) return 0;
676 ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 4);
677 if (!ClassDef_type) return 0;
678 Return_type = make_type("Return", stmt_type, Return_fields, 1);
679 if (!Return_type) return 0;
680 Delete_type = make_type("Delete", stmt_type, Delete_fields, 1);
681 if (!Delete_type) return 0;
682 Assign_type = make_type("Assign", stmt_type, Assign_fields, 2);
683 if (!Assign_type) return 0;
684 AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3);
685 if (!AugAssign_type) return 0;
686 Print_type = make_type("Print", stmt_type, Print_fields, 3);
687 if (!Print_type) return 0;
688 For_type = make_type("For", stmt_type, For_fields, 4);
689 if (!For_type) return 0;
690 While_type = make_type("While", stmt_type, While_fields, 3);
691 if (!While_type) return 0;
692 If_type = make_type("If", stmt_type, If_fields, 3);
693 if (!If_type) return 0;
694 With_type = make_type("With", stmt_type, With_fields, 3);
695 if (!With_type) return 0;
696 Raise_type = make_type("Raise", stmt_type, Raise_fields, 3);
697 if (!Raise_type) return 0;
698 TryExcept_type = make_type("TryExcept", stmt_type, TryExcept_fields, 3);
699 if (!TryExcept_type) return 0;
700 TryFinally_type = make_type("TryFinally", stmt_type, TryFinally_fields,
702 if (!TryFinally_type) return 0;
703 Assert_type = make_type("Assert", stmt_type, Assert_fields, 2);
704 if (!Assert_type) return 0;
705 Import_type = make_type("Import", stmt_type, Import_fields, 1);
706 if (!Import_type) return 0;
707 ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields,
709 if (!ImportFrom_type) return 0;
710 Exec_type = make_type("Exec", stmt_type, Exec_fields, 3);
711 if (!Exec_type) return 0;
712 Global_type = make_type("Global", stmt_type, Global_fields, 1);
713 if (!Global_type) return 0;
714 Expr_type = make_type("Expr", stmt_type, Expr_fields, 1);
715 if (!Expr_type) return 0;
716 Pass_type = make_type("Pass", stmt_type, NULL, 0);
717 if (!Pass_type) return 0;
718 Break_type = make_type("Break", stmt_type, NULL, 0);
719 if (!Break_type) return 0;
720 Continue_type = make_type("Continue", stmt_type, NULL, 0);
721 if (!Continue_type) return 0;
722 expr_type = make_type("expr", &AST_type, NULL, 0);
723 if (!expr_type) return 0;
724 if (!add_attributes(expr_type, expr_attributes, 2)) return 0;
725 BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2);
726 if (!BoolOp_type) return 0;
727 BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3);
728 if (!BinOp_type) return 0;
729 UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2);
730 if (!UnaryOp_type) return 0;
731 Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2);
732 if (!Lambda_type) return 0;
733 IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3);
734 if (!IfExp_type) return 0;
735 Dict_type = make_type("Dict", expr_type, Dict_fields, 2);
736 if (!Dict_type) return 0;
737 Set_type = make_type("Set", expr_type, Set_fields, 1);
738 if (!Set_type) return 0;
739 ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2);
740 if (!ListComp_type) return 0;
741 SetComp_type = make_type("SetComp", expr_type, SetComp_fields, 2);
742 if (!SetComp_type) return 0;
743 DictComp_type = make_type("DictComp", expr_type, DictComp_fields, 3);
744 if (!DictComp_type) return 0;
745 GeneratorExp_type = make_type("GeneratorExp", expr_type,
746 GeneratorExp_fields, 2);
747 if (!GeneratorExp_type) return 0;
748 Yield_type = make_type("Yield", expr_type, Yield_fields, 1);
749 if (!Yield_type) return 0;
750 Compare_type = make_type("Compare", expr_type, Compare_fields, 3);
751 if (!Compare_type) return 0;
752 Call_type = make_type("Call", expr_type, Call_fields, 5);
753 if (!Call_type) return 0;
754 Repr_type = make_type("Repr", expr_type, Repr_fields, 1);
755 if (!Repr_type) return 0;
756 Num_type = make_type("Num", expr_type, Num_fields, 1);
757 if (!Num_type) return 0;
758 Str_type = make_type("Str", expr_type, Str_fields, 1);
759 if (!Str_type) return 0;
760 Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3);
761 if (!Attribute_type) return 0;
762 Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3);
763 if (!Subscript_type) return 0;
764 Name_type = make_type("Name", expr_type, Name_fields, 2);
765 if (!Name_type) return 0;
766 List_type = make_type("List", expr_type, List_fields, 2);
767 if (!List_type) return 0;
768 Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2);
769 if (!Tuple_type) return 0;
770 expr_context_type = make_type("expr_context", &AST_type, NULL, 0);
771 if (!expr_context_type) return 0;
772 if (!add_attributes(expr_context_type, NULL, 0)) return 0;
773 Load_type = make_type("Load", expr_context_type, NULL, 0);
774 if (!Load_type) return 0;
775 Load_singleton = PyType_GenericNew(Load_type, NULL, NULL);
776 if (!Load_singleton) return 0;
777 Store_type = make_type("Store", expr_context_type, NULL, 0);
778 if (!Store_type) return 0;
779 Store_singleton = PyType_GenericNew(Store_type, NULL, NULL);
780 if (!Store_singleton) return 0;
781 Del_type = make_type("Del", expr_context_type, NULL, 0);
782 if (!Del_type) return 0;
783 Del_singleton = PyType_GenericNew(Del_type, NULL, NULL);
784 if (!Del_singleton) return 0;
785 AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0);
786 if (!AugLoad_type) return 0;
787 AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL);
788 if (!AugLoad_singleton) return 0;
789 AugStore_type = make_type("AugStore", expr_context_type, NULL, 0);
790 if (!AugStore_type) return 0;
791 AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL);
792 if (!AugStore_singleton) return 0;
793 Param_type = make_type("Param", expr_context_type, NULL, 0);
794 if (!Param_type) return 0;
795 Param_singleton = PyType_GenericNew(Param_type, NULL, NULL);
796 if (!Param_singleton) return 0;
797 slice_type = make_type("slice", &AST_type, NULL, 0);
798 if (!slice_type) return 0;
799 if (!add_attributes(slice_type, NULL, 0)) return 0;
800 Ellipsis_type = make_type("Ellipsis", slice_type, NULL, 0);
801 if (!Ellipsis_type) return 0;
802 Slice_type = make_type("Slice", slice_type, Slice_fields, 3);
803 if (!Slice_type) return 0;
804 ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1);
805 if (!ExtSlice_type) return 0;
806 Index_type = make_type("Index", slice_type, Index_fields, 1);
807 if (!Index_type) return 0;
808 boolop_type = make_type("boolop", &AST_type, NULL, 0);
809 if (!boolop_type) return 0;
810 if (!add_attributes(boolop_type, NULL, 0)) return 0;
811 And_type = make_type("And", boolop_type, NULL, 0);
812 if (!And_type) return 0;
813 And_singleton = PyType_GenericNew(And_type, NULL, NULL);
814 if (!And_singleton) return 0;
815 Or_type = make_type("Or", boolop_type, NULL, 0);
816 if (!Or_type) return 0;
817 Or_singleton = PyType_GenericNew(Or_type, NULL, NULL);
818 if (!Or_singleton) return 0;
819 operator_type = make_type("operator", &AST_type, NULL, 0);
820 if (!operator_type) return 0;
821 if (!add_attributes(operator_type, NULL, 0)) return 0;
822 Add_type = make_type("Add", operator_type, NULL, 0);
823 if (!Add_type) return 0;
824 Add_singleton = PyType_GenericNew(Add_type, NULL, NULL);
825 if (!Add_singleton) return 0;
826 Sub_type = make_type("Sub", operator_type, NULL, 0);
827 if (!Sub_type) return 0;
828 Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL);
829 if (!Sub_singleton) return 0;
830 Mult_type = make_type("Mult", operator_type, NULL, 0);
831 if (!Mult_type) return 0;
832 Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL);
833 if (!Mult_singleton) return 0;
834 Div_type = make_type("Div", operator_type, NULL, 0);
835 if (!Div_type) return 0;
836 Div_singleton = PyType_GenericNew(Div_type, NULL, NULL);
837 if (!Div_singleton) return 0;
838 Mod_type = make_type("Mod", operator_type, NULL, 0);
839 if (!Mod_type) return 0;
840 Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL);
841 if (!Mod_singleton) return 0;
842 Pow_type = make_type("Pow", operator_type, NULL, 0);
843 if (!Pow_type) return 0;
844 Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL);
845 if (!Pow_singleton) return 0;
846 LShift_type = make_type("LShift", operator_type, NULL, 0);
847 if (!LShift_type) return 0;
848 LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL);
849 if (!LShift_singleton) return 0;
850 RShift_type = make_type("RShift", operator_type, NULL, 0);
851 if (!RShift_type) return 0;
852 RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL);
853 if (!RShift_singleton) return 0;
854 BitOr_type = make_type("BitOr", operator_type, NULL, 0);
855 if (!BitOr_type) return 0;
856 BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL);
857 if (!BitOr_singleton) return 0;
858 BitXor_type = make_type("BitXor", operator_type, NULL, 0);
859 if (!BitXor_type) return 0;
860 BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL);
861 if (!BitXor_singleton) return 0;
862 BitAnd_type = make_type("BitAnd", operator_type, NULL, 0);
863 if (!BitAnd_type) return 0;
864 BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL);
865 if (!BitAnd_singleton) return 0;
866 FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0);
867 if (!FloorDiv_type) return 0;
868 FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL);
869 if (!FloorDiv_singleton) return 0;
870 unaryop_type = make_type("unaryop", &AST_type, NULL, 0);
871 if (!unaryop_type) return 0;
872 if (!add_attributes(unaryop_type, NULL, 0)) return 0;
873 Invert_type = make_type("Invert", unaryop_type, NULL, 0);
874 if (!Invert_type) return 0;
875 Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL);
876 if (!Invert_singleton) return 0;
877 Not_type = make_type("Not", unaryop_type, NULL, 0);
878 if (!Not_type) return 0;
879 Not_singleton = PyType_GenericNew(Not_type, NULL, NULL);
880 if (!Not_singleton) return 0;
881 UAdd_type = make_type("UAdd", unaryop_type, NULL, 0);
882 if (!UAdd_type) return 0;
883 UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL);
884 if (!UAdd_singleton) return 0;
885 USub_type = make_type("USub", unaryop_type, NULL, 0);
886 if (!USub_type) return 0;
887 USub_singleton = PyType_GenericNew(USub_type, NULL, NULL);
888 if (!USub_singleton) return 0;
889 cmpop_type = make_type("cmpop", &AST_type, NULL, 0);
890 if (!cmpop_type) return 0;
891 if (!add_attributes(cmpop_type, NULL, 0)) return 0;
892 Eq_type = make_type("Eq", cmpop_type, NULL, 0);
893 if (!Eq_type) return 0;
894 Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL);
895 if (!Eq_singleton) return 0;
896 NotEq_type = make_type("NotEq", cmpop_type, NULL, 0);
897 if (!NotEq_type) return 0;
898 NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL);
899 if (!NotEq_singleton) return 0;
900 Lt_type = make_type("Lt", cmpop_type, NULL, 0);
901 if (!Lt_type) return 0;
902 Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL);
903 if (!Lt_singleton) return 0;
904 LtE_type = make_type("LtE", cmpop_type, NULL, 0);
905 if (!LtE_type) return 0;
906 LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL);
907 if (!LtE_singleton) return 0;
908 Gt_type = make_type("Gt", cmpop_type, NULL, 0);
909 if (!Gt_type) return 0;
910 Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL);
911 if (!Gt_singleton) return 0;
912 GtE_type = make_type("GtE", cmpop_type, NULL, 0);
913 if (!GtE_type) return 0;
914 GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL);
915 if (!GtE_singleton) return 0;
916 Is_type = make_type("Is", cmpop_type, NULL, 0);
917 if (!Is_type) return 0;
918 Is_singleton = PyType_GenericNew(Is_type, NULL, NULL);
919 if (!Is_singleton) return 0;
920 IsNot_type = make_type("IsNot", cmpop_type, NULL, 0);
921 if (!IsNot_type) return 0;
922 IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL);
923 if (!IsNot_singleton) return 0;
924 In_type = make_type("In", cmpop_type, NULL, 0);
925 if (!In_type) return 0;
926 In_singleton = PyType_GenericNew(In_type, NULL, NULL);
927 if (!In_singleton) return 0;
928 NotIn_type = make_type("NotIn", cmpop_type, NULL, 0);
929 if (!NotIn_type) return 0;
930 NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL);
931 if (!NotIn_singleton) return 0;
932 comprehension_type = make_type("comprehension", &AST_type,
933 comprehension_fields, 3);
934 if (!comprehension_type) return 0;
935 excepthandler_type = make_type("excepthandler", &AST_type, NULL, 0);
936 if (!excepthandler_type) return 0;
937 if (!add_attributes(excepthandler_type, excepthandler_attributes, 2))
938 return 0;
939 ExceptHandler_type = make_type("ExceptHandler", excepthandler_type,
940 ExceptHandler_fields, 3);
941 if (!ExceptHandler_type) return 0;
942 arguments_type = make_type("arguments", &AST_type, arguments_fields, 4);
943 if (!arguments_type) return 0;
944 keyword_type = make_type("keyword", &AST_type, keyword_fields, 2);
945 if (!keyword_type) return 0;
946 alias_type = make_type("alias", &AST_type, alias_fields, 2);
947 if (!alias_type) return 0;
948 initialized = 1;
949 return 1;
952 static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena);
953 static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena);
954 static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena);
955 static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena*
956 arena);
957 static int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena);
958 static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena);
959 static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena);
960 static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena);
961 static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena);
962 static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena*
963 arena);
964 static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena*
965 arena);
966 static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena);
967 static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena);
968 static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena);
970 mod_ty
971 Module(asdl_seq * body, PyArena *arena)
973 mod_ty p;
974 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
975 if (!p)
976 return NULL;
977 p->kind = Module_kind;
978 p->v.Module.body = body;
979 return p;
982 mod_ty
983 Interactive(asdl_seq * body, PyArena *arena)
985 mod_ty p;
986 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
987 if (!p)
988 return NULL;
989 p->kind = Interactive_kind;
990 p->v.Interactive.body = body;
991 return p;
994 mod_ty
995 Expression(expr_ty body, PyArena *arena)
997 mod_ty p;
998 if (!body) {
999 PyErr_SetString(PyExc_ValueError,
1000 "field body is required for Expression");
1001 return NULL;
1003 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
1004 if (!p)
1005 return NULL;
1006 p->kind = Expression_kind;
1007 p->v.Expression.body = body;
1008 return p;
1011 mod_ty
1012 Suite(asdl_seq * body, PyArena *arena)
1014 mod_ty p;
1015 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
1016 if (!p)
1017 return NULL;
1018 p->kind = Suite_kind;
1019 p->v.Suite.body = body;
1020 return p;
1023 stmt_ty
1024 FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
1025 decorator_list, int lineno, int col_offset, PyArena *arena)
1027 stmt_ty p;
1028 if (!name) {
1029 PyErr_SetString(PyExc_ValueError,
1030 "field name is required for FunctionDef");
1031 return NULL;
1033 if (!args) {
1034 PyErr_SetString(PyExc_ValueError,
1035 "field args is required for FunctionDef");
1036 return NULL;
1038 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1039 if (!p)
1040 return NULL;
1041 p->kind = FunctionDef_kind;
1042 p->v.FunctionDef.name = name;
1043 p->v.FunctionDef.args = args;
1044 p->v.FunctionDef.body = body;
1045 p->v.FunctionDef.decorator_list = decorator_list;
1046 p->lineno = lineno;
1047 p->col_offset = col_offset;
1048 return p;
1051 stmt_ty
1052 ClassDef(identifier name, asdl_seq * bases, asdl_seq * body, asdl_seq *
1053 decorator_list, int lineno, int col_offset, PyArena *arena)
1055 stmt_ty p;
1056 if (!name) {
1057 PyErr_SetString(PyExc_ValueError,
1058 "field name is required for ClassDef");
1059 return NULL;
1061 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1062 if (!p)
1063 return NULL;
1064 p->kind = ClassDef_kind;
1065 p->v.ClassDef.name = name;
1066 p->v.ClassDef.bases = bases;
1067 p->v.ClassDef.body = body;
1068 p->v.ClassDef.decorator_list = decorator_list;
1069 p->lineno = lineno;
1070 p->col_offset = col_offset;
1071 return p;
1074 stmt_ty
1075 Return(expr_ty value, int lineno, int col_offset, PyArena *arena)
1077 stmt_ty p;
1078 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1079 if (!p)
1080 return NULL;
1081 p->kind = Return_kind;
1082 p->v.Return.value = value;
1083 p->lineno = lineno;
1084 p->col_offset = col_offset;
1085 return p;
1088 stmt_ty
1089 Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena)
1091 stmt_ty p;
1092 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1093 if (!p)
1094 return NULL;
1095 p->kind = Delete_kind;
1096 p->v.Delete.targets = targets;
1097 p->lineno = lineno;
1098 p->col_offset = col_offset;
1099 return p;
1102 stmt_ty
1103 Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena
1104 *arena)
1106 stmt_ty p;
1107 if (!value) {
1108 PyErr_SetString(PyExc_ValueError,
1109 "field value is required for Assign");
1110 return NULL;
1112 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1113 if (!p)
1114 return NULL;
1115 p->kind = Assign_kind;
1116 p->v.Assign.targets = targets;
1117 p->v.Assign.value = value;
1118 p->lineno = lineno;
1119 p->col_offset = col_offset;
1120 return p;
1123 stmt_ty
1124 AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
1125 col_offset, PyArena *arena)
1127 stmt_ty p;
1128 if (!target) {
1129 PyErr_SetString(PyExc_ValueError,
1130 "field target is required for AugAssign");
1131 return NULL;
1133 if (!op) {
1134 PyErr_SetString(PyExc_ValueError,
1135 "field op is required for AugAssign");
1136 return NULL;
1138 if (!value) {
1139 PyErr_SetString(PyExc_ValueError,
1140 "field value is required for AugAssign");
1141 return NULL;
1143 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1144 if (!p)
1145 return NULL;
1146 p->kind = AugAssign_kind;
1147 p->v.AugAssign.target = target;
1148 p->v.AugAssign.op = op;
1149 p->v.AugAssign.value = value;
1150 p->lineno = lineno;
1151 p->col_offset = col_offset;
1152 return p;
1155 stmt_ty
1156 Print(expr_ty dest, asdl_seq * values, bool nl, int lineno, int col_offset,
1157 PyArena *arena)
1159 stmt_ty p;
1160 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1161 if (!p)
1162 return NULL;
1163 p->kind = Print_kind;
1164 p->v.Print.dest = dest;
1165 p->v.Print.values = values;
1166 p->v.Print.nl = nl;
1167 p->lineno = lineno;
1168 p->col_offset = col_offset;
1169 return p;
1172 stmt_ty
1173 For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int
1174 lineno, int col_offset, PyArena *arena)
1176 stmt_ty p;
1177 if (!target) {
1178 PyErr_SetString(PyExc_ValueError,
1179 "field target is required for For");
1180 return NULL;
1182 if (!iter) {
1183 PyErr_SetString(PyExc_ValueError,
1184 "field iter is required for For");
1185 return NULL;
1187 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1188 if (!p)
1189 return NULL;
1190 p->kind = For_kind;
1191 p->v.For.target = target;
1192 p->v.For.iter = iter;
1193 p->v.For.body = body;
1194 p->v.For.orelse = orelse;
1195 p->lineno = lineno;
1196 p->col_offset = col_offset;
1197 return p;
1200 stmt_ty
1201 While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
1202 col_offset, PyArena *arena)
1204 stmt_ty p;
1205 if (!test) {
1206 PyErr_SetString(PyExc_ValueError,
1207 "field test is required for While");
1208 return NULL;
1210 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1211 if (!p)
1212 return NULL;
1213 p->kind = While_kind;
1214 p->v.While.test = test;
1215 p->v.While.body = body;
1216 p->v.While.orelse = orelse;
1217 p->lineno = lineno;
1218 p->col_offset = col_offset;
1219 return p;
1222 stmt_ty
1223 If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
1224 col_offset, PyArena *arena)
1226 stmt_ty p;
1227 if (!test) {
1228 PyErr_SetString(PyExc_ValueError,
1229 "field test is required for If");
1230 return NULL;
1232 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1233 if (!p)
1234 return NULL;
1235 p->kind = If_kind;
1236 p->v.If.test = test;
1237 p->v.If.body = body;
1238 p->v.If.orelse = orelse;
1239 p->lineno = lineno;
1240 p->col_offset = col_offset;
1241 return p;
1244 stmt_ty
1245 With(expr_ty context_expr, expr_ty optional_vars, asdl_seq * body, int lineno,
1246 int col_offset, PyArena *arena)
1248 stmt_ty p;
1249 if (!context_expr) {
1250 PyErr_SetString(PyExc_ValueError,
1251 "field context_expr is required for With");
1252 return NULL;
1254 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1255 if (!p)
1256 return NULL;
1257 p->kind = With_kind;
1258 p->v.With.context_expr = context_expr;
1259 p->v.With.optional_vars = optional_vars;
1260 p->v.With.body = body;
1261 p->lineno = lineno;
1262 p->col_offset = col_offset;
1263 return p;
1266 stmt_ty
1267 Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno, int col_offset,
1268 PyArena *arena)
1270 stmt_ty p;
1271 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1272 if (!p)
1273 return NULL;
1274 p->kind = Raise_kind;
1275 p->v.Raise.type = type;
1276 p->v.Raise.inst = inst;
1277 p->v.Raise.tback = tback;
1278 p->lineno = lineno;
1279 p->col_offset = col_offset;
1280 return p;
1283 stmt_ty
1284 TryExcept(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, int lineno,
1285 int col_offset, PyArena *arena)
1287 stmt_ty p;
1288 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1289 if (!p)
1290 return NULL;
1291 p->kind = TryExcept_kind;
1292 p->v.TryExcept.body = body;
1293 p->v.TryExcept.handlers = handlers;
1294 p->v.TryExcept.orelse = orelse;
1295 p->lineno = lineno;
1296 p->col_offset = col_offset;
1297 return p;
1300 stmt_ty
1301 TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, int col_offset,
1302 PyArena *arena)
1304 stmt_ty p;
1305 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1306 if (!p)
1307 return NULL;
1308 p->kind = TryFinally_kind;
1309 p->v.TryFinally.body = body;
1310 p->v.TryFinally.finalbody = finalbody;
1311 p->lineno = lineno;
1312 p->col_offset = col_offset;
1313 return p;
1316 stmt_ty
1317 Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, PyArena *arena)
1319 stmt_ty p;
1320 if (!test) {
1321 PyErr_SetString(PyExc_ValueError,
1322 "field test is required for Assert");
1323 return NULL;
1325 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1326 if (!p)
1327 return NULL;
1328 p->kind = Assert_kind;
1329 p->v.Assert.test = test;
1330 p->v.Assert.msg = msg;
1331 p->lineno = lineno;
1332 p->col_offset = col_offset;
1333 return p;
1336 stmt_ty
1337 Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
1339 stmt_ty p;
1340 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1341 if (!p)
1342 return NULL;
1343 p->kind = Import_kind;
1344 p->v.Import.names = names;
1345 p->lineno = lineno;
1346 p->col_offset = col_offset;
1347 return p;
1350 stmt_ty
1351 ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int
1352 col_offset, PyArena *arena)
1354 stmt_ty p;
1355 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1356 if (!p)
1357 return NULL;
1358 p->kind = ImportFrom_kind;
1359 p->v.ImportFrom.module = module;
1360 p->v.ImportFrom.names = names;
1361 p->v.ImportFrom.level = level;
1362 p->lineno = lineno;
1363 p->col_offset = col_offset;
1364 return p;
1367 stmt_ty
1368 Exec(expr_ty body, expr_ty globals, expr_ty locals, int lineno, int col_offset,
1369 PyArena *arena)
1371 stmt_ty p;
1372 if (!body) {
1373 PyErr_SetString(PyExc_ValueError,
1374 "field body is required for Exec");
1375 return NULL;
1377 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1378 if (!p)
1379 return NULL;
1380 p->kind = Exec_kind;
1381 p->v.Exec.body = body;
1382 p->v.Exec.globals = globals;
1383 p->v.Exec.locals = locals;
1384 p->lineno = lineno;
1385 p->col_offset = col_offset;
1386 return p;
1389 stmt_ty
1390 Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
1392 stmt_ty p;
1393 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1394 if (!p)
1395 return NULL;
1396 p->kind = Global_kind;
1397 p->v.Global.names = names;
1398 p->lineno = lineno;
1399 p->col_offset = col_offset;
1400 return p;
1403 stmt_ty
1404 Expr(expr_ty value, int lineno, int col_offset, PyArena *arena)
1406 stmt_ty p;
1407 if (!value) {
1408 PyErr_SetString(PyExc_ValueError,
1409 "field value is required for Expr");
1410 return NULL;
1412 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1413 if (!p)
1414 return NULL;
1415 p->kind = Expr_kind;
1416 p->v.Expr.value = value;
1417 p->lineno = lineno;
1418 p->col_offset = col_offset;
1419 return p;
1422 stmt_ty
1423 Pass(int lineno, int col_offset, PyArena *arena)
1425 stmt_ty p;
1426 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1427 if (!p)
1428 return NULL;
1429 p->kind = Pass_kind;
1430 p->lineno = lineno;
1431 p->col_offset = col_offset;
1432 return p;
1435 stmt_ty
1436 Break(int lineno, int col_offset, PyArena *arena)
1438 stmt_ty p;
1439 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1440 if (!p)
1441 return NULL;
1442 p->kind = Break_kind;
1443 p->lineno = lineno;
1444 p->col_offset = col_offset;
1445 return p;
1448 stmt_ty
1449 Continue(int lineno, int col_offset, PyArena *arena)
1451 stmt_ty p;
1452 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1453 if (!p)
1454 return NULL;
1455 p->kind = Continue_kind;
1456 p->lineno = lineno;
1457 p->col_offset = col_offset;
1458 return p;
1461 expr_ty
1462 BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena
1463 *arena)
1465 expr_ty p;
1466 if (!op) {
1467 PyErr_SetString(PyExc_ValueError,
1468 "field op is required for BoolOp");
1469 return NULL;
1471 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1472 if (!p)
1473 return NULL;
1474 p->kind = BoolOp_kind;
1475 p->v.BoolOp.op = op;
1476 p->v.BoolOp.values = values;
1477 p->lineno = lineno;
1478 p->col_offset = col_offset;
1479 return p;
1482 expr_ty
1483 BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset,
1484 PyArena *arena)
1486 expr_ty p;
1487 if (!left) {
1488 PyErr_SetString(PyExc_ValueError,
1489 "field left is required for BinOp");
1490 return NULL;
1492 if (!op) {
1493 PyErr_SetString(PyExc_ValueError,
1494 "field op is required for BinOp");
1495 return NULL;
1497 if (!right) {
1498 PyErr_SetString(PyExc_ValueError,
1499 "field right is required for BinOp");
1500 return NULL;
1502 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1503 if (!p)
1504 return NULL;
1505 p->kind = BinOp_kind;
1506 p->v.BinOp.left = left;
1507 p->v.BinOp.op = op;
1508 p->v.BinOp.right = right;
1509 p->lineno = lineno;
1510 p->col_offset = col_offset;
1511 return p;
1514 expr_ty
1515 UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena
1516 *arena)
1518 expr_ty p;
1519 if (!op) {
1520 PyErr_SetString(PyExc_ValueError,
1521 "field op is required for UnaryOp");
1522 return NULL;
1524 if (!operand) {
1525 PyErr_SetString(PyExc_ValueError,
1526 "field operand is required for UnaryOp");
1527 return NULL;
1529 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1530 if (!p)
1531 return NULL;
1532 p->kind = UnaryOp_kind;
1533 p->v.UnaryOp.op = op;
1534 p->v.UnaryOp.operand = operand;
1535 p->lineno = lineno;
1536 p->col_offset = col_offset;
1537 return p;
1540 expr_ty
1541 Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena
1542 *arena)
1544 expr_ty p;
1545 if (!args) {
1546 PyErr_SetString(PyExc_ValueError,
1547 "field args is required for Lambda");
1548 return NULL;
1550 if (!body) {
1551 PyErr_SetString(PyExc_ValueError,
1552 "field body is required for Lambda");
1553 return NULL;
1555 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1556 if (!p)
1557 return NULL;
1558 p->kind = Lambda_kind;
1559 p->v.Lambda.args = args;
1560 p->v.Lambda.body = body;
1561 p->lineno = lineno;
1562 p->col_offset = col_offset;
1563 return p;
1566 expr_ty
1567 IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset,
1568 PyArena *arena)
1570 expr_ty p;
1571 if (!test) {
1572 PyErr_SetString(PyExc_ValueError,
1573 "field test is required for IfExp");
1574 return NULL;
1576 if (!body) {
1577 PyErr_SetString(PyExc_ValueError,
1578 "field body is required for IfExp");
1579 return NULL;
1581 if (!orelse) {
1582 PyErr_SetString(PyExc_ValueError,
1583 "field orelse is required for IfExp");
1584 return NULL;
1586 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1587 if (!p)
1588 return NULL;
1589 p->kind = IfExp_kind;
1590 p->v.IfExp.test = test;
1591 p->v.IfExp.body = body;
1592 p->v.IfExp.orelse = orelse;
1593 p->lineno = lineno;
1594 p->col_offset = col_offset;
1595 return p;
1598 expr_ty
1599 Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena
1600 *arena)
1602 expr_ty p;
1603 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1604 if (!p)
1605 return NULL;
1606 p->kind = Dict_kind;
1607 p->v.Dict.keys = keys;
1608 p->v.Dict.values = values;
1609 p->lineno = lineno;
1610 p->col_offset = col_offset;
1611 return p;
1614 expr_ty
1615 Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena)
1617 expr_ty p;
1618 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1619 if (!p)
1620 return NULL;
1621 p->kind = Set_kind;
1622 p->v.Set.elts = elts;
1623 p->lineno = lineno;
1624 p->col_offset = col_offset;
1625 return p;
1628 expr_ty
1629 ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1630 PyArena *arena)
1632 expr_ty p;
1633 if (!elt) {
1634 PyErr_SetString(PyExc_ValueError,
1635 "field elt is required for ListComp");
1636 return NULL;
1638 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1639 if (!p)
1640 return NULL;
1641 p->kind = ListComp_kind;
1642 p->v.ListComp.elt = elt;
1643 p->v.ListComp.generators = generators;
1644 p->lineno = lineno;
1645 p->col_offset = col_offset;
1646 return p;
1649 expr_ty
1650 SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, PyArena
1651 *arena)
1653 expr_ty p;
1654 if (!elt) {
1655 PyErr_SetString(PyExc_ValueError,
1656 "field elt is required for SetComp");
1657 return NULL;
1659 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1660 if (!p)
1661 return NULL;
1662 p->kind = SetComp_kind;
1663 p->v.SetComp.elt = elt;
1664 p->v.SetComp.generators = generators;
1665 p->lineno = lineno;
1666 p->col_offset = col_offset;
1667 return p;
1670 expr_ty
1671 DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int lineno, int
1672 col_offset, PyArena *arena)
1674 expr_ty p;
1675 if (!key) {
1676 PyErr_SetString(PyExc_ValueError,
1677 "field key is required for DictComp");
1678 return NULL;
1680 if (!value) {
1681 PyErr_SetString(PyExc_ValueError,
1682 "field value is required for DictComp");
1683 return NULL;
1685 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1686 if (!p)
1687 return NULL;
1688 p->kind = DictComp_kind;
1689 p->v.DictComp.key = key;
1690 p->v.DictComp.value = value;
1691 p->v.DictComp.generators = generators;
1692 p->lineno = lineno;
1693 p->col_offset = col_offset;
1694 return p;
1697 expr_ty
1698 GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1699 PyArena *arena)
1701 expr_ty p;
1702 if (!elt) {
1703 PyErr_SetString(PyExc_ValueError,
1704 "field elt is required for GeneratorExp");
1705 return NULL;
1707 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1708 if (!p)
1709 return NULL;
1710 p->kind = GeneratorExp_kind;
1711 p->v.GeneratorExp.elt = elt;
1712 p->v.GeneratorExp.generators = generators;
1713 p->lineno = lineno;
1714 p->col_offset = col_offset;
1715 return p;
1718 expr_ty
1719 Yield(expr_ty value, int lineno, int col_offset, PyArena *arena)
1721 expr_ty p;
1722 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1723 if (!p)
1724 return NULL;
1725 p->kind = Yield_kind;
1726 p->v.Yield.value = value;
1727 p->lineno = lineno;
1728 p->col_offset = col_offset;
1729 return p;
1732 expr_ty
1733 Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno,
1734 int col_offset, PyArena *arena)
1736 expr_ty p;
1737 if (!left) {
1738 PyErr_SetString(PyExc_ValueError,
1739 "field left is required for Compare");
1740 return NULL;
1742 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1743 if (!p)
1744 return NULL;
1745 p->kind = Compare_kind;
1746 p->v.Compare.left = left;
1747 p->v.Compare.ops = ops;
1748 p->v.Compare.comparators = comparators;
1749 p->lineno = lineno;
1750 p->col_offset = col_offset;
1751 return p;
1754 expr_ty
1755 Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, expr_ty starargs,
1756 expr_ty kwargs, int lineno, int col_offset, PyArena *arena)
1758 expr_ty p;
1759 if (!func) {
1760 PyErr_SetString(PyExc_ValueError,
1761 "field func is required for Call");
1762 return NULL;
1764 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1765 if (!p)
1766 return NULL;
1767 p->kind = Call_kind;
1768 p->v.Call.func = func;
1769 p->v.Call.args = args;
1770 p->v.Call.keywords = keywords;
1771 p->v.Call.starargs = starargs;
1772 p->v.Call.kwargs = kwargs;
1773 p->lineno = lineno;
1774 p->col_offset = col_offset;
1775 return p;
1778 expr_ty
1779 Repr(expr_ty value, int lineno, int col_offset, PyArena *arena)
1781 expr_ty p;
1782 if (!value) {
1783 PyErr_SetString(PyExc_ValueError,
1784 "field value is required for Repr");
1785 return NULL;
1787 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1788 if (!p)
1789 return NULL;
1790 p->kind = Repr_kind;
1791 p->v.Repr.value = value;
1792 p->lineno = lineno;
1793 p->col_offset = col_offset;
1794 return p;
1797 expr_ty
1798 Num(object n, int lineno, int col_offset, PyArena *arena)
1800 expr_ty p;
1801 if (!n) {
1802 PyErr_SetString(PyExc_ValueError,
1803 "field n is required for Num");
1804 return NULL;
1806 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1807 if (!p)
1808 return NULL;
1809 p->kind = Num_kind;
1810 p->v.Num.n = n;
1811 p->lineno = lineno;
1812 p->col_offset = col_offset;
1813 return p;
1816 expr_ty
1817 Str(string s, int lineno, int col_offset, PyArena *arena)
1819 expr_ty p;
1820 if (!s) {
1821 PyErr_SetString(PyExc_ValueError,
1822 "field s is required for Str");
1823 return NULL;
1825 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1826 if (!p)
1827 return NULL;
1828 p->kind = Str_kind;
1829 p->v.Str.s = s;
1830 p->lineno = lineno;
1831 p->col_offset = col_offset;
1832 return p;
1835 expr_ty
1836 Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int
1837 col_offset, PyArena *arena)
1839 expr_ty p;
1840 if (!value) {
1841 PyErr_SetString(PyExc_ValueError,
1842 "field value is required for Attribute");
1843 return NULL;
1845 if (!attr) {
1846 PyErr_SetString(PyExc_ValueError,
1847 "field attr is required for Attribute");
1848 return NULL;
1850 if (!ctx) {
1851 PyErr_SetString(PyExc_ValueError,
1852 "field ctx is required for Attribute");
1853 return NULL;
1855 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1856 if (!p)
1857 return NULL;
1858 p->kind = Attribute_kind;
1859 p->v.Attribute.value = value;
1860 p->v.Attribute.attr = attr;
1861 p->v.Attribute.ctx = ctx;
1862 p->lineno = lineno;
1863 p->col_offset = col_offset;
1864 return p;
1867 expr_ty
1868 Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int
1869 col_offset, PyArena *arena)
1871 expr_ty p;
1872 if (!value) {
1873 PyErr_SetString(PyExc_ValueError,
1874 "field value is required for Subscript");
1875 return NULL;
1877 if (!slice) {
1878 PyErr_SetString(PyExc_ValueError,
1879 "field slice is required for Subscript");
1880 return NULL;
1882 if (!ctx) {
1883 PyErr_SetString(PyExc_ValueError,
1884 "field ctx is required for Subscript");
1885 return NULL;
1887 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1888 if (!p)
1889 return NULL;
1890 p->kind = Subscript_kind;
1891 p->v.Subscript.value = value;
1892 p->v.Subscript.slice = slice;
1893 p->v.Subscript.ctx = ctx;
1894 p->lineno = lineno;
1895 p->col_offset = col_offset;
1896 return p;
1899 expr_ty
1900 Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena
1901 *arena)
1903 expr_ty p;
1904 if (!id) {
1905 PyErr_SetString(PyExc_ValueError,
1906 "field id is required for Name");
1907 return NULL;
1909 if (!ctx) {
1910 PyErr_SetString(PyExc_ValueError,
1911 "field ctx is required for Name");
1912 return NULL;
1914 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1915 if (!p)
1916 return NULL;
1917 p->kind = Name_kind;
1918 p->v.Name.id = id;
1919 p->v.Name.ctx = ctx;
1920 p->lineno = lineno;
1921 p->col_offset = col_offset;
1922 return p;
1925 expr_ty
1926 List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1927 *arena)
1929 expr_ty p;
1930 if (!ctx) {
1931 PyErr_SetString(PyExc_ValueError,
1932 "field ctx is required for List");
1933 return NULL;
1935 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1936 if (!p)
1937 return NULL;
1938 p->kind = List_kind;
1939 p->v.List.elts = elts;
1940 p->v.List.ctx = ctx;
1941 p->lineno = lineno;
1942 p->col_offset = col_offset;
1943 return p;
1946 expr_ty
1947 Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1948 *arena)
1950 expr_ty p;
1951 if (!ctx) {
1952 PyErr_SetString(PyExc_ValueError,
1953 "field ctx is required for Tuple");
1954 return NULL;
1956 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1957 if (!p)
1958 return NULL;
1959 p->kind = Tuple_kind;
1960 p->v.Tuple.elts = elts;
1961 p->v.Tuple.ctx = ctx;
1962 p->lineno = lineno;
1963 p->col_offset = col_offset;
1964 return p;
1967 slice_ty
1968 Ellipsis(PyArena *arena)
1970 slice_ty p;
1971 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
1972 if (!p)
1973 return NULL;
1974 p->kind = Ellipsis_kind;
1975 return p;
1978 slice_ty
1979 Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena)
1981 slice_ty p;
1982 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
1983 if (!p)
1984 return NULL;
1985 p->kind = Slice_kind;
1986 p->v.Slice.lower = lower;
1987 p->v.Slice.upper = upper;
1988 p->v.Slice.step = step;
1989 return p;
1992 slice_ty
1993 ExtSlice(asdl_seq * dims, PyArena *arena)
1995 slice_ty p;
1996 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
1997 if (!p)
1998 return NULL;
1999 p->kind = ExtSlice_kind;
2000 p->v.ExtSlice.dims = dims;
2001 return p;
2004 slice_ty
2005 Index(expr_ty value, PyArena *arena)
2007 slice_ty p;
2008 if (!value) {
2009 PyErr_SetString(PyExc_ValueError,
2010 "field value is required for Index");
2011 return NULL;
2013 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
2014 if (!p)
2015 return NULL;
2016 p->kind = Index_kind;
2017 p->v.Index.value = value;
2018 return p;
2021 comprehension_ty
2022 comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena)
2024 comprehension_ty p;
2025 if (!target) {
2026 PyErr_SetString(PyExc_ValueError,
2027 "field target is required for comprehension");
2028 return NULL;
2030 if (!iter) {
2031 PyErr_SetString(PyExc_ValueError,
2032 "field iter is required for comprehension");
2033 return NULL;
2035 p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));
2036 if (!p)
2037 return NULL;
2038 p->target = target;
2039 p->iter = iter;
2040 p->ifs = ifs;
2041 return p;
2044 excepthandler_ty
2045 ExceptHandler(expr_ty type, expr_ty name, asdl_seq * body, int lineno, int
2046 col_offset, PyArena *arena)
2048 excepthandler_ty p;
2049 p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
2050 if (!p)
2051 return NULL;
2052 p->kind = ExceptHandler_kind;
2053 p->v.ExceptHandler.type = type;
2054 p->v.ExceptHandler.name = name;
2055 p->v.ExceptHandler.body = body;
2056 p->lineno = lineno;
2057 p->col_offset = col_offset;
2058 return p;
2061 arguments_ty
2062 arguments(asdl_seq * args, identifier vararg, identifier kwarg, asdl_seq *
2063 defaults, PyArena *arena)
2065 arguments_ty p;
2066 p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
2067 if (!p)
2068 return NULL;
2069 p->args = args;
2070 p->vararg = vararg;
2071 p->kwarg = kwarg;
2072 p->defaults = defaults;
2073 return p;
2076 keyword_ty
2077 keyword(identifier arg, expr_ty value, PyArena *arena)
2079 keyword_ty p;
2080 if (!arg) {
2081 PyErr_SetString(PyExc_ValueError,
2082 "field arg is required for keyword");
2083 return NULL;
2085 if (!value) {
2086 PyErr_SetString(PyExc_ValueError,
2087 "field value is required for keyword");
2088 return NULL;
2090 p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));
2091 if (!p)
2092 return NULL;
2093 p->arg = arg;
2094 p->value = value;
2095 return p;
2098 alias_ty
2099 alias(identifier name, identifier asname, PyArena *arena)
2101 alias_ty p;
2102 if (!name) {
2103 PyErr_SetString(PyExc_ValueError,
2104 "field name is required for alias");
2105 return NULL;
2107 p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));
2108 if (!p)
2109 return NULL;
2110 p->name = name;
2111 p->asname = asname;
2112 return p;
2116 PyObject*
2117 ast2obj_mod(void* _o)
2119 mod_ty o = (mod_ty)_o;
2120 PyObject *result = NULL, *value = NULL;
2121 if (!o) {
2122 Py_INCREF(Py_None);
2123 return Py_None;
2126 switch (o->kind) {
2127 case Module_kind:
2128 result = PyType_GenericNew(Module_type, NULL, NULL);
2129 if (!result) goto failed;
2130 value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
2131 if (!value) goto failed;
2132 if (PyObject_SetAttrString(result, "body", value) == -1)
2133 goto failed;
2134 Py_DECREF(value);
2135 break;
2136 case Interactive_kind:
2137 result = PyType_GenericNew(Interactive_type, NULL, NULL);
2138 if (!result) goto failed;
2139 value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
2140 if (!value) goto failed;
2141 if (PyObject_SetAttrString(result, "body", value) == -1)
2142 goto failed;
2143 Py_DECREF(value);
2144 break;
2145 case Expression_kind:
2146 result = PyType_GenericNew(Expression_type, NULL, NULL);
2147 if (!result) goto failed;
2148 value = ast2obj_expr(o->v.Expression.body);
2149 if (!value) goto failed;
2150 if (PyObject_SetAttrString(result, "body", value) == -1)
2151 goto failed;
2152 Py_DECREF(value);
2153 break;
2154 case Suite_kind:
2155 result = PyType_GenericNew(Suite_type, NULL, NULL);
2156 if (!result) goto failed;
2157 value = ast2obj_list(o->v.Suite.body, ast2obj_stmt);
2158 if (!value) goto failed;
2159 if (PyObject_SetAttrString(result, "body", value) == -1)
2160 goto failed;
2161 Py_DECREF(value);
2162 break;
2164 return result;
2165 failed:
2166 Py_XDECREF(value);
2167 Py_XDECREF(result);
2168 return NULL;
2171 PyObject*
2172 ast2obj_stmt(void* _o)
2174 stmt_ty o = (stmt_ty)_o;
2175 PyObject *result = NULL, *value = NULL;
2176 if (!o) {
2177 Py_INCREF(Py_None);
2178 return Py_None;
2181 switch (o->kind) {
2182 case FunctionDef_kind:
2183 result = PyType_GenericNew(FunctionDef_type, NULL, NULL);
2184 if (!result) goto failed;
2185 value = ast2obj_identifier(o->v.FunctionDef.name);
2186 if (!value) goto failed;
2187 if (PyObject_SetAttrString(result, "name", value) == -1)
2188 goto failed;
2189 Py_DECREF(value);
2190 value = ast2obj_arguments(o->v.FunctionDef.args);
2191 if (!value) goto failed;
2192 if (PyObject_SetAttrString(result, "args", value) == -1)
2193 goto failed;
2194 Py_DECREF(value);
2195 value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
2196 if (!value) goto failed;
2197 if (PyObject_SetAttrString(result, "body", value) == -1)
2198 goto failed;
2199 Py_DECREF(value);
2200 value = ast2obj_list(o->v.FunctionDef.decorator_list,
2201 ast2obj_expr);
2202 if (!value) goto failed;
2203 if (PyObject_SetAttrString(result, "decorator_list", value) ==
2205 goto failed;
2206 Py_DECREF(value);
2207 break;
2208 case ClassDef_kind:
2209 result = PyType_GenericNew(ClassDef_type, NULL, NULL);
2210 if (!result) goto failed;
2211 value = ast2obj_identifier(o->v.ClassDef.name);
2212 if (!value) goto failed;
2213 if (PyObject_SetAttrString(result, "name", value) == -1)
2214 goto failed;
2215 Py_DECREF(value);
2216 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
2217 if (!value) goto failed;
2218 if (PyObject_SetAttrString(result, "bases", value) == -1)
2219 goto failed;
2220 Py_DECREF(value);
2221 value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
2222 if (!value) goto failed;
2223 if (PyObject_SetAttrString(result, "body", value) == -1)
2224 goto failed;
2225 Py_DECREF(value);
2226 value = ast2obj_list(o->v.ClassDef.decorator_list,
2227 ast2obj_expr);
2228 if (!value) goto failed;
2229 if (PyObject_SetAttrString(result, "decorator_list", value) ==
2231 goto failed;
2232 Py_DECREF(value);
2233 break;
2234 case Return_kind:
2235 result = PyType_GenericNew(Return_type, NULL, NULL);
2236 if (!result) goto failed;
2237 value = ast2obj_expr(o->v.Return.value);
2238 if (!value) goto failed;
2239 if (PyObject_SetAttrString(result, "value", value) == -1)
2240 goto failed;
2241 Py_DECREF(value);
2242 break;
2243 case Delete_kind:
2244 result = PyType_GenericNew(Delete_type, NULL, NULL);
2245 if (!result) goto failed;
2246 value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
2247 if (!value) goto failed;
2248 if (PyObject_SetAttrString(result, "targets", value) == -1)
2249 goto failed;
2250 Py_DECREF(value);
2251 break;
2252 case Assign_kind:
2253 result = PyType_GenericNew(Assign_type, NULL, NULL);
2254 if (!result) goto failed;
2255 value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
2256 if (!value) goto failed;
2257 if (PyObject_SetAttrString(result, "targets", value) == -1)
2258 goto failed;
2259 Py_DECREF(value);
2260 value = ast2obj_expr(o->v.Assign.value);
2261 if (!value) goto failed;
2262 if (PyObject_SetAttrString(result, "value", value) == -1)
2263 goto failed;
2264 Py_DECREF(value);
2265 break;
2266 case AugAssign_kind:
2267 result = PyType_GenericNew(AugAssign_type, NULL, NULL);
2268 if (!result) goto failed;
2269 value = ast2obj_expr(o->v.AugAssign.target);
2270 if (!value) goto failed;
2271 if (PyObject_SetAttrString(result, "target", value) == -1)
2272 goto failed;
2273 Py_DECREF(value);
2274 value = ast2obj_operator(o->v.AugAssign.op);
2275 if (!value) goto failed;
2276 if (PyObject_SetAttrString(result, "op", value) == -1)
2277 goto failed;
2278 Py_DECREF(value);
2279 value = ast2obj_expr(o->v.AugAssign.value);
2280 if (!value) goto failed;
2281 if (PyObject_SetAttrString(result, "value", value) == -1)
2282 goto failed;
2283 Py_DECREF(value);
2284 break;
2285 case Print_kind:
2286 result = PyType_GenericNew(Print_type, NULL, NULL);
2287 if (!result) goto failed;
2288 value = ast2obj_expr(o->v.Print.dest);
2289 if (!value) goto failed;
2290 if (PyObject_SetAttrString(result, "dest", value) == -1)
2291 goto failed;
2292 Py_DECREF(value);
2293 value = ast2obj_list(o->v.Print.values, ast2obj_expr);
2294 if (!value) goto failed;
2295 if (PyObject_SetAttrString(result, "values", value) == -1)
2296 goto failed;
2297 Py_DECREF(value);
2298 value = ast2obj_bool(o->v.Print.nl);
2299 if (!value) goto failed;
2300 if (PyObject_SetAttrString(result, "nl", value) == -1)
2301 goto failed;
2302 Py_DECREF(value);
2303 break;
2304 case For_kind:
2305 result = PyType_GenericNew(For_type, NULL, NULL);
2306 if (!result) goto failed;
2307 value = ast2obj_expr(o->v.For.target);
2308 if (!value) goto failed;
2309 if (PyObject_SetAttrString(result, "target", value) == -1)
2310 goto failed;
2311 Py_DECREF(value);
2312 value = ast2obj_expr(o->v.For.iter);
2313 if (!value) goto failed;
2314 if (PyObject_SetAttrString(result, "iter", value) == -1)
2315 goto failed;
2316 Py_DECREF(value);
2317 value = ast2obj_list(o->v.For.body, ast2obj_stmt);
2318 if (!value) goto failed;
2319 if (PyObject_SetAttrString(result, "body", value) == -1)
2320 goto failed;
2321 Py_DECREF(value);
2322 value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
2323 if (!value) goto failed;
2324 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2325 goto failed;
2326 Py_DECREF(value);
2327 break;
2328 case While_kind:
2329 result = PyType_GenericNew(While_type, NULL, NULL);
2330 if (!result) goto failed;
2331 value = ast2obj_expr(o->v.While.test);
2332 if (!value) goto failed;
2333 if (PyObject_SetAttrString(result, "test", value) == -1)
2334 goto failed;
2335 Py_DECREF(value);
2336 value = ast2obj_list(o->v.While.body, ast2obj_stmt);
2337 if (!value) goto failed;
2338 if (PyObject_SetAttrString(result, "body", value) == -1)
2339 goto failed;
2340 Py_DECREF(value);
2341 value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);
2342 if (!value) goto failed;
2343 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2344 goto failed;
2345 Py_DECREF(value);
2346 break;
2347 case If_kind:
2348 result = PyType_GenericNew(If_type, NULL, NULL);
2349 if (!result) goto failed;
2350 value = ast2obj_expr(o->v.If.test);
2351 if (!value) goto failed;
2352 if (PyObject_SetAttrString(result, "test", value) == -1)
2353 goto failed;
2354 Py_DECREF(value);
2355 value = ast2obj_list(o->v.If.body, ast2obj_stmt);
2356 if (!value) goto failed;
2357 if (PyObject_SetAttrString(result, "body", value) == -1)
2358 goto failed;
2359 Py_DECREF(value);
2360 value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
2361 if (!value) goto failed;
2362 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2363 goto failed;
2364 Py_DECREF(value);
2365 break;
2366 case With_kind:
2367 result = PyType_GenericNew(With_type, NULL, NULL);
2368 if (!result) goto failed;
2369 value = ast2obj_expr(o->v.With.context_expr);
2370 if (!value) goto failed;
2371 if (PyObject_SetAttrString(result, "context_expr", value) == -1)
2372 goto failed;
2373 Py_DECREF(value);
2374 value = ast2obj_expr(o->v.With.optional_vars);
2375 if (!value) goto failed;
2376 if (PyObject_SetAttrString(result, "optional_vars", value) ==
2378 goto failed;
2379 Py_DECREF(value);
2380 value = ast2obj_list(o->v.With.body, ast2obj_stmt);
2381 if (!value) goto failed;
2382 if (PyObject_SetAttrString(result, "body", value) == -1)
2383 goto failed;
2384 Py_DECREF(value);
2385 break;
2386 case Raise_kind:
2387 result = PyType_GenericNew(Raise_type, NULL, NULL);
2388 if (!result) goto failed;
2389 value = ast2obj_expr(o->v.Raise.type);
2390 if (!value) goto failed;
2391 if (PyObject_SetAttrString(result, "type", value) == -1)
2392 goto failed;
2393 Py_DECREF(value);
2394 value = ast2obj_expr(o->v.Raise.inst);
2395 if (!value) goto failed;
2396 if (PyObject_SetAttrString(result, "inst", value) == -1)
2397 goto failed;
2398 Py_DECREF(value);
2399 value = ast2obj_expr(o->v.Raise.tback);
2400 if (!value) goto failed;
2401 if (PyObject_SetAttrString(result, "tback", value) == -1)
2402 goto failed;
2403 Py_DECREF(value);
2404 break;
2405 case TryExcept_kind:
2406 result = PyType_GenericNew(TryExcept_type, NULL, NULL);
2407 if (!result) goto failed;
2408 value = ast2obj_list(o->v.TryExcept.body, ast2obj_stmt);
2409 if (!value) goto failed;
2410 if (PyObject_SetAttrString(result, "body", value) == -1)
2411 goto failed;
2412 Py_DECREF(value);
2413 value = ast2obj_list(o->v.TryExcept.handlers,
2414 ast2obj_excepthandler);
2415 if (!value) goto failed;
2416 if (PyObject_SetAttrString(result, "handlers", value) == -1)
2417 goto failed;
2418 Py_DECREF(value);
2419 value = ast2obj_list(o->v.TryExcept.orelse, ast2obj_stmt);
2420 if (!value) goto failed;
2421 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2422 goto failed;
2423 Py_DECREF(value);
2424 break;
2425 case TryFinally_kind:
2426 result = PyType_GenericNew(TryFinally_type, NULL, NULL);
2427 if (!result) goto failed;
2428 value = ast2obj_list(o->v.TryFinally.body, ast2obj_stmt);
2429 if (!value) goto failed;
2430 if (PyObject_SetAttrString(result, "body", value) == -1)
2431 goto failed;
2432 Py_DECREF(value);
2433 value = ast2obj_list(o->v.TryFinally.finalbody, ast2obj_stmt);
2434 if (!value) goto failed;
2435 if (PyObject_SetAttrString(result, "finalbody", value) == -1)
2436 goto failed;
2437 Py_DECREF(value);
2438 break;
2439 case Assert_kind:
2440 result = PyType_GenericNew(Assert_type, NULL, NULL);
2441 if (!result) goto failed;
2442 value = ast2obj_expr(o->v.Assert.test);
2443 if (!value) goto failed;
2444 if (PyObject_SetAttrString(result, "test", value) == -1)
2445 goto failed;
2446 Py_DECREF(value);
2447 value = ast2obj_expr(o->v.Assert.msg);
2448 if (!value) goto failed;
2449 if (PyObject_SetAttrString(result, "msg", value) == -1)
2450 goto failed;
2451 Py_DECREF(value);
2452 break;
2453 case Import_kind:
2454 result = PyType_GenericNew(Import_type, NULL, NULL);
2455 if (!result) goto failed;
2456 value = ast2obj_list(o->v.Import.names, ast2obj_alias);
2457 if (!value) goto failed;
2458 if (PyObject_SetAttrString(result, "names", value) == -1)
2459 goto failed;
2460 Py_DECREF(value);
2461 break;
2462 case ImportFrom_kind:
2463 result = PyType_GenericNew(ImportFrom_type, NULL, NULL);
2464 if (!result) goto failed;
2465 value = ast2obj_identifier(o->v.ImportFrom.module);
2466 if (!value) goto failed;
2467 if (PyObject_SetAttrString(result, "module", value) == -1)
2468 goto failed;
2469 Py_DECREF(value);
2470 value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
2471 if (!value) goto failed;
2472 if (PyObject_SetAttrString(result, "names", value) == -1)
2473 goto failed;
2474 Py_DECREF(value);
2475 value = ast2obj_int(o->v.ImportFrom.level);
2476 if (!value) goto failed;
2477 if (PyObject_SetAttrString(result, "level", value) == -1)
2478 goto failed;
2479 Py_DECREF(value);
2480 break;
2481 case Exec_kind:
2482 result = PyType_GenericNew(Exec_type, NULL, NULL);
2483 if (!result) goto failed;
2484 value = ast2obj_expr(o->v.Exec.body);
2485 if (!value) goto failed;
2486 if (PyObject_SetAttrString(result, "body", value) == -1)
2487 goto failed;
2488 Py_DECREF(value);
2489 value = ast2obj_expr(o->v.Exec.globals);
2490 if (!value) goto failed;
2491 if (PyObject_SetAttrString(result, "globals", value) == -1)
2492 goto failed;
2493 Py_DECREF(value);
2494 value = ast2obj_expr(o->v.Exec.locals);
2495 if (!value) goto failed;
2496 if (PyObject_SetAttrString(result, "locals", value) == -1)
2497 goto failed;
2498 Py_DECREF(value);
2499 break;
2500 case Global_kind:
2501 result = PyType_GenericNew(Global_type, NULL, NULL);
2502 if (!result) goto failed;
2503 value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
2504 if (!value) goto failed;
2505 if (PyObject_SetAttrString(result, "names", value) == -1)
2506 goto failed;
2507 Py_DECREF(value);
2508 break;
2509 case Expr_kind:
2510 result = PyType_GenericNew(Expr_type, NULL, NULL);
2511 if (!result) goto failed;
2512 value = ast2obj_expr(o->v.Expr.value);
2513 if (!value) goto failed;
2514 if (PyObject_SetAttrString(result, "value", value) == -1)
2515 goto failed;
2516 Py_DECREF(value);
2517 break;
2518 case Pass_kind:
2519 result = PyType_GenericNew(Pass_type, NULL, NULL);
2520 if (!result) goto failed;
2521 break;
2522 case Break_kind:
2523 result = PyType_GenericNew(Break_type, NULL, NULL);
2524 if (!result) goto failed;
2525 break;
2526 case Continue_kind:
2527 result = PyType_GenericNew(Continue_type, NULL, NULL);
2528 if (!result) goto failed;
2529 break;
2531 value = ast2obj_int(o->lineno);
2532 if (!value) goto failed;
2533 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2534 goto failed;
2535 Py_DECREF(value);
2536 value = ast2obj_int(o->col_offset);
2537 if (!value) goto failed;
2538 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2539 goto failed;
2540 Py_DECREF(value);
2541 return result;
2542 failed:
2543 Py_XDECREF(value);
2544 Py_XDECREF(result);
2545 return NULL;
2548 PyObject*
2549 ast2obj_expr(void* _o)
2551 expr_ty o = (expr_ty)_o;
2552 PyObject *result = NULL, *value = NULL;
2553 if (!o) {
2554 Py_INCREF(Py_None);
2555 return Py_None;
2558 switch (o->kind) {
2559 case BoolOp_kind:
2560 result = PyType_GenericNew(BoolOp_type, NULL, NULL);
2561 if (!result) goto failed;
2562 value = ast2obj_boolop(o->v.BoolOp.op);
2563 if (!value) goto failed;
2564 if (PyObject_SetAttrString(result, "op", value) == -1)
2565 goto failed;
2566 Py_DECREF(value);
2567 value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
2568 if (!value) goto failed;
2569 if (PyObject_SetAttrString(result, "values", value) == -1)
2570 goto failed;
2571 Py_DECREF(value);
2572 break;
2573 case BinOp_kind:
2574 result = PyType_GenericNew(BinOp_type, NULL, NULL);
2575 if (!result) goto failed;
2576 value = ast2obj_expr(o->v.BinOp.left);
2577 if (!value) goto failed;
2578 if (PyObject_SetAttrString(result, "left", value) == -1)
2579 goto failed;
2580 Py_DECREF(value);
2581 value = ast2obj_operator(o->v.BinOp.op);
2582 if (!value) goto failed;
2583 if (PyObject_SetAttrString(result, "op", value) == -1)
2584 goto failed;
2585 Py_DECREF(value);
2586 value = ast2obj_expr(o->v.BinOp.right);
2587 if (!value) goto failed;
2588 if (PyObject_SetAttrString(result, "right", value) == -1)
2589 goto failed;
2590 Py_DECREF(value);
2591 break;
2592 case UnaryOp_kind:
2593 result = PyType_GenericNew(UnaryOp_type, NULL, NULL);
2594 if (!result) goto failed;
2595 value = ast2obj_unaryop(o->v.UnaryOp.op);
2596 if (!value) goto failed;
2597 if (PyObject_SetAttrString(result, "op", value) == -1)
2598 goto failed;
2599 Py_DECREF(value);
2600 value = ast2obj_expr(o->v.UnaryOp.operand);
2601 if (!value) goto failed;
2602 if (PyObject_SetAttrString(result, "operand", value) == -1)
2603 goto failed;
2604 Py_DECREF(value);
2605 break;
2606 case Lambda_kind:
2607 result = PyType_GenericNew(Lambda_type, NULL, NULL);
2608 if (!result) goto failed;
2609 value = ast2obj_arguments(o->v.Lambda.args);
2610 if (!value) goto failed;
2611 if (PyObject_SetAttrString(result, "args", value) == -1)
2612 goto failed;
2613 Py_DECREF(value);
2614 value = ast2obj_expr(o->v.Lambda.body);
2615 if (!value) goto failed;
2616 if (PyObject_SetAttrString(result, "body", value) == -1)
2617 goto failed;
2618 Py_DECREF(value);
2619 break;
2620 case IfExp_kind:
2621 result = PyType_GenericNew(IfExp_type, NULL, NULL);
2622 if (!result) goto failed;
2623 value = ast2obj_expr(o->v.IfExp.test);
2624 if (!value) goto failed;
2625 if (PyObject_SetAttrString(result, "test", value) == -1)
2626 goto failed;
2627 Py_DECREF(value);
2628 value = ast2obj_expr(o->v.IfExp.body);
2629 if (!value) goto failed;
2630 if (PyObject_SetAttrString(result, "body", value) == -1)
2631 goto failed;
2632 Py_DECREF(value);
2633 value = ast2obj_expr(o->v.IfExp.orelse);
2634 if (!value) goto failed;
2635 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2636 goto failed;
2637 Py_DECREF(value);
2638 break;
2639 case Dict_kind:
2640 result = PyType_GenericNew(Dict_type, NULL, NULL);
2641 if (!result) goto failed;
2642 value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
2643 if (!value) goto failed;
2644 if (PyObject_SetAttrString(result, "keys", value) == -1)
2645 goto failed;
2646 Py_DECREF(value);
2647 value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
2648 if (!value) goto failed;
2649 if (PyObject_SetAttrString(result, "values", value) == -1)
2650 goto failed;
2651 Py_DECREF(value);
2652 break;
2653 case Set_kind:
2654 result = PyType_GenericNew(Set_type, NULL, NULL);
2655 if (!result) goto failed;
2656 value = ast2obj_list(o->v.Set.elts, ast2obj_expr);
2657 if (!value) goto failed;
2658 if (PyObject_SetAttrString(result, "elts", value) == -1)
2659 goto failed;
2660 Py_DECREF(value);
2661 break;
2662 case ListComp_kind:
2663 result = PyType_GenericNew(ListComp_type, NULL, NULL);
2664 if (!result) goto failed;
2665 value = ast2obj_expr(o->v.ListComp.elt);
2666 if (!value) goto failed;
2667 if (PyObject_SetAttrString(result, "elt", value) == -1)
2668 goto failed;
2669 Py_DECREF(value);
2670 value = ast2obj_list(o->v.ListComp.generators,
2671 ast2obj_comprehension);
2672 if (!value) goto failed;
2673 if (PyObject_SetAttrString(result, "generators", value) == -1)
2674 goto failed;
2675 Py_DECREF(value);
2676 break;
2677 case SetComp_kind:
2678 result = PyType_GenericNew(SetComp_type, NULL, NULL);
2679 if (!result) goto failed;
2680 value = ast2obj_expr(o->v.SetComp.elt);
2681 if (!value) goto failed;
2682 if (PyObject_SetAttrString(result, "elt", value) == -1)
2683 goto failed;
2684 Py_DECREF(value);
2685 value = ast2obj_list(o->v.SetComp.generators,
2686 ast2obj_comprehension);
2687 if (!value) goto failed;
2688 if (PyObject_SetAttrString(result, "generators", value) == -1)
2689 goto failed;
2690 Py_DECREF(value);
2691 break;
2692 case DictComp_kind:
2693 result = PyType_GenericNew(DictComp_type, NULL, NULL);
2694 if (!result) goto failed;
2695 value = ast2obj_expr(o->v.DictComp.key);
2696 if (!value) goto failed;
2697 if (PyObject_SetAttrString(result, "key", value) == -1)
2698 goto failed;
2699 Py_DECREF(value);
2700 value = ast2obj_expr(o->v.DictComp.value);
2701 if (!value) goto failed;
2702 if (PyObject_SetAttrString(result, "value", value) == -1)
2703 goto failed;
2704 Py_DECREF(value);
2705 value = ast2obj_list(o->v.DictComp.generators,
2706 ast2obj_comprehension);
2707 if (!value) goto failed;
2708 if (PyObject_SetAttrString(result, "generators", value) == -1)
2709 goto failed;
2710 Py_DECREF(value);
2711 break;
2712 case GeneratorExp_kind:
2713 result = PyType_GenericNew(GeneratorExp_type, NULL, NULL);
2714 if (!result) goto failed;
2715 value = ast2obj_expr(o->v.GeneratorExp.elt);
2716 if (!value) goto failed;
2717 if (PyObject_SetAttrString(result, "elt", value) == -1)
2718 goto failed;
2719 Py_DECREF(value);
2720 value = ast2obj_list(o->v.GeneratorExp.generators,
2721 ast2obj_comprehension);
2722 if (!value) goto failed;
2723 if (PyObject_SetAttrString(result, "generators", value) == -1)
2724 goto failed;
2725 Py_DECREF(value);
2726 break;
2727 case Yield_kind:
2728 result = PyType_GenericNew(Yield_type, NULL, NULL);
2729 if (!result) goto failed;
2730 value = ast2obj_expr(o->v.Yield.value);
2731 if (!value) goto failed;
2732 if (PyObject_SetAttrString(result, "value", value) == -1)
2733 goto failed;
2734 Py_DECREF(value);
2735 break;
2736 case Compare_kind:
2737 result = PyType_GenericNew(Compare_type, NULL, NULL);
2738 if (!result) goto failed;
2739 value = ast2obj_expr(o->v.Compare.left);
2740 if (!value) goto failed;
2741 if (PyObject_SetAttrString(result, "left", value) == -1)
2742 goto failed;
2743 Py_DECREF(value);
2745 int i, n = asdl_seq_LEN(o->v.Compare.ops);
2746 value = PyList_New(n);
2747 if (!value) goto failed;
2748 for(i = 0; i < n; i++)
2749 PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
2751 if (!value) goto failed;
2752 if (PyObject_SetAttrString(result, "ops", value) == -1)
2753 goto failed;
2754 Py_DECREF(value);
2755 value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
2756 if (!value) goto failed;
2757 if (PyObject_SetAttrString(result, "comparators", value) == -1)
2758 goto failed;
2759 Py_DECREF(value);
2760 break;
2761 case Call_kind:
2762 result = PyType_GenericNew(Call_type, NULL, NULL);
2763 if (!result) goto failed;
2764 value = ast2obj_expr(o->v.Call.func);
2765 if (!value) goto failed;
2766 if (PyObject_SetAttrString(result, "func", value) == -1)
2767 goto failed;
2768 Py_DECREF(value);
2769 value = ast2obj_list(o->v.Call.args, ast2obj_expr);
2770 if (!value) goto failed;
2771 if (PyObject_SetAttrString(result, "args", value) == -1)
2772 goto failed;
2773 Py_DECREF(value);
2774 value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
2775 if (!value) goto failed;
2776 if (PyObject_SetAttrString(result, "keywords", value) == -1)
2777 goto failed;
2778 Py_DECREF(value);
2779 value = ast2obj_expr(o->v.Call.starargs);
2780 if (!value) goto failed;
2781 if (PyObject_SetAttrString(result, "starargs", value) == -1)
2782 goto failed;
2783 Py_DECREF(value);
2784 value = ast2obj_expr(o->v.Call.kwargs);
2785 if (!value) goto failed;
2786 if (PyObject_SetAttrString(result, "kwargs", value) == -1)
2787 goto failed;
2788 Py_DECREF(value);
2789 break;
2790 case Repr_kind:
2791 result = PyType_GenericNew(Repr_type, NULL, NULL);
2792 if (!result) goto failed;
2793 value = ast2obj_expr(o->v.Repr.value);
2794 if (!value) goto failed;
2795 if (PyObject_SetAttrString(result, "value", value) == -1)
2796 goto failed;
2797 Py_DECREF(value);
2798 break;
2799 case Num_kind:
2800 result = PyType_GenericNew(Num_type, NULL, NULL);
2801 if (!result) goto failed;
2802 value = ast2obj_object(o->v.Num.n);
2803 if (!value) goto failed;
2804 if (PyObject_SetAttrString(result, "n", value) == -1)
2805 goto failed;
2806 Py_DECREF(value);
2807 break;
2808 case Str_kind:
2809 result = PyType_GenericNew(Str_type, NULL, NULL);
2810 if (!result) goto failed;
2811 value = ast2obj_string(o->v.Str.s);
2812 if (!value) goto failed;
2813 if (PyObject_SetAttrString(result, "s", value) == -1)
2814 goto failed;
2815 Py_DECREF(value);
2816 break;
2817 case Attribute_kind:
2818 result = PyType_GenericNew(Attribute_type, NULL, NULL);
2819 if (!result) goto failed;
2820 value = ast2obj_expr(o->v.Attribute.value);
2821 if (!value) goto failed;
2822 if (PyObject_SetAttrString(result, "value", value) == -1)
2823 goto failed;
2824 Py_DECREF(value);
2825 value = ast2obj_identifier(o->v.Attribute.attr);
2826 if (!value) goto failed;
2827 if (PyObject_SetAttrString(result, "attr", value) == -1)
2828 goto failed;
2829 Py_DECREF(value);
2830 value = ast2obj_expr_context(o->v.Attribute.ctx);
2831 if (!value) goto failed;
2832 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2833 goto failed;
2834 Py_DECREF(value);
2835 break;
2836 case Subscript_kind:
2837 result = PyType_GenericNew(Subscript_type, NULL, NULL);
2838 if (!result) goto failed;
2839 value = ast2obj_expr(o->v.Subscript.value);
2840 if (!value) goto failed;
2841 if (PyObject_SetAttrString(result, "value", value) == -1)
2842 goto failed;
2843 Py_DECREF(value);
2844 value = ast2obj_slice(o->v.Subscript.slice);
2845 if (!value) goto failed;
2846 if (PyObject_SetAttrString(result, "slice", value) == -1)
2847 goto failed;
2848 Py_DECREF(value);
2849 value = ast2obj_expr_context(o->v.Subscript.ctx);
2850 if (!value) goto failed;
2851 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2852 goto failed;
2853 Py_DECREF(value);
2854 break;
2855 case Name_kind:
2856 result = PyType_GenericNew(Name_type, NULL, NULL);
2857 if (!result) goto failed;
2858 value = ast2obj_identifier(o->v.Name.id);
2859 if (!value) goto failed;
2860 if (PyObject_SetAttrString(result, "id", value) == -1)
2861 goto failed;
2862 Py_DECREF(value);
2863 value = ast2obj_expr_context(o->v.Name.ctx);
2864 if (!value) goto failed;
2865 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2866 goto failed;
2867 Py_DECREF(value);
2868 break;
2869 case List_kind:
2870 result = PyType_GenericNew(List_type, NULL, NULL);
2871 if (!result) goto failed;
2872 value = ast2obj_list(o->v.List.elts, ast2obj_expr);
2873 if (!value) goto failed;
2874 if (PyObject_SetAttrString(result, "elts", value) == -1)
2875 goto failed;
2876 Py_DECREF(value);
2877 value = ast2obj_expr_context(o->v.List.ctx);
2878 if (!value) goto failed;
2879 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2880 goto failed;
2881 Py_DECREF(value);
2882 break;
2883 case Tuple_kind:
2884 result = PyType_GenericNew(Tuple_type, NULL, NULL);
2885 if (!result) goto failed;
2886 value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
2887 if (!value) goto failed;
2888 if (PyObject_SetAttrString(result, "elts", value) == -1)
2889 goto failed;
2890 Py_DECREF(value);
2891 value = ast2obj_expr_context(o->v.Tuple.ctx);
2892 if (!value) goto failed;
2893 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2894 goto failed;
2895 Py_DECREF(value);
2896 break;
2898 value = ast2obj_int(o->lineno);
2899 if (!value) goto failed;
2900 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2901 goto failed;
2902 Py_DECREF(value);
2903 value = ast2obj_int(o->col_offset);
2904 if (!value) goto failed;
2905 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2906 goto failed;
2907 Py_DECREF(value);
2908 return result;
2909 failed:
2910 Py_XDECREF(value);
2911 Py_XDECREF(result);
2912 return NULL;
2915 PyObject* ast2obj_expr_context(expr_context_ty o)
2917 switch(o) {
2918 case Load:
2919 Py_INCREF(Load_singleton);
2920 return Load_singleton;
2921 case Store:
2922 Py_INCREF(Store_singleton);
2923 return Store_singleton;
2924 case Del:
2925 Py_INCREF(Del_singleton);
2926 return Del_singleton;
2927 case AugLoad:
2928 Py_INCREF(AugLoad_singleton);
2929 return AugLoad_singleton;
2930 case AugStore:
2931 Py_INCREF(AugStore_singleton);
2932 return AugStore_singleton;
2933 case Param:
2934 Py_INCREF(Param_singleton);
2935 return Param_singleton;
2936 default:
2937 /* should never happen, but just in case ... */
2938 PyErr_Format(PyExc_SystemError, "unknown expr_context found");
2939 return NULL;
2942 PyObject*
2943 ast2obj_slice(void* _o)
2945 slice_ty o = (slice_ty)_o;
2946 PyObject *result = NULL, *value = NULL;
2947 if (!o) {
2948 Py_INCREF(Py_None);
2949 return Py_None;
2952 switch (o->kind) {
2953 case Ellipsis_kind:
2954 result = PyType_GenericNew(Ellipsis_type, NULL, NULL);
2955 if (!result) goto failed;
2956 break;
2957 case Slice_kind:
2958 result = PyType_GenericNew(Slice_type, NULL, NULL);
2959 if (!result) goto failed;
2960 value = ast2obj_expr(o->v.Slice.lower);
2961 if (!value) goto failed;
2962 if (PyObject_SetAttrString(result, "lower", value) == -1)
2963 goto failed;
2964 Py_DECREF(value);
2965 value = ast2obj_expr(o->v.Slice.upper);
2966 if (!value) goto failed;
2967 if (PyObject_SetAttrString(result, "upper", value) == -1)
2968 goto failed;
2969 Py_DECREF(value);
2970 value = ast2obj_expr(o->v.Slice.step);
2971 if (!value) goto failed;
2972 if (PyObject_SetAttrString(result, "step", value) == -1)
2973 goto failed;
2974 Py_DECREF(value);
2975 break;
2976 case ExtSlice_kind:
2977 result = PyType_GenericNew(ExtSlice_type, NULL, NULL);
2978 if (!result) goto failed;
2979 value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice);
2980 if (!value) goto failed;
2981 if (PyObject_SetAttrString(result, "dims", value) == -1)
2982 goto failed;
2983 Py_DECREF(value);
2984 break;
2985 case Index_kind:
2986 result = PyType_GenericNew(Index_type, NULL, NULL);
2987 if (!result) goto failed;
2988 value = ast2obj_expr(o->v.Index.value);
2989 if (!value) goto failed;
2990 if (PyObject_SetAttrString(result, "value", value) == -1)
2991 goto failed;
2992 Py_DECREF(value);
2993 break;
2995 return result;
2996 failed:
2997 Py_XDECREF(value);
2998 Py_XDECREF(result);
2999 return NULL;
3002 PyObject* ast2obj_boolop(boolop_ty o)
3004 switch(o) {
3005 case And:
3006 Py_INCREF(And_singleton);
3007 return And_singleton;
3008 case Or:
3009 Py_INCREF(Or_singleton);
3010 return Or_singleton;
3011 default:
3012 /* should never happen, but just in case ... */
3013 PyErr_Format(PyExc_SystemError, "unknown boolop found");
3014 return NULL;
3017 PyObject* ast2obj_operator(operator_ty o)
3019 switch(o) {
3020 case Add:
3021 Py_INCREF(Add_singleton);
3022 return Add_singleton;
3023 case Sub:
3024 Py_INCREF(Sub_singleton);
3025 return Sub_singleton;
3026 case Mult:
3027 Py_INCREF(Mult_singleton);
3028 return Mult_singleton;
3029 case Div:
3030 Py_INCREF(Div_singleton);
3031 return Div_singleton;
3032 case Mod:
3033 Py_INCREF(Mod_singleton);
3034 return Mod_singleton;
3035 case Pow:
3036 Py_INCREF(Pow_singleton);
3037 return Pow_singleton;
3038 case LShift:
3039 Py_INCREF(LShift_singleton);
3040 return LShift_singleton;
3041 case RShift:
3042 Py_INCREF(RShift_singleton);
3043 return RShift_singleton;
3044 case BitOr:
3045 Py_INCREF(BitOr_singleton);
3046 return BitOr_singleton;
3047 case BitXor:
3048 Py_INCREF(BitXor_singleton);
3049 return BitXor_singleton;
3050 case BitAnd:
3051 Py_INCREF(BitAnd_singleton);
3052 return BitAnd_singleton;
3053 case FloorDiv:
3054 Py_INCREF(FloorDiv_singleton);
3055 return FloorDiv_singleton;
3056 default:
3057 /* should never happen, but just in case ... */
3058 PyErr_Format(PyExc_SystemError, "unknown operator found");
3059 return NULL;
3062 PyObject* ast2obj_unaryop(unaryop_ty o)
3064 switch(o) {
3065 case Invert:
3066 Py_INCREF(Invert_singleton);
3067 return Invert_singleton;
3068 case Not:
3069 Py_INCREF(Not_singleton);
3070 return Not_singleton;
3071 case UAdd:
3072 Py_INCREF(UAdd_singleton);
3073 return UAdd_singleton;
3074 case USub:
3075 Py_INCREF(USub_singleton);
3076 return USub_singleton;
3077 default:
3078 /* should never happen, but just in case ... */
3079 PyErr_Format(PyExc_SystemError, "unknown unaryop found");
3080 return NULL;
3083 PyObject* ast2obj_cmpop(cmpop_ty o)
3085 switch(o) {
3086 case Eq:
3087 Py_INCREF(Eq_singleton);
3088 return Eq_singleton;
3089 case NotEq:
3090 Py_INCREF(NotEq_singleton);
3091 return NotEq_singleton;
3092 case Lt:
3093 Py_INCREF(Lt_singleton);
3094 return Lt_singleton;
3095 case LtE:
3096 Py_INCREF(LtE_singleton);
3097 return LtE_singleton;
3098 case Gt:
3099 Py_INCREF(Gt_singleton);
3100 return Gt_singleton;
3101 case GtE:
3102 Py_INCREF(GtE_singleton);
3103 return GtE_singleton;
3104 case Is:
3105 Py_INCREF(Is_singleton);
3106 return Is_singleton;
3107 case IsNot:
3108 Py_INCREF(IsNot_singleton);
3109 return IsNot_singleton;
3110 case In:
3111 Py_INCREF(In_singleton);
3112 return In_singleton;
3113 case NotIn:
3114 Py_INCREF(NotIn_singleton);
3115 return NotIn_singleton;
3116 default:
3117 /* should never happen, but just in case ... */
3118 PyErr_Format(PyExc_SystemError, "unknown cmpop found");
3119 return NULL;
3122 PyObject*
3123 ast2obj_comprehension(void* _o)
3125 comprehension_ty o = (comprehension_ty)_o;
3126 PyObject *result = NULL, *value = NULL;
3127 if (!o) {
3128 Py_INCREF(Py_None);
3129 return Py_None;
3132 result = PyType_GenericNew(comprehension_type, NULL, NULL);
3133 if (!result) return NULL;
3134 value = ast2obj_expr(o->target);
3135 if (!value) goto failed;
3136 if (PyObject_SetAttrString(result, "target", value) == -1)
3137 goto failed;
3138 Py_DECREF(value);
3139 value = ast2obj_expr(o->iter);
3140 if (!value) goto failed;
3141 if (PyObject_SetAttrString(result, "iter", value) == -1)
3142 goto failed;
3143 Py_DECREF(value);
3144 value = ast2obj_list(o->ifs, ast2obj_expr);
3145 if (!value) goto failed;
3146 if (PyObject_SetAttrString(result, "ifs", value) == -1)
3147 goto failed;
3148 Py_DECREF(value);
3149 return result;
3150 failed:
3151 Py_XDECREF(value);
3152 Py_XDECREF(result);
3153 return NULL;
3156 PyObject*
3157 ast2obj_excepthandler(void* _o)
3159 excepthandler_ty o = (excepthandler_ty)_o;
3160 PyObject *result = NULL, *value = NULL;
3161 if (!o) {
3162 Py_INCREF(Py_None);
3163 return Py_None;
3166 switch (o->kind) {
3167 case ExceptHandler_kind:
3168 result = PyType_GenericNew(ExceptHandler_type, NULL, NULL);
3169 if (!result) goto failed;
3170 value = ast2obj_expr(o->v.ExceptHandler.type);
3171 if (!value) goto failed;
3172 if (PyObject_SetAttrString(result, "type", value) == -1)
3173 goto failed;
3174 Py_DECREF(value);
3175 value = ast2obj_expr(o->v.ExceptHandler.name);
3176 if (!value) goto failed;
3177 if (PyObject_SetAttrString(result, "name", value) == -1)
3178 goto failed;
3179 Py_DECREF(value);
3180 value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt);
3181 if (!value) goto failed;
3182 if (PyObject_SetAttrString(result, "body", value) == -1)
3183 goto failed;
3184 Py_DECREF(value);
3185 break;
3187 value = ast2obj_int(o->lineno);
3188 if (!value) goto failed;
3189 if (PyObject_SetAttrString(result, "lineno", value) < 0)
3190 goto failed;
3191 Py_DECREF(value);
3192 value = ast2obj_int(o->col_offset);
3193 if (!value) goto failed;
3194 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
3195 goto failed;
3196 Py_DECREF(value);
3197 return result;
3198 failed:
3199 Py_XDECREF(value);
3200 Py_XDECREF(result);
3201 return NULL;
3204 PyObject*
3205 ast2obj_arguments(void* _o)
3207 arguments_ty o = (arguments_ty)_o;
3208 PyObject *result = NULL, *value = NULL;
3209 if (!o) {
3210 Py_INCREF(Py_None);
3211 return Py_None;
3214 result = PyType_GenericNew(arguments_type, NULL, NULL);
3215 if (!result) return NULL;
3216 value = ast2obj_list(o->args, ast2obj_expr);
3217 if (!value) goto failed;
3218 if (PyObject_SetAttrString(result, "args", value) == -1)
3219 goto failed;
3220 Py_DECREF(value);
3221 value = ast2obj_identifier(o->vararg);
3222 if (!value) goto failed;
3223 if (PyObject_SetAttrString(result, "vararg", value) == -1)
3224 goto failed;
3225 Py_DECREF(value);
3226 value = ast2obj_identifier(o->kwarg);
3227 if (!value) goto failed;
3228 if (PyObject_SetAttrString(result, "kwarg", value) == -1)
3229 goto failed;
3230 Py_DECREF(value);
3231 value = ast2obj_list(o->defaults, ast2obj_expr);
3232 if (!value) goto failed;
3233 if (PyObject_SetAttrString(result, "defaults", value) == -1)
3234 goto failed;
3235 Py_DECREF(value);
3236 return result;
3237 failed:
3238 Py_XDECREF(value);
3239 Py_XDECREF(result);
3240 return NULL;
3243 PyObject*
3244 ast2obj_keyword(void* _o)
3246 keyword_ty o = (keyword_ty)_o;
3247 PyObject *result = NULL, *value = NULL;
3248 if (!o) {
3249 Py_INCREF(Py_None);
3250 return Py_None;
3253 result = PyType_GenericNew(keyword_type, NULL, NULL);
3254 if (!result) return NULL;
3255 value = ast2obj_identifier(o->arg);
3256 if (!value) goto failed;
3257 if (PyObject_SetAttrString(result, "arg", value) == -1)
3258 goto failed;
3259 Py_DECREF(value);
3260 value = ast2obj_expr(o->value);
3261 if (!value) goto failed;
3262 if (PyObject_SetAttrString(result, "value", value) == -1)
3263 goto failed;
3264 Py_DECREF(value);
3265 return result;
3266 failed:
3267 Py_XDECREF(value);
3268 Py_XDECREF(result);
3269 return NULL;
3272 PyObject*
3273 ast2obj_alias(void* _o)
3275 alias_ty o = (alias_ty)_o;
3276 PyObject *result = NULL, *value = NULL;
3277 if (!o) {
3278 Py_INCREF(Py_None);
3279 return Py_None;
3282 result = PyType_GenericNew(alias_type, NULL, NULL);
3283 if (!result) return NULL;
3284 value = ast2obj_identifier(o->name);
3285 if (!value) goto failed;
3286 if (PyObject_SetAttrString(result, "name", value) == -1)
3287 goto failed;
3288 Py_DECREF(value);
3289 value = ast2obj_identifier(o->asname);
3290 if (!value) goto failed;
3291 if (PyObject_SetAttrString(result, "asname", value) == -1)
3292 goto failed;
3293 Py_DECREF(value);
3294 return result;
3295 failed:
3296 Py_XDECREF(value);
3297 Py_XDECREF(result);
3298 return NULL;
3303 obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena)
3305 PyObject* tmp = NULL;
3306 int isinstance;
3309 if (obj == Py_None) {
3310 *out = NULL;
3311 return 0;
3313 isinstance = PyObject_IsInstance(obj, (PyObject*)Module_type);
3314 if (isinstance == -1) {
3315 return 1;
3317 if (isinstance) {
3318 asdl_seq* body;
3320 if (PyObject_HasAttrString(obj, "body")) {
3321 int res;
3322 Py_ssize_t len;
3323 Py_ssize_t i;
3324 tmp = PyObject_GetAttrString(obj, "body");
3325 if (tmp == NULL) goto failed;
3326 if (!PyList_Check(tmp)) {
3327 PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3328 goto failed;
3330 len = PyList_GET_SIZE(tmp);
3331 body = asdl_seq_new(len, arena);
3332 if (body == NULL) goto failed;
3333 for (i = 0; i < len; i++) {
3334 stmt_ty value;
3335 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
3336 if (res != 0) goto failed;
3337 asdl_seq_SET(body, i, value);
3339 Py_XDECREF(tmp);
3340 tmp = NULL;
3341 } else {
3342 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module");
3343 return 1;
3345 *out = Module(body, arena);
3346 if (*out == NULL) goto failed;
3347 return 0;
3349 isinstance = PyObject_IsInstance(obj, (PyObject*)Interactive_type);
3350 if (isinstance == -1) {
3351 return 1;
3353 if (isinstance) {
3354 asdl_seq* body;
3356 if (PyObject_HasAttrString(obj, "body")) {
3357 int res;
3358 Py_ssize_t len;
3359 Py_ssize_t i;
3360 tmp = PyObject_GetAttrString(obj, "body");
3361 if (tmp == NULL) goto failed;
3362 if (!PyList_Check(tmp)) {
3363 PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3364 goto failed;
3366 len = PyList_GET_SIZE(tmp);
3367 body = asdl_seq_new(len, arena);
3368 if (body == NULL) goto failed;
3369 for (i = 0; i < len; i++) {
3370 stmt_ty value;
3371 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
3372 if (res != 0) goto failed;
3373 asdl_seq_SET(body, i, value);
3375 Py_XDECREF(tmp);
3376 tmp = NULL;
3377 } else {
3378 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive");
3379 return 1;
3381 *out = Interactive(body, arena);
3382 if (*out == NULL) goto failed;
3383 return 0;
3385 isinstance = PyObject_IsInstance(obj, (PyObject*)Expression_type);
3386 if (isinstance == -1) {
3387 return 1;
3389 if (isinstance) {
3390 expr_ty body;
3392 if (PyObject_HasAttrString(obj, "body")) {
3393 int res;
3394 tmp = PyObject_GetAttrString(obj, "body");
3395 if (tmp == NULL) goto failed;
3396 res = obj2ast_expr(tmp, &body, arena);
3397 if (res != 0) goto failed;
3398 Py_XDECREF(tmp);
3399 tmp = NULL;
3400 } else {
3401 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression");
3402 return 1;
3404 *out = Expression(body, arena);
3405 if (*out == NULL) goto failed;
3406 return 0;
3408 isinstance = PyObject_IsInstance(obj, (PyObject*)Suite_type);
3409 if (isinstance == -1) {
3410 return 1;
3412 if (isinstance) {
3413 asdl_seq* body;
3415 if (PyObject_HasAttrString(obj, "body")) {
3416 int res;
3417 Py_ssize_t len;
3418 Py_ssize_t i;
3419 tmp = PyObject_GetAttrString(obj, "body");
3420 if (tmp == NULL) goto failed;
3421 if (!PyList_Check(tmp)) {
3422 PyErr_Format(PyExc_TypeError, "Suite field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3423 goto failed;
3425 len = PyList_GET_SIZE(tmp);
3426 body = asdl_seq_new(len, arena);
3427 if (body == NULL) goto failed;
3428 for (i = 0; i < len; i++) {
3429 stmt_ty value;
3430 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
3431 if (res != 0) goto failed;
3432 asdl_seq_SET(body, i, value);
3434 Py_XDECREF(tmp);
3435 tmp = NULL;
3436 } else {
3437 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Suite");
3438 return 1;
3440 *out = Suite(body, arena);
3441 if (*out == NULL) goto failed;
3442 return 0;
3445 tmp = PyObject_Repr(obj);
3446 if (tmp == NULL) goto failed;
3447 PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %.400s", PyString_AS_STRING(tmp));
3448 failed:
3449 Py_XDECREF(tmp);
3450 return 1;
3454 obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
3456 PyObject* tmp = NULL;
3457 int isinstance;
3459 int lineno;
3460 int col_offset;
3462 if (obj == Py_None) {
3463 *out = NULL;
3464 return 0;
3466 if (PyObject_HasAttrString(obj, "lineno")) {
3467 int res;
3468 tmp = PyObject_GetAttrString(obj, "lineno");
3469 if (tmp == NULL) goto failed;
3470 res = obj2ast_int(tmp, &lineno, arena);
3471 if (res != 0) goto failed;
3472 Py_XDECREF(tmp);
3473 tmp = NULL;
3474 } else {
3475 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt");
3476 return 1;
3478 if (PyObject_HasAttrString(obj, "col_offset")) {
3479 int res;
3480 tmp = PyObject_GetAttrString(obj, "col_offset");
3481 if (tmp == NULL) goto failed;
3482 res = obj2ast_int(tmp, &col_offset, arena);
3483 if (res != 0) goto failed;
3484 Py_XDECREF(tmp);
3485 tmp = NULL;
3486 } else {
3487 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt");
3488 return 1;
3490 isinstance = PyObject_IsInstance(obj, (PyObject*)FunctionDef_type);
3491 if (isinstance == -1) {
3492 return 1;
3494 if (isinstance) {
3495 identifier name;
3496 arguments_ty args;
3497 asdl_seq* body;
3498 asdl_seq* decorator_list;
3500 if (PyObject_HasAttrString(obj, "name")) {
3501 int res;
3502 tmp = PyObject_GetAttrString(obj, "name");
3503 if (tmp == NULL) goto failed;
3504 res = obj2ast_identifier(tmp, &name, arena);
3505 if (res != 0) goto failed;
3506 Py_XDECREF(tmp);
3507 tmp = NULL;
3508 } else {
3509 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef");
3510 return 1;
3512 if (PyObject_HasAttrString(obj, "args")) {
3513 int res;
3514 tmp = PyObject_GetAttrString(obj, "args");
3515 if (tmp == NULL) goto failed;
3516 res = obj2ast_arguments(tmp, &args, arena);
3517 if (res != 0) goto failed;
3518 Py_XDECREF(tmp);
3519 tmp = NULL;
3520 } else {
3521 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef");
3522 return 1;
3524 if (PyObject_HasAttrString(obj, "body")) {
3525 int res;
3526 Py_ssize_t len;
3527 Py_ssize_t i;
3528 tmp = PyObject_GetAttrString(obj, "body");
3529 if (tmp == NULL) goto failed;
3530 if (!PyList_Check(tmp)) {
3531 PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3532 goto failed;
3534 len = PyList_GET_SIZE(tmp);
3535 body = asdl_seq_new(len, arena);
3536 if (body == NULL) goto failed;
3537 for (i = 0; i < len; i++) {
3538 stmt_ty value;
3539 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
3540 if (res != 0) goto failed;
3541 asdl_seq_SET(body, i, value);
3543 Py_XDECREF(tmp);
3544 tmp = NULL;
3545 } else {
3546 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef");
3547 return 1;
3549 if (PyObject_HasAttrString(obj, "decorator_list")) {
3550 int res;
3551 Py_ssize_t len;
3552 Py_ssize_t i;
3553 tmp = PyObject_GetAttrString(obj, "decorator_list");
3554 if (tmp == NULL) goto failed;
3555 if (!PyList_Check(tmp)) {
3556 PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3557 goto failed;
3559 len = PyList_GET_SIZE(tmp);
3560 decorator_list = asdl_seq_new(len, arena);
3561 if (decorator_list == NULL) goto failed;
3562 for (i = 0; i < len; i++) {
3563 expr_ty value;
3564 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
3565 if (res != 0) goto failed;
3566 asdl_seq_SET(decorator_list, i, value);
3568 Py_XDECREF(tmp);
3569 tmp = NULL;
3570 } else {
3571 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef");
3572 return 1;
3574 *out = FunctionDef(name, args, body, decorator_list, lineno,
3575 col_offset, arena);
3576 if (*out == NULL) goto failed;
3577 return 0;
3579 isinstance = PyObject_IsInstance(obj, (PyObject*)ClassDef_type);
3580 if (isinstance == -1) {
3581 return 1;
3583 if (isinstance) {
3584 identifier name;
3585 asdl_seq* bases;
3586 asdl_seq* body;
3587 asdl_seq* decorator_list;
3589 if (PyObject_HasAttrString(obj, "name")) {
3590 int res;
3591 tmp = PyObject_GetAttrString(obj, "name");
3592 if (tmp == NULL) goto failed;
3593 res = obj2ast_identifier(tmp, &name, arena);
3594 if (res != 0) goto failed;
3595 Py_XDECREF(tmp);
3596 tmp = NULL;
3597 } else {
3598 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef");
3599 return 1;
3601 if (PyObject_HasAttrString(obj, "bases")) {
3602 int res;
3603 Py_ssize_t len;
3604 Py_ssize_t i;
3605 tmp = PyObject_GetAttrString(obj, "bases");
3606 if (tmp == NULL) goto failed;
3607 if (!PyList_Check(tmp)) {
3608 PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3609 goto failed;
3611 len = PyList_GET_SIZE(tmp);
3612 bases = asdl_seq_new(len, arena);
3613 if (bases == NULL) goto failed;
3614 for (i = 0; i < len; i++) {
3615 expr_ty value;
3616 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
3617 if (res != 0) goto failed;
3618 asdl_seq_SET(bases, i, value);
3620 Py_XDECREF(tmp);
3621 tmp = NULL;
3622 } else {
3623 PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef");
3624 return 1;
3626 if (PyObject_HasAttrString(obj, "body")) {
3627 int res;
3628 Py_ssize_t len;
3629 Py_ssize_t i;
3630 tmp = PyObject_GetAttrString(obj, "body");
3631 if (tmp == NULL) goto failed;
3632 if (!PyList_Check(tmp)) {
3633 PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3634 goto failed;
3636 len = PyList_GET_SIZE(tmp);
3637 body = asdl_seq_new(len, arena);
3638 if (body == NULL) goto failed;
3639 for (i = 0; i < len; i++) {
3640 stmt_ty value;
3641 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
3642 if (res != 0) goto failed;
3643 asdl_seq_SET(body, i, value);
3645 Py_XDECREF(tmp);
3646 tmp = NULL;
3647 } else {
3648 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef");
3649 return 1;
3651 if (PyObject_HasAttrString(obj, "decorator_list")) {
3652 int res;
3653 Py_ssize_t len;
3654 Py_ssize_t i;
3655 tmp = PyObject_GetAttrString(obj, "decorator_list");
3656 if (tmp == NULL) goto failed;
3657 if (!PyList_Check(tmp)) {
3658 PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3659 goto failed;
3661 len = PyList_GET_SIZE(tmp);
3662 decorator_list = asdl_seq_new(len, arena);
3663 if (decorator_list == NULL) goto failed;
3664 for (i = 0; i < len; i++) {
3665 expr_ty value;
3666 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
3667 if (res != 0) goto failed;
3668 asdl_seq_SET(decorator_list, i, value);
3670 Py_XDECREF(tmp);
3671 tmp = NULL;
3672 } else {
3673 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef");
3674 return 1;
3676 *out = ClassDef(name, bases, body, decorator_list, lineno,
3677 col_offset, arena);
3678 if (*out == NULL) goto failed;
3679 return 0;
3681 isinstance = PyObject_IsInstance(obj, (PyObject*)Return_type);
3682 if (isinstance == -1) {
3683 return 1;
3685 if (isinstance) {
3686 expr_ty value;
3688 if (PyObject_HasAttrString(obj, "value")) {
3689 int res;
3690 tmp = PyObject_GetAttrString(obj, "value");
3691 if (tmp == NULL) goto failed;
3692 res = obj2ast_expr(tmp, &value, arena);
3693 if (res != 0) goto failed;
3694 Py_XDECREF(tmp);
3695 tmp = NULL;
3696 } else {
3697 value = NULL;
3699 *out = Return(value, lineno, col_offset, arena);
3700 if (*out == NULL) goto failed;
3701 return 0;
3703 isinstance = PyObject_IsInstance(obj, (PyObject*)Delete_type);
3704 if (isinstance == -1) {
3705 return 1;
3707 if (isinstance) {
3708 asdl_seq* targets;
3710 if (PyObject_HasAttrString(obj, "targets")) {
3711 int res;
3712 Py_ssize_t len;
3713 Py_ssize_t i;
3714 tmp = PyObject_GetAttrString(obj, "targets");
3715 if (tmp == NULL) goto failed;
3716 if (!PyList_Check(tmp)) {
3717 PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3718 goto failed;
3720 len = PyList_GET_SIZE(tmp);
3721 targets = asdl_seq_new(len, arena);
3722 if (targets == NULL) goto failed;
3723 for (i = 0; i < len; i++) {
3724 expr_ty value;
3725 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
3726 if (res != 0) goto failed;
3727 asdl_seq_SET(targets, i, value);
3729 Py_XDECREF(tmp);
3730 tmp = NULL;
3731 } else {
3732 PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete");
3733 return 1;
3735 *out = Delete(targets, lineno, col_offset, arena);
3736 if (*out == NULL) goto failed;
3737 return 0;
3739 isinstance = PyObject_IsInstance(obj, (PyObject*)Assign_type);
3740 if (isinstance == -1) {
3741 return 1;
3743 if (isinstance) {
3744 asdl_seq* targets;
3745 expr_ty value;
3747 if (PyObject_HasAttrString(obj, "targets")) {
3748 int res;
3749 Py_ssize_t len;
3750 Py_ssize_t i;
3751 tmp = PyObject_GetAttrString(obj, "targets");
3752 if (tmp == NULL) goto failed;
3753 if (!PyList_Check(tmp)) {
3754 PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3755 goto failed;
3757 len = PyList_GET_SIZE(tmp);
3758 targets = asdl_seq_new(len, arena);
3759 if (targets == NULL) goto failed;
3760 for (i = 0; i < len; i++) {
3761 expr_ty value;
3762 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
3763 if (res != 0) goto failed;
3764 asdl_seq_SET(targets, i, value);
3766 Py_XDECREF(tmp);
3767 tmp = NULL;
3768 } else {
3769 PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign");
3770 return 1;
3772 if (PyObject_HasAttrString(obj, "value")) {
3773 int res;
3774 tmp = PyObject_GetAttrString(obj, "value");
3775 if (tmp == NULL) goto failed;
3776 res = obj2ast_expr(tmp, &value, arena);
3777 if (res != 0) goto failed;
3778 Py_XDECREF(tmp);
3779 tmp = NULL;
3780 } else {
3781 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign");
3782 return 1;
3784 *out = Assign(targets, value, lineno, col_offset, arena);
3785 if (*out == NULL) goto failed;
3786 return 0;
3788 isinstance = PyObject_IsInstance(obj, (PyObject*)AugAssign_type);
3789 if (isinstance == -1) {
3790 return 1;
3792 if (isinstance) {
3793 expr_ty target;
3794 operator_ty op;
3795 expr_ty value;
3797 if (PyObject_HasAttrString(obj, "target")) {
3798 int res;
3799 tmp = PyObject_GetAttrString(obj, "target");
3800 if (tmp == NULL) goto failed;
3801 res = obj2ast_expr(tmp, &target, arena);
3802 if (res != 0) goto failed;
3803 Py_XDECREF(tmp);
3804 tmp = NULL;
3805 } else {
3806 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign");
3807 return 1;
3809 if (PyObject_HasAttrString(obj, "op")) {
3810 int res;
3811 tmp = PyObject_GetAttrString(obj, "op");
3812 if (tmp == NULL) goto failed;
3813 res = obj2ast_operator(tmp, &op, arena);
3814 if (res != 0) goto failed;
3815 Py_XDECREF(tmp);
3816 tmp = NULL;
3817 } else {
3818 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign");
3819 return 1;
3821 if (PyObject_HasAttrString(obj, "value")) {
3822 int res;
3823 tmp = PyObject_GetAttrString(obj, "value");
3824 if (tmp == NULL) goto failed;
3825 res = obj2ast_expr(tmp, &value, arena);
3826 if (res != 0) goto failed;
3827 Py_XDECREF(tmp);
3828 tmp = NULL;
3829 } else {
3830 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign");
3831 return 1;
3833 *out = AugAssign(target, op, value, lineno, col_offset, arena);
3834 if (*out == NULL) goto failed;
3835 return 0;
3837 isinstance = PyObject_IsInstance(obj, (PyObject*)Print_type);
3838 if (isinstance == -1) {
3839 return 1;
3841 if (isinstance) {
3842 expr_ty dest;
3843 asdl_seq* values;
3844 bool nl;
3846 if (PyObject_HasAttrString(obj, "dest")) {
3847 int res;
3848 tmp = PyObject_GetAttrString(obj, "dest");
3849 if (tmp == NULL) goto failed;
3850 res = obj2ast_expr(tmp, &dest, arena);
3851 if (res != 0) goto failed;
3852 Py_XDECREF(tmp);
3853 tmp = NULL;
3854 } else {
3855 dest = NULL;
3857 if (PyObject_HasAttrString(obj, "values")) {
3858 int res;
3859 Py_ssize_t len;
3860 Py_ssize_t i;
3861 tmp = PyObject_GetAttrString(obj, "values");
3862 if (tmp == NULL) goto failed;
3863 if (!PyList_Check(tmp)) {
3864 PyErr_Format(PyExc_TypeError, "Print field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3865 goto failed;
3867 len = PyList_GET_SIZE(tmp);
3868 values = asdl_seq_new(len, arena);
3869 if (values == NULL) goto failed;
3870 for (i = 0; i < len; i++) {
3871 expr_ty value;
3872 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
3873 if (res != 0) goto failed;
3874 asdl_seq_SET(values, i, value);
3876 Py_XDECREF(tmp);
3877 tmp = NULL;
3878 } else {
3879 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Print");
3880 return 1;
3882 if (PyObject_HasAttrString(obj, "nl")) {
3883 int res;
3884 tmp = PyObject_GetAttrString(obj, "nl");
3885 if (tmp == NULL) goto failed;
3886 res = obj2ast_bool(tmp, &nl, arena);
3887 if (res != 0) goto failed;
3888 Py_XDECREF(tmp);
3889 tmp = NULL;
3890 } else {
3891 PyErr_SetString(PyExc_TypeError, "required field \"nl\" missing from Print");
3892 return 1;
3894 *out = Print(dest, values, nl, lineno, col_offset, arena);
3895 if (*out == NULL) goto failed;
3896 return 0;
3898 isinstance = PyObject_IsInstance(obj, (PyObject*)For_type);
3899 if (isinstance == -1) {
3900 return 1;
3902 if (isinstance) {
3903 expr_ty target;
3904 expr_ty iter;
3905 asdl_seq* body;
3906 asdl_seq* orelse;
3908 if (PyObject_HasAttrString(obj, "target")) {
3909 int res;
3910 tmp = PyObject_GetAttrString(obj, "target");
3911 if (tmp == NULL) goto failed;
3912 res = obj2ast_expr(tmp, &target, arena);
3913 if (res != 0) goto failed;
3914 Py_XDECREF(tmp);
3915 tmp = NULL;
3916 } else {
3917 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For");
3918 return 1;
3920 if (PyObject_HasAttrString(obj, "iter")) {
3921 int res;
3922 tmp = PyObject_GetAttrString(obj, "iter");
3923 if (tmp == NULL) goto failed;
3924 res = obj2ast_expr(tmp, &iter, arena);
3925 if (res != 0) goto failed;
3926 Py_XDECREF(tmp);
3927 tmp = NULL;
3928 } else {
3929 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For");
3930 return 1;
3932 if (PyObject_HasAttrString(obj, "body")) {
3933 int res;
3934 Py_ssize_t len;
3935 Py_ssize_t i;
3936 tmp = PyObject_GetAttrString(obj, "body");
3937 if (tmp == NULL) goto failed;
3938 if (!PyList_Check(tmp)) {
3939 PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3940 goto failed;
3942 len = PyList_GET_SIZE(tmp);
3943 body = asdl_seq_new(len, arena);
3944 if (body == NULL) goto failed;
3945 for (i = 0; i < len; i++) {
3946 stmt_ty value;
3947 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
3948 if (res != 0) goto failed;
3949 asdl_seq_SET(body, i, value);
3951 Py_XDECREF(tmp);
3952 tmp = NULL;
3953 } else {
3954 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For");
3955 return 1;
3957 if (PyObject_HasAttrString(obj, "orelse")) {
3958 int res;
3959 Py_ssize_t len;
3960 Py_ssize_t i;
3961 tmp = PyObject_GetAttrString(obj, "orelse");
3962 if (tmp == NULL) goto failed;
3963 if (!PyList_Check(tmp)) {
3964 PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3965 goto failed;
3967 len = PyList_GET_SIZE(tmp);
3968 orelse = asdl_seq_new(len, arena);
3969 if (orelse == NULL) goto failed;
3970 for (i = 0; i < len; i++) {
3971 stmt_ty value;
3972 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
3973 if (res != 0) goto failed;
3974 asdl_seq_SET(orelse, i, value);
3976 Py_XDECREF(tmp);
3977 tmp = NULL;
3978 } else {
3979 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For");
3980 return 1;
3982 *out = For(target, iter, body, orelse, lineno, col_offset,
3983 arena);
3984 if (*out == NULL) goto failed;
3985 return 0;
3987 isinstance = PyObject_IsInstance(obj, (PyObject*)While_type);
3988 if (isinstance == -1) {
3989 return 1;
3991 if (isinstance) {
3992 expr_ty test;
3993 asdl_seq* body;
3994 asdl_seq* orelse;
3996 if (PyObject_HasAttrString(obj, "test")) {
3997 int res;
3998 tmp = PyObject_GetAttrString(obj, "test");
3999 if (tmp == NULL) goto failed;
4000 res = obj2ast_expr(tmp, &test, arena);
4001 if (res != 0) goto failed;
4002 Py_XDECREF(tmp);
4003 tmp = NULL;
4004 } else {
4005 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While");
4006 return 1;
4008 if (PyObject_HasAttrString(obj, "body")) {
4009 int res;
4010 Py_ssize_t len;
4011 Py_ssize_t i;
4012 tmp = PyObject_GetAttrString(obj, "body");
4013 if (tmp == NULL) goto failed;
4014 if (!PyList_Check(tmp)) {
4015 PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4016 goto failed;
4018 len = PyList_GET_SIZE(tmp);
4019 body = asdl_seq_new(len, arena);
4020 if (body == NULL) goto failed;
4021 for (i = 0; i < len; i++) {
4022 stmt_ty value;
4023 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
4024 if (res != 0) goto failed;
4025 asdl_seq_SET(body, i, value);
4027 Py_XDECREF(tmp);
4028 tmp = NULL;
4029 } else {
4030 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While");
4031 return 1;
4033 if (PyObject_HasAttrString(obj, "orelse")) {
4034 int res;
4035 Py_ssize_t len;
4036 Py_ssize_t i;
4037 tmp = PyObject_GetAttrString(obj, "orelse");
4038 if (tmp == NULL) goto failed;
4039 if (!PyList_Check(tmp)) {
4040 PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4041 goto failed;
4043 len = PyList_GET_SIZE(tmp);
4044 orelse = asdl_seq_new(len, arena);
4045 if (orelse == NULL) goto failed;
4046 for (i = 0; i < len; i++) {
4047 stmt_ty value;
4048 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
4049 if (res != 0) goto failed;
4050 asdl_seq_SET(orelse, i, value);
4052 Py_XDECREF(tmp);
4053 tmp = NULL;
4054 } else {
4055 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While");
4056 return 1;
4058 *out = While(test, body, orelse, lineno, col_offset, arena);
4059 if (*out == NULL) goto failed;
4060 return 0;
4062 isinstance = PyObject_IsInstance(obj, (PyObject*)If_type);
4063 if (isinstance == -1) {
4064 return 1;
4066 if (isinstance) {
4067 expr_ty test;
4068 asdl_seq* body;
4069 asdl_seq* orelse;
4071 if (PyObject_HasAttrString(obj, "test")) {
4072 int res;
4073 tmp = PyObject_GetAttrString(obj, "test");
4074 if (tmp == NULL) goto failed;
4075 res = obj2ast_expr(tmp, &test, arena);
4076 if (res != 0) goto failed;
4077 Py_XDECREF(tmp);
4078 tmp = NULL;
4079 } else {
4080 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If");
4081 return 1;
4083 if (PyObject_HasAttrString(obj, "body")) {
4084 int res;
4085 Py_ssize_t len;
4086 Py_ssize_t i;
4087 tmp = PyObject_GetAttrString(obj, "body");
4088 if (tmp == NULL) goto failed;
4089 if (!PyList_Check(tmp)) {
4090 PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4091 goto failed;
4093 len = PyList_GET_SIZE(tmp);
4094 body = asdl_seq_new(len, arena);
4095 if (body == NULL) goto failed;
4096 for (i = 0; i < len; i++) {
4097 stmt_ty value;
4098 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
4099 if (res != 0) goto failed;
4100 asdl_seq_SET(body, i, value);
4102 Py_XDECREF(tmp);
4103 tmp = NULL;
4104 } else {
4105 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If");
4106 return 1;
4108 if (PyObject_HasAttrString(obj, "orelse")) {
4109 int res;
4110 Py_ssize_t len;
4111 Py_ssize_t i;
4112 tmp = PyObject_GetAttrString(obj, "orelse");
4113 if (tmp == NULL) goto failed;
4114 if (!PyList_Check(tmp)) {
4115 PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4116 goto failed;
4118 len = PyList_GET_SIZE(tmp);
4119 orelse = asdl_seq_new(len, arena);
4120 if (orelse == NULL) goto failed;
4121 for (i = 0; i < len; i++) {
4122 stmt_ty value;
4123 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
4124 if (res != 0) goto failed;
4125 asdl_seq_SET(orelse, i, value);
4127 Py_XDECREF(tmp);
4128 tmp = NULL;
4129 } else {
4130 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If");
4131 return 1;
4133 *out = If(test, body, orelse, lineno, col_offset, arena);
4134 if (*out == NULL) goto failed;
4135 return 0;
4137 isinstance = PyObject_IsInstance(obj, (PyObject*)With_type);
4138 if (isinstance == -1) {
4139 return 1;
4141 if (isinstance) {
4142 expr_ty context_expr;
4143 expr_ty optional_vars;
4144 asdl_seq* body;
4146 if (PyObject_HasAttrString(obj, "context_expr")) {
4147 int res;
4148 tmp = PyObject_GetAttrString(obj, "context_expr");
4149 if (tmp == NULL) goto failed;
4150 res = obj2ast_expr(tmp, &context_expr, arena);
4151 if (res != 0) goto failed;
4152 Py_XDECREF(tmp);
4153 tmp = NULL;
4154 } else {
4155 PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from With");
4156 return 1;
4158 if (PyObject_HasAttrString(obj, "optional_vars")) {
4159 int res;
4160 tmp = PyObject_GetAttrString(obj, "optional_vars");
4161 if (tmp == NULL) goto failed;
4162 res = obj2ast_expr(tmp, &optional_vars, arena);
4163 if (res != 0) goto failed;
4164 Py_XDECREF(tmp);
4165 tmp = NULL;
4166 } else {
4167 optional_vars = NULL;
4169 if (PyObject_HasAttrString(obj, "body")) {
4170 int res;
4171 Py_ssize_t len;
4172 Py_ssize_t i;
4173 tmp = PyObject_GetAttrString(obj, "body");
4174 if (tmp == NULL) goto failed;
4175 if (!PyList_Check(tmp)) {
4176 PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4177 goto failed;
4179 len = PyList_GET_SIZE(tmp);
4180 body = asdl_seq_new(len, arena);
4181 if (body == NULL) goto failed;
4182 for (i = 0; i < len; i++) {
4183 stmt_ty value;
4184 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
4185 if (res != 0) goto failed;
4186 asdl_seq_SET(body, i, value);
4188 Py_XDECREF(tmp);
4189 tmp = NULL;
4190 } else {
4191 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With");
4192 return 1;
4194 *out = With(context_expr, optional_vars, body, lineno,
4195 col_offset, arena);
4196 if (*out == NULL) goto failed;
4197 return 0;
4199 isinstance = PyObject_IsInstance(obj, (PyObject*)Raise_type);
4200 if (isinstance == -1) {
4201 return 1;
4203 if (isinstance) {
4204 expr_ty type;
4205 expr_ty inst;
4206 expr_ty tback;
4208 if (PyObject_HasAttrString(obj, "type")) {
4209 int res;
4210 tmp = PyObject_GetAttrString(obj, "type");
4211 if (tmp == NULL) goto failed;
4212 res = obj2ast_expr(tmp, &type, arena);
4213 if (res != 0) goto failed;
4214 Py_XDECREF(tmp);
4215 tmp = NULL;
4216 } else {
4217 type = NULL;
4219 if (PyObject_HasAttrString(obj, "inst")) {
4220 int res;
4221 tmp = PyObject_GetAttrString(obj, "inst");
4222 if (tmp == NULL) goto failed;
4223 res = obj2ast_expr(tmp, &inst, arena);
4224 if (res != 0) goto failed;
4225 Py_XDECREF(tmp);
4226 tmp = NULL;
4227 } else {
4228 inst = NULL;
4230 if (PyObject_HasAttrString(obj, "tback")) {
4231 int res;
4232 tmp = PyObject_GetAttrString(obj, "tback");
4233 if (tmp == NULL) goto failed;
4234 res = obj2ast_expr(tmp, &tback, arena);
4235 if (res != 0) goto failed;
4236 Py_XDECREF(tmp);
4237 tmp = NULL;
4238 } else {
4239 tback = NULL;
4241 *out = Raise(type, inst, tback, lineno, col_offset, arena);
4242 if (*out == NULL) goto failed;
4243 return 0;
4245 isinstance = PyObject_IsInstance(obj, (PyObject*)TryExcept_type);
4246 if (isinstance == -1) {
4247 return 1;
4249 if (isinstance) {
4250 asdl_seq* body;
4251 asdl_seq* handlers;
4252 asdl_seq* orelse;
4254 if (PyObject_HasAttrString(obj, "body")) {
4255 int res;
4256 Py_ssize_t len;
4257 Py_ssize_t i;
4258 tmp = PyObject_GetAttrString(obj, "body");
4259 if (tmp == NULL) goto failed;
4260 if (!PyList_Check(tmp)) {
4261 PyErr_Format(PyExc_TypeError, "TryExcept field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4262 goto failed;
4264 len = PyList_GET_SIZE(tmp);
4265 body = asdl_seq_new(len, arena);
4266 if (body == NULL) goto failed;
4267 for (i = 0; i < len; i++) {
4268 stmt_ty value;
4269 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
4270 if (res != 0) goto failed;
4271 asdl_seq_SET(body, i, value);
4273 Py_XDECREF(tmp);
4274 tmp = NULL;
4275 } else {
4276 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from TryExcept");
4277 return 1;
4279 if (PyObject_HasAttrString(obj, "handlers")) {
4280 int res;
4281 Py_ssize_t len;
4282 Py_ssize_t i;
4283 tmp = PyObject_GetAttrString(obj, "handlers");
4284 if (tmp == NULL) goto failed;
4285 if (!PyList_Check(tmp)) {
4286 PyErr_Format(PyExc_TypeError, "TryExcept field \"handlers\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4287 goto failed;
4289 len = PyList_GET_SIZE(tmp);
4290 handlers = asdl_seq_new(len, arena);
4291 if (handlers == NULL) goto failed;
4292 for (i = 0; i < len; i++) {
4293 excepthandler_ty value;
4294 res = obj2ast_excepthandler(PyList_GET_ITEM(tmp, i), &value, arena);
4295 if (res != 0) goto failed;
4296 asdl_seq_SET(handlers, i, value);
4298 Py_XDECREF(tmp);
4299 tmp = NULL;
4300 } else {
4301 PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from TryExcept");
4302 return 1;
4304 if (PyObject_HasAttrString(obj, "orelse")) {
4305 int res;
4306 Py_ssize_t len;
4307 Py_ssize_t i;
4308 tmp = PyObject_GetAttrString(obj, "orelse");
4309 if (tmp == NULL) goto failed;
4310 if (!PyList_Check(tmp)) {
4311 PyErr_Format(PyExc_TypeError, "TryExcept field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4312 goto failed;
4314 len = PyList_GET_SIZE(tmp);
4315 orelse = asdl_seq_new(len, arena);
4316 if (orelse == NULL) goto failed;
4317 for (i = 0; i < len; i++) {
4318 stmt_ty value;
4319 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
4320 if (res != 0) goto failed;
4321 asdl_seq_SET(orelse, i, value);
4323 Py_XDECREF(tmp);
4324 tmp = NULL;
4325 } else {
4326 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from TryExcept");
4327 return 1;
4329 *out = TryExcept(body, handlers, orelse, lineno, col_offset,
4330 arena);
4331 if (*out == NULL) goto failed;
4332 return 0;
4334 isinstance = PyObject_IsInstance(obj, (PyObject*)TryFinally_type);
4335 if (isinstance == -1) {
4336 return 1;
4338 if (isinstance) {
4339 asdl_seq* body;
4340 asdl_seq* finalbody;
4342 if (PyObject_HasAttrString(obj, "body")) {
4343 int res;
4344 Py_ssize_t len;
4345 Py_ssize_t i;
4346 tmp = PyObject_GetAttrString(obj, "body");
4347 if (tmp == NULL) goto failed;
4348 if (!PyList_Check(tmp)) {
4349 PyErr_Format(PyExc_TypeError, "TryFinally field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4350 goto failed;
4352 len = PyList_GET_SIZE(tmp);
4353 body = asdl_seq_new(len, arena);
4354 if (body == NULL) goto failed;
4355 for (i = 0; i < len; i++) {
4356 stmt_ty value;
4357 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
4358 if (res != 0) goto failed;
4359 asdl_seq_SET(body, i, value);
4361 Py_XDECREF(tmp);
4362 tmp = NULL;
4363 } else {
4364 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from TryFinally");
4365 return 1;
4367 if (PyObject_HasAttrString(obj, "finalbody")) {
4368 int res;
4369 Py_ssize_t len;
4370 Py_ssize_t i;
4371 tmp = PyObject_GetAttrString(obj, "finalbody");
4372 if (tmp == NULL) goto failed;
4373 if (!PyList_Check(tmp)) {
4374 PyErr_Format(PyExc_TypeError, "TryFinally field \"finalbody\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4375 goto failed;
4377 len = PyList_GET_SIZE(tmp);
4378 finalbody = asdl_seq_new(len, arena);
4379 if (finalbody == NULL) goto failed;
4380 for (i = 0; i < len; i++) {
4381 stmt_ty value;
4382 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
4383 if (res != 0) goto failed;
4384 asdl_seq_SET(finalbody, i, value);
4386 Py_XDECREF(tmp);
4387 tmp = NULL;
4388 } else {
4389 PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from TryFinally");
4390 return 1;
4392 *out = TryFinally(body, finalbody, lineno, col_offset, arena);
4393 if (*out == NULL) goto failed;
4394 return 0;
4396 isinstance = PyObject_IsInstance(obj, (PyObject*)Assert_type);
4397 if (isinstance == -1) {
4398 return 1;
4400 if (isinstance) {
4401 expr_ty test;
4402 expr_ty msg;
4404 if (PyObject_HasAttrString(obj, "test")) {
4405 int res;
4406 tmp = PyObject_GetAttrString(obj, "test");
4407 if (tmp == NULL) goto failed;
4408 res = obj2ast_expr(tmp, &test, arena);
4409 if (res != 0) goto failed;
4410 Py_XDECREF(tmp);
4411 tmp = NULL;
4412 } else {
4413 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert");
4414 return 1;
4416 if (PyObject_HasAttrString(obj, "msg")) {
4417 int res;
4418 tmp = PyObject_GetAttrString(obj, "msg");
4419 if (tmp == NULL) goto failed;
4420 res = obj2ast_expr(tmp, &msg, arena);
4421 if (res != 0) goto failed;
4422 Py_XDECREF(tmp);
4423 tmp = NULL;
4424 } else {
4425 msg = NULL;
4427 *out = Assert(test, msg, lineno, col_offset, arena);
4428 if (*out == NULL) goto failed;
4429 return 0;
4431 isinstance = PyObject_IsInstance(obj, (PyObject*)Import_type);
4432 if (isinstance == -1) {
4433 return 1;
4435 if (isinstance) {
4436 asdl_seq* names;
4438 if (PyObject_HasAttrString(obj, "names")) {
4439 int res;
4440 Py_ssize_t len;
4441 Py_ssize_t i;
4442 tmp = PyObject_GetAttrString(obj, "names");
4443 if (tmp == NULL) goto failed;
4444 if (!PyList_Check(tmp)) {
4445 PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4446 goto failed;
4448 len = PyList_GET_SIZE(tmp);
4449 names = asdl_seq_new(len, arena);
4450 if (names == NULL) goto failed;
4451 for (i = 0; i < len; i++) {
4452 alias_ty value;
4453 res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena);
4454 if (res != 0) goto failed;
4455 asdl_seq_SET(names, i, value);
4457 Py_XDECREF(tmp);
4458 tmp = NULL;
4459 } else {
4460 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import");
4461 return 1;
4463 *out = Import(names, lineno, col_offset, arena);
4464 if (*out == NULL) goto failed;
4465 return 0;
4467 isinstance = PyObject_IsInstance(obj, (PyObject*)ImportFrom_type);
4468 if (isinstance == -1) {
4469 return 1;
4471 if (isinstance) {
4472 identifier module;
4473 asdl_seq* names;
4474 int level;
4476 if (PyObject_HasAttrString(obj, "module")) {
4477 int res;
4478 tmp = PyObject_GetAttrString(obj, "module");
4479 if (tmp == NULL) goto failed;
4480 res = obj2ast_identifier(tmp, &module, arena);
4481 if (res != 0) goto failed;
4482 Py_XDECREF(tmp);
4483 tmp = NULL;
4484 } else {
4485 module = NULL;
4487 if (PyObject_HasAttrString(obj, "names")) {
4488 int res;
4489 Py_ssize_t len;
4490 Py_ssize_t i;
4491 tmp = PyObject_GetAttrString(obj, "names");
4492 if (tmp == NULL) goto failed;
4493 if (!PyList_Check(tmp)) {
4494 PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4495 goto failed;
4497 len = PyList_GET_SIZE(tmp);
4498 names = asdl_seq_new(len, arena);
4499 if (names == NULL) goto failed;
4500 for (i = 0; i < len; i++) {
4501 alias_ty value;
4502 res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena);
4503 if (res != 0) goto failed;
4504 asdl_seq_SET(names, i, value);
4506 Py_XDECREF(tmp);
4507 tmp = NULL;
4508 } else {
4509 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom");
4510 return 1;
4512 if (PyObject_HasAttrString(obj, "level")) {
4513 int res;
4514 tmp = PyObject_GetAttrString(obj, "level");
4515 if (tmp == NULL) goto failed;
4516 res = obj2ast_int(tmp, &level, arena);
4517 if (res != 0) goto failed;
4518 Py_XDECREF(tmp);
4519 tmp = NULL;
4520 } else {
4521 level = 0;
4523 *out = ImportFrom(module, names, level, lineno, col_offset,
4524 arena);
4525 if (*out == NULL) goto failed;
4526 return 0;
4528 isinstance = PyObject_IsInstance(obj, (PyObject*)Exec_type);
4529 if (isinstance == -1) {
4530 return 1;
4532 if (isinstance) {
4533 expr_ty body;
4534 expr_ty globals;
4535 expr_ty locals;
4537 if (PyObject_HasAttrString(obj, "body")) {
4538 int res;
4539 tmp = PyObject_GetAttrString(obj, "body");
4540 if (tmp == NULL) goto failed;
4541 res = obj2ast_expr(tmp, &body, arena);
4542 if (res != 0) goto failed;
4543 Py_XDECREF(tmp);
4544 tmp = NULL;
4545 } else {
4546 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Exec");
4547 return 1;
4549 if (PyObject_HasAttrString(obj, "globals")) {
4550 int res;
4551 tmp = PyObject_GetAttrString(obj, "globals");
4552 if (tmp == NULL) goto failed;
4553 res = obj2ast_expr(tmp, &globals, arena);
4554 if (res != 0) goto failed;
4555 Py_XDECREF(tmp);
4556 tmp = NULL;
4557 } else {
4558 globals = NULL;
4560 if (PyObject_HasAttrString(obj, "locals")) {
4561 int res;
4562 tmp = PyObject_GetAttrString(obj, "locals");
4563 if (tmp == NULL) goto failed;
4564 res = obj2ast_expr(tmp, &locals, arena);
4565 if (res != 0) goto failed;
4566 Py_XDECREF(tmp);
4567 tmp = NULL;
4568 } else {
4569 locals = NULL;
4571 *out = Exec(body, globals, locals, lineno, col_offset, arena);
4572 if (*out == NULL) goto failed;
4573 return 0;
4575 isinstance = PyObject_IsInstance(obj, (PyObject*)Global_type);
4576 if (isinstance == -1) {
4577 return 1;
4579 if (isinstance) {
4580 asdl_seq* names;
4582 if (PyObject_HasAttrString(obj, "names")) {
4583 int res;
4584 Py_ssize_t len;
4585 Py_ssize_t i;
4586 tmp = PyObject_GetAttrString(obj, "names");
4587 if (tmp == NULL) goto failed;
4588 if (!PyList_Check(tmp)) {
4589 PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4590 goto failed;
4592 len = PyList_GET_SIZE(tmp);
4593 names = asdl_seq_new(len, arena);
4594 if (names == NULL) goto failed;
4595 for (i = 0; i < len; i++) {
4596 identifier value;
4597 res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena);
4598 if (res != 0) goto failed;
4599 asdl_seq_SET(names, i, value);
4601 Py_XDECREF(tmp);
4602 tmp = NULL;
4603 } else {
4604 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global");
4605 return 1;
4607 *out = Global(names, lineno, col_offset, arena);
4608 if (*out == NULL) goto failed;
4609 return 0;
4611 isinstance = PyObject_IsInstance(obj, (PyObject*)Expr_type);
4612 if (isinstance == -1) {
4613 return 1;
4615 if (isinstance) {
4616 expr_ty value;
4618 if (PyObject_HasAttrString(obj, "value")) {
4619 int res;
4620 tmp = PyObject_GetAttrString(obj, "value");
4621 if (tmp == NULL) goto failed;
4622 res = obj2ast_expr(tmp, &value, arena);
4623 if (res != 0) goto failed;
4624 Py_XDECREF(tmp);
4625 tmp = NULL;
4626 } else {
4627 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr");
4628 return 1;
4630 *out = Expr(value, lineno, col_offset, arena);
4631 if (*out == NULL) goto failed;
4632 return 0;
4634 isinstance = PyObject_IsInstance(obj, (PyObject*)Pass_type);
4635 if (isinstance == -1) {
4636 return 1;
4638 if (isinstance) {
4640 *out = Pass(lineno, col_offset, arena);
4641 if (*out == NULL) goto failed;
4642 return 0;
4644 isinstance = PyObject_IsInstance(obj, (PyObject*)Break_type);
4645 if (isinstance == -1) {
4646 return 1;
4648 if (isinstance) {
4650 *out = Break(lineno, col_offset, arena);
4651 if (*out == NULL) goto failed;
4652 return 0;
4654 isinstance = PyObject_IsInstance(obj, (PyObject*)Continue_type);
4655 if (isinstance == -1) {
4656 return 1;
4658 if (isinstance) {
4660 *out = Continue(lineno, col_offset, arena);
4661 if (*out == NULL) goto failed;
4662 return 0;
4665 tmp = PyObject_Repr(obj);
4666 if (tmp == NULL) goto failed;
4667 PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %.400s", PyString_AS_STRING(tmp));
4668 failed:
4669 Py_XDECREF(tmp);
4670 return 1;
4674 obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
4676 PyObject* tmp = NULL;
4677 int isinstance;
4679 int lineno;
4680 int col_offset;
4682 if (obj == Py_None) {
4683 *out = NULL;
4684 return 0;
4686 if (PyObject_HasAttrString(obj, "lineno")) {
4687 int res;
4688 tmp = PyObject_GetAttrString(obj, "lineno");
4689 if (tmp == NULL) goto failed;
4690 res = obj2ast_int(tmp, &lineno, arena);
4691 if (res != 0) goto failed;
4692 Py_XDECREF(tmp);
4693 tmp = NULL;
4694 } else {
4695 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr");
4696 return 1;
4698 if (PyObject_HasAttrString(obj, "col_offset")) {
4699 int res;
4700 tmp = PyObject_GetAttrString(obj, "col_offset");
4701 if (tmp == NULL) goto failed;
4702 res = obj2ast_int(tmp, &col_offset, arena);
4703 if (res != 0) goto failed;
4704 Py_XDECREF(tmp);
4705 tmp = NULL;
4706 } else {
4707 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr");
4708 return 1;
4710 isinstance = PyObject_IsInstance(obj, (PyObject*)BoolOp_type);
4711 if (isinstance == -1) {
4712 return 1;
4714 if (isinstance) {
4715 boolop_ty op;
4716 asdl_seq* values;
4718 if (PyObject_HasAttrString(obj, "op")) {
4719 int res;
4720 tmp = PyObject_GetAttrString(obj, "op");
4721 if (tmp == NULL) goto failed;
4722 res = obj2ast_boolop(tmp, &op, arena);
4723 if (res != 0) goto failed;
4724 Py_XDECREF(tmp);
4725 tmp = NULL;
4726 } else {
4727 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp");
4728 return 1;
4730 if (PyObject_HasAttrString(obj, "values")) {
4731 int res;
4732 Py_ssize_t len;
4733 Py_ssize_t i;
4734 tmp = PyObject_GetAttrString(obj, "values");
4735 if (tmp == NULL) goto failed;
4736 if (!PyList_Check(tmp)) {
4737 PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4738 goto failed;
4740 len = PyList_GET_SIZE(tmp);
4741 values = asdl_seq_new(len, arena);
4742 if (values == NULL) goto failed;
4743 for (i = 0; i < len; i++) {
4744 expr_ty value;
4745 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
4746 if (res != 0) goto failed;
4747 asdl_seq_SET(values, i, value);
4749 Py_XDECREF(tmp);
4750 tmp = NULL;
4751 } else {
4752 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp");
4753 return 1;
4755 *out = BoolOp(op, values, lineno, col_offset, arena);
4756 if (*out == NULL) goto failed;
4757 return 0;
4759 isinstance = PyObject_IsInstance(obj, (PyObject*)BinOp_type);
4760 if (isinstance == -1) {
4761 return 1;
4763 if (isinstance) {
4764 expr_ty left;
4765 operator_ty op;
4766 expr_ty right;
4768 if (PyObject_HasAttrString(obj, "left")) {
4769 int res;
4770 tmp = PyObject_GetAttrString(obj, "left");
4771 if (tmp == NULL) goto failed;
4772 res = obj2ast_expr(tmp, &left, arena);
4773 if (res != 0) goto failed;
4774 Py_XDECREF(tmp);
4775 tmp = NULL;
4776 } else {
4777 PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp");
4778 return 1;
4780 if (PyObject_HasAttrString(obj, "op")) {
4781 int res;
4782 tmp = PyObject_GetAttrString(obj, "op");
4783 if (tmp == NULL) goto failed;
4784 res = obj2ast_operator(tmp, &op, arena);
4785 if (res != 0) goto failed;
4786 Py_XDECREF(tmp);
4787 tmp = NULL;
4788 } else {
4789 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp");
4790 return 1;
4792 if (PyObject_HasAttrString(obj, "right")) {
4793 int res;
4794 tmp = PyObject_GetAttrString(obj, "right");
4795 if (tmp == NULL) goto failed;
4796 res = obj2ast_expr(tmp, &right, arena);
4797 if (res != 0) goto failed;
4798 Py_XDECREF(tmp);
4799 tmp = NULL;
4800 } else {
4801 PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp");
4802 return 1;
4804 *out = BinOp(left, op, right, lineno, col_offset, arena);
4805 if (*out == NULL) goto failed;
4806 return 0;
4808 isinstance = PyObject_IsInstance(obj, (PyObject*)UnaryOp_type);
4809 if (isinstance == -1) {
4810 return 1;
4812 if (isinstance) {
4813 unaryop_ty op;
4814 expr_ty operand;
4816 if (PyObject_HasAttrString(obj, "op")) {
4817 int res;
4818 tmp = PyObject_GetAttrString(obj, "op");
4819 if (tmp == NULL) goto failed;
4820 res = obj2ast_unaryop(tmp, &op, arena);
4821 if (res != 0) goto failed;
4822 Py_XDECREF(tmp);
4823 tmp = NULL;
4824 } else {
4825 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp");
4826 return 1;
4828 if (PyObject_HasAttrString(obj, "operand")) {
4829 int res;
4830 tmp = PyObject_GetAttrString(obj, "operand");
4831 if (tmp == NULL) goto failed;
4832 res = obj2ast_expr(tmp, &operand, arena);
4833 if (res != 0) goto failed;
4834 Py_XDECREF(tmp);
4835 tmp = NULL;
4836 } else {
4837 PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp");
4838 return 1;
4840 *out = UnaryOp(op, operand, lineno, col_offset, arena);
4841 if (*out == NULL) goto failed;
4842 return 0;
4844 isinstance = PyObject_IsInstance(obj, (PyObject*)Lambda_type);
4845 if (isinstance == -1) {
4846 return 1;
4848 if (isinstance) {
4849 arguments_ty args;
4850 expr_ty body;
4852 if (PyObject_HasAttrString(obj, "args")) {
4853 int res;
4854 tmp = PyObject_GetAttrString(obj, "args");
4855 if (tmp == NULL) goto failed;
4856 res = obj2ast_arguments(tmp, &args, arena);
4857 if (res != 0) goto failed;
4858 Py_XDECREF(tmp);
4859 tmp = NULL;
4860 } else {
4861 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda");
4862 return 1;
4864 if (PyObject_HasAttrString(obj, "body")) {
4865 int res;
4866 tmp = PyObject_GetAttrString(obj, "body");
4867 if (tmp == NULL) goto failed;
4868 res = obj2ast_expr(tmp, &body, arena);
4869 if (res != 0) goto failed;
4870 Py_XDECREF(tmp);
4871 tmp = NULL;
4872 } else {
4873 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda");
4874 return 1;
4876 *out = Lambda(args, body, lineno, col_offset, arena);
4877 if (*out == NULL) goto failed;
4878 return 0;
4880 isinstance = PyObject_IsInstance(obj, (PyObject*)IfExp_type);
4881 if (isinstance == -1) {
4882 return 1;
4884 if (isinstance) {
4885 expr_ty test;
4886 expr_ty body;
4887 expr_ty orelse;
4889 if (PyObject_HasAttrString(obj, "test")) {
4890 int res;
4891 tmp = PyObject_GetAttrString(obj, "test");
4892 if (tmp == NULL) goto failed;
4893 res = obj2ast_expr(tmp, &test, arena);
4894 if (res != 0) goto failed;
4895 Py_XDECREF(tmp);
4896 tmp = NULL;
4897 } else {
4898 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp");
4899 return 1;
4901 if (PyObject_HasAttrString(obj, "body")) {
4902 int res;
4903 tmp = PyObject_GetAttrString(obj, "body");
4904 if (tmp == NULL) goto failed;
4905 res = obj2ast_expr(tmp, &body, arena);
4906 if (res != 0) goto failed;
4907 Py_XDECREF(tmp);
4908 tmp = NULL;
4909 } else {
4910 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp");
4911 return 1;
4913 if (PyObject_HasAttrString(obj, "orelse")) {
4914 int res;
4915 tmp = PyObject_GetAttrString(obj, "orelse");
4916 if (tmp == NULL) goto failed;
4917 res = obj2ast_expr(tmp, &orelse, arena);
4918 if (res != 0) goto failed;
4919 Py_XDECREF(tmp);
4920 tmp = NULL;
4921 } else {
4922 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp");
4923 return 1;
4925 *out = IfExp(test, body, orelse, lineno, col_offset, arena);
4926 if (*out == NULL) goto failed;
4927 return 0;
4929 isinstance = PyObject_IsInstance(obj, (PyObject*)Dict_type);
4930 if (isinstance == -1) {
4931 return 1;
4933 if (isinstance) {
4934 asdl_seq* keys;
4935 asdl_seq* values;
4937 if (PyObject_HasAttrString(obj, "keys")) {
4938 int res;
4939 Py_ssize_t len;
4940 Py_ssize_t i;
4941 tmp = PyObject_GetAttrString(obj, "keys");
4942 if (tmp == NULL) goto failed;
4943 if (!PyList_Check(tmp)) {
4944 PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4945 goto failed;
4947 len = PyList_GET_SIZE(tmp);
4948 keys = asdl_seq_new(len, arena);
4949 if (keys == NULL) goto failed;
4950 for (i = 0; i < len; i++) {
4951 expr_ty value;
4952 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
4953 if (res != 0) goto failed;
4954 asdl_seq_SET(keys, i, value);
4956 Py_XDECREF(tmp);
4957 tmp = NULL;
4958 } else {
4959 PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict");
4960 return 1;
4962 if (PyObject_HasAttrString(obj, "values")) {
4963 int res;
4964 Py_ssize_t len;
4965 Py_ssize_t i;
4966 tmp = PyObject_GetAttrString(obj, "values");
4967 if (tmp == NULL) goto failed;
4968 if (!PyList_Check(tmp)) {
4969 PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4970 goto failed;
4972 len = PyList_GET_SIZE(tmp);
4973 values = asdl_seq_new(len, arena);
4974 if (values == NULL) goto failed;
4975 for (i = 0; i < len; i++) {
4976 expr_ty value;
4977 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
4978 if (res != 0) goto failed;
4979 asdl_seq_SET(values, i, value);
4981 Py_XDECREF(tmp);
4982 tmp = NULL;
4983 } else {
4984 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict");
4985 return 1;
4987 *out = Dict(keys, values, lineno, col_offset, arena);
4988 if (*out == NULL) goto failed;
4989 return 0;
4991 isinstance = PyObject_IsInstance(obj, (PyObject*)Set_type);
4992 if (isinstance == -1) {
4993 return 1;
4995 if (isinstance) {
4996 asdl_seq* elts;
4998 if (PyObject_HasAttrString(obj, "elts")) {
4999 int res;
5000 Py_ssize_t len;
5001 Py_ssize_t i;
5002 tmp = PyObject_GetAttrString(obj, "elts");
5003 if (tmp == NULL) goto failed;
5004 if (!PyList_Check(tmp)) {
5005 PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5006 goto failed;
5008 len = PyList_GET_SIZE(tmp);
5009 elts = asdl_seq_new(len, arena);
5010 if (elts == NULL) goto failed;
5011 for (i = 0; i < len; i++) {
5012 expr_ty value;
5013 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
5014 if (res != 0) goto failed;
5015 asdl_seq_SET(elts, i, value);
5017 Py_XDECREF(tmp);
5018 tmp = NULL;
5019 } else {
5020 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set");
5021 return 1;
5023 *out = Set(elts, lineno, col_offset, arena);
5024 if (*out == NULL) goto failed;
5025 return 0;
5027 isinstance = PyObject_IsInstance(obj, (PyObject*)ListComp_type);
5028 if (isinstance == -1) {
5029 return 1;
5031 if (isinstance) {
5032 expr_ty elt;
5033 asdl_seq* generators;
5035 if (PyObject_HasAttrString(obj, "elt")) {
5036 int res;
5037 tmp = PyObject_GetAttrString(obj, "elt");
5038 if (tmp == NULL) goto failed;
5039 res = obj2ast_expr(tmp, &elt, arena);
5040 if (res != 0) goto failed;
5041 Py_XDECREF(tmp);
5042 tmp = NULL;
5043 } else {
5044 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp");
5045 return 1;
5047 if (PyObject_HasAttrString(obj, "generators")) {
5048 int res;
5049 Py_ssize_t len;
5050 Py_ssize_t i;
5051 tmp = PyObject_GetAttrString(obj, "generators");
5052 if (tmp == NULL) goto failed;
5053 if (!PyList_Check(tmp)) {
5054 PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5055 goto failed;
5057 len = PyList_GET_SIZE(tmp);
5058 generators = asdl_seq_new(len, arena);
5059 if (generators == NULL) goto failed;
5060 for (i = 0; i < len; i++) {
5061 comprehension_ty value;
5062 res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena);
5063 if (res != 0) goto failed;
5064 asdl_seq_SET(generators, i, value);
5066 Py_XDECREF(tmp);
5067 tmp = NULL;
5068 } else {
5069 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp");
5070 return 1;
5072 *out = ListComp(elt, generators, lineno, col_offset, arena);
5073 if (*out == NULL) goto failed;
5074 return 0;
5076 isinstance = PyObject_IsInstance(obj, (PyObject*)SetComp_type);
5077 if (isinstance == -1) {
5078 return 1;
5080 if (isinstance) {
5081 expr_ty elt;
5082 asdl_seq* generators;
5084 if (PyObject_HasAttrString(obj, "elt")) {
5085 int res;
5086 tmp = PyObject_GetAttrString(obj, "elt");
5087 if (tmp == NULL) goto failed;
5088 res = obj2ast_expr(tmp, &elt, arena);
5089 if (res != 0) goto failed;
5090 Py_XDECREF(tmp);
5091 tmp = NULL;
5092 } else {
5093 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp");
5094 return 1;
5096 if (PyObject_HasAttrString(obj, "generators")) {
5097 int res;
5098 Py_ssize_t len;
5099 Py_ssize_t i;
5100 tmp = PyObject_GetAttrString(obj, "generators");
5101 if (tmp == NULL) goto failed;
5102 if (!PyList_Check(tmp)) {
5103 PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5104 goto failed;
5106 len = PyList_GET_SIZE(tmp);
5107 generators = asdl_seq_new(len, arena);
5108 if (generators == NULL) goto failed;
5109 for (i = 0; i < len; i++) {
5110 comprehension_ty value;
5111 res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena);
5112 if (res != 0) goto failed;
5113 asdl_seq_SET(generators, i, value);
5115 Py_XDECREF(tmp);
5116 tmp = NULL;
5117 } else {
5118 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp");
5119 return 1;
5121 *out = SetComp(elt, generators, lineno, col_offset, arena);
5122 if (*out == NULL) goto failed;
5123 return 0;
5125 isinstance = PyObject_IsInstance(obj, (PyObject*)DictComp_type);
5126 if (isinstance == -1) {
5127 return 1;
5129 if (isinstance) {
5130 expr_ty key;
5131 expr_ty value;
5132 asdl_seq* generators;
5134 if (PyObject_HasAttrString(obj, "key")) {
5135 int res;
5136 tmp = PyObject_GetAttrString(obj, "key");
5137 if (tmp == NULL) goto failed;
5138 res = obj2ast_expr(tmp, &key, arena);
5139 if (res != 0) goto failed;
5140 Py_XDECREF(tmp);
5141 tmp = NULL;
5142 } else {
5143 PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp");
5144 return 1;
5146 if (PyObject_HasAttrString(obj, "value")) {
5147 int res;
5148 tmp = PyObject_GetAttrString(obj, "value");
5149 if (tmp == NULL) goto failed;
5150 res = obj2ast_expr(tmp, &value, arena);
5151 if (res != 0) goto failed;
5152 Py_XDECREF(tmp);
5153 tmp = NULL;
5154 } else {
5155 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp");
5156 return 1;
5158 if (PyObject_HasAttrString(obj, "generators")) {
5159 int res;
5160 Py_ssize_t len;
5161 Py_ssize_t i;
5162 tmp = PyObject_GetAttrString(obj, "generators");
5163 if (tmp == NULL) goto failed;
5164 if (!PyList_Check(tmp)) {
5165 PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5166 goto failed;
5168 len = PyList_GET_SIZE(tmp);
5169 generators = asdl_seq_new(len, arena);
5170 if (generators == NULL) goto failed;
5171 for (i = 0; i < len; i++) {
5172 comprehension_ty value;
5173 res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena);
5174 if (res != 0) goto failed;
5175 asdl_seq_SET(generators, i, value);
5177 Py_XDECREF(tmp);
5178 tmp = NULL;
5179 } else {
5180 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp");
5181 return 1;
5183 *out = DictComp(key, value, generators, lineno, col_offset,
5184 arena);
5185 if (*out == NULL) goto failed;
5186 return 0;
5188 isinstance = PyObject_IsInstance(obj, (PyObject*)GeneratorExp_type);
5189 if (isinstance == -1) {
5190 return 1;
5192 if (isinstance) {
5193 expr_ty elt;
5194 asdl_seq* generators;
5196 if (PyObject_HasAttrString(obj, "elt")) {
5197 int res;
5198 tmp = PyObject_GetAttrString(obj, "elt");
5199 if (tmp == NULL) goto failed;
5200 res = obj2ast_expr(tmp, &elt, arena);
5201 if (res != 0) goto failed;
5202 Py_XDECREF(tmp);
5203 tmp = NULL;
5204 } else {
5205 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp");
5206 return 1;
5208 if (PyObject_HasAttrString(obj, "generators")) {
5209 int res;
5210 Py_ssize_t len;
5211 Py_ssize_t i;
5212 tmp = PyObject_GetAttrString(obj, "generators");
5213 if (tmp == NULL) goto failed;
5214 if (!PyList_Check(tmp)) {
5215 PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5216 goto failed;
5218 len = PyList_GET_SIZE(tmp);
5219 generators = asdl_seq_new(len, arena);
5220 if (generators == NULL) goto failed;
5221 for (i = 0; i < len; i++) {
5222 comprehension_ty value;
5223 res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena);
5224 if (res != 0) goto failed;
5225 asdl_seq_SET(generators, i, value);
5227 Py_XDECREF(tmp);
5228 tmp = NULL;
5229 } else {
5230 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp");
5231 return 1;
5233 *out = GeneratorExp(elt, generators, lineno, col_offset, arena);
5234 if (*out == NULL) goto failed;
5235 return 0;
5237 isinstance = PyObject_IsInstance(obj, (PyObject*)Yield_type);
5238 if (isinstance == -1) {
5239 return 1;
5241 if (isinstance) {
5242 expr_ty value;
5244 if (PyObject_HasAttrString(obj, "value")) {
5245 int res;
5246 tmp = PyObject_GetAttrString(obj, "value");
5247 if (tmp == NULL) goto failed;
5248 res = obj2ast_expr(tmp, &value, arena);
5249 if (res != 0) goto failed;
5250 Py_XDECREF(tmp);
5251 tmp = NULL;
5252 } else {
5253 value = NULL;
5255 *out = Yield(value, lineno, col_offset, arena);
5256 if (*out == NULL) goto failed;
5257 return 0;
5259 isinstance = PyObject_IsInstance(obj, (PyObject*)Compare_type);
5260 if (isinstance == -1) {
5261 return 1;
5263 if (isinstance) {
5264 expr_ty left;
5265 asdl_int_seq* ops;
5266 asdl_seq* comparators;
5268 if (PyObject_HasAttrString(obj, "left")) {
5269 int res;
5270 tmp = PyObject_GetAttrString(obj, "left");
5271 if (tmp == NULL) goto failed;
5272 res = obj2ast_expr(tmp, &left, arena);
5273 if (res != 0) goto failed;
5274 Py_XDECREF(tmp);
5275 tmp = NULL;
5276 } else {
5277 PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare");
5278 return 1;
5280 if (PyObject_HasAttrString(obj, "ops")) {
5281 int res;
5282 Py_ssize_t len;
5283 Py_ssize_t i;
5284 tmp = PyObject_GetAttrString(obj, "ops");
5285 if (tmp == NULL) goto failed;
5286 if (!PyList_Check(tmp)) {
5287 PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5288 goto failed;
5290 len = PyList_GET_SIZE(tmp);
5291 ops = asdl_int_seq_new(len, arena);
5292 if (ops == NULL) goto failed;
5293 for (i = 0; i < len; i++) {
5294 cmpop_ty value;
5295 res = obj2ast_cmpop(PyList_GET_ITEM(tmp, i), &value, arena);
5296 if (res != 0) goto failed;
5297 asdl_seq_SET(ops, i, value);
5299 Py_XDECREF(tmp);
5300 tmp = NULL;
5301 } else {
5302 PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare");
5303 return 1;
5305 if (PyObject_HasAttrString(obj, "comparators")) {
5306 int res;
5307 Py_ssize_t len;
5308 Py_ssize_t i;
5309 tmp = PyObject_GetAttrString(obj, "comparators");
5310 if (tmp == NULL) goto failed;
5311 if (!PyList_Check(tmp)) {
5312 PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5313 goto failed;
5315 len = PyList_GET_SIZE(tmp);
5316 comparators = asdl_seq_new(len, arena);
5317 if (comparators == NULL) goto failed;
5318 for (i = 0; i < len; i++) {
5319 expr_ty value;
5320 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
5321 if (res != 0) goto failed;
5322 asdl_seq_SET(comparators, i, value);
5324 Py_XDECREF(tmp);
5325 tmp = NULL;
5326 } else {
5327 PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare");
5328 return 1;
5330 *out = Compare(left, ops, comparators, lineno, col_offset,
5331 arena);
5332 if (*out == NULL) goto failed;
5333 return 0;
5335 isinstance = PyObject_IsInstance(obj, (PyObject*)Call_type);
5336 if (isinstance == -1) {
5337 return 1;
5339 if (isinstance) {
5340 expr_ty func;
5341 asdl_seq* args;
5342 asdl_seq* keywords;
5343 expr_ty starargs;
5344 expr_ty kwargs;
5346 if (PyObject_HasAttrString(obj, "func")) {
5347 int res;
5348 tmp = PyObject_GetAttrString(obj, "func");
5349 if (tmp == NULL) goto failed;
5350 res = obj2ast_expr(tmp, &func, arena);
5351 if (res != 0) goto failed;
5352 Py_XDECREF(tmp);
5353 tmp = NULL;
5354 } else {
5355 PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call");
5356 return 1;
5358 if (PyObject_HasAttrString(obj, "args")) {
5359 int res;
5360 Py_ssize_t len;
5361 Py_ssize_t i;
5362 tmp = PyObject_GetAttrString(obj, "args");
5363 if (tmp == NULL) goto failed;
5364 if (!PyList_Check(tmp)) {
5365 PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5366 goto failed;
5368 len = PyList_GET_SIZE(tmp);
5369 args = asdl_seq_new(len, arena);
5370 if (args == NULL) goto failed;
5371 for (i = 0; i < len; i++) {
5372 expr_ty value;
5373 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
5374 if (res != 0) goto failed;
5375 asdl_seq_SET(args, i, value);
5377 Py_XDECREF(tmp);
5378 tmp = NULL;
5379 } else {
5380 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call");
5381 return 1;
5383 if (PyObject_HasAttrString(obj, "keywords")) {
5384 int res;
5385 Py_ssize_t len;
5386 Py_ssize_t i;
5387 tmp = PyObject_GetAttrString(obj, "keywords");
5388 if (tmp == NULL) goto failed;
5389 if (!PyList_Check(tmp)) {
5390 PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5391 goto failed;
5393 len = PyList_GET_SIZE(tmp);
5394 keywords = asdl_seq_new(len, arena);
5395 if (keywords == NULL) goto failed;
5396 for (i = 0; i < len; i++) {
5397 keyword_ty value;
5398 res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &value, arena);
5399 if (res != 0) goto failed;
5400 asdl_seq_SET(keywords, i, value);
5402 Py_XDECREF(tmp);
5403 tmp = NULL;
5404 } else {
5405 PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call");
5406 return 1;
5408 if (PyObject_HasAttrString(obj, "starargs")) {
5409 int res;
5410 tmp = PyObject_GetAttrString(obj, "starargs");
5411 if (tmp == NULL) goto failed;
5412 res = obj2ast_expr(tmp, &starargs, arena);
5413 if (res != 0) goto failed;
5414 Py_XDECREF(tmp);
5415 tmp = NULL;
5416 } else {
5417 starargs = NULL;
5419 if (PyObject_HasAttrString(obj, "kwargs")) {
5420 int res;
5421 tmp = PyObject_GetAttrString(obj, "kwargs");
5422 if (tmp == NULL) goto failed;
5423 res = obj2ast_expr(tmp, &kwargs, arena);
5424 if (res != 0) goto failed;
5425 Py_XDECREF(tmp);
5426 tmp = NULL;
5427 } else {
5428 kwargs = NULL;
5430 *out = Call(func, args, keywords, starargs, kwargs, lineno,
5431 col_offset, arena);
5432 if (*out == NULL) goto failed;
5433 return 0;
5435 isinstance = PyObject_IsInstance(obj, (PyObject*)Repr_type);
5436 if (isinstance == -1) {
5437 return 1;
5439 if (isinstance) {
5440 expr_ty value;
5442 if (PyObject_HasAttrString(obj, "value")) {
5443 int res;
5444 tmp = PyObject_GetAttrString(obj, "value");
5445 if (tmp == NULL) goto failed;
5446 res = obj2ast_expr(tmp, &value, arena);
5447 if (res != 0) goto failed;
5448 Py_XDECREF(tmp);
5449 tmp = NULL;
5450 } else {
5451 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Repr");
5452 return 1;
5454 *out = Repr(value, lineno, col_offset, arena);
5455 if (*out == NULL) goto failed;
5456 return 0;
5458 isinstance = PyObject_IsInstance(obj, (PyObject*)Num_type);
5459 if (isinstance == -1) {
5460 return 1;
5462 if (isinstance) {
5463 object n;
5465 if (PyObject_HasAttrString(obj, "n")) {
5466 int res;
5467 tmp = PyObject_GetAttrString(obj, "n");
5468 if (tmp == NULL) goto failed;
5469 res = obj2ast_object(tmp, &n, arena);
5470 if (res != 0) goto failed;
5471 Py_XDECREF(tmp);
5472 tmp = NULL;
5473 } else {
5474 PyErr_SetString(PyExc_TypeError, "required field \"n\" missing from Num");
5475 return 1;
5477 *out = Num(n, lineno, col_offset, arena);
5478 if (*out == NULL) goto failed;
5479 return 0;
5481 isinstance = PyObject_IsInstance(obj, (PyObject*)Str_type);
5482 if (isinstance == -1) {
5483 return 1;
5485 if (isinstance) {
5486 string s;
5488 if (PyObject_HasAttrString(obj, "s")) {
5489 int res;
5490 tmp = PyObject_GetAttrString(obj, "s");
5491 if (tmp == NULL) goto failed;
5492 res = obj2ast_string(tmp, &s, arena);
5493 if (res != 0) goto failed;
5494 Py_XDECREF(tmp);
5495 tmp = NULL;
5496 } else {
5497 PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Str");
5498 return 1;
5500 *out = Str(s, lineno, col_offset, arena);
5501 if (*out == NULL) goto failed;
5502 return 0;
5504 isinstance = PyObject_IsInstance(obj, (PyObject*)Attribute_type);
5505 if (isinstance == -1) {
5506 return 1;
5508 if (isinstance) {
5509 expr_ty value;
5510 identifier attr;
5511 expr_context_ty ctx;
5513 if (PyObject_HasAttrString(obj, "value")) {
5514 int res;
5515 tmp = PyObject_GetAttrString(obj, "value");
5516 if (tmp == NULL) goto failed;
5517 res = obj2ast_expr(tmp, &value, arena);
5518 if (res != 0) goto failed;
5519 Py_XDECREF(tmp);
5520 tmp = NULL;
5521 } else {
5522 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute");
5523 return 1;
5525 if (PyObject_HasAttrString(obj, "attr")) {
5526 int res;
5527 tmp = PyObject_GetAttrString(obj, "attr");
5528 if (tmp == NULL) goto failed;
5529 res = obj2ast_identifier(tmp, &attr, arena);
5530 if (res != 0) goto failed;
5531 Py_XDECREF(tmp);
5532 tmp = NULL;
5533 } else {
5534 PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute");
5535 return 1;
5537 if (PyObject_HasAttrString(obj, "ctx")) {
5538 int res;
5539 tmp = PyObject_GetAttrString(obj, "ctx");
5540 if (tmp == NULL) goto failed;
5541 res = obj2ast_expr_context(tmp, &ctx, arena);
5542 if (res != 0) goto failed;
5543 Py_XDECREF(tmp);
5544 tmp = NULL;
5545 } else {
5546 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute");
5547 return 1;
5549 *out = Attribute(value, attr, ctx, lineno, col_offset, arena);
5550 if (*out == NULL) goto failed;
5551 return 0;
5553 isinstance = PyObject_IsInstance(obj, (PyObject*)Subscript_type);
5554 if (isinstance == -1) {
5555 return 1;
5557 if (isinstance) {
5558 expr_ty value;
5559 slice_ty slice;
5560 expr_context_ty ctx;
5562 if (PyObject_HasAttrString(obj, "value")) {
5563 int res;
5564 tmp = PyObject_GetAttrString(obj, "value");
5565 if (tmp == NULL) goto failed;
5566 res = obj2ast_expr(tmp, &value, arena);
5567 if (res != 0) goto failed;
5568 Py_XDECREF(tmp);
5569 tmp = NULL;
5570 } else {
5571 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript");
5572 return 1;
5574 if (PyObject_HasAttrString(obj, "slice")) {
5575 int res;
5576 tmp = PyObject_GetAttrString(obj, "slice");
5577 if (tmp == NULL) goto failed;
5578 res = obj2ast_slice(tmp, &slice, arena);
5579 if (res != 0) goto failed;
5580 Py_XDECREF(tmp);
5581 tmp = NULL;
5582 } else {
5583 PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript");
5584 return 1;
5586 if (PyObject_HasAttrString(obj, "ctx")) {
5587 int res;
5588 tmp = PyObject_GetAttrString(obj, "ctx");
5589 if (tmp == NULL) goto failed;
5590 res = obj2ast_expr_context(tmp, &ctx, arena);
5591 if (res != 0) goto failed;
5592 Py_XDECREF(tmp);
5593 tmp = NULL;
5594 } else {
5595 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript");
5596 return 1;
5598 *out = Subscript(value, slice, ctx, lineno, col_offset, arena);
5599 if (*out == NULL) goto failed;
5600 return 0;
5602 isinstance = PyObject_IsInstance(obj, (PyObject*)Name_type);
5603 if (isinstance == -1) {
5604 return 1;
5606 if (isinstance) {
5607 identifier id;
5608 expr_context_ty ctx;
5610 if (PyObject_HasAttrString(obj, "id")) {
5611 int res;
5612 tmp = PyObject_GetAttrString(obj, "id");
5613 if (tmp == NULL) goto failed;
5614 res = obj2ast_identifier(tmp, &id, arena);
5615 if (res != 0) goto failed;
5616 Py_XDECREF(tmp);
5617 tmp = NULL;
5618 } else {
5619 PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name");
5620 return 1;
5622 if (PyObject_HasAttrString(obj, "ctx")) {
5623 int res;
5624 tmp = PyObject_GetAttrString(obj, "ctx");
5625 if (tmp == NULL) goto failed;
5626 res = obj2ast_expr_context(tmp, &ctx, arena);
5627 if (res != 0) goto failed;
5628 Py_XDECREF(tmp);
5629 tmp = NULL;
5630 } else {
5631 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name");
5632 return 1;
5634 *out = Name(id, ctx, lineno, col_offset, arena);
5635 if (*out == NULL) goto failed;
5636 return 0;
5638 isinstance = PyObject_IsInstance(obj, (PyObject*)List_type);
5639 if (isinstance == -1) {
5640 return 1;
5642 if (isinstance) {
5643 asdl_seq* elts;
5644 expr_context_ty ctx;
5646 if (PyObject_HasAttrString(obj, "elts")) {
5647 int res;
5648 Py_ssize_t len;
5649 Py_ssize_t i;
5650 tmp = PyObject_GetAttrString(obj, "elts");
5651 if (tmp == NULL) goto failed;
5652 if (!PyList_Check(tmp)) {
5653 PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5654 goto failed;
5656 len = PyList_GET_SIZE(tmp);
5657 elts = asdl_seq_new(len, arena);
5658 if (elts == NULL) goto failed;
5659 for (i = 0; i < len; i++) {
5660 expr_ty value;
5661 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
5662 if (res != 0) goto failed;
5663 asdl_seq_SET(elts, i, value);
5665 Py_XDECREF(tmp);
5666 tmp = NULL;
5667 } else {
5668 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List");
5669 return 1;
5671 if (PyObject_HasAttrString(obj, "ctx")) {
5672 int res;
5673 tmp = PyObject_GetAttrString(obj, "ctx");
5674 if (tmp == NULL) goto failed;
5675 res = obj2ast_expr_context(tmp, &ctx, arena);
5676 if (res != 0) goto failed;
5677 Py_XDECREF(tmp);
5678 tmp = NULL;
5679 } else {
5680 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List");
5681 return 1;
5683 *out = List(elts, ctx, lineno, col_offset, arena);
5684 if (*out == NULL) goto failed;
5685 return 0;
5687 isinstance = PyObject_IsInstance(obj, (PyObject*)Tuple_type);
5688 if (isinstance == -1) {
5689 return 1;
5691 if (isinstance) {
5692 asdl_seq* elts;
5693 expr_context_ty ctx;
5695 if (PyObject_HasAttrString(obj, "elts")) {
5696 int res;
5697 Py_ssize_t len;
5698 Py_ssize_t i;
5699 tmp = PyObject_GetAttrString(obj, "elts");
5700 if (tmp == NULL) goto failed;
5701 if (!PyList_Check(tmp)) {
5702 PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5703 goto failed;
5705 len = PyList_GET_SIZE(tmp);
5706 elts = asdl_seq_new(len, arena);
5707 if (elts == NULL) goto failed;
5708 for (i = 0; i < len; i++) {
5709 expr_ty value;
5710 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
5711 if (res != 0) goto failed;
5712 asdl_seq_SET(elts, i, value);
5714 Py_XDECREF(tmp);
5715 tmp = NULL;
5716 } else {
5717 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple");
5718 return 1;
5720 if (PyObject_HasAttrString(obj, "ctx")) {
5721 int res;
5722 tmp = PyObject_GetAttrString(obj, "ctx");
5723 if (tmp == NULL) goto failed;
5724 res = obj2ast_expr_context(tmp, &ctx, arena);
5725 if (res != 0) goto failed;
5726 Py_XDECREF(tmp);
5727 tmp = NULL;
5728 } else {
5729 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple");
5730 return 1;
5732 *out = Tuple(elts, ctx, lineno, col_offset, arena);
5733 if (*out == NULL) goto failed;
5734 return 0;
5737 tmp = PyObject_Repr(obj);
5738 if (tmp == NULL) goto failed;
5739 PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %.400s", PyString_AS_STRING(tmp));
5740 failed:
5741 Py_XDECREF(tmp);
5742 return 1;
5746 obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena)
5748 PyObject* tmp = NULL;
5749 int isinstance;
5751 isinstance = PyObject_IsInstance(obj, (PyObject *)Load_type);
5752 if (isinstance == -1) {
5753 return 1;
5755 if (isinstance) {
5756 *out = Load;
5757 return 0;
5759 isinstance = PyObject_IsInstance(obj, (PyObject *)Store_type);
5760 if (isinstance == -1) {
5761 return 1;
5763 if (isinstance) {
5764 *out = Store;
5765 return 0;
5767 isinstance = PyObject_IsInstance(obj, (PyObject *)Del_type);
5768 if (isinstance == -1) {
5769 return 1;
5771 if (isinstance) {
5772 *out = Del;
5773 return 0;
5775 isinstance = PyObject_IsInstance(obj, (PyObject *)AugLoad_type);
5776 if (isinstance == -1) {
5777 return 1;
5779 if (isinstance) {
5780 *out = AugLoad;
5781 return 0;
5783 isinstance = PyObject_IsInstance(obj, (PyObject *)AugStore_type);
5784 if (isinstance == -1) {
5785 return 1;
5787 if (isinstance) {
5788 *out = AugStore;
5789 return 0;
5791 isinstance = PyObject_IsInstance(obj, (PyObject *)Param_type);
5792 if (isinstance == -1) {
5793 return 1;
5795 if (isinstance) {
5796 *out = Param;
5797 return 0;
5800 tmp = PyObject_Repr(obj);
5801 if (tmp == NULL) goto failed;
5802 PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %.400s", PyString_AS_STRING(tmp));
5803 failed:
5804 Py_XDECREF(tmp);
5805 return 1;
5809 obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena)
5811 PyObject* tmp = NULL;
5812 int isinstance;
5815 if (obj == Py_None) {
5816 *out = NULL;
5817 return 0;
5819 isinstance = PyObject_IsInstance(obj, (PyObject*)Ellipsis_type);
5820 if (isinstance == -1) {
5821 return 1;
5823 if (isinstance) {
5825 *out = Ellipsis(arena);
5826 if (*out == NULL) goto failed;
5827 return 0;
5829 isinstance = PyObject_IsInstance(obj, (PyObject*)Slice_type);
5830 if (isinstance == -1) {
5831 return 1;
5833 if (isinstance) {
5834 expr_ty lower;
5835 expr_ty upper;
5836 expr_ty step;
5838 if (PyObject_HasAttrString(obj, "lower")) {
5839 int res;
5840 tmp = PyObject_GetAttrString(obj, "lower");
5841 if (tmp == NULL) goto failed;
5842 res = obj2ast_expr(tmp, &lower, arena);
5843 if (res != 0) goto failed;
5844 Py_XDECREF(tmp);
5845 tmp = NULL;
5846 } else {
5847 lower = NULL;
5849 if (PyObject_HasAttrString(obj, "upper")) {
5850 int res;
5851 tmp = PyObject_GetAttrString(obj, "upper");
5852 if (tmp == NULL) goto failed;
5853 res = obj2ast_expr(tmp, &upper, arena);
5854 if (res != 0) goto failed;
5855 Py_XDECREF(tmp);
5856 tmp = NULL;
5857 } else {
5858 upper = NULL;
5860 if (PyObject_HasAttrString(obj, "step")) {
5861 int res;
5862 tmp = PyObject_GetAttrString(obj, "step");
5863 if (tmp == NULL) goto failed;
5864 res = obj2ast_expr(tmp, &step, arena);
5865 if (res != 0) goto failed;
5866 Py_XDECREF(tmp);
5867 tmp = NULL;
5868 } else {
5869 step = NULL;
5871 *out = Slice(lower, upper, step, arena);
5872 if (*out == NULL) goto failed;
5873 return 0;
5875 isinstance = PyObject_IsInstance(obj, (PyObject*)ExtSlice_type);
5876 if (isinstance == -1) {
5877 return 1;
5879 if (isinstance) {
5880 asdl_seq* dims;
5882 if (PyObject_HasAttrString(obj, "dims")) {
5883 int res;
5884 Py_ssize_t len;
5885 Py_ssize_t i;
5886 tmp = PyObject_GetAttrString(obj, "dims");
5887 if (tmp == NULL) goto failed;
5888 if (!PyList_Check(tmp)) {
5889 PyErr_Format(PyExc_TypeError, "ExtSlice field \"dims\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5890 goto failed;
5892 len = PyList_GET_SIZE(tmp);
5893 dims = asdl_seq_new(len, arena);
5894 if (dims == NULL) goto failed;
5895 for (i = 0; i < len; i++) {
5896 slice_ty value;
5897 res = obj2ast_slice(PyList_GET_ITEM(tmp, i), &value, arena);
5898 if (res != 0) goto failed;
5899 asdl_seq_SET(dims, i, value);
5901 Py_XDECREF(tmp);
5902 tmp = NULL;
5903 } else {
5904 PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice");
5905 return 1;
5907 *out = ExtSlice(dims, arena);
5908 if (*out == NULL) goto failed;
5909 return 0;
5911 isinstance = PyObject_IsInstance(obj, (PyObject*)Index_type);
5912 if (isinstance == -1) {
5913 return 1;
5915 if (isinstance) {
5916 expr_ty value;
5918 if (PyObject_HasAttrString(obj, "value")) {
5919 int res;
5920 tmp = PyObject_GetAttrString(obj, "value");
5921 if (tmp == NULL) goto failed;
5922 res = obj2ast_expr(tmp, &value, arena);
5923 if (res != 0) goto failed;
5924 Py_XDECREF(tmp);
5925 tmp = NULL;
5926 } else {
5927 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index");
5928 return 1;
5930 *out = Index(value, arena);
5931 if (*out == NULL) goto failed;
5932 return 0;
5935 tmp = PyObject_Repr(obj);
5936 if (tmp == NULL) goto failed;
5937 PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %.400s", PyString_AS_STRING(tmp));
5938 failed:
5939 Py_XDECREF(tmp);
5940 return 1;
5944 obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena)
5946 PyObject* tmp = NULL;
5947 int isinstance;
5949 isinstance = PyObject_IsInstance(obj, (PyObject *)And_type);
5950 if (isinstance == -1) {
5951 return 1;
5953 if (isinstance) {
5954 *out = And;
5955 return 0;
5957 isinstance = PyObject_IsInstance(obj, (PyObject *)Or_type);
5958 if (isinstance == -1) {
5959 return 1;
5961 if (isinstance) {
5962 *out = Or;
5963 return 0;
5966 tmp = PyObject_Repr(obj);
5967 if (tmp == NULL) goto failed;
5968 PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %.400s", PyString_AS_STRING(tmp));
5969 failed:
5970 Py_XDECREF(tmp);
5971 return 1;
5975 obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena)
5977 PyObject* tmp = NULL;
5978 int isinstance;
5980 isinstance = PyObject_IsInstance(obj, (PyObject *)Add_type);
5981 if (isinstance == -1) {
5982 return 1;
5984 if (isinstance) {
5985 *out = Add;
5986 return 0;
5988 isinstance = PyObject_IsInstance(obj, (PyObject *)Sub_type);
5989 if (isinstance == -1) {
5990 return 1;
5992 if (isinstance) {
5993 *out = Sub;
5994 return 0;
5996 isinstance = PyObject_IsInstance(obj, (PyObject *)Mult_type);
5997 if (isinstance == -1) {
5998 return 1;
6000 if (isinstance) {
6001 *out = Mult;
6002 return 0;
6004 isinstance = PyObject_IsInstance(obj, (PyObject *)Div_type);
6005 if (isinstance == -1) {
6006 return 1;
6008 if (isinstance) {
6009 *out = Div;
6010 return 0;
6012 isinstance = PyObject_IsInstance(obj, (PyObject *)Mod_type);
6013 if (isinstance == -1) {
6014 return 1;
6016 if (isinstance) {
6017 *out = Mod;
6018 return 0;
6020 isinstance = PyObject_IsInstance(obj, (PyObject *)Pow_type);
6021 if (isinstance == -1) {
6022 return 1;
6024 if (isinstance) {
6025 *out = Pow;
6026 return 0;
6028 isinstance = PyObject_IsInstance(obj, (PyObject *)LShift_type);
6029 if (isinstance == -1) {
6030 return 1;
6032 if (isinstance) {
6033 *out = LShift;
6034 return 0;
6036 isinstance = PyObject_IsInstance(obj, (PyObject *)RShift_type);
6037 if (isinstance == -1) {
6038 return 1;
6040 if (isinstance) {
6041 *out = RShift;
6042 return 0;
6044 isinstance = PyObject_IsInstance(obj, (PyObject *)BitOr_type);
6045 if (isinstance == -1) {
6046 return 1;
6048 if (isinstance) {
6049 *out = BitOr;
6050 return 0;
6052 isinstance = PyObject_IsInstance(obj, (PyObject *)BitXor_type);
6053 if (isinstance == -1) {
6054 return 1;
6056 if (isinstance) {
6057 *out = BitXor;
6058 return 0;
6060 isinstance = PyObject_IsInstance(obj, (PyObject *)BitAnd_type);
6061 if (isinstance == -1) {
6062 return 1;
6064 if (isinstance) {
6065 *out = BitAnd;
6066 return 0;
6068 isinstance = PyObject_IsInstance(obj, (PyObject *)FloorDiv_type);
6069 if (isinstance == -1) {
6070 return 1;
6072 if (isinstance) {
6073 *out = FloorDiv;
6074 return 0;
6077 tmp = PyObject_Repr(obj);
6078 if (tmp == NULL) goto failed;
6079 PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %.400s", PyString_AS_STRING(tmp));
6080 failed:
6081 Py_XDECREF(tmp);
6082 return 1;
6086 obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena)
6088 PyObject* tmp = NULL;
6089 int isinstance;
6091 isinstance = PyObject_IsInstance(obj, (PyObject *)Invert_type);
6092 if (isinstance == -1) {
6093 return 1;
6095 if (isinstance) {
6096 *out = Invert;
6097 return 0;
6099 isinstance = PyObject_IsInstance(obj, (PyObject *)Not_type);
6100 if (isinstance == -1) {
6101 return 1;
6103 if (isinstance) {
6104 *out = Not;
6105 return 0;
6107 isinstance = PyObject_IsInstance(obj, (PyObject *)UAdd_type);
6108 if (isinstance == -1) {
6109 return 1;
6111 if (isinstance) {
6112 *out = UAdd;
6113 return 0;
6115 isinstance = PyObject_IsInstance(obj, (PyObject *)USub_type);
6116 if (isinstance == -1) {
6117 return 1;
6119 if (isinstance) {
6120 *out = USub;
6121 return 0;
6124 tmp = PyObject_Repr(obj);
6125 if (tmp == NULL) goto failed;
6126 PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %.400s", PyString_AS_STRING(tmp));
6127 failed:
6128 Py_XDECREF(tmp);
6129 return 1;
6133 obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena)
6135 PyObject* tmp = NULL;
6136 int isinstance;
6138 isinstance = PyObject_IsInstance(obj, (PyObject *)Eq_type);
6139 if (isinstance == -1) {
6140 return 1;
6142 if (isinstance) {
6143 *out = Eq;
6144 return 0;
6146 isinstance = PyObject_IsInstance(obj, (PyObject *)NotEq_type);
6147 if (isinstance == -1) {
6148 return 1;
6150 if (isinstance) {
6151 *out = NotEq;
6152 return 0;
6154 isinstance = PyObject_IsInstance(obj, (PyObject *)Lt_type);
6155 if (isinstance == -1) {
6156 return 1;
6158 if (isinstance) {
6159 *out = Lt;
6160 return 0;
6162 isinstance = PyObject_IsInstance(obj, (PyObject *)LtE_type);
6163 if (isinstance == -1) {
6164 return 1;
6166 if (isinstance) {
6167 *out = LtE;
6168 return 0;
6170 isinstance = PyObject_IsInstance(obj, (PyObject *)Gt_type);
6171 if (isinstance == -1) {
6172 return 1;
6174 if (isinstance) {
6175 *out = Gt;
6176 return 0;
6178 isinstance = PyObject_IsInstance(obj, (PyObject *)GtE_type);
6179 if (isinstance == -1) {
6180 return 1;
6182 if (isinstance) {
6183 *out = GtE;
6184 return 0;
6186 isinstance = PyObject_IsInstance(obj, (PyObject *)Is_type);
6187 if (isinstance == -1) {
6188 return 1;
6190 if (isinstance) {
6191 *out = Is;
6192 return 0;
6194 isinstance = PyObject_IsInstance(obj, (PyObject *)IsNot_type);
6195 if (isinstance == -1) {
6196 return 1;
6198 if (isinstance) {
6199 *out = IsNot;
6200 return 0;
6202 isinstance = PyObject_IsInstance(obj, (PyObject *)In_type);
6203 if (isinstance == -1) {
6204 return 1;
6206 if (isinstance) {
6207 *out = In;
6208 return 0;
6210 isinstance = PyObject_IsInstance(obj, (PyObject *)NotIn_type);
6211 if (isinstance == -1) {
6212 return 1;
6214 if (isinstance) {
6215 *out = NotIn;
6216 return 0;
6219 tmp = PyObject_Repr(obj);
6220 if (tmp == NULL) goto failed;
6221 PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %.400s", PyString_AS_STRING(tmp));
6222 failed:
6223 Py_XDECREF(tmp);
6224 return 1;
6228 obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena)
6230 PyObject* tmp = NULL;
6231 expr_ty target;
6232 expr_ty iter;
6233 asdl_seq* ifs;
6235 if (PyObject_HasAttrString(obj, "target")) {
6236 int res;
6237 tmp = PyObject_GetAttrString(obj, "target");
6238 if (tmp == NULL) goto failed;
6239 res = obj2ast_expr(tmp, &target, arena);
6240 if (res != 0) goto failed;
6241 Py_XDECREF(tmp);
6242 tmp = NULL;
6243 } else {
6244 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension");
6245 return 1;
6247 if (PyObject_HasAttrString(obj, "iter")) {
6248 int res;
6249 tmp = PyObject_GetAttrString(obj, "iter");
6250 if (tmp == NULL) goto failed;
6251 res = obj2ast_expr(tmp, &iter, arena);
6252 if (res != 0) goto failed;
6253 Py_XDECREF(tmp);
6254 tmp = NULL;
6255 } else {
6256 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension");
6257 return 1;
6259 if (PyObject_HasAttrString(obj, "ifs")) {
6260 int res;
6261 Py_ssize_t len;
6262 Py_ssize_t i;
6263 tmp = PyObject_GetAttrString(obj, "ifs");
6264 if (tmp == NULL) goto failed;
6265 if (!PyList_Check(tmp)) {
6266 PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", tmp->ob_type->tp_name);
6267 goto failed;
6269 len = PyList_GET_SIZE(tmp);
6270 ifs = asdl_seq_new(len, arena);
6271 if (ifs == NULL) goto failed;
6272 for (i = 0; i < len; i++) {
6273 expr_ty value;
6274 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
6275 if (res != 0) goto failed;
6276 asdl_seq_SET(ifs, i, value);
6278 Py_XDECREF(tmp);
6279 tmp = NULL;
6280 } else {
6281 PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension");
6282 return 1;
6284 *out = comprehension(target, iter, ifs, arena);
6285 return 0;
6286 failed:
6287 Py_XDECREF(tmp);
6288 return 1;
6292 obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena)
6294 PyObject* tmp = NULL;
6295 int isinstance;
6297 int lineno;
6298 int col_offset;
6300 if (obj == Py_None) {
6301 *out = NULL;
6302 return 0;
6304 if (PyObject_HasAttrString(obj, "lineno")) {
6305 int res;
6306 tmp = PyObject_GetAttrString(obj, "lineno");
6307 if (tmp == NULL) goto failed;
6308 res = obj2ast_int(tmp, &lineno, arena);
6309 if (res != 0) goto failed;
6310 Py_XDECREF(tmp);
6311 tmp = NULL;
6312 } else {
6313 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler");
6314 return 1;
6316 if (PyObject_HasAttrString(obj, "col_offset")) {
6317 int res;
6318 tmp = PyObject_GetAttrString(obj, "col_offset");
6319 if (tmp == NULL) goto failed;
6320 res = obj2ast_int(tmp, &col_offset, arena);
6321 if (res != 0) goto failed;
6322 Py_XDECREF(tmp);
6323 tmp = NULL;
6324 } else {
6325 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler");
6326 return 1;
6328 isinstance = PyObject_IsInstance(obj, (PyObject*)ExceptHandler_type);
6329 if (isinstance == -1) {
6330 return 1;
6332 if (isinstance) {
6333 expr_ty type;
6334 expr_ty name;
6335 asdl_seq* body;
6337 if (PyObject_HasAttrString(obj, "type")) {
6338 int res;
6339 tmp = PyObject_GetAttrString(obj, "type");
6340 if (tmp == NULL) goto failed;
6341 res = obj2ast_expr(tmp, &type, arena);
6342 if (res != 0) goto failed;
6343 Py_XDECREF(tmp);
6344 tmp = NULL;
6345 } else {
6346 type = NULL;
6348 if (PyObject_HasAttrString(obj, "name")) {
6349 int res;
6350 tmp = PyObject_GetAttrString(obj, "name");
6351 if (tmp == NULL) goto failed;
6352 res = obj2ast_expr(tmp, &name, arena);
6353 if (res != 0) goto failed;
6354 Py_XDECREF(tmp);
6355 tmp = NULL;
6356 } else {
6357 name = NULL;
6359 if (PyObject_HasAttrString(obj, "body")) {
6360 int res;
6361 Py_ssize_t len;
6362 Py_ssize_t i;
6363 tmp = PyObject_GetAttrString(obj, "body");
6364 if (tmp == NULL) goto failed;
6365 if (!PyList_Check(tmp)) {
6366 PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
6367 goto failed;
6369 len = PyList_GET_SIZE(tmp);
6370 body = asdl_seq_new(len, arena);
6371 if (body == NULL) goto failed;
6372 for (i = 0; i < len; i++) {
6373 stmt_ty value;
6374 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
6375 if (res != 0) goto failed;
6376 asdl_seq_SET(body, i, value);
6378 Py_XDECREF(tmp);
6379 tmp = NULL;
6380 } else {
6381 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler");
6382 return 1;
6384 *out = ExceptHandler(type, name, body, lineno, col_offset,
6385 arena);
6386 if (*out == NULL) goto failed;
6387 return 0;
6390 tmp = PyObject_Repr(obj);
6391 if (tmp == NULL) goto failed;
6392 PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %.400s", PyString_AS_STRING(tmp));
6393 failed:
6394 Py_XDECREF(tmp);
6395 return 1;
6399 obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena)
6401 PyObject* tmp = NULL;
6402 asdl_seq* args;
6403 identifier vararg;
6404 identifier kwarg;
6405 asdl_seq* defaults;
6407 if (PyObject_HasAttrString(obj, "args")) {
6408 int res;
6409 Py_ssize_t len;
6410 Py_ssize_t i;
6411 tmp = PyObject_GetAttrString(obj, "args");
6412 if (tmp == NULL) goto failed;
6413 if (!PyList_Check(tmp)) {
6414 PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name);
6415 goto failed;
6417 len = PyList_GET_SIZE(tmp);
6418 args = asdl_seq_new(len, arena);
6419 if (args == NULL) goto failed;
6420 for (i = 0; i < len; i++) {
6421 expr_ty value;
6422 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
6423 if (res != 0) goto failed;
6424 asdl_seq_SET(args, i, value);
6426 Py_XDECREF(tmp);
6427 tmp = NULL;
6428 } else {
6429 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments");
6430 return 1;
6432 if (PyObject_HasAttrString(obj, "vararg")) {
6433 int res;
6434 tmp = PyObject_GetAttrString(obj, "vararg");
6435 if (tmp == NULL) goto failed;
6436 res = obj2ast_identifier(tmp, &vararg, arena);
6437 if (res != 0) goto failed;
6438 Py_XDECREF(tmp);
6439 tmp = NULL;
6440 } else {
6441 vararg = NULL;
6443 if (PyObject_HasAttrString(obj, "kwarg")) {
6444 int res;
6445 tmp = PyObject_GetAttrString(obj, "kwarg");
6446 if (tmp == NULL) goto failed;
6447 res = obj2ast_identifier(tmp, &kwarg, arena);
6448 if (res != 0) goto failed;
6449 Py_XDECREF(tmp);
6450 tmp = NULL;
6451 } else {
6452 kwarg = NULL;
6454 if (PyObject_HasAttrString(obj, "defaults")) {
6455 int res;
6456 Py_ssize_t len;
6457 Py_ssize_t i;
6458 tmp = PyObject_GetAttrString(obj, "defaults");
6459 if (tmp == NULL) goto failed;
6460 if (!PyList_Check(tmp)) {
6461 PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name);
6462 goto failed;
6464 len = PyList_GET_SIZE(tmp);
6465 defaults = asdl_seq_new(len, arena);
6466 if (defaults == NULL) goto failed;
6467 for (i = 0; i < len; i++) {
6468 expr_ty value;
6469 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
6470 if (res != 0) goto failed;
6471 asdl_seq_SET(defaults, i, value);
6473 Py_XDECREF(tmp);
6474 tmp = NULL;
6475 } else {
6476 PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments");
6477 return 1;
6479 *out = arguments(args, vararg, kwarg, defaults, arena);
6480 return 0;
6481 failed:
6482 Py_XDECREF(tmp);
6483 return 1;
6487 obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena)
6489 PyObject* tmp = NULL;
6490 identifier arg;
6491 expr_ty value;
6493 if (PyObject_HasAttrString(obj, "arg")) {
6494 int res;
6495 tmp = PyObject_GetAttrString(obj, "arg");
6496 if (tmp == NULL) goto failed;
6497 res = obj2ast_identifier(tmp, &arg, arena);
6498 if (res != 0) goto failed;
6499 Py_XDECREF(tmp);
6500 tmp = NULL;
6501 } else {
6502 PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from keyword");
6503 return 1;
6505 if (PyObject_HasAttrString(obj, "value")) {
6506 int res;
6507 tmp = PyObject_GetAttrString(obj, "value");
6508 if (tmp == NULL) goto failed;
6509 res = obj2ast_expr(tmp, &value, arena);
6510 if (res != 0) goto failed;
6511 Py_XDECREF(tmp);
6512 tmp = NULL;
6513 } else {
6514 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword");
6515 return 1;
6517 *out = keyword(arg, value, arena);
6518 return 0;
6519 failed:
6520 Py_XDECREF(tmp);
6521 return 1;
6525 obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena)
6527 PyObject* tmp = NULL;
6528 identifier name;
6529 identifier asname;
6531 if (PyObject_HasAttrString(obj, "name")) {
6532 int res;
6533 tmp = PyObject_GetAttrString(obj, "name");
6534 if (tmp == NULL) goto failed;
6535 res = obj2ast_identifier(tmp, &name, arena);
6536 if (res != 0) goto failed;
6537 Py_XDECREF(tmp);
6538 tmp = NULL;
6539 } else {
6540 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias");
6541 return 1;
6543 if (PyObject_HasAttrString(obj, "asname")) {
6544 int res;
6545 tmp = PyObject_GetAttrString(obj, "asname");
6546 if (tmp == NULL) goto failed;
6547 res = obj2ast_identifier(tmp, &asname, arena);
6548 if (res != 0) goto failed;
6549 Py_XDECREF(tmp);
6550 tmp = NULL;
6551 } else {
6552 asname = NULL;
6554 *out = alias(name, asname, arena);
6555 return 0;
6556 failed:
6557 Py_XDECREF(tmp);
6558 return 1;
6562 PyMODINIT_FUNC
6563 init_ast(void)
6565 PyObject *m, *d;
6566 if (!init_types()) return;
6567 m = Py_InitModule3("_ast", NULL, NULL);
6568 if (!m) return;
6569 d = PyModule_GetDict(m);
6570 if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return;
6571 if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)
6572 return;
6573 if (PyModule_AddStringConstant(m, "__version__", "82160") < 0)
6574 return;
6575 if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return;
6576 if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0)
6577 return;
6578 if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type)
6579 < 0) return;
6580 if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) <
6581 0) return;
6582 if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return;
6583 if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return;
6584 if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type)
6585 < 0) return;
6586 if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0)
6587 return;
6588 if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0)
6589 return;
6590 if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0)
6591 return;
6592 if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0)
6593 return;
6594 if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) <
6595 0) return;
6596 if (PyDict_SetItemString(d, "Print", (PyObject*)Print_type) < 0) return;
6597 if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return;
6598 if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return;
6599 if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return;
6600 if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return;
6601 if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return;
6602 if (PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) <
6603 0) return;
6604 if (PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) <
6605 0) return;
6606 if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0)
6607 return;
6608 if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0)
6609 return;
6610 if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) <
6611 0) return;
6612 if (PyDict_SetItemString(d, "Exec", (PyObject*)Exec_type) < 0) return;
6613 if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0)
6614 return;
6615 if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return;
6616 if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return;
6617 if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return;
6618 if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0)
6619 return;
6620 if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return;
6621 if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0)
6622 return;
6623 if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return;
6624 if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0)
6625 return;
6626 if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0)
6627 return;
6628 if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return;
6629 if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return;
6630 if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return;
6631 if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0)
6632 return;
6633 if (PyDict_SetItemString(d, "SetComp", (PyObject*)SetComp_type) < 0)
6634 return;
6635 if (PyDict_SetItemString(d, "DictComp", (PyObject*)DictComp_type) < 0)
6636 return;
6637 if (PyDict_SetItemString(d, "GeneratorExp",
6638 (PyObject*)GeneratorExp_type) < 0) return;
6639 if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return;
6640 if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0)
6641 return;
6642 if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return;
6643 if (PyDict_SetItemString(d, "Repr", (PyObject*)Repr_type) < 0) return;
6644 if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return;
6645 if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return;
6646 if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) <
6647 0) return;
6648 if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) <
6649 0) return;
6650 if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return;
6651 if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return;
6652 if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return;
6653 if (PyDict_SetItemString(d, "expr_context",
6654 (PyObject*)expr_context_type) < 0) return;
6655 if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return;
6656 if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return;
6657 if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return;
6658 if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0)
6659 return;
6660 if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0)
6661 return;
6662 if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return;
6663 if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return;
6664 if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0)
6665 return;
6666 if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return;
6667 if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0)
6668 return;
6669 if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return;
6670 if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0)
6671 return;
6672 if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return;
6673 if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return;
6674 if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0)
6675 return;
6676 if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return;
6677 if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return;
6678 if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return;
6679 if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return;
6680 if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return;
6681 if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return;
6682 if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0)
6683 return;
6684 if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0)
6685 return;
6686 if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return;
6687 if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0)
6688 return;
6689 if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0)
6690 return;
6691 if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0)
6692 return;
6693 if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0)
6694 return;
6695 if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0)
6696 return;
6697 if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return;
6698 if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return;
6699 if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return;
6700 if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return;
6701 if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return;
6702 if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return;
6703 if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return;
6704 if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return;
6705 if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return;
6706 if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return;
6707 if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return;
6708 if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return;
6709 if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return;
6710 if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return;
6711 if (PyDict_SetItemString(d, "comprehension",
6712 (PyObject*)comprehension_type) < 0) return;
6713 if (PyDict_SetItemString(d, "excepthandler",
6714 (PyObject*)excepthandler_type) < 0) return;
6715 if (PyDict_SetItemString(d, "ExceptHandler",
6716 (PyObject*)ExceptHandler_type) < 0) return;
6717 if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) <
6718 0) return;
6719 if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0)
6720 return;
6721 if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return;
6725 PyObject* PyAST_mod2obj(mod_ty t)
6727 init_types();
6728 return ast2obj_mod(t);
6731 /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */
6732 mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode)
6734 mod_ty res;
6735 PyObject *req_type[] = {(PyObject*)Module_type, (PyObject*)Expression_type,
6736 (PyObject*)Interactive_type};
6737 char *req_name[] = {"Module", "Expression", "Interactive"};
6738 int isinstance;
6739 assert(0 <= mode && mode <= 2);
6741 init_types();
6743 isinstance = PyObject_IsInstance(ast, req_type[mode]);
6744 if (isinstance == -1)
6745 return NULL;
6746 if (!isinstance) {
6747 PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s",
6748 req_name[mode], Py_TYPE(ast)->tp_name);
6749 return NULL;
6751 if (obj2ast_mod(ast, &res, arena) != 0)
6752 return NULL;
6753 else
6754 return res;
6757 int PyAST_Check(PyObject* obj)
6759 init_types();
6760 return PyObject_IsInstance(obj, (PyObject*)&AST_type);