1 /* File automatically generated by Parser/asdl_c.py. */
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.
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
[]={
22 static PyTypeObject
*Interactive_type
;
23 static char *Interactive_fields
[]={
26 static PyTypeObject
*Expression_type
;
27 static char *Expression_fields
[]={
30 static PyTypeObject
*Suite_type
;
31 static char *Suite_fields
[]={
34 static PyTypeObject
*stmt_type
;
35 static char *stmt_attributes
[] = {
39 static PyObject
* ast2obj_stmt(void*);
40 static PyTypeObject
*FunctionDef_type
;
41 static char *FunctionDef_fields
[]={
47 static PyTypeObject
*ClassDef_type
;
48 static char *ClassDef_fields
[]={
54 static PyTypeObject
*Return_type
;
55 static char *Return_fields
[]={
58 static PyTypeObject
*Delete_type
;
59 static char *Delete_fields
[]={
62 static PyTypeObject
*Assign_type
;
63 static char *Assign_fields
[]={
67 static PyTypeObject
*AugAssign_type
;
68 static char *AugAssign_fields
[]={
73 static PyTypeObject
*Print_type
;
74 static char *Print_fields
[]={
79 static PyTypeObject
*For_type
;
80 static char *For_fields
[]={
86 static PyTypeObject
*While_type
;
87 static char *While_fields
[]={
92 static PyTypeObject
*If_type
;
93 static char *If_fields
[]={
98 static PyTypeObject
*With_type
;
99 static char *With_fields
[]={
104 static PyTypeObject
*Raise_type
;
105 static char *Raise_fields
[]={
110 static PyTypeObject
*TryExcept_type
;
111 static char *TryExcept_fields
[]={
116 static PyTypeObject
*TryFinally_type
;
117 static char *TryFinally_fields
[]={
121 static PyTypeObject
*Assert_type
;
122 static char *Assert_fields
[]={
126 static PyTypeObject
*Import_type
;
127 static char *Import_fields
[]={
130 static PyTypeObject
*ImportFrom_type
;
131 static char *ImportFrom_fields
[]={
136 static PyTypeObject
*Exec_type
;
137 static char *Exec_fields
[]={
142 static PyTypeObject
*Global_type
;
143 static char *Global_fields
[]={
146 static PyTypeObject
*Expr_type
;
147 static char *Expr_fields
[]={
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
[] = {
158 static PyObject
* ast2obj_expr(void*);
159 static PyTypeObject
*BoolOp_type
;
160 static char *BoolOp_fields
[]={
164 static PyTypeObject
*BinOp_type
;
165 static char *BinOp_fields
[]={
170 static PyTypeObject
*UnaryOp_type
;
171 static char *UnaryOp_fields
[]={
175 static PyTypeObject
*Lambda_type
;
176 static char *Lambda_fields
[]={
180 static PyTypeObject
*IfExp_type
;
181 static char *IfExp_fields
[]={
186 static PyTypeObject
*Dict_type
;
187 static char *Dict_fields
[]={
191 static PyTypeObject
*ListComp_type
;
192 static char *ListComp_fields
[]={
196 static PyTypeObject
*GeneratorExp_type
;
197 static char *GeneratorExp_fields
[]={
201 static PyTypeObject
*Yield_type
;
202 static char *Yield_fields
[]={
205 static PyTypeObject
*Compare_type
;
206 static char *Compare_fields
[]={
211 static PyTypeObject
*Call_type
;
212 static char *Call_fields
[]={
219 static PyTypeObject
*Repr_type
;
220 static char *Repr_fields
[]={
223 static PyTypeObject
*Num_type
;
224 static char *Num_fields
[]={
227 static PyTypeObject
*Str_type
;
228 static char *Str_fields
[]={
231 static PyTypeObject
*Attribute_type
;
232 static char *Attribute_fields
[]={
237 static PyTypeObject
*Subscript_type
;
238 static char *Subscript_fields
[]={
243 static PyTypeObject
*Name_type
;
244 static char *Name_fields
[]={
248 static PyTypeObject
*List_type
;
249 static char *List_fields
[]={
253 static PyTypeObject
*Tuple_type
;
254 static char *Tuple_fields
[]={
258 static PyTypeObject
*expr_context_type
;
259 static PyObject
*Load_singleton
, *Store_singleton
, *Del_singleton
,
260 *AugLoad_singleton
, *AugStore_singleton
, *Param_singleton
;
261 static PyObject
* ast2obj_expr_context(expr_context_ty
);
262 static PyTypeObject
*Load_type
;
263 static PyTypeObject
*Store_type
;
264 static PyTypeObject
*Del_type
;
265 static PyTypeObject
*AugLoad_type
;
266 static PyTypeObject
*AugStore_type
;
267 static PyTypeObject
*Param_type
;
268 static PyTypeObject
*slice_type
;
269 static PyObject
* ast2obj_slice(void*);
270 static PyTypeObject
*Ellipsis_type
;
271 static PyTypeObject
*Slice_type
;
272 static char *Slice_fields
[]={
277 static PyTypeObject
*ExtSlice_type
;
278 static char *ExtSlice_fields
[]={
281 static PyTypeObject
*Index_type
;
282 static char *Index_fields
[]={
285 static PyTypeObject
*boolop_type
;
286 static PyObject
*And_singleton
, *Or_singleton
;
287 static PyObject
* ast2obj_boolop(boolop_ty
);
288 static PyTypeObject
*And_type
;
289 static PyTypeObject
*Or_type
;
290 static PyTypeObject
*operator_type
;
291 static PyObject
*Add_singleton
, *Sub_singleton
, *Mult_singleton
,
292 *Div_singleton
, *Mod_singleton
, *Pow_singleton
, *LShift_singleton
,
293 *RShift_singleton
, *BitOr_singleton
, *BitXor_singleton
, *BitAnd_singleton
,
295 static PyObject
* ast2obj_operator(operator_ty
);
296 static PyTypeObject
*Add_type
;
297 static PyTypeObject
*Sub_type
;
298 static PyTypeObject
*Mult_type
;
299 static PyTypeObject
*Div_type
;
300 static PyTypeObject
*Mod_type
;
301 static PyTypeObject
*Pow_type
;
302 static PyTypeObject
*LShift_type
;
303 static PyTypeObject
*RShift_type
;
304 static PyTypeObject
*BitOr_type
;
305 static PyTypeObject
*BitXor_type
;
306 static PyTypeObject
*BitAnd_type
;
307 static PyTypeObject
*FloorDiv_type
;
308 static PyTypeObject
*unaryop_type
;
309 static PyObject
*Invert_singleton
, *Not_singleton
, *UAdd_singleton
,
311 static PyObject
* ast2obj_unaryop(unaryop_ty
);
312 static PyTypeObject
*Invert_type
;
313 static PyTypeObject
*Not_type
;
314 static PyTypeObject
*UAdd_type
;
315 static PyTypeObject
*USub_type
;
316 static PyTypeObject
*cmpop_type
;
317 static PyObject
*Eq_singleton
, *NotEq_singleton
, *Lt_singleton
, *LtE_singleton
,
318 *Gt_singleton
, *GtE_singleton
, *Is_singleton
, *IsNot_singleton
, *In_singleton
,
320 static PyObject
* ast2obj_cmpop(cmpop_ty
);
321 static PyTypeObject
*Eq_type
;
322 static PyTypeObject
*NotEq_type
;
323 static PyTypeObject
*Lt_type
;
324 static PyTypeObject
*LtE_type
;
325 static PyTypeObject
*Gt_type
;
326 static PyTypeObject
*GtE_type
;
327 static PyTypeObject
*Is_type
;
328 static PyTypeObject
*IsNot_type
;
329 static PyTypeObject
*In_type
;
330 static PyTypeObject
*NotIn_type
;
331 static PyTypeObject
*comprehension_type
;
332 static PyObject
* ast2obj_comprehension(void*);
333 static char *comprehension_fields
[]={
338 static PyTypeObject
*excepthandler_type
;
339 static char *excepthandler_attributes
[] = {
343 static PyObject
* ast2obj_excepthandler(void*);
344 static PyTypeObject
*ExceptHandler_type
;
345 static char *ExceptHandler_fields
[]={
350 static PyTypeObject
*arguments_type
;
351 static PyObject
* ast2obj_arguments(void*);
352 static char *arguments_fields
[]={
358 static PyTypeObject
*keyword_type
;
359 static PyObject
* ast2obj_keyword(void*);
360 static char *keyword_fields
[]={
364 static PyTypeObject
*alias_type
;
365 static PyObject
* ast2obj_alias(void*);
366 static char *alias_fields
[]={
373 ast_type_init(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
375 Py_ssize_t i
, numfields
= 0;
377 PyObject
*key
, *value
, *fields
;
378 fields
= PyObject_GetAttrString((PyObject
*)Py_TYPE(self
), "_fields");
382 numfields
= PySequence_Size(fields
);
386 res
= 0; /* if no error occurs, this stays 0 to the end */
387 if (PyTuple_GET_SIZE(args
) > 0) {
388 if (numfields
!= PyTuple_GET_SIZE(args
)) {
389 PyErr_Format(PyExc_TypeError
, "%.400s constructor takes %s"
390 "%" PY_FORMAT_SIZE_T
"d positional argument%s",
391 Py_TYPE(self
)->tp_name
,
392 numfields
== 0 ? "" : "either 0 or ",
393 numfields
, numfields
== 1 ? "" : "s");
397 for (i
= 0; i
< PyTuple_GET_SIZE(args
); i
++) {
398 /* cannot be reached when fields is NULL */
399 PyObject
*name
= PySequence_GetItem(fields
, i
);
404 res
= PyObject_SetAttr(self
, name
, PyTuple_GET_ITEM(args
, i
));
411 i
= 0; /* needed by PyDict_Next */
412 while (PyDict_Next(kw
, &i
, &key
, &value
)) {
413 res
= PyObject_SetAttr(self
, key
, value
);
423 /* Pickling support */
425 ast_type_reduce(PyObject
*self
, PyObject
*unused
)
428 PyObject
*dict
= PyObject_GetAttrString(self
, "__dict__");
430 if (PyErr_ExceptionMatches(PyExc_AttributeError
))
436 res
= Py_BuildValue("O()O", Py_TYPE(self
), dict
);
440 return Py_BuildValue("O()", Py_TYPE(self
));
443 static PyMethodDef ast_type_methods
[] = {
444 {"__reduce__", ast_type_reduce
, METH_NOARGS
, NULL
},
448 static PyTypeObject AST_type
= {
449 PyVarObject_HEAD_INIT(&PyType_Type
, 0)
459 0, /* tp_as_number */
460 0, /* tp_as_sequence */
461 0, /* tp_as_mapping */
465 PyObject_GenericGetAttr
, /* tp_getattro */
466 PyObject_GenericSetAttr
, /* tp_setattro */
467 0, /* tp_as_buffer */
468 Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_BASETYPE
, /* tp_flags */
472 0, /* tp_richcompare */
473 0, /* tp_weaklistoffset */
476 ast_type_methods
, /* tp_methods */
481 0, /* tp_descr_get */
482 0, /* tp_descr_set */
483 0, /* tp_dictoffset */
484 (initproc
)ast_type_init
, /* tp_init */
485 PyType_GenericAlloc
, /* tp_alloc */
486 PyType_GenericNew
, /* tp_new */
487 PyObject_Del
, /* tp_free */
491 static PyTypeObject
* make_type(char *type
, PyTypeObject
* base
, char**fields
, int num_fields
)
493 PyObject
*fnames
, *result
;
495 fnames
= PyTuple_New(num_fields
);
496 if (!fnames
) return NULL
;
497 for (i
= 0; i
< num_fields
; i
++) {
498 PyObject
*field
= PyString_FromString(fields
[i
]);
503 PyTuple_SET_ITEM(fnames
, i
, field
);
505 result
= PyObject_CallFunction((PyObject
*)&PyType_Type
, "s(O){sOss}",
506 type
, base
, "_fields", fnames
, "__module__", "_ast");
508 return (PyTypeObject
*)result
;
511 static int add_attributes(PyTypeObject
* type
, char**attrs
, int num_fields
)
514 PyObject
*s
, *l
= PyTuple_New(num_fields
);
516 for(i
= 0; i
< num_fields
; i
++) {
517 s
= PyString_FromString(attrs
[i
]);
522 PyTuple_SET_ITEM(l
, i
, s
);
524 result
= PyObject_SetAttrString((PyObject
*)type
, "_attributes", l
) >= 0;
529 /* Conversion AST -> Python */
531 static PyObject
* ast2obj_list(asdl_seq
*seq
, PyObject
* (*func
)(void*))
533 int i
, n
= asdl_seq_LEN(seq
);
534 PyObject
*result
= PyList_New(n
);
538 for (i
= 0; i
< n
; i
++) {
539 value
= func(asdl_seq_GET(seq
, i
));
544 PyList_SET_ITEM(result
, i
, value
);
549 static PyObject
* ast2obj_object(void *o
)
553 Py_INCREF((PyObject
*)o
);
556 #define ast2obj_identifier ast2obj_object
557 #define ast2obj_string ast2obj_object
558 static PyObject
* ast2obj_bool(bool b
)
560 return PyBool_FromLong(b
);
563 static PyObject
* ast2obj_int(long b
)
565 return PyInt_FromLong(b
);
568 /* Conversion Python -> AST */
570 static int obj2ast_object(PyObject
* obj
, PyObject
** out
, PyArena
* arena
)
575 PyArena_AddPyObject(arena
, obj
);
581 #define obj2ast_identifier obj2ast_object
582 #define obj2ast_string obj2ast_object
584 static int obj2ast_int(PyObject
* obj
, int* out
, PyArena
* arena
)
587 if (!PyInt_Check(obj
) && !PyLong_Check(obj
)) {
588 PyObject
*s
= PyObject_Repr(obj
);
589 if (s
== NULL
) return 1;
590 PyErr_Format(PyExc_ValueError
, "invalid integer value: %.400s",
591 PyString_AS_STRING(s
));
596 i
= (int)PyLong_AsLong(obj
);
597 if (i
== -1 && PyErr_Occurred())
603 static int obj2ast_bool(PyObject
* obj
, bool* out
, PyArena
* arena
)
605 if (!PyBool_Check(obj
)) {
606 PyObject
*s
= PyObject_Repr(obj
);
607 if (s
== NULL
) return 1;
608 PyErr_Format(PyExc_ValueError
, "invalid boolean value: %.400s",
609 PyString_AS_STRING(s
));
614 *out
= (obj
== Py_True
);
619 static int init_types(void)
621 static int initialized
;
622 if (initialized
) return 1;
623 mod_type
= make_type("mod", &AST_type
, NULL
, 0);
624 if (!mod_type
) return 0;
625 if (!add_attributes(mod_type
, NULL
, 0)) return 0;
626 Module_type
= make_type("Module", mod_type
, Module_fields
, 1);
627 if (!Module_type
) return 0;
628 Interactive_type
= make_type("Interactive", mod_type
,
629 Interactive_fields
, 1);
630 if (!Interactive_type
) return 0;
631 Expression_type
= make_type("Expression", mod_type
, Expression_fields
,
633 if (!Expression_type
) return 0;
634 Suite_type
= make_type("Suite", mod_type
, Suite_fields
, 1);
635 if (!Suite_type
) return 0;
636 stmt_type
= make_type("stmt", &AST_type
, NULL
, 0);
637 if (!stmt_type
) return 0;
638 if (!add_attributes(stmt_type
, stmt_attributes
, 2)) return 0;
639 FunctionDef_type
= make_type("FunctionDef", stmt_type
,
640 FunctionDef_fields
, 4);
641 if (!FunctionDef_type
) return 0;
642 ClassDef_type
= make_type("ClassDef", stmt_type
, ClassDef_fields
, 4);
643 if (!ClassDef_type
) return 0;
644 Return_type
= make_type("Return", stmt_type
, Return_fields
, 1);
645 if (!Return_type
) return 0;
646 Delete_type
= make_type("Delete", stmt_type
, Delete_fields
, 1);
647 if (!Delete_type
) return 0;
648 Assign_type
= make_type("Assign", stmt_type
, Assign_fields
, 2);
649 if (!Assign_type
) return 0;
650 AugAssign_type
= make_type("AugAssign", stmt_type
, AugAssign_fields
, 3);
651 if (!AugAssign_type
) return 0;
652 Print_type
= make_type("Print", stmt_type
, Print_fields
, 3);
653 if (!Print_type
) return 0;
654 For_type
= make_type("For", stmt_type
, For_fields
, 4);
655 if (!For_type
) return 0;
656 While_type
= make_type("While", stmt_type
, While_fields
, 3);
657 if (!While_type
) return 0;
658 If_type
= make_type("If", stmt_type
, If_fields
, 3);
659 if (!If_type
) return 0;
660 With_type
= make_type("With", stmt_type
, With_fields
, 3);
661 if (!With_type
) return 0;
662 Raise_type
= make_type("Raise", stmt_type
, Raise_fields
, 3);
663 if (!Raise_type
) return 0;
664 TryExcept_type
= make_type("TryExcept", stmt_type
, TryExcept_fields
, 3);
665 if (!TryExcept_type
) return 0;
666 TryFinally_type
= make_type("TryFinally", stmt_type
, TryFinally_fields
,
668 if (!TryFinally_type
) return 0;
669 Assert_type
= make_type("Assert", stmt_type
, Assert_fields
, 2);
670 if (!Assert_type
) return 0;
671 Import_type
= make_type("Import", stmt_type
, Import_fields
, 1);
672 if (!Import_type
) return 0;
673 ImportFrom_type
= make_type("ImportFrom", stmt_type
, ImportFrom_fields
,
675 if (!ImportFrom_type
) return 0;
676 Exec_type
= make_type("Exec", stmt_type
, Exec_fields
, 3);
677 if (!Exec_type
) return 0;
678 Global_type
= make_type("Global", stmt_type
, Global_fields
, 1);
679 if (!Global_type
) return 0;
680 Expr_type
= make_type("Expr", stmt_type
, Expr_fields
, 1);
681 if (!Expr_type
) return 0;
682 Pass_type
= make_type("Pass", stmt_type
, NULL
, 0);
683 if (!Pass_type
) return 0;
684 Break_type
= make_type("Break", stmt_type
, NULL
, 0);
685 if (!Break_type
) return 0;
686 Continue_type
= make_type("Continue", stmt_type
, NULL
, 0);
687 if (!Continue_type
) return 0;
688 expr_type
= make_type("expr", &AST_type
, NULL
, 0);
689 if (!expr_type
) return 0;
690 if (!add_attributes(expr_type
, expr_attributes
, 2)) return 0;
691 BoolOp_type
= make_type("BoolOp", expr_type
, BoolOp_fields
, 2);
692 if (!BoolOp_type
) return 0;
693 BinOp_type
= make_type("BinOp", expr_type
, BinOp_fields
, 3);
694 if (!BinOp_type
) return 0;
695 UnaryOp_type
= make_type("UnaryOp", expr_type
, UnaryOp_fields
, 2);
696 if (!UnaryOp_type
) return 0;
697 Lambda_type
= make_type("Lambda", expr_type
, Lambda_fields
, 2);
698 if (!Lambda_type
) return 0;
699 IfExp_type
= make_type("IfExp", expr_type
, IfExp_fields
, 3);
700 if (!IfExp_type
) return 0;
701 Dict_type
= make_type("Dict", expr_type
, Dict_fields
, 2);
702 if (!Dict_type
) return 0;
703 ListComp_type
= make_type("ListComp", expr_type
, ListComp_fields
, 2);
704 if (!ListComp_type
) return 0;
705 GeneratorExp_type
= make_type("GeneratorExp", expr_type
,
706 GeneratorExp_fields
, 2);
707 if (!GeneratorExp_type
) return 0;
708 Yield_type
= make_type("Yield", expr_type
, Yield_fields
, 1);
709 if (!Yield_type
) return 0;
710 Compare_type
= make_type("Compare", expr_type
, Compare_fields
, 3);
711 if (!Compare_type
) return 0;
712 Call_type
= make_type("Call", expr_type
, Call_fields
, 5);
713 if (!Call_type
) return 0;
714 Repr_type
= make_type("Repr", expr_type
, Repr_fields
, 1);
715 if (!Repr_type
) return 0;
716 Num_type
= make_type("Num", expr_type
, Num_fields
, 1);
717 if (!Num_type
) return 0;
718 Str_type
= make_type("Str", expr_type
, Str_fields
, 1);
719 if (!Str_type
) return 0;
720 Attribute_type
= make_type("Attribute", expr_type
, Attribute_fields
, 3);
721 if (!Attribute_type
) return 0;
722 Subscript_type
= make_type("Subscript", expr_type
, Subscript_fields
, 3);
723 if (!Subscript_type
) return 0;
724 Name_type
= make_type("Name", expr_type
, Name_fields
, 2);
725 if (!Name_type
) return 0;
726 List_type
= make_type("List", expr_type
, List_fields
, 2);
727 if (!List_type
) return 0;
728 Tuple_type
= make_type("Tuple", expr_type
, Tuple_fields
, 2);
729 if (!Tuple_type
) return 0;
730 expr_context_type
= make_type("expr_context", &AST_type
, NULL
, 0);
731 if (!expr_context_type
) return 0;
732 if (!add_attributes(expr_context_type
, NULL
, 0)) return 0;
733 Load_type
= make_type("Load", expr_context_type
, NULL
, 0);
734 if (!Load_type
) return 0;
735 Load_singleton
= PyType_GenericNew(Load_type
, NULL
, NULL
);
736 if (!Load_singleton
) return 0;
737 Store_type
= make_type("Store", expr_context_type
, NULL
, 0);
738 if (!Store_type
) return 0;
739 Store_singleton
= PyType_GenericNew(Store_type
, NULL
, NULL
);
740 if (!Store_singleton
) return 0;
741 Del_type
= make_type("Del", expr_context_type
, NULL
, 0);
742 if (!Del_type
) return 0;
743 Del_singleton
= PyType_GenericNew(Del_type
, NULL
, NULL
);
744 if (!Del_singleton
) return 0;
745 AugLoad_type
= make_type("AugLoad", expr_context_type
, NULL
, 0);
746 if (!AugLoad_type
) return 0;
747 AugLoad_singleton
= PyType_GenericNew(AugLoad_type
, NULL
, NULL
);
748 if (!AugLoad_singleton
) return 0;
749 AugStore_type
= make_type("AugStore", expr_context_type
, NULL
, 0);
750 if (!AugStore_type
) return 0;
751 AugStore_singleton
= PyType_GenericNew(AugStore_type
, NULL
, NULL
);
752 if (!AugStore_singleton
) return 0;
753 Param_type
= make_type("Param", expr_context_type
, NULL
, 0);
754 if (!Param_type
) return 0;
755 Param_singleton
= PyType_GenericNew(Param_type
, NULL
, NULL
);
756 if (!Param_singleton
) return 0;
757 slice_type
= make_type("slice", &AST_type
, NULL
, 0);
758 if (!slice_type
) return 0;
759 if (!add_attributes(slice_type
, NULL
, 0)) return 0;
760 Ellipsis_type
= make_type("Ellipsis", slice_type
, NULL
, 0);
761 if (!Ellipsis_type
) return 0;
762 Slice_type
= make_type("Slice", slice_type
, Slice_fields
, 3);
763 if (!Slice_type
) return 0;
764 ExtSlice_type
= make_type("ExtSlice", slice_type
, ExtSlice_fields
, 1);
765 if (!ExtSlice_type
) return 0;
766 Index_type
= make_type("Index", slice_type
, Index_fields
, 1);
767 if (!Index_type
) return 0;
768 boolop_type
= make_type("boolop", &AST_type
, NULL
, 0);
769 if (!boolop_type
) return 0;
770 if (!add_attributes(boolop_type
, NULL
, 0)) return 0;
771 And_type
= make_type("And", boolop_type
, NULL
, 0);
772 if (!And_type
) return 0;
773 And_singleton
= PyType_GenericNew(And_type
, NULL
, NULL
);
774 if (!And_singleton
) return 0;
775 Or_type
= make_type("Or", boolop_type
, NULL
, 0);
776 if (!Or_type
) return 0;
777 Or_singleton
= PyType_GenericNew(Or_type
, NULL
, NULL
);
778 if (!Or_singleton
) return 0;
779 operator_type
= make_type("operator", &AST_type
, NULL
, 0);
780 if (!operator_type
) return 0;
781 if (!add_attributes(operator_type
, NULL
, 0)) return 0;
782 Add_type
= make_type("Add", operator_type
, NULL
, 0);
783 if (!Add_type
) return 0;
784 Add_singleton
= PyType_GenericNew(Add_type
, NULL
, NULL
);
785 if (!Add_singleton
) return 0;
786 Sub_type
= make_type("Sub", operator_type
, NULL
, 0);
787 if (!Sub_type
) return 0;
788 Sub_singleton
= PyType_GenericNew(Sub_type
, NULL
, NULL
);
789 if (!Sub_singleton
) return 0;
790 Mult_type
= make_type("Mult", operator_type
, NULL
, 0);
791 if (!Mult_type
) return 0;
792 Mult_singleton
= PyType_GenericNew(Mult_type
, NULL
, NULL
);
793 if (!Mult_singleton
) return 0;
794 Div_type
= make_type("Div", operator_type
, NULL
, 0);
795 if (!Div_type
) return 0;
796 Div_singleton
= PyType_GenericNew(Div_type
, NULL
, NULL
);
797 if (!Div_singleton
) return 0;
798 Mod_type
= make_type("Mod", operator_type
, NULL
, 0);
799 if (!Mod_type
) return 0;
800 Mod_singleton
= PyType_GenericNew(Mod_type
, NULL
, NULL
);
801 if (!Mod_singleton
) return 0;
802 Pow_type
= make_type("Pow", operator_type
, NULL
, 0);
803 if (!Pow_type
) return 0;
804 Pow_singleton
= PyType_GenericNew(Pow_type
, NULL
, NULL
);
805 if (!Pow_singleton
) return 0;
806 LShift_type
= make_type("LShift", operator_type
, NULL
, 0);
807 if (!LShift_type
) return 0;
808 LShift_singleton
= PyType_GenericNew(LShift_type
, NULL
, NULL
);
809 if (!LShift_singleton
) return 0;
810 RShift_type
= make_type("RShift", operator_type
, NULL
, 0);
811 if (!RShift_type
) return 0;
812 RShift_singleton
= PyType_GenericNew(RShift_type
, NULL
, NULL
);
813 if (!RShift_singleton
) return 0;
814 BitOr_type
= make_type("BitOr", operator_type
, NULL
, 0);
815 if (!BitOr_type
) return 0;
816 BitOr_singleton
= PyType_GenericNew(BitOr_type
, NULL
, NULL
);
817 if (!BitOr_singleton
) return 0;
818 BitXor_type
= make_type("BitXor", operator_type
, NULL
, 0);
819 if (!BitXor_type
) return 0;
820 BitXor_singleton
= PyType_GenericNew(BitXor_type
, NULL
, NULL
);
821 if (!BitXor_singleton
) return 0;
822 BitAnd_type
= make_type("BitAnd", operator_type
, NULL
, 0);
823 if (!BitAnd_type
) return 0;
824 BitAnd_singleton
= PyType_GenericNew(BitAnd_type
, NULL
, NULL
);
825 if (!BitAnd_singleton
) return 0;
826 FloorDiv_type
= make_type("FloorDiv", operator_type
, NULL
, 0);
827 if (!FloorDiv_type
) return 0;
828 FloorDiv_singleton
= PyType_GenericNew(FloorDiv_type
, NULL
, NULL
);
829 if (!FloorDiv_singleton
) return 0;
830 unaryop_type
= make_type("unaryop", &AST_type
, NULL
, 0);
831 if (!unaryop_type
) return 0;
832 if (!add_attributes(unaryop_type
, NULL
, 0)) return 0;
833 Invert_type
= make_type("Invert", unaryop_type
, NULL
, 0);
834 if (!Invert_type
) return 0;
835 Invert_singleton
= PyType_GenericNew(Invert_type
, NULL
, NULL
);
836 if (!Invert_singleton
) return 0;
837 Not_type
= make_type("Not", unaryop_type
, NULL
, 0);
838 if (!Not_type
) return 0;
839 Not_singleton
= PyType_GenericNew(Not_type
, NULL
, NULL
);
840 if (!Not_singleton
) return 0;
841 UAdd_type
= make_type("UAdd", unaryop_type
, NULL
, 0);
842 if (!UAdd_type
) return 0;
843 UAdd_singleton
= PyType_GenericNew(UAdd_type
, NULL
, NULL
);
844 if (!UAdd_singleton
) return 0;
845 USub_type
= make_type("USub", unaryop_type
, NULL
, 0);
846 if (!USub_type
) return 0;
847 USub_singleton
= PyType_GenericNew(USub_type
, NULL
, NULL
);
848 if (!USub_singleton
) return 0;
849 cmpop_type
= make_type("cmpop", &AST_type
, NULL
, 0);
850 if (!cmpop_type
) return 0;
851 if (!add_attributes(cmpop_type
, NULL
, 0)) return 0;
852 Eq_type
= make_type("Eq", cmpop_type
, NULL
, 0);
853 if (!Eq_type
) return 0;
854 Eq_singleton
= PyType_GenericNew(Eq_type
, NULL
, NULL
);
855 if (!Eq_singleton
) return 0;
856 NotEq_type
= make_type("NotEq", cmpop_type
, NULL
, 0);
857 if (!NotEq_type
) return 0;
858 NotEq_singleton
= PyType_GenericNew(NotEq_type
, NULL
, NULL
);
859 if (!NotEq_singleton
) return 0;
860 Lt_type
= make_type("Lt", cmpop_type
, NULL
, 0);
861 if (!Lt_type
) return 0;
862 Lt_singleton
= PyType_GenericNew(Lt_type
, NULL
, NULL
);
863 if (!Lt_singleton
) return 0;
864 LtE_type
= make_type("LtE", cmpop_type
, NULL
, 0);
865 if (!LtE_type
) return 0;
866 LtE_singleton
= PyType_GenericNew(LtE_type
, NULL
, NULL
);
867 if (!LtE_singleton
) return 0;
868 Gt_type
= make_type("Gt", cmpop_type
, NULL
, 0);
869 if (!Gt_type
) return 0;
870 Gt_singleton
= PyType_GenericNew(Gt_type
, NULL
, NULL
);
871 if (!Gt_singleton
) return 0;
872 GtE_type
= make_type("GtE", cmpop_type
, NULL
, 0);
873 if (!GtE_type
) return 0;
874 GtE_singleton
= PyType_GenericNew(GtE_type
, NULL
, NULL
);
875 if (!GtE_singleton
) return 0;
876 Is_type
= make_type("Is", cmpop_type
, NULL
, 0);
877 if (!Is_type
) return 0;
878 Is_singleton
= PyType_GenericNew(Is_type
, NULL
, NULL
);
879 if (!Is_singleton
) return 0;
880 IsNot_type
= make_type("IsNot", cmpop_type
, NULL
, 0);
881 if (!IsNot_type
) return 0;
882 IsNot_singleton
= PyType_GenericNew(IsNot_type
, NULL
, NULL
);
883 if (!IsNot_singleton
) return 0;
884 In_type
= make_type("In", cmpop_type
, NULL
, 0);
885 if (!In_type
) return 0;
886 In_singleton
= PyType_GenericNew(In_type
, NULL
, NULL
);
887 if (!In_singleton
) return 0;
888 NotIn_type
= make_type("NotIn", cmpop_type
, NULL
, 0);
889 if (!NotIn_type
) return 0;
890 NotIn_singleton
= PyType_GenericNew(NotIn_type
, NULL
, NULL
);
891 if (!NotIn_singleton
) return 0;
892 comprehension_type
= make_type("comprehension", &AST_type
,
893 comprehension_fields
, 3);
894 if (!comprehension_type
) return 0;
895 excepthandler_type
= make_type("excepthandler", &AST_type
, NULL
, 0);
896 if (!excepthandler_type
) return 0;
897 if (!add_attributes(excepthandler_type
, excepthandler_attributes
, 2))
899 ExceptHandler_type
= make_type("ExceptHandler", excepthandler_type
,
900 ExceptHandler_fields
, 3);
901 if (!ExceptHandler_type
) return 0;
902 arguments_type
= make_type("arguments", &AST_type
, arguments_fields
, 4);
903 if (!arguments_type
) return 0;
904 keyword_type
= make_type("keyword", &AST_type
, keyword_fields
, 2);
905 if (!keyword_type
) return 0;
906 alias_type
= make_type("alias", &AST_type
, alias_fields
, 2);
907 if (!alias_type
) return 0;
912 static int obj2ast_mod(PyObject
* obj
, mod_ty
* out
, PyArena
* arena
);
913 static int obj2ast_stmt(PyObject
* obj
, stmt_ty
* out
, PyArena
* arena
);
914 static int obj2ast_expr(PyObject
* obj
, expr_ty
* out
, PyArena
* arena
);
915 static int obj2ast_expr_context(PyObject
* obj
, expr_context_ty
* out
, PyArena
*
917 static int obj2ast_slice(PyObject
* obj
, slice_ty
* out
, PyArena
* arena
);
918 static int obj2ast_boolop(PyObject
* obj
, boolop_ty
* out
, PyArena
* arena
);
919 static int obj2ast_operator(PyObject
* obj
, operator_ty
* out
, PyArena
* arena
);
920 static int obj2ast_unaryop(PyObject
* obj
, unaryop_ty
* out
, PyArena
* arena
);
921 static int obj2ast_cmpop(PyObject
* obj
, cmpop_ty
* out
, PyArena
* arena
);
922 static int obj2ast_comprehension(PyObject
* obj
, comprehension_ty
* out
, PyArena
*
924 static int obj2ast_excepthandler(PyObject
* obj
, excepthandler_ty
* out
, PyArena
*
926 static int obj2ast_arguments(PyObject
* obj
, arguments_ty
* out
, PyArena
* arena
);
927 static int obj2ast_keyword(PyObject
* obj
, keyword_ty
* out
, PyArena
* arena
);
928 static int obj2ast_alias(PyObject
* obj
, alias_ty
* out
, PyArena
* arena
);
931 Module(asdl_seq
* body
, PyArena
*arena
)
934 p
= (mod_ty
)PyArena_Malloc(arena
, sizeof(*p
));
937 p
->kind
= Module_kind
;
938 p
->v
.Module
.body
= body
;
943 Interactive(asdl_seq
* body
, PyArena
*arena
)
946 p
= (mod_ty
)PyArena_Malloc(arena
, sizeof(*p
));
949 p
->kind
= Interactive_kind
;
950 p
->v
.Interactive
.body
= body
;
955 Expression(expr_ty body
, PyArena
*arena
)
959 PyErr_SetString(PyExc_ValueError
,
960 "field body is required for Expression");
963 p
= (mod_ty
)PyArena_Malloc(arena
, sizeof(*p
));
966 p
->kind
= Expression_kind
;
967 p
->v
.Expression
.body
= body
;
972 Suite(asdl_seq
* body
, PyArena
*arena
)
975 p
= (mod_ty
)PyArena_Malloc(arena
, sizeof(*p
));
978 p
->kind
= Suite_kind
;
979 p
->v
.Suite
.body
= body
;
984 FunctionDef(identifier name
, arguments_ty args
, asdl_seq
* body
, asdl_seq
*
985 decorator_list
, int lineno
, int col_offset
, PyArena
*arena
)
989 PyErr_SetString(PyExc_ValueError
,
990 "field name is required for FunctionDef");
994 PyErr_SetString(PyExc_ValueError
,
995 "field args is required for FunctionDef");
998 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1001 p
->kind
= FunctionDef_kind
;
1002 p
->v
.FunctionDef
.name
= name
;
1003 p
->v
.FunctionDef
.args
= args
;
1004 p
->v
.FunctionDef
.body
= body
;
1005 p
->v
.FunctionDef
.decorator_list
= decorator_list
;
1007 p
->col_offset
= col_offset
;
1012 ClassDef(identifier name
, asdl_seq
* bases
, asdl_seq
* body
, asdl_seq
*
1013 decorator_list
, int lineno
, int col_offset
, PyArena
*arena
)
1017 PyErr_SetString(PyExc_ValueError
,
1018 "field name is required for ClassDef");
1021 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1024 p
->kind
= ClassDef_kind
;
1025 p
->v
.ClassDef
.name
= name
;
1026 p
->v
.ClassDef
.bases
= bases
;
1027 p
->v
.ClassDef
.body
= body
;
1028 p
->v
.ClassDef
.decorator_list
= decorator_list
;
1030 p
->col_offset
= col_offset
;
1035 Return(expr_ty value
, int lineno
, int col_offset
, PyArena
*arena
)
1038 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1041 p
->kind
= Return_kind
;
1042 p
->v
.Return
.value
= value
;
1044 p
->col_offset
= col_offset
;
1049 Delete(asdl_seq
* targets
, int lineno
, int col_offset
, PyArena
*arena
)
1052 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1055 p
->kind
= Delete_kind
;
1056 p
->v
.Delete
.targets
= targets
;
1058 p
->col_offset
= col_offset
;
1063 Assign(asdl_seq
* targets
, expr_ty value
, int lineno
, int col_offset
, PyArena
1068 PyErr_SetString(PyExc_ValueError
,
1069 "field value is required for Assign");
1072 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1075 p
->kind
= Assign_kind
;
1076 p
->v
.Assign
.targets
= targets
;
1077 p
->v
.Assign
.value
= value
;
1079 p
->col_offset
= col_offset
;
1084 AugAssign(expr_ty target
, operator_ty op
, expr_ty value
, int lineno
, int
1085 col_offset
, PyArena
*arena
)
1089 PyErr_SetString(PyExc_ValueError
,
1090 "field target is required for AugAssign");
1094 PyErr_SetString(PyExc_ValueError
,
1095 "field op is required for AugAssign");
1099 PyErr_SetString(PyExc_ValueError
,
1100 "field value is required for AugAssign");
1103 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1106 p
->kind
= AugAssign_kind
;
1107 p
->v
.AugAssign
.target
= target
;
1108 p
->v
.AugAssign
.op
= op
;
1109 p
->v
.AugAssign
.value
= value
;
1111 p
->col_offset
= col_offset
;
1116 Print(expr_ty dest
, asdl_seq
* values
, bool nl
, int lineno
, int col_offset
,
1120 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1123 p
->kind
= Print_kind
;
1124 p
->v
.Print
.dest
= dest
;
1125 p
->v
.Print
.values
= values
;
1128 p
->col_offset
= col_offset
;
1133 For(expr_ty target
, expr_ty iter
, asdl_seq
* body
, asdl_seq
* orelse
, int
1134 lineno
, int col_offset
, PyArena
*arena
)
1138 PyErr_SetString(PyExc_ValueError
,
1139 "field target is required for For");
1143 PyErr_SetString(PyExc_ValueError
,
1144 "field iter is required for For");
1147 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1151 p
->v
.For
.target
= target
;
1152 p
->v
.For
.iter
= iter
;
1153 p
->v
.For
.body
= body
;
1154 p
->v
.For
.orelse
= orelse
;
1156 p
->col_offset
= col_offset
;
1161 While(expr_ty test
, asdl_seq
* body
, asdl_seq
* orelse
, int lineno
, int
1162 col_offset
, PyArena
*arena
)
1166 PyErr_SetString(PyExc_ValueError
,
1167 "field test is required for While");
1170 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1173 p
->kind
= While_kind
;
1174 p
->v
.While
.test
= test
;
1175 p
->v
.While
.body
= body
;
1176 p
->v
.While
.orelse
= orelse
;
1178 p
->col_offset
= col_offset
;
1183 If(expr_ty test
, asdl_seq
* body
, asdl_seq
* orelse
, int lineno
, int
1184 col_offset
, PyArena
*arena
)
1188 PyErr_SetString(PyExc_ValueError
,
1189 "field test is required for If");
1192 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1196 p
->v
.If
.test
= test
;
1197 p
->v
.If
.body
= body
;
1198 p
->v
.If
.orelse
= orelse
;
1200 p
->col_offset
= col_offset
;
1205 With(expr_ty context_expr
, expr_ty optional_vars
, asdl_seq
* body
, int lineno
,
1206 int col_offset
, PyArena
*arena
)
1209 if (!context_expr
) {
1210 PyErr_SetString(PyExc_ValueError
,
1211 "field context_expr is required for With");
1214 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1217 p
->kind
= With_kind
;
1218 p
->v
.With
.context_expr
= context_expr
;
1219 p
->v
.With
.optional_vars
= optional_vars
;
1220 p
->v
.With
.body
= body
;
1222 p
->col_offset
= col_offset
;
1227 Raise(expr_ty type
, expr_ty inst
, expr_ty tback
, int lineno
, int col_offset
,
1231 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1234 p
->kind
= Raise_kind
;
1235 p
->v
.Raise
.type
= type
;
1236 p
->v
.Raise
.inst
= inst
;
1237 p
->v
.Raise
.tback
= tback
;
1239 p
->col_offset
= col_offset
;
1244 TryExcept(asdl_seq
* body
, asdl_seq
* handlers
, asdl_seq
* orelse
, int lineno
,
1245 int col_offset
, PyArena
*arena
)
1248 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1251 p
->kind
= TryExcept_kind
;
1252 p
->v
.TryExcept
.body
= body
;
1253 p
->v
.TryExcept
.handlers
= handlers
;
1254 p
->v
.TryExcept
.orelse
= orelse
;
1256 p
->col_offset
= col_offset
;
1261 TryFinally(asdl_seq
* body
, asdl_seq
* finalbody
, int lineno
, int col_offset
,
1265 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1268 p
->kind
= TryFinally_kind
;
1269 p
->v
.TryFinally
.body
= body
;
1270 p
->v
.TryFinally
.finalbody
= finalbody
;
1272 p
->col_offset
= col_offset
;
1277 Assert(expr_ty test
, expr_ty msg
, int lineno
, int col_offset
, PyArena
*arena
)
1281 PyErr_SetString(PyExc_ValueError
,
1282 "field test is required for Assert");
1285 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1288 p
->kind
= Assert_kind
;
1289 p
->v
.Assert
.test
= test
;
1290 p
->v
.Assert
.msg
= msg
;
1292 p
->col_offset
= col_offset
;
1297 Import(asdl_seq
* names
, int lineno
, int col_offset
, PyArena
*arena
)
1300 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1303 p
->kind
= Import_kind
;
1304 p
->v
.Import
.names
= names
;
1306 p
->col_offset
= col_offset
;
1311 ImportFrom(identifier module
, asdl_seq
* names
, int level
, int lineno
, int
1312 col_offset
, PyArena
*arena
)
1316 PyErr_SetString(PyExc_ValueError
,
1317 "field module is required for ImportFrom");
1320 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1323 p
->kind
= ImportFrom_kind
;
1324 p
->v
.ImportFrom
.module
= module
;
1325 p
->v
.ImportFrom
.names
= names
;
1326 p
->v
.ImportFrom
.level
= level
;
1328 p
->col_offset
= col_offset
;
1333 Exec(expr_ty body
, expr_ty globals
, expr_ty locals
, int lineno
, int col_offset
,
1338 PyErr_SetString(PyExc_ValueError
,
1339 "field body is required for Exec");
1342 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1345 p
->kind
= Exec_kind
;
1346 p
->v
.Exec
.body
= body
;
1347 p
->v
.Exec
.globals
= globals
;
1348 p
->v
.Exec
.locals
= locals
;
1350 p
->col_offset
= col_offset
;
1355 Global(asdl_seq
* names
, int lineno
, int col_offset
, PyArena
*arena
)
1358 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1361 p
->kind
= Global_kind
;
1362 p
->v
.Global
.names
= names
;
1364 p
->col_offset
= col_offset
;
1369 Expr(expr_ty value
, int lineno
, int col_offset
, PyArena
*arena
)
1373 PyErr_SetString(PyExc_ValueError
,
1374 "field value is required for Expr");
1377 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1380 p
->kind
= Expr_kind
;
1381 p
->v
.Expr
.value
= value
;
1383 p
->col_offset
= col_offset
;
1388 Pass(int lineno
, int col_offset
, PyArena
*arena
)
1391 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1394 p
->kind
= Pass_kind
;
1396 p
->col_offset
= col_offset
;
1401 Break(int lineno
, int col_offset
, PyArena
*arena
)
1404 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1407 p
->kind
= Break_kind
;
1409 p
->col_offset
= col_offset
;
1414 Continue(int lineno
, int col_offset
, PyArena
*arena
)
1417 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1420 p
->kind
= Continue_kind
;
1422 p
->col_offset
= col_offset
;
1427 BoolOp(boolop_ty op
, asdl_seq
* values
, int lineno
, int col_offset
, PyArena
1432 PyErr_SetString(PyExc_ValueError
,
1433 "field op is required for BoolOp");
1436 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1439 p
->kind
= BoolOp_kind
;
1440 p
->v
.BoolOp
.op
= op
;
1441 p
->v
.BoolOp
.values
= values
;
1443 p
->col_offset
= col_offset
;
1448 BinOp(expr_ty left
, operator_ty op
, expr_ty right
, int lineno
, int col_offset
,
1453 PyErr_SetString(PyExc_ValueError
,
1454 "field left is required for BinOp");
1458 PyErr_SetString(PyExc_ValueError
,
1459 "field op is required for BinOp");
1463 PyErr_SetString(PyExc_ValueError
,
1464 "field right is required for BinOp");
1467 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1470 p
->kind
= BinOp_kind
;
1471 p
->v
.BinOp
.left
= left
;
1473 p
->v
.BinOp
.right
= right
;
1475 p
->col_offset
= col_offset
;
1480 UnaryOp(unaryop_ty op
, expr_ty operand
, int lineno
, int col_offset
, PyArena
1485 PyErr_SetString(PyExc_ValueError
,
1486 "field op is required for UnaryOp");
1490 PyErr_SetString(PyExc_ValueError
,
1491 "field operand is required for UnaryOp");
1494 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1497 p
->kind
= UnaryOp_kind
;
1498 p
->v
.UnaryOp
.op
= op
;
1499 p
->v
.UnaryOp
.operand
= operand
;
1501 p
->col_offset
= col_offset
;
1506 Lambda(arguments_ty args
, expr_ty body
, int lineno
, int col_offset
, PyArena
1511 PyErr_SetString(PyExc_ValueError
,
1512 "field args is required for Lambda");
1516 PyErr_SetString(PyExc_ValueError
,
1517 "field body is required for Lambda");
1520 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1523 p
->kind
= Lambda_kind
;
1524 p
->v
.Lambda
.args
= args
;
1525 p
->v
.Lambda
.body
= body
;
1527 p
->col_offset
= col_offset
;
1532 IfExp(expr_ty test
, expr_ty body
, expr_ty orelse
, int lineno
, int col_offset
,
1537 PyErr_SetString(PyExc_ValueError
,
1538 "field test is required for IfExp");
1542 PyErr_SetString(PyExc_ValueError
,
1543 "field body is required for IfExp");
1547 PyErr_SetString(PyExc_ValueError
,
1548 "field orelse is required for IfExp");
1551 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1554 p
->kind
= IfExp_kind
;
1555 p
->v
.IfExp
.test
= test
;
1556 p
->v
.IfExp
.body
= body
;
1557 p
->v
.IfExp
.orelse
= orelse
;
1559 p
->col_offset
= col_offset
;
1564 Dict(asdl_seq
* keys
, asdl_seq
* values
, int lineno
, int col_offset
, PyArena
1568 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1571 p
->kind
= Dict_kind
;
1572 p
->v
.Dict
.keys
= keys
;
1573 p
->v
.Dict
.values
= values
;
1575 p
->col_offset
= col_offset
;
1580 ListComp(expr_ty elt
, asdl_seq
* generators
, int lineno
, int col_offset
,
1585 PyErr_SetString(PyExc_ValueError
,
1586 "field elt is required for ListComp");
1589 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1592 p
->kind
= ListComp_kind
;
1593 p
->v
.ListComp
.elt
= elt
;
1594 p
->v
.ListComp
.generators
= generators
;
1596 p
->col_offset
= col_offset
;
1601 GeneratorExp(expr_ty elt
, asdl_seq
* generators
, int lineno
, int col_offset
,
1606 PyErr_SetString(PyExc_ValueError
,
1607 "field elt is required for GeneratorExp");
1610 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1613 p
->kind
= GeneratorExp_kind
;
1614 p
->v
.GeneratorExp
.elt
= elt
;
1615 p
->v
.GeneratorExp
.generators
= generators
;
1617 p
->col_offset
= col_offset
;
1622 Yield(expr_ty value
, int lineno
, int col_offset
, PyArena
*arena
)
1625 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1628 p
->kind
= Yield_kind
;
1629 p
->v
.Yield
.value
= value
;
1631 p
->col_offset
= col_offset
;
1636 Compare(expr_ty left
, asdl_int_seq
* ops
, asdl_seq
* comparators
, int lineno
,
1637 int col_offset
, PyArena
*arena
)
1641 PyErr_SetString(PyExc_ValueError
,
1642 "field left is required for Compare");
1645 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1648 p
->kind
= Compare_kind
;
1649 p
->v
.Compare
.left
= left
;
1650 p
->v
.Compare
.ops
= ops
;
1651 p
->v
.Compare
.comparators
= comparators
;
1653 p
->col_offset
= col_offset
;
1658 Call(expr_ty func
, asdl_seq
* args
, asdl_seq
* keywords
, expr_ty starargs
,
1659 expr_ty kwargs
, int lineno
, int col_offset
, PyArena
*arena
)
1663 PyErr_SetString(PyExc_ValueError
,
1664 "field func is required for Call");
1667 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1670 p
->kind
= Call_kind
;
1671 p
->v
.Call
.func
= func
;
1672 p
->v
.Call
.args
= args
;
1673 p
->v
.Call
.keywords
= keywords
;
1674 p
->v
.Call
.starargs
= starargs
;
1675 p
->v
.Call
.kwargs
= kwargs
;
1677 p
->col_offset
= col_offset
;
1682 Repr(expr_ty value
, int lineno
, int col_offset
, PyArena
*arena
)
1686 PyErr_SetString(PyExc_ValueError
,
1687 "field value is required for Repr");
1690 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1693 p
->kind
= Repr_kind
;
1694 p
->v
.Repr
.value
= value
;
1696 p
->col_offset
= col_offset
;
1701 Num(object n
, int lineno
, int col_offset
, PyArena
*arena
)
1705 PyErr_SetString(PyExc_ValueError
,
1706 "field n is required for Num");
1709 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1715 p
->col_offset
= col_offset
;
1720 Str(string s
, int lineno
, int col_offset
, PyArena
*arena
)
1724 PyErr_SetString(PyExc_ValueError
,
1725 "field s is required for Str");
1728 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1734 p
->col_offset
= col_offset
;
1739 Attribute(expr_ty value
, identifier attr
, expr_context_ty ctx
, int lineno
, int
1740 col_offset
, PyArena
*arena
)
1744 PyErr_SetString(PyExc_ValueError
,
1745 "field value is required for Attribute");
1749 PyErr_SetString(PyExc_ValueError
,
1750 "field attr is required for Attribute");
1754 PyErr_SetString(PyExc_ValueError
,
1755 "field ctx is required for Attribute");
1758 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1761 p
->kind
= Attribute_kind
;
1762 p
->v
.Attribute
.value
= value
;
1763 p
->v
.Attribute
.attr
= attr
;
1764 p
->v
.Attribute
.ctx
= ctx
;
1766 p
->col_offset
= col_offset
;
1771 Subscript(expr_ty value
, slice_ty slice
, expr_context_ty ctx
, int lineno
, int
1772 col_offset
, PyArena
*arena
)
1776 PyErr_SetString(PyExc_ValueError
,
1777 "field value is required for Subscript");
1781 PyErr_SetString(PyExc_ValueError
,
1782 "field slice is required for Subscript");
1786 PyErr_SetString(PyExc_ValueError
,
1787 "field ctx is required for Subscript");
1790 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1793 p
->kind
= Subscript_kind
;
1794 p
->v
.Subscript
.value
= value
;
1795 p
->v
.Subscript
.slice
= slice
;
1796 p
->v
.Subscript
.ctx
= ctx
;
1798 p
->col_offset
= col_offset
;
1803 Name(identifier id
, expr_context_ty ctx
, int lineno
, int col_offset
, PyArena
1808 PyErr_SetString(PyExc_ValueError
,
1809 "field id is required for Name");
1813 PyErr_SetString(PyExc_ValueError
,
1814 "field ctx is required for Name");
1817 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1820 p
->kind
= Name_kind
;
1822 p
->v
.Name
.ctx
= ctx
;
1824 p
->col_offset
= col_offset
;
1829 List(asdl_seq
* elts
, expr_context_ty ctx
, int lineno
, int col_offset
, PyArena
1834 PyErr_SetString(PyExc_ValueError
,
1835 "field ctx is required for List");
1838 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1841 p
->kind
= List_kind
;
1842 p
->v
.List
.elts
= elts
;
1843 p
->v
.List
.ctx
= ctx
;
1845 p
->col_offset
= col_offset
;
1850 Tuple(asdl_seq
* elts
, expr_context_ty ctx
, int lineno
, int col_offset
, PyArena
1855 PyErr_SetString(PyExc_ValueError
,
1856 "field ctx is required for Tuple");
1859 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1862 p
->kind
= Tuple_kind
;
1863 p
->v
.Tuple
.elts
= elts
;
1864 p
->v
.Tuple
.ctx
= ctx
;
1866 p
->col_offset
= col_offset
;
1871 Ellipsis(PyArena
*arena
)
1874 p
= (slice_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1877 p
->kind
= Ellipsis_kind
;
1882 Slice(expr_ty lower
, expr_ty upper
, expr_ty step
, PyArena
*arena
)
1885 p
= (slice_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1888 p
->kind
= Slice_kind
;
1889 p
->v
.Slice
.lower
= lower
;
1890 p
->v
.Slice
.upper
= upper
;
1891 p
->v
.Slice
.step
= step
;
1896 ExtSlice(asdl_seq
* dims
, PyArena
*arena
)
1899 p
= (slice_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1902 p
->kind
= ExtSlice_kind
;
1903 p
->v
.ExtSlice
.dims
= dims
;
1908 Index(expr_ty value
, PyArena
*arena
)
1912 PyErr_SetString(PyExc_ValueError
,
1913 "field value is required for Index");
1916 p
= (slice_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1919 p
->kind
= Index_kind
;
1920 p
->v
.Index
.value
= value
;
1925 comprehension(expr_ty target
, expr_ty iter
, asdl_seq
* ifs
, PyArena
*arena
)
1929 PyErr_SetString(PyExc_ValueError
,
1930 "field target is required for comprehension");
1934 PyErr_SetString(PyExc_ValueError
,
1935 "field iter is required for comprehension");
1938 p
= (comprehension_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1948 ExceptHandler(expr_ty type
, expr_ty name
, asdl_seq
* body
, int lineno
, int
1949 col_offset
, PyArena
*arena
)
1952 p
= (excepthandler_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1955 p
->kind
= ExceptHandler_kind
;
1956 p
->v
.ExceptHandler
.type
= type
;
1957 p
->v
.ExceptHandler
.name
= name
;
1958 p
->v
.ExceptHandler
.body
= body
;
1960 p
->col_offset
= col_offset
;
1965 arguments(asdl_seq
* args
, identifier vararg
, identifier kwarg
, asdl_seq
*
1966 defaults
, PyArena
*arena
)
1969 p
= (arguments_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1975 p
->defaults
= defaults
;
1980 keyword(identifier arg
, expr_ty value
, PyArena
*arena
)
1984 PyErr_SetString(PyExc_ValueError
,
1985 "field arg is required for keyword");
1989 PyErr_SetString(PyExc_ValueError
,
1990 "field value is required for keyword");
1993 p
= (keyword_ty
)PyArena_Malloc(arena
, sizeof(*p
));
2002 alias(identifier name
, identifier asname
, PyArena
*arena
)
2006 PyErr_SetString(PyExc_ValueError
,
2007 "field name is required for alias");
2010 p
= (alias_ty
)PyArena_Malloc(arena
, sizeof(*p
));
2020 ast2obj_mod(void* _o
)
2022 mod_ty o
= (mod_ty
)_o
;
2023 PyObject
*result
= NULL
, *value
= NULL
;
2031 result
= PyType_GenericNew(Module_type
, NULL
, NULL
);
2032 if (!result
) goto failed
;
2033 value
= ast2obj_list(o
->v
.Module
.body
, ast2obj_stmt
);
2034 if (!value
) goto failed
;
2035 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2039 case Interactive_kind
:
2040 result
= PyType_GenericNew(Interactive_type
, NULL
, NULL
);
2041 if (!result
) goto failed
;
2042 value
= ast2obj_list(o
->v
.Interactive
.body
, ast2obj_stmt
);
2043 if (!value
) goto failed
;
2044 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2048 case Expression_kind
:
2049 result
= PyType_GenericNew(Expression_type
, NULL
, NULL
);
2050 if (!result
) goto failed
;
2051 value
= ast2obj_expr(o
->v
.Expression
.body
);
2052 if (!value
) goto failed
;
2053 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2058 result
= PyType_GenericNew(Suite_type
, NULL
, NULL
);
2059 if (!result
) goto failed
;
2060 value
= ast2obj_list(o
->v
.Suite
.body
, ast2obj_stmt
);
2061 if (!value
) goto failed
;
2062 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2075 ast2obj_stmt(void* _o
)
2077 stmt_ty o
= (stmt_ty
)_o
;
2078 PyObject
*result
= NULL
, *value
= NULL
;
2085 case FunctionDef_kind
:
2086 result
= PyType_GenericNew(FunctionDef_type
, NULL
, NULL
);
2087 if (!result
) goto failed
;
2088 value
= ast2obj_identifier(o
->v
.FunctionDef
.name
);
2089 if (!value
) goto failed
;
2090 if (PyObject_SetAttrString(result
, "name", value
) == -1)
2093 value
= ast2obj_arguments(o
->v
.FunctionDef
.args
);
2094 if (!value
) goto failed
;
2095 if (PyObject_SetAttrString(result
, "args", value
) == -1)
2098 value
= ast2obj_list(o
->v
.FunctionDef
.body
, ast2obj_stmt
);
2099 if (!value
) goto failed
;
2100 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2103 value
= ast2obj_list(o
->v
.FunctionDef
.decorator_list
,
2105 if (!value
) goto failed
;
2106 if (PyObject_SetAttrString(result
, "decorator_list", value
) ==
2112 result
= PyType_GenericNew(ClassDef_type
, NULL
, NULL
);
2113 if (!result
) goto failed
;
2114 value
= ast2obj_identifier(o
->v
.ClassDef
.name
);
2115 if (!value
) goto failed
;
2116 if (PyObject_SetAttrString(result
, "name", value
) == -1)
2119 value
= ast2obj_list(o
->v
.ClassDef
.bases
, ast2obj_expr
);
2120 if (!value
) goto failed
;
2121 if (PyObject_SetAttrString(result
, "bases", value
) == -1)
2124 value
= ast2obj_list(o
->v
.ClassDef
.body
, ast2obj_stmt
);
2125 if (!value
) goto failed
;
2126 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2129 value
= ast2obj_list(o
->v
.ClassDef
.decorator_list
,
2131 if (!value
) goto failed
;
2132 if (PyObject_SetAttrString(result
, "decorator_list", value
) ==
2138 result
= PyType_GenericNew(Return_type
, NULL
, NULL
);
2139 if (!result
) goto failed
;
2140 value
= ast2obj_expr(o
->v
.Return
.value
);
2141 if (!value
) goto failed
;
2142 if (PyObject_SetAttrString(result
, "value", value
) == -1)
2147 result
= PyType_GenericNew(Delete_type
, NULL
, NULL
);
2148 if (!result
) goto failed
;
2149 value
= ast2obj_list(o
->v
.Delete
.targets
, ast2obj_expr
);
2150 if (!value
) goto failed
;
2151 if (PyObject_SetAttrString(result
, "targets", value
) == -1)
2156 result
= PyType_GenericNew(Assign_type
, NULL
, NULL
);
2157 if (!result
) goto failed
;
2158 value
= ast2obj_list(o
->v
.Assign
.targets
, ast2obj_expr
);
2159 if (!value
) goto failed
;
2160 if (PyObject_SetAttrString(result
, "targets", value
) == -1)
2163 value
= ast2obj_expr(o
->v
.Assign
.value
);
2164 if (!value
) goto failed
;
2165 if (PyObject_SetAttrString(result
, "value", value
) == -1)
2169 case AugAssign_kind
:
2170 result
= PyType_GenericNew(AugAssign_type
, NULL
, NULL
);
2171 if (!result
) goto failed
;
2172 value
= ast2obj_expr(o
->v
.AugAssign
.target
);
2173 if (!value
) goto failed
;
2174 if (PyObject_SetAttrString(result
, "target", value
) == -1)
2177 value
= ast2obj_operator(o
->v
.AugAssign
.op
);
2178 if (!value
) goto failed
;
2179 if (PyObject_SetAttrString(result
, "op", value
) == -1)
2182 value
= ast2obj_expr(o
->v
.AugAssign
.value
);
2183 if (!value
) goto failed
;
2184 if (PyObject_SetAttrString(result
, "value", value
) == -1)
2189 result
= PyType_GenericNew(Print_type
, NULL
, NULL
);
2190 if (!result
) goto failed
;
2191 value
= ast2obj_expr(o
->v
.Print
.dest
);
2192 if (!value
) goto failed
;
2193 if (PyObject_SetAttrString(result
, "dest", value
) == -1)
2196 value
= ast2obj_list(o
->v
.Print
.values
, ast2obj_expr
);
2197 if (!value
) goto failed
;
2198 if (PyObject_SetAttrString(result
, "values", value
) == -1)
2201 value
= ast2obj_bool(o
->v
.Print
.nl
);
2202 if (!value
) goto failed
;
2203 if (PyObject_SetAttrString(result
, "nl", value
) == -1)
2208 result
= PyType_GenericNew(For_type
, NULL
, NULL
);
2209 if (!result
) goto failed
;
2210 value
= ast2obj_expr(o
->v
.For
.target
);
2211 if (!value
) goto failed
;
2212 if (PyObject_SetAttrString(result
, "target", value
) == -1)
2215 value
= ast2obj_expr(o
->v
.For
.iter
);
2216 if (!value
) goto failed
;
2217 if (PyObject_SetAttrString(result
, "iter", value
) == -1)
2220 value
= ast2obj_list(o
->v
.For
.body
, ast2obj_stmt
);
2221 if (!value
) goto failed
;
2222 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2225 value
= ast2obj_list(o
->v
.For
.orelse
, ast2obj_stmt
);
2226 if (!value
) goto failed
;
2227 if (PyObject_SetAttrString(result
, "orelse", value
) == -1)
2232 result
= PyType_GenericNew(While_type
, NULL
, NULL
);
2233 if (!result
) goto failed
;
2234 value
= ast2obj_expr(o
->v
.While
.test
);
2235 if (!value
) goto failed
;
2236 if (PyObject_SetAttrString(result
, "test", value
) == -1)
2239 value
= ast2obj_list(o
->v
.While
.body
, ast2obj_stmt
);
2240 if (!value
) goto failed
;
2241 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2244 value
= ast2obj_list(o
->v
.While
.orelse
, ast2obj_stmt
);
2245 if (!value
) goto failed
;
2246 if (PyObject_SetAttrString(result
, "orelse", value
) == -1)
2251 result
= PyType_GenericNew(If_type
, NULL
, NULL
);
2252 if (!result
) goto failed
;
2253 value
= ast2obj_expr(o
->v
.If
.test
);
2254 if (!value
) goto failed
;
2255 if (PyObject_SetAttrString(result
, "test", value
) == -1)
2258 value
= ast2obj_list(o
->v
.If
.body
, ast2obj_stmt
);
2259 if (!value
) goto failed
;
2260 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2263 value
= ast2obj_list(o
->v
.If
.orelse
, ast2obj_stmt
);
2264 if (!value
) goto failed
;
2265 if (PyObject_SetAttrString(result
, "orelse", value
) == -1)
2270 result
= PyType_GenericNew(With_type
, NULL
, NULL
);
2271 if (!result
) goto failed
;
2272 value
= ast2obj_expr(o
->v
.With
.context_expr
);
2273 if (!value
) goto failed
;
2274 if (PyObject_SetAttrString(result
, "context_expr", value
) == -1)
2277 value
= ast2obj_expr(o
->v
.With
.optional_vars
);
2278 if (!value
) goto failed
;
2279 if (PyObject_SetAttrString(result
, "optional_vars", value
) ==
2283 value
= ast2obj_list(o
->v
.With
.body
, ast2obj_stmt
);
2284 if (!value
) goto failed
;
2285 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2290 result
= PyType_GenericNew(Raise_type
, NULL
, NULL
);
2291 if (!result
) goto failed
;
2292 value
= ast2obj_expr(o
->v
.Raise
.type
);
2293 if (!value
) goto failed
;
2294 if (PyObject_SetAttrString(result
, "type", value
) == -1)
2297 value
= ast2obj_expr(o
->v
.Raise
.inst
);
2298 if (!value
) goto failed
;
2299 if (PyObject_SetAttrString(result
, "inst", value
) == -1)
2302 value
= ast2obj_expr(o
->v
.Raise
.tback
);
2303 if (!value
) goto failed
;
2304 if (PyObject_SetAttrString(result
, "tback", value
) == -1)
2308 case TryExcept_kind
:
2309 result
= PyType_GenericNew(TryExcept_type
, NULL
, NULL
);
2310 if (!result
) goto failed
;
2311 value
= ast2obj_list(o
->v
.TryExcept
.body
, ast2obj_stmt
);
2312 if (!value
) goto failed
;
2313 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2316 value
= ast2obj_list(o
->v
.TryExcept
.handlers
,
2317 ast2obj_excepthandler
);
2318 if (!value
) goto failed
;
2319 if (PyObject_SetAttrString(result
, "handlers", value
) == -1)
2322 value
= ast2obj_list(o
->v
.TryExcept
.orelse
, ast2obj_stmt
);
2323 if (!value
) goto failed
;
2324 if (PyObject_SetAttrString(result
, "orelse", value
) == -1)
2328 case TryFinally_kind
:
2329 result
= PyType_GenericNew(TryFinally_type
, NULL
, NULL
);
2330 if (!result
) goto failed
;
2331 value
= ast2obj_list(o
->v
.TryFinally
.body
, ast2obj_stmt
);
2332 if (!value
) goto failed
;
2333 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2336 value
= ast2obj_list(o
->v
.TryFinally
.finalbody
, ast2obj_stmt
);
2337 if (!value
) goto failed
;
2338 if (PyObject_SetAttrString(result
, "finalbody", value
) == -1)
2343 result
= PyType_GenericNew(Assert_type
, NULL
, NULL
);
2344 if (!result
) goto failed
;
2345 value
= ast2obj_expr(o
->v
.Assert
.test
);
2346 if (!value
) goto failed
;
2347 if (PyObject_SetAttrString(result
, "test", value
) == -1)
2350 value
= ast2obj_expr(o
->v
.Assert
.msg
);
2351 if (!value
) goto failed
;
2352 if (PyObject_SetAttrString(result
, "msg", value
) == -1)
2357 result
= PyType_GenericNew(Import_type
, NULL
, NULL
);
2358 if (!result
) goto failed
;
2359 value
= ast2obj_list(o
->v
.Import
.names
, ast2obj_alias
);
2360 if (!value
) goto failed
;
2361 if (PyObject_SetAttrString(result
, "names", value
) == -1)
2365 case ImportFrom_kind
:
2366 result
= PyType_GenericNew(ImportFrom_type
, NULL
, NULL
);
2367 if (!result
) goto failed
;
2368 value
= ast2obj_identifier(o
->v
.ImportFrom
.module
);
2369 if (!value
) goto failed
;
2370 if (PyObject_SetAttrString(result
, "module", value
) == -1)
2373 value
= ast2obj_list(o
->v
.ImportFrom
.names
, ast2obj_alias
);
2374 if (!value
) goto failed
;
2375 if (PyObject_SetAttrString(result
, "names", value
) == -1)
2378 value
= ast2obj_int(o
->v
.ImportFrom
.level
);
2379 if (!value
) goto failed
;
2380 if (PyObject_SetAttrString(result
, "level", value
) == -1)
2385 result
= PyType_GenericNew(Exec_type
, NULL
, NULL
);
2386 if (!result
) goto failed
;
2387 value
= ast2obj_expr(o
->v
.Exec
.body
);
2388 if (!value
) goto failed
;
2389 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2392 value
= ast2obj_expr(o
->v
.Exec
.globals
);
2393 if (!value
) goto failed
;
2394 if (PyObject_SetAttrString(result
, "globals", value
) == -1)
2397 value
= ast2obj_expr(o
->v
.Exec
.locals
);
2398 if (!value
) goto failed
;
2399 if (PyObject_SetAttrString(result
, "locals", value
) == -1)
2404 result
= PyType_GenericNew(Global_type
, NULL
, NULL
);
2405 if (!result
) goto failed
;
2406 value
= ast2obj_list(o
->v
.Global
.names
, ast2obj_identifier
);
2407 if (!value
) goto failed
;
2408 if (PyObject_SetAttrString(result
, "names", value
) == -1)
2413 result
= PyType_GenericNew(Expr_type
, NULL
, NULL
);
2414 if (!result
) goto failed
;
2415 value
= ast2obj_expr(o
->v
.Expr
.value
);
2416 if (!value
) goto failed
;
2417 if (PyObject_SetAttrString(result
, "value", value
) == -1)
2422 result
= PyType_GenericNew(Pass_type
, NULL
, NULL
);
2423 if (!result
) goto failed
;
2426 result
= PyType_GenericNew(Break_type
, NULL
, NULL
);
2427 if (!result
) goto failed
;
2430 result
= PyType_GenericNew(Continue_type
, NULL
, NULL
);
2431 if (!result
) goto failed
;
2434 value
= ast2obj_int(o
->lineno
);
2435 if (!value
) goto failed
;
2436 if (PyObject_SetAttrString(result
, "lineno", value
) < 0)
2439 value
= ast2obj_int(o
->col_offset
);
2440 if (!value
) goto failed
;
2441 if (PyObject_SetAttrString(result
, "col_offset", value
) < 0)
2452 ast2obj_expr(void* _o
)
2454 expr_ty o
= (expr_ty
)_o
;
2455 PyObject
*result
= NULL
, *value
= NULL
;
2463 result
= PyType_GenericNew(BoolOp_type
, NULL
, NULL
);
2464 if (!result
) goto failed
;
2465 value
= ast2obj_boolop(o
->v
.BoolOp
.op
);
2466 if (!value
) goto failed
;
2467 if (PyObject_SetAttrString(result
, "op", value
) == -1)
2470 value
= ast2obj_list(o
->v
.BoolOp
.values
, ast2obj_expr
);
2471 if (!value
) goto failed
;
2472 if (PyObject_SetAttrString(result
, "values", value
) == -1)
2477 result
= PyType_GenericNew(BinOp_type
, NULL
, NULL
);
2478 if (!result
) goto failed
;
2479 value
= ast2obj_expr(o
->v
.BinOp
.left
);
2480 if (!value
) goto failed
;
2481 if (PyObject_SetAttrString(result
, "left", value
) == -1)
2484 value
= ast2obj_operator(o
->v
.BinOp
.op
);
2485 if (!value
) goto failed
;
2486 if (PyObject_SetAttrString(result
, "op", value
) == -1)
2489 value
= ast2obj_expr(o
->v
.BinOp
.right
);
2490 if (!value
) goto failed
;
2491 if (PyObject_SetAttrString(result
, "right", value
) == -1)
2496 result
= PyType_GenericNew(UnaryOp_type
, NULL
, NULL
);
2497 if (!result
) goto failed
;
2498 value
= ast2obj_unaryop(o
->v
.UnaryOp
.op
);
2499 if (!value
) goto failed
;
2500 if (PyObject_SetAttrString(result
, "op", value
) == -1)
2503 value
= ast2obj_expr(o
->v
.UnaryOp
.operand
);
2504 if (!value
) goto failed
;
2505 if (PyObject_SetAttrString(result
, "operand", value
) == -1)
2510 result
= PyType_GenericNew(Lambda_type
, NULL
, NULL
);
2511 if (!result
) goto failed
;
2512 value
= ast2obj_arguments(o
->v
.Lambda
.args
);
2513 if (!value
) goto failed
;
2514 if (PyObject_SetAttrString(result
, "args", value
) == -1)
2517 value
= ast2obj_expr(o
->v
.Lambda
.body
);
2518 if (!value
) goto failed
;
2519 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2524 result
= PyType_GenericNew(IfExp_type
, NULL
, NULL
);
2525 if (!result
) goto failed
;
2526 value
= ast2obj_expr(o
->v
.IfExp
.test
);
2527 if (!value
) goto failed
;
2528 if (PyObject_SetAttrString(result
, "test", value
) == -1)
2531 value
= ast2obj_expr(o
->v
.IfExp
.body
);
2532 if (!value
) goto failed
;
2533 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2536 value
= ast2obj_expr(o
->v
.IfExp
.orelse
);
2537 if (!value
) goto failed
;
2538 if (PyObject_SetAttrString(result
, "orelse", value
) == -1)
2543 result
= PyType_GenericNew(Dict_type
, NULL
, NULL
);
2544 if (!result
) goto failed
;
2545 value
= ast2obj_list(o
->v
.Dict
.keys
, ast2obj_expr
);
2546 if (!value
) goto failed
;
2547 if (PyObject_SetAttrString(result
, "keys", value
) == -1)
2550 value
= ast2obj_list(o
->v
.Dict
.values
, ast2obj_expr
);
2551 if (!value
) goto failed
;
2552 if (PyObject_SetAttrString(result
, "values", value
) == -1)
2557 result
= PyType_GenericNew(ListComp_type
, NULL
, NULL
);
2558 if (!result
) goto failed
;
2559 value
= ast2obj_expr(o
->v
.ListComp
.elt
);
2560 if (!value
) goto failed
;
2561 if (PyObject_SetAttrString(result
, "elt", value
) == -1)
2564 value
= ast2obj_list(o
->v
.ListComp
.generators
,
2565 ast2obj_comprehension
);
2566 if (!value
) goto failed
;
2567 if (PyObject_SetAttrString(result
, "generators", value
) == -1)
2571 case GeneratorExp_kind
:
2572 result
= PyType_GenericNew(GeneratorExp_type
, NULL
, NULL
);
2573 if (!result
) goto failed
;
2574 value
= ast2obj_expr(o
->v
.GeneratorExp
.elt
);
2575 if (!value
) goto failed
;
2576 if (PyObject_SetAttrString(result
, "elt", value
) == -1)
2579 value
= ast2obj_list(o
->v
.GeneratorExp
.generators
,
2580 ast2obj_comprehension
);
2581 if (!value
) goto failed
;
2582 if (PyObject_SetAttrString(result
, "generators", value
) == -1)
2587 result
= PyType_GenericNew(Yield_type
, NULL
, NULL
);
2588 if (!result
) goto failed
;
2589 value
= ast2obj_expr(o
->v
.Yield
.value
);
2590 if (!value
) goto failed
;
2591 if (PyObject_SetAttrString(result
, "value", value
) == -1)
2596 result
= PyType_GenericNew(Compare_type
, NULL
, NULL
);
2597 if (!result
) goto failed
;
2598 value
= ast2obj_expr(o
->v
.Compare
.left
);
2599 if (!value
) goto failed
;
2600 if (PyObject_SetAttrString(result
, "left", value
) == -1)
2604 int i
, n
= asdl_seq_LEN(o
->v
.Compare
.ops
);
2605 value
= PyList_New(n
);
2606 if (!value
) goto failed
;
2607 for(i
= 0; i
< n
; i
++)
2608 PyList_SET_ITEM(value
, i
, ast2obj_cmpop((cmpop_ty
)asdl_seq_GET(o
->v
.Compare
.ops
, i
)));
2610 if (!value
) goto failed
;
2611 if (PyObject_SetAttrString(result
, "ops", value
) == -1)
2614 value
= ast2obj_list(o
->v
.Compare
.comparators
, ast2obj_expr
);
2615 if (!value
) goto failed
;
2616 if (PyObject_SetAttrString(result
, "comparators", value
) == -1)
2621 result
= PyType_GenericNew(Call_type
, NULL
, NULL
);
2622 if (!result
) goto failed
;
2623 value
= ast2obj_expr(o
->v
.Call
.func
);
2624 if (!value
) goto failed
;
2625 if (PyObject_SetAttrString(result
, "func", value
) == -1)
2628 value
= ast2obj_list(o
->v
.Call
.args
, ast2obj_expr
);
2629 if (!value
) goto failed
;
2630 if (PyObject_SetAttrString(result
, "args", value
) == -1)
2633 value
= ast2obj_list(o
->v
.Call
.keywords
, ast2obj_keyword
);
2634 if (!value
) goto failed
;
2635 if (PyObject_SetAttrString(result
, "keywords", value
) == -1)
2638 value
= ast2obj_expr(o
->v
.Call
.starargs
);
2639 if (!value
) goto failed
;
2640 if (PyObject_SetAttrString(result
, "starargs", value
) == -1)
2643 value
= ast2obj_expr(o
->v
.Call
.kwargs
);
2644 if (!value
) goto failed
;
2645 if (PyObject_SetAttrString(result
, "kwargs", value
) == -1)
2650 result
= PyType_GenericNew(Repr_type
, NULL
, NULL
);
2651 if (!result
) goto failed
;
2652 value
= ast2obj_expr(o
->v
.Repr
.value
);
2653 if (!value
) goto failed
;
2654 if (PyObject_SetAttrString(result
, "value", value
) == -1)
2659 result
= PyType_GenericNew(Num_type
, NULL
, NULL
);
2660 if (!result
) goto failed
;
2661 value
= ast2obj_object(o
->v
.Num
.n
);
2662 if (!value
) goto failed
;
2663 if (PyObject_SetAttrString(result
, "n", value
) == -1)
2668 result
= PyType_GenericNew(Str_type
, NULL
, NULL
);
2669 if (!result
) goto failed
;
2670 value
= ast2obj_string(o
->v
.Str
.s
);
2671 if (!value
) goto failed
;
2672 if (PyObject_SetAttrString(result
, "s", value
) == -1)
2676 case Attribute_kind
:
2677 result
= PyType_GenericNew(Attribute_type
, NULL
, NULL
);
2678 if (!result
) goto failed
;
2679 value
= ast2obj_expr(o
->v
.Attribute
.value
);
2680 if (!value
) goto failed
;
2681 if (PyObject_SetAttrString(result
, "value", value
) == -1)
2684 value
= ast2obj_identifier(o
->v
.Attribute
.attr
);
2685 if (!value
) goto failed
;
2686 if (PyObject_SetAttrString(result
, "attr", value
) == -1)
2689 value
= ast2obj_expr_context(o
->v
.Attribute
.ctx
);
2690 if (!value
) goto failed
;
2691 if (PyObject_SetAttrString(result
, "ctx", value
) == -1)
2695 case Subscript_kind
:
2696 result
= PyType_GenericNew(Subscript_type
, NULL
, NULL
);
2697 if (!result
) goto failed
;
2698 value
= ast2obj_expr(o
->v
.Subscript
.value
);
2699 if (!value
) goto failed
;
2700 if (PyObject_SetAttrString(result
, "value", value
) == -1)
2703 value
= ast2obj_slice(o
->v
.Subscript
.slice
);
2704 if (!value
) goto failed
;
2705 if (PyObject_SetAttrString(result
, "slice", value
) == -1)
2708 value
= ast2obj_expr_context(o
->v
.Subscript
.ctx
);
2709 if (!value
) goto failed
;
2710 if (PyObject_SetAttrString(result
, "ctx", value
) == -1)
2715 result
= PyType_GenericNew(Name_type
, NULL
, NULL
);
2716 if (!result
) goto failed
;
2717 value
= ast2obj_identifier(o
->v
.Name
.id
);
2718 if (!value
) goto failed
;
2719 if (PyObject_SetAttrString(result
, "id", value
) == -1)
2722 value
= ast2obj_expr_context(o
->v
.Name
.ctx
);
2723 if (!value
) goto failed
;
2724 if (PyObject_SetAttrString(result
, "ctx", value
) == -1)
2729 result
= PyType_GenericNew(List_type
, NULL
, NULL
);
2730 if (!result
) goto failed
;
2731 value
= ast2obj_list(o
->v
.List
.elts
, ast2obj_expr
);
2732 if (!value
) goto failed
;
2733 if (PyObject_SetAttrString(result
, "elts", value
) == -1)
2736 value
= ast2obj_expr_context(o
->v
.List
.ctx
);
2737 if (!value
) goto failed
;
2738 if (PyObject_SetAttrString(result
, "ctx", value
) == -1)
2743 result
= PyType_GenericNew(Tuple_type
, NULL
, NULL
);
2744 if (!result
) goto failed
;
2745 value
= ast2obj_list(o
->v
.Tuple
.elts
, ast2obj_expr
);
2746 if (!value
) goto failed
;
2747 if (PyObject_SetAttrString(result
, "elts", value
) == -1)
2750 value
= ast2obj_expr_context(o
->v
.Tuple
.ctx
);
2751 if (!value
) goto failed
;
2752 if (PyObject_SetAttrString(result
, "ctx", value
) == -1)
2757 value
= ast2obj_int(o
->lineno
);
2758 if (!value
) goto failed
;
2759 if (PyObject_SetAttrString(result
, "lineno", value
) < 0)
2762 value
= ast2obj_int(o
->col_offset
);
2763 if (!value
) goto failed
;
2764 if (PyObject_SetAttrString(result
, "col_offset", value
) < 0)
2774 PyObject
* ast2obj_expr_context(expr_context_ty o
)
2778 Py_INCREF(Load_singleton
);
2779 return Load_singleton
;
2781 Py_INCREF(Store_singleton
);
2782 return Store_singleton
;
2784 Py_INCREF(Del_singleton
);
2785 return Del_singleton
;
2787 Py_INCREF(AugLoad_singleton
);
2788 return AugLoad_singleton
;
2790 Py_INCREF(AugStore_singleton
);
2791 return AugStore_singleton
;
2793 Py_INCREF(Param_singleton
);
2794 return Param_singleton
;
2796 /* should never happen, but just in case ... */
2797 PyErr_Format(PyExc_SystemError
, "unknown expr_context found");
2802 ast2obj_slice(void* _o
)
2804 slice_ty o
= (slice_ty
)_o
;
2805 PyObject
*result
= NULL
, *value
= NULL
;
2813 result
= PyType_GenericNew(Ellipsis_type
, NULL
, NULL
);
2814 if (!result
) goto failed
;
2817 result
= PyType_GenericNew(Slice_type
, NULL
, NULL
);
2818 if (!result
) goto failed
;
2819 value
= ast2obj_expr(o
->v
.Slice
.lower
);
2820 if (!value
) goto failed
;
2821 if (PyObject_SetAttrString(result
, "lower", value
) == -1)
2824 value
= ast2obj_expr(o
->v
.Slice
.upper
);
2825 if (!value
) goto failed
;
2826 if (PyObject_SetAttrString(result
, "upper", value
) == -1)
2829 value
= ast2obj_expr(o
->v
.Slice
.step
);
2830 if (!value
) goto failed
;
2831 if (PyObject_SetAttrString(result
, "step", value
) == -1)
2836 result
= PyType_GenericNew(ExtSlice_type
, NULL
, NULL
);
2837 if (!result
) goto failed
;
2838 value
= ast2obj_list(o
->v
.ExtSlice
.dims
, ast2obj_slice
);
2839 if (!value
) goto failed
;
2840 if (PyObject_SetAttrString(result
, "dims", value
) == -1)
2845 result
= PyType_GenericNew(Index_type
, NULL
, NULL
);
2846 if (!result
) goto failed
;
2847 value
= ast2obj_expr(o
->v
.Index
.value
);
2848 if (!value
) goto failed
;
2849 if (PyObject_SetAttrString(result
, "value", value
) == -1)
2861 PyObject
* ast2obj_boolop(boolop_ty o
)
2865 Py_INCREF(And_singleton
);
2866 return And_singleton
;
2868 Py_INCREF(Or_singleton
);
2869 return Or_singleton
;
2871 /* should never happen, but just in case ... */
2872 PyErr_Format(PyExc_SystemError
, "unknown boolop found");
2876 PyObject
* ast2obj_operator(operator_ty o
)
2880 Py_INCREF(Add_singleton
);
2881 return Add_singleton
;
2883 Py_INCREF(Sub_singleton
);
2884 return Sub_singleton
;
2886 Py_INCREF(Mult_singleton
);
2887 return Mult_singleton
;
2889 Py_INCREF(Div_singleton
);
2890 return Div_singleton
;
2892 Py_INCREF(Mod_singleton
);
2893 return Mod_singleton
;
2895 Py_INCREF(Pow_singleton
);
2896 return Pow_singleton
;
2898 Py_INCREF(LShift_singleton
);
2899 return LShift_singleton
;
2901 Py_INCREF(RShift_singleton
);
2902 return RShift_singleton
;
2904 Py_INCREF(BitOr_singleton
);
2905 return BitOr_singleton
;
2907 Py_INCREF(BitXor_singleton
);
2908 return BitXor_singleton
;
2910 Py_INCREF(BitAnd_singleton
);
2911 return BitAnd_singleton
;
2913 Py_INCREF(FloorDiv_singleton
);
2914 return FloorDiv_singleton
;
2916 /* should never happen, but just in case ... */
2917 PyErr_Format(PyExc_SystemError
, "unknown operator found");
2921 PyObject
* ast2obj_unaryop(unaryop_ty o
)
2925 Py_INCREF(Invert_singleton
);
2926 return Invert_singleton
;
2928 Py_INCREF(Not_singleton
);
2929 return Not_singleton
;
2931 Py_INCREF(UAdd_singleton
);
2932 return UAdd_singleton
;
2934 Py_INCREF(USub_singleton
);
2935 return USub_singleton
;
2937 /* should never happen, but just in case ... */
2938 PyErr_Format(PyExc_SystemError
, "unknown unaryop found");
2942 PyObject
* ast2obj_cmpop(cmpop_ty o
)
2946 Py_INCREF(Eq_singleton
);
2947 return Eq_singleton
;
2949 Py_INCREF(NotEq_singleton
);
2950 return NotEq_singleton
;
2952 Py_INCREF(Lt_singleton
);
2953 return Lt_singleton
;
2955 Py_INCREF(LtE_singleton
);
2956 return LtE_singleton
;
2958 Py_INCREF(Gt_singleton
);
2959 return Gt_singleton
;
2961 Py_INCREF(GtE_singleton
);
2962 return GtE_singleton
;
2964 Py_INCREF(Is_singleton
);
2965 return Is_singleton
;
2967 Py_INCREF(IsNot_singleton
);
2968 return IsNot_singleton
;
2970 Py_INCREF(In_singleton
);
2971 return In_singleton
;
2973 Py_INCREF(NotIn_singleton
);
2974 return NotIn_singleton
;
2976 /* should never happen, but just in case ... */
2977 PyErr_Format(PyExc_SystemError
, "unknown cmpop found");
2982 ast2obj_comprehension(void* _o
)
2984 comprehension_ty o
= (comprehension_ty
)_o
;
2985 PyObject
*result
= NULL
, *value
= NULL
;
2991 result
= PyType_GenericNew(comprehension_type
, NULL
, NULL
);
2992 if (!result
) return NULL
;
2993 value
= ast2obj_expr(o
->target
);
2994 if (!value
) goto failed
;
2995 if (PyObject_SetAttrString(result
, "target", value
) == -1)
2998 value
= ast2obj_expr(o
->iter
);
2999 if (!value
) goto failed
;
3000 if (PyObject_SetAttrString(result
, "iter", value
) == -1)
3003 value
= ast2obj_list(o
->ifs
, ast2obj_expr
);
3004 if (!value
) goto failed
;
3005 if (PyObject_SetAttrString(result
, "ifs", value
) == -1)
3016 ast2obj_excepthandler(void* _o
)
3018 excepthandler_ty o
= (excepthandler_ty
)_o
;
3019 PyObject
*result
= NULL
, *value
= NULL
;
3026 case ExceptHandler_kind
:
3027 result
= PyType_GenericNew(ExceptHandler_type
, NULL
, NULL
);
3028 if (!result
) goto failed
;
3029 value
= ast2obj_expr(o
->v
.ExceptHandler
.type
);
3030 if (!value
) goto failed
;
3031 if (PyObject_SetAttrString(result
, "type", value
) == -1)
3034 value
= ast2obj_expr(o
->v
.ExceptHandler
.name
);
3035 if (!value
) goto failed
;
3036 if (PyObject_SetAttrString(result
, "name", value
) == -1)
3039 value
= ast2obj_list(o
->v
.ExceptHandler
.body
, ast2obj_stmt
);
3040 if (!value
) goto failed
;
3041 if (PyObject_SetAttrString(result
, "body", value
) == -1)
3046 value
= ast2obj_int(o
->lineno
);
3047 if (!value
) goto failed
;
3048 if (PyObject_SetAttrString(result
, "lineno", value
) < 0)
3051 value
= ast2obj_int(o
->col_offset
);
3052 if (!value
) goto failed
;
3053 if (PyObject_SetAttrString(result
, "col_offset", value
) < 0)
3064 ast2obj_arguments(void* _o
)
3066 arguments_ty o
= (arguments_ty
)_o
;
3067 PyObject
*result
= NULL
, *value
= NULL
;
3073 result
= PyType_GenericNew(arguments_type
, NULL
, NULL
);
3074 if (!result
) return NULL
;
3075 value
= ast2obj_list(o
->args
, ast2obj_expr
);
3076 if (!value
) goto failed
;
3077 if (PyObject_SetAttrString(result
, "args", value
) == -1)
3080 value
= ast2obj_identifier(o
->vararg
);
3081 if (!value
) goto failed
;
3082 if (PyObject_SetAttrString(result
, "vararg", value
) == -1)
3085 value
= ast2obj_identifier(o
->kwarg
);
3086 if (!value
) goto failed
;
3087 if (PyObject_SetAttrString(result
, "kwarg", value
) == -1)
3090 value
= ast2obj_list(o
->defaults
, ast2obj_expr
);
3091 if (!value
) goto failed
;
3092 if (PyObject_SetAttrString(result
, "defaults", value
) == -1)
3103 ast2obj_keyword(void* _o
)
3105 keyword_ty o
= (keyword_ty
)_o
;
3106 PyObject
*result
= NULL
, *value
= NULL
;
3112 result
= PyType_GenericNew(keyword_type
, NULL
, NULL
);
3113 if (!result
) return NULL
;
3114 value
= ast2obj_identifier(o
->arg
);
3115 if (!value
) goto failed
;
3116 if (PyObject_SetAttrString(result
, "arg", value
) == -1)
3119 value
= ast2obj_expr(o
->value
);
3120 if (!value
) goto failed
;
3121 if (PyObject_SetAttrString(result
, "value", value
) == -1)
3132 ast2obj_alias(void* _o
)
3134 alias_ty o
= (alias_ty
)_o
;
3135 PyObject
*result
= NULL
, *value
= NULL
;
3141 result
= PyType_GenericNew(alias_type
, NULL
, NULL
);
3142 if (!result
) return NULL
;
3143 value
= ast2obj_identifier(o
->name
);
3144 if (!value
) goto failed
;
3145 if (PyObject_SetAttrString(result
, "name", value
) == -1)
3148 value
= ast2obj_identifier(o
->asname
);
3149 if (!value
) goto failed
;
3150 if (PyObject_SetAttrString(result
, "asname", value
) == -1)
3162 obj2ast_mod(PyObject
* obj
, mod_ty
* out
, PyArena
* arena
)
3164 PyObject
* tmp
= NULL
;
3167 if (obj
== Py_None
) {
3171 if (PyObject_IsInstance(obj
, (PyObject
*)Module_type
)) {
3174 if (PyObject_HasAttrString(obj
, "body")) {
3178 tmp
= PyObject_GetAttrString(obj
, "body");
3179 if (tmp
== NULL
) goto failed
;
3180 if (!PyList_Check(tmp
)) {
3181 PyErr_Format(PyExc_TypeError
, "Module field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3184 len
= PyList_GET_SIZE(tmp
);
3185 body
= asdl_seq_new(len
, arena
);
3186 if (body
== NULL
) goto failed
;
3187 for (i
= 0; i
< len
; i
++) {
3189 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3190 if (res
!= 0) goto failed
;
3191 asdl_seq_SET(body
, i
, value
);
3196 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from Module");
3199 *out
= Module(body
, arena
);
3200 if (*out
== NULL
) goto failed
;
3203 if (PyObject_IsInstance(obj
, (PyObject
*)Interactive_type
)) {
3206 if (PyObject_HasAttrString(obj
, "body")) {
3210 tmp
= PyObject_GetAttrString(obj
, "body");
3211 if (tmp
== NULL
) goto failed
;
3212 if (!PyList_Check(tmp
)) {
3213 PyErr_Format(PyExc_TypeError
, "Interactive field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3216 len
= PyList_GET_SIZE(tmp
);
3217 body
= asdl_seq_new(len
, arena
);
3218 if (body
== NULL
) goto failed
;
3219 for (i
= 0; i
< len
; i
++) {
3221 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3222 if (res
!= 0) goto failed
;
3223 asdl_seq_SET(body
, i
, value
);
3228 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from Interactive");
3231 *out
= Interactive(body
, arena
);
3232 if (*out
== NULL
) goto failed
;
3235 if (PyObject_IsInstance(obj
, (PyObject
*)Expression_type
)) {
3238 if (PyObject_HasAttrString(obj
, "body")) {
3240 tmp
= PyObject_GetAttrString(obj
, "body");
3241 if (tmp
== NULL
) goto failed
;
3242 res
= obj2ast_expr(tmp
, &body
, arena
);
3243 if (res
!= 0) goto failed
;
3247 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from Expression");
3250 *out
= Expression(body
, arena
);
3251 if (*out
== NULL
) goto failed
;
3254 if (PyObject_IsInstance(obj
, (PyObject
*)Suite_type
)) {
3257 if (PyObject_HasAttrString(obj
, "body")) {
3261 tmp
= PyObject_GetAttrString(obj
, "body");
3262 if (tmp
== NULL
) goto failed
;
3263 if (!PyList_Check(tmp
)) {
3264 PyErr_Format(PyExc_TypeError
, "Suite field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3267 len
= PyList_GET_SIZE(tmp
);
3268 body
= asdl_seq_new(len
, arena
);
3269 if (body
== NULL
) goto failed
;
3270 for (i
= 0; i
< len
; i
++) {
3272 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3273 if (res
!= 0) goto failed
;
3274 asdl_seq_SET(body
, i
, value
);
3279 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from Suite");
3282 *out
= Suite(body
, arena
);
3283 if (*out
== NULL
) goto failed
;
3287 tmp
= PyObject_Repr(obj
);
3288 if (tmp
== NULL
) goto failed
;
3289 PyErr_Format(PyExc_TypeError
, "expected some sort of mod, but got %.400s", PyString_AS_STRING(tmp
));
3296 obj2ast_stmt(PyObject
* obj
, stmt_ty
* out
, PyArena
* arena
)
3298 PyObject
* tmp
= NULL
;
3303 if (obj
== Py_None
) {
3307 if (PyObject_HasAttrString(obj
, "lineno")) {
3309 tmp
= PyObject_GetAttrString(obj
, "lineno");
3310 if (tmp
== NULL
) goto failed
;
3311 res
= obj2ast_int(tmp
, &lineno
, arena
);
3312 if (res
!= 0) goto failed
;
3316 PyErr_SetString(PyExc_TypeError
, "required field \"lineno\" missing from stmt");
3319 if (PyObject_HasAttrString(obj
, "col_offset")) {
3321 tmp
= PyObject_GetAttrString(obj
, "col_offset");
3322 if (tmp
== NULL
) goto failed
;
3323 res
= obj2ast_int(tmp
, &col_offset
, arena
);
3324 if (res
!= 0) goto failed
;
3328 PyErr_SetString(PyExc_TypeError
, "required field \"col_offset\" missing from stmt");
3331 if (PyObject_IsInstance(obj
, (PyObject
*)FunctionDef_type
)) {
3335 asdl_seq
* decorator_list
;
3337 if (PyObject_HasAttrString(obj
, "name")) {
3339 tmp
= PyObject_GetAttrString(obj
, "name");
3340 if (tmp
== NULL
) goto failed
;
3341 res
= obj2ast_identifier(tmp
, &name
, arena
);
3342 if (res
!= 0) goto failed
;
3346 PyErr_SetString(PyExc_TypeError
, "required field \"name\" missing from FunctionDef");
3349 if (PyObject_HasAttrString(obj
, "args")) {
3351 tmp
= PyObject_GetAttrString(obj
, "args");
3352 if (tmp
== NULL
) goto failed
;
3353 res
= obj2ast_arguments(tmp
, &args
, arena
);
3354 if (res
!= 0) goto failed
;
3358 PyErr_SetString(PyExc_TypeError
, "required field \"args\" missing from FunctionDef");
3361 if (PyObject_HasAttrString(obj
, "body")) {
3365 tmp
= PyObject_GetAttrString(obj
, "body");
3366 if (tmp
== NULL
) goto failed
;
3367 if (!PyList_Check(tmp
)) {
3368 PyErr_Format(PyExc_TypeError
, "FunctionDef field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3371 len
= PyList_GET_SIZE(tmp
);
3372 body
= asdl_seq_new(len
, arena
);
3373 if (body
== NULL
) goto failed
;
3374 for (i
= 0; i
< len
; i
++) {
3376 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3377 if (res
!= 0) goto failed
;
3378 asdl_seq_SET(body
, i
, value
);
3383 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from FunctionDef");
3386 if (PyObject_HasAttrString(obj
, "decorator_list")) {
3390 tmp
= PyObject_GetAttrString(obj
, "decorator_list");
3391 if (tmp
== NULL
) goto failed
;
3392 if (!PyList_Check(tmp
)) {
3393 PyErr_Format(PyExc_TypeError
, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3396 len
= PyList_GET_SIZE(tmp
);
3397 decorator_list
= asdl_seq_new(len
, arena
);
3398 if (decorator_list
== NULL
) goto failed
;
3399 for (i
= 0; i
< len
; i
++) {
3401 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3402 if (res
!= 0) goto failed
;
3403 asdl_seq_SET(decorator_list
, i
, value
);
3408 PyErr_SetString(PyExc_TypeError
, "required field \"decorator_list\" missing from FunctionDef");
3411 *out
= FunctionDef(name
, args
, body
, decorator_list
, lineno
,
3413 if (*out
== NULL
) goto failed
;
3416 if (PyObject_IsInstance(obj
, (PyObject
*)ClassDef_type
)) {
3420 asdl_seq
* decorator_list
;
3422 if (PyObject_HasAttrString(obj
, "name")) {
3424 tmp
= PyObject_GetAttrString(obj
, "name");
3425 if (tmp
== NULL
) goto failed
;
3426 res
= obj2ast_identifier(tmp
, &name
, arena
);
3427 if (res
!= 0) goto failed
;
3431 PyErr_SetString(PyExc_TypeError
, "required field \"name\" missing from ClassDef");
3434 if (PyObject_HasAttrString(obj
, "bases")) {
3438 tmp
= PyObject_GetAttrString(obj
, "bases");
3439 if (tmp
== NULL
) goto failed
;
3440 if (!PyList_Check(tmp
)) {
3441 PyErr_Format(PyExc_TypeError
, "ClassDef field \"bases\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3444 len
= PyList_GET_SIZE(tmp
);
3445 bases
= asdl_seq_new(len
, arena
);
3446 if (bases
== NULL
) goto failed
;
3447 for (i
= 0; i
< len
; i
++) {
3449 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3450 if (res
!= 0) goto failed
;
3451 asdl_seq_SET(bases
, i
, value
);
3456 PyErr_SetString(PyExc_TypeError
, "required field \"bases\" missing from ClassDef");
3459 if (PyObject_HasAttrString(obj
, "body")) {
3463 tmp
= PyObject_GetAttrString(obj
, "body");
3464 if (tmp
== NULL
) goto failed
;
3465 if (!PyList_Check(tmp
)) {
3466 PyErr_Format(PyExc_TypeError
, "ClassDef field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3469 len
= PyList_GET_SIZE(tmp
);
3470 body
= asdl_seq_new(len
, arena
);
3471 if (body
== NULL
) goto failed
;
3472 for (i
= 0; i
< len
; i
++) {
3474 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3475 if (res
!= 0) goto failed
;
3476 asdl_seq_SET(body
, i
, value
);
3481 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from ClassDef");
3484 if (PyObject_HasAttrString(obj
, "decorator_list")) {
3488 tmp
= PyObject_GetAttrString(obj
, "decorator_list");
3489 if (tmp
== NULL
) goto failed
;
3490 if (!PyList_Check(tmp
)) {
3491 PyErr_Format(PyExc_TypeError
, "ClassDef field \"decorator_list\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3494 len
= PyList_GET_SIZE(tmp
);
3495 decorator_list
= asdl_seq_new(len
, arena
);
3496 if (decorator_list
== NULL
) goto failed
;
3497 for (i
= 0; i
< len
; i
++) {
3499 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3500 if (res
!= 0) goto failed
;
3501 asdl_seq_SET(decorator_list
, i
, value
);
3506 PyErr_SetString(PyExc_TypeError
, "required field \"decorator_list\" missing from ClassDef");
3509 *out
= ClassDef(name
, bases
, body
, decorator_list
, lineno
,
3511 if (*out
== NULL
) goto failed
;
3514 if (PyObject_IsInstance(obj
, (PyObject
*)Return_type
)) {
3517 if (PyObject_HasAttrString(obj
, "value")) {
3519 tmp
= PyObject_GetAttrString(obj
, "value");
3520 if (tmp
== NULL
) goto failed
;
3521 res
= obj2ast_expr(tmp
, &value
, arena
);
3522 if (res
!= 0) goto failed
;
3528 *out
= Return(value
, lineno
, col_offset
, arena
);
3529 if (*out
== NULL
) goto failed
;
3532 if (PyObject_IsInstance(obj
, (PyObject
*)Delete_type
)) {
3535 if (PyObject_HasAttrString(obj
, "targets")) {
3539 tmp
= PyObject_GetAttrString(obj
, "targets");
3540 if (tmp
== NULL
) goto failed
;
3541 if (!PyList_Check(tmp
)) {
3542 PyErr_Format(PyExc_TypeError
, "Delete field \"targets\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3545 len
= PyList_GET_SIZE(tmp
);
3546 targets
= asdl_seq_new(len
, arena
);
3547 if (targets
== NULL
) goto failed
;
3548 for (i
= 0; i
< len
; i
++) {
3550 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3551 if (res
!= 0) goto failed
;
3552 asdl_seq_SET(targets
, i
, value
);
3557 PyErr_SetString(PyExc_TypeError
, "required field \"targets\" missing from Delete");
3560 *out
= Delete(targets
, lineno
, col_offset
, arena
);
3561 if (*out
== NULL
) goto failed
;
3564 if (PyObject_IsInstance(obj
, (PyObject
*)Assign_type
)) {
3568 if (PyObject_HasAttrString(obj
, "targets")) {
3572 tmp
= PyObject_GetAttrString(obj
, "targets");
3573 if (tmp
== NULL
) goto failed
;
3574 if (!PyList_Check(tmp
)) {
3575 PyErr_Format(PyExc_TypeError
, "Assign field \"targets\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3578 len
= PyList_GET_SIZE(tmp
);
3579 targets
= asdl_seq_new(len
, arena
);
3580 if (targets
== NULL
) goto failed
;
3581 for (i
= 0; i
< len
; i
++) {
3583 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3584 if (res
!= 0) goto failed
;
3585 asdl_seq_SET(targets
, i
, value
);
3590 PyErr_SetString(PyExc_TypeError
, "required field \"targets\" missing from Assign");
3593 if (PyObject_HasAttrString(obj
, "value")) {
3595 tmp
= PyObject_GetAttrString(obj
, "value");
3596 if (tmp
== NULL
) goto failed
;
3597 res
= obj2ast_expr(tmp
, &value
, arena
);
3598 if (res
!= 0) goto failed
;
3602 PyErr_SetString(PyExc_TypeError
, "required field \"value\" missing from Assign");
3605 *out
= Assign(targets
, value
, lineno
, col_offset
, arena
);
3606 if (*out
== NULL
) goto failed
;
3609 if (PyObject_IsInstance(obj
, (PyObject
*)AugAssign_type
)) {
3614 if (PyObject_HasAttrString(obj
, "target")) {
3616 tmp
= PyObject_GetAttrString(obj
, "target");
3617 if (tmp
== NULL
) goto failed
;
3618 res
= obj2ast_expr(tmp
, &target
, arena
);
3619 if (res
!= 0) goto failed
;
3623 PyErr_SetString(PyExc_TypeError
, "required field \"target\" missing from AugAssign");
3626 if (PyObject_HasAttrString(obj
, "op")) {
3628 tmp
= PyObject_GetAttrString(obj
, "op");
3629 if (tmp
== NULL
) goto failed
;
3630 res
= obj2ast_operator(tmp
, &op
, arena
);
3631 if (res
!= 0) goto failed
;
3635 PyErr_SetString(PyExc_TypeError
, "required field \"op\" missing from AugAssign");
3638 if (PyObject_HasAttrString(obj
, "value")) {
3640 tmp
= PyObject_GetAttrString(obj
, "value");
3641 if (tmp
== NULL
) goto failed
;
3642 res
= obj2ast_expr(tmp
, &value
, arena
);
3643 if (res
!= 0) goto failed
;
3647 PyErr_SetString(PyExc_TypeError
, "required field \"value\" missing from AugAssign");
3650 *out
= AugAssign(target
, op
, value
, lineno
, col_offset
, arena
);
3651 if (*out
== NULL
) goto failed
;
3654 if (PyObject_IsInstance(obj
, (PyObject
*)Print_type
)) {
3659 if (PyObject_HasAttrString(obj
, "dest")) {
3661 tmp
= PyObject_GetAttrString(obj
, "dest");
3662 if (tmp
== NULL
) goto failed
;
3663 res
= obj2ast_expr(tmp
, &dest
, arena
);
3664 if (res
!= 0) goto failed
;
3670 if (PyObject_HasAttrString(obj
, "values")) {
3674 tmp
= PyObject_GetAttrString(obj
, "values");
3675 if (tmp
== NULL
) goto failed
;
3676 if (!PyList_Check(tmp
)) {
3677 PyErr_Format(PyExc_TypeError
, "Print field \"values\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3680 len
= PyList_GET_SIZE(tmp
);
3681 values
= asdl_seq_new(len
, arena
);
3682 if (values
== NULL
) goto failed
;
3683 for (i
= 0; i
< len
; i
++) {
3685 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3686 if (res
!= 0) goto failed
;
3687 asdl_seq_SET(values
, i
, value
);
3692 PyErr_SetString(PyExc_TypeError
, "required field \"values\" missing from Print");
3695 if (PyObject_HasAttrString(obj
, "nl")) {
3697 tmp
= PyObject_GetAttrString(obj
, "nl");
3698 if (tmp
== NULL
) goto failed
;
3699 res
= obj2ast_bool(tmp
, &nl
, arena
);
3700 if (res
!= 0) goto failed
;
3704 PyErr_SetString(PyExc_TypeError
, "required field \"nl\" missing from Print");
3707 *out
= Print(dest
, values
, nl
, lineno
, col_offset
, arena
);
3708 if (*out
== NULL
) goto failed
;
3711 if (PyObject_IsInstance(obj
, (PyObject
*)For_type
)) {
3717 if (PyObject_HasAttrString(obj
, "target")) {
3719 tmp
= PyObject_GetAttrString(obj
, "target");
3720 if (tmp
== NULL
) goto failed
;
3721 res
= obj2ast_expr(tmp
, &target
, arena
);
3722 if (res
!= 0) goto failed
;
3726 PyErr_SetString(PyExc_TypeError
, "required field \"target\" missing from For");
3729 if (PyObject_HasAttrString(obj
, "iter")) {
3731 tmp
= PyObject_GetAttrString(obj
, "iter");
3732 if (tmp
== NULL
) goto failed
;
3733 res
= obj2ast_expr(tmp
, &iter
, arena
);
3734 if (res
!= 0) goto failed
;
3738 PyErr_SetString(PyExc_TypeError
, "required field \"iter\" missing from For");
3741 if (PyObject_HasAttrString(obj
, "body")) {
3745 tmp
= PyObject_GetAttrString(obj
, "body");
3746 if (tmp
== NULL
) goto failed
;
3747 if (!PyList_Check(tmp
)) {
3748 PyErr_Format(PyExc_TypeError
, "For field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3751 len
= PyList_GET_SIZE(tmp
);
3752 body
= asdl_seq_new(len
, arena
);
3753 if (body
== NULL
) goto failed
;
3754 for (i
= 0; i
< len
; i
++) {
3756 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3757 if (res
!= 0) goto failed
;
3758 asdl_seq_SET(body
, i
, value
);
3763 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from For");
3766 if (PyObject_HasAttrString(obj
, "orelse")) {
3770 tmp
= PyObject_GetAttrString(obj
, "orelse");
3771 if (tmp
== NULL
) goto failed
;
3772 if (!PyList_Check(tmp
)) {
3773 PyErr_Format(PyExc_TypeError
, "For field \"orelse\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3776 len
= PyList_GET_SIZE(tmp
);
3777 orelse
= asdl_seq_new(len
, arena
);
3778 if (orelse
== NULL
) goto failed
;
3779 for (i
= 0; i
< len
; i
++) {
3781 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3782 if (res
!= 0) goto failed
;
3783 asdl_seq_SET(orelse
, i
, value
);
3788 PyErr_SetString(PyExc_TypeError
, "required field \"orelse\" missing from For");
3791 *out
= For(target
, iter
, body
, orelse
, lineno
, col_offset
,
3793 if (*out
== NULL
) goto failed
;
3796 if (PyObject_IsInstance(obj
, (PyObject
*)While_type
)) {
3801 if (PyObject_HasAttrString(obj
, "test")) {
3803 tmp
= PyObject_GetAttrString(obj
, "test");
3804 if (tmp
== NULL
) goto failed
;
3805 res
= obj2ast_expr(tmp
, &test
, arena
);
3806 if (res
!= 0) goto failed
;
3810 PyErr_SetString(PyExc_TypeError
, "required field \"test\" missing from While");
3813 if (PyObject_HasAttrString(obj
, "body")) {
3817 tmp
= PyObject_GetAttrString(obj
, "body");
3818 if (tmp
== NULL
) goto failed
;
3819 if (!PyList_Check(tmp
)) {
3820 PyErr_Format(PyExc_TypeError
, "While field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3823 len
= PyList_GET_SIZE(tmp
);
3824 body
= asdl_seq_new(len
, arena
);
3825 if (body
== NULL
) goto failed
;
3826 for (i
= 0; i
< len
; i
++) {
3828 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3829 if (res
!= 0) goto failed
;
3830 asdl_seq_SET(body
, i
, value
);
3835 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from While");
3838 if (PyObject_HasAttrString(obj
, "orelse")) {
3842 tmp
= PyObject_GetAttrString(obj
, "orelse");
3843 if (tmp
== NULL
) goto failed
;
3844 if (!PyList_Check(tmp
)) {
3845 PyErr_Format(PyExc_TypeError
, "While field \"orelse\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3848 len
= PyList_GET_SIZE(tmp
);
3849 orelse
= asdl_seq_new(len
, arena
);
3850 if (orelse
== NULL
) goto failed
;
3851 for (i
= 0; i
< len
; i
++) {
3853 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3854 if (res
!= 0) goto failed
;
3855 asdl_seq_SET(orelse
, i
, value
);
3860 PyErr_SetString(PyExc_TypeError
, "required field \"orelse\" missing from While");
3863 *out
= While(test
, body
, orelse
, lineno
, col_offset
, arena
);
3864 if (*out
== NULL
) goto failed
;
3867 if (PyObject_IsInstance(obj
, (PyObject
*)If_type
)) {
3872 if (PyObject_HasAttrString(obj
, "test")) {
3874 tmp
= PyObject_GetAttrString(obj
, "test");
3875 if (tmp
== NULL
) goto failed
;
3876 res
= obj2ast_expr(tmp
, &test
, arena
);
3877 if (res
!= 0) goto failed
;
3881 PyErr_SetString(PyExc_TypeError
, "required field \"test\" missing from If");
3884 if (PyObject_HasAttrString(obj
, "body")) {
3888 tmp
= PyObject_GetAttrString(obj
, "body");
3889 if (tmp
== NULL
) goto failed
;
3890 if (!PyList_Check(tmp
)) {
3891 PyErr_Format(PyExc_TypeError
, "If field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3894 len
= PyList_GET_SIZE(tmp
);
3895 body
= asdl_seq_new(len
, arena
);
3896 if (body
== NULL
) goto failed
;
3897 for (i
= 0; i
< len
; i
++) {
3899 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3900 if (res
!= 0) goto failed
;
3901 asdl_seq_SET(body
, i
, value
);
3906 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from If");
3909 if (PyObject_HasAttrString(obj
, "orelse")) {
3913 tmp
= PyObject_GetAttrString(obj
, "orelse");
3914 if (tmp
== NULL
) goto failed
;
3915 if (!PyList_Check(tmp
)) {
3916 PyErr_Format(PyExc_TypeError
, "If field \"orelse\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3919 len
= PyList_GET_SIZE(tmp
);
3920 orelse
= asdl_seq_new(len
, arena
);
3921 if (orelse
== NULL
) goto failed
;
3922 for (i
= 0; i
< len
; i
++) {
3924 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3925 if (res
!= 0) goto failed
;
3926 asdl_seq_SET(orelse
, i
, value
);
3931 PyErr_SetString(PyExc_TypeError
, "required field \"orelse\" missing from If");
3934 *out
= If(test
, body
, orelse
, lineno
, col_offset
, arena
);
3935 if (*out
== NULL
) goto failed
;
3938 if (PyObject_IsInstance(obj
, (PyObject
*)With_type
)) {
3939 expr_ty context_expr
;
3940 expr_ty optional_vars
;
3943 if (PyObject_HasAttrString(obj
, "context_expr")) {
3945 tmp
= PyObject_GetAttrString(obj
, "context_expr");
3946 if (tmp
== NULL
) goto failed
;
3947 res
= obj2ast_expr(tmp
, &context_expr
, arena
);
3948 if (res
!= 0) goto failed
;
3952 PyErr_SetString(PyExc_TypeError
, "required field \"context_expr\" missing from With");
3955 if (PyObject_HasAttrString(obj
, "optional_vars")) {
3957 tmp
= PyObject_GetAttrString(obj
, "optional_vars");
3958 if (tmp
== NULL
) goto failed
;
3959 res
= obj2ast_expr(tmp
, &optional_vars
, arena
);
3960 if (res
!= 0) goto failed
;
3964 optional_vars
= NULL
;
3966 if (PyObject_HasAttrString(obj
, "body")) {
3970 tmp
= PyObject_GetAttrString(obj
, "body");
3971 if (tmp
== NULL
) goto failed
;
3972 if (!PyList_Check(tmp
)) {
3973 PyErr_Format(PyExc_TypeError
, "With field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3976 len
= PyList_GET_SIZE(tmp
);
3977 body
= asdl_seq_new(len
, arena
);
3978 if (body
== NULL
) goto failed
;
3979 for (i
= 0; i
< len
; i
++) {
3981 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3982 if (res
!= 0) goto failed
;
3983 asdl_seq_SET(body
, i
, value
);
3988 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from With");
3991 *out
= With(context_expr
, optional_vars
, body
, lineno
,
3993 if (*out
== NULL
) goto failed
;
3996 if (PyObject_IsInstance(obj
, (PyObject
*)Raise_type
)) {
4001 if (PyObject_HasAttrString(obj
, "type")) {
4003 tmp
= PyObject_GetAttrString(obj
, "type");
4004 if (tmp
== NULL
) goto failed
;
4005 res
= obj2ast_expr(tmp
, &type
, arena
);
4006 if (res
!= 0) goto failed
;
4012 if (PyObject_HasAttrString(obj
, "inst")) {
4014 tmp
= PyObject_GetAttrString(obj
, "inst");
4015 if (tmp
== NULL
) goto failed
;
4016 res
= obj2ast_expr(tmp
, &inst
, arena
);
4017 if (res
!= 0) goto failed
;
4023 if (PyObject_HasAttrString(obj
, "tback")) {
4025 tmp
= PyObject_GetAttrString(obj
, "tback");
4026 if (tmp
== NULL
) goto failed
;
4027 res
= obj2ast_expr(tmp
, &tback
, arena
);
4028 if (res
!= 0) goto failed
;
4034 *out
= Raise(type
, inst
, tback
, lineno
, col_offset
, arena
);
4035 if (*out
== NULL
) goto failed
;
4038 if (PyObject_IsInstance(obj
, (PyObject
*)TryExcept_type
)) {
4043 if (PyObject_HasAttrString(obj
, "body")) {
4047 tmp
= PyObject_GetAttrString(obj
, "body");
4048 if (tmp
== NULL
) goto failed
;
4049 if (!PyList_Check(tmp
)) {
4050 PyErr_Format(PyExc_TypeError
, "TryExcept field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4053 len
= PyList_GET_SIZE(tmp
);
4054 body
= asdl_seq_new(len
, arena
);
4055 if (body
== NULL
) goto failed
;
4056 for (i
= 0; i
< len
; i
++) {
4058 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4059 if (res
!= 0) goto failed
;
4060 asdl_seq_SET(body
, i
, value
);
4065 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from TryExcept");
4068 if (PyObject_HasAttrString(obj
, "handlers")) {
4072 tmp
= PyObject_GetAttrString(obj
, "handlers");
4073 if (tmp
== NULL
) goto failed
;
4074 if (!PyList_Check(tmp
)) {
4075 PyErr_Format(PyExc_TypeError
, "TryExcept field \"handlers\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4078 len
= PyList_GET_SIZE(tmp
);
4079 handlers
= asdl_seq_new(len
, arena
);
4080 if (handlers
== NULL
) goto failed
;
4081 for (i
= 0; i
< len
; i
++) {
4082 excepthandler_ty value
;
4083 res
= obj2ast_excepthandler(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4084 if (res
!= 0) goto failed
;
4085 asdl_seq_SET(handlers
, i
, value
);
4090 PyErr_SetString(PyExc_TypeError
, "required field \"handlers\" missing from TryExcept");
4093 if (PyObject_HasAttrString(obj
, "orelse")) {
4097 tmp
= PyObject_GetAttrString(obj
, "orelse");
4098 if (tmp
== NULL
) goto failed
;
4099 if (!PyList_Check(tmp
)) {
4100 PyErr_Format(PyExc_TypeError
, "TryExcept field \"orelse\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4103 len
= PyList_GET_SIZE(tmp
);
4104 orelse
= asdl_seq_new(len
, arena
);
4105 if (orelse
== NULL
) goto failed
;
4106 for (i
= 0; i
< len
; i
++) {
4108 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4109 if (res
!= 0) goto failed
;
4110 asdl_seq_SET(orelse
, i
, value
);
4115 PyErr_SetString(PyExc_TypeError
, "required field \"orelse\" missing from TryExcept");
4118 *out
= TryExcept(body
, handlers
, orelse
, lineno
, col_offset
,
4120 if (*out
== NULL
) goto failed
;
4123 if (PyObject_IsInstance(obj
, (PyObject
*)TryFinally_type
)) {
4125 asdl_seq
* finalbody
;
4127 if (PyObject_HasAttrString(obj
, "body")) {
4131 tmp
= PyObject_GetAttrString(obj
, "body");
4132 if (tmp
== NULL
) goto failed
;
4133 if (!PyList_Check(tmp
)) {
4134 PyErr_Format(PyExc_TypeError
, "TryFinally field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4137 len
= PyList_GET_SIZE(tmp
);
4138 body
= asdl_seq_new(len
, arena
);
4139 if (body
== NULL
) goto failed
;
4140 for (i
= 0; i
< len
; i
++) {
4142 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4143 if (res
!= 0) goto failed
;
4144 asdl_seq_SET(body
, i
, value
);
4149 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from TryFinally");
4152 if (PyObject_HasAttrString(obj
, "finalbody")) {
4156 tmp
= PyObject_GetAttrString(obj
, "finalbody");
4157 if (tmp
== NULL
) goto failed
;
4158 if (!PyList_Check(tmp
)) {
4159 PyErr_Format(PyExc_TypeError
, "TryFinally field \"finalbody\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4162 len
= PyList_GET_SIZE(tmp
);
4163 finalbody
= asdl_seq_new(len
, arena
);
4164 if (finalbody
== NULL
) goto failed
;
4165 for (i
= 0; i
< len
; i
++) {
4167 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4168 if (res
!= 0) goto failed
;
4169 asdl_seq_SET(finalbody
, i
, value
);
4174 PyErr_SetString(PyExc_TypeError
, "required field \"finalbody\" missing from TryFinally");
4177 *out
= TryFinally(body
, finalbody
, lineno
, col_offset
, arena
);
4178 if (*out
== NULL
) goto failed
;
4181 if (PyObject_IsInstance(obj
, (PyObject
*)Assert_type
)) {
4185 if (PyObject_HasAttrString(obj
, "test")) {
4187 tmp
= PyObject_GetAttrString(obj
, "test");
4188 if (tmp
== NULL
) goto failed
;
4189 res
= obj2ast_expr(tmp
, &test
, arena
);
4190 if (res
!= 0) goto failed
;
4194 PyErr_SetString(PyExc_TypeError
, "required field \"test\" missing from Assert");
4197 if (PyObject_HasAttrString(obj
, "msg")) {
4199 tmp
= PyObject_GetAttrString(obj
, "msg");
4200 if (tmp
== NULL
) goto failed
;
4201 res
= obj2ast_expr(tmp
, &msg
, arena
);
4202 if (res
!= 0) goto failed
;
4208 *out
= Assert(test
, msg
, lineno
, col_offset
, arena
);
4209 if (*out
== NULL
) goto failed
;
4212 if (PyObject_IsInstance(obj
, (PyObject
*)Import_type
)) {
4215 if (PyObject_HasAttrString(obj
, "names")) {
4219 tmp
= PyObject_GetAttrString(obj
, "names");
4220 if (tmp
== NULL
) goto failed
;
4221 if (!PyList_Check(tmp
)) {
4222 PyErr_Format(PyExc_TypeError
, "Import field \"names\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4225 len
= PyList_GET_SIZE(tmp
);
4226 names
= asdl_seq_new(len
, arena
);
4227 if (names
== NULL
) goto failed
;
4228 for (i
= 0; i
< len
; i
++) {
4230 res
= obj2ast_alias(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4231 if (res
!= 0) goto failed
;
4232 asdl_seq_SET(names
, i
, value
);
4237 PyErr_SetString(PyExc_TypeError
, "required field \"names\" missing from Import");
4240 *out
= Import(names
, lineno
, col_offset
, arena
);
4241 if (*out
== NULL
) goto failed
;
4244 if (PyObject_IsInstance(obj
, (PyObject
*)ImportFrom_type
)) {
4249 if (PyObject_HasAttrString(obj
, "module")) {
4251 tmp
= PyObject_GetAttrString(obj
, "module");
4252 if (tmp
== NULL
) goto failed
;
4253 res
= obj2ast_identifier(tmp
, &module
, arena
);
4254 if (res
!= 0) goto failed
;
4258 PyErr_SetString(PyExc_TypeError
, "required field \"module\" missing from ImportFrom");
4261 if (PyObject_HasAttrString(obj
, "names")) {
4265 tmp
= PyObject_GetAttrString(obj
, "names");
4266 if (tmp
== NULL
) goto failed
;
4267 if (!PyList_Check(tmp
)) {
4268 PyErr_Format(PyExc_TypeError
, "ImportFrom field \"names\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4271 len
= PyList_GET_SIZE(tmp
);
4272 names
= asdl_seq_new(len
, arena
);
4273 if (names
== NULL
) goto failed
;
4274 for (i
= 0; i
< len
; i
++) {
4276 res
= obj2ast_alias(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4277 if (res
!= 0) goto failed
;
4278 asdl_seq_SET(names
, i
, value
);
4283 PyErr_SetString(PyExc_TypeError
, "required field \"names\" missing from ImportFrom");
4286 if (PyObject_HasAttrString(obj
, "level")) {
4288 tmp
= PyObject_GetAttrString(obj
, "level");
4289 if (tmp
== NULL
) goto failed
;
4290 res
= obj2ast_int(tmp
, &level
, arena
);
4291 if (res
!= 0) goto failed
;
4297 *out
= ImportFrom(module
, names
, level
, lineno
, col_offset
,
4299 if (*out
== NULL
) goto failed
;
4302 if (PyObject_IsInstance(obj
, (PyObject
*)Exec_type
)) {
4307 if (PyObject_HasAttrString(obj
, "body")) {
4309 tmp
= PyObject_GetAttrString(obj
, "body");
4310 if (tmp
== NULL
) goto failed
;
4311 res
= obj2ast_expr(tmp
, &body
, arena
);
4312 if (res
!= 0) goto failed
;
4316 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from Exec");
4319 if (PyObject_HasAttrString(obj
, "globals")) {
4321 tmp
= PyObject_GetAttrString(obj
, "globals");
4322 if (tmp
== NULL
) goto failed
;
4323 res
= obj2ast_expr(tmp
, &globals
, arena
);
4324 if (res
!= 0) goto failed
;
4330 if (PyObject_HasAttrString(obj
, "locals")) {
4332 tmp
= PyObject_GetAttrString(obj
, "locals");
4333 if (tmp
== NULL
) goto failed
;
4334 res
= obj2ast_expr(tmp
, &locals
, arena
);
4335 if (res
!= 0) goto failed
;
4341 *out
= Exec(body
, globals
, locals
, lineno
, col_offset
, arena
);
4342 if (*out
== NULL
) goto failed
;
4345 if (PyObject_IsInstance(obj
, (PyObject
*)Global_type
)) {
4348 if (PyObject_HasAttrString(obj
, "names")) {
4352 tmp
= PyObject_GetAttrString(obj
, "names");
4353 if (tmp
== NULL
) goto failed
;
4354 if (!PyList_Check(tmp
)) {
4355 PyErr_Format(PyExc_TypeError
, "Global field \"names\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4358 len
= PyList_GET_SIZE(tmp
);
4359 names
= asdl_seq_new(len
, arena
);
4360 if (names
== NULL
) goto failed
;
4361 for (i
= 0; i
< len
; i
++) {
4363 res
= obj2ast_identifier(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4364 if (res
!= 0) goto failed
;
4365 asdl_seq_SET(names
, i
, value
);
4370 PyErr_SetString(PyExc_TypeError
, "required field \"names\" missing from Global");
4373 *out
= Global(names
, lineno
, col_offset
, arena
);
4374 if (*out
== NULL
) goto failed
;
4377 if (PyObject_IsInstance(obj
, (PyObject
*)Expr_type
)) {
4380 if (PyObject_HasAttrString(obj
, "value")) {
4382 tmp
= PyObject_GetAttrString(obj
, "value");
4383 if (tmp
== NULL
) goto failed
;
4384 res
= obj2ast_expr(tmp
, &value
, arena
);
4385 if (res
!= 0) goto failed
;
4389 PyErr_SetString(PyExc_TypeError
, "required field \"value\" missing from Expr");
4392 *out
= Expr(value
, lineno
, col_offset
, arena
);
4393 if (*out
== NULL
) goto failed
;
4396 if (PyObject_IsInstance(obj
, (PyObject
*)Pass_type
)) {
4398 *out
= Pass(lineno
, col_offset
, arena
);
4399 if (*out
== NULL
) goto failed
;
4402 if (PyObject_IsInstance(obj
, (PyObject
*)Break_type
)) {
4404 *out
= Break(lineno
, col_offset
, arena
);
4405 if (*out
== NULL
) goto failed
;
4408 if (PyObject_IsInstance(obj
, (PyObject
*)Continue_type
)) {
4410 *out
= Continue(lineno
, col_offset
, arena
);
4411 if (*out
== NULL
) goto failed
;
4415 tmp
= PyObject_Repr(obj
);
4416 if (tmp
== NULL
) goto failed
;
4417 PyErr_Format(PyExc_TypeError
, "expected some sort of stmt, but got %.400s", PyString_AS_STRING(tmp
));
4424 obj2ast_expr(PyObject
* obj
, expr_ty
* out
, PyArena
* arena
)
4426 PyObject
* tmp
= NULL
;
4431 if (obj
== Py_None
) {
4435 if (PyObject_HasAttrString(obj
, "lineno")) {
4437 tmp
= PyObject_GetAttrString(obj
, "lineno");
4438 if (tmp
== NULL
) goto failed
;
4439 res
= obj2ast_int(tmp
, &lineno
, arena
);
4440 if (res
!= 0) goto failed
;
4444 PyErr_SetString(PyExc_TypeError
, "required field \"lineno\" missing from expr");
4447 if (PyObject_HasAttrString(obj
, "col_offset")) {
4449 tmp
= PyObject_GetAttrString(obj
, "col_offset");
4450 if (tmp
== NULL
) goto failed
;
4451 res
= obj2ast_int(tmp
, &col_offset
, arena
);
4452 if (res
!= 0) goto failed
;
4456 PyErr_SetString(PyExc_TypeError
, "required field \"col_offset\" missing from expr");
4459 if (PyObject_IsInstance(obj
, (PyObject
*)BoolOp_type
)) {
4463 if (PyObject_HasAttrString(obj
, "op")) {
4465 tmp
= PyObject_GetAttrString(obj
, "op");
4466 if (tmp
== NULL
) goto failed
;
4467 res
= obj2ast_boolop(tmp
, &op
, arena
);
4468 if (res
!= 0) goto failed
;
4472 PyErr_SetString(PyExc_TypeError
, "required field \"op\" missing from BoolOp");
4475 if (PyObject_HasAttrString(obj
, "values")) {
4479 tmp
= PyObject_GetAttrString(obj
, "values");
4480 if (tmp
== NULL
) goto failed
;
4481 if (!PyList_Check(tmp
)) {
4482 PyErr_Format(PyExc_TypeError
, "BoolOp field \"values\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4485 len
= PyList_GET_SIZE(tmp
);
4486 values
= asdl_seq_new(len
, arena
);
4487 if (values
== NULL
) goto failed
;
4488 for (i
= 0; i
< len
; i
++) {
4490 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4491 if (res
!= 0) goto failed
;
4492 asdl_seq_SET(values
, i
, value
);
4497 PyErr_SetString(PyExc_TypeError
, "required field \"values\" missing from BoolOp");
4500 *out
= BoolOp(op
, values
, lineno
, col_offset
, arena
);
4501 if (*out
== NULL
) goto failed
;
4504 if (PyObject_IsInstance(obj
, (PyObject
*)BinOp_type
)) {
4509 if (PyObject_HasAttrString(obj
, "left")) {
4511 tmp
= PyObject_GetAttrString(obj
, "left");
4512 if (tmp
== NULL
) goto failed
;
4513 res
= obj2ast_expr(tmp
, &left
, arena
);
4514 if (res
!= 0) goto failed
;
4518 PyErr_SetString(PyExc_TypeError
, "required field \"left\" missing from BinOp");
4521 if (PyObject_HasAttrString(obj
, "op")) {
4523 tmp
= PyObject_GetAttrString(obj
, "op");
4524 if (tmp
== NULL
) goto failed
;
4525 res
= obj2ast_operator(tmp
, &op
, arena
);
4526 if (res
!= 0) goto failed
;
4530 PyErr_SetString(PyExc_TypeError
, "required field \"op\" missing from BinOp");
4533 if (PyObject_HasAttrString(obj
, "right")) {
4535 tmp
= PyObject_GetAttrString(obj
, "right");
4536 if (tmp
== NULL
) goto failed
;
4537 res
= obj2ast_expr(tmp
, &right
, arena
);
4538 if (res
!= 0) goto failed
;
4542 PyErr_SetString(PyExc_TypeError
, "required field \"right\" missing from BinOp");
4545 *out
= BinOp(left
, op
, right
, lineno
, col_offset
, arena
);
4546 if (*out
== NULL
) goto failed
;
4549 if (PyObject_IsInstance(obj
, (PyObject
*)UnaryOp_type
)) {
4553 if (PyObject_HasAttrString(obj
, "op")) {
4555 tmp
= PyObject_GetAttrString(obj
, "op");
4556 if (tmp
== NULL
) goto failed
;
4557 res
= obj2ast_unaryop(tmp
, &op
, arena
);
4558 if (res
!= 0) goto failed
;
4562 PyErr_SetString(PyExc_TypeError
, "required field \"op\" missing from UnaryOp");
4565 if (PyObject_HasAttrString(obj
, "operand")) {
4567 tmp
= PyObject_GetAttrString(obj
, "operand");
4568 if (tmp
== NULL
) goto failed
;
4569 res
= obj2ast_expr(tmp
, &operand
, arena
);
4570 if (res
!= 0) goto failed
;
4574 PyErr_SetString(PyExc_TypeError
, "required field \"operand\" missing from UnaryOp");
4577 *out
= UnaryOp(op
, operand
, lineno
, col_offset
, arena
);
4578 if (*out
== NULL
) goto failed
;
4581 if (PyObject_IsInstance(obj
, (PyObject
*)Lambda_type
)) {
4585 if (PyObject_HasAttrString(obj
, "args")) {
4587 tmp
= PyObject_GetAttrString(obj
, "args");
4588 if (tmp
== NULL
) goto failed
;
4589 res
= obj2ast_arguments(tmp
, &args
, arena
);
4590 if (res
!= 0) goto failed
;
4594 PyErr_SetString(PyExc_TypeError
, "required field \"args\" missing from Lambda");
4597 if (PyObject_HasAttrString(obj
, "body")) {
4599 tmp
= PyObject_GetAttrString(obj
, "body");
4600 if (tmp
== NULL
) goto failed
;
4601 res
= obj2ast_expr(tmp
, &body
, arena
);
4602 if (res
!= 0) goto failed
;
4606 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from Lambda");
4609 *out
= Lambda(args
, body
, lineno
, col_offset
, arena
);
4610 if (*out
== NULL
) goto failed
;
4613 if (PyObject_IsInstance(obj
, (PyObject
*)IfExp_type
)) {
4618 if (PyObject_HasAttrString(obj
, "test")) {
4620 tmp
= PyObject_GetAttrString(obj
, "test");
4621 if (tmp
== NULL
) goto failed
;
4622 res
= obj2ast_expr(tmp
, &test
, arena
);
4623 if (res
!= 0) goto failed
;
4627 PyErr_SetString(PyExc_TypeError
, "required field \"test\" missing from IfExp");
4630 if (PyObject_HasAttrString(obj
, "body")) {
4632 tmp
= PyObject_GetAttrString(obj
, "body");
4633 if (tmp
== NULL
) goto failed
;
4634 res
= obj2ast_expr(tmp
, &body
, arena
);
4635 if (res
!= 0) goto failed
;
4639 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from IfExp");
4642 if (PyObject_HasAttrString(obj
, "orelse")) {
4644 tmp
= PyObject_GetAttrString(obj
, "orelse");
4645 if (tmp
== NULL
) goto failed
;
4646 res
= obj2ast_expr(tmp
, &orelse
, arena
);
4647 if (res
!= 0) goto failed
;
4651 PyErr_SetString(PyExc_TypeError
, "required field \"orelse\" missing from IfExp");
4654 *out
= IfExp(test
, body
, orelse
, lineno
, col_offset
, arena
);
4655 if (*out
== NULL
) goto failed
;
4658 if (PyObject_IsInstance(obj
, (PyObject
*)Dict_type
)) {
4662 if (PyObject_HasAttrString(obj
, "keys")) {
4666 tmp
= PyObject_GetAttrString(obj
, "keys");
4667 if (tmp
== NULL
) goto failed
;
4668 if (!PyList_Check(tmp
)) {
4669 PyErr_Format(PyExc_TypeError
, "Dict field \"keys\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4672 len
= PyList_GET_SIZE(tmp
);
4673 keys
= asdl_seq_new(len
, arena
);
4674 if (keys
== NULL
) goto failed
;
4675 for (i
= 0; i
< len
; i
++) {
4677 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4678 if (res
!= 0) goto failed
;
4679 asdl_seq_SET(keys
, i
, value
);
4684 PyErr_SetString(PyExc_TypeError
, "required field \"keys\" missing from Dict");
4687 if (PyObject_HasAttrString(obj
, "values")) {
4691 tmp
= PyObject_GetAttrString(obj
, "values");
4692 if (tmp
== NULL
) goto failed
;
4693 if (!PyList_Check(tmp
)) {
4694 PyErr_Format(PyExc_TypeError
, "Dict field \"values\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4697 len
= PyList_GET_SIZE(tmp
);
4698 values
= asdl_seq_new(len
, arena
);
4699 if (values
== NULL
) goto failed
;
4700 for (i
= 0; i
< len
; i
++) {
4702 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4703 if (res
!= 0) goto failed
;
4704 asdl_seq_SET(values
, i
, value
);
4709 PyErr_SetString(PyExc_TypeError
, "required field \"values\" missing from Dict");
4712 *out
= Dict(keys
, values
, lineno
, col_offset
, arena
);
4713 if (*out
== NULL
) goto failed
;
4716 if (PyObject_IsInstance(obj
, (PyObject
*)ListComp_type
)) {
4718 asdl_seq
* generators
;
4720 if (PyObject_HasAttrString(obj
, "elt")) {
4722 tmp
= PyObject_GetAttrString(obj
, "elt");
4723 if (tmp
== NULL
) goto failed
;
4724 res
= obj2ast_expr(tmp
, &elt
, arena
);
4725 if (res
!= 0) goto failed
;
4729 PyErr_SetString(PyExc_TypeError
, "required field \"elt\" missing from ListComp");
4732 if (PyObject_HasAttrString(obj
, "generators")) {
4736 tmp
= PyObject_GetAttrString(obj
, "generators");
4737 if (tmp
== NULL
) goto failed
;
4738 if (!PyList_Check(tmp
)) {
4739 PyErr_Format(PyExc_TypeError
, "ListComp field \"generators\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4742 len
= PyList_GET_SIZE(tmp
);
4743 generators
= asdl_seq_new(len
, arena
);
4744 if (generators
== NULL
) goto failed
;
4745 for (i
= 0; i
< len
; i
++) {
4746 comprehension_ty value
;
4747 res
= obj2ast_comprehension(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4748 if (res
!= 0) goto failed
;
4749 asdl_seq_SET(generators
, i
, value
);
4754 PyErr_SetString(PyExc_TypeError
, "required field \"generators\" missing from ListComp");
4757 *out
= ListComp(elt
, generators
, lineno
, col_offset
, arena
);
4758 if (*out
== NULL
) goto failed
;
4761 if (PyObject_IsInstance(obj
, (PyObject
*)GeneratorExp_type
)) {
4763 asdl_seq
* generators
;
4765 if (PyObject_HasAttrString(obj
, "elt")) {
4767 tmp
= PyObject_GetAttrString(obj
, "elt");
4768 if (tmp
== NULL
) goto failed
;
4769 res
= obj2ast_expr(tmp
, &elt
, arena
);
4770 if (res
!= 0) goto failed
;
4774 PyErr_SetString(PyExc_TypeError
, "required field \"elt\" missing from GeneratorExp");
4777 if (PyObject_HasAttrString(obj
, "generators")) {
4781 tmp
= PyObject_GetAttrString(obj
, "generators");
4782 if (tmp
== NULL
) goto failed
;
4783 if (!PyList_Check(tmp
)) {
4784 PyErr_Format(PyExc_TypeError
, "GeneratorExp field \"generators\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4787 len
= PyList_GET_SIZE(tmp
);
4788 generators
= asdl_seq_new(len
, arena
);
4789 if (generators
== NULL
) goto failed
;
4790 for (i
= 0; i
< len
; i
++) {
4791 comprehension_ty value
;
4792 res
= obj2ast_comprehension(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4793 if (res
!= 0) goto failed
;
4794 asdl_seq_SET(generators
, i
, value
);
4799 PyErr_SetString(PyExc_TypeError
, "required field \"generators\" missing from GeneratorExp");
4802 *out
= GeneratorExp(elt
, generators
, lineno
, col_offset
, arena
);
4803 if (*out
== NULL
) goto failed
;
4806 if (PyObject_IsInstance(obj
, (PyObject
*)Yield_type
)) {
4809 if (PyObject_HasAttrString(obj
, "value")) {
4811 tmp
= PyObject_GetAttrString(obj
, "value");
4812 if (tmp
== NULL
) goto failed
;
4813 res
= obj2ast_expr(tmp
, &value
, arena
);
4814 if (res
!= 0) goto failed
;
4820 *out
= Yield(value
, lineno
, col_offset
, arena
);
4821 if (*out
== NULL
) goto failed
;
4824 if (PyObject_IsInstance(obj
, (PyObject
*)Compare_type
)) {
4827 asdl_seq
* comparators
;
4829 if (PyObject_HasAttrString(obj
, "left")) {
4831 tmp
= PyObject_GetAttrString(obj
, "left");
4832 if (tmp
== NULL
) goto failed
;
4833 res
= obj2ast_expr(tmp
, &left
, arena
);
4834 if (res
!= 0) goto failed
;
4838 PyErr_SetString(PyExc_TypeError
, "required field \"left\" missing from Compare");
4841 if (PyObject_HasAttrString(obj
, "ops")) {
4845 tmp
= PyObject_GetAttrString(obj
, "ops");
4846 if (tmp
== NULL
) goto failed
;
4847 if (!PyList_Check(tmp
)) {
4848 PyErr_Format(PyExc_TypeError
, "Compare field \"ops\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4851 len
= PyList_GET_SIZE(tmp
);
4852 ops
= asdl_int_seq_new(len
, arena
);
4853 if (ops
== NULL
) goto failed
;
4854 for (i
= 0; i
< len
; i
++) {
4856 res
= obj2ast_cmpop(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4857 if (res
!= 0) goto failed
;
4858 asdl_seq_SET(ops
, i
, value
);
4863 PyErr_SetString(PyExc_TypeError
, "required field \"ops\" missing from Compare");
4866 if (PyObject_HasAttrString(obj
, "comparators")) {
4870 tmp
= PyObject_GetAttrString(obj
, "comparators");
4871 if (tmp
== NULL
) goto failed
;
4872 if (!PyList_Check(tmp
)) {
4873 PyErr_Format(PyExc_TypeError
, "Compare field \"comparators\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4876 len
= PyList_GET_SIZE(tmp
);
4877 comparators
= asdl_seq_new(len
, arena
);
4878 if (comparators
== NULL
) goto failed
;
4879 for (i
= 0; i
< len
; i
++) {
4881 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4882 if (res
!= 0) goto failed
;
4883 asdl_seq_SET(comparators
, i
, value
);
4888 PyErr_SetString(PyExc_TypeError
, "required field \"comparators\" missing from Compare");
4891 *out
= Compare(left
, ops
, comparators
, lineno
, col_offset
,
4893 if (*out
== NULL
) goto failed
;
4896 if (PyObject_IsInstance(obj
, (PyObject
*)Call_type
)) {
4903 if (PyObject_HasAttrString(obj
, "func")) {
4905 tmp
= PyObject_GetAttrString(obj
, "func");
4906 if (tmp
== NULL
) goto failed
;
4907 res
= obj2ast_expr(tmp
, &func
, arena
);
4908 if (res
!= 0) goto failed
;
4912 PyErr_SetString(PyExc_TypeError
, "required field \"func\" missing from Call");
4915 if (PyObject_HasAttrString(obj
, "args")) {
4919 tmp
= PyObject_GetAttrString(obj
, "args");
4920 if (tmp
== NULL
) goto failed
;
4921 if (!PyList_Check(tmp
)) {
4922 PyErr_Format(PyExc_TypeError
, "Call field \"args\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4925 len
= PyList_GET_SIZE(tmp
);
4926 args
= asdl_seq_new(len
, arena
);
4927 if (args
== NULL
) goto failed
;
4928 for (i
= 0; i
< len
; i
++) {
4930 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4931 if (res
!= 0) goto failed
;
4932 asdl_seq_SET(args
, i
, value
);
4937 PyErr_SetString(PyExc_TypeError
, "required field \"args\" missing from Call");
4940 if (PyObject_HasAttrString(obj
, "keywords")) {
4944 tmp
= PyObject_GetAttrString(obj
, "keywords");
4945 if (tmp
== NULL
) goto failed
;
4946 if (!PyList_Check(tmp
)) {
4947 PyErr_Format(PyExc_TypeError
, "Call field \"keywords\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4950 len
= PyList_GET_SIZE(tmp
);
4951 keywords
= asdl_seq_new(len
, arena
);
4952 if (keywords
== NULL
) goto failed
;
4953 for (i
= 0; i
< len
; i
++) {
4955 res
= obj2ast_keyword(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4956 if (res
!= 0) goto failed
;
4957 asdl_seq_SET(keywords
, i
, value
);
4962 PyErr_SetString(PyExc_TypeError
, "required field \"keywords\" missing from Call");
4965 if (PyObject_HasAttrString(obj
, "starargs")) {
4967 tmp
= PyObject_GetAttrString(obj
, "starargs");
4968 if (tmp
== NULL
) goto failed
;
4969 res
= obj2ast_expr(tmp
, &starargs
, arena
);
4970 if (res
!= 0) goto failed
;
4976 if (PyObject_HasAttrString(obj
, "kwargs")) {
4978 tmp
= PyObject_GetAttrString(obj
, "kwargs");
4979 if (tmp
== NULL
) goto failed
;
4980 res
= obj2ast_expr(tmp
, &kwargs
, arena
);
4981 if (res
!= 0) goto failed
;
4987 *out
= Call(func
, args
, keywords
, starargs
, kwargs
, lineno
,
4989 if (*out
== NULL
) goto failed
;
4992 if (PyObject_IsInstance(obj
, (PyObject
*)Repr_type
)) {
4995 if (PyObject_HasAttrString(obj
, "value")) {
4997 tmp
= PyObject_GetAttrString(obj
, "value");
4998 if (tmp
== NULL
) goto failed
;
4999 res
= obj2ast_expr(tmp
, &value
, arena
);
5000 if (res
!= 0) goto failed
;
5004 PyErr_SetString(PyExc_TypeError
, "required field \"value\" missing from Repr");
5007 *out
= Repr(value
, lineno
, col_offset
, arena
);
5008 if (*out
== NULL
) goto failed
;
5011 if (PyObject_IsInstance(obj
, (PyObject
*)Num_type
)) {
5014 if (PyObject_HasAttrString(obj
, "n")) {
5016 tmp
= PyObject_GetAttrString(obj
, "n");
5017 if (tmp
== NULL
) goto failed
;
5018 res
= obj2ast_object(tmp
, &n
, arena
);
5019 if (res
!= 0) goto failed
;
5023 PyErr_SetString(PyExc_TypeError
, "required field \"n\" missing from Num");
5026 *out
= Num(n
, lineno
, col_offset
, arena
);
5027 if (*out
== NULL
) goto failed
;
5030 if (PyObject_IsInstance(obj
, (PyObject
*)Str_type
)) {
5033 if (PyObject_HasAttrString(obj
, "s")) {
5035 tmp
= PyObject_GetAttrString(obj
, "s");
5036 if (tmp
== NULL
) goto failed
;
5037 res
= obj2ast_string(tmp
, &s
, arena
);
5038 if (res
!= 0) goto failed
;
5042 PyErr_SetString(PyExc_TypeError
, "required field \"s\" missing from Str");
5045 *out
= Str(s
, lineno
, col_offset
, arena
);
5046 if (*out
== NULL
) goto failed
;
5049 if (PyObject_IsInstance(obj
, (PyObject
*)Attribute_type
)) {
5052 expr_context_ty ctx
;
5054 if (PyObject_HasAttrString(obj
, "value")) {
5056 tmp
= PyObject_GetAttrString(obj
, "value");
5057 if (tmp
== NULL
) goto failed
;
5058 res
= obj2ast_expr(tmp
, &value
, arena
);
5059 if (res
!= 0) goto failed
;
5063 PyErr_SetString(PyExc_TypeError
, "required field \"value\" missing from Attribute");
5066 if (PyObject_HasAttrString(obj
, "attr")) {
5068 tmp
= PyObject_GetAttrString(obj
, "attr");
5069 if (tmp
== NULL
) goto failed
;
5070 res
= obj2ast_identifier(tmp
, &attr
, arena
);
5071 if (res
!= 0) goto failed
;
5075 PyErr_SetString(PyExc_TypeError
, "required field \"attr\" missing from Attribute");
5078 if (PyObject_HasAttrString(obj
, "ctx")) {
5080 tmp
= PyObject_GetAttrString(obj
, "ctx");
5081 if (tmp
== NULL
) goto failed
;
5082 res
= obj2ast_expr_context(tmp
, &ctx
, arena
);
5083 if (res
!= 0) goto failed
;
5087 PyErr_SetString(PyExc_TypeError
, "required field \"ctx\" missing from Attribute");
5090 *out
= Attribute(value
, attr
, ctx
, lineno
, col_offset
, arena
);
5091 if (*out
== NULL
) goto failed
;
5094 if (PyObject_IsInstance(obj
, (PyObject
*)Subscript_type
)) {
5097 expr_context_ty ctx
;
5099 if (PyObject_HasAttrString(obj
, "value")) {
5101 tmp
= PyObject_GetAttrString(obj
, "value");
5102 if (tmp
== NULL
) goto failed
;
5103 res
= obj2ast_expr(tmp
, &value
, arena
);
5104 if (res
!= 0) goto failed
;
5108 PyErr_SetString(PyExc_TypeError
, "required field \"value\" missing from Subscript");
5111 if (PyObject_HasAttrString(obj
, "slice")) {
5113 tmp
= PyObject_GetAttrString(obj
, "slice");
5114 if (tmp
== NULL
) goto failed
;
5115 res
= obj2ast_slice(tmp
, &slice
, arena
);
5116 if (res
!= 0) goto failed
;
5120 PyErr_SetString(PyExc_TypeError
, "required field \"slice\" missing from Subscript");
5123 if (PyObject_HasAttrString(obj
, "ctx")) {
5125 tmp
= PyObject_GetAttrString(obj
, "ctx");
5126 if (tmp
== NULL
) goto failed
;
5127 res
= obj2ast_expr_context(tmp
, &ctx
, arena
);
5128 if (res
!= 0) goto failed
;
5132 PyErr_SetString(PyExc_TypeError
, "required field \"ctx\" missing from Subscript");
5135 *out
= Subscript(value
, slice
, ctx
, lineno
, col_offset
, arena
);
5136 if (*out
== NULL
) goto failed
;
5139 if (PyObject_IsInstance(obj
, (PyObject
*)Name_type
)) {
5141 expr_context_ty ctx
;
5143 if (PyObject_HasAttrString(obj
, "id")) {
5145 tmp
= PyObject_GetAttrString(obj
, "id");
5146 if (tmp
== NULL
) goto failed
;
5147 res
= obj2ast_identifier(tmp
, &id
, arena
);
5148 if (res
!= 0) goto failed
;
5152 PyErr_SetString(PyExc_TypeError
, "required field \"id\" missing from Name");
5155 if (PyObject_HasAttrString(obj
, "ctx")) {
5157 tmp
= PyObject_GetAttrString(obj
, "ctx");
5158 if (tmp
== NULL
) goto failed
;
5159 res
= obj2ast_expr_context(tmp
, &ctx
, arena
);
5160 if (res
!= 0) goto failed
;
5164 PyErr_SetString(PyExc_TypeError
, "required field \"ctx\" missing from Name");
5167 *out
= Name(id
, ctx
, lineno
, col_offset
, arena
);
5168 if (*out
== NULL
) goto failed
;
5171 if (PyObject_IsInstance(obj
, (PyObject
*)List_type
)) {
5173 expr_context_ty ctx
;
5175 if (PyObject_HasAttrString(obj
, "elts")) {
5179 tmp
= PyObject_GetAttrString(obj
, "elts");
5180 if (tmp
== NULL
) goto failed
;
5181 if (!PyList_Check(tmp
)) {
5182 PyErr_Format(PyExc_TypeError
, "List field \"elts\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5185 len
= PyList_GET_SIZE(tmp
);
5186 elts
= asdl_seq_new(len
, arena
);
5187 if (elts
== NULL
) goto failed
;
5188 for (i
= 0; i
< len
; i
++) {
5190 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5191 if (res
!= 0) goto failed
;
5192 asdl_seq_SET(elts
, i
, value
);
5197 PyErr_SetString(PyExc_TypeError
, "required field \"elts\" missing from List");
5200 if (PyObject_HasAttrString(obj
, "ctx")) {
5202 tmp
= PyObject_GetAttrString(obj
, "ctx");
5203 if (tmp
== NULL
) goto failed
;
5204 res
= obj2ast_expr_context(tmp
, &ctx
, arena
);
5205 if (res
!= 0) goto failed
;
5209 PyErr_SetString(PyExc_TypeError
, "required field \"ctx\" missing from List");
5212 *out
= List(elts
, ctx
, lineno
, col_offset
, arena
);
5213 if (*out
== NULL
) goto failed
;
5216 if (PyObject_IsInstance(obj
, (PyObject
*)Tuple_type
)) {
5218 expr_context_ty ctx
;
5220 if (PyObject_HasAttrString(obj
, "elts")) {
5224 tmp
= PyObject_GetAttrString(obj
, "elts");
5225 if (tmp
== NULL
) goto failed
;
5226 if (!PyList_Check(tmp
)) {
5227 PyErr_Format(PyExc_TypeError
, "Tuple field \"elts\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5230 len
= PyList_GET_SIZE(tmp
);
5231 elts
= asdl_seq_new(len
, arena
);
5232 if (elts
== NULL
) goto failed
;
5233 for (i
= 0; i
< len
; i
++) {
5235 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5236 if (res
!= 0) goto failed
;
5237 asdl_seq_SET(elts
, i
, value
);
5242 PyErr_SetString(PyExc_TypeError
, "required field \"elts\" missing from Tuple");
5245 if (PyObject_HasAttrString(obj
, "ctx")) {
5247 tmp
= PyObject_GetAttrString(obj
, "ctx");
5248 if (tmp
== NULL
) goto failed
;
5249 res
= obj2ast_expr_context(tmp
, &ctx
, arena
);
5250 if (res
!= 0) goto failed
;
5254 PyErr_SetString(PyExc_TypeError
, "required field \"ctx\" missing from Tuple");
5257 *out
= Tuple(elts
, ctx
, lineno
, col_offset
, arena
);
5258 if (*out
== NULL
) goto failed
;
5262 tmp
= PyObject_Repr(obj
);
5263 if (tmp
== NULL
) goto failed
;
5264 PyErr_Format(PyExc_TypeError
, "expected some sort of expr, but got %.400s", PyString_AS_STRING(tmp
));
5271 obj2ast_expr_context(PyObject
* obj
, expr_context_ty
* out
, PyArena
* arena
)
5273 PyObject
* tmp
= NULL
;
5275 if (PyObject_IsInstance(obj
, (PyObject
*)Load_type
)) {
5279 if (PyObject_IsInstance(obj
, (PyObject
*)Store_type
)) {
5283 if (PyObject_IsInstance(obj
, (PyObject
*)Del_type
)) {
5287 if (PyObject_IsInstance(obj
, (PyObject
*)AugLoad_type
)) {
5291 if (PyObject_IsInstance(obj
, (PyObject
*)AugStore_type
)) {
5295 if (PyObject_IsInstance(obj
, (PyObject
*)Param_type
)) {
5300 tmp
= PyObject_Repr(obj
);
5301 if (tmp
== NULL
) goto failed
;
5302 PyErr_Format(PyExc_TypeError
, "expected some sort of expr_context, but got %.400s", PyString_AS_STRING(tmp
));
5309 obj2ast_slice(PyObject
* obj
, slice_ty
* out
, PyArena
* arena
)
5311 PyObject
* tmp
= NULL
;
5314 if (obj
== Py_None
) {
5318 if (PyObject_IsInstance(obj
, (PyObject
*)Ellipsis_type
)) {
5320 *out
= Ellipsis(arena
);
5321 if (*out
== NULL
) goto failed
;
5324 if (PyObject_IsInstance(obj
, (PyObject
*)Slice_type
)) {
5329 if (PyObject_HasAttrString(obj
, "lower")) {
5331 tmp
= PyObject_GetAttrString(obj
, "lower");
5332 if (tmp
== NULL
) goto failed
;
5333 res
= obj2ast_expr(tmp
, &lower
, arena
);
5334 if (res
!= 0) goto failed
;
5340 if (PyObject_HasAttrString(obj
, "upper")) {
5342 tmp
= PyObject_GetAttrString(obj
, "upper");
5343 if (tmp
== NULL
) goto failed
;
5344 res
= obj2ast_expr(tmp
, &upper
, arena
);
5345 if (res
!= 0) goto failed
;
5351 if (PyObject_HasAttrString(obj
, "step")) {
5353 tmp
= PyObject_GetAttrString(obj
, "step");
5354 if (tmp
== NULL
) goto failed
;
5355 res
= obj2ast_expr(tmp
, &step
, arena
);
5356 if (res
!= 0) goto failed
;
5362 *out
= Slice(lower
, upper
, step
, arena
);
5363 if (*out
== NULL
) goto failed
;
5366 if (PyObject_IsInstance(obj
, (PyObject
*)ExtSlice_type
)) {
5369 if (PyObject_HasAttrString(obj
, "dims")) {
5373 tmp
= PyObject_GetAttrString(obj
, "dims");
5374 if (tmp
== NULL
) goto failed
;
5375 if (!PyList_Check(tmp
)) {
5376 PyErr_Format(PyExc_TypeError
, "ExtSlice field \"dims\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5379 len
= PyList_GET_SIZE(tmp
);
5380 dims
= asdl_seq_new(len
, arena
);
5381 if (dims
== NULL
) goto failed
;
5382 for (i
= 0; i
< len
; i
++) {
5384 res
= obj2ast_slice(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5385 if (res
!= 0) goto failed
;
5386 asdl_seq_SET(dims
, i
, value
);
5391 PyErr_SetString(PyExc_TypeError
, "required field \"dims\" missing from ExtSlice");
5394 *out
= ExtSlice(dims
, arena
);
5395 if (*out
== NULL
) goto failed
;
5398 if (PyObject_IsInstance(obj
, (PyObject
*)Index_type
)) {
5401 if (PyObject_HasAttrString(obj
, "value")) {
5403 tmp
= PyObject_GetAttrString(obj
, "value");
5404 if (tmp
== NULL
) goto failed
;
5405 res
= obj2ast_expr(tmp
, &value
, arena
);
5406 if (res
!= 0) goto failed
;
5410 PyErr_SetString(PyExc_TypeError
, "required field \"value\" missing from Index");
5413 *out
= Index(value
, arena
);
5414 if (*out
== NULL
) goto failed
;
5418 tmp
= PyObject_Repr(obj
);
5419 if (tmp
== NULL
) goto failed
;
5420 PyErr_Format(PyExc_TypeError
, "expected some sort of slice, but got %.400s", PyString_AS_STRING(tmp
));
5427 obj2ast_boolop(PyObject
* obj
, boolop_ty
* out
, PyArena
* arena
)
5429 PyObject
* tmp
= NULL
;
5431 if (PyObject_IsInstance(obj
, (PyObject
*)And_type
)) {
5435 if (PyObject_IsInstance(obj
, (PyObject
*)Or_type
)) {
5440 tmp
= PyObject_Repr(obj
);
5441 if (tmp
== NULL
) goto failed
;
5442 PyErr_Format(PyExc_TypeError
, "expected some sort of boolop, but got %.400s", PyString_AS_STRING(tmp
));
5449 obj2ast_operator(PyObject
* obj
, operator_ty
* out
, PyArena
* arena
)
5451 PyObject
* tmp
= NULL
;
5453 if (PyObject_IsInstance(obj
, (PyObject
*)Add_type
)) {
5457 if (PyObject_IsInstance(obj
, (PyObject
*)Sub_type
)) {
5461 if (PyObject_IsInstance(obj
, (PyObject
*)Mult_type
)) {
5465 if (PyObject_IsInstance(obj
, (PyObject
*)Div_type
)) {
5469 if (PyObject_IsInstance(obj
, (PyObject
*)Mod_type
)) {
5473 if (PyObject_IsInstance(obj
, (PyObject
*)Pow_type
)) {
5477 if (PyObject_IsInstance(obj
, (PyObject
*)LShift_type
)) {
5481 if (PyObject_IsInstance(obj
, (PyObject
*)RShift_type
)) {
5485 if (PyObject_IsInstance(obj
, (PyObject
*)BitOr_type
)) {
5489 if (PyObject_IsInstance(obj
, (PyObject
*)BitXor_type
)) {
5493 if (PyObject_IsInstance(obj
, (PyObject
*)BitAnd_type
)) {
5497 if (PyObject_IsInstance(obj
, (PyObject
*)FloorDiv_type
)) {
5502 tmp
= PyObject_Repr(obj
);
5503 if (tmp
== NULL
) goto failed
;
5504 PyErr_Format(PyExc_TypeError
, "expected some sort of operator, but got %.400s", PyString_AS_STRING(tmp
));
5511 obj2ast_unaryop(PyObject
* obj
, unaryop_ty
* out
, PyArena
* arena
)
5513 PyObject
* tmp
= NULL
;
5515 if (PyObject_IsInstance(obj
, (PyObject
*)Invert_type
)) {
5519 if (PyObject_IsInstance(obj
, (PyObject
*)Not_type
)) {
5523 if (PyObject_IsInstance(obj
, (PyObject
*)UAdd_type
)) {
5527 if (PyObject_IsInstance(obj
, (PyObject
*)USub_type
)) {
5532 tmp
= PyObject_Repr(obj
);
5533 if (tmp
== NULL
) goto failed
;
5534 PyErr_Format(PyExc_TypeError
, "expected some sort of unaryop, but got %.400s", PyString_AS_STRING(tmp
));
5541 obj2ast_cmpop(PyObject
* obj
, cmpop_ty
* out
, PyArena
* arena
)
5543 PyObject
* tmp
= NULL
;
5545 if (PyObject_IsInstance(obj
, (PyObject
*)Eq_type
)) {
5549 if (PyObject_IsInstance(obj
, (PyObject
*)NotEq_type
)) {
5553 if (PyObject_IsInstance(obj
, (PyObject
*)Lt_type
)) {
5557 if (PyObject_IsInstance(obj
, (PyObject
*)LtE_type
)) {
5561 if (PyObject_IsInstance(obj
, (PyObject
*)Gt_type
)) {
5565 if (PyObject_IsInstance(obj
, (PyObject
*)GtE_type
)) {
5569 if (PyObject_IsInstance(obj
, (PyObject
*)Is_type
)) {
5573 if (PyObject_IsInstance(obj
, (PyObject
*)IsNot_type
)) {
5577 if (PyObject_IsInstance(obj
, (PyObject
*)In_type
)) {
5581 if (PyObject_IsInstance(obj
, (PyObject
*)NotIn_type
)) {
5586 tmp
= PyObject_Repr(obj
);
5587 if (tmp
== NULL
) goto failed
;
5588 PyErr_Format(PyExc_TypeError
, "expected some sort of cmpop, but got %.400s", PyString_AS_STRING(tmp
));
5595 obj2ast_comprehension(PyObject
* obj
, comprehension_ty
* out
, PyArena
* arena
)
5597 PyObject
* tmp
= NULL
;
5602 if (PyObject_HasAttrString(obj
, "target")) {
5604 tmp
= PyObject_GetAttrString(obj
, "target");
5605 if (tmp
== NULL
) goto failed
;
5606 res
= obj2ast_expr(tmp
, &target
, arena
);
5607 if (res
!= 0) goto failed
;
5611 PyErr_SetString(PyExc_TypeError
, "required field \"target\" missing from comprehension");
5614 if (PyObject_HasAttrString(obj
, "iter")) {
5616 tmp
= PyObject_GetAttrString(obj
, "iter");
5617 if (tmp
== NULL
) goto failed
;
5618 res
= obj2ast_expr(tmp
, &iter
, arena
);
5619 if (res
!= 0) goto failed
;
5623 PyErr_SetString(PyExc_TypeError
, "required field \"iter\" missing from comprehension");
5626 if (PyObject_HasAttrString(obj
, "ifs")) {
5630 tmp
= PyObject_GetAttrString(obj
, "ifs");
5631 if (tmp
== NULL
) goto failed
;
5632 if (!PyList_Check(tmp
)) {
5633 PyErr_Format(PyExc_TypeError
, "comprehension field \"ifs\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5636 len
= PyList_GET_SIZE(tmp
);
5637 ifs
= asdl_seq_new(len
, arena
);
5638 if (ifs
== NULL
) goto failed
;
5639 for (i
= 0; i
< len
; i
++) {
5641 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5642 if (res
!= 0) goto failed
;
5643 asdl_seq_SET(ifs
, i
, value
);
5648 PyErr_SetString(PyExc_TypeError
, "required field \"ifs\" missing from comprehension");
5651 *out
= comprehension(target
, iter
, ifs
, arena
);
5659 obj2ast_excepthandler(PyObject
* obj
, excepthandler_ty
* out
, PyArena
* arena
)
5661 PyObject
* tmp
= NULL
;
5666 if (obj
== Py_None
) {
5670 if (PyObject_HasAttrString(obj
, "lineno")) {
5672 tmp
= PyObject_GetAttrString(obj
, "lineno");
5673 if (tmp
== NULL
) goto failed
;
5674 res
= obj2ast_int(tmp
, &lineno
, arena
);
5675 if (res
!= 0) goto failed
;
5679 PyErr_SetString(PyExc_TypeError
, "required field \"lineno\" missing from excepthandler");
5682 if (PyObject_HasAttrString(obj
, "col_offset")) {
5684 tmp
= PyObject_GetAttrString(obj
, "col_offset");
5685 if (tmp
== NULL
) goto failed
;
5686 res
= obj2ast_int(tmp
, &col_offset
, arena
);
5687 if (res
!= 0) goto failed
;
5691 PyErr_SetString(PyExc_TypeError
, "required field \"col_offset\" missing from excepthandler");
5694 if (PyObject_IsInstance(obj
, (PyObject
*)ExceptHandler_type
)) {
5699 if (PyObject_HasAttrString(obj
, "type")) {
5701 tmp
= PyObject_GetAttrString(obj
, "type");
5702 if (tmp
== NULL
) goto failed
;
5703 res
= obj2ast_expr(tmp
, &type
, arena
);
5704 if (res
!= 0) goto failed
;
5710 if (PyObject_HasAttrString(obj
, "name")) {
5712 tmp
= PyObject_GetAttrString(obj
, "name");
5713 if (tmp
== NULL
) goto failed
;
5714 res
= obj2ast_expr(tmp
, &name
, arena
);
5715 if (res
!= 0) goto failed
;
5721 if (PyObject_HasAttrString(obj
, "body")) {
5725 tmp
= PyObject_GetAttrString(obj
, "body");
5726 if (tmp
== NULL
) goto failed
;
5727 if (!PyList_Check(tmp
)) {
5728 PyErr_Format(PyExc_TypeError
, "ExceptHandler field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5731 len
= PyList_GET_SIZE(tmp
);
5732 body
= asdl_seq_new(len
, arena
);
5733 if (body
== NULL
) goto failed
;
5734 for (i
= 0; i
< len
; i
++) {
5736 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5737 if (res
!= 0) goto failed
;
5738 asdl_seq_SET(body
, i
, value
);
5743 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from ExceptHandler");
5746 *out
= ExceptHandler(type
, name
, body
, lineno
, col_offset
,
5748 if (*out
== NULL
) goto failed
;
5752 tmp
= PyObject_Repr(obj
);
5753 if (tmp
== NULL
) goto failed
;
5754 PyErr_Format(PyExc_TypeError
, "expected some sort of excepthandler, but got %.400s", PyString_AS_STRING(tmp
));
5761 obj2ast_arguments(PyObject
* obj
, arguments_ty
* out
, PyArena
* arena
)
5763 PyObject
* tmp
= NULL
;
5769 if (PyObject_HasAttrString(obj
, "args")) {
5773 tmp
= PyObject_GetAttrString(obj
, "args");
5774 if (tmp
== NULL
) goto failed
;
5775 if (!PyList_Check(tmp
)) {
5776 PyErr_Format(PyExc_TypeError
, "arguments field \"args\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5779 len
= PyList_GET_SIZE(tmp
);
5780 args
= asdl_seq_new(len
, arena
);
5781 if (args
== NULL
) goto failed
;
5782 for (i
= 0; i
< len
; i
++) {
5784 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5785 if (res
!= 0) goto failed
;
5786 asdl_seq_SET(args
, i
, value
);
5791 PyErr_SetString(PyExc_TypeError
, "required field \"args\" missing from arguments");
5794 if (PyObject_HasAttrString(obj
, "vararg")) {
5796 tmp
= PyObject_GetAttrString(obj
, "vararg");
5797 if (tmp
== NULL
) goto failed
;
5798 res
= obj2ast_identifier(tmp
, &vararg
, arena
);
5799 if (res
!= 0) goto failed
;
5805 if (PyObject_HasAttrString(obj
, "kwarg")) {
5807 tmp
= PyObject_GetAttrString(obj
, "kwarg");
5808 if (tmp
== NULL
) goto failed
;
5809 res
= obj2ast_identifier(tmp
, &kwarg
, arena
);
5810 if (res
!= 0) goto failed
;
5816 if (PyObject_HasAttrString(obj
, "defaults")) {
5820 tmp
= PyObject_GetAttrString(obj
, "defaults");
5821 if (tmp
== NULL
) goto failed
;
5822 if (!PyList_Check(tmp
)) {
5823 PyErr_Format(PyExc_TypeError
, "arguments field \"defaults\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5826 len
= PyList_GET_SIZE(tmp
);
5827 defaults
= asdl_seq_new(len
, arena
);
5828 if (defaults
== NULL
) goto failed
;
5829 for (i
= 0; i
< len
; i
++) {
5831 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5832 if (res
!= 0) goto failed
;
5833 asdl_seq_SET(defaults
, i
, value
);
5838 PyErr_SetString(PyExc_TypeError
, "required field \"defaults\" missing from arguments");
5841 *out
= arguments(args
, vararg
, kwarg
, defaults
, arena
);
5849 obj2ast_keyword(PyObject
* obj
, keyword_ty
* out
, PyArena
* arena
)
5851 PyObject
* tmp
= NULL
;
5855 if (PyObject_HasAttrString(obj
, "arg")) {
5857 tmp
= PyObject_GetAttrString(obj
, "arg");
5858 if (tmp
== NULL
) goto failed
;
5859 res
= obj2ast_identifier(tmp
, &arg
, arena
);
5860 if (res
!= 0) goto failed
;
5864 PyErr_SetString(PyExc_TypeError
, "required field \"arg\" missing from keyword");
5867 if (PyObject_HasAttrString(obj
, "value")) {
5869 tmp
= PyObject_GetAttrString(obj
, "value");
5870 if (tmp
== NULL
) goto failed
;
5871 res
= obj2ast_expr(tmp
, &value
, arena
);
5872 if (res
!= 0) goto failed
;
5876 PyErr_SetString(PyExc_TypeError
, "required field \"value\" missing from keyword");
5879 *out
= keyword(arg
, value
, arena
);
5887 obj2ast_alias(PyObject
* obj
, alias_ty
* out
, PyArena
* arena
)
5889 PyObject
* tmp
= NULL
;
5893 if (PyObject_HasAttrString(obj
, "name")) {
5895 tmp
= PyObject_GetAttrString(obj
, "name");
5896 if (tmp
== NULL
) goto failed
;
5897 res
= obj2ast_identifier(tmp
, &name
, arena
);
5898 if (res
!= 0) goto failed
;
5902 PyErr_SetString(PyExc_TypeError
, "required field \"name\" missing from alias");
5905 if (PyObject_HasAttrString(obj
, "asname")) {
5907 tmp
= PyObject_GetAttrString(obj
, "asname");
5908 if (tmp
== NULL
) goto failed
;
5909 res
= obj2ast_identifier(tmp
, &asname
, arena
);
5910 if (res
!= 0) goto failed
;
5916 *out
= alias(name
, asname
, arena
);
5928 if (!init_types()) return;
5929 m
= Py_InitModule3("_ast", NULL
, NULL
);
5931 d
= PyModule_GetDict(m
);
5932 if (PyDict_SetItemString(d
, "AST", (PyObject
*)&AST_type
) < 0) return;
5933 if (PyModule_AddIntConstant(m
, "PyCF_ONLY_AST", PyCF_ONLY_AST
) < 0)
5935 if (PyModule_AddStringConstant(m
, "__version__", "62047") < 0)
5937 if (PyDict_SetItemString(d
, "mod", (PyObject
*)mod_type
) < 0) return;
5938 if (PyDict_SetItemString(d
, "Module", (PyObject
*)Module_type
) < 0)
5940 if (PyDict_SetItemString(d
, "Interactive", (PyObject
*)Interactive_type
)
5942 if (PyDict_SetItemString(d
, "Expression", (PyObject
*)Expression_type
) <
5944 if (PyDict_SetItemString(d
, "Suite", (PyObject
*)Suite_type
) < 0) return;
5945 if (PyDict_SetItemString(d
, "stmt", (PyObject
*)stmt_type
) < 0) return;
5946 if (PyDict_SetItemString(d
, "FunctionDef", (PyObject
*)FunctionDef_type
)
5948 if (PyDict_SetItemString(d
, "ClassDef", (PyObject
*)ClassDef_type
) < 0)
5950 if (PyDict_SetItemString(d
, "Return", (PyObject
*)Return_type
) < 0)
5952 if (PyDict_SetItemString(d
, "Delete", (PyObject
*)Delete_type
) < 0)
5954 if (PyDict_SetItemString(d
, "Assign", (PyObject
*)Assign_type
) < 0)
5956 if (PyDict_SetItemString(d
, "AugAssign", (PyObject
*)AugAssign_type
) <
5958 if (PyDict_SetItemString(d
, "Print", (PyObject
*)Print_type
) < 0) return;
5959 if (PyDict_SetItemString(d
, "For", (PyObject
*)For_type
) < 0) return;
5960 if (PyDict_SetItemString(d
, "While", (PyObject
*)While_type
) < 0) return;
5961 if (PyDict_SetItemString(d
, "If", (PyObject
*)If_type
) < 0) return;
5962 if (PyDict_SetItemString(d
, "With", (PyObject
*)With_type
) < 0) return;
5963 if (PyDict_SetItemString(d
, "Raise", (PyObject
*)Raise_type
) < 0) return;
5964 if (PyDict_SetItemString(d
, "TryExcept", (PyObject
*)TryExcept_type
) <
5966 if (PyDict_SetItemString(d
, "TryFinally", (PyObject
*)TryFinally_type
) <
5968 if (PyDict_SetItemString(d
, "Assert", (PyObject
*)Assert_type
) < 0)
5970 if (PyDict_SetItemString(d
, "Import", (PyObject
*)Import_type
) < 0)
5972 if (PyDict_SetItemString(d
, "ImportFrom", (PyObject
*)ImportFrom_type
) <
5974 if (PyDict_SetItemString(d
, "Exec", (PyObject
*)Exec_type
) < 0) return;
5975 if (PyDict_SetItemString(d
, "Global", (PyObject
*)Global_type
) < 0)
5977 if (PyDict_SetItemString(d
, "Expr", (PyObject
*)Expr_type
) < 0) return;
5978 if (PyDict_SetItemString(d
, "Pass", (PyObject
*)Pass_type
) < 0) return;
5979 if (PyDict_SetItemString(d
, "Break", (PyObject
*)Break_type
) < 0) return;
5980 if (PyDict_SetItemString(d
, "Continue", (PyObject
*)Continue_type
) < 0)
5982 if (PyDict_SetItemString(d
, "expr", (PyObject
*)expr_type
) < 0) return;
5983 if (PyDict_SetItemString(d
, "BoolOp", (PyObject
*)BoolOp_type
) < 0)
5985 if (PyDict_SetItemString(d
, "BinOp", (PyObject
*)BinOp_type
) < 0) return;
5986 if (PyDict_SetItemString(d
, "UnaryOp", (PyObject
*)UnaryOp_type
) < 0)
5988 if (PyDict_SetItemString(d
, "Lambda", (PyObject
*)Lambda_type
) < 0)
5990 if (PyDict_SetItemString(d
, "IfExp", (PyObject
*)IfExp_type
) < 0) return;
5991 if (PyDict_SetItemString(d
, "Dict", (PyObject
*)Dict_type
) < 0) return;
5992 if (PyDict_SetItemString(d
, "ListComp", (PyObject
*)ListComp_type
) < 0)
5994 if (PyDict_SetItemString(d
, "GeneratorExp",
5995 (PyObject
*)GeneratorExp_type
) < 0) return;
5996 if (PyDict_SetItemString(d
, "Yield", (PyObject
*)Yield_type
) < 0) return;
5997 if (PyDict_SetItemString(d
, "Compare", (PyObject
*)Compare_type
) < 0)
5999 if (PyDict_SetItemString(d
, "Call", (PyObject
*)Call_type
) < 0) return;
6000 if (PyDict_SetItemString(d
, "Repr", (PyObject
*)Repr_type
) < 0) return;
6001 if (PyDict_SetItemString(d
, "Num", (PyObject
*)Num_type
) < 0) return;
6002 if (PyDict_SetItemString(d
, "Str", (PyObject
*)Str_type
) < 0) return;
6003 if (PyDict_SetItemString(d
, "Attribute", (PyObject
*)Attribute_type
) <
6005 if (PyDict_SetItemString(d
, "Subscript", (PyObject
*)Subscript_type
) <
6007 if (PyDict_SetItemString(d
, "Name", (PyObject
*)Name_type
) < 0) return;
6008 if (PyDict_SetItemString(d
, "List", (PyObject
*)List_type
) < 0) return;
6009 if (PyDict_SetItemString(d
, "Tuple", (PyObject
*)Tuple_type
) < 0) return;
6010 if (PyDict_SetItemString(d
, "expr_context",
6011 (PyObject
*)expr_context_type
) < 0) return;
6012 if (PyDict_SetItemString(d
, "Load", (PyObject
*)Load_type
) < 0) return;
6013 if (PyDict_SetItemString(d
, "Store", (PyObject
*)Store_type
) < 0) return;
6014 if (PyDict_SetItemString(d
, "Del", (PyObject
*)Del_type
) < 0) return;
6015 if (PyDict_SetItemString(d
, "AugLoad", (PyObject
*)AugLoad_type
) < 0)
6017 if (PyDict_SetItemString(d
, "AugStore", (PyObject
*)AugStore_type
) < 0)
6019 if (PyDict_SetItemString(d
, "Param", (PyObject
*)Param_type
) < 0) return;
6020 if (PyDict_SetItemString(d
, "slice", (PyObject
*)slice_type
) < 0) return;
6021 if (PyDict_SetItemString(d
, "Ellipsis", (PyObject
*)Ellipsis_type
) < 0)
6023 if (PyDict_SetItemString(d
, "Slice", (PyObject
*)Slice_type
) < 0) return;
6024 if (PyDict_SetItemString(d
, "ExtSlice", (PyObject
*)ExtSlice_type
) < 0)
6026 if (PyDict_SetItemString(d
, "Index", (PyObject
*)Index_type
) < 0) return;
6027 if (PyDict_SetItemString(d
, "boolop", (PyObject
*)boolop_type
) < 0)
6029 if (PyDict_SetItemString(d
, "And", (PyObject
*)And_type
) < 0) return;
6030 if (PyDict_SetItemString(d
, "Or", (PyObject
*)Or_type
) < 0) return;
6031 if (PyDict_SetItemString(d
, "operator", (PyObject
*)operator_type
) < 0)
6033 if (PyDict_SetItemString(d
, "Add", (PyObject
*)Add_type
) < 0) return;
6034 if (PyDict_SetItemString(d
, "Sub", (PyObject
*)Sub_type
) < 0) return;
6035 if (PyDict_SetItemString(d
, "Mult", (PyObject
*)Mult_type
) < 0) return;
6036 if (PyDict_SetItemString(d
, "Div", (PyObject
*)Div_type
) < 0) return;
6037 if (PyDict_SetItemString(d
, "Mod", (PyObject
*)Mod_type
) < 0) return;
6038 if (PyDict_SetItemString(d
, "Pow", (PyObject
*)Pow_type
) < 0) return;
6039 if (PyDict_SetItemString(d
, "LShift", (PyObject
*)LShift_type
) < 0)
6041 if (PyDict_SetItemString(d
, "RShift", (PyObject
*)RShift_type
) < 0)
6043 if (PyDict_SetItemString(d
, "BitOr", (PyObject
*)BitOr_type
) < 0) return;
6044 if (PyDict_SetItemString(d
, "BitXor", (PyObject
*)BitXor_type
) < 0)
6046 if (PyDict_SetItemString(d
, "BitAnd", (PyObject
*)BitAnd_type
) < 0)
6048 if (PyDict_SetItemString(d
, "FloorDiv", (PyObject
*)FloorDiv_type
) < 0)
6050 if (PyDict_SetItemString(d
, "unaryop", (PyObject
*)unaryop_type
) < 0)
6052 if (PyDict_SetItemString(d
, "Invert", (PyObject
*)Invert_type
) < 0)
6054 if (PyDict_SetItemString(d
, "Not", (PyObject
*)Not_type
) < 0) return;
6055 if (PyDict_SetItemString(d
, "UAdd", (PyObject
*)UAdd_type
) < 0) return;
6056 if (PyDict_SetItemString(d
, "USub", (PyObject
*)USub_type
) < 0) return;
6057 if (PyDict_SetItemString(d
, "cmpop", (PyObject
*)cmpop_type
) < 0) return;
6058 if (PyDict_SetItemString(d
, "Eq", (PyObject
*)Eq_type
) < 0) return;
6059 if (PyDict_SetItemString(d
, "NotEq", (PyObject
*)NotEq_type
) < 0) return;
6060 if (PyDict_SetItemString(d
, "Lt", (PyObject
*)Lt_type
) < 0) return;
6061 if (PyDict_SetItemString(d
, "LtE", (PyObject
*)LtE_type
) < 0) return;
6062 if (PyDict_SetItemString(d
, "Gt", (PyObject
*)Gt_type
) < 0) return;
6063 if (PyDict_SetItemString(d
, "GtE", (PyObject
*)GtE_type
) < 0) return;
6064 if (PyDict_SetItemString(d
, "Is", (PyObject
*)Is_type
) < 0) return;
6065 if (PyDict_SetItemString(d
, "IsNot", (PyObject
*)IsNot_type
) < 0) return;
6066 if (PyDict_SetItemString(d
, "In", (PyObject
*)In_type
) < 0) return;
6067 if (PyDict_SetItemString(d
, "NotIn", (PyObject
*)NotIn_type
) < 0) return;
6068 if (PyDict_SetItemString(d
, "comprehension",
6069 (PyObject
*)comprehension_type
) < 0) return;
6070 if (PyDict_SetItemString(d
, "excepthandler",
6071 (PyObject
*)excepthandler_type
) < 0) return;
6072 if (PyDict_SetItemString(d
, "ExceptHandler",
6073 (PyObject
*)ExceptHandler_type
) < 0) return;
6074 if (PyDict_SetItemString(d
, "arguments", (PyObject
*)arguments_type
) <
6076 if (PyDict_SetItemString(d
, "keyword", (PyObject
*)keyword_type
) < 0)
6078 if (PyDict_SetItemString(d
, "alias", (PyObject
*)alias_type
) < 0) return;
6082 PyObject
* PyAST_mod2obj(mod_ty t
)
6085 return ast2obj_mod(t
);
6088 /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */
6089 mod_ty
PyAST_obj2mod(PyObject
* ast
, PyArena
* arena
, int mode
)
6092 PyObject
*req_type
[] = {(PyObject
*)Module_type
, (PyObject
*)Expression_type
,
6093 (PyObject
*)Interactive_type
};
6094 char *req_name
[] = {"Module", "Expression", "Interactive"};
6095 assert(0 <= mode
&& mode
<= 2);
6099 if (!PyObject_IsInstance(ast
, req_type
[mode
])) {
6100 PyErr_Format(PyExc_TypeError
, "expected %s node, got %.400s",
6101 req_name
[mode
], Py_TYPE(ast
)->tp_name
);
6104 if (obj2ast_mod(ast
, &res
, arena
) != 0)
6110 int PyAST_Check(PyObject
* obj
)
6113 return PyObject_IsInstance(obj
, (PyObject
*)&AST_type
);