remove wrong markup
[python.git] / Python / Python-ast.c
blob6b3424a292df0a5d66d3b6370e0193738dda6d2b
1 /* File automatically generated by Parser/asdl_c.py. */
4 /*
5 __version__ 77422.
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) return 0;
531 for(i = 0; i < num_fields; i++) {
532 s = PyString_FromString(attrs[i]);
533 if (!s) {
534 Py_DECREF(l);
535 return 0;
537 PyTuple_SET_ITEM(l, i, s);
539 result = PyObject_SetAttrString((PyObject*)type, "_attributes", l) >= 0;
540 Py_DECREF(l);
541 return result;
544 /* Conversion AST -> Python */
546 static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
548 int i, n = asdl_seq_LEN(seq);
549 PyObject *result = PyList_New(n);
550 PyObject *value;
551 if (!result)
552 return NULL;
553 for (i = 0; i < n; i++) {
554 value = func(asdl_seq_GET(seq, i));
555 if (!value) {
556 Py_DECREF(result);
557 return NULL;
559 PyList_SET_ITEM(result, i, value);
561 return result;
564 static PyObject* ast2obj_object(void *o)
566 if (!o)
567 o = Py_None;
568 Py_INCREF((PyObject*)o);
569 return (PyObject*)o;
571 #define ast2obj_identifier ast2obj_object
572 #define ast2obj_string ast2obj_object
573 static PyObject* ast2obj_bool(bool b)
575 return PyBool_FromLong(b);
578 static PyObject* ast2obj_int(long b)
580 return PyInt_FromLong(b);
583 /* Conversion Python -> AST */
585 static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena)
587 if (obj == Py_None)
588 obj = NULL;
589 if (obj)
590 PyArena_AddPyObject(arena, obj);
591 Py_XINCREF(obj);
592 *out = obj;
593 return 0;
596 #define obj2ast_identifier obj2ast_object
597 #define obj2ast_string obj2ast_object
599 static int obj2ast_int(PyObject* obj, int* out, PyArena* arena)
601 int i;
602 if (!PyInt_Check(obj) && !PyLong_Check(obj)) {
603 PyObject *s = PyObject_Repr(obj);
604 if (s == NULL) return 1;
605 PyErr_Format(PyExc_ValueError, "invalid integer value: %.400s",
606 PyString_AS_STRING(s));
607 Py_DECREF(s);
608 return 1;
611 i = (int)PyLong_AsLong(obj);
612 if (i == -1 && PyErr_Occurred())
613 return 1;
614 *out = i;
615 return 0;
618 static int obj2ast_bool(PyObject* obj, bool* out, PyArena* arena)
620 if (!PyBool_Check(obj)) {
621 PyObject *s = PyObject_Repr(obj);
622 if (s == NULL) return 1;
623 PyErr_Format(PyExc_ValueError, "invalid boolean value: %.400s",
624 PyString_AS_STRING(s));
625 Py_DECREF(s);
626 return 1;
629 *out = (obj == Py_True);
630 return 0;
633 static int add_ast_fields(void)
635 PyObject *empty_tuple, *d;
636 if (PyType_Ready(&AST_type) < 0)
637 return -1;
638 d = AST_type.tp_dict;
639 empty_tuple = PyTuple_New(0);
640 if (!empty_tuple ||
641 PyDict_SetItemString(d, "_fields", empty_tuple) < 0 ||
642 PyDict_SetItemString(d, "_attributes", empty_tuple) < 0) {
643 Py_XDECREF(empty_tuple);
644 return -1;
646 Py_DECREF(empty_tuple);
647 return 0;
651 static int init_types(void)
653 static int initialized;
654 if (initialized) return 1;
655 if (add_ast_fields() < 0) return 0;
656 mod_type = make_type("mod", &AST_type, NULL, 0);
657 if (!mod_type) return 0;
658 if (!add_attributes(mod_type, NULL, 0)) return 0;
659 Module_type = make_type("Module", mod_type, Module_fields, 1);
660 if (!Module_type) return 0;
661 Interactive_type = make_type("Interactive", mod_type,
662 Interactive_fields, 1);
663 if (!Interactive_type) return 0;
664 Expression_type = make_type("Expression", mod_type, Expression_fields,
666 if (!Expression_type) return 0;
667 Suite_type = make_type("Suite", mod_type, Suite_fields, 1);
668 if (!Suite_type) return 0;
669 stmt_type = make_type("stmt", &AST_type, NULL, 0);
670 if (!stmt_type) return 0;
671 if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0;
672 FunctionDef_type = make_type("FunctionDef", stmt_type,
673 FunctionDef_fields, 4);
674 if (!FunctionDef_type) return 0;
675 ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 4);
676 if (!ClassDef_type) return 0;
677 Return_type = make_type("Return", stmt_type, Return_fields, 1);
678 if (!Return_type) return 0;
679 Delete_type = make_type("Delete", stmt_type, Delete_fields, 1);
680 if (!Delete_type) return 0;
681 Assign_type = make_type("Assign", stmt_type, Assign_fields, 2);
682 if (!Assign_type) return 0;
683 AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3);
684 if (!AugAssign_type) return 0;
685 Print_type = make_type("Print", stmt_type, Print_fields, 3);
686 if (!Print_type) return 0;
687 For_type = make_type("For", stmt_type, For_fields, 4);
688 if (!For_type) return 0;
689 While_type = make_type("While", stmt_type, While_fields, 3);
690 if (!While_type) return 0;
691 If_type = make_type("If", stmt_type, If_fields, 3);
692 if (!If_type) return 0;
693 With_type = make_type("With", stmt_type, With_fields, 3);
694 if (!With_type) return 0;
695 Raise_type = make_type("Raise", stmt_type, Raise_fields, 3);
696 if (!Raise_type) return 0;
697 TryExcept_type = make_type("TryExcept", stmt_type, TryExcept_fields, 3);
698 if (!TryExcept_type) return 0;
699 TryFinally_type = make_type("TryFinally", stmt_type, TryFinally_fields,
701 if (!TryFinally_type) return 0;
702 Assert_type = make_type("Assert", stmt_type, Assert_fields, 2);
703 if (!Assert_type) return 0;
704 Import_type = make_type("Import", stmt_type, Import_fields, 1);
705 if (!Import_type) return 0;
706 ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields,
708 if (!ImportFrom_type) return 0;
709 Exec_type = make_type("Exec", stmt_type, Exec_fields, 3);
710 if (!Exec_type) return 0;
711 Global_type = make_type("Global", stmt_type, Global_fields, 1);
712 if (!Global_type) return 0;
713 Expr_type = make_type("Expr", stmt_type, Expr_fields, 1);
714 if (!Expr_type) return 0;
715 Pass_type = make_type("Pass", stmt_type, NULL, 0);
716 if (!Pass_type) return 0;
717 Break_type = make_type("Break", stmt_type, NULL, 0);
718 if (!Break_type) return 0;
719 Continue_type = make_type("Continue", stmt_type, NULL, 0);
720 if (!Continue_type) return 0;
721 expr_type = make_type("expr", &AST_type, NULL, 0);
722 if (!expr_type) return 0;
723 if (!add_attributes(expr_type, expr_attributes, 2)) return 0;
724 BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2);
725 if (!BoolOp_type) return 0;
726 BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3);
727 if (!BinOp_type) return 0;
728 UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2);
729 if (!UnaryOp_type) return 0;
730 Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2);
731 if (!Lambda_type) return 0;
732 IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3);
733 if (!IfExp_type) return 0;
734 Dict_type = make_type("Dict", expr_type, Dict_fields, 2);
735 if (!Dict_type) return 0;
736 Set_type = make_type("Set", expr_type, Set_fields, 1);
737 if (!Set_type) return 0;
738 ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2);
739 if (!ListComp_type) return 0;
740 SetComp_type = make_type("SetComp", expr_type, SetComp_fields, 2);
741 if (!SetComp_type) return 0;
742 DictComp_type = make_type("DictComp", expr_type, DictComp_fields, 3);
743 if (!DictComp_type) return 0;
744 GeneratorExp_type = make_type("GeneratorExp", expr_type,
745 GeneratorExp_fields, 2);
746 if (!GeneratorExp_type) return 0;
747 Yield_type = make_type("Yield", expr_type, Yield_fields, 1);
748 if (!Yield_type) return 0;
749 Compare_type = make_type("Compare", expr_type, Compare_fields, 3);
750 if (!Compare_type) return 0;
751 Call_type = make_type("Call", expr_type, Call_fields, 5);
752 if (!Call_type) return 0;
753 Repr_type = make_type("Repr", expr_type, Repr_fields, 1);
754 if (!Repr_type) return 0;
755 Num_type = make_type("Num", expr_type, Num_fields, 1);
756 if (!Num_type) return 0;
757 Str_type = make_type("Str", expr_type, Str_fields, 1);
758 if (!Str_type) return 0;
759 Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3);
760 if (!Attribute_type) return 0;
761 Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3);
762 if (!Subscript_type) return 0;
763 Name_type = make_type("Name", expr_type, Name_fields, 2);
764 if (!Name_type) return 0;
765 List_type = make_type("List", expr_type, List_fields, 2);
766 if (!List_type) return 0;
767 Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2);
768 if (!Tuple_type) return 0;
769 expr_context_type = make_type("expr_context", &AST_type, NULL, 0);
770 if (!expr_context_type) return 0;
771 if (!add_attributes(expr_context_type, NULL, 0)) return 0;
772 Load_type = make_type("Load", expr_context_type, NULL, 0);
773 if (!Load_type) return 0;
774 Load_singleton = PyType_GenericNew(Load_type, NULL, NULL);
775 if (!Load_singleton) return 0;
776 Store_type = make_type("Store", expr_context_type, NULL, 0);
777 if (!Store_type) return 0;
778 Store_singleton = PyType_GenericNew(Store_type, NULL, NULL);
779 if (!Store_singleton) return 0;
780 Del_type = make_type("Del", expr_context_type, NULL, 0);
781 if (!Del_type) return 0;
782 Del_singleton = PyType_GenericNew(Del_type, NULL, NULL);
783 if (!Del_singleton) return 0;
784 AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0);
785 if (!AugLoad_type) return 0;
786 AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL);
787 if (!AugLoad_singleton) return 0;
788 AugStore_type = make_type("AugStore", expr_context_type, NULL, 0);
789 if (!AugStore_type) return 0;
790 AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL);
791 if (!AugStore_singleton) return 0;
792 Param_type = make_type("Param", expr_context_type, NULL, 0);
793 if (!Param_type) return 0;
794 Param_singleton = PyType_GenericNew(Param_type, NULL, NULL);
795 if (!Param_singleton) return 0;
796 slice_type = make_type("slice", &AST_type, NULL, 0);
797 if (!slice_type) return 0;
798 if (!add_attributes(slice_type, NULL, 0)) return 0;
799 Ellipsis_type = make_type("Ellipsis", slice_type, NULL, 0);
800 if (!Ellipsis_type) return 0;
801 Slice_type = make_type("Slice", slice_type, Slice_fields, 3);
802 if (!Slice_type) return 0;
803 ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1);
804 if (!ExtSlice_type) return 0;
805 Index_type = make_type("Index", slice_type, Index_fields, 1);
806 if (!Index_type) return 0;
807 boolop_type = make_type("boolop", &AST_type, NULL, 0);
808 if (!boolop_type) return 0;
809 if (!add_attributes(boolop_type, NULL, 0)) return 0;
810 And_type = make_type("And", boolop_type, NULL, 0);
811 if (!And_type) return 0;
812 And_singleton = PyType_GenericNew(And_type, NULL, NULL);
813 if (!And_singleton) return 0;
814 Or_type = make_type("Or", boolop_type, NULL, 0);
815 if (!Or_type) return 0;
816 Or_singleton = PyType_GenericNew(Or_type, NULL, NULL);
817 if (!Or_singleton) return 0;
818 operator_type = make_type("operator", &AST_type, NULL, 0);
819 if (!operator_type) return 0;
820 if (!add_attributes(operator_type, NULL, 0)) return 0;
821 Add_type = make_type("Add", operator_type, NULL, 0);
822 if (!Add_type) return 0;
823 Add_singleton = PyType_GenericNew(Add_type, NULL, NULL);
824 if (!Add_singleton) return 0;
825 Sub_type = make_type("Sub", operator_type, NULL, 0);
826 if (!Sub_type) return 0;
827 Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL);
828 if (!Sub_singleton) return 0;
829 Mult_type = make_type("Mult", operator_type, NULL, 0);
830 if (!Mult_type) return 0;
831 Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL);
832 if (!Mult_singleton) return 0;
833 Div_type = make_type("Div", operator_type, NULL, 0);
834 if (!Div_type) return 0;
835 Div_singleton = PyType_GenericNew(Div_type, NULL, NULL);
836 if (!Div_singleton) return 0;
837 Mod_type = make_type("Mod", operator_type, NULL, 0);
838 if (!Mod_type) return 0;
839 Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL);
840 if (!Mod_singleton) return 0;
841 Pow_type = make_type("Pow", operator_type, NULL, 0);
842 if (!Pow_type) return 0;
843 Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL);
844 if (!Pow_singleton) return 0;
845 LShift_type = make_type("LShift", operator_type, NULL, 0);
846 if (!LShift_type) return 0;
847 LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL);
848 if (!LShift_singleton) return 0;
849 RShift_type = make_type("RShift", operator_type, NULL, 0);
850 if (!RShift_type) return 0;
851 RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL);
852 if (!RShift_singleton) return 0;
853 BitOr_type = make_type("BitOr", operator_type, NULL, 0);
854 if (!BitOr_type) return 0;
855 BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL);
856 if (!BitOr_singleton) return 0;
857 BitXor_type = make_type("BitXor", operator_type, NULL, 0);
858 if (!BitXor_type) return 0;
859 BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL);
860 if (!BitXor_singleton) return 0;
861 BitAnd_type = make_type("BitAnd", operator_type, NULL, 0);
862 if (!BitAnd_type) return 0;
863 BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL);
864 if (!BitAnd_singleton) return 0;
865 FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0);
866 if (!FloorDiv_type) return 0;
867 FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL);
868 if (!FloorDiv_singleton) return 0;
869 unaryop_type = make_type("unaryop", &AST_type, NULL, 0);
870 if (!unaryop_type) return 0;
871 if (!add_attributes(unaryop_type, NULL, 0)) return 0;
872 Invert_type = make_type("Invert", unaryop_type, NULL, 0);
873 if (!Invert_type) return 0;
874 Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL);
875 if (!Invert_singleton) return 0;
876 Not_type = make_type("Not", unaryop_type, NULL, 0);
877 if (!Not_type) return 0;
878 Not_singleton = PyType_GenericNew(Not_type, NULL, NULL);
879 if (!Not_singleton) return 0;
880 UAdd_type = make_type("UAdd", unaryop_type, NULL, 0);
881 if (!UAdd_type) return 0;
882 UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL);
883 if (!UAdd_singleton) return 0;
884 USub_type = make_type("USub", unaryop_type, NULL, 0);
885 if (!USub_type) return 0;
886 USub_singleton = PyType_GenericNew(USub_type, NULL, NULL);
887 if (!USub_singleton) return 0;
888 cmpop_type = make_type("cmpop", &AST_type, NULL, 0);
889 if (!cmpop_type) return 0;
890 if (!add_attributes(cmpop_type, NULL, 0)) return 0;
891 Eq_type = make_type("Eq", cmpop_type, NULL, 0);
892 if (!Eq_type) return 0;
893 Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL);
894 if (!Eq_singleton) return 0;
895 NotEq_type = make_type("NotEq", cmpop_type, NULL, 0);
896 if (!NotEq_type) return 0;
897 NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL);
898 if (!NotEq_singleton) return 0;
899 Lt_type = make_type("Lt", cmpop_type, NULL, 0);
900 if (!Lt_type) return 0;
901 Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL);
902 if (!Lt_singleton) return 0;
903 LtE_type = make_type("LtE", cmpop_type, NULL, 0);
904 if (!LtE_type) return 0;
905 LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL);
906 if (!LtE_singleton) return 0;
907 Gt_type = make_type("Gt", cmpop_type, NULL, 0);
908 if (!Gt_type) return 0;
909 Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL);
910 if (!Gt_singleton) return 0;
911 GtE_type = make_type("GtE", cmpop_type, NULL, 0);
912 if (!GtE_type) return 0;
913 GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL);
914 if (!GtE_singleton) return 0;
915 Is_type = make_type("Is", cmpop_type, NULL, 0);
916 if (!Is_type) return 0;
917 Is_singleton = PyType_GenericNew(Is_type, NULL, NULL);
918 if (!Is_singleton) return 0;
919 IsNot_type = make_type("IsNot", cmpop_type, NULL, 0);
920 if (!IsNot_type) return 0;
921 IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL);
922 if (!IsNot_singleton) return 0;
923 In_type = make_type("In", cmpop_type, NULL, 0);
924 if (!In_type) return 0;
925 In_singleton = PyType_GenericNew(In_type, NULL, NULL);
926 if (!In_singleton) return 0;
927 NotIn_type = make_type("NotIn", cmpop_type, NULL, 0);
928 if (!NotIn_type) return 0;
929 NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL);
930 if (!NotIn_singleton) return 0;
931 comprehension_type = make_type("comprehension", &AST_type,
932 comprehension_fields, 3);
933 if (!comprehension_type) return 0;
934 excepthandler_type = make_type("excepthandler", &AST_type, NULL, 0);
935 if (!excepthandler_type) return 0;
936 if (!add_attributes(excepthandler_type, excepthandler_attributes, 2))
937 return 0;
938 ExceptHandler_type = make_type("ExceptHandler", excepthandler_type,
939 ExceptHandler_fields, 3);
940 if (!ExceptHandler_type) return 0;
941 arguments_type = make_type("arguments", &AST_type, arguments_fields, 4);
942 if (!arguments_type) return 0;
943 keyword_type = make_type("keyword", &AST_type, keyword_fields, 2);
944 if (!keyword_type) return 0;
945 alias_type = make_type("alias", &AST_type, alias_fields, 2);
946 if (!alias_type) return 0;
947 initialized = 1;
948 return 1;
951 static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena);
952 static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena);
953 static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena);
954 static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena*
955 arena);
956 static int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena);
957 static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena);
958 static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena);
959 static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena);
960 static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena);
961 static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena*
962 arena);
963 static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena*
964 arena);
965 static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena);
966 static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena);
967 static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena);
969 mod_ty
970 Module(asdl_seq * body, PyArena *arena)
972 mod_ty p;
973 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
974 if (!p)
975 return NULL;
976 p->kind = Module_kind;
977 p->v.Module.body = body;
978 return p;
981 mod_ty
982 Interactive(asdl_seq * body, PyArena *arena)
984 mod_ty p;
985 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
986 if (!p)
987 return NULL;
988 p->kind = Interactive_kind;
989 p->v.Interactive.body = body;
990 return p;
993 mod_ty
994 Expression(expr_ty body, PyArena *arena)
996 mod_ty p;
997 if (!body) {
998 PyErr_SetString(PyExc_ValueError,
999 "field body is required for Expression");
1000 return NULL;
1002 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
1003 if (!p)
1004 return NULL;
1005 p->kind = Expression_kind;
1006 p->v.Expression.body = body;
1007 return p;
1010 mod_ty
1011 Suite(asdl_seq * body, PyArena *arena)
1013 mod_ty p;
1014 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
1015 if (!p)
1016 return NULL;
1017 p->kind = Suite_kind;
1018 p->v.Suite.body = body;
1019 return p;
1022 stmt_ty
1023 FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
1024 decorator_list, int lineno, int col_offset, PyArena *arena)
1026 stmt_ty p;
1027 if (!name) {
1028 PyErr_SetString(PyExc_ValueError,
1029 "field name is required for FunctionDef");
1030 return NULL;
1032 if (!args) {
1033 PyErr_SetString(PyExc_ValueError,
1034 "field args is required for FunctionDef");
1035 return NULL;
1037 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1038 if (!p)
1039 return NULL;
1040 p->kind = FunctionDef_kind;
1041 p->v.FunctionDef.name = name;
1042 p->v.FunctionDef.args = args;
1043 p->v.FunctionDef.body = body;
1044 p->v.FunctionDef.decorator_list = decorator_list;
1045 p->lineno = lineno;
1046 p->col_offset = col_offset;
1047 return p;
1050 stmt_ty
1051 ClassDef(identifier name, asdl_seq * bases, asdl_seq * body, asdl_seq *
1052 decorator_list, int lineno, int col_offset, PyArena *arena)
1054 stmt_ty p;
1055 if (!name) {
1056 PyErr_SetString(PyExc_ValueError,
1057 "field name is required for ClassDef");
1058 return NULL;
1060 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1061 if (!p)
1062 return NULL;
1063 p->kind = ClassDef_kind;
1064 p->v.ClassDef.name = name;
1065 p->v.ClassDef.bases = bases;
1066 p->v.ClassDef.body = body;
1067 p->v.ClassDef.decorator_list = decorator_list;
1068 p->lineno = lineno;
1069 p->col_offset = col_offset;
1070 return p;
1073 stmt_ty
1074 Return(expr_ty value, int lineno, int col_offset, PyArena *arena)
1076 stmt_ty p;
1077 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1078 if (!p)
1079 return NULL;
1080 p->kind = Return_kind;
1081 p->v.Return.value = value;
1082 p->lineno = lineno;
1083 p->col_offset = col_offset;
1084 return p;
1087 stmt_ty
1088 Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena)
1090 stmt_ty p;
1091 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1092 if (!p)
1093 return NULL;
1094 p->kind = Delete_kind;
1095 p->v.Delete.targets = targets;
1096 p->lineno = lineno;
1097 p->col_offset = col_offset;
1098 return p;
1101 stmt_ty
1102 Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena
1103 *arena)
1105 stmt_ty p;
1106 if (!value) {
1107 PyErr_SetString(PyExc_ValueError,
1108 "field value is required for Assign");
1109 return NULL;
1111 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1112 if (!p)
1113 return NULL;
1114 p->kind = Assign_kind;
1115 p->v.Assign.targets = targets;
1116 p->v.Assign.value = value;
1117 p->lineno = lineno;
1118 p->col_offset = col_offset;
1119 return p;
1122 stmt_ty
1123 AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
1124 col_offset, PyArena *arena)
1126 stmt_ty p;
1127 if (!target) {
1128 PyErr_SetString(PyExc_ValueError,
1129 "field target is required for AugAssign");
1130 return NULL;
1132 if (!op) {
1133 PyErr_SetString(PyExc_ValueError,
1134 "field op is required for AugAssign");
1135 return NULL;
1137 if (!value) {
1138 PyErr_SetString(PyExc_ValueError,
1139 "field value is required for AugAssign");
1140 return NULL;
1142 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1143 if (!p)
1144 return NULL;
1145 p->kind = AugAssign_kind;
1146 p->v.AugAssign.target = target;
1147 p->v.AugAssign.op = op;
1148 p->v.AugAssign.value = value;
1149 p->lineno = lineno;
1150 p->col_offset = col_offset;
1151 return p;
1154 stmt_ty
1155 Print(expr_ty dest, asdl_seq * values, bool nl, int lineno, int col_offset,
1156 PyArena *arena)
1158 stmt_ty p;
1159 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1160 if (!p)
1161 return NULL;
1162 p->kind = Print_kind;
1163 p->v.Print.dest = dest;
1164 p->v.Print.values = values;
1165 p->v.Print.nl = nl;
1166 p->lineno = lineno;
1167 p->col_offset = col_offset;
1168 return p;
1171 stmt_ty
1172 For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int
1173 lineno, int col_offset, PyArena *arena)
1175 stmt_ty p;
1176 if (!target) {
1177 PyErr_SetString(PyExc_ValueError,
1178 "field target is required for For");
1179 return NULL;
1181 if (!iter) {
1182 PyErr_SetString(PyExc_ValueError,
1183 "field iter is required for For");
1184 return NULL;
1186 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1187 if (!p)
1188 return NULL;
1189 p->kind = For_kind;
1190 p->v.For.target = target;
1191 p->v.For.iter = iter;
1192 p->v.For.body = body;
1193 p->v.For.orelse = orelse;
1194 p->lineno = lineno;
1195 p->col_offset = col_offset;
1196 return p;
1199 stmt_ty
1200 While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
1201 col_offset, PyArena *arena)
1203 stmt_ty p;
1204 if (!test) {
1205 PyErr_SetString(PyExc_ValueError,
1206 "field test is required for While");
1207 return NULL;
1209 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1210 if (!p)
1211 return NULL;
1212 p->kind = While_kind;
1213 p->v.While.test = test;
1214 p->v.While.body = body;
1215 p->v.While.orelse = orelse;
1216 p->lineno = lineno;
1217 p->col_offset = col_offset;
1218 return p;
1221 stmt_ty
1222 If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
1223 col_offset, PyArena *arena)
1225 stmt_ty p;
1226 if (!test) {
1227 PyErr_SetString(PyExc_ValueError,
1228 "field test is required for If");
1229 return NULL;
1231 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1232 if (!p)
1233 return NULL;
1234 p->kind = If_kind;
1235 p->v.If.test = test;
1236 p->v.If.body = body;
1237 p->v.If.orelse = orelse;
1238 p->lineno = lineno;
1239 p->col_offset = col_offset;
1240 return p;
1243 stmt_ty
1244 With(expr_ty context_expr, expr_ty optional_vars, asdl_seq * body, int lineno,
1245 int col_offset, PyArena *arena)
1247 stmt_ty p;
1248 if (!context_expr) {
1249 PyErr_SetString(PyExc_ValueError,
1250 "field context_expr is required for With");
1251 return NULL;
1253 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1254 if (!p)
1255 return NULL;
1256 p->kind = With_kind;
1257 p->v.With.context_expr = context_expr;
1258 p->v.With.optional_vars = optional_vars;
1259 p->v.With.body = body;
1260 p->lineno = lineno;
1261 p->col_offset = col_offset;
1262 return p;
1265 stmt_ty
1266 Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno, int col_offset,
1267 PyArena *arena)
1269 stmt_ty p;
1270 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1271 if (!p)
1272 return NULL;
1273 p->kind = Raise_kind;
1274 p->v.Raise.type = type;
1275 p->v.Raise.inst = inst;
1276 p->v.Raise.tback = tback;
1277 p->lineno = lineno;
1278 p->col_offset = col_offset;
1279 return p;
1282 stmt_ty
1283 TryExcept(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, int lineno,
1284 int col_offset, PyArena *arena)
1286 stmt_ty p;
1287 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1288 if (!p)
1289 return NULL;
1290 p->kind = TryExcept_kind;
1291 p->v.TryExcept.body = body;
1292 p->v.TryExcept.handlers = handlers;
1293 p->v.TryExcept.orelse = orelse;
1294 p->lineno = lineno;
1295 p->col_offset = col_offset;
1296 return p;
1299 stmt_ty
1300 TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, int col_offset,
1301 PyArena *arena)
1303 stmt_ty p;
1304 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1305 if (!p)
1306 return NULL;
1307 p->kind = TryFinally_kind;
1308 p->v.TryFinally.body = body;
1309 p->v.TryFinally.finalbody = finalbody;
1310 p->lineno = lineno;
1311 p->col_offset = col_offset;
1312 return p;
1315 stmt_ty
1316 Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, PyArena *arena)
1318 stmt_ty p;
1319 if (!test) {
1320 PyErr_SetString(PyExc_ValueError,
1321 "field test is required for Assert");
1322 return NULL;
1324 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1325 if (!p)
1326 return NULL;
1327 p->kind = Assert_kind;
1328 p->v.Assert.test = test;
1329 p->v.Assert.msg = msg;
1330 p->lineno = lineno;
1331 p->col_offset = col_offset;
1332 return p;
1335 stmt_ty
1336 Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
1338 stmt_ty p;
1339 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1340 if (!p)
1341 return NULL;
1342 p->kind = Import_kind;
1343 p->v.Import.names = names;
1344 p->lineno = lineno;
1345 p->col_offset = col_offset;
1346 return p;
1349 stmt_ty
1350 ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int
1351 col_offset, PyArena *arena)
1353 stmt_ty p;
1354 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1355 if (!p)
1356 return NULL;
1357 p->kind = ImportFrom_kind;
1358 p->v.ImportFrom.module = module;
1359 p->v.ImportFrom.names = names;
1360 p->v.ImportFrom.level = level;
1361 p->lineno = lineno;
1362 p->col_offset = col_offset;
1363 return p;
1366 stmt_ty
1367 Exec(expr_ty body, expr_ty globals, expr_ty locals, int lineno, int col_offset,
1368 PyArena *arena)
1370 stmt_ty p;
1371 if (!body) {
1372 PyErr_SetString(PyExc_ValueError,
1373 "field body is required for Exec");
1374 return NULL;
1376 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1377 if (!p)
1378 return NULL;
1379 p->kind = Exec_kind;
1380 p->v.Exec.body = body;
1381 p->v.Exec.globals = globals;
1382 p->v.Exec.locals = locals;
1383 p->lineno = lineno;
1384 p->col_offset = col_offset;
1385 return p;
1388 stmt_ty
1389 Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
1391 stmt_ty p;
1392 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1393 if (!p)
1394 return NULL;
1395 p->kind = Global_kind;
1396 p->v.Global.names = names;
1397 p->lineno = lineno;
1398 p->col_offset = col_offset;
1399 return p;
1402 stmt_ty
1403 Expr(expr_ty value, int lineno, int col_offset, PyArena *arena)
1405 stmt_ty p;
1406 if (!value) {
1407 PyErr_SetString(PyExc_ValueError,
1408 "field value is required for Expr");
1409 return NULL;
1411 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1412 if (!p)
1413 return NULL;
1414 p->kind = Expr_kind;
1415 p->v.Expr.value = value;
1416 p->lineno = lineno;
1417 p->col_offset = col_offset;
1418 return p;
1421 stmt_ty
1422 Pass(int lineno, int col_offset, PyArena *arena)
1424 stmt_ty p;
1425 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1426 if (!p)
1427 return NULL;
1428 p->kind = Pass_kind;
1429 p->lineno = lineno;
1430 p->col_offset = col_offset;
1431 return p;
1434 stmt_ty
1435 Break(int lineno, int col_offset, PyArena *arena)
1437 stmt_ty p;
1438 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1439 if (!p)
1440 return NULL;
1441 p->kind = Break_kind;
1442 p->lineno = lineno;
1443 p->col_offset = col_offset;
1444 return p;
1447 stmt_ty
1448 Continue(int lineno, int col_offset, PyArena *arena)
1450 stmt_ty p;
1451 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1452 if (!p)
1453 return NULL;
1454 p->kind = Continue_kind;
1455 p->lineno = lineno;
1456 p->col_offset = col_offset;
1457 return p;
1460 expr_ty
1461 BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena
1462 *arena)
1464 expr_ty p;
1465 if (!op) {
1466 PyErr_SetString(PyExc_ValueError,
1467 "field op is required for BoolOp");
1468 return NULL;
1470 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1471 if (!p)
1472 return NULL;
1473 p->kind = BoolOp_kind;
1474 p->v.BoolOp.op = op;
1475 p->v.BoolOp.values = values;
1476 p->lineno = lineno;
1477 p->col_offset = col_offset;
1478 return p;
1481 expr_ty
1482 BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset,
1483 PyArena *arena)
1485 expr_ty p;
1486 if (!left) {
1487 PyErr_SetString(PyExc_ValueError,
1488 "field left is required for BinOp");
1489 return NULL;
1491 if (!op) {
1492 PyErr_SetString(PyExc_ValueError,
1493 "field op is required for BinOp");
1494 return NULL;
1496 if (!right) {
1497 PyErr_SetString(PyExc_ValueError,
1498 "field right is required for BinOp");
1499 return NULL;
1501 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1502 if (!p)
1503 return NULL;
1504 p->kind = BinOp_kind;
1505 p->v.BinOp.left = left;
1506 p->v.BinOp.op = op;
1507 p->v.BinOp.right = right;
1508 p->lineno = lineno;
1509 p->col_offset = col_offset;
1510 return p;
1513 expr_ty
1514 UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena
1515 *arena)
1517 expr_ty p;
1518 if (!op) {
1519 PyErr_SetString(PyExc_ValueError,
1520 "field op is required for UnaryOp");
1521 return NULL;
1523 if (!operand) {
1524 PyErr_SetString(PyExc_ValueError,
1525 "field operand is required for UnaryOp");
1526 return NULL;
1528 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1529 if (!p)
1530 return NULL;
1531 p->kind = UnaryOp_kind;
1532 p->v.UnaryOp.op = op;
1533 p->v.UnaryOp.operand = operand;
1534 p->lineno = lineno;
1535 p->col_offset = col_offset;
1536 return p;
1539 expr_ty
1540 Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena
1541 *arena)
1543 expr_ty p;
1544 if (!args) {
1545 PyErr_SetString(PyExc_ValueError,
1546 "field args is required for Lambda");
1547 return NULL;
1549 if (!body) {
1550 PyErr_SetString(PyExc_ValueError,
1551 "field body is required for Lambda");
1552 return NULL;
1554 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1555 if (!p)
1556 return NULL;
1557 p->kind = Lambda_kind;
1558 p->v.Lambda.args = args;
1559 p->v.Lambda.body = body;
1560 p->lineno = lineno;
1561 p->col_offset = col_offset;
1562 return p;
1565 expr_ty
1566 IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset,
1567 PyArena *arena)
1569 expr_ty p;
1570 if (!test) {
1571 PyErr_SetString(PyExc_ValueError,
1572 "field test is required for IfExp");
1573 return NULL;
1575 if (!body) {
1576 PyErr_SetString(PyExc_ValueError,
1577 "field body is required for IfExp");
1578 return NULL;
1580 if (!orelse) {
1581 PyErr_SetString(PyExc_ValueError,
1582 "field orelse is required for IfExp");
1583 return NULL;
1585 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1586 if (!p)
1587 return NULL;
1588 p->kind = IfExp_kind;
1589 p->v.IfExp.test = test;
1590 p->v.IfExp.body = body;
1591 p->v.IfExp.orelse = orelse;
1592 p->lineno = lineno;
1593 p->col_offset = col_offset;
1594 return p;
1597 expr_ty
1598 Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena
1599 *arena)
1601 expr_ty p;
1602 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1603 if (!p)
1604 return NULL;
1605 p->kind = Dict_kind;
1606 p->v.Dict.keys = keys;
1607 p->v.Dict.values = values;
1608 p->lineno = lineno;
1609 p->col_offset = col_offset;
1610 return p;
1613 expr_ty
1614 Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena)
1616 expr_ty p;
1617 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1618 if (!p)
1619 return NULL;
1620 p->kind = Set_kind;
1621 p->v.Set.elts = elts;
1622 p->lineno = lineno;
1623 p->col_offset = col_offset;
1624 return p;
1627 expr_ty
1628 ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1629 PyArena *arena)
1631 expr_ty p;
1632 if (!elt) {
1633 PyErr_SetString(PyExc_ValueError,
1634 "field elt is required for ListComp");
1635 return NULL;
1637 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1638 if (!p)
1639 return NULL;
1640 p->kind = ListComp_kind;
1641 p->v.ListComp.elt = elt;
1642 p->v.ListComp.generators = generators;
1643 p->lineno = lineno;
1644 p->col_offset = col_offset;
1645 return p;
1648 expr_ty
1649 SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, PyArena
1650 *arena)
1652 expr_ty p;
1653 if (!elt) {
1654 PyErr_SetString(PyExc_ValueError,
1655 "field elt is required for SetComp");
1656 return NULL;
1658 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1659 if (!p)
1660 return NULL;
1661 p->kind = SetComp_kind;
1662 p->v.SetComp.elt = elt;
1663 p->v.SetComp.generators = generators;
1664 p->lineno = lineno;
1665 p->col_offset = col_offset;
1666 return p;
1669 expr_ty
1670 DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int lineno, int
1671 col_offset, PyArena *arena)
1673 expr_ty p;
1674 if (!key) {
1675 PyErr_SetString(PyExc_ValueError,
1676 "field key is required for DictComp");
1677 return NULL;
1679 if (!value) {
1680 PyErr_SetString(PyExc_ValueError,
1681 "field value is required for DictComp");
1682 return NULL;
1684 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1685 if (!p)
1686 return NULL;
1687 p->kind = DictComp_kind;
1688 p->v.DictComp.key = key;
1689 p->v.DictComp.value = value;
1690 p->v.DictComp.generators = generators;
1691 p->lineno = lineno;
1692 p->col_offset = col_offset;
1693 return p;
1696 expr_ty
1697 GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1698 PyArena *arena)
1700 expr_ty p;
1701 if (!elt) {
1702 PyErr_SetString(PyExc_ValueError,
1703 "field elt is required for GeneratorExp");
1704 return NULL;
1706 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1707 if (!p)
1708 return NULL;
1709 p->kind = GeneratorExp_kind;
1710 p->v.GeneratorExp.elt = elt;
1711 p->v.GeneratorExp.generators = generators;
1712 p->lineno = lineno;
1713 p->col_offset = col_offset;
1714 return p;
1717 expr_ty
1718 Yield(expr_ty value, int lineno, int col_offset, PyArena *arena)
1720 expr_ty p;
1721 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1722 if (!p)
1723 return NULL;
1724 p->kind = Yield_kind;
1725 p->v.Yield.value = value;
1726 p->lineno = lineno;
1727 p->col_offset = col_offset;
1728 return p;
1731 expr_ty
1732 Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno,
1733 int col_offset, PyArena *arena)
1735 expr_ty p;
1736 if (!left) {
1737 PyErr_SetString(PyExc_ValueError,
1738 "field left is required for Compare");
1739 return NULL;
1741 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1742 if (!p)
1743 return NULL;
1744 p->kind = Compare_kind;
1745 p->v.Compare.left = left;
1746 p->v.Compare.ops = ops;
1747 p->v.Compare.comparators = comparators;
1748 p->lineno = lineno;
1749 p->col_offset = col_offset;
1750 return p;
1753 expr_ty
1754 Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, expr_ty starargs,
1755 expr_ty kwargs, int lineno, int col_offset, PyArena *arena)
1757 expr_ty p;
1758 if (!func) {
1759 PyErr_SetString(PyExc_ValueError,
1760 "field func is required for Call");
1761 return NULL;
1763 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1764 if (!p)
1765 return NULL;
1766 p->kind = Call_kind;
1767 p->v.Call.func = func;
1768 p->v.Call.args = args;
1769 p->v.Call.keywords = keywords;
1770 p->v.Call.starargs = starargs;
1771 p->v.Call.kwargs = kwargs;
1772 p->lineno = lineno;
1773 p->col_offset = col_offset;
1774 return p;
1777 expr_ty
1778 Repr(expr_ty value, int lineno, int col_offset, PyArena *arena)
1780 expr_ty p;
1781 if (!value) {
1782 PyErr_SetString(PyExc_ValueError,
1783 "field value is required for Repr");
1784 return NULL;
1786 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1787 if (!p)
1788 return NULL;
1789 p->kind = Repr_kind;
1790 p->v.Repr.value = value;
1791 p->lineno = lineno;
1792 p->col_offset = col_offset;
1793 return p;
1796 expr_ty
1797 Num(object n, int lineno, int col_offset, PyArena *arena)
1799 expr_ty p;
1800 if (!n) {
1801 PyErr_SetString(PyExc_ValueError,
1802 "field n is required for Num");
1803 return NULL;
1805 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1806 if (!p)
1807 return NULL;
1808 p->kind = Num_kind;
1809 p->v.Num.n = n;
1810 p->lineno = lineno;
1811 p->col_offset = col_offset;
1812 return p;
1815 expr_ty
1816 Str(string s, int lineno, int col_offset, PyArena *arena)
1818 expr_ty p;
1819 if (!s) {
1820 PyErr_SetString(PyExc_ValueError,
1821 "field s is required for Str");
1822 return NULL;
1824 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1825 if (!p)
1826 return NULL;
1827 p->kind = Str_kind;
1828 p->v.Str.s = s;
1829 p->lineno = lineno;
1830 p->col_offset = col_offset;
1831 return p;
1834 expr_ty
1835 Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int
1836 col_offset, PyArena *arena)
1838 expr_ty p;
1839 if (!value) {
1840 PyErr_SetString(PyExc_ValueError,
1841 "field value is required for Attribute");
1842 return NULL;
1844 if (!attr) {
1845 PyErr_SetString(PyExc_ValueError,
1846 "field attr is required for Attribute");
1847 return NULL;
1849 if (!ctx) {
1850 PyErr_SetString(PyExc_ValueError,
1851 "field ctx is required for Attribute");
1852 return NULL;
1854 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1855 if (!p)
1856 return NULL;
1857 p->kind = Attribute_kind;
1858 p->v.Attribute.value = value;
1859 p->v.Attribute.attr = attr;
1860 p->v.Attribute.ctx = ctx;
1861 p->lineno = lineno;
1862 p->col_offset = col_offset;
1863 return p;
1866 expr_ty
1867 Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int
1868 col_offset, PyArena *arena)
1870 expr_ty p;
1871 if (!value) {
1872 PyErr_SetString(PyExc_ValueError,
1873 "field value is required for Subscript");
1874 return NULL;
1876 if (!slice) {
1877 PyErr_SetString(PyExc_ValueError,
1878 "field slice is required for Subscript");
1879 return NULL;
1881 if (!ctx) {
1882 PyErr_SetString(PyExc_ValueError,
1883 "field ctx is required for Subscript");
1884 return NULL;
1886 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1887 if (!p)
1888 return NULL;
1889 p->kind = Subscript_kind;
1890 p->v.Subscript.value = value;
1891 p->v.Subscript.slice = slice;
1892 p->v.Subscript.ctx = ctx;
1893 p->lineno = lineno;
1894 p->col_offset = col_offset;
1895 return p;
1898 expr_ty
1899 Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena
1900 *arena)
1902 expr_ty p;
1903 if (!id) {
1904 PyErr_SetString(PyExc_ValueError,
1905 "field id is required for Name");
1906 return NULL;
1908 if (!ctx) {
1909 PyErr_SetString(PyExc_ValueError,
1910 "field ctx is required for Name");
1911 return NULL;
1913 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1914 if (!p)
1915 return NULL;
1916 p->kind = Name_kind;
1917 p->v.Name.id = id;
1918 p->v.Name.ctx = ctx;
1919 p->lineno = lineno;
1920 p->col_offset = col_offset;
1921 return p;
1924 expr_ty
1925 List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1926 *arena)
1928 expr_ty p;
1929 if (!ctx) {
1930 PyErr_SetString(PyExc_ValueError,
1931 "field ctx is required for List");
1932 return NULL;
1934 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1935 if (!p)
1936 return NULL;
1937 p->kind = List_kind;
1938 p->v.List.elts = elts;
1939 p->v.List.ctx = ctx;
1940 p->lineno = lineno;
1941 p->col_offset = col_offset;
1942 return p;
1945 expr_ty
1946 Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1947 *arena)
1949 expr_ty p;
1950 if (!ctx) {
1951 PyErr_SetString(PyExc_ValueError,
1952 "field ctx is required for Tuple");
1953 return NULL;
1955 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1956 if (!p)
1957 return NULL;
1958 p->kind = Tuple_kind;
1959 p->v.Tuple.elts = elts;
1960 p->v.Tuple.ctx = ctx;
1961 p->lineno = lineno;
1962 p->col_offset = col_offset;
1963 return p;
1966 slice_ty
1967 Ellipsis(PyArena *arena)
1969 slice_ty p;
1970 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
1971 if (!p)
1972 return NULL;
1973 p->kind = Ellipsis_kind;
1974 return p;
1977 slice_ty
1978 Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena)
1980 slice_ty p;
1981 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
1982 if (!p)
1983 return NULL;
1984 p->kind = Slice_kind;
1985 p->v.Slice.lower = lower;
1986 p->v.Slice.upper = upper;
1987 p->v.Slice.step = step;
1988 return p;
1991 slice_ty
1992 ExtSlice(asdl_seq * dims, PyArena *arena)
1994 slice_ty p;
1995 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
1996 if (!p)
1997 return NULL;
1998 p->kind = ExtSlice_kind;
1999 p->v.ExtSlice.dims = dims;
2000 return p;
2003 slice_ty
2004 Index(expr_ty value, PyArena *arena)
2006 slice_ty p;
2007 if (!value) {
2008 PyErr_SetString(PyExc_ValueError,
2009 "field value is required for Index");
2010 return NULL;
2012 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
2013 if (!p)
2014 return NULL;
2015 p->kind = Index_kind;
2016 p->v.Index.value = value;
2017 return p;
2020 comprehension_ty
2021 comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena)
2023 comprehension_ty p;
2024 if (!target) {
2025 PyErr_SetString(PyExc_ValueError,
2026 "field target is required for comprehension");
2027 return NULL;
2029 if (!iter) {
2030 PyErr_SetString(PyExc_ValueError,
2031 "field iter is required for comprehension");
2032 return NULL;
2034 p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));
2035 if (!p)
2036 return NULL;
2037 p->target = target;
2038 p->iter = iter;
2039 p->ifs = ifs;
2040 return p;
2043 excepthandler_ty
2044 ExceptHandler(expr_ty type, expr_ty name, asdl_seq * body, int lineno, int
2045 col_offset, PyArena *arena)
2047 excepthandler_ty p;
2048 p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
2049 if (!p)
2050 return NULL;
2051 p->kind = ExceptHandler_kind;
2052 p->v.ExceptHandler.type = type;
2053 p->v.ExceptHandler.name = name;
2054 p->v.ExceptHandler.body = body;
2055 p->lineno = lineno;
2056 p->col_offset = col_offset;
2057 return p;
2060 arguments_ty
2061 arguments(asdl_seq * args, identifier vararg, identifier kwarg, asdl_seq *
2062 defaults, PyArena *arena)
2064 arguments_ty p;
2065 p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
2066 if (!p)
2067 return NULL;
2068 p->args = args;
2069 p->vararg = vararg;
2070 p->kwarg = kwarg;
2071 p->defaults = defaults;
2072 return p;
2075 keyword_ty
2076 keyword(identifier arg, expr_ty value, PyArena *arena)
2078 keyword_ty p;
2079 if (!arg) {
2080 PyErr_SetString(PyExc_ValueError,
2081 "field arg is required for keyword");
2082 return NULL;
2084 if (!value) {
2085 PyErr_SetString(PyExc_ValueError,
2086 "field value is required for keyword");
2087 return NULL;
2089 p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));
2090 if (!p)
2091 return NULL;
2092 p->arg = arg;
2093 p->value = value;
2094 return p;
2097 alias_ty
2098 alias(identifier name, identifier asname, PyArena *arena)
2100 alias_ty p;
2101 if (!name) {
2102 PyErr_SetString(PyExc_ValueError,
2103 "field name is required for alias");
2104 return NULL;
2106 p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));
2107 if (!p)
2108 return NULL;
2109 p->name = name;
2110 p->asname = asname;
2111 return p;
2115 PyObject*
2116 ast2obj_mod(void* _o)
2118 mod_ty o = (mod_ty)_o;
2119 PyObject *result = NULL, *value = NULL;
2120 if (!o) {
2121 Py_INCREF(Py_None);
2122 return Py_None;
2125 switch (o->kind) {
2126 case Module_kind:
2127 result = PyType_GenericNew(Module_type, NULL, NULL);
2128 if (!result) goto failed;
2129 value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
2130 if (!value) goto failed;
2131 if (PyObject_SetAttrString(result, "body", value) == -1)
2132 goto failed;
2133 Py_DECREF(value);
2134 break;
2135 case Interactive_kind:
2136 result = PyType_GenericNew(Interactive_type, NULL, NULL);
2137 if (!result) goto failed;
2138 value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
2139 if (!value) goto failed;
2140 if (PyObject_SetAttrString(result, "body", value) == -1)
2141 goto failed;
2142 Py_DECREF(value);
2143 break;
2144 case Expression_kind:
2145 result = PyType_GenericNew(Expression_type, NULL, NULL);
2146 if (!result) goto failed;
2147 value = ast2obj_expr(o->v.Expression.body);
2148 if (!value) goto failed;
2149 if (PyObject_SetAttrString(result, "body", value) == -1)
2150 goto failed;
2151 Py_DECREF(value);
2152 break;
2153 case Suite_kind:
2154 result = PyType_GenericNew(Suite_type, NULL, NULL);
2155 if (!result) goto failed;
2156 value = ast2obj_list(o->v.Suite.body, ast2obj_stmt);
2157 if (!value) goto failed;
2158 if (PyObject_SetAttrString(result, "body", value) == -1)
2159 goto failed;
2160 Py_DECREF(value);
2161 break;
2163 return result;
2164 failed:
2165 Py_XDECREF(value);
2166 Py_XDECREF(result);
2167 return NULL;
2170 PyObject*
2171 ast2obj_stmt(void* _o)
2173 stmt_ty o = (stmt_ty)_o;
2174 PyObject *result = NULL, *value = NULL;
2175 if (!o) {
2176 Py_INCREF(Py_None);
2177 return Py_None;
2180 switch (o->kind) {
2181 case FunctionDef_kind:
2182 result = PyType_GenericNew(FunctionDef_type, NULL, NULL);
2183 if (!result) goto failed;
2184 value = ast2obj_identifier(o->v.FunctionDef.name);
2185 if (!value) goto failed;
2186 if (PyObject_SetAttrString(result, "name", value) == -1)
2187 goto failed;
2188 Py_DECREF(value);
2189 value = ast2obj_arguments(o->v.FunctionDef.args);
2190 if (!value) goto failed;
2191 if (PyObject_SetAttrString(result, "args", value) == -1)
2192 goto failed;
2193 Py_DECREF(value);
2194 value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
2195 if (!value) goto failed;
2196 if (PyObject_SetAttrString(result, "body", value) == -1)
2197 goto failed;
2198 Py_DECREF(value);
2199 value = ast2obj_list(o->v.FunctionDef.decorator_list,
2200 ast2obj_expr);
2201 if (!value) goto failed;
2202 if (PyObject_SetAttrString(result, "decorator_list", value) ==
2204 goto failed;
2205 Py_DECREF(value);
2206 break;
2207 case ClassDef_kind:
2208 result = PyType_GenericNew(ClassDef_type, NULL, NULL);
2209 if (!result) goto failed;
2210 value = ast2obj_identifier(o->v.ClassDef.name);
2211 if (!value) goto failed;
2212 if (PyObject_SetAttrString(result, "name", value) == -1)
2213 goto failed;
2214 Py_DECREF(value);
2215 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
2216 if (!value) goto failed;
2217 if (PyObject_SetAttrString(result, "bases", value) == -1)
2218 goto failed;
2219 Py_DECREF(value);
2220 value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
2221 if (!value) goto failed;
2222 if (PyObject_SetAttrString(result, "body", value) == -1)
2223 goto failed;
2224 Py_DECREF(value);
2225 value = ast2obj_list(o->v.ClassDef.decorator_list,
2226 ast2obj_expr);
2227 if (!value) goto failed;
2228 if (PyObject_SetAttrString(result, "decorator_list", value) ==
2230 goto failed;
2231 Py_DECREF(value);
2232 break;
2233 case Return_kind:
2234 result = PyType_GenericNew(Return_type, NULL, NULL);
2235 if (!result) goto failed;
2236 value = ast2obj_expr(o->v.Return.value);
2237 if (!value) goto failed;
2238 if (PyObject_SetAttrString(result, "value", value) == -1)
2239 goto failed;
2240 Py_DECREF(value);
2241 break;
2242 case Delete_kind:
2243 result = PyType_GenericNew(Delete_type, NULL, NULL);
2244 if (!result) goto failed;
2245 value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
2246 if (!value) goto failed;
2247 if (PyObject_SetAttrString(result, "targets", value) == -1)
2248 goto failed;
2249 Py_DECREF(value);
2250 break;
2251 case Assign_kind:
2252 result = PyType_GenericNew(Assign_type, NULL, NULL);
2253 if (!result) goto failed;
2254 value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
2255 if (!value) goto failed;
2256 if (PyObject_SetAttrString(result, "targets", value) == -1)
2257 goto failed;
2258 Py_DECREF(value);
2259 value = ast2obj_expr(o->v.Assign.value);
2260 if (!value) goto failed;
2261 if (PyObject_SetAttrString(result, "value", value) == -1)
2262 goto failed;
2263 Py_DECREF(value);
2264 break;
2265 case AugAssign_kind:
2266 result = PyType_GenericNew(AugAssign_type, NULL, NULL);
2267 if (!result) goto failed;
2268 value = ast2obj_expr(o->v.AugAssign.target);
2269 if (!value) goto failed;
2270 if (PyObject_SetAttrString(result, "target", value) == -1)
2271 goto failed;
2272 Py_DECREF(value);
2273 value = ast2obj_operator(o->v.AugAssign.op);
2274 if (!value) goto failed;
2275 if (PyObject_SetAttrString(result, "op", value) == -1)
2276 goto failed;
2277 Py_DECREF(value);
2278 value = ast2obj_expr(o->v.AugAssign.value);
2279 if (!value) goto failed;
2280 if (PyObject_SetAttrString(result, "value", value) == -1)
2281 goto failed;
2282 Py_DECREF(value);
2283 break;
2284 case Print_kind:
2285 result = PyType_GenericNew(Print_type, NULL, NULL);
2286 if (!result) goto failed;
2287 value = ast2obj_expr(o->v.Print.dest);
2288 if (!value) goto failed;
2289 if (PyObject_SetAttrString(result, "dest", value) == -1)
2290 goto failed;
2291 Py_DECREF(value);
2292 value = ast2obj_list(o->v.Print.values, ast2obj_expr);
2293 if (!value) goto failed;
2294 if (PyObject_SetAttrString(result, "values", value) == -1)
2295 goto failed;
2296 Py_DECREF(value);
2297 value = ast2obj_bool(o->v.Print.nl);
2298 if (!value) goto failed;
2299 if (PyObject_SetAttrString(result, "nl", value) == -1)
2300 goto failed;
2301 Py_DECREF(value);
2302 break;
2303 case For_kind:
2304 result = PyType_GenericNew(For_type, NULL, NULL);
2305 if (!result) goto failed;
2306 value = ast2obj_expr(o->v.For.target);
2307 if (!value) goto failed;
2308 if (PyObject_SetAttrString(result, "target", value) == -1)
2309 goto failed;
2310 Py_DECREF(value);
2311 value = ast2obj_expr(o->v.For.iter);
2312 if (!value) goto failed;
2313 if (PyObject_SetAttrString(result, "iter", value) == -1)
2314 goto failed;
2315 Py_DECREF(value);
2316 value = ast2obj_list(o->v.For.body, ast2obj_stmt);
2317 if (!value) goto failed;
2318 if (PyObject_SetAttrString(result, "body", value) == -1)
2319 goto failed;
2320 Py_DECREF(value);
2321 value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
2322 if (!value) goto failed;
2323 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2324 goto failed;
2325 Py_DECREF(value);
2326 break;
2327 case While_kind:
2328 result = PyType_GenericNew(While_type, NULL, NULL);
2329 if (!result) goto failed;
2330 value = ast2obj_expr(o->v.While.test);
2331 if (!value) goto failed;
2332 if (PyObject_SetAttrString(result, "test", value) == -1)
2333 goto failed;
2334 Py_DECREF(value);
2335 value = ast2obj_list(o->v.While.body, ast2obj_stmt);
2336 if (!value) goto failed;
2337 if (PyObject_SetAttrString(result, "body", value) == -1)
2338 goto failed;
2339 Py_DECREF(value);
2340 value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);
2341 if (!value) goto failed;
2342 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2343 goto failed;
2344 Py_DECREF(value);
2345 break;
2346 case If_kind:
2347 result = PyType_GenericNew(If_type, NULL, NULL);
2348 if (!result) goto failed;
2349 value = ast2obj_expr(o->v.If.test);
2350 if (!value) goto failed;
2351 if (PyObject_SetAttrString(result, "test", value) == -1)
2352 goto failed;
2353 Py_DECREF(value);
2354 value = ast2obj_list(o->v.If.body, ast2obj_stmt);
2355 if (!value) goto failed;
2356 if (PyObject_SetAttrString(result, "body", value) == -1)
2357 goto failed;
2358 Py_DECREF(value);
2359 value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
2360 if (!value) goto failed;
2361 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2362 goto failed;
2363 Py_DECREF(value);
2364 break;
2365 case With_kind:
2366 result = PyType_GenericNew(With_type, NULL, NULL);
2367 if (!result) goto failed;
2368 value = ast2obj_expr(o->v.With.context_expr);
2369 if (!value) goto failed;
2370 if (PyObject_SetAttrString(result, "context_expr", value) == -1)
2371 goto failed;
2372 Py_DECREF(value);
2373 value = ast2obj_expr(o->v.With.optional_vars);
2374 if (!value) goto failed;
2375 if (PyObject_SetAttrString(result, "optional_vars", value) ==
2377 goto failed;
2378 Py_DECREF(value);
2379 value = ast2obj_list(o->v.With.body, ast2obj_stmt);
2380 if (!value) goto failed;
2381 if (PyObject_SetAttrString(result, "body", value) == -1)
2382 goto failed;
2383 Py_DECREF(value);
2384 break;
2385 case Raise_kind:
2386 result = PyType_GenericNew(Raise_type, NULL, NULL);
2387 if (!result) goto failed;
2388 value = ast2obj_expr(o->v.Raise.type);
2389 if (!value) goto failed;
2390 if (PyObject_SetAttrString(result, "type", value) == -1)
2391 goto failed;
2392 Py_DECREF(value);
2393 value = ast2obj_expr(o->v.Raise.inst);
2394 if (!value) goto failed;
2395 if (PyObject_SetAttrString(result, "inst", value) == -1)
2396 goto failed;
2397 Py_DECREF(value);
2398 value = ast2obj_expr(o->v.Raise.tback);
2399 if (!value) goto failed;
2400 if (PyObject_SetAttrString(result, "tback", value) == -1)
2401 goto failed;
2402 Py_DECREF(value);
2403 break;
2404 case TryExcept_kind:
2405 result = PyType_GenericNew(TryExcept_type, NULL, NULL);
2406 if (!result) goto failed;
2407 value = ast2obj_list(o->v.TryExcept.body, ast2obj_stmt);
2408 if (!value) goto failed;
2409 if (PyObject_SetAttrString(result, "body", value) == -1)
2410 goto failed;
2411 Py_DECREF(value);
2412 value = ast2obj_list(o->v.TryExcept.handlers,
2413 ast2obj_excepthandler);
2414 if (!value) goto failed;
2415 if (PyObject_SetAttrString(result, "handlers", value) == -1)
2416 goto failed;
2417 Py_DECREF(value);
2418 value = ast2obj_list(o->v.TryExcept.orelse, ast2obj_stmt);
2419 if (!value) goto failed;
2420 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2421 goto failed;
2422 Py_DECREF(value);
2423 break;
2424 case TryFinally_kind:
2425 result = PyType_GenericNew(TryFinally_type, NULL, NULL);
2426 if (!result) goto failed;
2427 value = ast2obj_list(o->v.TryFinally.body, ast2obj_stmt);
2428 if (!value) goto failed;
2429 if (PyObject_SetAttrString(result, "body", value) == -1)
2430 goto failed;
2431 Py_DECREF(value);
2432 value = ast2obj_list(o->v.TryFinally.finalbody, ast2obj_stmt);
2433 if (!value) goto failed;
2434 if (PyObject_SetAttrString(result, "finalbody", value) == -1)
2435 goto failed;
2436 Py_DECREF(value);
2437 break;
2438 case Assert_kind:
2439 result = PyType_GenericNew(Assert_type, NULL, NULL);
2440 if (!result) goto failed;
2441 value = ast2obj_expr(o->v.Assert.test);
2442 if (!value) goto failed;
2443 if (PyObject_SetAttrString(result, "test", value) == -1)
2444 goto failed;
2445 Py_DECREF(value);
2446 value = ast2obj_expr(o->v.Assert.msg);
2447 if (!value) goto failed;
2448 if (PyObject_SetAttrString(result, "msg", value) == -1)
2449 goto failed;
2450 Py_DECREF(value);
2451 break;
2452 case Import_kind:
2453 result = PyType_GenericNew(Import_type, NULL, NULL);
2454 if (!result) goto failed;
2455 value = ast2obj_list(o->v.Import.names, ast2obj_alias);
2456 if (!value) goto failed;
2457 if (PyObject_SetAttrString(result, "names", value) == -1)
2458 goto failed;
2459 Py_DECREF(value);
2460 break;
2461 case ImportFrom_kind:
2462 result = PyType_GenericNew(ImportFrom_type, NULL, NULL);
2463 if (!result) goto failed;
2464 value = ast2obj_identifier(o->v.ImportFrom.module);
2465 if (!value) goto failed;
2466 if (PyObject_SetAttrString(result, "module", value) == -1)
2467 goto failed;
2468 Py_DECREF(value);
2469 value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
2470 if (!value) goto failed;
2471 if (PyObject_SetAttrString(result, "names", value) == -1)
2472 goto failed;
2473 Py_DECREF(value);
2474 value = ast2obj_int(o->v.ImportFrom.level);
2475 if (!value) goto failed;
2476 if (PyObject_SetAttrString(result, "level", value) == -1)
2477 goto failed;
2478 Py_DECREF(value);
2479 break;
2480 case Exec_kind:
2481 result = PyType_GenericNew(Exec_type, NULL, NULL);
2482 if (!result) goto failed;
2483 value = ast2obj_expr(o->v.Exec.body);
2484 if (!value) goto failed;
2485 if (PyObject_SetAttrString(result, "body", value) == -1)
2486 goto failed;
2487 Py_DECREF(value);
2488 value = ast2obj_expr(o->v.Exec.globals);
2489 if (!value) goto failed;
2490 if (PyObject_SetAttrString(result, "globals", value) == -1)
2491 goto failed;
2492 Py_DECREF(value);
2493 value = ast2obj_expr(o->v.Exec.locals);
2494 if (!value) goto failed;
2495 if (PyObject_SetAttrString(result, "locals", value) == -1)
2496 goto failed;
2497 Py_DECREF(value);
2498 break;
2499 case Global_kind:
2500 result = PyType_GenericNew(Global_type, NULL, NULL);
2501 if (!result) goto failed;
2502 value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
2503 if (!value) goto failed;
2504 if (PyObject_SetAttrString(result, "names", value) == -1)
2505 goto failed;
2506 Py_DECREF(value);
2507 break;
2508 case Expr_kind:
2509 result = PyType_GenericNew(Expr_type, NULL, NULL);
2510 if (!result) goto failed;
2511 value = ast2obj_expr(o->v.Expr.value);
2512 if (!value) goto failed;
2513 if (PyObject_SetAttrString(result, "value", value) == -1)
2514 goto failed;
2515 Py_DECREF(value);
2516 break;
2517 case Pass_kind:
2518 result = PyType_GenericNew(Pass_type, NULL, NULL);
2519 if (!result) goto failed;
2520 break;
2521 case Break_kind:
2522 result = PyType_GenericNew(Break_type, NULL, NULL);
2523 if (!result) goto failed;
2524 break;
2525 case Continue_kind:
2526 result = PyType_GenericNew(Continue_type, NULL, NULL);
2527 if (!result) goto failed;
2528 break;
2530 value = ast2obj_int(o->lineno);
2531 if (!value) goto failed;
2532 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2533 goto failed;
2534 Py_DECREF(value);
2535 value = ast2obj_int(o->col_offset);
2536 if (!value) goto failed;
2537 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2538 goto failed;
2539 Py_DECREF(value);
2540 return result;
2541 failed:
2542 Py_XDECREF(value);
2543 Py_XDECREF(result);
2544 return NULL;
2547 PyObject*
2548 ast2obj_expr(void* _o)
2550 expr_ty o = (expr_ty)_o;
2551 PyObject *result = NULL, *value = NULL;
2552 if (!o) {
2553 Py_INCREF(Py_None);
2554 return Py_None;
2557 switch (o->kind) {
2558 case BoolOp_kind:
2559 result = PyType_GenericNew(BoolOp_type, NULL, NULL);
2560 if (!result) goto failed;
2561 value = ast2obj_boolop(o->v.BoolOp.op);
2562 if (!value) goto failed;
2563 if (PyObject_SetAttrString(result, "op", value) == -1)
2564 goto failed;
2565 Py_DECREF(value);
2566 value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
2567 if (!value) goto failed;
2568 if (PyObject_SetAttrString(result, "values", value) == -1)
2569 goto failed;
2570 Py_DECREF(value);
2571 break;
2572 case BinOp_kind:
2573 result = PyType_GenericNew(BinOp_type, NULL, NULL);
2574 if (!result) goto failed;
2575 value = ast2obj_expr(o->v.BinOp.left);
2576 if (!value) goto failed;
2577 if (PyObject_SetAttrString(result, "left", value) == -1)
2578 goto failed;
2579 Py_DECREF(value);
2580 value = ast2obj_operator(o->v.BinOp.op);
2581 if (!value) goto failed;
2582 if (PyObject_SetAttrString(result, "op", value) == -1)
2583 goto failed;
2584 Py_DECREF(value);
2585 value = ast2obj_expr(o->v.BinOp.right);
2586 if (!value) goto failed;
2587 if (PyObject_SetAttrString(result, "right", value) == -1)
2588 goto failed;
2589 Py_DECREF(value);
2590 break;
2591 case UnaryOp_kind:
2592 result = PyType_GenericNew(UnaryOp_type, NULL, NULL);
2593 if (!result) goto failed;
2594 value = ast2obj_unaryop(o->v.UnaryOp.op);
2595 if (!value) goto failed;
2596 if (PyObject_SetAttrString(result, "op", value) == -1)
2597 goto failed;
2598 Py_DECREF(value);
2599 value = ast2obj_expr(o->v.UnaryOp.operand);
2600 if (!value) goto failed;
2601 if (PyObject_SetAttrString(result, "operand", value) == -1)
2602 goto failed;
2603 Py_DECREF(value);
2604 break;
2605 case Lambda_kind:
2606 result = PyType_GenericNew(Lambda_type, NULL, NULL);
2607 if (!result) goto failed;
2608 value = ast2obj_arguments(o->v.Lambda.args);
2609 if (!value) goto failed;
2610 if (PyObject_SetAttrString(result, "args", value) == -1)
2611 goto failed;
2612 Py_DECREF(value);
2613 value = ast2obj_expr(o->v.Lambda.body);
2614 if (!value) goto failed;
2615 if (PyObject_SetAttrString(result, "body", value) == -1)
2616 goto failed;
2617 Py_DECREF(value);
2618 break;
2619 case IfExp_kind:
2620 result = PyType_GenericNew(IfExp_type, NULL, NULL);
2621 if (!result) goto failed;
2622 value = ast2obj_expr(o->v.IfExp.test);
2623 if (!value) goto failed;
2624 if (PyObject_SetAttrString(result, "test", value) == -1)
2625 goto failed;
2626 Py_DECREF(value);
2627 value = ast2obj_expr(o->v.IfExp.body);
2628 if (!value) goto failed;
2629 if (PyObject_SetAttrString(result, "body", value) == -1)
2630 goto failed;
2631 Py_DECREF(value);
2632 value = ast2obj_expr(o->v.IfExp.orelse);
2633 if (!value) goto failed;
2634 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2635 goto failed;
2636 Py_DECREF(value);
2637 break;
2638 case Dict_kind:
2639 result = PyType_GenericNew(Dict_type, NULL, NULL);
2640 if (!result) goto failed;
2641 value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
2642 if (!value) goto failed;
2643 if (PyObject_SetAttrString(result, "keys", value) == -1)
2644 goto failed;
2645 Py_DECREF(value);
2646 value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
2647 if (!value) goto failed;
2648 if (PyObject_SetAttrString(result, "values", value) == -1)
2649 goto failed;
2650 Py_DECREF(value);
2651 break;
2652 case Set_kind:
2653 result = PyType_GenericNew(Set_type, NULL, NULL);
2654 if (!result) goto failed;
2655 value = ast2obj_list(o->v.Set.elts, ast2obj_expr);
2656 if (!value) goto failed;
2657 if (PyObject_SetAttrString(result, "elts", value) == -1)
2658 goto failed;
2659 Py_DECREF(value);
2660 break;
2661 case ListComp_kind:
2662 result = PyType_GenericNew(ListComp_type, NULL, NULL);
2663 if (!result) goto failed;
2664 value = ast2obj_expr(o->v.ListComp.elt);
2665 if (!value) goto failed;
2666 if (PyObject_SetAttrString(result, "elt", value) == -1)
2667 goto failed;
2668 Py_DECREF(value);
2669 value = ast2obj_list(o->v.ListComp.generators,
2670 ast2obj_comprehension);
2671 if (!value) goto failed;
2672 if (PyObject_SetAttrString(result, "generators", value) == -1)
2673 goto failed;
2674 Py_DECREF(value);
2675 break;
2676 case SetComp_kind:
2677 result = PyType_GenericNew(SetComp_type, NULL, NULL);
2678 if (!result) goto failed;
2679 value = ast2obj_expr(o->v.SetComp.elt);
2680 if (!value) goto failed;
2681 if (PyObject_SetAttrString(result, "elt", value) == -1)
2682 goto failed;
2683 Py_DECREF(value);
2684 value = ast2obj_list(o->v.SetComp.generators,
2685 ast2obj_comprehension);
2686 if (!value) goto failed;
2687 if (PyObject_SetAttrString(result, "generators", value) == -1)
2688 goto failed;
2689 Py_DECREF(value);
2690 break;
2691 case DictComp_kind:
2692 result = PyType_GenericNew(DictComp_type, NULL, NULL);
2693 if (!result) goto failed;
2694 value = ast2obj_expr(o->v.DictComp.key);
2695 if (!value) goto failed;
2696 if (PyObject_SetAttrString(result, "key", value) == -1)
2697 goto failed;
2698 Py_DECREF(value);
2699 value = ast2obj_expr(o->v.DictComp.value);
2700 if (!value) goto failed;
2701 if (PyObject_SetAttrString(result, "value", value) == -1)
2702 goto failed;
2703 Py_DECREF(value);
2704 value = ast2obj_list(o->v.DictComp.generators,
2705 ast2obj_comprehension);
2706 if (!value) goto failed;
2707 if (PyObject_SetAttrString(result, "generators", value) == -1)
2708 goto failed;
2709 Py_DECREF(value);
2710 break;
2711 case GeneratorExp_kind:
2712 result = PyType_GenericNew(GeneratorExp_type, NULL, NULL);
2713 if (!result) goto failed;
2714 value = ast2obj_expr(o->v.GeneratorExp.elt);
2715 if (!value) goto failed;
2716 if (PyObject_SetAttrString(result, "elt", value) == -1)
2717 goto failed;
2718 Py_DECREF(value);
2719 value = ast2obj_list(o->v.GeneratorExp.generators,
2720 ast2obj_comprehension);
2721 if (!value) goto failed;
2722 if (PyObject_SetAttrString(result, "generators", value) == -1)
2723 goto failed;
2724 Py_DECREF(value);
2725 break;
2726 case Yield_kind:
2727 result = PyType_GenericNew(Yield_type, NULL, NULL);
2728 if (!result) goto failed;
2729 value = ast2obj_expr(o->v.Yield.value);
2730 if (!value) goto failed;
2731 if (PyObject_SetAttrString(result, "value", value) == -1)
2732 goto failed;
2733 Py_DECREF(value);
2734 break;
2735 case Compare_kind:
2736 result = PyType_GenericNew(Compare_type, NULL, NULL);
2737 if (!result) goto failed;
2738 value = ast2obj_expr(o->v.Compare.left);
2739 if (!value) goto failed;
2740 if (PyObject_SetAttrString(result, "left", value) == -1)
2741 goto failed;
2742 Py_DECREF(value);
2744 int i, n = asdl_seq_LEN(o->v.Compare.ops);
2745 value = PyList_New(n);
2746 if (!value) goto failed;
2747 for(i = 0; i < n; i++)
2748 PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
2750 if (!value) goto failed;
2751 if (PyObject_SetAttrString(result, "ops", value) == -1)
2752 goto failed;
2753 Py_DECREF(value);
2754 value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
2755 if (!value) goto failed;
2756 if (PyObject_SetAttrString(result, "comparators", value) == -1)
2757 goto failed;
2758 Py_DECREF(value);
2759 break;
2760 case Call_kind:
2761 result = PyType_GenericNew(Call_type, NULL, NULL);
2762 if (!result) goto failed;
2763 value = ast2obj_expr(o->v.Call.func);
2764 if (!value) goto failed;
2765 if (PyObject_SetAttrString(result, "func", value) == -1)
2766 goto failed;
2767 Py_DECREF(value);
2768 value = ast2obj_list(o->v.Call.args, ast2obj_expr);
2769 if (!value) goto failed;
2770 if (PyObject_SetAttrString(result, "args", value) == -1)
2771 goto failed;
2772 Py_DECREF(value);
2773 value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
2774 if (!value) goto failed;
2775 if (PyObject_SetAttrString(result, "keywords", value) == -1)
2776 goto failed;
2777 Py_DECREF(value);
2778 value = ast2obj_expr(o->v.Call.starargs);
2779 if (!value) goto failed;
2780 if (PyObject_SetAttrString(result, "starargs", value) == -1)
2781 goto failed;
2782 Py_DECREF(value);
2783 value = ast2obj_expr(o->v.Call.kwargs);
2784 if (!value) goto failed;
2785 if (PyObject_SetAttrString(result, "kwargs", value) == -1)
2786 goto failed;
2787 Py_DECREF(value);
2788 break;
2789 case Repr_kind:
2790 result = PyType_GenericNew(Repr_type, NULL, NULL);
2791 if (!result) goto failed;
2792 value = ast2obj_expr(o->v.Repr.value);
2793 if (!value) goto failed;
2794 if (PyObject_SetAttrString(result, "value", value) == -1)
2795 goto failed;
2796 Py_DECREF(value);
2797 break;
2798 case Num_kind:
2799 result = PyType_GenericNew(Num_type, NULL, NULL);
2800 if (!result) goto failed;
2801 value = ast2obj_object(o->v.Num.n);
2802 if (!value) goto failed;
2803 if (PyObject_SetAttrString(result, "n", value) == -1)
2804 goto failed;
2805 Py_DECREF(value);
2806 break;
2807 case Str_kind:
2808 result = PyType_GenericNew(Str_type, NULL, NULL);
2809 if (!result) goto failed;
2810 value = ast2obj_string(o->v.Str.s);
2811 if (!value) goto failed;
2812 if (PyObject_SetAttrString(result, "s", value) == -1)
2813 goto failed;
2814 Py_DECREF(value);
2815 break;
2816 case Attribute_kind:
2817 result = PyType_GenericNew(Attribute_type, NULL, NULL);
2818 if (!result) goto failed;
2819 value = ast2obj_expr(o->v.Attribute.value);
2820 if (!value) goto failed;
2821 if (PyObject_SetAttrString(result, "value", value) == -1)
2822 goto failed;
2823 Py_DECREF(value);
2824 value = ast2obj_identifier(o->v.Attribute.attr);
2825 if (!value) goto failed;
2826 if (PyObject_SetAttrString(result, "attr", value) == -1)
2827 goto failed;
2828 Py_DECREF(value);
2829 value = ast2obj_expr_context(o->v.Attribute.ctx);
2830 if (!value) goto failed;
2831 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2832 goto failed;
2833 Py_DECREF(value);
2834 break;
2835 case Subscript_kind:
2836 result = PyType_GenericNew(Subscript_type, NULL, NULL);
2837 if (!result) goto failed;
2838 value = ast2obj_expr(o->v.Subscript.value);
2839 if (!value) goto failed;
2840 if (PyObject_SetAttrString(result, "value", value) == -1)
2841 goto failed;
2842 Py_DECREF(value);
2843 value = ast2obj_slice(o->v.Subscript.slice);
2844 if (!value) goto failed;
2845 if (PyObject_SetAttrString(result, "slice", value) == -1)
2846 goto failed;
2847 Py_DECREF(value);
2848 value = ast2obj_expr_context(o->v.Subscript.ctx);
2849 if (!value) goto failed;
2850 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2851 goto failed;
2852 Py_DECREF(value);
2853 break;
2854 case Name_kind:
2855 result = PyType_GenericNew(Name_type, NULL, NULL);
2856 if (!result) goto failed;
2857 value = ast2obj_identifier(o->v.Name.id);
2858 if (!value) goto failed;
2859 if (PyObject_SetAttrString(result, "id", value) == -1)
2860 goto failed;
2861 Py_DECREF(value);
2862 value = ast2obj_expr_context(o->v.Name.ctx);
2863 if (!value) goto failed;
2864 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2865 goto failed;
2866 Py_DECREF(value);
2867 break;
2868 case List_kind:
2869 result = PyType_GenericNew(List_type, NULL, NULL);
2870 if (!result) goto failed;
2871 value = ast2obj_list(o->v.List.elts, ast2obj_expr);
2872 if (!value) goto failed;
2873 if (PyObject_SetAttrString(result, "elts", value) == -1)
2874 goto failed;
2875 Py_DECREF(value);
2876 value = ast2obj_expr_context(o->v.List.ctx);
2877 if (!value) goto failed;
2878 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2879 goto failed;
2880 Py_DECREF(value);
2881 break;
2882 case Tuple_kind:
2883 result = PyType_GenericNew(Tuple_type, NULL, NULL);
2884 if (!result) goto failed;
2885 value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
2886 if (!value) goto failed;
2887 if (PyObject_SetAttrString(result, "elts", value) == -1)
2888 goto failed;
2889 Py_DECREF(value);
2890 value = ast2obj_expr_context(o->v.Tuple.ctx);
2891 if (!value) goto failed;
2892 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2893 goto failed;
2894 Py_DECREF(value);
2895 break;
2897 value = ast2obj_int(o->lineno);
2898 if (!value) goto failed;
2899 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2900 goto failed;
2901 Py_DECREF(value);
2902 value = ast2obj_int(o->col_offset);
2903 if (!value) goto failed;
2904 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2905 goto failed;
2906 Py_DECREF(value);
2907 return result;
2908 failed:
2909 Py_XDECREF(value);
2910 Py_XDECREF(result);
2911 return NULL;
2914 PyObject* ast2obj_expr_context(expr_context_ty o)
2916 switch(o) {
2917 case Load:
2918 Py_INCREF(Load_singleton);
2919 return Load_singleton;
2920 case Store:
2921 Py_INCREF(Store_singleton);
2922 return Store_singleton;
2923 case Del:
2924 Py_INCREF(Del_singleton);
2925 return Del_singleton;
2926 case AugLoad:
2927 Py_INCREF(AugLoad_singleton);
2928 return AugLoad_singleton;
2929 case AugStore:
2930 Py_INCREF(AugStore_singleton);
2931 return AugStore_singleton;
2932 case Param:
2933 Py_INCREF(Param_singleton);
2934 return Param_singleton;
2935 default:
2936 /* should never happen, but just in case ... */
2937 PyErr_Format(PyExc_SystemError, "unknown expr_context found");
2938 return NULL;
2941 PyObject*
2942 ast2obj_slice(void* _o)
2944 slice_ty o = (slice_ty)_o;
2945 PyObject *result = NULL, *value = NULL;
2946 if (!o) {
2947 Py_INCREF(Py_None);
2948 return Py_None;
2951 switch (o->kind) {
2952 case Ellipsis_kind:
2953 result = PyType_GenericNew(Ellipsis_type, NULL, NULL);
2954 if (!result) goto failed;
2955 break;
2956 case Slice_kind:
2957 result = PyType_GenericNew(Slice_type, NULL, NULL);
2958 if (!result) goto failed;
2959 value = ast2obj_expr(o->v.Slice.lower);
2960 if (!value) goto failed;
2961 if (PyObject_SetAttrString(result, "lower", value) == -1)
2962 goto failed;
2963 Py_DECREF(value);
2964 value = ast2obj_expr(o->v.Slice.upper);
2965 if (!value) goto failed;
2966 if (PyObject_SetAttrString(result, "upper", value) == -1)
2967 goto failed;
2968 Py_DECREF(value);
2969 value = ast2obj_expr(o->v.Slice.step);
2970 if (!value) goto failed;
2971 if (PyObject_SetAttrString(result, "step", value) == -1)
2972 goto failed;
2973 Py_DECREF(value);
2974 break;
2975 case ExtSlice_kind:
2976 result = PyType_GenericNew(ExtSlice_type, NULL, NULL);
2977 if (!result) goto failed;
2978 value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice);
2979 if (!value) goto failed;
2980 if (PyObject_SetAttrString(result, "dims", value) == -1)
2981 goto failed;
2982 Py_DECREF(value);
2983 break;
2984 case Index_kind:
2985 result = PyType_GenericNew(Index_type, NULL, NULL);
2986 if (!result) goto failed;
2987 value = ast2obj_expr(o->v.Index.value);
2988 if (!value) goto failed;
2989 if (PyObject_SetAttrString(result, "value", value) == -1)
2990 goto failed;
2991 Py_DECREF(value);
2992 break;
2994 return result;
2995 failed:
2996 Py_XDECREF(value);
2997 Py_XDECREF(result);
2998 return NULL;
3001 PyObject* ast2obj_boolop(boolop_ty o)
3003 switch(o) {
3004 case And:
3005 Py_INCREF(And_singleton);
3006 return And_singleton;
3007 case Or:
3008 Py_INCREF(Or_singleton);
3009 return Or_singleton;
3010 default:
3011 /* should never happen, but just in case ... */
3012 PyErr_Format(PyExc_SystemError, "unknown boolop found");
3013 return NULL;
3016 PyObject* ast2obj_operator(operator_ty o)
3018 switch(o) {
3019 case Add:
3020 Py_INCREF(Add_singleton);
3021 return Add_singleton;
3022 case Sub:
3023 Py_INCREF(Sub_singleton);
3024 return Sub_singleton;
3025 case Mult:
3026 Py_INCREF(Mult_singleton);
3027 return Mult_singleton;
3028 case Div:
3029 Py_INCREF(Div_singleton);
3030 return Div_singleton;
3031 case Mod:
3032 Py_INCREF(Mod_singleton);
3033 return Mod_singleton;
3034 case Pow:
3035 Py_INCREF(Pow_singleton);
3036 return Pow_singleton;
3037 case LShift:
3038 Py_INCREF(LShift_singleton);
3039 return LShift_singleton;
3040 case RShift:
3041 Py_INCREF(RShift_singleton);
3042 return RShift_singleton;
3043 case BitOr:
3044 Py_INCREF(BitOr_singleton);
3045 return BitOr_singleton;
3046 case BitXor:
3047 Py_INCREF(BitXor_singleton);
3048 return BitXor_singleton;
3049 case BitAnd:
3050 Py_INCREF(BitAnd_singleton);
3051 return BitAnd_singleton;
3052 case FloorDiv:
3053 Py_INCREF(FloorDiv_singleton);
3054 return FloorDiv_singleton;
3055 default:
3056 /* should never happen, but just in case ... */
3057 PyErr_Format(PyExc_SystemError, "unknown operator found");
3058 return NULL;
3061 PyObject* ast2obj_unaryop(unaryop_ty o)
3063 switch(o) {
3064 case Invert:
3065 Py_INCREF(Invert_singleton);
3066 return Invert_singleton;
3067 case Not:
3068 Py_INCREF(Not_singleton);
3069 return Not_singleton;
3070 case UAdd:
3071 Py_INCREF(UAdd_singleton);
3072 return UAdd_singleton;
3073 case USub:
3074 Py_INCREF(USub_singleton);
3075 return USub_singleton;
3076 default:
3077 /* should never happen, but just in case ... */
3078 PyErr_Format(PyExc_SystemError, "unknown unaryop found");
3079 return NULL;
3082 PyObject* ast2obj_cmpop(cmpop_ty o)
3084 switch(o) {
3085 case Eq:
3086 Py_INCREF(Eq_singleton);
3087 return Eq_singleton;
3088 case NotEq:
3089 Py_INCREF(NotEq_singleton);
3090 return NotEq_singleton;
3091 case Lt:
3092 Py_INCREF(Lt_singleton);
3093 return Lt_singleton;
3094 case LtE:
3095 Py_INCREF(LtE_singleton);
3096 return LtE_singleton;
3097 case Gt:
3098 Py_INCREF(Gt_singleton);
3099 return Gt_singleton;
3100 case GtE:
3101 Py_INCREF(GtE_singleton);
3102 return GtE_singleton;
3103 case Is:
3104 Py_INCREF(Is_singleton);
3105 return Is_singleton;
3106 case IsNot:
3107 Py_INCREF(IsNot_singleton);
3108 return IsNot_singleton;
3109 case In:
3110 Py_INCREF(In_singleton);
3111 return In_singleton;
3112 case NotIn:
3113 Py_INCREF(NotIn_singleton);
3114 return NotIn_singleton;
3115 default:
3116 /* should never happen, but just in case ... */
3117 PyErr_Format(PyExc_SystemError, "unknown cmpop found");
3118 return NULL;
3121 PyObject*
3122 ast2obj_comprehension(void* _o)
3124 comprehension_ty o = (comprehension_ty)_o;
3125 PyObject *result = NULL, *value = NULL;
3126 if (!o) {
3127 Py_INCREF(Py_None);
3128 return Py_None;
3131 result = PyType_GenericNew(comprehension_type, NULL, NULL);
3132 if (!result) return NULL;
3133 value = ast2obj_expr(o->target);
3134 if (!value) goto failed;
3135 if (PyObject_SetAttrString(result, "target", value) == -1)
3136 goto failed;
3137 Py_DECREF(value);
3138 value = ast2obj_expr(o->iter);
3139 if (!value) goto failed;
3140 if (PyObject_SetAttrString(result, "iter", value) == -1)
3141 goto failed;
3142 Py_DECREF(value);
3143 value = ast2obj_list(o->ifs, ast2obj_expr);
3144 if (!value) goto failed;
3145 if (PyObject_SetAttrString(result, "ifs", value) == -1)
3146 goto failed;
3147 Py_DECREF(value);
3148 return result;
3149 failed:
3150 Py_XDECREF(value);
3151 Py_XDECREF(result);
3152 return NULL;
3155 PyObject*
3156 ast2obj_excepthandler(void* _o)
3158 excepthandler_ty o = (excepthandler_ty)_o;
3159 PyObject *result = NULL, *value = NULL;
3160 if (!o) {
3161 Py_INCREF(Py_None);
3162 return Py_None;
3165 switch (o->kind) {
3166 case ExceptHandler_kind:
3167 result = PyType_GenericNew(ExceptHandler_type, NULL, NULL);
3168 if (!result) goto failed;
3169 value = ast2obj_expr(o->v.ExceptHandler.type);
3170 if (!value) goto failed;
3171 if (PyObject_SetAttrString(result, "type", value) == -1)
3172 goto failed;
3173 Py_DECREF(value);
3174 value = ast2obj_expr(o->v.ExceptHandler.name);
3175 if (!value) goto failed;
3176 if (PyObject_SetAttrString(result, "name", value) == -1)
3177 goto failed;
3178 Py_DECREF(value);
3179 value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt);
3180 if (!value) goto failed;
3181 if (PyObject_SetAttrString(result, "body", value) == -1)
3182 goto failed;
3183 Py_DECREF(value);
3184 break;
3186 value = ast2obj_int(o->lineno);
3187 if (!value) goto failed;
3188 if (PyObject_SetAttrString(result, "lineno", value) < 0)
3189 goto failed;
3190 Py_DECREF(value);
3191 value = ast2obj_int(o->col_offset);
3192 if (!value) goto failed;
3193 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
3194 goto failed;
3195 Py_DECREF(value);
3196 return result;
3197 failed:
3198 Py_XDECREF(value);
3199 Py_XDECREF(result);
3200 return NULL;
3203 PyObject*
3204 ast2obj_arguments(void* _o)
3206 arguments_ty o = (arguments_ty)_o;
3207 PyObject *result = NULL, *value = NULL;
3208 if (!o) {
3209 Py_INCREF(Py_None);
3210 return Py_None;
3213 result = PyType_GenericNew(arguments_type, NULL, NULL);
3214 if (!result) return NULL;
3215 value = ast2obj_list(o->args, ast2obj_expr);
3216 if (!value) goto failed;
3217 if (PyObject_SetAttrString(result, "args", value) == -1)
3218 goto failed;
3219 Py_DECREF(value);
3220 value = ast2obj_identifier(o->vararg);
3221 if (!value) goto failed;
3222 if (PyObject_SetAttrString(result, "vararg", value) == -1)
3223 goto failed;
3224 Py_DECREF(value);
3225 value = ast2obj_identifier(o->kwarg);
3226 if (!value) goto failed;
3227 if (PyObject_SetAttrString(result, "kwarg", value) == -1)
3228 goto failed;
3229 Py_DECREF(value);
3230 value = ast2obj_list(o->defaults, ast2obj_expr);
3231 if (!value) goto failed;
3232 if (PyObject_SetAttrString(result, "defaults", value) == -1)
3233 goto failed;
3234 Py_DECREF(value);
3235 return result;
3236 failed:
3237 Py_XDECREF(value);
3238 Py_XDECREF(result);
3239 return NULL;
3242 PyObject*
3243 ast2obj_keyword(void* _o)
3245 keyword_ty o = (keyword_ty)_o;
3246 PyObject *result = NULL, *value = NULL;
3247 if (!o) {
3248 Py_INCREF(Py_None);
3249 return Py_None;
3252 result = PyType_GenericNew(keyword_type, NULL, NULL);
3253 if (!result) return NULL;
3254 value = ast2obj_identifier(o->arg);
3255 if (!value) goto failed;
3256 if (PyObject_SetAttrString(result, "arg", value) == -1)
3257 goto failed;
3258 Py_DECREF(value);
3259 value = ast2obj_expr(o->value);
3260 if (!value) goto failed;
3261 if (PyObject_SetAttrString(result, "value", value) == -1)
3262 goto failed;
3263 Py_DECREF(value);
3264 return result;
3265 failed:
3266 Py_XDECREF(value);
3267 Py_XDECREF(result);
3268 return NULL;
3271 PyObject*
3272 ast2obj_alias(void* _o)
3274 alias_ty o = (alias_ty)_o;
3275 PyObject *result = NULL, *value = NULL;
3276 if (!o) {
3277 Py_INCREF(Py_None);
3278 return Py_None;
3281 result = PyType_GenericNew(alias_type, NULL, NULL);
3282 if (!result) return NULL;
3283 value = ast2obj_identifier(o->name);
3284 if (!value) goto failed;
3285 if (PyObject_SetAttrString(result, "name", value) == -1)
3286 goto failed;
3287 Py_DECREF(value);
3288 value = ast2obj_identifier(o->asname);
3289 if (!value) goto failed;
3290 if (PyObject_SetAttrString(result, "asname", value) == -1)
3291 goto failed;
3292 Py_DECREF(value);
3293 return result;
3294 failed:
3295 Py_XDECREF(value);
3296 Py_XDECREF(result);
3297 return NULL;
3302 obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena)
3304 PyObject* tmp = NULL;
3305 int isinstance;
3308 if (obj == Py_None) {
3309 *out = NULL;
3310 return 0;
3312 isinstance = PyObject_IsInstance(obj, (PyObject*)Module_type);
3313 if (isinstance == -1) {
3314 return 1;
3316 if (isinstance) {
3317 asdl_seq* body;
3319 if (PyObject_HasAttrString(obj, "body")) {
3320 int res;
3321 Py_ssize_t len;
3322 Py_ssize_t i;
3323 tmp = PyObject_GetAttrString(obj, "body");
3324 if (tmp == NULL) goto failed;
3325 if (!PyList_Check(tmp)) {
3326 PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3327 goto failed;
3329 len = PyList_GET_SIZE(tmp);
3330 body = asdl_seq_new(len, arena);
3331 if (body == NULL) goto failed;
3332 for (i = 0; i < len; i++) {
3333 stmt_ty value;
3334 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
3335 if (res != 0) goto failed;
3336 asdl_seq_SET(body, i, value);
3338 Py_XDECREF(tmp);
3339 tmp = NULL;
3340 } else {
3341 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module");
3342 return 1;
3344 *out = Module(body, arena);
3345 if (*out == NULL) goto failed;
3346 return 0;
3348 isinstance = PyObject_IsInstance(obj, (PyObject*)Interactive_type);
3349 if (isinstance == -1) {
3350 return 1;
3352 if (isinstance) {
3353 asdl_seq* body;
3355 if (PyObject_HasAttrString(obj, "body")) {
3356 int res;
3357 Py_ssize_t len;
3358 Py_ssize_t i;
3359 tmp = PyObject_GetAttrString(obj, "body");
3360 if (tmp == NULL) goto failed;
3361 if (!PyList_Check(tmp)) {
3362 PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3363 goto failed;
3365 len = PyList_GET_SIZE(tmp);
3366 body = asdl_seq_new(len, arena);
3367 if (body == NULL) goto failed;
3368 for (i = 0; i < len; i++) {
3369 stmt_ty value;
3370 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
3371 if (res != 0) goto failed;
3372 asdl_seq_SET(body, i, value);
3374 Py_XDECREF(tmp);
3375 tmp = NULL;
3376 } else {
3377 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive");
3378 return 1;
3380 *out = Interactive(body, arena);
3381 if (*out == NULL) goto failed;
3382 return 0;
3384 isinstance = PyObject_IsInstance(obj, (PyObject*)Expression_type);
3385 if (isinstance == -1) {
3386 return 1;
3388 if (isinstance) {
3389 expr_ty body;
3391 if (PyObject_HasAttrString(obj, "body")) {
3392 int res;
3393 tmp = PyObject_GetAttrString(obj, "body");
3394 if (tmp == NULL) goto failed;
3395 res = obj2ast_expr(tmp, &body, arena);
3396 if (res != 0) goto failed;
3397 Py_XDECREF(tmp);
3398 tmp = NULL;
3399 } else {
3400 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression");
3401 return 1;
3403 *out = Expression(body, arena);
3404 if (*out == NULL) goto failed;
3405 return 0;
3407 isinstance = PyObject_IsInstance(obj, (PyObject*)Suite_type);
3408 if (isinstance == -1) {
3409 return 1;
3411 if (isinstance) {
3412 asdl_seq* body;
3414 if (PyObject_HasAttrString(obj, "body")) {
3415 int res;
3416 Py_ssize_t len;
3417 Py_ssize_t i;
3418 tmp = PyObject_GetAttrString(obj, "body");
3419 if (tmp == NULL) goto failed;
3420 if (!PyList_Check(tmp)) {
3421 PyErr_Format(PyExc_TypeError, "Suite field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3422 goto failed;
3424 len = PyList_GET_SIZE(tmp);
3425 body = asdl_seq_new(len, arena);
3426 if (body == NULL) goto failed;
3427 for (i = 0; i < len; i++) {
3428 stmt_ty value;
3429 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
3430 if (res != 0) goto failed;
3431 asdl_seq_SET(body, i, value);
3433 Py_XDECREF(tmp);
3434 tmp = NULL;
3435 } else {
3436 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Suite");
3437 return 1;
3439 *out = Suite(body, arena);
3440 if (*out == NULL) goto failed;
3441 return 0;
3444 tmp = PyObject_Repr(obj);
3445 if (tmp == NULL) goto failed;
3446 PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %.400s", PyString_AS_STRING(tmp));
3447 failed:
3448 Py_XDECREF(tmp);
3449 return 1;
3453 obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
3455 PyObject* tmp = NULL;
3456 int isinstance;
3458 int lineno;
3459 int col_offset;
3461 if (obj == Py_None) {
3462 *out = NULL;
3463 return 0;
3465 if (PyObject_HasAttrString(obj, "lineno")) {
3466 int res;
3467 tmp = PyObject_GetAttrString(obj, "lineno");
3468 if (tmp == NULL) goto failed;
3469 res = obj2ast_int(tmp, &lineno, arena);
3470 if (res != 0) goto failed;
3471 Py_XDECREF(tmp);
3472 tmp = NULL;
3473 } else {
3474 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt");
3475 return 1;
3477 if (PyObject_HasAttrString(obj, "col_offset")) {
3478 int res;
3479 tmp = PyObject_GetAttrString(obj, "col_offset");
3480 if (tmp == NULL) goto failed;
3481 res = obj2ast_int(tmp, &col_offset, arena);
3482 if (res != 0) goto failed;
3483 Py_XDECREF(tmp);
3484 tmp = NULL;
3485 } else {
3486 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt");
3487 return 1;
3489 isinstance = PyObject_IsInstance(obj, (PyObject*)FunctionDef_type);
3490 if (isinstance == -1) {
3491 return 1;
3493 if (isinstance) {
3494 identifier name;
3495 arguments_ty args;
3496 asdl_seq* body;
3497 asdl_seq* decorator_list;
3499 if (PyObject_HasAttrString(obj, "name")) {
3500 int res;
3501 tmp = PyObject_GetAttrString(obj, "name");
3502 if (tmp == NULL) goto failed;
3503 res = obj2ast_identifier(tmp, &name, arena);
3504 if (res != 0) goto failed;
3505 Py_XDECREF(tmp);
3506 tmp = NULL;
3507 } else {
3508 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef");
3509 return 1;
3511 if (PyObject_HasAttrString(obj, "args")) {
3512 int res;
3513 tmp = PyObject_GetAttrString(obj, "args");
3514 if (tmp == NULL) goto failed;
3515 res = obj2ast_arguments(tmp, &args, arena);
3516 if (res != 0) goto failed;
3517 Py_XDECREF(tmp);
3518 tmp = NULL;
3519 } else {
3520 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef");
3521 return 1;
3523 if (PyObject_HasAttrString(obj, "body")) {
3524 int res;
3525 Py_ssize_t len;
3526 Py_ssize_t i;
3527 tmp = PyObject_GetAttrString(obj, "body");
3528 if (tmp == NULL) goto failed;
3529 if (!PyList_Check(tmp)) {
3530 PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3531 goto failed;
3533 len = PyList_GET_SIZE(tmp);
3534 body = asdl_seq_new(len, arena);
3535 if (body == NULL) goto failed;
3536 for (i = 0; i < len; i++) {
3537 stmt_ty value;
3538 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
3539 if (res != 0) goto failed;
3540 asdl_seq_SET(body, i, value);
3542 Py_XDECREF(tmp);
3543 tmp = NULL;
3544 } else {
3545 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef");
3546 return 1;
3548 if (PyObject_HasAttrString(obj, "decorator_list")) {
3549 int res;
3550 Py_ssize_t len;
3551 Py_ssize_t i;
3552 tmp = PyObject_GetAttrString(obj, "decorator_list");
3553 if (tmp == NULL) goto failed;
3554 if (!PyList_Check(tmp)) {
3555 PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3556 goto failed;
3558 len = PyList_GET_SIZE(tmp);
3559 decorator_list = asdl_seq_new(len, arena);
3560 if (decorator_list == NULL) goto failed;
3561 for (i = 0; i < len; i++) {
3562 expr_ty value;
3563 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
3564 if (res != 0) goto failed;
3565 asdl_seq_SET(decorator_list, i, value);
3567 Py_XDECREF(tmp);
3568 tmp = NULL;
3569 } else {
3570 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef");
3571 return 1;
3573 *out = FunctionDef(name, args, body, decorator_list, lineno,
3574 col_offset, arena);
3575 if (*out == NULL) goto failed;
3576 return 0;
3578 isinstance = PyObject_IsInstance(obj, (PyObject*)ClassDef_type);
3579 if (isinstance == -1) {
3580 return 1;
3582 if (isinstance) {
3583 identifier name;
3584 asdl_seq* bases;
3585 asdl_seq* body;
3586 asdl_seq* decorator_list;
3588 if (PyObject_HasAttrString(obj, "name")) {
3589 int res;
3590 tmp = PyObject_GetAttrString(obj, "name");
3591 if (tmp == NULL) goto failed;
3592 res = obj2ast_identifier(tmp, &name, arena);
3593 if (res != 0) goto failed;
3594 Py_XDECREF(tmp);
3595 tmp = NULL;
3596 } else {
3597 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef");
3598 return 1;
3600 if (PyObject_HasAttrString(obj, "bases")) {
3601 int res;
3602 Py_ssize_t len;
3603 Py_ssize_t i;
3604 tmp = PyObject_GetAttrString(obj, "bases");
3605 if (tmp == NULL) goto failed;
3606 if (!PyList_Check(tmp)) {
3607 PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3608 goto failed;
3610 len = PyList_GET_SIZE(tmp);
3611 bases = asdl_seq_new(len, arena);
3612 if (bases == NULL) goto failed;
3613 for (i = 0; i < len; i++) {
3614 expr_ty value;
3615 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
3616 if (res != 0) goto failed;
3617 asdl_seq_SET(bases, i, value);
3619 Py_XDECREF(tmp);
3620 tmp = NULL;
3621 } else {
3622 PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef");
3623 return 1;
3625 if (PyObject_HasAttrString(obj, "body")) {
3626 int res;
3627 Py_ssize_t len;
3628 Py_ssize_t i;
3629 tmp = PyObject_GetAttrString(obj, "body");
3630 if (tmp == NULL) goto failed;
3631 if (!PyList_Check(tmp)) {
3632 PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3633 goto failed;
3635 len = PyList_GET_SIZE(tmp);
3636 body = asdl_seq_new(len, arena);
3637 if (body == NULL) goto failed;
3638 for (i = 0; i < len; i++) {
3639 stmt_ty value;
3640 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
3641 if (res != 0) goto failed;
3642 asdl_seq_SET(body, i, value);
3644 Py_XDECREF(tmp);
3645 tmp = NULL;
3646 } else {
3647 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef");
3648 return 1;
3650 if (PyObject_HasAttrString(obj, "decorator_list")) {
3651 int res;
3652 Py_ssize_t len;
3653 Py_ssize_t i;
3654 tmp = PyObject_GetAttrString(obj, "decorator_list");
3655 if (tmp == NULL) goto failed;
3656 if (!PyList_Check(tmp)) {
3657 PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3658 goto failed;
3660 len = PyList_GET_SIZE(tmp);
3661 decorator_list = asdl_seq_new(len, arena);
3662 if (decorator_list == NULL) goto failed;
3663 for (i = 0; i < len; i++) {
3664 expr_ty value;
3665 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
3666 if (res != 0) goto failed;
3667 asdl_seq_SET(decorator_list, i, value);
3669 Py_XDECREF(tmp);
3670 tmp = NULL;
3671 } else {
3672 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef");
3673 return 1;
3675 *out = ClassDef(name, bases, body, decorator_list, lineno,
3676 col_offset, arena);
3677 if (*out == NULL) goto failed;
3678 return 0;
3680 isinstance = PyObject_IsInstance(obj, (PyObject*)Return_type);
3681 if (isinstance == -1) {
3682 return 1;
3684 if (isinstance) {
3685 expr_ty value;
3687 if (PyObject_HasAttrString(obj, "value")) {
3688 int res;
3689 tmp = PyObject_GetAttrString(obj, "value");
3690 if (tmp == NULL) goto failed;
3691 res = obj2ast_expr(tmp, &value, arena);
3692 if (res != 0) goto failed;
3693 Py_XDECREF(tmp);
3694 tmp = NULL;
3695 } else {
3696 value = NULL;
3698 *out = Return(value, lineno, col_offset, arena);
3699 if (*out == NULL) goto failed;
3700 return 0;
3702 isinstance = PyObject_IsInstance(obj, (PyObject*)Delete_type);
3703 if (isinstance == -1) {
3704 return 1;
3706 if (isinstance) {
3707 asdl_seq* targets;
3709 if (PyObject_HasAttrString(obj, "targets")) {
3710 int res;
3711 Py_ssize_t len;
3712 Py_ssize_t i;
3713 tmp = PyObject_GetAttrString(obj, "targets");
3714 if (tmp == NULL) goto failed;
3715 if (!PyList_Check(tmp)) {
3716 PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3717 goto failed;
3719 len = PyList_GET_SIZE(tmp);
3720 targets = asdl_seq_new(len, arena);
3721 if (targets == NULL) goto failed;
3722 for (i = 0; i < len; i++) {
3723 expr_ty value;
3724 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
3725 if (res != 0) goto failed;
3726 asdl_seq_SET(targets, i, value);
3728 Py_XDECREF(tmp);
3729 tmp = NULL;
3730 } else {
3731 PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete");
3732 return 1;
3734 *out = Delete(targets, lineno, col_offset, arena);
3735 if (*out == NULL) goto failed;
3736 return 0;
3738 isinstance = PyObject_IsInstance(obj, (PyObject*)Assign_type);
3739 if (isinstance == -1) {
3740 return 1;
3742 if (isinstance) {
3743 asdl_seq* targets;
3744 expr_ty value;
3746 if (PyObject_HasAttrString(obj, "targets")) {
3747 int res;
3748 Py_ssize_t len;
3749 Py_ssize_t i;
3750 tmp = PyObject_GetAttrString(obj, "targets");
3751 if (tmp == NULL) goto failed;
3752 if (!PyList_Check(tmp)) {
3753 PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3754 goto failed;
3756 len = PyList_GET_SIZE(tmp);
3757 targets = asdl_seq_new(len, arena);
3758 if (targets == NULL) goto failed;
3759 for (i = 0; i < len; i++) {
3760 expr_ty value;
3761 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
3762 if (res != 0) goto failed;
3763 asdl_seq_SET(targets, i, value);
3765 Py_XDECREF(tmp);
3766 tmp = NULL;
3767 } else {
3768 PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign");
3769 return 1;
3771 if (PyObject_HasAttrString(obj, "value")) {
3772 int res;
3773 tmp = PyObject_GetAttrString(obj, "value");
3774 if (tmp == NULL) goto failed;
3775 res = obj2ast_expr(tmp, &value, arena);
3776 if (res != 0) goto failed;
3777 Py_XDECREF(tmp);
3778 tmp = NULL;
3779 } else {
3780 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign");
3781 return 1;
3783 *out = Assign(targets, value, lineno, col_offset, arena);
3784 if (*out == NULL) goto failed;
3785 return 0;
3787 isinstance = PyObject_IsInstance(obj, (PyObject*)AugAssign_type);
3788 if (isinstance == -1) {
3789 return 1;
3791 if (isinstance) {
3792 expr_ty target;
3793 operator_ty op;
3794 expr_ty value;
3796 if (PyObject_HasAttrString(obj, "target")) {
3797 int res;
3798 tmp = PyObject_GetAttrString(obj, "target");
3799 if (tmp == NULL) goto failed;
3800 res = obj2ast_expr(tmp, &target, arena);
3801 if (res != 0) goto failed;
3802 Py_XDECREF(tmp);
3803 tmp = NULL;
3804 } else {
3805 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign");
3806 return 1;
3808 if (PyObject_HasAttrString(obj, "op")) {
3809 int res;
3810 tmp = PyObject_GetAttrString(obj, "op");
3811 if (tmp == NULL) goto failed;
3812 res = obj2ast_operator(tmp, &op, arena);
3813 if (res != 0) goto failed;
3814 Py_XDECREF(tmp);
3815 tmp = NULL;
3816 } else {
3817 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign");
3818 return 1;
3820 if (PyObject_HasAttrString(obj, "value")) {
3821 int res;
3822 tmp = PyObject_GetAttrString(obj, "value");
3823 if (tmp == NULL) goto failed;
3824 res = obj2ast_expr(tmp, &value, arena);
3825 if (res != 0) goto failed;
3826 Py_XDECREF(tmp);
3827 tmp = NULL;
3828 } else {
3829 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign");
3830 return 1;
3832 *out = AugAssign(target, op, value, lineno, col_offset, arena);
3833 if (*out == NULL) goto failed;
3834 return 0;
3836 isinstance = PyObject_IsInstance(obj, (PyObject*)Print_type);
3837 if (isinstance == -1) {
3838 return 1;
3840 if (isinstance) {
3841 expr_ty dest;
3842 asdl_seq* values;
3843 bool nl;
3845 if (PyObject_HasAttrString(obj, "dest")) {
3846 int res;
3847 tmp = PyObject_GetAttrString(obj, "dest");
3848 if (tmp == NULL) goto failed;
3849 res = obj2ast_expr(tmp, &dest, arena);
3850 if (res != 0) goto failed;
3851 Py_XDECREF(tmp);
3852 tmp = NULL;
3853 } else {
3854 dest = NULL;
3856 if (PyObject_HasAttrString(obj, "values")) {
3857 int res;
3858 Py_ssize_t len;
3859 Py_ssize_t i;
3860 tmp = PyObject_GetAttrString(obj, "values");
3861 if (tmp == NULL) goto failed;
3862 if (!PyList_Check(tmp)) {
3863 PyErr_Format(PyExc_TypeError, "Print field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3864 goto failed;
3866 len = PyList_GET_SIZE(tmp);
3867 values = asdl_seq_new(len, arena);
3868 if (values == NULL) goto failed;
3869 for (i = 0; i < len; i++) {
3870 expr_ty value;
3871 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
3872 if (res != 0) goto failed;
3873 asdl_seq_SET(values, i, value);
3875 Py_XDECREF(tmp);
3876 tmp = NULL;
3877 } else {
3878 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Print");
3879 return 1;
3881 if (PyObject_HasAttrString(obj, "nl")) {
3882 int res;
3883 tmp = PyObject_GetAttrString(obj, "nl");
3884 if (tmp == NULL) goto failed;
3885 res = obj2ast_bool(tmp, &nl, arena);
3886 if (res != 0) goto failed;
3887 Py_XDECREF(tmp);
3888 tmp = NULL;
3889 } else {
3890 PyErr_SetString(PyExc_TypeError, "required field \"nl\" missing from Print");
3891 return 1;
3893 *out = Print(dest, values, nl, lineno, col_offset, arena);
3894 if (*out == NULL) goto failed;
3895 return 0;
3897 isinstance = PyObject_IsInstance(obj, (PyObject*)For_type);
3898 if (isinstance == -1) {
3899 return 1;
3901 if (isinstance) {
3902 expr_ty target;
3903 expr_ty iter;
3904 asdl_seq* body;
3905 asdl_seq* orelse;
3907 if (PyObject_HasAttrString(obj, "target")) {
3908 int res;
3909 tmp = PyObject_GetAttrString(obj, "target");
3910 if (tmp == NULL) goto failed;
3911 res = obj2ast_expr(tmp, &target, arena);
3912 if (res != 0) goto failed;
3913 Py_XDECREF(tmp);
3914 tmp = NULL;
3915 } else {
3916 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For");
3917 return 1;
3919 if (PyObject_HasAttrString(obj, "iter")) {
3920 int res;
3921 tmp = PyObject_GetAttrString(obj, "iter");
3922 if (tmp == NULL) goto failed;
3923 res = obj2ast_expr(tmp, &iter, arena);
3924 if (res != 0) goto failed;
3925 Py_XDECREF(tmp);
3926 tmp = NULL;
3927 } else {
3928 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For");
3929 return 1;
3931 if (PyObject_HasAttrString(obj, "body")) {
3932 int res;
3933 Py_ssize_t len;
3934 Py_ssize_t i;
3935 tmp = PyObject_GetAttrString(obj, "body");
3936 if (tmp == NULL) goto failed;
3937 if (!PyList_Check(tmp)) {
3938 PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3939 goto failed;
3941 len = PyList_GET_SIZE(tmp);
3942 body = asdl_seq_new(len, arena);
3943 if (body == NULL) goto failed;
3944 for (i = 0; i < len; i++) {
3945 stmt_ty value;
3946 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
3947 if (res != 0) goto failed;
3948 asdl_seq_SET(body, i, value);
3950 Py_XDECREF(tmp);
3951 tmp = NULL;
3952 } else {
3953 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For");
3954 return 1;
3956 if (PyObject_HasAttrString(obj, "orelse")) {
3957 int res;
3958 Py_ssize_t len;
3959 Py_ssize_t i;
3960 tmp = PyObject_GetAttrString(obj, "orelse");
3961 if (tmp == NULL) goto failed;
3962 if (!PyList_Check(tmp)) {
3963 PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);
3964 goto failed;
3966 len = PyList_GET_SIZE(tmp);
3967 orelse = asdl_seq_new(len, arena);
3968 if (orelse == NULL) goto failed;
3969 for (i = 0; i < len; i++) {
3970 stmt_ty value;
3971 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
3972 if (res != 0) goto failed;
3973 asdl_seq_SET(orelse, i, value);
3975 Py_XDECREF(tmp);
3976 tmp = NULL;
3977 } else {
3978 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For");
3979 return 1;
3981 *out = For(target, iter, body, orelse, lineno, col_offset,
3982 arena);
3983 if (*out == NULL) goto failed;
3984 return 0;
3986 isinstance = PyObject_IsInstance(obj, (PyObject*)While_type);
3987 if (isinstance == -1) {
3988 return 1;
3990 if (isinstance) {
3991 expr_ty test;
3992 asdl_seq* body;
3993 asdl_seq* orelse;
3995 if (PyObject_HasAttrString(obj, "test")) {
3996 int res;
3997 tmp = PyObject_GetAttrString(obj, "test");
3998 if (tmp == NULL) goto failed;
3999 res = obj2ast_expr(tmp, &test, arena);
4000 if (res != 0) goto failed;
4001 Py_XDECREF(tmp);
4002 tmp = NULL;
4003 } else {
4004 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While");
4005 return 1;
4007 if (PyObject_HasAttrString(obj, "body")) {
4008 int res;
4009 Py_ssize_t len;
4010 Py_ssize_t i;
4011 tmp = PyObject_GetAttrString(obj, "body");
4012 if (tmp == NULL) goto failed;
4013 if (!PyList_Check(tmp)) {
4014 PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4015 goto failed;
4017 len = PyList_GET_SIZE(tmp);
4018 body = asdl_seq_new(len, arena);
4019 if (body == NULL) goto failed;
4020 for (i = 0; i < len; i++) {
4021 stmt_ty value;
4022 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
4023 if (res != 0) goto failed;
4024 asdl_seq_SET(body, i, value);
4026 Py_XDECREF(tmp);
4027 tmp = NULL;
4028 } else {
4029 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While");
4030 return 1;
4032 if (PyObject_HasAttrString(obj, "orelse")) {
4033 int res;
4034 Py_ssize_t len;
4035 Py_ssize_t i;
4036 tmp = PyObject_GetAttrString(obj, "orelse");
4037 if (tmp == NULL) goto failed;
4038 if (!PyList_Check(tmp)) {
4039 PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4040 goto failed;
4042 len = PyList_GET_SIZE(tmp);
4043 orelse = asdl_seq_new(len, arena);
4044 if (orelse == NULL) goto failed;
4045 for (i = 0; i < len; i++) {
4046 stmt_ty value;
4047 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
4048 if (res != 0) goto failed;
4049 asdl_seq_SET(orelse, i, value);
4051 Py_XDECREF(tmp);
4052 tmp = NULL;
4053 } else {
4054 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While");
4055 return 1;
4057 *out = While(test, body, orelse, lineno, col_offset, arena);
4058 if (*out == NULL) goto failed;
4059 return 0;
4061 isinstance = PyObject_IsInstance(obj, (PyObject*)If_type);
4062 if (isinstance == -1) {
4063 return 1;
4065 if (isinstance) {
4066 expr_ty test;
4067 asdl_seq* body;
4068 asdl_seq* orelse;
4070 if (PyObject_HasAttrString(obj, "test")) {
4071 int res;
4072 tmp = PyObject_GetAttrString(obj, "test");
4073 if (tmp == NULL) goto failed;
4074 res = obj2ast_expr(tmp, &test, arena);
4075 if (res != 0) goto failed;
4076 Py_XDECREF(tmp);
4077 tmp = NULL;
4078 } else {
4079 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If");
4080 return 1;
4082 if (PyObject_HasAttrString(obj, "body")) {
4083 int res;
4084 Py_ssize_t len;
4085 Py_ssize_t i;
4086 tmp = PyObject_GetAttrString(obj, "body");
4087 if (tmp == NULL) goto failed;
4088 if (!PyList_Check(tmp)) {
4089 PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4090 goto failed;
4092 len = PyList_GET_SIZE(tmp);
4093 body = asdl_seq_new(len, arena);
4094 if (body == NULL) goto failed;
4095 for (i = 0; i < len; i++) {
4096 stmt_ty value;
4097 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
4098 if (res != 0) goto failed;
4099 asdl_seq_SET(body, i, value);
4101 Py_XDECREF(tmp);
4102 tmp = NULL;
4103 } else {
4104 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If");
4105 return 1;
4107 if (PyObject_HasAttrString(obj, "orelse")) {
4108 int res;
4109 Py_ssize_t len;
4110 Py_ssize_t i;
4111 tmp = PyObject_GetAttrString(obj, "orelse");
4112 if (tmp == NULL) goto failed;
4113 if (!PyList_Check(tmp)) {
4114 PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4115 goto failed;
4117 len = PyList_GET_SIZE(tmp);
4118 orelse = asdl_seq_new(len, arena);
4119 if (orelse == NULL) goto failed;
4120 for (i = 0; i < len; i++) {
4121 stmt_ty value;
4122 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
4123 if (res != 0) goto failed;
4124 asdl_seq_SET(orelse, i, value);
4126 Py_XDECREF(tmp);
4127 tmp = NULL;
4128 } else {
4129 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If");
4130 return 1;
4132 *out = If(test, body, orelse, lineno, col_offset, arena);
4133 if (*out == NULL) goto failed;
4134 return 0;
4136 isinstance = PyObject_IsInstance(obj, (PyObject*)With_type);
4137 if (isinstance == -1) {
4138 return 1;
4140 if (isinstance) {
4141 expr_ty context_expr;
4142 expr_ty optional_vars;
4143 asdl_seq* body;
4145 if (PyObject_HasAttrString(obj, "context_expr")) {
4146 int res;
4147 tmp = PyObject_GetAttrString(obj, "context_expr");
4148 if (tmp == NULL) goto failed;
4149 res = obj2ast_expr(tmp, &context_expr, arena);
4150 if (res != 0) goto failed;
4151 Py_XDECREF(tmp);
4152 tmp = NULL;
4153 } else {
4154 PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from With");
4155 return 1;
4157 if (PyObject_HasAttrString(obj, "optional_vars")) {
4158 int res;
4159 tmp = PyObject_GetAttrString(obj, "optional_vars");
4160 if (tmp == NULL) goto failed;
4161 res = obj2ast_expr(tmp, &optional_vars, arena);
4162 if (res != 0) goto failed;
4163 Py_XDECREF(tmp);
4164 tmp = NULL;
4165 } else {
4166 optional_vars = NULL;
4168 if (PyObject_HasAttrString(obj, "body")) {
4169 int res;
4170 Py_ssize_t len;
4171 Py_ssize_t i;
4172 tmp = PyObject_GetAttrString(obj, "body");
4173 if (tmp == NULL) goto failed;
4174 if (!PyList_Check(tmp)) {
4175 PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4176 goto failed;
4178 len = PyList_GET_SIZE(tmp);
4179 body = asdl_seq_new(len, arena);
4180 if (body == NULL) goto failed;
4181 for (i = 0; i < len; i++) {
4182 stmt_ty value;
4183 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
4184 if (res != 0) goto failed;
4185 asdl_seq_SET(body, i, value);
4187 Py_XDECREF(tmp);
4188 tmp = NULL;
4189 } else {
4190 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With");
4191 return 1;
4193 *out = With(context_expr, optional_vars, body, lineno,
4194 col_offset, arena);
4195 if (*out == NULL) goto failed;
4196 return 0;
4198 isinstance = PyObject_IsInstance(obj, (PyObject*)Raise_type);
4199 if (isinstance == -1) {
4200 return 1;
4202 if (isinstance) {
4203 expr_ty type;
4204 expr_ty inst;
4205 expr_ty tback;
4207 if (PyObject_HasAttrString(obj, "type")) {
4208 int res;
4209 tmp = PyObject_GetAttrString(obj, "type");
4210 if (tmp == NULL) goto failed;
4211 res = obj2ast_expr(tmp, &type, arena);
4212 if (res != 0) goto failed;
4213 Py_XDECREF(tmp);
4214 tmp = NULL;
4215 } else {
4216 type = NULL;
4218 if (PyObject_HasAttrString(obj, "inst")) {
4219 int res;
4220 tmp = PyObject_GetAttrString(obj, "inst");
4221 if (tmp == NULL) goto failed;
4222 res = obj2ast_expr(tmp, &inst, arena);
4223 if (res != 0) goto failed;
4224 Py_XDECREF(tmp);
4225 tmp = NULL;
4226 } else {
4227 inst = NULL;
4229 if (PyObject_HasAttrString(obj, "tback")) {
4230 int res;
4231 tmp = PyObject_GetAttrString(obj, "tback");
4232 if (tmp == NULL) goto failed;
4233 res = obj2ast_expr(tmp, &tback, arena);
4234 if (res != 0) goto failed;
4235 Py_XDECREF(tmp);
4236 tmp = NULL;
4237 } else {
4238 tback = NULL;
4240 *out = Raise(type, inst, tback, lineno, col_offset, arena);
4241 if (*out == NULL) goto failed;
4242 return 0;
4244 isinstance = PyObject_IsInstance(obj, (PyObject*)TryExcept_type);
4245 if (isinstance == -1) {
4246 return 1;
4248 if (isinstance) {
4249 asdl_seq* body;
4250 asdl_seq* handlers;
4251 asdl_seq* orelse;
4253 if (PyObject_HasAttrString(obj, "body")) {
4254 int res;
4255 Py_ssize_t len;
4256 Py_ssize_t i;
4257 tmp = PyObject_GetAttrString(obj, "body");
4258 if (tmp == NULL) goto failed;
4259 if (!PyList_Check(tmp)) {
4260 PyErr_Format(PyExc_TypeError, "TryExcept field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4261 goto failed;
4263 len = PyList_GET_SIZE(tmp);
4264 body = asdl_seq_new(len, arena);
4265 if (body == NULL) goto failed;
4266 for (i = 0; i < len; i++) {
4267 stmt_ty value;
4268 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
4269 if (res != 0) goto failed;
4270 asdl_seq_SET(body, i, value);
4272 Py_XDECREF(tmp);
4273 tmp = NULL;
4274 } else {
4275 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from TryExcept");
4276 return 1;
4278 if (PyObject_HasAttrString(obj, "handlers")) {
4279 int res;
4280 Py_ssize_t len;
4281 Py_ssize_t i;
4282 tmp = PyObject_GetAttrString(obj, "handlers");
4283 if (tmp == NULL) goto failed;
4284 if (!PyList_Check(tmp)) {
4285 PyErr_Format(PyExc_TypeError, "TryExcept field \"handlers\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4286 goto failed;
4288 len = PyList_GET_SIZE(tmp);
4289 handlers = asdl_seq_new(len, arena);
4290 if (handlers == NULL) goto failed;
4291 for (i = 0; i < len; i++) {
4292 excepthandler_ty value;
4293 res = obj2ast_excepthandler(PyList_GET_ITEM(tmp, i), &value, arena);
4294 if (res != 0) goto failed;
4295 asdl_seq_SET(handlers, i, value);
4297 Py_XDECREF(tmp);
4298 tmp = NULL;
4299 } else {
4300 PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from TryExcept");
4301 return 1;
4303 if (PyObject_HasAttrString(obj, "orelse")) {
4304 int res;
4305 Py_ssize_t len;
4306 Py_ssize_t i;
4307 tmp = PyObject_GetAttrString(obj, "orelse");
4308 if (tmp == NULL) goto failed;
4309 if (!PyList_Check(tmp)) {
4310 PyErr_Format(PyExc_TypeError, "TryExcept field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4311 goto failed;
4313 len = PyList_GET_SIZE(tmp);
4314 orelse = asdl_seq_new(len, arena);
4315 if (orelse == NULL) goto failed;
4316 for (i = 0; i < len; i++) {
4317 stmt_ty value;
4318 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
4319 if (res != 0) goto failed;
4320 asdl_seq_SET(orelse, i, value);
4322 Py_XDECREF(tmp);
4323 tmp = NULL;
4324 } else {
4325 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from TryExcept");
4326 return 1;
4328 *out = TryExcept(body, handlers, orelse, lineno, col_offset,
4329 arena);
4330 if (*out == NULL) goto failed;
4331 return 0;
4333 isinstance = PyObject_IsInstance(obj, (PyObject*)TryFinally_type);
4334 if (isinstance == -1) {
4335 return 1;
4337 if (isinstance) {
4338 asdl_seq* body;
4339 asdl_seq* finalbody;
4341 if (PyObject_HasAttrString(obj, "body")) {
4342 int res;
4343 Py_ssize_t len;
4344 Py_ssize_t i;
4345 tmp = PyObject_GetAttrString(obj, "body");
4346 if (tmp == NULL) goto failed;
4347 if (!PyList_Check(tmp)) {
4348 PyErr_Format(PyExc_TypeError, "TryFinally field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4349 goto failed;
4351 len = PyList_GET_SIZE(tmp);
4352 body = asdl_seq_new(len, arena);
4353 if (body == NULL) goto failed;
4354 for (i = 0; i < len; i++) {
4355 stmt_ty value;
4356 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
4357 if (res != 0) goto failed;
4358 asdl_seq_SET(body, i, value);
4360 Py_XDECREF(tmp);
4361 tmp = NULL;
4362 } else {
4363 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from TryFinally");
4364 return 1;
4366 if (PyObject_HasAttrString(obj, "finalbody")) {
4367 int res;
4368 Py_ssize_t len;
4369 Py_ssize_t i;
4370 tmp = PyObject_GetAttrString(obj, "finalbody");
4371 if (tmp == NULL) goto failed;
4372 if (!PyList_Check(tmp)) {
4373 PyErr_Format(PyExc_TypeError, "TryFinally field \"finalbody\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4374 goto failed;
4376 len = PyList_GET_SIZE(tmp);
4377 finalbody = asdl_seq_new(len, arena);
4378 if (finalbody == NULL) goto failed;
4379 for (i = 0; i < len; i++) {
4380 stmt_ty value;
4381 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
4382 if (res != 0) goto failed;
4383 asdl_seq_SET(finalbody, i, value);
4385 Py_XDECREF(tmp);
4386 tmp = NULL;
4387 } else {
4388 PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from TryFinally");
4389 return 1;
4391 *out = TryFinally(body, finalbody, lineno, col_offset, arena);
4392 if (*out == NULL) goto failed;
4393 return 0;
4395 isinstance = PyObject_IsInstance(obj, (PyObject*)Assert_type);
4396 if (isinstance == -1) {
4397 return 1;
4399 if (isinstance) {
4400 expr_ty test;
4401 expr_ty msg;
4403 if (PyObject_HasAttrString(obj, "test")) {
4404 int res;
4405 tmp = PyObject_GetAttrString(obj, "test");
4406 if (tmp == NULL) goto failed;
4407 res = obj2ast_expr(tmp, &test, arena);
4408 if (res != 0) goto failed;
4409 Py_XDECREF(tmp);
4410 tmp = NULL;
4411 } else {
4412 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert");
4413 return 1;
4415 if (PyObject_HasAttrString(obj, "msg")) {
4416 int res;
4417 tmp = PyObject_GetAttrString(obj, "msg");
4418 if (tmp == NULL) goto failed;
4419 res = obj2ast_expr(tmp, &msg, arena);
4420 if (res != 0) goto failed;
4421 Py_XDECREF(tmp);
4422 tmp = NULL;
4423 } else {
4424 msg = NULL;
4426 *out = Assert(test, msg, lineno, col_offset, arena);
4427 if (*out == NULL) goto failed;
4428 return 0;
4430 isinstance = PyObject_IsInstance(obj, (PyObject*)Import_type);
4431 if (isinstance == -1) {
4432 return 1;
4434 if (isinstance) {
4435 asdl_seq* names;
4437 if (PyObject_HasAttrString(obj, "names")) {
4438 int res;
4439 Py_ssize_t len;
4440 Py_ssize_t i;
4441 tmp = PyObject_GetAttrString(obj, "names");
4442 if (tmp == NULL) goto failed;
4443 if (!PyList_Check(tmp)) {
4444 PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4445 goto failed;
4447 len = PyList_GET_SIZE(tmp);
4448 names = asdl_seq_new(len, arena);
4449 if (names == NULL) goto failed;
4450 for (i = 0; i < len; i++) {
4451 alias_ty value;
4452 res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena);
4453 if (res != 0) goto failed;
4454 asdl_seq_SET(names, i, value);
4456 Py_XDECREF(tmp);
4457 tmp = NULL;
4458 } else {
4459 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import");
4460 return 1;
4462 *out = Import(names, lineno, col_offset, arena);
4463 if (*out == NULL) goto failed;
4464 return 0;
4466 isinstance = PyObject_IsInstance(obj, (PyObject*)ImportFrom_type);
4467 if (isinstance == -1) {
4468 return 1;
4470 if (isinstance) {
4471 identifier module;
4472 asdl_seq* names;
4473 int level;
4475 if (PyObject_HasAttrString(obj, "module")) {
4476 int res;
4477 tmp = PyObject_GetAttrString(obj, "module");
4478 if (tmp == NULL) goto failed;
4479 res = obj2ast_identifier(tmp, &module, arena);
4480 if (res != 0) goto failed;
4481 Py_XDECREF(tmp);
4482 tmp = NULL;
4483 } else {
4484 module = NULL;
4486 if (PyObject_HasAttrString(obj, "names")) {
4487 int res;
4488 Py_ssize_t len;
4489 Py_ssize_t i;
4490 tmp = PyObject_GetAttrString(obj, "names");
4491 if (tmp == NULL) goto failed;
4492 if (!PyList_Check(tmp)) {
4493 PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4494 goto failed;
4496 len = PyList_GET_SIZE(tmp);
4497 names = asdl_seq_new(len, arena);
4498 if (names == NULL) goto failed;
4499 for (i = 0; i < len; i++) {
4500 alias_ty value;
4501 res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena);
4502 if (res != 0) goto failed;
4503 asdl_seq_SET(names, i, value);
4505 Py_XDECREF(tmp);
4506 tmp = NULL;
4507 } else {
4508 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom");
4509 return 1;
4511 if (PyObject_HasAttrString(obj, "level")) {
4512 int res;
4513 tmp = PyObject_GetAttrString(obj, "level");
4514 if (tmp == NULL) goto failed;
4515 res = obj2ast_int(tmp, &level, arena);
4516 if (res != 0) goto failed;
4517 Py_XDECREF(tmp);
4518 tmp = NULL;
4519 } else {
4520 level = 0;
4522 *out = ImportFrom(module, names, level, lineno, col_offset,
4523 arena);
4524 if (*out == NULL) goto failed;
4525 return 0;
4527 isinstance = PyObject_IsInstance(obj, (PyObject*)Exec_type);
4528 if (isinstance == -1) {
4529 return 1;
4531 if (isinstance) {
4532 expr_ty body;
4533 expr_ty globals;
4534 expr_ty locals;
4536 if (PyObject_HasAttrString(obj, "body")) {
4537 int res;
4538 tmp = PyObject_GetAttrString(obj, "body");
4539 if (tmp == NULL) goto failed;
4540 res = obj2ast_expr(tmp, &body, arena);
4541 if (res != 0) goto failed;
4542 Py_XDECREF(tmp);
4543 tmp = NULL;
4544 } else {
4545 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Exec");
4546 return 1;
4548 if (PyObject_HasAttrString(obj, "globals")) {
4549 int res;
4550 tmp = PyObject_GetAttrString(obj, "globals");
4551 if (tmp == NULL) goto failed;
4552 res = obj2ast_expr(tmp, &globals, arena);
4553 if (res != 0) goto failed;
4554 Py_XDECREF(tmp);
4555 tmp = NULL;
4556 } else {
4557 globals = NULL;
4559 if (PyObject_HasAttrString(obj, "locals")) {
4560 int res;
4561 tmp = PyObject_GetAttrString(obj, "locals");
4562 if (tmp == NULL) goto failed;
4563 res = obj2ast_expr(tmp, &locals, arena);
4564 if (res != 0) goto failed;
4565 Py_XDECREF(tmp);
4566 tmp = NULL;
4567 } else {
4568 locals = NULL;
4570 *out = Exec(body, globals, locals, lineno, col_offset, arena);
4571 if (*out == NULL) goto failed;
4572 return 0;
4574 isinstance = PyObject_IsInstance(obj, (PyObject*)Global_type);
4575 if (isinstance == -1) {
4576 return 1;
4578 if (isinstance) {
4579 asdl_seq* names;
4581 if (PyObject_HasAttrString(obj, "names")) {
4582 int res;
4583 Py_ssize_t len;
4584 Py_ssize_t i;
4585 tmp = PyObject_GetAttrString(obj, "names");
4586 if (tmp == NULL) goto failed;
4587 if (!PyList_Check(tmp)) {
4588 PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4589 goto failed;
4591 len = PyList_GET_SIZE(tmp);
4592 names = asdl_seq_new(len, arena);
4593 if (names == NULL) goto failed;
4594 for (i = 0; i < len; i++) {
4595 identifier value;
4596 res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena);
4597 if (res != 0) goto failed;
4598 asdl_seq_SET(names, i, value);
4600 Py_XDECREF(tmp);
4601 tmp = NULL;
4602 } else {
4603 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global");
4604 return 1;
4606 *out = Global(names, lineno, col_offset, arena);
4607 if (*out == NULL) goto failed;
4608 return 0;
4610 isinstance = PyObject_IsInstance(obj, (PyObject*)Expr_type);
4611 if (isinstance == -1) {
4612 return 1;
4614 if (isinstance) {
4615 expr_ty value;
4617 if (PyObject_HasAttrString(obj, "value")) {
4618 int res;
4619 tmp = PyObject_GetAttrString(obj, "value");
4620 if (tmp == NULL) goto failed;
4621 res = obj2ast_expr(tmp, &value, arena);
4622 if (res != 0) goto failed;
4623 Py_XDECREF(tmp);
4624 tmp = NULL;
4625 } else {
4626 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr");
4627 return 1;
4629 *out = Expr(value, lineno, col_offset, arena);
4630 if (*out == NULL) goto failed;
4631 return 0;
4633 isinstance = PyObject_IsInstance(obj, (PyObject*)Pass_type);
4634 if (isinstance == -1) {
4635 return 1;
4637 if (isinstance) {
4639 *out = Pass(lineno, col_offset, arena);
4640 if (*out == NULL) goto failed;
4641 return 0;
4643 isinstance = PyObject_IsInstance(obj, (PyObject*)Break_type);
4644 if (isinstance == -1) {
4645 return 1;
4647 if (isinstance) {
4649 *out = Break(lineno, col_offset, arena);
4650 if (*out == NULL) goto failed;
4651 return 0;
4653 isinstance = PyObject_IsInstance(obj, (PyObject*)Continue_type);
4654 if (isinstance == -1) {
4655 return 1;
4657 if (isinstance) {
4659 *out = Continue(lineno, col_offset, arena);
4660 if (*out == NULL) goto failed;
4661 return 0;
4664 tmp = PyObject_Repr(obj);
4665 if (tmp == NULL) goto failed;
4666 PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %.400s", PyString_AS_STRING(tmp));
4667 failed:
4668 Py_XDECREF(tmp);
4669 return 1;
4673 obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
4675 PyObject* tmp = NULL;
4676 int isinstance;
4678 int lineno;
4679 int col_offset;
4681 if (obj == Py_None) {
4682 *out = NULL;
4683 return 0;
4685 if (PyObject_HasAttrString(obj, "lineno")) {
4686 int res;
4687 tmp = PyObject_GetAttrString(obj, "lineno");
4688 if (tmp == NULL) goto failed;
4689 res = obj2ast_int(tmp, &lineno, arena);
4690 if (res != 0) goto failed;
4691 Py_XDECREF(tmp);
4692 tmp = NULL;
4693 } else {
4694 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr");
4695 return 1;
4697 if (PyObject_HasAttrString(obj, "col_offset")) {
4698 int res;
4699 tmp = PyObject_GetAttrString(obj, "col_offset");
4700 if (tmp == NULL) goto failed;
4701 res = obj2ast_int(tmp, &col_offset, arena);
4702 if (res != 0) goto failed;
4703 Py_XDECREF(tmp);
4704 tmp = NULL;
4705 } else {
4706 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr");
4707 return 1;
4709 isinstance = PyObject_IsInstance(obj, (PyObject*)BoolOp_type);
4710 if (isinstance == -1) {
4711 return 1;
4713 if (isinstance) {
4714 boolop_ty op;
4715 asdl_seq* values;
4717 if (PyObject_HasAttrString(obj, "op")) {
4718 int res;
4719 tmp = PyObject_GetAttrString(obj, "op");
4720 if (tmp == NULL) goto failed;
4721 res = obj2ast_boolop(tmp, &op, arena);
4722 if (res != 0) goto failed;
4723 Py_XDECREF(tmp);
4724 tmp = NULL;
4725 } else {
4726 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp");
4727 return 1;
4729 if (PyObject_HasAttrString(obj, "values")) {
4730 int res;
4731 Py_ssize_t len;
4732 Py_ssize_t i;
4733 tmp = PyObject_GetAttrString(obj, "values");
4734 if (tmp == NULL) goto failed;
4735 if (!PyList_Check(tmp)) {
4736 PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4737 goto failed;
4739 len = PyList_GET_SIZE(tmp);
4740 values = asdl_seq_new(len, arena);
4741 if (values == NULL) goto failed;
4742 for (i = 0; i < len; i++) {
4743 expr_ty value;
4744 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
4745 if (res != 0) goto failed;
4746 asdl_seq_SET(values, i, value);
4748 Py_XDECREF(tmp);
4749 tmp = NULL;
4750 } else {
4751 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp");
4752 return 1;
4754 *out = BoolOp(op, values, lineno, col_offset, arena);
4755 if (*out == NULL) goto failed;
4756 return 0;
4758 isinstance = PyObject_IsInstance(obj, (PyObject*)BinOp_type);
4759 if (isinstance == -1) {
4760 return 1;
4762 if (isinstance) {
4763 expr_ty left;
4764 operator_ty op;
4765 expr_ty right;
4767 if (PyObject_HasAttrString(obj, "left")) {
4768 int res;
4769 tmp = PyObject_GetAttrString(obj, "left");
4770 if (tmp == NULL) goto failed;
4771 res = obj2ast_expr(tmp, &left, arena);
4772 if (res != 0) goto failed;
4773 Py_XDECREF(tmp);
4774 tmp = NULL;
4775 } else {
4776 PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp");
4777 return 1;
4779 if (PyObject_HasAttrString(obj, "op")) {
4780 int res;
4781 tmp = PyObject_GetAttrString(obj, "op");
4782 if (tmp == NULL) goto failed;
4783 res = obj2ast_operator(tmp, &op, arena);
4784 if (res != 0) goto failed;
4785 Py_XDECREF(tmp);
4786 tmp = NULL;
4787 } else {
4788 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp");
4789 return 1;
4791 if (PyObject_HasAttrString(obj, "right")) {
4792 int res;
4793 tmp = PyObject_GetAttrString(obj, "right");
4794 if (tmp == NULL) goto failed;
4795 res = obj2ast_expr(tmp, &right, arena);
4796 if (res != 0) goto failed;
4797 Py_XDECREF(tmp);
4798 tmp = NULL;
4799 } else {
4800 PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp");
4801 return 1;
4803 *out = BinOp(left, op, right, lineno, col_offset, arena);
4804 if (*out == NULL) goto failed;
4805 return 0;
4807 isinstance = PyObject_IsInstance(obj, (PyObject*)UnaryOp_type);
4808 if (isinstance == -1) {
4809 return 1;
4811 if (isinstance) {
4812 unaryop_ty op;
4813 expr_ty operand;
4815 if (PyObject_HasAttrString(obj, "op")) {
4816 int res;
4817 tmp = PyObject_GetAttrString(obj, "op");
4818 if (tmp == NULL) goto failed;
4819 res = obj2ast_unaryop(tmp, &op, arena);
4820 if (res != 0) goto failed;
4821 Py_XDECREF(tmp);
4822 tmp = NULL;
4823 } else {
4824 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp");
4825 return 1;
4827 if (PyObject_HasAttrString(obj, "operand")) {
4828 int res;
4829 tmp = PyObject_GetAttrString(obj, "operand");
4830 if (tmp == NULL) goto failed;
4831 res = obj2ast_expr(tmp, &operand, arena);
4832 if (res != 0) goto failed;
4833 Py_XDECREF(tmp);
4834 tmp = NULL;
4835 } else {
4836 PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp");
4837 return 1;
4839 *out = UnaryOp(op, operand, lineno, col_offset, arena);
4840 if (*out == NULL) goto failed;
4841 return 0;
4843 isinstance = PyObject_IsInstance(obj, (PyObject*)Lambda_type);
4844 if (isinstance == -1) {
4845 return 1;
4847 if (isinstance) {
4848 arguments_ty args;
4849 expr_ty body;
4851 if (PyObject_HasAttrString(obj, "args")) {
4852 int res;
4853 tmp = PyObject_GetAttrString(obj, "args");
4854 if (tmp == NULL) goto failed;
4855 res = obj2ast_arguments(tmp, &args, arena);
4856 if (res != 0) goto failed;
4857 Py_XDECREF(tmp);
4858 tmp = NULL;
4859 } else {
4860 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda");
4861 return 1;
4863 if (PyObject_HasAttrString(obj, "body")) {
4864 int res;
4865 tmp = PyObject_GetAttrString(obj, "body");
4866 if (tmp == NULL) goto failed;
4867 res = obj2ast_expr(tmp, &body, arena);
4868 if (res != 0) goto failed;
4869 Py_XDECREF(tmp);
4870 tmp = NULL;
4871 } else {
4872 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda");
4873 return 1;
4875 *out = Lambda(args, body, lineno, col_offset, arena);
4876 if (*out == NULL) goto failed;
4877 return 0;
4879 isinstance = PyObject_IsInstance(obj, (PyObject*)IfExp_type);
4880 if (isinstance == -1) {
4881 return 1;
4883 if (isinstance) {
4884 expr_ty test;
4885 expr_ty body;
4886 expr_ty orelse;
4888 if (PyObject_HasAttrString(obj, "test")) {
4889 int res;
4890 tmp = PyObject_GetAttrString(obj, "test");
4891 if (tmp == NULL) goto failed;
4892 res = obj2ast_expr(tmp, &test, arena);
4893 if (res != 0) goto failed;
4894 Py_XDECREF(tmp);
4895 tmp = NULL;
4896 } else {
4897 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp");
4898 return 1;
4900 if (PyObject_HasAttrString(obj, "body")) {
4901 int res;
4902 tmp = PyObject_GetAttrString(obj, "body");
4903 if (tmp == NULL) goto failed;
4904 res = obj2ast_expr(tmp, &body, arena);
4905 if (res != 0) goto failed;
4906 Py_XDECREF(tmp);
4907 tmp = NULL;
4908 } else {
4909 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp");
4910 return 1;
4912 if (PyObject_HasAttrString(obj, "orelse")) {
4913 int res;
4914 tmp = PyObject_GetAttrString(obj, "orelse");
4915 if (tmp == NULL) goto failed;
4916 res = obj2ast_expr(tmp, &orelse, arena);
4917 if (res != 0) goto failed;
4918 Py_XDECREF(tmp);
4919 tmp = NULL;
4920 } else {
4921 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp");
4922 return 1;
4924 *out = IfExp(test, body, orelse, lineno, col_offset, arena);
4925 if (*out == NULL) goto failed;
4926 return 0;
4928 isinstance = PyObject_IsInstance(obj, (PyObject*)Dict_type);
4929 if (isinstance == -1) {
4930 return 1;
4932 if (isinstance) {
4933 asdl_seq* keys;
4934 asdl_seq* values;
4936 if (PyObject_HasAttrString(obj, "keys")) {
4937 int res;
4938 Py_ssize_t len;
4939 Py_ssize_t i;
4940 tmp = PyObject_GetAttrString(obj, "keys");
4941 if (tmp == NULL) goto failed;
4942 if (!PyList_Check(tmp)) {
4943 PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4944 goto failed;
4946 len = PyList_GET_SIZE(tmp);
4947 keys = asdl_seq_new(len, arena);
4948 if (keys == NULL) goto failed;
4949 for (i = 0; i < len; i++) {
4950 expr_ty value;
4951 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
4952 if (res != 0) goto failed;
4953 asdl_seq_SET(keys, i, value);
4955 Py_XDECREF(tmp);
4956 tmp = NULL;
4957 } else {
4958 PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict");
4959 return 1;
4961 if (PyObject_HasAttrString(obj, "values")) {
4962 int res;
4963 Py_ssize_t len;
4964 Py_ssize_t i;
4965 tmp = PyObject_GetAttrString(obj, "values");
4966 if (tmp == NULL) goto failed;
4967 if (!PyList_Check(tmp)) {
4968 PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name);
4969 goto failed;
4971 len = PyList_GET_SIZE(tmp);
4972 values = asdl_seq_new(len, arena);
4973 if (values == NULL) goto failed;
4974 for (i = 0; i < len; i++) {
4975 expr_ty value;
4976 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
4977 if (res != 0) goto failed;
4978 asdl_seq_SET(values, i, value);
4980 Py_XDECREF(tmp);
4981 tmp = NULL;
4982 } else {
4983 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict");
4984 return 1;
4986 *out = Dict(keys, values, lineno, col_offset, arena);
4987 if (*out == NULL) goto failed;
4988 return 0;
4990 isinstance = PyObject_IsInstance(obj, (PyObject*)Set_type);
4991 if (isinstance == -1) {
4992 return 1;
4994 if (isinstance) {
4995 asdl_seq* elts;
4997 if (PyObject_HasAttrString(obj, "elts")) {
4998 int res;
4999 Py_ssize_t len;
5000 Py_ssize_t i;
5001 tmp = PyObject_GetAttrString(obj, "elts");
5002 if (tmp == NULL) goto failed;
5003 if (!PyList_Check(tmp)) {
5004 PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5005 goto failed;
5007 len = PyList_GET_SIZE(tmp);
5008 elts = asdl_seq_new(len, arena);
5009 if (elts == NULL) goto failed;
5010 for (i = 0; i < len; i++) {
5011 expr_ty value;
5012 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
5013 if (res != 0) goto failed;
5014 asdl_seq_SET(elts, i, value);
5016 Py_XDECREF(tmp);
5017 tmp = NULL;
5018 } else {
5019 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set");
5020 return 1;
5022 *out = Set(elts, lineno, col_offset, arena);
5023 if (*out == NULL) goto failed;
5024 return 0;
5026 isinstance = PyObject_IsInstance(obj, (PyObject*)ListComp_type);
5027 if (isinstance == -1) {
5028 return 1;
5030 if (isinstance) {
5031 expr_ty elt;
5032 asdl_seq* generators;
5034 if (PyObject_HasAttrString(obj, "elt")) {
5035 int res;
5036 tmp = PyObject_GetAttrString(obj, "elt");
5037 if (tmp == NULL) goto failed;
5038 res = obj2ast_expr(tmp, &elt, arena);
5039 if (res != 0) goto failed;
5040 Py_XDECREF(tmp);
5041 tmp = NULL;
5042 } else {
5043 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp");
5044 return 1;
5046 if (PyObject_HasAttrString(obj, "generators")) {
5047 int res;
5048 Py_ssize_t len;
5049 Py_ssize_t i;
5050 tmp = PyObject_GetAttrString(obj, "generators");
5051 if (tmp == NULL) goto failed;
5052 if (!PyList_Check(tmp)) {
5053 PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5054 goto failed;
5056 len = PyList_GET_SIZE(tmp);
5057 generators = asdl_seq_new(len, arena);
5058 if (generators == NULL) goto failed;
5059 for (i = 0; i < len; i++) {
5060 comprehension_ty value;
5061 res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena);
5062 if (res != 0) goto failed;
5063 asdl_seq_SET(generators, i, value);
5065 Py_XDECREF(tmp);
5066 tmp = NULL;
5067 } else {
5068 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp");
5069 return 1;
5071 *out = ListComp(elt, generators, lineno, col_offset, arena);
5072 if (*out == NULL) goto failed;
5073 return 0;
5075 isinstance = PyObject_IsInstance(obj, (PyObject*)SetComp_type);
5076 if (isinstance == -1) {
5077 return 1;
5079 if (isinstance) {
5080 expr_ty elt;
5081 asdl_seq* generators;
5083 if (PyObject_HasAttrString(obj, "elt")) {
5084 int res;
5085 tmp = PyObject_GetAttrString(obj, "elt");
5086 if (tmp == NULL) goto failed;
5087 res = obj2ast_expr(tmp, &elt, arena);
5088 if (res != 0) goto failed;
5089 Py_XDECREF(tmp);
5090 tmp = NULL;
5091 } else {
5092 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp");
5093 return 1;
5095 if (PyObject_HasAttrString(obj, "generators")) {
5096 int res;
5097 Py_ssize_t len;
5098 Py_ssize_t i;
5099 tmp = PyObject_GetAttrString(obj, "generators");
5100 if (tmp == NULL) goto failed;
5101 if (!PyList_Check(tmp)) {
5102 PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5103 goto failed;
5105 len = PyList_GET_SIZE(tmp);
5106 generators = asdl_seq_new(len, arena);
5107 if (generators == NULL) goto failed;
5108 for (i = 0; i < len; i++) {
5109 comprehension_ty value;
5110 res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena);
5111 if (res != 0) goto failed;
5112 asdl_seq_SET(generators, i, value);
5114 Py_XDECREF(tmp);
5115 tmp = NULL;
5116 } else {
5117 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp");
5118 return 1;
5120 *out = SetComp(elt, generators, lineno, col_offset, arena);
5121 if (*out == NULL) goto failed;
5122 return 0;
5124 isinstance = PyObject_IsInstance(obj, (PyObject*)DictComp_type);
5125 if (isinstance == -1) {
5126 return 1;
5128 if (isinstance) {
5129 expr_ty key;
5130 expr_ty value;
5131 asdl_seq* generators;
5133 if (PyObject_HasAttrString(obj, "key")) {
5134 int res;
5135 tmp = PyObject_GetAttrString(obj, "key");
5136 if (tmp == NULL) goto failed;
5137 res = obj2ast_expr(tmp, &key, arena);
5138 if (res != 0) goto failed;
5139 Py_XDECREF(tmp);
5140 tmp = NULL;
5141 } else {
5142 PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp");
5143 return 1;
5145 if (PyObject_HasAttrString(obj, "value")) {
5146 int res;
5147 tmp = PyObject_GetAttrString(obj, "value");
5148 if (tmp == NULL) goto failed;
5149 res = obj2ast_expr(tmp, &value, arena);
5150 if (res != 0) goto failed;
5151 Py_XDECREF(tmp);
5152 tmp = NULL;
5153 } else {
5154 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp");
5155 return 1;
5157 if (PyObject_HasAttrString(obj, "generators")) {
5158 int res;
5159 Py_ssize_t len;
5160 Py_ssize_t i;
5161 tmp = PyObject_GetAttrString(obj, "generators");
5162 if (tmp == NULL) goto failed;
5163 if (!PyList_Check(tmp)) {
5164 PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5165 goto failed;
5167 len = PyList_GET_SIZE(tmp);
5168 generators = asdl_seq_new(len, arena);
5169 if (generators == NULL) goto failed;
5170 for (i = 0; i < len; i++) {
5171 comprehension_ty value;
5172 res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena);
5173 if (res != 0) goto failed;
5174 asdl_seq_SET(generators, i, value);
5176 Py_XDECREF(tmp);
5177 tmp = NULL;
5178 } else {
5179 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp");
5180 return 1;
5182 *out = DictComp(key, value, generators, lineno, col_offset,
5183 arena);
5184 if (*out == NULL) goto failed;
5185 return 0;
5187 isinstance = PyObject_IsInstance(obj, (PyObject*)GeneratorExp_type);
5188 if (isinstance == -1) {
5189 return 1;
5191 if (isinstance) {
5192 expr_ty elt;
5193 asdl_seq* generators;
5195 if (PyObject_HasAttrString(obj, "elt")) {
5196 int res;
5197 tmp = PyObject_GetAttrString(obj, "elt");
5198 if (tmp == NULL) goto failed;
5199 res = obj2ast_expr(tmp, &elt, arena);
5200 if (res != 0) goto failed;
5201 Py_XDECREF(tmp);
5202 tmp = NULL;
5203 } else {
5204 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp");
5205 return 1;
5207 if (PyObject_HasAttrString(obj, "generators")) {
5208 int res;
5209 Py_ssize_t len;
5210 Py_ssize_t i;
5211 tmp = PyObject_GetAttrString(obj, "generators");
5212 if (tmp == NULL) goto failed;
5213 if (!PyList_Check(tmp)) {
5214 PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5215 goto failed;
5217 len = PyList_GET_SIZE(tmp);
5218 generators = asdl_seq_new(len, arena);
5219 if (generators == NULL) goto failed;
5220 for (i = 0; i < len; i++) {
5221 comprehension_ty value;
5222 res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena);
5223 if (res != 0) goto failed;
5224 asdl_seq_SET(generators, i, value);
5226 Py_XDECREF(tmp);
5227 tmp = NULL;
5228 } else {
5229 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp");
5230 return 1;
5232 *out = GeneratorExp(elt, generators, lineno, col_offset, arena);
5233 if (*out == NULL) goto failed;
5234 return 0;
5236 isinstance = PyObject_IsInstance(obj, (PyObject*)Yield_type);
5237 if (isinstance == -1) {
5238 return 1;
5240 if (isinstance) {
5241 expr_ty value;
5243 if (PyObject_HasAttrString(obj, "value")) {
5244 int res;
5245 tmp = PyObject_GetAttrString(obj, "value");
5246 if (tmp == NULL) goto failed;
5247 res = obj2ast_expr(tmp, &value, arena);
5248 if (res != 0) goto failed;
5249 Py_XDECREF(tmp);
5250 tmp = NULL;
5251 } else {
5252 value = NULL;
5254 *out = Yield(value, lineno, col_offset, arena);
5255 if (*out == NULL) goto failed;
5256 return 0;
5258 isinstance = PyObject_IsInstance(obj, (PyObject*)Compare_type);
5259 if (isinstance == -1) {
5260 return 1;
5262 if (isinstance) {
5263 expr_ty left;
5264 asdl_int_seq* ops;
5265 asdl_seq* comparators;
5267 if (PyObject_HasAttrString(obj, "left")) {
5268 int res;
5269 tmp = PyObject_GetAttrString(obj, "left");
5270 if (tmp == NULL) goto failed;
5271 res = obj2ast_expr(tmp, &left, arena);
5272 if (res != 0) goto failed;
5273 Py_XDECREF(tmp);
5274 tmp = NULL;
5275 } else {
5276 PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare");
5277 return 1;
5279 if (PyObject_HasAttrString(obj, "ops")) {
5280 int res;
5281 Py_ssize_t len;
5282 Py_ssize_t i;
5283 tmp = PyObject_GetAttrString(obj, "ops");
5284 if (tmp == NULL) goto failed;
5285 if (!PyList_Check(tmp)) {
5286 PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5287 goto failed;
5289 len = PyList_GET_SIZE(tmp);
5290 ops = asdl_int_seq_new(len, arena);
5291 if (ops == NULL) goto failed;
5292 for (i = 0; i < len; i++) {
5293 cmpop_ty value;
5294 res = obj2ast_cmpop(PyList_GET_ITEM(tmp, i), &value, arena);
5295 if (res != 0) goto failed;
5296 asdl_seq_SET(ops, i, value);
5298 Py_XDECREF(tmp);
5299 tmp = NULL;
5300 } else {
5301 PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare");
5302 return 1;
5304 if (PyObject_HasAttrString(obj, "comparators")) {
5305 int res;
5306 Py_ssize_t len;
5307 Py_ssize_t i;
5308 tmp = PyObject_GetAttrString(obj, "comparators");
5309 if (tmp == NULL) goto failed;
5310 if (!PyList_Check(tmp)) {
5311 PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5312 goto failed;
5314 len = PyList_GET_SIZE(tmp);
5315 comparators = asdl_seq_new(len, arena);
5316 if (comparators == NULL) goto failed;
5317 for (i = 0; i < len; i++) {
5318 expr_ty value;
5319 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
5320 if (res != 0) goto failed;
5321 asdl_seq_SET(comparators, i, value);
5323 Py_XDECREF(tmp);
5324 tmp = NULL;
5325 } else {
5326 PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare");
5327 return 1;
5329 *out = Compare(left, ops, comparators, lineno, col_offset,
5330 arena);
5331 if (*out == NULL) goto failed;
5332 return 0;
5334 isinstance = PyObject_IsInstance(obj, (PyObject*)Call_type);
5335 if (isinstance == -1) {
5336 return 1;
5338 if (isinstance) {
5339 expr_ty func;
5340 asdl_seq* args;
5341 asdl_seq* keywords;
5342 expr_ty starargs;
5343 expr_ty kwargs;
5345 if (PyObject_HasAttrString(obj, "func")) {
5346 int res;
5347 tmp = PyObject_GetAttrString(obj, "func");
5348 if (tmp == NULL) goto failed;
5349 res = obj2ast_expr(tmp, &func, arena);
5350 if (res != 0) goto failed;
5351 Py_XDECREF(tmp);
5352 tmp = NULL;
5353 } else {
5354 PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call");
5355 return 1;
5357 if (PyObject_HasAttrString(obj, "args")) {
5358 int res;
5359 Py_ssize_t len;
5360 Py_ssize_t i;
5361 tmp = PyObject_GetAttrString(obj, "args");
5362 if (tmp == NULL) goto failed;
5363 if (!PyList_Check(tmp)) {
5364 PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5365 goto failed;
5367 len = PyList_GET_SIZE(tmp);
5368 args = asdl_seq_new(len, arena);
5369 if (args == NULL) goto failed;
5370 for (i = 0; i < len; i++) {
5371 expr_ty value;
5372 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
5373 if (res != 0) goto failed;
5374 asdl_seq_SET(args, i, value);
5376 Py_XDECREF(tmp);
5377 tmp = NULL;
5378 } else {
5379 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call");
5380 return 1;
5382 if (PyObject_HasAttrString(obj, "keywords")) {
5383 int res;
5384 Py_ssize_t len;
5385 Py_ssize_t i;
5386 tmp = PyObject_GetAttrString(obj, "keywords");
5387 if (tmp == NULL) goto failed;
5388 if (!PyList_Check(tmp)) {
5389 PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5390 goto failed;
5392 len = PyList_GET_SIZE(tmp);
5393 keywords = asdl_seq_new(len, arena);
5394 if (keywords == NULL) goto failed;
5395 for (i = 0; i < len; i++) {
5396 keyword_ty value;
5397 res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &value, arena);
5398 if (res != 0) goto failed;
5399 asdl_seq_SET(keywords, i, value);
5401 Py_XDECREF(tmp);
5402 tmp = NULL;
5403 } else {
5404 PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call");
5405 return 1;
5407 if (PyObject_HasAttrString(obj, "starargs")) {
5408 int res;
5409 tmp = PyObject_GetAttrString(obj, "starargs");
5410 if (tmp == NULL) goto failed;
5411 res = obj2ast_expr(tmp, &starargs, arena);
5412 if (res != 0) goto failed;
5413 Py_XDECREF(tmp);
5414 tmp = NULL;
5415 } else {
5416 starargs = NULL;
5418 if (PyObject_HasAttrString(obj, "kwargs")) {
5419 int res;
5420 tmp = PyObject_GetAttrString(obj, "kwargs");
5421 if (tmp == NULL) goto failed;
5422 res = obj2ast_expr(tmp, &kwargs, arena);
5423 if (res != 0) goto failed;
5424 Py_XDECREF(tmp);
5425 tmp = NULL;
5426 } else {
5427 kwargs = NULL;
5429 *out = Call(func, args, keywords, starargs, kwargs, lineno,
5430 col_offset, arena);
5431 if (*out == NULL) goto failed;
5432 return 0;
5434 isinstance = PyObject_IsInstance(obj, (PyObject*)Repr_type);
5435 if (isinstance == -1) {
5436 return 1;
5438 if (isinstance) {
5439 expr_ty value;
5441 if (PyObject_HasAttrString(obj, "value")) {
5442 int res;
5443 tmp = PyObject_GetAttrString(obj, "value");
5444 if (tmp == NULL) goto failed;
5445 res = obj2ast_expr(tmp, &value, arena);
5446 if (res != 0) goto failed;
5447 Py_XDECREF(tmp);
5448 tmp = NULL;
5449 } else {
5450 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Repr");
5451 return 1;
5453 *out = Repr(value, lineno, col_offset, arena);
5454 if (*out == NULL) goto failed;
5455 return 0;
5457 isinstance = PyObject_IsInstance(obj, (PyObject*)Num_type);
5458 if (isinstance == -1) {
5459 return 1;
5461 if (isinstance) {
5462 object n;
5464 if (PyObject_HasAttrString(obj, "n")) {
5465 int res;
5466 tmp = PyObject_GetAttrString(obj, "n");
5467 if (tmp == NULL) goto failed;
5468 res = obj2ast_object(tmp, &n, arena);
5469 if (res != 0) goto failed;
5470 Py_XDECREF(tmp);
5471 tmp = NULL;
5472 } else {
5473 PyErr_SetString(PyExc_TypeError, "required field \"n\" missing from Num");
5474 return 1;
5476 *out = Num(n, lineno, col_offset, arena);
5477 if (*out == NULL) goto failed;
5478 return 0;
5480 isinstance = PyObject_IsInstance(obj, (PyObject*)Str_type);
5481 if (isinstance == -1) {
5482 return 1;
5484 if (isinstance) {
5485 string s;
5487 if (PyObject_HasAttrString(obj, "s")) {
5488 int res;
5489 tmp = PyObject_GetAttrString(obj, "s");
5490 if (tmp == NULL) goto failed;
5491 res = obj2ast_string(tmp, &s, arena);
5492 if (res != 0) goto failed;
5493 Py_XDECREF(tmp);
5494 tmp = NULL;
5495 } else {
5496 PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Str");
5497 return 1;
5499 *out = Str(s, lineno, col_offset, arena);
5500 if (*out == NULL) goto failed;
5501 return 0;
5503 isinstance = PyObject_IsInstance(obj, (PyObject*)Attribute_type);
5504 if (isinstance == -1) {
5505 return 1;
5507 if (isinstance) {
5508 expr_ty value;
5509 identifier attr;
5510 expr_context_ty ctx;
5512 if (PyObject_HasAttrString(obj, "value")) {
5513 int res;
5514 tmp = PyObject_GetAttrString(obj, "value");
5515 if (tmp == NULL) goto failed;
5516 res = obj2ast_expr(tmp, &value, arena);
5517 if (res != 0) goto failed;
5518 Py_XDECREF(tmp);
5519 tmp = NULL;
5520 } else {
5521 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute");
5522 return 1;
5524 if (PyObject_HasAttrString(obj, "attr")) {
5525 int res;
5526 tmp = PyObject_GetAttrString(obj, "attr");
5527 if (tmp == NULL) goto failed;
5528 res = obj2ast_identifier(tmp, &attr, arena);
5529 if (res != 0) goto failed;
5530 Py_XDECREF(tmp);
5531 tmp = NULL;
5532 } else {
5533 PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute");
5534 return 1;
5536 if (PyObject_HasAttrString(obj, "ctx")) {
5537 int res;
5538 tmp = PyObject_GetAttrString(obj, "ctx");
5539 if (tmp == NULL) goto failed;
5540 res = obj2ast_expr_context(tmp, &ctx, arena);
5541 if (res != 0) goto failed;
5542 Py_XDECREF(tmp);
5543 tmp = NULL;
5544 } else {
5545 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute");
5546 return 1;
5548 *out = Attribute(value, attr, ctx, lineno, col_offset, arena);
5549 if (*out == NULL) goto failed;
5550 return 0;
5552 isinstance = PyObject_IsInstance(obj, (PyObject*)Subscript_type);
5553 if (isinstance == -1) {
5554 return 1;
5556 if (isinstance) {
5557 expr_ty value;
5558 slice_ty slice;
5559 expr_context_ty ctx;
5561 if (PyObject_HasAttrString(obj, "value")) {
5562 int res;
5563 tmp = PyObject_GetAttrString(obj, "value");
5564 if (tmp == NULL) goto failed;
5565 res = obj2ast_expr(tmp, &value, arena);
5566 if (res != 0) goto failed;
5567 Py_XDECREF(tmp);
5568 tmp = NULL;
5569 } else {
5570 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript");
5571 return 1;
5573 if (PyObject_HasAttrString(obj, "slice")) {
5574 int res;
5575 tmp = PyObject_GetAttrString(obj, "slice");
5576 if (tmp == NULL) goto failed;
5577 res = obj2ast_slice(tmp, &slice, arena);
5578 if (res != 0) goto failed;
5579 Py_XDECREF(tmp);
5580 tmp = NULL;
5581 } else {
5582 PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript");
5583 return 1;
5585 if (PyObject_HasAttrString(obj, "ctx")) {
5586 int res;
5587 tmp = PyObject_GetAttrString(obj, "ctx");
5588 if (tmp == NULL) goto failed;
5589 res = obj2ast_expr_context(tmp, &ctx, arena);
5590 if (res != 0) goto failed;
5591 Py_XDECREF(tmp);
5592 tmp = NULL;
5593 } else {
5594 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript");
5595 return 1;
5597 *out = Subscript(value, slice, ctx, lineno, col_offset, arena);
5598 if (*out == NULL) goto failed;
5599 return 0;
5601 isinstance = PyObject_IsInstance(obj, (PyObject*)Name_type);
5602 if (isinstance == -1) {
5603 return 1;
5605 if (isinstance) {
5606 identifier id;
5607 expr_context_ty ctx;
5609 if (PyObject_HasAttrString(obj, "id")) {
5610 int res;
5611 tmp = PyObject_GetAttrString(obj, "id");
5612 if (tmp == NULL) goto failed;
5613 res = obj2ast_identifier(tmp, &id, arena);
5614 if (res != 0) goto failed;
5615 Py_XDECREF(tmp);
5616 tmp = NULL;
5617 } else {
5618 PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name");
5619 return 1;
5621 if (PyObject_HasAttrString(obj, "ctx")) {
5622 int res;
5623 tmp = PyObject_GetAttrString(obj, "ctx");
5624 if (tmp == NULL) goto failed;
5625 res = obj2ast_expr_context(tmp, &ctx, arena);
5626 if (res != 0) goto failed;
5627 Py_XDECREF(tmp);
5628 tmp = NULL;
5629 } else {
5630 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name");
5631 return 1;
5633 *out = Name(id, ctx, lineno, col_offset, arena);
5634 if (*out == NULL) goto failed;
5635 return 0;
5637 isinstance = PyObject_IsInstance(obj, (PyObject*)List_type);
5638 if (isinstance == -1) {
5639 return 1;
5641 if (isinstance) {
5642 asdl_seq* elts;
5643 expr_context_ty ctx;
5645 if (PyObject_HasAttrString(obj, "elts")) {
5646 int res;
5647 Py_ssize_t len;
5648 Py_ssize_t i;
5649 tmp = PyObject_GetAttrString(obj, "elts");
5650 if (tmp == NULL) goto failed;
5651 if (!PyList_Check(tmp)) {
5652 PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5653 goto failed;
5655 len = PyList_GET_SIZE(tmp);
5656 elts = asdl_seq_new(len, arena);
5657 if (elts == NULL) goto failed;
5658 for (i = 0; i < len; i++) {
5659 expr_ty value;
5660 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
5661 if (res != 0) goto failed;
5662 asdl_seq_SET(elts, i, value);
5664 Py_XDECREF(tmp);
5665 tmp = NULL;
5666 } else {
5667 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List");
5668 return 1;
5670 if (PyObject_HasAttrString(obj, "ctx")) {
5671 int res;
5672 tmp = PyObject_GetAttrString(obj, "ctx");
5673 if (tmp == NULL) goto failed;
5674 res = obj2ast_expr_context(tmp, &ctx, arena);
5675 if (res != 0) goto failed;
5676 Py_XDECREF(tmp);
5677 tmp = NULL;
5678 } else {
5679 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List");
5680 return 1;
5682 *out = List(elts, ctx, lineno, col_offset, arena);
5683 if (*out == NULL) goto failed;
5684 return 0;
5686 isinstance = PyObject_IsInstance(obj, (PyObject*)Tuple_type);
5687 if (isinstance == -1) {
5688 return 1;
5690 if (isinstance) {
5691 asdl_seq* elts;
5692 expr_context_ty ctx;
5694 if (PyObject_HasAttrString(obj, "elts")) {
5695 int res;
5696 Py_ssize_t len;
5697 Py_ssize_t i;
5698 tmp = PyObject_GetAttrString(obj, "elts");
5699 if (tmp == NULL) goto failed;
5700 if (!PyList_Check(tmp)) {
5701 PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5702 goto failed;
5704 len = PyList_GET_SIZE(tmp);
5705 elts = asdl_seq_new(len, arena);
5706 if (elts == NULL) goto failed;
5707 for (i = 0; i < len; i++) {
5708 expr_ty value;
5709 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
5710 if (res != 0) goto failed;
5711 asdl_seq_SET(elts, i, value);
5713 Py_XDECREF(tmp);
5714 tmp = NULL;
5715 } else {
5716 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple");
5717 return 1;
5719 if (PyObject_HasAttrString(obj, "ctx")) {
5720 int res;
5721 tmp = PyObject_GetAttrString(obj, "ctx");
5722 if (tmp == NULL) goto failed;
5723 res = obj2ast_expr_context(tmp, &ctx, arena);
5724 if (res != 0) goto failed;
5725 Py_XDECREF(tmp);
5726 tmp = NULL;
5727 } else {
5728 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple");
5729 return 1;
5731 *out = Tuple(elts, ctx, lineno, col_offset, arena);
5732 if (*out == NULL) goto failed;
5733 return 0;
5736 tmp = PyObject_Repr(obj);
5737 if (tmp == NULL) goto failed;
5738 PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %.400s", PyString_AS_STRING(tmp));
5739 failed:
5740 Py_XDECREF(tmp);
5741 return 1;
5745 obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena)
5747 PyObject* tmp = NULL;
5748 int isinstance;
5750 isinstance = PyObject_IsInstance(obj, (PyObject *)Load_type);
5751 if (isinstance == -1) {
5752 return 1;
5754 if (isinstance) {
5755 *out = Load;
5756 return 0;
5758 isinstance = PyObject_IsInstance(obj, (PyObject *)Store_type);
5759 if (isinstance == -1) {
5760 return 1;
5762 if (isinstance) {
5763 *out = Store;
5764 return 0;
5766 isinstance = PyObject_IsInstance(obj, (PyObject *)Del_type);
5767 if (isinstance == -1) {
5768 return 1;
5770 if (isinstance) {
5771 *out = Del;
5772 return 0;
5774 isinstance = PyObject_IsInstance(obj, (PyObject *)AugLoad_type);
5775 if (isinstance == -1) {
5776 return 1;
5778 if (isinstance) {
5779 *out = AugLoad;
5780 return 0;
5782 isinstance = PyObject_IsInstance(obj, (PyObject *)AugStore_type);
5783 if (isinstance == -1) {
5784 return 1;
5786 if (isinstance) {
5787 *out = AugStore;
5788 return 0;
5790 isinstance = PyObject_IsInstance(obj, (PyObject *)Param_type);
5791 if (isinstance == -1) {
5792 return 1;
5794 if (isinstance) {
5795 *out = Param;
5796 return 0;
5799 tmp = PyObject_Repr(obj);
5800 if (tmp == NULL) goto failed;
5801 PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %.400s", PyString_AS_STRING(tmp));
5802 failed:
5803 Py_XDECREF(tmp);
5804 return 1;
5808 obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena)
5810 PyObject* tmp = NULL;
5811 int isinstance;
5814 if (obj == Py_None) {
5815 *out = NULL;
5816 return 0;
5818 isinstance = PyObject_IsInstance(obj, (PyObject*)Ellipsis_type);
5819 if (isinstance == -1) {
5820 return 1;
5822 if (isinstance) {
5824 *out = Ellipsis(arena);
5825 if (*out == NULL) goto failed;
5826 return 0;
5828 isinstance = PyObject_IsInstance(obj, (PyObject*)Slice_type);
5829 if (isinstance == -1) {
5830 return 1;
5832 if (isinstance) {
5833 expr_ty lower;
5834 expr_ty upper;
5835 expr_ty step;
5837 if (PyObject_HasAttrString(obj, "lower")) {
5838 int res;
5839 tmp = PyObject_GetAttrString(obj, "lower");
5840 if (tmp == NULL) goto failed;
5841 res = obj2ast_expr(tmp, &lower, arena);
5842 if (res != 0) goto failed;
5843 Py_XDECREF(tmp);
5844 tmp = NULL;
5845 } else {
5846 lower = NULL;
5848 if (PyObject_HasAttrString(obj, "upper")) {
5849 int res;
5850 tmp = PyObject_GetAttrString(obj, "upper");
5851 if (tmp == NULL) goto failed;
5852 res = obj2ast_expr(tmp, &upper, arena);
5853 if (res != 0) goto failed;
5854 Py_XDECREF(tmp);
5855 tmp = NULL;
5856 } else {
5857 upper = NULL;
5859 if (PyObject_HasAttrString(obj, "step")) {
5860 int res;
5861 tmp = PyObject_GetAttrString(obj, "step");
5862 if (tmp == NULL) goto failed;
5863 res = obj2ast_expr(tmp, &step, arena);
5864 if (res != 0) goto failed;
5865 Py_XDECREF(tmp);
5866 tmp = NULL;
5867 } else {
5868 step = NULL;
5870 *out = Slice(lower, upper, step, arena);
5871 if (*out == NULL) goto failed;
5872 return 0;
5874 isinstance = PyObject_IsInstance(obj, (PyObject*)ExtSlice_type);
5875 if (isinstance == -1) {
5876 return 1;
5878 if (isinstance) {
5879 asdl_seq* dims;
5881 if (PyObject_HasAttrString(obj, "dims")) {
5882 int res;
5883 Py_ssize_t len;
5884 Py_ssize_t i;
5885 tmp = PyObject_GetAttrString(obj, "dims");
5886 if (tmp == NULL) goto failed;
5887 if (!PyList_Check(tmp)) {
5888 PyErr_Format(PyExc_TypeError, "ExtSlice field \"dims\" must be a list, not a %.200s", tmp->ob_type->tp_name);
5889 goto failed;
5891 len = PyList_GET_SIZE(tmp);
5892 dims = asdl_seq_new(len, arena);
5893 if (dims == NULL) goto failed;
5894 for (i = 0; i < len; i++) {
5895 slice_ty value;
5896 res = obj2ast_slice(PyList_GET_ITEM(tmp, i), &value, arena);
5897 if (res != 0) goto failed;
5898 asdl_seq_SET(dims, i, value);
5900 Py_XDECREF(tmp);
5901 tmp = NULL;
5902 } else {
5903 PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice");
5904 return 1;
5906 *out = ExtSlice(dims, arena);
5907 if (*out == NULL) goto failed;
5908 return 0;
5910 isinstance = PyObject_IsInstance(obj, (PyObject*)Index_type);
5911 if (isinstance == -1) {
5912 return 1;
5914 if (isinstance) {
5915 expr_ty value;
5917 if (PyObject_HasAttrString(obj, "value")) {
5918 int res;
5919 tmp = PyObject_GetAttrString(obj, "value");
5920 if (tmp == NULL) goto failed;
5921 res = obj2ast_expr(tmp, &value, arena);
5922 if (res != 0) goto failed;
5923 Py_XDECREF(tmp);
5924 tmp = NULL;
5925 } else {
5926 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index");
5927 return 1;
5929 *out = Index(value, arena);
5930 if (*out == NULL) goto failed;
5931 return 0;
5934 tmp = PyObject_Repr(obj);
5935 if (tmp == NULL) goto failed;
5936 PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %.400s", PyString_AS_STRING(tmp));
5937 failed:
5938 Py_XDECREF(tmp);
5939 return 1;
5943 obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena)
5945 PyObject* tmp = NULL;
5946 int isinstance;
5948 isinstance = PyObject_IsInstance(obj, (PyObject *)And_type);
5949 if (isinstance == -1) {
5950 return 1;
5952 if (isinstance) {
5953 *out = And;
5954 return 0;
5956 isinstance = PyObject_IsInstance(obj, (PyObject *)Or_type);
5957 if (isinstance == -1) {
5958 return 1;
5960 if (isinstance) {
5961 *out = Or;
5962 return 0;
5965 tmp = PyObject_Repr(obj);
5966 if (tmp == NULL) goto failed;
5967 PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %.400s", PyString_AS_STRING(tmp));
5968 failed:
5969 Py_XDECREF(tmp);
5970 return 1;
5974 obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena)
5976 PyObject* tmp = NULL;
5977 int isinstance;
5979 isinstance = PyObject_IsInstance(obj, (PyObject *)Add_type);
5980 if (isinstance == -1) {
5981 return 1;
5983 if (isinstance) {
5984 *out = Add;
5985 return 0;
5987 isinstance = PyObject_IsInstance(obj, (PyObject *)Sub_type);
5988 if (isinstance == -1) {
5989 return 1;
5991 if (isinstance) {
5992 *out = Sub;
5993 return 0;
5995 isinstance = PyObject_IsInstance(obj, (PyObject *)Mult_type);
5996 if (isinstance == -1) {
5997 return 1;
5999 if (isinstance) {
6000 *out = Mult;
6001 return 0;
6003 isinstance = PyObject_IsInstance(obj, (PyObject *)Div_type);
6004 if (isinstance == -1) {
6005 return 1;
6007 if (isinstance) {
6008 *out = Div;
6009 return 0;
6011 isinstance = PyObject_IsInstance(obj, (PyObject *)Mod_type);
6012 if (isinstance == -1) {
6013 return 1;
6015 if (isinstance) {
6016 *out = Mod;
6017 return 0;
6019 isinstance = PyObject_IsInstance(obj, (PyObject *)Pow_type);
6020 if (isinstance == -1) {
6021 return 1;
6023 if (isinstance) {
6024 *out = Pow;
6025 return 0;
6027 isinstance = PyObject_IsInstance(obj, (PyObject *)LShift_type);
6028 if (isinstance == -1) {
6029 return 1;
6031 if (isinstance) {
6032 *out = LShift;
6033 return 0;
6035 isinstance = PyObject_IsInstance(obj, (PyObject *)RShift_type);
6036 if (isinstance == -1) {
6037 return 1;
6039 if (isinstance) {
6040 *out = RShift;
6041 return 0;
6043 isinstance = PyObject_IsInstance(obj, (PyObject *)BitOr_type);
6044 if (isinstance == -1) {
6045 return 1;
6047 if (isinstance) {
6048 *out = BitOr;
6049 return 0;
6051 isinstance = PyObject_IsInstance(obj, (PyObject *)BitXor_type);
6052 if (isinstance == -1) {
6053 return 1;
6055 if (isinstance) {
6056 *out = BitXor;
6057 return 0;
6059 isinstance = PyObject_IsInstance(obj, (PyObject *)BitAnd_type);
6060 if (isinstance == -1) {
6061 return 1;
6063 if (isinstance) {
6064 *out = BitAnd;
6065 return 0;
6067 isinstance = PyObject_IsInstance(obj, (PyObject *)FloorDiv_type);
6068 if (isinstance == -1) {
6069 return 1;
6071 if (isinstance) {
6072 *out = FloorDiv;
6073 return 0;
6076 tmp = PyObject_Repr(obj);
6077 if (tmp == NULL) goto failed;
6078 PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %.400s", PyString_AS_STRING(tmp));
6079 failed:
6080 Py_XDECREF(tmp);
6081 return 1;
6085 obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena)
6087 PyObject* tmp = NULL;
6088 int isinstance;
6090 isinstance = PyObject_IsInstance(obj, (PyObject *)Invert_type);
6091 if (isinstance == -1) {
6092 return 1;
6094 if (isinstance) {
6095 *out = Invert;
6096 return 0;
6098 isinstance = PyObject_IsInstance(obj, (PyObject *)Not_type);
6099 if (isinstance == -1) {
6100 return 1;
6102 if (isinstance) {
6103 *out = Not;
6104 return 0;
6106 isinstance = PyObject_IsInstance(obj, (PyObject *)UAdd_type);
6107 if (isinstance == -1) {
6108 return 1;
6110 if (isinstance) {
6111 *out = UAdd;
6112 return 0;
6114 isinstance = PyObject_IsInstance(obj, (PyObject *)USub_type);
6115 if (isinstance == -1) {
6116 return 1;
6118 if (isinstance) {
6119 *out = USub;
6120 return 0;
6123 tmp = PyObject_Repr(obj);
6124 if (tmp == NULL) goto failed;
6125 PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %.400s", PyString_AS_STRING(tmp));
6126 failed:
6127 Py_XDECREF(tmp);
6128 return 1;
6132 obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena)
6134 PyObject* tmp = NULL;
6135 int isinstance;
6137 isinstance = PyObject_IsInstance(obj, (PyObject *)Eq_type);
6138 if (isinstance == -1) {
6139 return 1;
6141 if (isinstance) {
6142 *out = Eq;
6143 return 0;
6145 isinstance = PyObject_IsInstance(obj, (PyObject *)NotEq_type);
6146 if (isinstance == -1) {
6147 return 1;
6149 if (isinstance) {
6150 *out = NotEq;
6151 return 0;
6153 isinstance = PyObject_IsInstance(obj, (PyObject *)Lt_type);
6154 if (isinstance == -1) {
6155 return 1;
6157 if (isinstance) {
6158 *out = Lt;
6159 return 0;
6161 isinstance = PyObject_IsInstance(obj, (PyObject *)LtE_type);
6162 if (isinstance == -1) {
6163 return 1;
6165 if (isinstance) {
6166 *out = LtE;
6167 return 0;
6169 isinstance = PyObject_IsInstance(obj, (PyObject *)Gt_type);
6170 if (isinstance == -1) {
6171 return 1;
6173 if (isinstance) {
6174 *out = Gt;
6175 return 0;
6177 isinstance = PyObject_IsInstance(obj, (PyObject *)GtE_type);
6178 if (isinstance == -1) {
6179 return 1;
6181 if (isinstance) {
6182 *out = GtE;
6183 return 0;
6185 isinstance = PyObject_IsInstance(obj, (PyObject *)Is_type);
6186 if (isinstance == -1) {
6187 return 1;
6189 if (isinstance) {
6190 *out = Is;
6191 return 0;
6193 isinstance = PyObject_IsInstance(obj, (PyObject *)IsNot_type);
6194 if (isinstance == -1) {
6195 return 1;
6197 if (isinstance) {
6198 *out = IsNot;
6199 return 0;
6201 isinstance = PyObject_IsInstance(obj, (PyObject *)In_type);
6202 if (isinstance == -1) {
6203 return 1;
6205 if (isinstance) {
6206 *out = In;
6207 return 0;
6209 isinstance = PyObject_IsInstance(obj, (PyObject *)NotIn_type);
6210 if (isinstance == -1) {
6211 return 1;
6213 if (isinstance) {
6214 *out = NotIn;
6215 return 0;
6218 tmp = PyObject_Repr(obj);
6219 if (tmp == NULL) goto failed;
6220 PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %.400s", PyString_AS_STRING(tmp));
6221 failed:
6222 Py_XDECREF(tmp);
6223 return 1;
6227 obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena)
6229 PyObject* tmp = NULL;
6230 expr_ty target;
6231 expr_ty iter;
6232 asdl_seq* ifs;
6234 if (PyObject_HasAttrString(obj, "target")) {
6235 int res;
6236 tmp = PyObject_GetAttrString(obj, "target");
6237 if (tmp == NULL) goto failed;
6238 res = obj2ast_expr(tmp, &target, arena);
6239 if (res != 0) goto failed;
6240 Py_XDECREF(tmp);
6241 tmp = NULL;
6242 } else {
6243 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension");
6244 return 1;
6246 if (PyObject_HasAttrString(obj, "iter")) {
6247 int res;
6248 tmp = PyObject_GetAttrString(obj, "iter");
6249 if (tmp == NULL) goto failed;
6250 res = obj2ast_expr(tmp, &iter, arena);
6251 if (res != 0) goto failed;
6252 Py_XDECREF(tmp);
6253 tmp = NULL;
6254 } else {
6255 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension");
6256 return 1;
6258 if (PyObject_HasAttrString(obj, "ifs")) {
6259 int res;
6260 Py_ssize_t len;
6261 Py_ssize_t i;
6262 tmp = PyObject_GetAttrString(obj, "ifs");
6263 if (tmp == NULL) goto failed;
6264 if (!PyList_Check(tmp)) {
6265 PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", tmp->ob_type->tp_name);
6266 goto failed;
6268 len = PyList_GET_SIZE(tmp);
6269 ifs = asdl_seq_new(len, arena);
6270 if (ifs == NULL) goto failed;
6271 for (i = 0; i < len; i++) {
6272 expr_ty value;
6273 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
6274 if (res != 0) goto failed;
6275 asdl_seq_SET(ifs, i, value);
6277 Py_XDECREF(tmp);
6278 tmp = NULL;
6279 } else {
6280 PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension");
6281 return 1;
6283 *out = comprehension(target, iter, ifs, arena);
6284 return 0;
6285 failed:
6286 Py_XDECREF(tmp);
6287 return 1;
6291 obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena)
6293 PyObject* tmp = NULL;
6294 int isinstance;
6296 int lineno;
6297 int col_offset;
6299 if (obj == Py_None) {
6300 *out = NULL;
6301 return 0;
6303 if (PyObject_HasAttrString(obj, "lineno")) {
6304 int res;
6305 tmp = PyObject_GetAttrString(obj, "lineno");
6306 if (tmp == NULL) goto failed;
6307 res = obj2ast_int(tmp, &lineno, arena);
6308 if (res != 0) goto failed;
6309 Py_XDECREF(tmp);
6310 tmp = NULL;
6311 } else {
6312 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler");
6313 return 1;
6315 if (PyObject_HasAttrString(obj, "col_offset")) {
6316 int res;
6317 tmp = PyObject_GetAttrString(obj, "col_offset");
6318 if (tmp == NULL) goto failed;
6319 res = obj2ast_int(tmp, &col_offset, arena);
6320 if (res != 0) goto failed;
6321 Py_XDECREF(tmp);
6322 tmp = NULL;
6323 } else {
6324 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler");
6325 return 1;
6327 isinstance = PyObject_IsInstance(obj, (PyObject*)ExceptHandler_type);
6328 if (isinstance == -1) {
6329 return 1;
6331 if (isinstance) {
6332 expr_ty type;
6333 expr_ty name;
6334 asdl_seq* body;
6336 if (PyObject_HasAttrString(obj, "type")) {
6337 int res;
6338 tmp = PyObject_GetAttrString(obj, "type");
6339 if (tmp == NULL) goto failed;
6340 res = obj2ast_expr(tmp, &type, arena);
6341 if (res != 0) goto failed;
6342 Py_XDECREF(tmp);
6343 tmp = NULL;
6344 } else {
6345 type = NULL;
6347 if (PyObject_HasAttrString(obj, "name")) {
6348 int res;
6349 tmp = PyObject_GetAttrString(obj, "name");
6350 if (tmp == NULL) goto failed;
6351 res = obj2ast_expr(tmp, &name, arena);
6352 if (res != 0) goto failed;
6353 Py_XDECREF(tmp);
6354 tmp = NULL;
6355 } else {
6356 name = NULL;
6358 if (PyObject_HasAttrString(obj, "body")) {
6359 int res;
6360 Py_ssize_t len;
6361 Py_ssize_t i;
6362 tmp = PyObject_GetAttrString(obj, "body");
6363 if (tmp == NULL) goto failed;
6364 if (!PyList_Check(tmp)) {
6365 PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
6366 goto failed;
6368 len = PyList_GET_SIZE(tmp);
6369 body = asdl_seq_new(len, arena);
6370 if (body == NULL) goto failed;
6371 for (i = 0; i < len; i++) {
6372 stmt_ty value;
6373 res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
6374 if (res != 0) goto failed;
6375 asdl_seq_SET(body, i, value);
6377 Py_XDECREF(tmp);
6378 tmp = NULL;
6379 } else {
6380 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler");
6381 return 1;
6383 *out = ExceptHandler(type, name, body, lineno, col_offset,
6384 arena);
6385 if (*out == NULL) goto failed;
6386 return 0;
6389 tmp = PyObject_Repr(obj);
6390 if (tmp == NULL) goto failed;
6391 PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %.400s", PyString_AS_STRING(tmp));
6392 failed:
6393 Py_XDECREF(tmp);
6394 return 1;
6398 obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena)
6400 PyObject* tmp = NULL;
6401 asdl_seq* args;
6402 identifier vararg;
6403 identifier kwarg;
6404 asdl_seq* defaults;
6406 if (PyObject_HasAttrString(obj, "args")) {
6407 int res;
6408 Py_ssize_t len;
6409 Py_ssize_t i;
6410 tmp = PyObject_GetAttrString(obj, "args");
6411 if (tmp == NULL) goto failed;
6412 if (!PyList_Check(tmp)) {
6413 PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name);
6414 goto failed;
6416 len = PyList_GET_SIZE(tmp);
6417 args = asdl_seq_new(len, arena);
6418 if (args == NULL) goto failed;
6419 for (i = 0; i < len; i++) {
6420 expr_ty value;
6421 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
6422 if (res != 0) goto failed;
6423 asdl_seq_SET(args, i, value);
6425 Py_XDECREF(tmp);
6426 tmp = NULL;
6427 } else {
6428 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments");
6429 return 1;
6431 if (PyObject_HasAttrString(obj, "vararg")) {
6432 int res;
6433 tmp = PyObject_GetAttrString(obj, "vararg");
6434 if (tmp == NULL) goto failed;
6435 res = obj2ast_identifier(tmp, &vararg, arena);
6436 if (res != 0) goto failed;
6437 Py_XDECREF(tmp);
6438 tmp = NULL;
6439 } else {
6440 vararg = NULL;
6442 if (PyObject_HasAttrString(obj, "kwarg")) {
6443 int res;
6444 tmp = PyObject_GetAttrString(obj, "kwarg");
6445 if (tmp == NULL) goto failed;
6446 res = obj2ast_identifier(tmp, &kwarg, arena);
6447 if (res != 0) goto failed;
6448 Py_XDECREF(tmp);
6449 tmp = NULL;
6450 } else {
6451 kwarg = NULL;
6453 if (PyObject_HasAttrString(obj, "defaults")) {
6454 int res;
6455 Py_ssize_t len;
6456 Py_ssize_t i;
6457 tmp = PyObject_GetAttrString(obj, "defaults");
6458 if (tmp == NULL) goto failed;
6459 if (!PyList_Check(tmp)) {
6460 PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name);
6461 goto failed;
6463 len = PyList_GET_SIZE(tmp);
6464 defaults = asdl_seq_new(len, arena);
6465 if (defaults == NULL) goto failed;
6466 for (i = 0; i < len; i++) {
6467 expr_ty value;
6468 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
6469 if (res != 0) goto failed;
6470 asdl_seq_SET(defaults, i, value);
6472 Py_XDECREF(tmp);
6473 tmp = NULL;
6474 } else {
6475 PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments");
6476 return 1;
6478 *out = arguments(args, vararg, kwarg, defaults, arena);
6479 return 0;
6480 failed:
6481 Py_XDECREF(tmp);
6482 return 1;
6486 obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena)
6488 PyObject* tmp = NULL;
6489 identifier arg;
6490 expr_ty value;
6492 if (PyObject_HasAttrString(obj, "arg")) {
6493 int res;
6494 tmp = PyObject_GetAttrString(obj, "arg");
6495 if (tmp == NULL) goto failed;
6496 res = obj2ast_identifier(tmp, &arg, arena);
6497 if (res != 0) goto failed;
6498 Py_XDECREF(tmp);
6499 tmp = NULL;
6500 } else {
6501 PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from keyword");
6502 return 1;
6504 if (PyObject_HasAttrString(obj, "value")) {
6505 int res;
6506 tmp = PyObject_GetAttrString(obj, "value");
6507 if (tmp == NULL) goto failed;
6508 res = obj2ast_expr(tmp, &value, arena);
6509 if (res != 0) goto failed;
6510 Py_XDECREF(tmp);
6511 tmp = NULL;
6512 } else {
6513 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword");
6514 return 1;
6516 *out = keyword(arg, value, arena);
6517 return 0;
6518 failed:
6519 Py_XDECREF(tmp);
6520 return 1;
6524 obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena)
6526 PyObject* tmp = NULL;
6527 identifier name;
6528 identifier asname;
6530 if (PyObject_HasAttrString(obj, "name")) {
6531 int res;
6532 tmp = PyObject_GetAttrString(obj, "name");
6533 if (tmp == NULL) goto failed;
6534 res = obj2ast_identifier(tmp, &name, arena);
6535 if (res != 0) goto failed;
6536 Py_XDECREF(tmp);
6537 tmp = NULL;
6538 } else {
6539 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias");
6540 return 1;
6542 if (PyObject_HasAttrString(obj, "asname")) {
6543 int res;
6544 tmp = PyObject_GetAttrString(obj, "asname");
6545 if (tmp == NULL) goto failed;
6546 res = obj2ast_identifier(tmp, &asname, arena);
6547 if (res != 0) goto failed;
6548 Py_XDECREF(tmp);
6549 tmp = NULL;
6550 } else {
6551 asname = NULL;
6553 *out = alias(name, asname, arena);
6554 return 0;
6555 failed:
6556 Py_XDECREF(tmp);
6557 return 1;
6561 PyMODINIT_FUNC
6562 init_ast(void)
6564 PyObject *m, *d;
6565 if (!init_types()) return;
6566 m = Py_InitModule3("_ast", NULL, NULL);
6567 if (!m) return;
6568 d = PyModule_GetDict(m);
6569 if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return;
6570 if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)
6571 return;
6572 if (PyModule_AddStringConstant(m, "__version__", "77422") < 0)
6573 return;
6574 if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return;
6575 if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0)
6576 return;
6577 if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type)
6578 < 0) return;
6579 if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) <
6580 0) return;
6581 if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return;
6582 if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return;
6583 if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type)
6584 < 0) return;
6585 if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0)
6586 return;
6587 if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0)
6588 return;
6589 if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0)
6590 return;
6591 if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0)
6592 return;
6593 if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) <
6594 0) return;
6595 if (PyDict_SetItemString(d, "Print", (PyObject*)Print_type) < 0) return;
6596 if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return;
6597 if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return;
6598 if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return;
6599 if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return;
6600 if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return;
6601 if (PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) <
6602 0) return;
6603 if (PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) <
6604 0) return;
6605 if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0)
6606 return;
6607 if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0)
6608 return;
6609 if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) <
6610 0) return;
6611 if (PyDict_SetItemString(d, "Exec", (PyObject*)Exec_type) < 0) return;
6612 if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0)
6613 return;
6614 if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return;
6615 if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return;
6616 if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return;
6617 if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0)
6618 return;
6619 if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return;
6620 if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0)
6621 return;
6622 if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return;
6623 if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0)
6624 return;
6625 if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0)
6626 return;
6627 if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return;
6628 if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return;
6629 if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return;
6630 if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0)
6631 return;
6632 if (PyDict_SetItemString(d, "SetComp", (PyObject*)SetComp_type) < 0)
6633 return;
6634 if (PyDict_SetItemString(d, "DictComp", (PyObject*)DictComp_type) < 0)
6635 return;
6636 if (PyDict_SetItemString(d, "GeneratorExp",
6637 (PyObject*)GeneratorExp_type) < 0) return;
6638 if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return;
6639 if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0)
6640 return;
6641 if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return;
6642 if (PyDict_SetItemString(d, "Repr", (PyObject*)Repr_type) < 0) return;
6643 if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return;
6644 if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return;
6645 if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) <
6646 0) return;
6647 if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) <
6648 0) return;
6649 if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return;
6650 if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return;
6651 if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return;
6652 if (PyDict_SetItemString(d, "expr_context",
6653 (PyObject*)expr_context_type) < 0) return;
6654 if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return;
6655 if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return;
6656 if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return;
6657 if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0)
6658 return;
6659 if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0)
6660 return;
6661 if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return;
6662 if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return;
6663 if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0)
6664 return;
6665 if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return;
6666 if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0)
6667 return;
6668 if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return;
6669 if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0)
6670 return;
6671 if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return;
6672 if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return;
6673 if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0)
6674 return;
6675 if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return;
6676 if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return;
6677 if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return;
6678 if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return;
6679 if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return;
6680 if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return;
6681 if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0)
6682 return;
6683 if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0)
6684 return;
6685 if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return;
6686 if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0)
6687 return;
6688 if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0)
6689 return;
6690 if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0)
6691 return;
6692 if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0)
6693 return;
6694 if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0)
6695 return;
6696 if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return;
6697 if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return;
6698 if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return;
6699 if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return;
6700 if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return;
6701 if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return;
6702 if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return;
6703 if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return;
6704 if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return;
6705 if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return;
6706 if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return;
6707 if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return;
6708 if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return;
6709 if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return;
6710 if (PyDict_SetItemString(d, "comprehension",
6711 (PyObject*)comprehension_type) < 0) return;
6712 if (PyDict_SetItemString(d, "excepthandler",
6713 (PyObject*)excepthandler_type) < 0) return;
6714 if (PyDict_SetItemString(d, "ExceptHandler",
6715 (PyObject*)ExceptHandler_type) < 0) return;
6716 if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) <
6717 0) return;
6718 if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0)
6719 return;
6720 if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return;
6724 PyObject* PyAST_mod2obj(mod_ty t)
6726 init_types();
6727 return ast2obj_mod(t);
6730 /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */
6731 mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode)
6733 mod_ty res;
6734 PyObject *req_type[] = {(PyObject*)Module_type, (PyObject*)Expression_type,
6735 (PyObject*)Interactive_type};
6736 char *req_name[] = {"Module", "Expression", "Interactive"};
6737 int isinstance;
6738 assert(0 <= mode && mode <= 2);
6740 init_types();
6742 isinstance = PyObject_IsInstance(ast, req_type[mode]);
6743 if (isinstance == -1)
6744 return NULL;
6745 if (!isinstance) {
6746 PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s",
6747 req_name[mode], Py_TYPE(ast)->tp_name);
6748 return NULL;
6750 if (obj2ast_mod(ast, &res, arena) != 0)
6751 return NULL;
6752 else
6753 return res;
6756 int PyAST_Check(PyObject* obj)
6758 init_types();
6759 return PyObject_IsInstance(obj, (PyObject*)&AST_type);