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 "%zd 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
);
618 static int add_ast_fields(void)
620 PyObject
*empty_tuple
, *d
;
621 if (PyType_Ready(&AST_type
) < 0)
623 d
= AST_type
.tp_dict
;
624 empty_tuple
= PyTuple_New(0);
626 PyDict_SetItemString(d
, "_fields", empty_tuple
) < 0 ||
627 PyDict_SetItemString(d
, "_attributes", empty_tuple
) < 0) {
628 Py_XDECREF(empty_tuple
);
631 Py_DECREF(empty_tuple
);
636 static int init_types(void)
638 static int initialized
;
639 if (initialized
) return 1;
640 if (add_ast_fields() < 0) return 0;
641 mod_type
= make_type("mod", &AST_type
, NULL
, 0);
642 if (!mod_type
) return 0;
643 if (!add_attributes(mod_type
, NULL
, 0)) return 0;
644 Module_type
= make_type("Module", mod_type
, Module_fields
, 1);
645 if (!Module_type
) return 0;
646 Interactive_type
= make_type("Interactive", mod_type
,
647 Interactive_fields
, 1);
648 if (!Interactive_type
) return 0;
649 Expression_type
= make_type("Expression", mod_type
, Expression_fields
,
651 if (!Expression_type
) return 0;
652 Suite_type
= make_type("Suite", mod_type
, Suite_fields
, 1);
653 if (!Suite_type
) return 0;
654 stmt_type
= make_type("stmt", &AST_type
, NULL
, 0);
655 if (!stmt_type
) return 0;
656 if (!add_attributes(stmt_type
, stmt_attributes
, 2)) return 0;
657 FunctionDef_type
= make_type("FunctionDef", stmt_type
,
658 FunctionDef_fields
, 4);
659 if (!FunctionDef_type
) return 0;
660 ClassDef_type
= make_type("ClassDef", stmt_type
, ClassDef_fields
, 4);
661 if (!ClassDef_type
) return 0;
662 Return_type
= make_type("Return", stmt_type
, Return_fields
, 1);
663 if (!Return_type
) return 0;
664 Delete_type
= make_type("Delete", stmt_type
, Delete_fields
, 1);
665 if (!Delete_type
) return 0;
666 Assign_type
= make_type("Assign", stmt_type
, Assign_fields
, 2);
667 if (!Assign_type
) return 0;
668 AugAssign_type
= make_type("AugAssign", stmt_type
, AugAssign_fields
, 3);
669 if (!AugAssign_type
) return 0;
670 Print_type
= make_type("Print", stmt_type
, Print_fields
, 3);
671 if (!Print_type
) return 0;
672 For_type
= make_type("For", stmt_type
, For_fields
, 4);
673 if (!For_type
) return 0;
674 While_type
= make_type("While", stmt_type
, While_fields
, 3);
675 if (!While_type
) return 0;
676 If_type
= make_type("If", stmt_type
, If_fields
, 3);
677 if (!If_type
) return 0;
678 With_type
= make_type("With", stmt_type
, With_fields
, 3);
679 if (!With_type
) return 0;
680 Raise_type
= make_type("Raise", stmt_type
, Raise_fields
, 3);
681 if (!Raise_type
) return 0;
682 TryExcept_type
= make_type("TryExcept", stmt_type
, TryExcept_fields
, 3);
683 if (!TryExcept_type
) return 0;
684 TryFinally_type
= make_type("TryFinally", stmt_type
, TryFinally_fields
,
686 if (!TryFinally_type
) return 0;
687 Assert_type
= make_type("Assert", stmt_type
, Assert_fields
, 2);
688 if (!Assert_type
) return 0;
689 Import_type
= make_type("Import", stmt_type
, Import_fields
, 1);
690 if (!Import_type
) return 0;
691 ImportFrom_type
= make_type("ImportFrom", stmt_type
, ImportFrom_fields
,
693 if (!ImportFrom_type
) return 0;
694 Exec_type
= make_type("Exec", stmt_type
, Exec_fields
, 3);
695 if (!Exec_type
) return 0;
696 Global_type
= make_type("Global", stmt_type
, Global_fields
, 1);
697 if (!Global_type
) return 0;
698 Expr_type
= make_type("Expr", stmt_type
, Expr_fields
, 1);
699 if (!Expr_type
) return 0;
700 Pass_type
= make_type("Pass", stmt_type
, NULL
, 0);
701 if (!Pass_type
) return 0;
702 Break_type
= make_type("Break", stmt_type
, NULL
, 0);
703 if (!Break_type
) return 0;
704 Continue_type
= make_type("Continue", stmt_type
, NULL
, 0);
705 if (!Continue_type
) return 0;
706 expr_type
= make_type("expr", &AST_type
, NULL
, 0);
707 if (!expr_type
) return 0;
708 if (!add_attributes(expr_type
, expr_attributes
, 2)) return 0;
709 BoolOp_type
= make_type("BoolOp", expr_type
, BoolOp_fields
, 2);
710 if (!BoolOp_type
) return 0;
711 BinOp_type
= make_type("BinOp", expr_type
, BinOp_fields
, 3);
712 if (!BinOp_type
) return 0;
713 UnaryOp_type
= make_type("UnaryOp", expr_type
, UnaryOp_fields
, 2);
714 if (!UnaryOp_type
) return 0;
715 Lambda_type
= make_type("Lambda", expr_type
, Lambda_fields
, 2);
716 if (!Lambda_type
) return 0;
717 IfExp_type
= make_type("IfExp", expr_type
, IfExp_fields
, 3);
718 if (!IfExp_type
) return 0;
719 Dict_type
= make_type("Dict", expr_type
, Dict_fields
, 2);
720 if (!Dict_type
) return 0;
721 ListComp_type
= make_type("ListComp", expr_type
, ListComp_fields
, 2);
722 if (!ListComp_type
) return 0;
723 GeneratorExp_type
= make_type("GeneratorExp", expr_type
,
724 GeneratorExp_fields
, 2);
725 if (!GeneratorExp_type
) return 0;
726 Yield_type
= make_type("Yield", expr_type
, Yield_fields
, 1);
727 if (!Yield_type
) return 0;
728 Compare_type
= make_type("Compare", expr_type
, Compare_fields
, 3);
729 if (!Compare_type
) return 0;
730 Call_type
= make_type("Call", expr_type
, Call_fields
, 5);
731 if (!Call_type
) return 0;
732 Repr_type
= make_type("Repr", expr_type
, Repr_fields
, 1);
733 if (!Repr_type
) return 0;
734 Num_type
= make_type("Num", expr_type
, Num_fields
, 1);
735 if (!Num_type
) return 0;
736 Str_type
= make_type("Str", expr_type
, Str_fields
, 1);
737 if (!Str_type
) return 0;
738 Attribute_type
= make_type("Attribute", expr_type
, Attribute_fields
, 3);
739 if (!Attribute_type
) return 0;
740 Subscript_type
= make_type("Subscript", expr_type
, Subscript_fields
, 3);
741 if (!Subscript_type
) return 0;
742 Name_type
= make_type("Name", expr_type
, Name_fields
, 2);
743 if (!Name_type
) return 0;
744 List_type
= make_type("List", expr_type
, List_fields
, 2);
745 if (!List_type
) return 0;
746 Tuple_type
= make_type("Tuple", expr_type
, Tuple_fields
, 2);
747 if (!Tuple_type
) return 0;
748 expr_context_type
= make_type("expr_context", &AST_type
, NULL
, 0);
749 if (!expr_context_type
) return 0;
750 if (!add_attributes(expr_context_type
, NULL
, 0)) return 0;
751 Load_type
= make_type("Load", expr_context_type
, NULL
, 0);
752 if (!Load_type
) return 0;
753 Load_singleton
= PyType_GenericNew(Load_type
, NULL
, NULL
);
754 if (!Load_singleton
) return 0;
755 Store_type
= make_type("Store", expr_context_type
, NULL
, 0);
756 if (!Store_type
) return 0;
757 Store_singleton
= PyType_GenericNew(Store_type
, NULL
, NULL
);
758 if (!Store_singleton
) return 0;
759 Del_type
= make_type("Del", expr_context_type
, NULL
, 0);
760 if (!Del_type
) return 0;
761 Del_singleton
= PyType_GenericNew(Del_type
, NULL
, NULL
);
762 if (!Del_singleton
) return 0;
763 AugLoad_type
= make_type("AugLoad", expr_context_type
, NULL
, 0);
764 if (!AugLoad_type
) return 0;
765 AugLoad_singleton
= PyType_GenericNew(AugLoad_type
, NULL
, NULL
);
766 if (!AugLoad_singleton
) return 0;
767 AugStore_type
= make_type("AugStore", expr_context_type
, NULL
, 0);
768 if (!AugStore_type
) return 0;
769 AugStore_singleton
= PyType_GenericNew(AugStore_type
, NULL
, NULL
);
770 if (!AugStore_singleton
) return 0;
771 Param_type
= make_type("Param", expr_context_type
, NULL
, 0);
772 if (!Param_type
) return 0;
773 Param_singleton
= PyType_GenericNew(Param_type
, NULL
, NULL
);
774 if (!Param_singleton
) return 0;
775 slice_type
= make_type("slice", &AST_type
, NULL
, 0);
776 if (!slice_type
) return 0;
777 if (!add_attributes(slice_type
, NULL
, 0)) return 0;
778 Ellipsis_type
= make_type("Ellipsis", slice_type
, NULL
, 0);
779 if (!Ellipsis_type
) return 0;
780 Slice_type
= make_type("Slice", slice_type
, Slice_fields
, 3);
781 if (!Slice_type
) return 0;
782 ExtSlice_type
= make_type("ExtSlice", slice_type
, ExtSlice_fields
, 1);
783 if (!ExtSlice_type
) return 0;
784 Index_type
= make_type("Index", slice_type
, Index_fields
, 1);
785 if (!Index_type
) return 0;
786 boolop_type
= make_type("boolop", &AST_type
, NULL
, 0);
787 if (!boolop_type
) return 0;
788 if (!add_attributes(boolop_type
, NULL
, 0)) return 0;
789 And_type
= make_type("And", boolop_type
, NULL
, 0);
790 if (!And_type
) return 0;
791 And_singleton
= PyType_GenericNew(And_type
, NULL
, NULL
);
792 if (!And_singleton
) return 0;
793 Or_type
= make_type("Or", boolop_type
, NULL
, 0);
794 if (!Or_type
) return 0;
795 Or_singleton
= PyType_GenericNew(Or_type
, NULL
, NULL
);
796 if (!Or_singleton
) return 0;
797 operator_type
= make_type("operator", &AST_type
, NULL
, 0);
798 if (!operator_type
) return 0;
799 if (!add_attributes(operator_type
, NULL
, 0)) return 0;
800 Add_type
= make_type("Add", operator_type
, NULL
, 0);
801 if (!Add_type
) return 0;
802 Add_singleton
= PyType_GenericNew(Add_type
, NULL
, NULL
);
803 if (!Add_singleton
) return 0;
804 Sub_type
= make_type("Sub", operator_type
, NULL
, 0);
805 if (!Sub_type
) return 0;
806 Sub_singleton
= PyType_GenericNew(Sub_type
, NULL
, NULL
);
807 if (!Sub_singleton
) return 0;
808 Mult_type
= make_type("Mult", operator_type
, NULL
, 0);
809 if (!Mult_type
) return 0;
810 Mult_singleton
= PyType_GenericNew(Mult_type
, NULL
, NULL
);
811 if (!Mult_singleton
) return 0;
812 Div_type
= make_type("Div", operator_type
, NULL
, 0);
813 if (!Div_type
) return 0;
814 Div_singleton
= PyType_GenericNew(Div_type
, NULL
, NULL
);
815 if (!Div_singleton
) return 0;
816 Mod_type
= make_type("Mod", operator_type
, NULL
, 0);
817 if (!Mod_type
) return 0;
818 Mod_singleton
= PyType_GenericNew(Mod_type
, NULL
, NULL
);
819 if (!Mod_singleton
) return 0;
820 Pow_type
= make_type("Pow", operator_type
, NULL
, 0);
821 if (!Pow_type
) return 0;
822 Pow_singleton
= PyType_GenericNew(Pow_type
, NULL
, NULL
);
823 if (!Pow_singleton
) return 0;
824 LShift_type
= make_type("LShift", operator_type
, NULL
, 0);
825 if (!LShift_type
) return 0;
826 LShift_singleton
= PyType_GenericNew(LShift_type
, NULL
, NULL
);
827 if (!LShift_singleton
) return 0;
828 RShift_type
= make_type("RShift", operator_type
, NULL
, 0);
829 if (!RShift_type
) return 0;
830 RShift_singleton
= PyType_GenericNew(RShift_type
, NULL
, NULL
);
831 if (!RShift_singleton
) return 0;
832 BitOr_type
= make_type("BitOr", operator_type
, NULL
, 0);
833 if (!BitOr_type
) return 0;
834 BitOr_singleton
= PyType_GenericNew(BitOr_type
, NULL
, NULL
);
835 if (!BitOr_singleton
) return 0;
836 BitXor_type
= make_type("BitXor", operator_type
, NULL
, 0);
837 if (!BitXor_type
) return 0;
838 BitXor_singleton
= PyType_GenericNew(BitXor_type
, NULL
, NULL
);
839 if (!BitXor_singleton
) return 0;
840 BitAnd_type
= make_type("BitAnd", operator_type
, NULL
, 0);
841 if (!BitAnd_type
) return 0;
842 BitAnd_singleton
= PyType_GenericNew(BitAnd_type
, NULL
, NULL
);
843 if (!BitAnd_singleton
) return 0;
844 FloorDiv_type
= make_type("FloorDiv", operator_type
, NULL
, 0);
845 if (!FloorDiv_type
) return 0;
846 FloorDiv_singleton
= PyType_GenericNew(FloorDiv_type
, NULL
, NULL
);
847 if (!FloorDiv_singleton
) return 0;
848 unaryop_type
= make_type("unaryop", &AST_type
, NULL
, 0);
849 if (!unaryop_type
) return 0;
850 if (!add_attributes(unaryop_type
, NULL
, 0)) return 0;
851 Invert_type
= make_type("Invert", unaryop_type
, NULL
, 0);
852 if (!Invert_type
) return 0;
853 Invert_singleton
= PyType_GenericNew(Invert_type
, NULL
, NULL
);
854 if (!Invert_singleton
) return 0;
855 Not_type
= make_type("Not", unaryop_type
, NULL
, 0);
856 if (!Not_type
) return 0;
857 Not_singleton
= PyType_GenericNew(Not_type
, NULL
, NULL
);
858 if (!Not_singleton
) return 0;
859 UAdd_type
= make_type("UAdd", unaryop_type
, NULL
, 0);
860 if (!UAdd_type
) return 0;
861 UAdd_singleton
= PyType_GenericNew(UAdd_type
, NULL
, NULL
);
862 if (!UAdd_singleton
) return 0;
863 USub_type
= make_type("USub", unaryop_type
, NULL
, 0);
864 if (!USub_type
) return 0;
865 USub_singleton
= PyType_GenericNew(USub_type
, NULL
, NULL
);
866 if (!USub_singleton
) return 0;
867 cmpop_type
= make_type("cmpop", &AST_type
, NULL
, 0);
868 if (!cmpop_type
) return 0;
869 if (!add_attributes(cmpop_type
, NULL
, 0)) return 0;
870 Eq_type
= make_type("Eq", cmpop_type
, NULL
, 0);
871 if (!Eq_type
) return 0;
872 Eq_singleton
= PyType_GenericNew(Eq_type
, NULL
, NULL
);
873 if (!Eq_singleton
) return 0;
874 NotEq_type
= make_type("NotEq", cmpop_type
, NULL
, 0);
875 if (!NotEq_type
) return 0;
876 NotEq_singleton
= PyType_GenericNew(NotEq_type
, NULL
, NULL
);
877 if (!NotEq_singleton
) return 0;
878 Lt_type
= make_type("Lt", cmpop_type
, NULL
, 0);
879 if (!Lt_type
) return 0;
880 Lt_singleton
= PyType_GenericNew(Lt_type
, NULL
, NULL
);
881 if (!Lt_singleton
) return 0;
882 LtE_type
= make_type("LtE", cmpop_type
, NULL
, 0);
883 if (!LtE_type
) return 0;
884 LtE_singleton
= PyType_GenericNew(LtE_type
, NULL
, NULL
);
885 if (!LtE_singleton
) return 0;
886 Gt_type
= make_type("Gt", cmpop_type
, NULL
, 0);
887 if (!Gt_type
) return 0;
888 Gt_singleton
= PyType_GenericNew(Gt_type
, NULL
, NULL
);
889 if (!Gt_singleton
) return 0;
890 GtE_type
= make_type("GtE", cmpop_type
, NULL
, 0);
891 if (!GtE_type
) return 0;
892 GtE_singleton
= PyType_GenericNew(GtE_type
, NULL
, NULL
);
893 if (!GtE_singleton
) return 0;
894 Is_type
= make_type("Is", cmpop_type
, NULL
, 0);
895 if (!Is_type
) return 0;
896 Is_singleton
= PyType_GenericNew(Is_type
, NULL
, NULL
);
897 if (!Is_singleton
) return 0;
898 IsNot_type
= make_type("IsNot", cmpop_type
, NULL
, 0);
899 if (!IsNot_type
) return 0;
900 IsNot_singleton
= PyType_GenericNew(IsNot_type
, NULL
, NULL
);
901 if (!IsNot_singleton
) return 0;
902 In_type
= make_type("In", cmpop_type
, NULL
, 0);
903 if (!In_type
) return 0;
904 In_singleton
= PyType_GenericNew(In_type
, NULL
, NULL
);
905 if (!In_singleton
) return 0;
906 NotIn_type
= make_type("NotIn", cmpop_type
, NULL
, 0);
907 if (!NotIn_type
) return 0;
908 NotIn_singleton
= PyType_GenericNew(NotIn_type
, NULL
, NULL
);
909 if (!NotIn_singleton
) return 0;
910 comprehension_type
= make_type("comprehension", &AST_type
,
911 comprehension_fields
, 3);
912 if (!comprehension_type
) return 0;
913 excepthandler_type
= make_type("excepthandler", &AST_type
, NULL
, 0);
914 if (!excepthandler_type
) return 0;
915 if (!add_attributes(excepthandler_type
, excepthandler_attributes
, 2))
917 ExceptHandler_type
= make_type("ExceptHandler", excepthandler_type
,
918 ExceptHandler_fields
, 3);
919 if (!ExceptHandler_type
) return 0;
920 arguments_type
= make_type("arguments", &AST_type
, arguments_fields
, 4);
921 if (!arguments_type
) return 0;
922 keyword_type
= make_type("keyword", &AST_type
, keyword_fields
, 2);
923 if (!keyword_type
) return 0;
924 alias_type
= make_type("alias", &AST_type
, alias_fields
, 2);
925 if (!alias_type
) return 0;
930 static int obj2ast_mod(PyObject
* obj
, mod_ty
* out
, PyArena
* arena
);
931 static int obj2ast_stmt(PyObject
* obj
, stmt_ty
* out
, PyArena
* arena
);
932 static int obj2ast_expr(PyObject
* obj
, expr_ty
* out
, PyArena
* arena
);
933 static int obj2ast_expr_context(PyObject
* obj
, expr_context_ty
* out
, PyArena
*
935 static int obj2ast_slice(PyObject
* obj
, slice_ty
* out
, PyArena
* arena
);
936 static int obj2ast_boolop(PyObject
* obj
, boolop_ty
* out
, PyArena
* arena
);
937 static int obj2ast_operator(PyObject
* obj
, operator_ty
* out
, PyArena
* arena
);
938 static int obj2ast_unaryop(PyObject
* obj
, unaryop_ty
* out
, PyArena
* arena
);
939 static int obj2ast_cmpop(PyObject
* obj
, cmpop_ty
* out
, PyArena
* arena
);
940 static int obj2ast_comprehension(PyObject
* obj
, comprehension_ty
* out
, PyArena
*
942 static int obj2ast_excepthandler(PyObject
* obj
, excepthandler_ty
* out
, PyArena
*
944 static int obj2ast_arguments(PyObject
* obj
, arguments_ty
* out
, PyArena
* arena
);
945 static int obj2ast_keyword(PyObject
* obj
, keyword_ty
* out
, PyArena
* arena
);
946 static int obj2ast_alias(PyObject
* obj
, alias_ty
* out
, PyArena
* arena
);
949 Module(asdl_seq
* body
, PyArena
*arena
)
952 p
= (mod_ty
)PyArena_Malloc(arena
, sizeof(*p
));
955 p
->kind
= Module_kind
;
956 p
->v
.Module
.body
= body
;
961 Interactive(asdl_seq
* body
, PyArena
*arena
)
964 p
= (mod_ty
)PyArena_Malloc(arena
, sizeof(*p
));
967 p
->kind
= Interactive_kind
;
968 p
->v
.Interactive
.body
= body
;
973 Expression(expr_ty body
, PyArena
*arena
)
977 PyErr_SetString(PyExc_ValueError
,
978 "field body is required for Expression");
981 p
= (mod_ty
)PyArena_Malloc(arena
, sizeof(*p
));
984 p
->kind
= Expression_kind
;
985 p
->v
.Expression
.body
= body
;
990 Suite(asdl_seq
* body
, PyArena
*arena
)
993 p
= (mod_ty
)PyArena_Malloc(arena
, sizeof(*p
));
996 p
->kind
= Suite_kind
;
997 p
->v
.Suite
.body
= body
;
1002 FunctionDef(identifier name
, arguments_ty args
, asdl_seq
* body
, asdl_seq
*
1003 decorator_list
, int lineno
, int col_offset
, PyArena
*arena
)
1007 PyErr_SetString(PyExc_ValueError
,
1008 "field name is required for FunctionDef");
1012 PyErr_SetString(PyExc_ValueError
,
1013 "field args is required for FunctionDef");
1016 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1019 p
->kind
= FunctionDef_kind
;
1020 p
->v
.FunctionDef
.name
= name
;
1021 p
->v
.FunctionDef
.args
= args
;
1022 p
->v
.FunctionDef
.body
= body
;
1023 p
->v
.FunctionDef
.decorator_list
= decorator_list
;
1025 p
->col_offset
= col_offset
;
1030 ClassDef(identifier name
, asdl_seq
* bases
, asdl_seq
* body
, asdl_seq
*
1031 decorator_list
, int lineno
, int col_offset
, PyArena
*arena
)
1035 PyErr_SetString(PyExc_ValueError
,
1036 "field name is required for ClassDef");
1039 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1042 p
->kind
= ClassDef_kind
;
1043 p
->v
.ClassDef
.name
= name
;
1044 p
->v
.ClassDef
.bases
= bases
;
1045 p
->v
.ClassDef
.body
= body
;
1046 p
->v
.ClassDef
.decorator_list
= decorator_list
;
1048 p
->col_offset
= col_offset
;
1053 Return(expr_ty value
, int lineno
, int col_offset
, PyArena
*arena
)
1056 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1059 p
->kind
= Return_kind
;
1060 p
->v
.Return
.value
= value
;
1062 p
->col_offset
= col_offset
;
1067 Delete(asdl_seq
* targets
, int lineno
, int col_offset
, PyArena
*arena
)
1070 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1073 p
->kind
= Delete_kind
;
1074 p
->v
.Delete
.targets
= targets
;
1076 p
->col_offset
= col_offset
;
1081 Assign(asdl_seq
* targets
, expr_ty value
, int lineno
, int col_offset
, PyArena
1086 PyErr_SetString(PyExc_ValueError
,
1087 "field value is required for Assign");
1090 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1093 p
->kind
= Assign_kind
;
1094 p
->v
.Assign
.targets
= targets
;
1095 p
->v
.Assign
.value
= value
;
1097 p
->col_offset
= col_offset
;
1102 AugAssign(expr_ty target
, operator_ty op
, expr_ty value
, int lineno
, int
1103 col_offset
, PyArena
*arena
)
1107 PyErr_SetString(PyExc_ValueError
,
1108 "field target is required for AugAssign");
1112 PyErr_SetString(PyExc_ValueError
,
1113 "field op is required for AugAssign");
1117 PyErr_SetString(PyExc_ValueError
,
1118 "field value is required for AugAssign");
1121 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1124 p
->kind
= AugAssign_kind
;
1125 p
->v
.AugAssign
.target
= target
;
1126 p
->v
.AugAssign
.op
= op
;
1127 p
->v
.AugAssign
.value
= value
;
1129 p
->col_offset
= col_offset
;
1134 Print(expr_ty dest
, asdl_seq
* values
, bool nl
, int lineno
, int col_offset
,
1138 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1141 p
->kind
= Print_kind
;
1142 p
->v
.Print
.dest
= dest
;
1143 p
->v
.Print
.values
= values
;
1146 p
->col_offset
= col_offset
;
1151 For(expr_ty target
, expr_ty iter
, asdl_seq
* body
, asdl_seq
* orelse
, int
1152 lineno
, int col_offset
, PyArena
*arena
)
1156 PyErr_SetString(PyExc_ValueError
,
1157 "field target is required for For");
1161 PyErr_SetString(PyExc_ValueError
,
1162 "field iter is required for For");
1165 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1169 p
->v
.For
.target
= target
;
1170 p
->v
.For
.iter
= iter
;
1171 p
->v
.For
.body
= body
;
1172 p
->v
.For
.orelse
= orelse
;
1174 p
->col_offset
= col_offset
;
1179 While(expr_ty test
, asdl_seq
* body
, asdl_seq
* orelse
, int lineno
, int
1180 col_offset
, PyArena
*arena
)
1184 PyErr_SetString(PyExc_ValueError
,
1185 "field test is required for While");
1188 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1191 p
->kind
= While_kind
;
1192 p
->v
.While
.test
= test
;
1193 p
->v
.While
.body
= body
;
1194 p
->v
.While
.orelse
= orelse
;
1196 p
->col_offset
= col_offset
;
1201 If(expr_ty test
, asdl_seq
* body
, asdl_seq
* orelse
, int lineno
, int
1202 col_offset
, PyArena
*arena
)
1206 PyErr_SetString(PyExc_ValueError
,
1207 "field test is required for If");
1210 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1214 p
->v
.If
.test
= test
;
1215 p
->v
.If
.body
= body
;
1216 p
->v
.If
.orelse
= orelse
;
1218 p
->col_offset
= col_offset
;
1223 With(expr_ty context_expr
, expr_ty optional_vars
, asdl_seq
* body
, int lineno
,
1224 int col_offset
, PyArena
*arena
)
1227 if (!context_expr
) {
1228 PyErr_SetString(PyExc_ValueError
,
1229 "field context_expr is required for With");
1232 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1235 p
->kind
= With_kind
;
1236 p
->v
.With
.context_expr
= context_expr
;
1237 p
->v
.With
.optional_vars
= optional_vars
;
1238 p
->v
.With
.body
= body
;
1240 p
->col_offset
= col_offset
;
1245 Raise(expr_ty type
, expr_ty inst
, expr_ty tback
, int lineno
, int col_offset
,
1249 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1252 p
->kind
= Raise_kind
;
1253 p
->v
.Raise
.type
= type
;
1254 p
->v
.Raise
.inst
= inst
;
1255 p
->v
.Raise
.tback
= tback
;
1257 p
->col_offset
= col_offset
;
1262 TryExcept(asdl_seq
* body
, asdl_seq
* handlers
, asdl_seq
* orelse
, int lineno
,
1263 int col_offset
, PyArena
*arena
)
1266 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1269 p
->kind
= TryExcept_kind
;
1270 p
->v
.TryExcept
.body
= body
;
1271 p
->v
.TryExcept
.handlers
= handlers
;
1272 p
->v
.TryExcept
.orelse
= orelse
;
1274 p
->col_offset
= col_offset
;
1279 TryFinally(asdl_seq
* body
, asdl_seq
* finalbody
, int lineno
, int col_offset
,
1283 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1286 p
->kind
= TryFinally_kind
;
1287 p
->v
.TryFinally
.body
= body
;
1288 p
->v
.TryFinally
.finalbody
= finalbody
;
1290 p
->col_offset
= col_offset
;
1295 Assert(expr_ty test
, expr_ty msg
, int lineno
, int col_offset
, PyArena
*arena
)
1299 PyErr_SetString(PyExc_ValueError
,
1300 "field test is required for Assert");
1303 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1306 p
->kind
= Assert_kind
;
1307 p
->v
.Assert
.test
= test
;
1308 p
->v
.Assert
.msg
= msg
;
1310 p
->col_offset
= col_offset
;
1315 Import(asdl_seq
* names
, int lineno
, int col_offset
, PyArena
*arena
)
1318 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1321 p
->kind
= Import_kind
;
1322 p
->v
.Import
.names
= names
;
1324 p
->col_offset
= col_offset
;
1329 ImportFrom(identifier module
, asdl_seq
* names
, int level
, int lineno
, int
1330 col_offset
, PyArena
*arena
)
1334 PyErr_SetString(PyExc_ValueError
,
1335 "field module is required for ImportFrom");
1338 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1341 p
->kind
= ImportFrom_kind
;
1342 p
->v
.ImportFrom
.module
= module
;
1343 p
->v
.ImportFrom
.names
= names
;
1344 p
->v
.ImportFrom
.level
= level
;
1346 p
->col_offset
= col_offset
;
1351 Exec(expr_ty body
, expr_ty globals
, expr_ty locals
, int lineno
, int col_offset
,
1356 PyErr_SetString(PyExc_ValueError
,
1357 "field body is required for Exec");
1360 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1363 p
->kind
= Exec_kind
;
1364 p
->v
.Exec
.body
= body
;
1365 p
->v
.Exec
.globals
= globals
;
1366 p
->v
.Exec
.locals
= locals
;
1368 p
->col_offset
= col_offset
;
1373 Global(asdl_seq
* names
, int lineno
, int col_offset
, PyArena
*arena
)
1376 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1379 p
->kind
= Global_kind
;
1380 p
->v
.Global
.names
= names
;
1382 p
->col_offset
= col_offset
;
1387 Expr(expr_ty value
, int lineno
, int col_offset
, PyArena
*arena
)
1391 PyErr_SetString(PyExc_ValueError
,
1392 "field value is required for Expr");
1395 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1398 p
->kind
= Expr_kind
;
1399 p
->v
.Expr
.value
= value
;
1401 p
->col_offset
= col_offset
;
1406 Pass(int lineno
, int col_offset
, PyArena
*arena
)
1409 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1412 p
->kind
= Pass_kind
;
1414 p
->col_offset
= col_offset
;
1419 Break(int lineno
, int col_offset
, PyArena
*arena
)
1422 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1425 p
->kind
= Break_kind
;
1427 p
->col_offset
= col_offset
;
1432 Continue(int lineno
, int col_offset
, PyArena
*arena
)
1435 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1438 p
->kind
= Continue_kind
;
1440 p
->col_offset
= col_offset
;
1445 BoolOp(boolop_ty op
, asdl_seq
* values
, int lineno
, int col_offset
, PyArena
1450 PyErr_SetString(PyExc_ValueError
,
1451 "field op is required for BoolOp");
1454 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1457 p
->kind
= BoolOp_kind
;
1458 p
->v
.BoolOp
.op
= op
;
1459 p
->v
.BoolOp
.values
= values
;
1461 p
->col_offset
= col_offset
;
1466 BinOp(expr_ty left
, operator_ty op
, expr_ty right
, int lineno
, int col_offset
,
1471 PyErr_SetString(PyExc_ValueError
,
1472 "field left is required for BinOp");
1476 PyErr_SetString(PyExc_ValueError
,
1477 "field op is required for BinOp");
1481 PyErr_SetString(PyExc_ValueError
,
1482 "field right is required for BinOp");
1485 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1488 p
->kind
= BinOp_kind
;
1489 p
->v
.BinOp
.left
= left
;
1491 p
->v
.BinOp
.right
= right
;
1493 p
->col_offset
= col_offset
;
1498 UnaryOp(unaryop_ty op
, expr_ty operand
, int lineno
, int col_offset
, PyArena
1503 PyErr_SetString(PyExc_ValueError
,
1504 "field op is required for UnaryOp");
1508 PyErr_SetString(PyExc_ValueError
,
1509 "field operand is required for UnaryOp");
1512 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1515 p
->kind
= UnaryOp_kind
;
1516 p
->v
.UnaryOp
.op
= op
;
1517 p
->v
.UnaryOp
.operand
= operand
;
1519 p
->col_offset
= col_offset
;
1524 Lambda(arguments_ty args
, expr_ty body
, int lineno
, int col_offset
, PyArena
1529 PyErr_SetString(PyExc_ValueError
,
1530 "field args is required for Lambda");
1534 PyErr_SetString(PyExc_ValueError
,
1535 "field body is required for Lambda");
1538 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1541 p
->kind
= Lambda_kind
;
1542 p
->v
.Lambda
.args
= args
;
1543 p
->v
.Lambda
.body
= body
;
1545 p
->col_offset
= col_offset
;
1550 IfExp(expr_ty test
, expr_ty body
, expr_ty orelse
, int lineno
, int col_offset
,
1555 PyErr_SetString(PyExc_ValueError
,
1556 "field test is required for IfExp");
1560 PyErr_SetString(PyExc_ValueError
,
1561 "field body is required for IfExp");
1565 PyErr_SetString(PyExc_ValueError
,
1566 "field orelse is required for IfExp");
1569 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1572 p
->kind
= IfExp_kind
;
1573 p
->v
.IfExp
.test
= test
;
1574 p
->v
.IfExp
.body
= body
;
1575 p
->v
.IfExp
.orelse
= orelse
;
1577 p
->col_offset
= col_offset
;
1582 Dict(asdl_seq
* keys
, asdl_seq
* values
, int lineno
, int col_offset
, PyArena
1586 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1589 p
->kind
= Dict_kind
;
1590 p
->v
.Dict
.keys
= keys
;
1591 p
->v
.Dict
.values
= values
;
1593 p
->col_offset
= col_offset
;
1598 ListComp(expr_ty elt
, asdl_seq
* generators
, int lineno
, int col_offset
,
1603 PyErr_SetString(PyExc_ValueError
,
1604 "field elt is required for ListComp");
1607 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1610 p
->kind
= ListComp_kind
;
1611 p
->v
.ListComp
.elt
= elt
;
1612 p
->v
.ListComp
.generators
= generators
;
1614 p
->col_offset
= col_offset
;
1619 GeneratorExp(expr_ty elt
, asdl_seq
* generators
, int lineno
, int col_offset
,
1624 PyErr_SetString(PyExc_ValueError
,
1625 "field elt is required for GeneratorExp");
1628 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1631 p
->kind
= GeneratorExp_kind
;
1632 p
->v
.GeneratorExp
.elt
= elt
;
1633 p
->v
.GeneratorExp
.generators
= generators
;
1635 p
->col_offset
= col_offset
;
1640 Yield(expr_ty value
, int lineno
, int col_offset
, PyArena
*arena
)
1643 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1646 p
->kind
= Yield_kind
;
1647 p
->v
.Yield
.value
= value
;
1649 p
->col_offset
= col_offset
;
1654 Compare(expr_ty left
, asdl_int_seq
* ops
, asdl_seq
* comparators
, int lineno
,
1655 int col_offset
, PyArena
*arena
)
1659 PyErr_SetString(PyExc_ValueError
,
1660 "field left is required for Compare");
1663 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1666 p
->kind
= Compare_kind
;
1667 p
->v
.Compare
.left
= left
;
1668 p
->v
.Compare
.ops
= ops
;
1669 p
->v
.Compare
.comparators
= comparators
;
1671 p
->col_offset
= col_offset
;
1676 Call(expr_ty func
, asdl_seq
* args
, asdl_seq
* keywords
, expr_ty starargs
,
1677 expr_ty kwargs
, int lineno
, int col_offset
, PyArena
*arena
)
1681 PyErr_SetString(PyExc_ValueError
,
1682 "field func is required for Call");
1685 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1688 p
->kind
= Call_kind
;
1689 p
->v
.Call
.func
= func
;
1690 p
->v
.Call
.args
= args
;
1691 p
->v
.Call
.keywords
= keywords
;
1692 p
->v
.Call
.starargs
= starargs
;
1693 p
->v
.Call
.kwargs
= kwargs
;
1695 p
->col_offset
= col_offset
;
1700 Repr(expr_ty value
, int lineno
, int col_offset
, PyArena
*arena
)
1704 PyErr_SetString(PyExc_ValueError
,
1705 "field value is required for Repr");
1708 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1711 p
->kind
= Repr_kind
;
1712 p
->v
.Repr
.value
= value
;
1714 p
->col_offset
= col_offset
;
1719 Num(object n
, int lineno
, int col_offset
, PyArena
*arena
)
1723 PyErr_SetString(PyExc_ValueError
,
1724 "field n is required for Num");
1727 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1733 p
->col_offset
= col_offset
;
1738 Str(string s
, int lineno
, int col_offset
, PyArena
*arena
)
1742 PyErr_SetString(PyExc_ValueError
,
1743 "field s is required for Str");
1746 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1752 p
->col_offset
= col_offset
;
1757 Attribute(expr_ty value
, identifier attr
, expr_context_ty ctx
, int lineno
, int
1758 col_offset
, PyArena
*arena
)
1762 PyErr_SetString(PyExc_ValueError
,
1763 "field value is required for Attribute");
1767 PyErr_SetString(PyExc_ValueError
,
1768 "field attr is required for Attribute");
1772 PyErr_SetString(PyExc_ValueError
,
1773 "field ctx is required for Attribute");
1776 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1779 p
->kind
= Attribute_kind
;
1780 p
->v
.Attribute
.value
= value
;
1781 p
->v
.Attribute
.attr
= attr
;
1782 p
->v
.Attribute
.ctx
= ctx
;
1784 p
->col_offset
= col_offset
;
1789 Subscript(expr_ty value
, slice_ty slice
, expr_context_ty ctx
, int lineno
, int
1790 col_offset
, PyArena
*arena
)
1794 PyErr_SetString(PyExc_ValueError
,
1795 "field value is required for Subscript");
1799 PyErr_SetString(PyExc_ValueError
,
1800 "field slice is required for Subscript");
1804 PyErr_SetString(PyExc_ValueError
,
1805 "field ctx is required for Subscript");
1808 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1811 p
->kind
= Subscript_kind
;
1812 p
->v
.Subscript
.value
= value
;
1813 p
->v
.Subscript
.slice
= slice
;
1814 p
->v
.Subscript
.ctx
= ctx
;
1816 p
->col_offset
= col_offset
;
1821 Name(identifier id
, expr_context_ty ctx
, int lineno
, int col_offset
, PyArena
1826 PyErr_SetString(PyExc_ValueError
,
1827 "field id is required for Name");
1831 PyErr_SetString(PyExc_ValueError
,
1832 "field ctx is required for Name");
1835 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1838 p
->kind
= Name_kind
;
1840 p
->v
.Name
.ctx
= ctx
;
1842 p
->col_offset
= col_offset
;
1847 List(asdl_seq
* elts
, expr_context_ty ctx
, int lineno
, int col_offset
, PyArena
1852 PyErr_SetString(PyExc_ValueError
,
1853 "field ctx is required for List");
1856 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1859 p
->kind
= List_kind
;
1860 p
->v
.List
.elts
= elts
;
1861 p
->v
.List
.ctx
= ctx
;
1863 p
->col_offset
= col_offset
;
1868 Tuple(asdl_seq
* elts
, expr_context_ty ctx
, int lineno
, int col_offset
, PyArena
1873 PyErr_SetString(PyExc_ValueError
,
1874 "field ctx is required for Tuple");
1877 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1880 p
->kind
= Tuple_kind
;
1881 p
->v
.Tuple
.elts
= elts
;
1882 p
->v
.Tuple
.ctx
= ctx
;
1884 p
->col_offset
= col_offset
;
1889 Ellipsis(PyArena
*arena
)
1892 p
= (slice_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1895 p
->kind
= Ellipsis_kind
;
1900 Slice(expr_ty lower
, expr_ty upper
, expr_ty step
, PyArena
*arena
)
1903 p
= (slice_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1906 p
->kind
= Slice_kind
;
1907 p
->v
.Slice
.lower
= lower
;
1908 p
->v
.Slice
.upper
= upper
;
1909 p
->v
.Slice
.step
= step
;
1914 ExtSlice(asdl_seq
* dims
, PyArena
*arena
)
1917 p
= (slice_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1920 p
->kind
= ExtSlice_kind
;
1921 p
->v
.ExtSlice
.dims
= dims
;
1926 Index(expr_ty value
, PyArena
*arena
)
1930 PyErr_SetString(PyExc_ValueError
,
1931 "field value is required for Index");
1934 p
= (slice_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1937 p
->kind
= Index_kind
;
1938 p
->v
.Index
.value
= value
;
1943 comprehension(expr_ty target
, expr_ty iter
, asdl_seq
* ifs
, PyArena
*arena
)
1947 PyErr_SetString(PyExc_ValueError
,
1948 "field target is required for comprehension");
1952 PyErr_SetString(PyExc_ValueError
,
1953 "field iter is required for comprehension");
1956 p
= (comprehension_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1966 ExceptHandler(expr_ty type
, expr_ty name
, asdl_seq
* body
, int lineno
, int
1967 col_offset
, PyArena
*arena
)
1970 p
= (excepthandler_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1973 p
->kind
= ExceptHandler_kind
;
1974 p
->v
.ExceptHandler
.type
= type
;
1975 p
->v
.ExceptHandler
.name
= name
;
1976 p
->v
.ExceptHandler
.body
= body
;
1978 p
->col_offset
= col_offset
;
1983 arguments(asdl_seq
* args
, identifier vararg
, identifier kwarg
, asdl_seq
*
1984 defaults
, PyArena
*arena
)
1987 p
= (arguments_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1993 p
->defaults
= defaults
;
1998 keyword(identifier arg
, expr_ty value
, PyArena
*arena
)
2002 PyErr_SetString(PyExc_ValueError
,
2003 "field arg is required for keyword");
2007 PyErr_SetString(PyExc_ValueError
,
2008 "field value is required for keyword");
2011 p
= (keyword_ty
)PyArena_Malloc(arena
, sizeof(*p
));
2020 alias(identifier name
, identifier asname
, PyArena
*arena
)
2024 PyErr_SetString(PyExc_ValueError
,
2025 "field name is required for alias");
2028 p
= (alias_ty
)PyArena_Malloc(arena
, sizeof(*p
));
2038 ast2obj_mod(void* _o
)
2040 mod_ty o
= (mod_ty
)_o
;
2041 PyObject
*result
= NULL
, *value
= NULL
;
2049 result
= PyType_GenericNew(Module_type
, NULL
, NULL
);
2050 if (!result
) goto failed
;
2051 value
= ast2obj_list(o
->v
.Module
.body
, ast2obj_stmt
);
2052 if (!value
) goto failed
;
2053 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2057 case Interactive_kind
:
2058 result
= PyType_GenericNew(Interactive_type
, NULL
, NULL
);
2059 if (!result
) goto failed
;
2060 value
= ast2obj_list(o
->v
.Interactive
.body
, ast2obj_stmt
);
2061 if (!value
) goto failed
;
2062 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2066 case Expression_kind
:
2067 result
= PyType_GenericNew(Expression_type
, NULL
, NULL
);
2068 if (!result
) goto failed
;
2069 value
= ast2obj_expr(o
->v
.Expression
.body
);
2070 if (!value
) goto failed
;
2071 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2076 result
= PyType_GenericNew(Suite_type
, NULL
, NULL
);
2077 if (!result
) goto failed
;
2078 value
= ast2obj_list(o
->v
.Suite
.body
, ast2obj_stmt
);
2079 if (!value
) goto failed
;
2080 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2093 ast2obj_stmt(void* _o
)
2095 stmt_ty o
= (stmt_ty
)_o
;
2096 PyObject
*result
= NULL
, *value
= NULL
;
2103 case FunctionDef_kind
:
2104 result
= PyType_GenericNew(FunctionDef_type
, NULL
, NULL
);
2105 if (!result
) goto failed
;
2106 value
= ast2obj_identifier(o
->v
.FunctionDef
.name
);
2107 if (!value
) goto failed
;
2108 if (PyObject_SetAttrString(result
, "name", value
) == -1)
2111 value
= ast2obj_arguments(o
->v
.FunctionDef
.args
);
2112 if (!value
) goto failed
;
2113 if (PyObject_SetAttrString(result
, "args", value
) == -1)
2116 value
= ast2obj_list(o
->v
.FunctionDef
.body
, ast2obj_stmt
);
2117 if (!value
) goto failed
;
2118 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2121 value
= ast2obj_list(o
->v
.FunctionDef
.decorator_list
,
2123 if (!value
) goto failed
;
2124 if (PyObject_SetAttrString(result
, "decorator_list", value
) ==
2130 result
= PyType_GenericNew(ClassDef_type
, NULL
, NULL
);
2131 if (!result
) goto failed
;
2132 value
= ast2obj_identifier(o
->v
.ClassDef
.name
);
2133 if (!value
) goto failed
;
2134 if (PyObject_SetAttrString(result
, "name", value
) == -1)
2137 value
= ast2obj_list(o
->v
.ClassDef
.bases
, ast2obj_expr
);
2138 if (!value
) goto failed
;
2139 if (PyObject_SetAttrString(result
, "bases", value
) == -1)
2142 value
= ast2obj_list(o
->v
.ClassDef
.body
, ast2obj_stmt
);
2143 if (!value
) goto failed
;
2144 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2147 value
= ast2obj_list(o
->v
.ClassDef
.decorator_list
,
2149 if (!value
) goto failed
;
2150 if (PyObject_SetAttrString(result
, "decorator_list", value
) ==
2156 result
= PyType_GenericNew(Return_type
, NULL
, NULL
);
2157 if (!result
) goto failed
;
2158 value
= ast2obj_expr(o
->v
.Return
.value
);
2159 if (!value
) goto failed
;
2160 if (PyObject_SetAttrString(result
, "value", value
) == -1)
2165 result
= PyType_GenericNew(Delete_type
, NULL
, NULL
);
2166 if (!result
) goto failed
;
2167 value
= ast2obj_list(o
->v
.Delete
.targets
, ast2obj_expr
);
2168 if (!value
) goto failed
;
2169 if (PyObject_SetAttrString(result
, "targets", value
) == -1)
2174 result
= PyType_GenericNew(Assign_type
, NULL
, NULL
);
2175 if (!result
) goto failed
;
2176 value
= ast2obj_list(o
->v
.Assign
.targets
, ast2obj_expr
);
2177 if (!value
) goto failed
;
2178 if (PyObject_SetAttrString(result
, "targets", value
) == -1)
2181 value
= ast2obj_expr(o
->v
.Assign
.value
);
2182 if (!value
) goto failed
;
2183 if (PyObject_SetAttrString(result
, "value", value
) == -1)
2187 case AugAssign_kind
:
2188 result
= PyType_GenericNew(AugAssign_type
, NULL
, NULL
);
2189 if (!result
) goto failed
;
2190 value
= ast2obj_expr(o
->v
.AugAssign
.target
);
2191 if (!value
) goto failed
;
2192 if (PyObject_SetAttrString(result
, "target", value
) == -1)
2195 value
= ast2obj_operator(o
->v
.AugAssign
.op
);
2196 if (!value
) goto failed
;
2197 if (PyObject_SetAttrString(result
, "op", value
) == -1)
2200 value
= ast2obj_expr(o
->v
.AugAssign
.value
);
2201 if (!value
) goto failed
;
2202 if (PyObject_SetAttrString(result
, "value", value
) == -1)
2207 result
= PyType_GenericNew(Print_type
, NULL
, NULL
);
2208 if (!result
) goto failed
;
2209 value
= ast2obj_expr(o
->v
.Print
.dest
);
2210 if (!value
) goto failed
;
2211 if (PyObject_SetAttrString(result
, "dest", value
) == -1)
2214 value
= ast2obj_list(o
->v
.Print
.values
, ast2obj_expr
);
2215 if (!value
) goto failed
;
2216 if (PyObject_SetAttrString(result
, "values", value
) == -1)
2219 value
= ast2obj_bool(o
->v
.Print
.nl
);
2220 if (!value
) goto failed
;
2221 if (PyObject_SetAttrString(result
, "nl", value
) == -1)
2226 result
= PyType_GenericNew(For_type
, NULL
, NULL
);
2227 if (!result
) goto failed
;
2228 value
= ast2obj_expr(o
->v
.For
.target
);
2229 if (!value
) goto failed
;
2230 if (PyObject_SetAttrString(result
, "target", value
) == -1)
2233 value
= ast2obj_expr(o
->v
.For
.iter
);
2234 if (!value
) goto failed
;
2235 if (PyObject_SetAttrString(result
, "iter", value
) == -1)
2238 value
= ast2obj_list(o
->v
.For
.body
, ast2obj_stmt
);
2239 if (!value
) goto failed
;
2240 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2243 value
= ast2obj_list(o
->v
.For
.orelse
, ast2obj_stmt
);
2244 if (!value
) goto failed
;
2245 if (PyObject_SetAttrString(result
, "orelse", value
) == -1)
2250 result
= PyType_GenericNew(While_type
, NULL
, NULL
);
2251 if (!result
) goto failed
;
2252 value
= ast2obj_expr(o
->v
.While
.test
);
2253 if (!value
) goto failed
;
2254 if (PyObject_SetAttrString(result
, "test", value
) == -1)
2257 value
= ast2obj_list(o
->v
.While
.body
, ast2obj_stmt
);
2258 if (!value
) goto failed
;
2259 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2262 value
= ast2obj_list(o
->v
.While
.orelse
, ast2obj_stmt
);
2263 if (!value
) goto failed
;
2264 if (PyObject_SetAttrString(result
, "orelse", value
) == -1)
2269 result
= PyType_GenericNew(If_type
, NULL
, NULL
);
2270 if (!result
) goto failed
;
2271 value
= ast2obj_expr(o
->v
.If
.test
);
2272 if (!value
) goto failed
;
2273 if (PyObject_SetAttrString(result
, "test", value
) == -1)
2276 value
= ast2obj_list(o
->v
.If
.body
, ast2obj_stmt
);
2277 if (!value
) goto failed
;
2278 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2281 value
= ast2obj_list(o
->v
.If
.orelse
, ast2obj_stmt
);
2282 if (!value
) goto failed
;
2283 if (PyObject_SetAttrString(result
, "orelse", value
) == -1)
2288 result
= PyType_GenericNew(With_type
, NULL
, NULL
);
2289 if (!result
) goto failed
;
2290 value
= ast2obj_expr(o
->v
.With
.context_expr
);
2291 if (!value
) goto failed
;
2292 if (PyObject_SetAttrString(result
, "context_expr", value
) == -1)
2295 value
= ast2obj_expr(o
->v
.With
.optional_vars
);
2296 if (!value
) goto failed
;
2297 if (PyObject_SetAttrString(result
, "optional_vars", value
) ==
2301 value
= ast2obj_list(o
->v
.With
.body
, ast2obj_stmt
);
2302 if (!value
) goto failed
;
2303 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2308 result
= PyType_GenericNew(Raise_type
, NULL
, NULL
);
2309 if (!result
) goto failed
;
2310 value
= ast2obj_expr(o
->v
.Raise
.type
);
2311 if (!value
) goto failed
;
2312 if (PyObject_SetAttrString(result
, "type", value
) == -1)
2315 value
= ast2obj_expr(o
->v
.Raise
.inst
);
2316 if (!value
) goto failed
;
2317 if (PyObject_SetAttrString(result
, "inst", value
) == -1)
2320 value
= ast2obj_expr(o
->v
.Raise
.tback
);
2321 if (!value
) goto failed
;
2322 if (PyObject_SetAttrString(result
, "tback", value
) == -1)
2326 case TryExcept_kind
:
2327 result
= PyType_GenericNew(TryExcept_type
, NULL
, NULL
);
2328 if (!result
) goto failed
;
2329 value
= ast2obj_list(o
->v
.TryExcept
.body
, ast2obj_stmt
);
2330 if (!value
) goto failed
;
2331 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2334 value
= ast2obj_list(o
->v
.TryExcept
.handlers
,
2335 ast2obj_excepthandler
);
2336 if (!value
) goto failed
;
2337 if (PyObject_SetAttrString(result
, "handlers", value
) == -1)
2340 value
= ast2obj_list(o
->v
.TryExcept
.orelse
, ast2obj_stmt
);
2341 if (!value
) goto failed
;
2342 if (PyObject_SetAttrString(result
, "orelse", value
) == -1)
2346 case TryFinally_kind
:
2347 result
= PyType_GenericNew(TryFinally_type
, NULL
, NULL
);
2348 if (!result
) goto failed
;
2349 value
= ast2obj_list(o
->v
.TryFinally
.body
, ast2obj_stmt
);
2350 if (!value
) goto failed
;
2351 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2354 value
= ast2obj_list(o
->v
.TryFinally
.finalbody
, ast2obj_stmt
);
2355 if (!value
) goto failed
;
2356 if (PyObject_SetAttrString(result
, "finalbody", value
) == -1)
2361 result
= PyType_GenericNew(Assert_type
, NULL
, NULL
);
2362 if (!result
) goto failed
;
2363 value
= ast2obj_expr(o
->v
.Assert
.test
);
2364 if (!value
) goto failed
;
2365 if (PyObject_SetAttrString(result
, "test", value
) == -1)
2368 value
= ast2obj_expr(o
->v
.Assert
.msg
);
2369 if (!value
) goto failed
;
2370 if (PyObject_SetAttrString(result
, "msg", value
) == -1)
2375 result
= PyType_GenericNew(Import_type
, NULL
, NULL
);
2376 if (!result
) goto failed
;
2377 value
= ast2obj_list(o
->v
.Import
.names
, ast2obj_alias
);
2378 if (!value
) goto failed
;
2379 if (PyObject_SetAttrString(result
, "names", value
) == -1)
2383 case ImportFrom_kind
:
2384 result
= PyType_GenericNew(ImportFrom_type
, NULL
, NULL
);
2385 if (!result
) goto failed
;
2386 value
= ast2obj_identifier(o
->v
.ImportFrom
.module
);
2387 if (!value
) goto failed
;
2388 if (PyObject_SetAttrString(result
, "module", value
) == -1)
2391 value
= ast2obj_list(o
->v
.ImportFrom
.names
, ast2obj_alias
);
2392 if (!value
) goto failed
;
2393 if (PyObject_SetAttrString(result
, "names", value
) == -1)
2396 value
= ast2obj_int(o
->v
.ImportFrom
.level
);
2397 if (!value
) goto failed
;
2398 if (PyObject_SetAttrString(result
, "level", value
) == -1)
2403 result
= PyType_GenericNew(Exec_type
, NULL
, NULL
);
2404 if (!result
) goto failed
;
2405 value
= ast2obj_expr(o
->v
.Exec
.body
);
2406 if (!value
) goto failed
;
2407 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2410 value
= ast2obj_expr(o
->v
.Exec
.globals
);
2411 if (!value
) goto failed
;
2412 if (PyObject_SetAttrString(result
, "globals", value
) == -1)
2415 value
= ast2obj_expr(o
->v
.Exec
.locals
);
2416 if (!value
) goto failed
;
2417 if (PyObject_SetAttrString(result
, "locals", value
) == -1)
2422 result
= PyType_GenericNew(Global_type
, NULL
, NULL
);
2423 if (!result
) goto failed
;
2424 value
= ast2obj_list(o
->v
.Global
.names
, ast2obj_identifier
);
2425 if (!value
) goto failed
;
2426 if (PyObject_SetAttrString(result
, "names", value
) == -1)
2431 result
= PyType_GenericNew(Expr_type
, NULL
, NULL
);
2432 if (!result
) goto failed
;
2433 value
= ast2obj_expr(o
->v
.Expr
.value
);
2434 if (!value
) goto failed
;
2435 if (PyObject_SetAttrString(result
, "value", value
) == -1)
2440 result
= PyType_GenericNew(Pass_type
, NULL
, NULL
);
2441 if (!result
) goto failed
;
2444 result
= PyType_GenericNew(Break_type
, NULL
, NULL
);
2445 if (!result
) goto failed
;
2448 result
= PyType_GenericNew(Continue_type
, NULL
, NULL
);
2449 if (!result
) goto failed
;
2452 value
= ast2obj_int(o
->lineno
);
2453 if (!value
) goto failed
;
2454 if (PyObject_SetAttrString(result
, "lineno", value
) < 0)
2457 value
= ast2obj_int(o
->col_offset
);
2458 if (!value
) goto failed
;
2459 if (PyObject_SetAttrString(result
, "col_offset", value
) < 0)
2470 ast2obj_expr(void* _o
)
2472 expr_ty o
= (expr_ty
)_o
;
2473 PyObject
*result
= NULL
, *value
= NULL
;
2481 result
= PyType_GenericNew(BoolOp_type
, NULL
, NULL
);
2482 if (!result
) goto failed
;
2483 value
= ast2obj_boolop(o
->v
.BoolOp
.op
);
2484 if (!value
) goto failed
;
2485 if (PyObject_SetAttrString(result
, "op", value
) == -1)
2488 value
= ast2obj_list(o
->v
.BoolOp
.values
, ast2obj_expr
);
2489 if (!value
) goto failed
;
2490 if (PyObject_SetAttrString(result
, "values", value
) == -1)
2495 result
= PyType_GenericNew(BinOp_type
, NULL
, NULL
);
2496 if (!result
) goto failed
;
2497 value
= ast2obj_expr(o
->v
.BinOp
.left
);
2498 if (!value
) goto failed
;
2499 if (PyObject_SetAttrString(result
, "left", value
) == -1)
2502 value
= ast2obj_operator(o
->v
.BinOp
.op
);
2503 if (!value
) goto failed
;
2504 if (PyObject_SetAttrString(result
, "op", value
) == -1)
2507 value
= ast2obj_expr(o
->v
.BinOp
.right
);
2508 if (!value
) goto failed
;
2509 if (PyObject_SetAttrString(result
, "right", value
) == -1)
2514 result
= PyType_GenericNew(UnaryOp_type
, NULL
, NULL
);
2515 if (!result
) goto failed
;
2516 value
= ast2obj_unaryop(o
->v
.UnaryOp
.op
);
2517 if (!value
) goto failed
;
2518 if (PyObject_SetAttrString(result
, "op", value
) == -1)
2521 value
= ast2obj_expr(o
->v
.UnaryOp
.operand
);
2522 if (!value
) goto failed
;
2523 if (PyObject_SetAttrString(result
, "operand", value
) == -1)
2528 result
= PyType_GenericNew(Lambda_type
, NULL
, NULL
);
2529 if (!result
) goto failed
;
2530 value
= ast2obj_arguments(o
->v
.Lambda
.args
);
2531 if (!value
) goto failed
;
2532 if (PyObject_SetAttrString(result
, "args", value
) == -1)
2535 value
= ast2obj_expr(o
->v
.Lambda
.body
);
2536 if (!value
) goto failed
;
2537 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2542 result
= PyType_GenericNew(IfExp_type
, NULL
, NULL
);
2543 if (!result
) goto failed
;
2544 value
= ast2obj_expr(o
->v
.IfExp
.test
);
2545 if (!value
) goto failed
;
2546 if (PyObject_SetAttrString(result
, "test", value
) == -1)
2549 value
= ast2obj_expr(o
->v
.IfExp
.body
);
2550 if (!value
) goto failed
;
2551 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2554 value
= ast2obj_expr(o
->v
.IfExp
.orelse
);
2555 if (!value
) goto failed
;
2556 if (PyObject_SetAttrString(result
, "orelse", value
) == -1)
2561 result
= PyType_GenericNew(Dict_type
, NULL
, NULL
);
2562 if (!result
) goto failed
;
2563 value
= ast2obj_list(o
->v
.Dict
.keys
, ast2obj_expr
);
2564 if (!value
) goto failed
;
2565 if (PyObject_SetAttrString(result
, "keys", value
) == -1)
2568 value
= ast2obj_list(o
->v
.Dict
.values
, ast2obj_expr
);
2569 if (!value
) goto failed
;
2570 if (PyObject_SetAttrString(result
, "values", value
) == -1)
2575 result
= PyType_GenericNew(ListComp_type
, NULL
, NULL
);
2576 if (!result
) goto failed
;
2577 value
= ast2obj_expr(o
->v
.ListComp
.elt
);
2578 if (!value
) goto failed
;
2579 if (PyObject_SetAttrString(result
, "elt", value
) == -1)
2582 value
= ast2obj_list(o
->v
.ListComp
.generators
,
2583 ast2obj_comprehension
);
2584 if (!value
) goto failed
;
2585 if (PyObject_SetAttrString(result
, "generators", value
) == -1)
2589 case GeneratorExp_kind
:
2590 result
= PyType_GenericNew(GeneratorExp_type
, NULL
, NULL
);
2591 if (!result
) goto failed
;
2592 value
= ast2obj_expr(o
->v
.GeneratorExp
.elt
);
2593 if (!value
) goto failed
;
2594 if (PyObject_SetAttrString(result
, "elt", value
) == -1)
2597 value
= ast2obj_list(o
->v
.GeneratorExp
.generators
,
2598 ast2obj_comprehension
);
2599 if (!value
) goto failed
;
2600 if (PyObject_SetAttrString(result
, "generators", value
) == -1)
2605 result
= PyType_GenericNew(Yield_type
, NULL
, NULL
);
2606 if (!result
) goto failed
;
2607 value
= ast2obj_expr(o
->v
.Yield
.value
);
2608 if (!value
) goto failed
;
2609 if (PyObject_SetAttrString(result
, "value", value
) == -1)
2614 result
= PyType_GenericNew(Compare_type
, NULL
, NULL
);
2615 if (!result
) goto failed
;
2616 value
= ast2obj_expr(o
->v
.Compare
.left
);
2617 if (!value
) goto failed
;
2618 if (PyObject_SetAttrString(result
, "left", value
) == -1)
2622 int i
, n
= asdl_seq_LEN(o
->v
.Compare
.ops
);
2623 value
= PyList_New(n
);
2624 if (!value
) goto failed
;
2625 for(i
= 0; i
< n
; i
++)
2626 PyList_SET_ITEM(value
, i
, ast2obj_cmpop((cmpop_ty
)asdl_seq_GET(o
->v
.Compare
.ops
, i
)));
2628 if (!value
) goto failed
;
2629 if (PyObject_SetAttrString(result
, "ops", value
) == -1)
2632 value
= ast2obj_list(o
->v
.Compare
.comparators
, ast2obj_expr
);
2633 if (!value
) goto failed
;
2634 if (PyObject_SetAttrString(result
, "comparators", value
) == -1)
2639 result
= PyType_GenericNew(Call_type
, NULL
, NULL
);
2640 if (!result
) goto failed
;
2641 value
= ast2obj_expr(o
->v
.Call
.func
);
2642 if (!value
) goto failed
;
2643 if (PyObject_SetAttrString(result
, "func", value
) == -1)
2646 value
= ast2obj_list(o
->v
.Call
.args
, ast2obj_expr
);
2647 if (!value
) goto failed
;
2648 if (PyObject_SetAttrString(result
, "args", value
) == -1)
2651 value
= ast2obj_list(o
->v
.Call
.keywords
, ast2obj_keyword
);
2652 if (!value
) goto failed
;
2653 if (PyObject_SetAttrString(result
, "keywords", value
) == -1)
2656 value
= ast2obj_expr(o
->v
.Call
.starargs
);
2657 if (!value
) goto failed
;
2658 if (PyObject_SetAttrString(result
, "starargs", value
) == -1)
2661 value
= ast2obj_expr(o
->v
.Call
.kwargs
);
2662 if (!value
) goto failed
;
2663 if (PyObject_SetAttrString(result
, "kwargs", value
) == -1)
2668 result
= PyType_GenericNew(Repr_type
, NULL
, NULL
);
2669 if (!result
) goto failed
;
2670 value
= ast2obj_expr(o
->v
.Repr
.value
);
2671 if (!value
) goto failed
;
2672 if (PyObject_SetAttrString(result
, "value", value
) == -1)
2677 result
= PyType_GenericNew(Num_type
, NULL
, NULL
);
2678 if (!result
) goto failed
;
2679 value
= ast2obj_object(o
->v
.Num
.n
);
2680 if (!value
) goto failed
;
2681 if (PyObject_SetAttrString(result
, "n", value
) == -1)
2686 result
= PyType_GenericNew(Str_type
, NULL
, NULL
);
2687 if (!result
) goto failed
;
2688 value
= ast2obj_string(o
->v
.Str
.s
);
2689 if (!value
) goto failed
;
2690 if (PyObject_SetAttrString(result
, "s", value
) == -1)
2694 case Attribute_kind
:
2695 result
= PyType_GenericNew(Attribute_type
, NULL
, NULL
);
2696 if (!result
) goto failed
;
2697 value
= ast2obj_expr(o
->v
.Attribute
.value
);
2698 if (!value
) goto failed
;
2699 if (PyObject_SetAttrString(result
, "value", value
) == -1)
2702 value
= ast2obj_identifier(o
->v
.Attribute
.attr
);
2703 if (!value
) goto failed
;
2704 if (PyObject_SetAttrString(result
, "attr", value
) == -1)
2707 value
= ast2obj_expr_context(o
->v
.Attribute
.ctx
);
2708 if (!value
) goto failed
;
2709 if (PyObject_SetAttrString(result
, "ctx", value
) == -1)
2713 case Subscript_kind
:
2714 result
= PyType_GenericNew(Subscript_type
, NULL
, NULL
);
2715 if (!result
) goto failed
;
2716 value
= ast2obj_expr(o
->v
.Subscript
.value
);
2717 if (!value
) goto failed
;
2718 if (PyObject_SetAttrString(result
, "value", value
) == -1)
2721 value
= ast2obj_slice(o
->v
.Subscript
.slice
);
2722 if (!value
) goto failed
;
2723 if (PyObject_SetAttrString(result
, "slice", value
) == -1)
2726 value
= ast2obj_expr_context(o
->v
.Subscript
.ctx
);
2727 if (!value
) goto failed
;
2728 if (PyObject_SetAttrString(result
, "ctx", value
) == -1)
2733 result
= PyType_GenericNew(Name_type
, NULL
, NULL
);
2734 if (!result
) goto failed
;
2735 value
= ast2obj_identifier(o
->v
.Name
.id
);
2736 if (!value
) goto failed
;
2737 if (PyObject_SetAttrString(result
, "id", value
) == -1)
2740 value
= ast2obj_expr_context(o
->v
.Name
.ctx
);
2741 if (!value
) goto failed
;
2742 if (PyObject_SetAttrString(result
, "ctx", value
) == -1)
2747 result
= PyType_GenericNew(List_type
, NULL
, NULL
);
2748 if (!result
) goto failed
;
2749 value
= ast2obj_list(o
->v
.List
.elts
, ast2obj_expr
);
2750 if (!value
) goto failed
;
2751 if (PyObject_SetAttrString(result
, "elts", value
) == -1)
2754 value
= ast2obj_expr_context(o
->v
.List
.ctx
);
2755 if (!value
) goto failed
;
2756 if (PyObject_SetAttrString(result
, "ctx", value
) == -1)
2761 result
= PyType_GenericNew(Tuple_type
, NULL
, NULL
);
2762 if (!result
) goto failed
;
2763 value
= ast2obj_list(o
->v
.Tuple
.elts
, ast2obj_expr
);
2764 if (!value
) goto failed
;
2765 if (PyObject_SetAttrString(result
, "elts", value
) == -1)
2768 value
= ast2obj_expr_context(o
->v
.Tuple
.ctx
);
2769 if (!value
) goto failed
;
2770 if (PyObject_SetAttrString(result
, "ctx", value
) == -1)
2775 value
= ast2obj_int(o
->lineno
);
2776 if (!value
) goto failed
;
2777 if (PyObject_SetAttrString(result
, "lineno", value
) < 0)
2780 value
= ast2obj_int(o
->col_offset
);
2781 if (!value
) goto failed
;
2782 if (PyObject_SetAttrString(result
, "col_offset", value
) < 0)
2792 PyObject
* ast2obj_expr_context(expr_context_ty o
)
2796 Py_INCREF(Load_singleton
);
2797 return Load_singleton
;
2799 Py_INCREF(Store_singleton
);
2800 return Store_singleton
;
2802 Py_INCREF(Del_singleton
);
2803 return Del_singleton
;
2805 Py_INCREF(AugLoad_singleton
);
2806 return AugLoad_singleton
;
2808 Py_INCREF(AugStore_singleton
);
2809 return AugStore_singleton
;
2811 Py_INCREF(Param_singleton
);
2812 return Param_singleton
;
2814 /* should never happen, but just in case ... */
2815 PyErr_Format(PyExc_SystemError
, "unknown expr_context found");
2820 ast2obj_slice(void* _o
)
2822 slice_ty o
= (slice_ty
)_o
;
2823 PyObject
*result
= NULL
, *value
= NULL
;
2831 result
= PyType_GenericNew(Ellipsis_type
, NULL
, NULL
);
2832 if (!result
) goto failed
;
2835 result
= PyType_GenericNew(Slice_type
, NULL
, NULL
);
2836 if (!result
) goto failed
;
2837 value
= ast2obj_expr(o
->v
.Slice
.lower
);
2838 if (!value
) goto failed
;
2839 if (PyObject_SetAttrString(result
, "lower", value
) == -1)
2842 value
= ast2obj_expr(o
->v
.Slice
.upper
);
2843 if (!value
) goto failed
;
2844 if (PyObject_SetAttrString(result
, "upper", value
) == -1)
2847 value
= ast2obj_expr(o
->v
.Slice
.step
);
2848 if (!value
) goto failed
;
2849 if (PyObject_SetAttrString(result
, "step", value
) == -1)
2854 result
= PyType_GenericNew(ExtSlice_type
, NULL
, NULL
);
2855 if (!result
) goto failed
;
2856 value
= ast2obj_list(o
->v
.ExtSlice
.dims
, ast2obj_slice
);
2857 if (!value
) goto failed
;
2858 if (PyObject_SetAttrString(result
, "dims", value
) == -1)
2863 result
= PyType_GenericNew(Index_type
, NULL
, NULL
);
2864 if (!result
) goto failed
;
2865 value
= ast2obj_expr(o
->v
.Index
.value
);
2866 if (!value
) goto failed
;
2867 if (PyObject_SetAttrString(result
, "value", value
) == -1)
2879 PyObject
* ast2obj_boolop(boolop_ty o
)
2883 Py_INCREF(And_singleton
);
2884 return And_singleton
;
2886 Py_INCREF(Or_singleton
);
2887 return Or_singleton
;
2889 /* should never happen, but just in case ... */
2890 PyErr_Format(PyExc_SystemError
, "unknown boolop found");
2894 PyObject
* ast2obj_operator(operator_ty o
)
2898 Py_INCREF(Add_singleton
);
2899 return Add_singleton
;
2901 Py_INCREF(Sub_singleton
);
2902 return Sub_singleton
;
2904 Py_INCREF(Mult_singleton
);
2905 return Mult_singleton
;
2907 Py_INCREF(Div_singleton
);
2908 return Div_singleton
;
2910 Py_INCREF(Mod_singleton
);
2911 return Mod_singleton
;
2913 Py_INCREF(Pow_singleton
);
2914 return Pow_singleton
;
2916 Py_INCREF(LShift_singleton
);
2917 return LShift_singleton
;
2919 Py_INCREF(RShift_singleton
);
2920 return RShift_singleton
;
2922 Py_INCREF(BitOr_singleton
);
2923 return BitOr_singleton
;
2925 Py_INCREF(BitXor_singleton
);
2926 return BitXor_singleton
;
2928 Py_INCREF(BitAnd_singleton
);
2929 return BitAnd_singleton
;
2931 Py_INCREF(FloorDiv_singleton
);
2932 return FloorDiv_singleton
;
2934 /* should never happen, but just in case ... */
2935 PyErr_Format(PyExc_SystemError
, "unknown operator found");
2939 PyObject
* ast2obj_unaryop(unaryop_ty o
)
2943 Py_INCREF(Invert_singleton
);
2944 return Invert_singleton
;
2946 Py_INCREF(Not_singleton
);
2947 return Not_singleton
;
2949 Py_INCREF(UAdd_singleton
);
2950 return UAdd_singleton
;
2952 Py_INCREF(USub_singleton
);
2953 return USub_singleton
;
2955 /* should never happen, but just in case ... */
2956 PyErr_Format(PyExc_SystemError
, "unknown unaryop found");
2960 PyObject
* ast2obj_cmpop(cmpop_ty o
)
2964 Py_INCREF(Eq_singleton
);
2965 return Eq_singleton
;
2967 Py_INCREF(NotEq_singleton
);
2968 return NotEq_singleton
;
2970 Py_INCREF(Lt_singleton
);
2971 return Lt_singleton
;
2973 Py_INCREF(LtE_singleton
);
2974 return LtE_singleton
;
2976 Py_INCREF(Gt_singleton
);
2977 return Gt_singleton
;
2979 Py_INCREF(GtE_singleton
);
2980 return GtE_singleton
;
2982 Py_INCREF(Is_singleton
);
2983 return Is_singleton
;
2985 Py_INCREF(IsNot_singleton
);
2986 return IsNot_singleton
;
2988 Py_INCREF(In_singleton
);
2989 return In_singleton
;
2991 Py_INCREF(NotIn_singleton
);
2992 return NotIn_singleton
;
2994 /* should never happen, but just in case ... */
2995 PyErr_Format(PyExc_SystemError
, "unknown cmpop found");
3000 ast2obj_comprehension(void* _o
)
3002 comprehension_ty o
= (comprehension_ty
)_o
;
3003 PyObject
*result
= NULL
, *value
= NULL
;
3009 result
= PyType_GenericNew(comprehension_type
, NULL
, NULL
);
3010 if (!result
) return NULL
;
3011 value
= ast2obj_expr(o
->target
);
3012 if (!value
) goto failed
;
3013 if (PyObject_SetAttrString(result
, "target", value
) == -1)
3016 value
= ast2obj_expr(o
->iter
);
3017 if (!value
) goto failed
;
3018 if (PyObject_SetAttrString(result
, "iter", value
) == -1)
3021 value
= ast2obj_list(o
->ifs
, ast2obj_expr
);
3022 if (!value
) goto failed
;
3023 if (PyObject_SetAttrString(result
, "ifs", value
) == -1)
3034 ast2obj_excepthandler(void* _o
)
3036 excepthandler_ty o
= (excepthandler_ty
)_o
;
3037 PyObject
*result
= NULL
, *value
= NULL
;
3044 case ExceptHandler_kind
:
3045 result
= PyType_GenericNew(ExceptHandler_type
, NULL
, NULL
);
3046 if (!result
) goto failed
;
3047 value
= ast2obj_expr(o
->v
.ExceptHandler
.type
);
3048 if (!value
) goto failed
;
3049 if (PyObject_SetAttrString(result
, "type", value
) == -1)
3052 value
= ast2obj_expr(o
->v
.ExceptHandler
.name
);
3053 if (!value
) goto failed
;
3054 if (PyObject_SetAttrString(result
, "name", value
) == -1)
3057 value
= ast2obj_list(o
->v
.ExceptHandler
.body
, ast2obj_stmt
);
3058 if (!value
) goto failed
;
3059 if (PyObject_SetAttrString(result
, "body", value
) == -1)
3064 value
= ast2obj_int(o
->lineno
);
3065 if (!value
) goto failed
;
3066 if (PyObject_SetAttrString(result
, "lineno", value
) < 0)
3069 value
= ast2obj_int(o
->col_offset
);
3070 if (!value
) goto failed
;
3071 if (PyObject_SetAttrString(result
, "col_offset", value
) < 0)
3082 ast2obj_arguments(void* _o
)
3084 arguments_ty o
= (arguments_ty
)_o
;
3085 PyObject
*result
= NULL
, *value
= NULL
;
3091 result
= PyType_GenericNew(arguments_type
, NULL
, NULL
);
3092 if (!result
) return NULL
;
3093 value
= ast2obj_list(o
->args
, ast2obj_expr
);
3094 if (!value
) goto failed
;
3095 if (PyObject_SetAttrString(result
, "args", value
) == -1)
3098 value
= ast2obj_identifier(o
->vararg
);
3099 if (!value
) goto failed
;
3100 if (PyObject_SetAttrString(result
, "vararg", value
) == -1)
3103 value
= ast2obj_identifier(o
->kwarg
);
3104 if (!value
) goto failed
;
3105 if (PyObject_SetAttrString(result
, "kwarg", value
) == -1)
3108 value
= ast2obj_list(o
->defaults
, ast2obj_expr
);
3109 if (!value
) goto failed
;
3110 if (PyObject_SetAttrString(result
, "defaults", value
) == -1)
3121 ast2obj_keyword(void* _o
)
3123 keyword_ty o
= (keyword_ty
)_o
;
3124 PyObject
*result
= NULL
, *value
= NULL
;
3130 result
= PyType_GenericNew(keyword_type
, NULL
, NULL
);
3131 if (!result
) return NULL
;
3132 value
= ast2obj_identifier(o
->arg
);
3133 if (!value
) goto failed
;
3134 if (PyObject_SetAttrString(result
, "arg", value
) == -1)
3137 value
= ast2obj_expr(o
->value
);
3138 if (!value
) goto failed
;
3139 if (PyObject_SetAttrString(result
, "value", value
) == -1)
3150 ast2obj_alias(void* _o
)
3152 alias_ty o
= (alias_ty
)_o
;
3153 PyObject
*result
= NULL
, *value
= NULL
;
3159 result
= PyType_GenericNew(alias_type
, NULL
, NULL
);
3160 if (!result
) return NULL
;
3161 value
= ast2obj_identifier(o
->name
);
3162 if (!value
) goto failed
;
3163 if (PyObject_SetAttrString(result
, "name", value
) == -1)
3166 value
= ast2obj_identifier(o
->asname
);
3167 if (!value
) goto failed
;
3168 if (PyObject_SetAttrString(result
, "asname", value
) == -1)
3180 obj2ast_mod(PyObject
* obj
, mod_ty
* out
, PyArena
* arena
)
3182 PyObject
* tmp
= NULL
;
3185 if (obj
== Py_None
) {
3189 if (PyObject_IsInstance(obj
, (PyObject
*)Module_type
)) {
3192 if (PyObject_HasAttrString(obj
, "body")) {
3196 tmp
= PyObject_GetAttrString(obj
, "body");
3197 if (tmp
== NULL
) goto failed
;
3198 if (!PyList_Check(tmp
)) {
3199 PyErr_Format(PyExc_TypeError
, "Module field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3202 len
= PyList_GET_SIZE(tmp
);
3203 body
= asdl_seq_new(len
, arena
);
3204 if (body
== NULL
) goto failed
;
3205 for (i
= 0; i
< len
; i
++) {
3207 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3208 if (res
!= 0) goto failed
;
3209 asdl_seq_SET(body
, i
, value
);
3214 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from Module");
3217 *out
= Module(body
, arena
);
3218 if (*out
== NULL
) goto failed
;
3221 if (PyObject_IsInstance(obj
, (PyObject
*)Interactive_type
)) {
3224 if (PyObject_HasAttrString(obj
, "body")) {
3228 tmp
= PyObject_GetAttrString(obj
, "body");
3229 if (tmp
== NULL
) goto failed
;
3230 if (!PyList_Check(tmp
)) {
3231 PyErr_Format(PyExc_TypeError
, "Interactive field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3234 len
= PyList_GET_SIZE(tmp
);
3235 body
= asdl_seq_new(len
, arena
);
3236 if (body
== NULL
) goto failed
;
3237 for (i
= 0; i
< len
; i
++) {
3239 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3240 if (res
!= 0) goto failed
;
3241 asdl_seq_SET(body
, i
, value
);
3246 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from Interactive");
3249 *out
= Interactive(body
, arena
);
3250 if (*out
== NULL
) goto failed
;
3253 if (PyObject_IsInstance(obj
, (PyObject
*)Expression_type
)) {
3256 if (PyObject_HasAttrString(obj
, "body")) {
3258 tmp
= PyObject_GetAttrString(obj
, "body");
3259 if (tmp
== NULL
) goto failed
;
3260 res
= obj2ast_expr(tmp
, &body
, arena
);
3261 if (res
!= 0) goto failed
;
3265 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from Expression");
3268 *out
= Expression(body
, arena
);
3269 if (*out
== NULL
) goto failed
;
3272 if (PyObject_IsInstance(obj
, (PyObject
*)Suite_type
)) {
3275 if (PyObject_HasAttrString(obj
, "body")) {
3279 tmp
= PyObject_GetAttrString(obj
, "body");
3280 if (tmp
== NULL
) goto failed
;
3281 if (!PyList_Check(tmp
)) {
3282 PyErr_Format(PyExc_TypeError
, "Suite field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3285 len
= PyList_GET_SIZE(tmp
);
3286 body
= asdl_seq_new(len
, arena
);
3287 if (body
== NULL
) goto failed
;
3288 for (i
= 0; i
< len
; i
++) {
3290 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3291 if (res
!= 0) goto failed
;
3292 asdl_seq_SET(body
, i
, value
);
3297 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from Suite");
3300 *out
= Suite(body
, arena
);
3301 if (*out
== NULL
) goto failed
;
3305 tmp
= PyObject_Repr(obj
);
3306 if (tmp
== NULL
) goto failed
;
3307 PyErr_Format(PyExc_TypeError
, "expected some sort of mod, but got %.400s", PyString_AS_STRING(tmp
));
3314 obj2ast_stmt(PyObject
* obj
, stmt_ty
* out
, PyArena
* arena
)
3316 PyObject
* tmp
= NULL
;
3321 if (obj
== Py_None
) {
3325 if (PyObject_HasAttrString(obj
, "lineno")) {
3327 tmp
= PyObject_GetAttrString(obj
, "lineno");
3328 if (tmp
== NULL
) goto failed
;
3329 res
= obj2ast_int(tmp
, &lineno
, arena
);
3330 if (res
!= 0) goto failed
;
3334 PyErr_SetString(PyExc_TypeError
, "required field \"lineno\" missing from stmt");
3337 if (PyObject_HasAttrString(obj
, "col_offset")) {
3339 tmp
= PyObject_GetAttrString(obj
, "col_offset");
3340 if (tmp
== NULL
) goto failed
;
3341 res
= obj2ast_int(tmp
, &col_offset
, arena
);
3342 if (res
!= 0) goto failed
;
3346 PyErr_SetString(PyExc_TypeError
, "required field \"col_offset\" missing from stmt");
3349 if (PyObject_IsInstance(obj
, (PyObject
*)FunctionDef_type
)) {
3353 asdl_seq
* decorator_list
;
3355 if (PyObject_HasAttrString(obj
, "name")) {
3357 tmp
= PyObject_GetAttrString(obj
, "name");
3358 if (tmp
== NULL
) goto failed
;
3359 res
= obj2ast_identifier(tmp
, &name
, arena
);
3360 if (res
!= 0) goto failed
;
3364 PyErr_SetString(PyExc_TypeError
, "required field \"name\" missing from FunctionDef");
3367 if (PyObject_HasAttrString(obj
, "args")) {
3369 tmp
= PyObject_GetAttrString(obj
, "args");
3370 if (tmp
== NULL
) goto failed
;
3371 res
= obj2ast_arguments(tmp
, &args
, arena
);
3372 if (res
!= 0) goto failed
;
3376 PyErr_SetString(PyExc_TypeError
, "required field \"args\" missing from FunctionDef");
3379 if (PyObject_HasAttrString(obj
, "body")) {
3383 tmp
= PyObject_GetAttrString(obj
, "body");
3384 if (tmp
== NULL
) goto failed
;
3385 if (!PyList_Check(tmp
)) {
3386 PyErr_Format(PyExc_TypeError
, "FunctionDef field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3389 len
= PyList_GET_SIZE(tmp
);
3390 body
= asdl_seq_new(len
, arena
);
3391 if (body
== NULL
) goto failed
;
3392 for (i
= 0; i
< len
; i
++) {
3394 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3395 if (res
!= 0) goto failed
;
3396 asdl_seq_SET(body
, i
, value
);
3401 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from FunctionDef");
3404 if (PyObject_HasAttrString(obj
, "decorator_list")) {
3408 tmp
= PyObject_GetAttrString(obj
, "decorator_list");
3409 if (tmp
== NULL
) goto failed
;
3410 if (!PyList_Check(tmp
)) {
3411 PyErr_Format(PyExc_TypeError
, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3414 len
= PyList_GET_SIZE(tmp
);
3415 decorator_list
= asdl_seq_new(len
, arena
);
3416 if (decorator_list
== NULL
) goto failed
;
3417 for (i
= 0; i
< len
; i
++) {
3419 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3420 if (res
!= 0) goto failed
;
3421 asdl_seq_SET(decorator_list
, i
, value
);
3426 PyErr_SetString(PyExc_TypeError
, "required field \"decorator_list\" missing from FunctionDef");
3429 *out
= FunctionDef(name
, args
, body
, decorator_list
, lineno
,
3431 if (*out
== NULL
) goto failed
;
3434 if (PyObject_IsInstance(obj
, (PyObject
*)ClassDef_type
)) {
3438 asdl_seq
* decorator_list
;
3440 if (PyObject_HasAttrString(obj
, "name")) {
3442 tmp
= PyObject_GetAttrString(obj
, "name");
3443 if (tmp
== NULL
) goto failed
;
3444 res
= obj2ast_identifier(tmp
, &name
, arena
);
3445 if (res
!= 0) goto failed
;
3449 PyErr_SetString(PyExc_TypeError
, "required field \"name\" missing from ClassDef");
3452 if (PyObject_HasAttrString(obj
, "bases")) {
3456 tmp
= PyObject_GetAttrString(obj
, "bases");
3457 if (tmp
== NULL
) goto failed
;
3458 if (!PyList_Check(tmp
)) {
3459 PyErr_Format(PyExc_TypeError
, "ClassDef field \"bases\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3462 len
= PyList_GET_SIZE(tmp
);
3463 bases
= asdl_seq_new(len
, arena
);
3464 if (bases
== NULL
) goto failed
;
3465 for (i
= 0; i
< len
; i
++) {
3467 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3468 if (res
!= 0) goto failed
;
3469 asdl_seq_SET(bases
, i
, value
);
3474 PyErr_SetString(PyExc_TypeError
, "required field \"bases\" missing from ClassDef");
3477 if (PyObject_HasAttrString(obj
, "body")) {
3481 tmp
= PyObject_GetAttrString(obj
, "body");
3482 if (tmp
== NULL
) goto failed
;
3483 if (!PyList_Check(tmp
)) {
3484 PyErr_Format(PyExc_TypeError
, "ClassDef field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3487 len
= PyList_GET_SIZE(tmp
);
3488 body
= asdl_seq_new(len
, arena
);
3489 if (body
== NULL
) goto failed
;
3490 for (i
= 0; i
< len
; i
++) {
3492 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3493 if (res
!= 0) goto failed
;
3494 asdl_seq_SET(body
, i
, value
);
3499 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from ClassDef");
3502 if (PyObject_HasAttrString(obj
, "decorator_list")) {
3506 tmp
= PyObject_GetAttrString(obj
, "decorator_list");
3507 if (tmp
== NULL
) goto failed
;
3508 if (!PyList_Check(tmp
)) {
3509 PyErr_Format(PyExc_TypeError
, "ClassDef field \"decorator_list\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3512 len
= PyList_GET_SIZE(tmp
);
3513 decorator_list
= asdl_seq_new(len
, arena
);
3514 if (decorator_list
== NULL
) goto failed
;
3515 for (i
= 0; i
< len
; i
++) {
3517 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3518 if (res
!= 0) goto failed
;
3519 asdl_seq_SET(decorator_list
, i
, value
);
3524 PyErr_SetString(PyExc_TypeError
, "required field \"decorator_list\" missing from ClassDef");
3527 *out
= ClassDef(name
, bases
, body
, decorator_list
, lineno
,
3529 if (*out
== NULL
) goto failed
;
3532 if (PyObject_IsInstance(obj
, (PyObject
*)Return_type
)) {
3535 if (PyObject_HasAttrString(obj
, "value")) {
3537 tmp
= PyObject_GetAttrString(obj
, "value");
3538 if (tmp
== NULL
) goto failed
;
3539 res
= obj2ast_expr(tmp
, &value
, arena
);
3540 if (res
!= 0) goto failed
;
3546 *out
= Return(value
, lineno
, col_offset
, arena
);
3547 if (*out
== NULL
) goto failed
;
3550 if (PyObject_IsInstance(obj
, (PyObject
*)Delete_type
)) {
3553 if (PyObject_HasAttrString(obj
, "targets")) {
3557 tmp
= PyObject_GetAttrString(obj
, "targets");
3558 if (tmp
== NULL
) goto failed
;
3559 if (!PyList_Check(tmp
)) {
3560 PyErr_Format(PyExc_TypeError
, "Delete field \"targets\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3563 len
= PyList_GET_SIZE(tmp
);
3564 targets
= asdl_seq_new(len
, arena
);
3565 if (targets
== NULL
) goto failed
;
3566 for (i
= 0; i
< len
; i
++) {
3568 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3569 if (res
!= 0) goto failed
;
3570 asdl_seq_SET(targets
, i
, value
);
3575 PyErr_SetString(PyExc_TypeError
, "required field \"targets\" missing from Delete");
3578 *out
= Delete(targets
, lineno
, col_offset
, arena
);
3579 if (*out
== NULL
) goto failed
;
3582 if (PyObject_IsInstance(obj
, (PyObject
*)Assign_type
)) {
3586 if (PyObject_HasAttrString(obj
, "targets")) {
3590 tmp
= PyObject_GetAttrString(obj
, "targets");
3591 if (tmp
== NULL
) goto failed
;
3592 if (!PyList_Check(tmp
)) {
3593 PyErr_Format(PyExc_TypeError
, "Assign field \"targets\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3596 len
= PyList_GET_SIZE(tmp
);
3597 targets
= asdl_seq_new(len
, arena
);
3598 if (targets
== NULL
) goto failed
;
3599 for (i
= 0; i
< len
; i
++) {
3601 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3602 if (res
!= 0) goto failed
;
3603 asdl_seq_SET(targets
, i
, value
);
3608 PyErr_SetString(PyExc_TypeError
, "required field \"targets\" missing from Assign");
3611 if (PyObject_HasAttrString(obj
, "value")) {
3613 tmp
= PyObject_GetAttrString(obj
, "value");
3614 if (tmp
== NULL
) goto failed
;
3615 res
= obj2ast_expr(tmp
, &value
, arena
);
3616 if (res
!= 0) goto failed
;
3620 PyErr_SetString(PyExc_TypeError
, "required field \"value\" missing from Assign");
3623 *out
= Assign(targets
, value
, lineno
, col_offset
, arena
);
3624 if (*out
== NULL
) goto failed
;
3627 if (PyObject_IsInstance(obj
, (PyObject
*)AugAssign_type
)) {
3632 if (PyObject_HasAttrString(obj
, "target")) {
3634 tmp
= PyObject_GetAttrString(obj
, "target");
3635 if (tmp
== NULL
) goto failed
;
3636 res
= obj2ast_expr(tmp
, &target
, arena
);
3637 if (res
!= 0) goto failed
;
3641 PyErr_SetString(PyExc_TypeError
, "required field \"target\" missing from AugAssign");
3644 if (PyObject_HasAttrString(obj
, "op")) {
3646 tmp
= PyObject_GetAttrString(obj
, "op");
3647 if (tmp
== NULL
) goto failed
;
3648 res
= obj2ast_operator(tmp
, &op
, arena
);
3649 if (res
!= 0) goto failed
;
3653 PyErr_SetString(PyExc_TypeError
, "required field \"op\" missing from AugAssign");
3656 if (PyObject_HasAttrString(obj
, "value")) {
3658 tmp
= PyObject_GetAttrString(obj
, "value");
3659 if (tmp
== NULL
) goto failed
;
3660 res
= obj2ast_expr(tmp
, &value
, arena
);
3661 if (res
!= 0) goto failed
;
3665 PyErr_SetString(PyExc_TypeError
, "required field \"value\" missing from AugAssign");
3668 *out
= AugAssign(target
, op
, value
, lineno
, col_offset
, arena
);
3669 if (*out
== NULL
) goto failed
;
3672 if (PyObject_IsInstance(obj
, (PyObject
*)Print_type
)) {
3677 if (PyObject_HasAttrString(obj
, "dest")) {
3679 tmp
= PyObject_GetAttrString(obj
, "dest");
3680 if (tmp
== NULL
) goto failed
;
3681 res
= obj2ast_expr(tmp
, &dest
, arena
);
3682 if (res
!= 0) goto failed
;
3688 if (PyObject_HasAttrString(obj
, "values")) {
3692 tmp
= PyObject_GetAttrString(obj
, "values");
3693 if (tmp
== NULL
) goto failed
;
3694 if (!PyList_Check(tmp
)) {
3695 PyErr_Format(PyExc_TypeError
, "Print field \"values\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3698 len
= PyList_GET_SIZE(tmp
);
3699 values
= asdl_seq_new(len
, arena
);
3700 if (values
== NULL
) goto failed
;
3701 for (i
= 0; i
< len
; i
++) {
3703 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3704 if (res
!= 0) goto failed
;
3705 asdl_seq_SET(values
, i
, value
);
3710 PyErr_SetString(PyExc_TypeError
, "required field \"values\" missing from Print");
3713 if (PyObject_HasAttrString(obj
, "nl")) {
3715 tmp
= PyObject_GetAttrString(obj
, "nl");
3716 if (tmp
== NULL
) goto failed
;
3717 res
= obj2ast_bool(tmp
, &nl
, arena
);
3718 if (res
!= 0) goto failed
;
3722 PyErr_SetString(PyExc_TypeError
, "required field \"nl\" missing from Print");
3725 *out
= Print(dest
, values
, nl
, lineno
, col_offset
, arena
);
3726 if (*out
== NULL
) goto failed
;
3729 if (PyObject_IsInstance(obj
, (PyObject
*)For_type
)) {
3735 if (PyObject_HasAttrString(obj
, "target")) {
3737 tmp
= PyObject_GetAttrString(obj
, "target");
3738 if (tmp
== NULL
) goto failed
;
3739 res
= obj2ast_expr(tmp
, &target
, arena
);
3740 if (res
!= 0) goto failed
;
3744 PyErr_SetString(PyExc_TypeError
, "required field \"target\" missing from For");
3747 if (PyObject_HasAttrString(obj
, "iter")) {
3749 tmp
= PyObject_GetAttrString(obj
, "iter");
3750 if (tmp
== NULL
) goto failed
;
3751 res
= obj2ast_expr(tmp
, &iter
, arena
);
3752 if (res
!= 0) goto failed
;
3756 PyErr_SetString(PyExc_TypeError
, "required field \"iter\" missing from For");
3759 if (PyObject_HasAttrString(obj
, "body")) {
3763 tmp
= PyObject_GetAttrString(obj
, "body");
3764 if (tmp
== NULL
) goto failed
;
3765 if (!PyList_Check(tmp
)) {
3766 PyErr_Format(PyExc_TypeError
, "For field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3769 len
= PyList_GET_SIZE(tmp
);
3770 body
= asdl_seq_new(len
, arena
);
3771 if (body
== NULL
) goto failed
;
3772 for (i
= 0; i
< len
; i
++) {
3774 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3775 if (res
!= 0) goto failed
;
3776 asdl_seq_SET(body
, i
, value
);
3781 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from For");
3784 if (PyObject_HasAttrString(obj
, "orelse")) {
3788 tmp
= PyObject_GetAttrString(obj
, "orelse");
3789 if (tmp
== NULL
) goto failed
;
3790 if (!PyList_Check(tmp
)) {
3791 PyErr_Format(PyExc_TypeError
, "For field \"orelse\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3794 len
= PyList_GET_SIZE(tmp
);
3795 orelse
= asdl_seq_new(len
, arena
);
3796 if (orelse
== NULL
) goto failed
;
3797 for (i
= 0; i
< len
; i
++) {
3799 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3800 if (res
!= 0) goto failed
;
3801 asdl_seq_SET(orelse
, i
, value
);
3806 PyErr_SetString(PyExc_TypeError
, "required field \"orelse\" missing from For");
3809 *out
= For(target
, iter
, body
, orelse
, lineno
, col_offset
,
3811 if (*out
== NULL
) goto failed
;
3814 if (PyObject_IsInstance(obj
, (PyObject
*)While_type
)) {
3819 if (PyObject_HasAttrString(obj
, "test")) {
3821 tmp
= PyObject_GetAttrString(obj
, "test");
3822 if (tmp
== NULL
) goto failed
;
3823 res
= obj2ast_expr(tmp
, &test
, arena
);
3824 if (res
!= 0) goto failed
;
3828 PyErr_SetString(PyExc_TypeError
, "required field \"test\" missing from While");
3831 if (PyObject_HasAttrString(obj
, "body")) {
3835 tmp
= PyObject_GetAttrString(obj
, "body");
3836 if (tmp
== NULL
) goto failed
;
3837 if (!PyList_Check(tmp
)) {
3838 PyErr_Format(PyExc_TypeError
, "While field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3841 len
= PyList_GET_SIZE(tmp
);
3842 body
= asdl_seq_new(len
, arena
);
3843 if (body
== NULL
) goto failed
;
3844 for (i
= 0; i
< len
; i
++) {
3846 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3847 if (res
!= 0) goto failed
;
3848 asdl_seq_SET(body
, i
, value
);
3853 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from While");
3856 if (PyObject_HasAttrString(obj
, "orelse")) {
3860 tmp
= PyObject_GetAttrString(obj
, "orelse");
3861 if (tmp
== NULL
) goto failed
;
3862 if (!PyList_Check(tmp
)) {
3863 PyErr_Format(PyExc_TypeError
, "While field \"orelse\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3866 len
= PyList_GET_SIZE(tmp
);
3867 orelse
= asdl_seq_new(len
, arena
);
3868 if (orelse
== NULL
) goto failed
;
3869 for (i
= 0; i
< len
; i
++) {
3871 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3872 if (res
!= 0) goto failed
;
3873 asdl_seq_SET(orelse
, i
, value
);
3878 PyErr_SetString(PyExc_TypeError
, "required field \"orelse\" missing from While");
3881 *out
= While(test
, body
, orelse
, lineno
, col_offset
, arena
);
3882 if (*out
== NULL
) goto failed
;
3885 if (PyObject_IsInstance(obj
, (PyObject
*)If_type
)) {
3890 if (PyObject_HasAttrString(obj
, "test")) {
3892 tmp
= PyObject_GetAttrString(obj
, "test");
3893 if (tmp
== NULL
) goto failed
;
3894 res
= obj2ast_expr(tmp
, &test
, arena
);
3895 if (res
!= 0) goto failed
;
3899 PyErr_SetString(PyExc_TypeError
, "required field \"test\" missing from If");
3902 if (PyObject_HasAttrString(obj
, "body")) {
3906 tmp
= PyObject_GetAttrString(obj
, "body");
3907 if (tmp
== NULL
) goto failed
;
3908 if (!PyList_Check(tmp
)) {
3909 PyErr_Format(PyExc_TypeError
, "If field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3912 len
= PyList_GET_SIZE(tmp
);
3913 body
= asdl_seq_new(len
, arena
);
3914 if (body
== NULL
) goto failed
;
3915 for (i
= 0; i
< len
; i
++) {
3917 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3918 if (res
!= 0) goto failed
;
3919 asdl_seq_SET(body
, i
, value
);
3924 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from If");
3927 if (PyObject_HasAttrString(obj
, "orelse")) {
3931 tmp
= PyObject_GetAttrString(obj
, "orelse");
3932 if (tmp
== NULL
) goto failed
;
3933 if (!PyList_Check(tmp
)) {
3934 PyErr_Format(PyExc_TypeError
, "If field \"orelse\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3937 len
= PyList_GET_SIZE(tmp
);
3938 orelse
= asdl_seq_new(len
, arena
);
3939 if (orelse
== NULL
) goto failed
;
3940 for (i
= 0; i
< len
; i
++) {
3942 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3943 if (res
!= 0) goto failed
;
3944 asdl_seq_SET(orelse
, i
, value
);
3949 PyErr_SetString(PyExc_TypeError
, "required field \"orelse\" missing from If");
3952 *out
= If(test
, body
, orelse
, lineno
, col_offset
, arena
);
3953 if (*out
== NULL
) goto failed
;
3956 if (PyObject_IsInstance(obj
, (PyObject
*)With_type
)) {
3957 expr_ty context_expr
;
3958 expr_ty optional_vars
;
3961 if (PyObject_HasAttrString(obj
, "context_expr")) {
3963 tmp
= PyObject_GetAttrString(obj
, "context_expr");
3964 if (tmp
== NULL
) goto failed
;
3965 res
= obj2ast_expr(tmp
, &context_expr
, arena
);
3966 if (res
!= 0) goto failed
;
3970 PyErr_SetString(PyExc_TypeError
, "required field \"context_expr\" missing from With");
3973 if (PyObject_HasAttrString(obj
, "optional_vars")) {
3975 tmp
= PyObject_GetAttrString(obj
, "optional_vars");
3976 if (tmp
== NULL
) goto failed
;
3977 res
= obj2ast_expr(tmp
, &optional_vars
, arena
);
3978 if (res
!= 0) goto failed
;
3982 optional_vars
= NULL
;
3984 if (PyObject_HasAttrString(obj
, "body")) {
3988 tmp
= PyObject_GetAttrString(obj
, "body");
3989 if (tmp
== NULL
) goto failed
;
3990 if (!PyList_Check(tmp
)) {
3991 PyErr_Format(PyExc_TypeError
, "With field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3994 len
= PyList_GET_SIZE(tmp
);
3995 body
= asdl_seq_new(len
, arena
);
3996 if (body
== NULL
) goto failed
;
3997 for (i
= 0; i
< len
; i
++) {
3999 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4000 if (res
!= 0) goto failed
;
4001 asdl_seq_SET(body
, i
, value
);
4006 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from With");
4009 *out
= With(context_expr
, optional_vars
, body
, lineno
,
4011 if (*out
== NULL
) goto failed
;
4014 if (PyObject_IsInstance(obj
, (PyObject
*)Raise_type
)) {
4019 if (PyObject_HasAttrString(obj
, "type")) {
4021 tmp
= PyObject_GetAttrString(obj
, "type");
4022 if (tmp
== NULL
) goto failed
;
4023 res
= obj2ast_expr(tmp
, &type
, arena
);
4024 if (res
!= 0) goto failed
;
4030 if (PyObject_HasAttrString(obj
, "inst")) {
4032 tmp
= PyObject_GetAttrString(obj
, "inst");
4033 if (tmp
== NULL
) goto failed
;
4034 res
= obj2ast_expr(tmp
, &inst
, arena
);
4035 if (res
!= 0) goto failed
;
4041 if (PyObject_HasAttrString(obj
, "tback")) {
4043 tmp
= PyObject_GetAttrString(obj
, "tback");
4044 if (tmp
== NULL
) goto failed
;
4045 res
= obj2ast_expr(tmp
, &tback
, arena
);
4046 if (res
!= 0) goto failed
;
4052 *out
= Raise(type
, inst
, tback
, lineno
, col_offset
, arena
);
4053 if (*out
== NULL
) goto failed
;
4056 if (PyObject_IsInstance(obj
, (PyObject
*)TryExcept_type
)) {
4061 if (PyObject_HasAttrString(obj
, "body")) {
4065 tmp
= PyObject_GetAttrString(obj
, "body");
4066 if (tmp
== NULL
) goto failed
;
4067 if (!PyList_Check(tmp
)) {
4068 PyErr_Format(PyExc_TypeError
, "TryExcept field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4071 len
= PyList_GET_SIZE(tmp
);
4072 body
= asdl_seq_new(len
, arena
);
4073 if (body
== NULL
) goto failed
;
4074 for (i
= 0; i
< len
; i
++) {
4076 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4077 if (res
!= 0) goto failed
;
4078 asdl_seq_SET(body
, i
, value
);
4083 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from TryExcept");
4086 if (PyObject_HasAttrString(obj
, "handlers")) {
4090 tmp
= PyObject_GetAttrString(obj
, "handlers");
4091 if (tmp
== NULL
) goto failed
;
4092 if (!PyList_Check(tmp
)) {
4093 PyErr_Format(PyExc_TypeError
, "TryExcept field \"handlers\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4096 len
= PyList_GET_SIZE(tmp
);
4097 handlers
= asdl_seq_new(len
, arena
);
4098 if (handlers
== NULL
) goto failed
;
4099 for (i
= 0; i
< len
; i
++) {
4100 excepthandler_ty value
;
4101 res
= obj2ast_excepthandler(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4102 if (res
!= 0) goto failed
;
4103 asdl_seq_SET(handlers
, i
, value
);
4108 PyErr_SetString(PyExc_TypeError
, "required field \"handlers\" missing from TryExcept");
4111 if (PyObject_HasAttrString(obj
, "orelse")) {
4115 tmp
= PyObject_GetAttrString(obj
, "orelse");
4116 if (tmp
== NULL
) goto failed
;
4117 if (!PyList_Check(tmp
)) {
4118 PyErr_Format(PyExc_TypeError
, "TryExcept field \"orelse\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4121 len
= PyList_GET_SIZE(tmp
);
4122 orelse
= asdl_seq_new(len
, arena
);
4123 if (orelse
== NULL
) goto failed
;
4124 for (i
= 0; i
< len
; i
++) {
4126 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4127 if (res
!= 0) goto failed
;
4128 asdl_seq_SET(orelse
, i
, value
);
4133 PyErr_SetString(PyExc_TypeError
, "required field \"orelse\" missing from TryExcept");
4136 *out
= TryExcept(body
, handlers
, orelse
, lineno
, col_offset
,
4138 if (*out
== NULL
) goto failed
;
4141 if (PyObject_IsInstance(obj
, (PyObject
*)TryFinally_type
)) {
4143 asdl_seq
* finalbody
;
4145 if (PyObject_HasAttrString(obj
, "body")) {
4149 tmp
= PyObject_GetAttrString(obj
, "body");
4150 if (tmp
== NULL
) goto failed
;
4151 if (!PyList_Check(tmp
)) {
4152 PyErr_Format(PyExc_TypeError
, "TryFinally field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4155 len
= PyList_GET_SIZE(tmp
);
4156 body
= asdl_seq_new(len
, arena
);
4157 if (body
== NULL
) goto failed
;
4158 for (i
= 0; i
< len
; i
++) {
4160 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4161 if (res
!= 0) goto failed
;
4162 asdl_seq_SET(body
, i
, value
);
4167 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from TryFinally");
4170 if (PyObject_HasAttrString(obj
, "finalbody")) {
4174 tmp
= PyObject_GetAttrString(obj
, "finalbody");
4175 if (tmp
== NULL
) goto failed
;
4176 if (!PyList_Check(tmp
)) {
4177 PyErr_Format(PyExc_TypeError
, "TryFinally field \"finalbody\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4180 len
= PyList_GET_SIZE(tmp
);
4181 finalbody
= asdl_seq_new(len
, arena
);
4182 if (finalbody
== NULL
) goto failed
;
4183 for (i
= 0; i
< len
; i
++) {
4185 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4186 if (res
!= 0) goto failed
;
4187 asdl_seq_SET(finalbody
, i
, value
);
4192 PyErr_SetString(PyExc_TypeError
, "required field \"finalbody\" missing from TryFinally");
4195 *out
= TryFinally(body
, finalbody
, lineno
, col_offset
, arena
);
4196 if (*out
== NULL
) goto failed
;
4199 if (PyObject_IsInstance(obj
, (PyObject
*)Assert_type
)) {
4203 if (PyObject_HasAttrString(obj
, "test")) {
4205 tmp
= PyObject_GetAttrString(obj
, "test");
4206 if (tmp
== NULL
) goto failed
;
4207 res
= obj2ast_expr(tmp
, &test
, arena
);
4208 if (res
!= 0) goto failed
;
4212 PyErr_SetString(PyExc_TypeError
, "required field \"test\" missing from Assert");
4215 if (PyObject_HasAttrString(obj
, "msg")) {
4217 tmp
= PyObject_GetAttrString(obj
, "msg");
4218 if (tmp
== NULL
) goto failed
;
4219 res
= obj2ast_expr(tmp
, &msg
, arena
);
4220 if (res
!= 0) goto failed
;
4226 *out
= Assert(test
, msg
, lineno
, col_offset
, arena
);
4227 if (*out
== NULL
) goto failed
;
4230 if (PyObject_IsInstance(obj
, (PyObject
*)Import_type
)) {
4233 if (PyObject_HasAttrString(obj
, "names")) {
4237 tmp
= PyObject_GetAttrString(obj
, "names");
4238 if (tmp
== NULL
) goto failed
;
4239 if (!PyList_Check(tmp
)) {
4240 PyErr_Format(PyExc_TypeError
, "Import field \"names\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4243 len
= PyList_GET_SIZE(tmp
);
4244 names
= asdl_seq_new(len
, arena
);
4245 if (names
== NULL
) goto failed
;
4246 for (i
= 0; i
< len
; i
++) {
4248 res
= obj2ast_alias(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4249 if (res
!= 0) goto failed
;
4250 asdl_seq_SET(names
, i
, value
);
4255 PyErr_SetString(PyExc_TypeError
, "required field \"names\" missing from Import");
4258 *out
= Import(names
, lineno
, col_offset
, arena
);
4259 if (*out
== NULL
) goto failed
;
4262 if (PyObject_IsInstance(obj
, (PyObject
*)ImportFrom_type
)) {
4267 if (PyObject_HasAttrString(obj
, "module")) {
4269 tmp
= PyObject_GetAttrString(obj
, "module");
4270 if (tmp
== NULL
) goto failed
;
4271 res
= obj2ast_identifier(tmp
, &module
, arena
);
4272 if (res
!= 0) goto failed
;
4276 PyErr_SetString(PyExc_TypeError
, "required field \"module\" missing from ImportFrom");
4279 if (PyObject_HasAttrString(obj
, "names")) {
4283 tmp
= PyObject_GetAttrString(obj
, "names");
4284 if (tmp
== NULL
) goto failed
;
4285 if (!PyList_Check(tmp
)) {
4286 PyErr_Format(PyExc_TypeError
, "ImportFrom field \"names\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4289 len
= PyList_GET_SIZE(tmp
);
4290 names
= asdl_seq_new(len
, arena
);
4291 if (names
== NULL
) goto failed
;
4292 for (i
= 0; i
< len
; i
++) {
4294 res
= obj2ast_alias(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4295 if (res
!= 0) goto failed
;
4296 asdl_seq_SET(names
, i
, value
);
4301 PyErr_SetString(PyExc_TypeError
, "required field \"names\" missing from ImportFrom");
4304 if (PyObject_HasAttrString(obj
, "level")) {
4306 tmp
= PyObject_GetAttrString(obj
, "level");
4307 if (tmp
== NULL
) goto failed
;
4308 res
= obj2ast_int(tmp
, &level
, arena
);
4309 if (res
!= 0) goto failed
;
4315 *out
= ImportFrom(module
, names
, level
, lineno
, col_offset
,
4317 if (*out
== NULL
) goto failed
;
4320 if (PyObject_IsInstance(obj
, (PyObject
*)Exec_type
)) {
4325 if (PyObject_HasAttrString(obj
, "body")) {
4327 tmp
= PyObject_GetAttrString(obj
, "body");
4328 if (tmp
== NULL
) goto failed
;
4329 res
= obj2ast_expr(tmp
, &body
, arena
);
4330 if (res
!= 0) goto failed
;
4334 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from Exec");
4337 if (PyObject_HasAttrString(obj
, "globals")) {
4339 tmp
= PyObject_GetAttrString(obj
, "globals");
4340 if (tmp
== NULL
) goto failed
;
4341 res
= obj2ast_expr(tmp
, &globals
, arena
);
4342 if (res
!= 0) goto failed
;
4348 if (PyObject_HasAttrString(obj
, "locals")) {
4350 tmp
= PyObject_GetAttrString(obj
, "locals");
4351 if (tmp
== NULL
) goto failed
;
4352 res
= obj2ast_expr(tmp
, &locals
, arena
);
4353 if (res
!= 0) goto failed
;
4359 *out
= Exec(body
, globals
, locals
, lineno
, col_offset
, arena
);
4360 if (*out
== NULL
) goto failed
;
4363 if (PyObject_IsInstance(obj
, (PyObject
*)Global_type
)) {
4366 if (PyObject_HasAttrString(obj
, "names")) {
4370 tmp
= PyObject_GetAttrString(obj
, "names");
4371 if (tmp
== NULL
) goto failed
;
4372 if (!PyList_Check(tmp
)) {
4373 PyErr_Format(PyExc_TypeError
, "Global field \"names\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4376 len
= PyList_GET_SIZE(tmp
);
4377 names
= asdl_seq_new(len
, arena
);
4378 if (names
== NULL
) goto failed
;
4379 for (i
= 0; i
< len
; i
++) {
4381 res
= obj2ast_identifier(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4382 if (res
!= 0) goto failed
;
4383 asdl_seq_SET(names
, i
, value
);
4388 PyErr_SetString(PyExc_TypeError
, "required field \"names\" missing from Global");
4391 *out
= Global(names
, lineno
, col_offset
, arena
);
4392 if (*out
== NULL
) goto failed
;
4395 if (PyObject_IsInstance(obj
, (PyObject
*)Expr_type
)) {
4398 if (PyObject_HasAttrString(obj
, "value")) {
4400 tmp
= PyObject_GetAttrString(obj
, "value");
4401 if (tmp
== NULL
) goto failed
;
4402 res
= obj2ast_expr(tmp
, &value
, arena
);
4403 if (res
!= 0) goto failed
;
4407 PyErr_SetString(PyExc_TypeError
, "required field \"value\" missing from Expr");
4410 *out
= Expr(value
, lineno
, col_offset
, arena
);
4411 if (*out
== NULL
) goto failed
;
4414 if (PyObject_IsInstance(obj
, (PyObject
*)Pass_type
)) {
4416 *out
= Pass(lineno
, col_offset
, arena
);
4417 if (*out
== NULL
) goto failed
;
4420 if (PyObject_IsInstance(obj
, (PyObject
*)Break_type
)) {
4422 *out
= Break(lineno
, col_offset
, arena
);
4423 if (*out
== NULL
) goto failed
;
4426 if (PyObject_IsInstance(obj
, (PyObject
*)Continue_type
)) {
4428 *out
= Continue(lineno
, col_offset
, arena
);
4429 if (*out
== NULL
) goto failed
;
4433 tmp
= PyObject_Repr(obj
);
4434 if (tmp
== NULL
) goto failed
;
4435 PyErr_Format(PyExc_TypeError
, "expected some sort of stmt, but got %.400s", PyString_AS_STRING(tmp
));
4442 obj2ast_expr(PyObject
* obj
, expr_ty
* out
, PyArena
* arena
)
4444 PyObject
* tmp
= NULL
;
4449 if (obj
== Py_None
) {
4453 if (PyObject_HasAttrString(obj
, "lineno")) {
4455 tmp
= PyObject_GetAttrString(obj
, "lineno");
4456 if (tmp
== NULL
) goto failed
;
4457 res
= obj2ast_int(tmp
, &lineno
, arena
);
4458 if (res
!= 0) goto failed
;
4462 PyErr_SetString(PyExc_TypeError
, "required field \"lineno\" missing from expr");
4465 if (PyObject_HasAttrString(obj
, "col_offset")) {
4467 tmp
= PyObject_GetAttrString(obj
, "col_offset");
4468 if (tmp
== NULL
) goto failed
;
4469 res
= obj2ast_int(tmp
, &col_offset
, arena
);
4470 if (res
!= 0) goto failed
;
4474 PyErr_SetString(PyExc_TypeError
, "required field \"col_offset\" missing from expr");
4477 if (PyObject_IsInstance(obj
, (PyObject
*)BoolOp_type
)) {
4481 if (PyObject_HasAttrString(obj
, "op")) {
4483 tmp
= PyObject_GetAttrString(obj
, "op");
4484 if (tmp
== NULL
) goto failed
;
4485 res
= obj2ast_boolop(tmp
, &op
, arena
);
4486 if (res
!= 0) goto failed
;
4490 PyErr_SetString(PyExc_TypeError
, "required field \"op\" missing from BoolOp");
4493 if (PyObject_HasAttrString(obj
, "values")) {
4497 tmp
= PyObject_GetAttrString(obj
, "values");
4498 if (tmp
== NULL
) goto failed
;
4499 if (!PyList_Check(tmp
)) {
4500 PyErr_Format(PyExc_TypeError
, "BoolOp field \"values\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4503 len
= PyList_GET_SIZE(tmp
);
4504 values
= asdl_seq_new(len
, arena
);
4505 if (values
== NULL
) goto failed
;
4506 for (i
= 0; i
< len
; i
++) {
4508 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4509 if (res
!= 0) goto failed
;
4510 asdl_seq_SET(values
, i
, value
);
4515 PyErr_SetString(PyExc_TypeError
, "required field \"values\" missing from BoolOp");
4518 *out
= BoolOp(op
, values
, lineno
, col_offset
, arena
);
4519 if (*out
== NULL
) goto failed
;
4522 if (PyObject_IsInstance(obj
, (PyObject
*)BinOp_type
)) {
4527 if (PyObject_HasAttrString(obj
, "left")) {
4529 tmp
= PyObject_GetAttrString(obj
, "left");
4530 if (tmp
== NULL
) goto failed
;
4531 res
= obj2ast_expr(tmp
, &left
, arena
);
4532 if (res
!= 0) goto failed
;
4536 PyErr_SetString(PyExc_TypeError
, "required field \"left\" missing from BinOp");
4539 if (PyObject_HasAttrString(obj
, "op")) {
4541 tmp
= PyObject_GetAttrString(obj
, "op");
4542 if (tmp
== NULL
) goto failed
;
4543 res
= obj2ast_operator(tmp
, &op
, arena
);
4544 if (res
!= 0) goto failed
;
4548 PyErr_SetString(PyExc_TypeError
, "required field \"op\" missing from BinOp");
4551 if (PyObject_HasAttrString(obj
, "right")) {
4553 tmp
= PyObject_GetAttrString(obj
, "right");
4554 if (tmp
== NULL
) goto failed
;
4555 res
= obj2ast_expr(tmp
, &right
, arena
);
4556 if (res
!= 0) goto failed
;
4560 PyErr_SetString(PyExc_TypeError
, "required field \"right\" missing from BinOp");
4563 *out
= BinOp(left
, op
, right
, lineno
, col_offset
, arena
);
4564 if (*out
== NULL
) goto failed
;
4567 if (PyObject_IsInstance(obj
, (PyObject
*)UnaryOp_type
)) {
4571 if (PyObject_HasAttrString(obj
, "op")) {
4573 tmp
= PyObject_GetAttrString(obj
, "op");
4574 if (tmp
== NULL
) goto failed
;
4575 res
= obj2ast_unaryop(tmp
, &op
, arena
);
4576 if (res
!= 0) goto failed
;
4580 PyErr_SetString(PyExc_TypeError
, "required field \"op\" missing from UnaryOp");
4583 if (PyObject_HasAttrString(obj
, "operand")) {
4585 tmp
= PyObject_GetAttrString(obj
, "operand");
4586 if (tmp
== NULL
) goto failed
;
4587 res
= obj2ast_expr(tmp
, &operand
, arena
);
4588 if (res
!= 0) goto failed
;
4592 PyErr_SetString(PyExc_TypeError
, "required field \"operand\" missing from UnaryOp");
4595 *out
= UnaryOp(op
, operand
, lineno
, col_offset
, arena
);
4596 if (*out
== NULL
) goto failed
;
4599 if (PyObject_IsInstance(obj
, (PyObject
*)Lambda_type
)) {
4603 if (PyObject_HasAttrString(obj
, "args")) {
4605 tmp
= PyObject_GetAttrString(obj
, "args");
4606 if (tmp
== NULL
) goto failed
;
4607 res
= obj2ast_arguments(tmp
, &args
, arena
);
4608 if (res
!= 0) goto failed
;
4612 PyErr_SetString(PyExc_TypeError
, "required field \"args\" missing from Lambda");
4615 if (PyObject_HasAttrString(obj
, "body")) {
4617 tmp
= PyObject_GetAttrString(obj
, "body");
4618 if (tmp
== NULL
) goto failed
;
4619 res
= obj2ast_expr(tmp
, &body
, arena
);
4620 if (res
!= 0) goto failed
;
4624 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from Lambda");
4627 *out
= Lambda(args
, body
, lineno
, col_offset
, arena
);
4628 if (*out
== NULL
) goto failed
;
4631 if (PyObject_IsInstance(obj
, (PyObject
*)IfExp_type
)) {
4636 if (PyObject_HasAttrString(obj
, "test")) {
4638 tmp
= PyObject_GetAttrString(obj
, "test");
4639 if (tmp
== NULL
) goto failed
;
4640 res
= obj2ast_expr(tmp
, &test
, arena
);
4641 if (res
!= 0) goto failed
;
4645 PyErr_SetString(PyExc_TypeError
, "required field \"test\" missing from IfExp");
4648 if (PyObject_HasAttrString(obj
, "body")) {
4650 tmp
= PyObject_GetAttrString(obj
, "body");
4651 if (tmp
== NULL
) goto failed
;
4652 res
= obj2ast_expr(tmp
, &body
, arena
);
4653 if (res
!= 0) goto failed
;
4657 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from IfExp");
4660 if (PyObject_HasAttrString(obj
, "orelse")) {
4662 tmp
= PyObject_GetAttrString(obj
, "orelse");
4663 if (tmp
== NULL
) goto failed
;
4664 res
= obj2ast_expr(tmp
, &orelse
, arena
);
4665 if (res
!= 0) goto failed
;
4669 PyErr_SetString(PyExc_TypeError
, "required field \"orelse\" missing from IfExp");
4672 *out
= IfExp(test
, body
, orelse
, lineno
, col_offset
, arena
);
4673 if (*out
== NULL
) goto failed
;
4676 if (PyObject_IsInstance(obj
, (PyObject
*)Dict_type
)) {
4680 if (PyObject_HasAttrString(obj
, "keys")) {
4684 tmp
= PyObject_GetAttrString(obj
, "keys");
4685 if (tmp
== NULL
) goto failed
;
4686 if (!PyList_Check(tmp
)) {
4687 PyErr_Format(PyExc_TypeError
, "Dict field \"keys\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4690 len
= PyList_GET_SIZE(tmp
);
4691 keys
= asdl_seq_new(len
, arena
);
4692 if (keys
== NULL
) goto failed
;
4693 for (i
= 0; i
< len
; i
++) {
4695 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4696 if (res
!= 0) goto failed
;
4697 asdl_seq_SET(keys
, i
, value
);
4702 PyErr_SetString(PyExc_TypeError
, "required field \"keys\" missing from Dict");
4705 if (PyObject_HasAttrString(obj
, "values")) {
4709 tmp
= PyObject_GetAttrString(obj
, "values");
4710 if (tmp
== NULL
) goto failed
;
4711 if (!PyList_Check(tmp
)) {
4712 PyErr_Format(PyExc_TypeError
, "Dict field \"values\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4715 len
= PyList_GET_SIZE(tmp
);
4716 values
= asdl_seq_new(len
, arena
);
4717 if (values
== NULL
) goto failed
;
4718 for (i
= 0; i
< len
; i
++) {
4720 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4721 if (res
!= 0) goto failed
;
4722 asdl_seq_SET(values
, i
, value
);
4727 PyErr_SetString(PyExc_TypeError
, "required field \"values\" missing from Dict");
4730 *out
= Dict(keys
, values
, lineno
, col_offset
, arena
);
4731 if (*out
== NULL
) goto failed
;
4734 if (PyObject_IsInstance(obj
, (PyObject
*)ListComp_type
)) {
4736 asdl_seq
* generators
;
4738 if (PyObject_HasAttrString(obj
, "elt")) {
4740 tmp
= PyObject_GetAttrString(obj
, "elt");
4741 if (tmp
== NULL
) goto failed
;
4742 res
= obj2ast_expr(tmp
, &elt
, arena
);
4743 if (res
!= 0) goto failed
;
4747 PyErr_SetString(PyExc_TypeError
, "required field \"elt\" missing from ListComp");
4750 if (PyObject_HasAttrString(obj
, "generators")) {
4754 tmp
= PyObject_GetAttrString(obj
, "generators");
4755 if (tmp
== NULL
) goto failed
;
4756 if (!PyList_Check(tmp
)) {
4757 PyErr_Format(PyExc_TypeError
, "ListComp field \"generators\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4760 len
= PyList_GET_SIZE(tmp
);
4761 generators
= asdl_seq_new(len
, arena
);
4762 if (generators
== NULL
) goto failed
;
4763 for (i
= 0; i
< len
; i
++) {
4764 comprehension_ty value
;
4765 res
= obj2ast_comprehension(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4766 if (res
!= 0) goto failed
;
4767 asdl_seq_SET(generators
, i
, value
);
4772 PyErr_SetString(PyExc_TypeError
, "required field \"generators\" missing from ListComp");
4775 *out
= ListComp(elt
, generators
, lineno
, col_offset
, arena
);
4776 if (*out
== NULL
) goto failed
;
4779 if (PyObject_IsInstance(obj
, (PyObject
*)GeneratorExp_type
)) {
4781 asdl_seq
* generators
;
4783 if (PyObject_HasAttrString(obj
, "elt")) {
4785 tmp
= PyObject_GetAttrString(obj
, "elt");
4786 if (tmp
== NULL
) goto failed
;
4787 res
= obj2ast_expr(tmp
, &elt
, arena
);
4788 if (res
!= 0) goto failed
;
4792 PyErr_SetString(PyExc_TypeError
, "required field \"elt\" missing from GeneratorExp");
4795 if (PyObject_HasAttrString(obj
, "generators")) {
4799 tmp
= PyObject_GetAttrString(obj
, "generators");
4800 if (tmp
== NULL
) goto failed
;
4801 if (!PyList_Check(tmp
)) {
4802 PyErr_Format(PyExc_TypeError
, "GeneratorExp field \"generators\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4805 len
= PyList_GET_SIZE(tmp
);
4806 generators
= asdl_seq_new(len
, arena
);
4807 if (generators
== NULL
) goto failed
;
4808 for (i
= 0; i
< len
; i
++) {
4809 comprehension_ty value
;
4810 res
= obj2ast_comprehension(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4811 if (res
!= 0) goto failed
;
4812 asdl_seq_SET(generators
, i
, value
);
4817 PyErr_SetString(PyExc_TypeError
, "required field \"generators\" missing from GeneratorExp");
4820 *out
= GeneratorExp(elt
, generators
, lineno
, col_offset
, arena
);
4821 if (*out
== NULL
) goto failed
;
4824 if (PyObject_IsInstance(obj
, (PyObject
*)Yield_type
)) {
4827 if (PyObject_HasAttrString(obj
, "value")) {
4829 tmp
= PyObject_GetAttrString(obj
, "value");
4830 if (tmp
== NULL
) goto failed
;
4831 res
= obj2ast_expr(tmp
, &value
, arena
);
4832 if (res
!= 0) goto failed
;
4838 *out
= Yield(value
, lineno
, col_offset
, arena
);
4839 if (*out
== NULL
) goto failed
;
4842 if (PyObject_IsInstance(obj
, (PyObject
*)Compare_type
)) {
4845 asdl_seq
* comparators
;
4847 if (PyObject_HasAttrString(obj
, "left")) {
4849 tmp
= PyObject_GetAttrString(obj
, "left");
4850 if (tmp
== NULL
) goto failed
;
4851 res
= obj2ast_expr(tmp
, &left
, arena
);
4852 if (res
!= 0) goto failed
;
4856 PyErr_SetString(PyExc_TypeError
, "required field \"left\" missing from Compare");
4859 if (PyObject_HasAttrString(obj
, "ops")) {
4863 tmp
= PyObject_GetAttrString(obj
, "ops");
4864 if (tmp
== NULL
) goto failed
;
4865 if (!PyList_Check(tmp
)) {
4866 PyErr_Format(PyExc_TypeError
, "Compare field \"ops\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4869 len
= PyList_GET_SIZE(tmp
);
4870 ops
= asdl_int_seq_new(len
, arena
);
4871 if (ops
== NULL
) goto failed
;
4872 for (i
= 0; i
< len
; i
++) {
4874 res
= obj2ast_cmpop(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4875 if (res
!= 0) goto failed
;
4876 asdl_seq_SET(ops
, i
, value
);
4881 PyErr_SetString(PyExc_TypeError
, "required field \"ops\" missing from Compare");
4884 if (PyObject_HasAttrString(obj
, "comparators")) {
4888 tmp
= PyObject_GetAttrString(obj
, "comparators");
4889 if (tmp
== NULL
) goto failed
;
4890 if (!PyList_Check(tmp
)) {
4891 PyErr_Format(PyExc_TypeError
, "Compare field \"comparators\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4894 len
= PyList_GET_SIZE(tmp
);
4895 comparators
= asdl_seq_new(len
, arena
);
4896 if (comparators
== NULL
) goto failed
;
4897 for (i
= 0; i
< len
; i
++) {
4899 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4900 if (res
!= 0) goto failed
;
4901 asdl_seq_SET(comparators
, i
, value
);
4906 PyErr_SetString(PyExc_TypeError
, "required field \"comparators\" missing from Compare");
4909 *out
= Compare(left
, ops
, comparators
, lineno
, col_offset
,
4911 if (*out
== NULL
) goto failed
;
4914 if (PyObject_IsInstance(obj
, (PyObject
*)Call_type
)) {
4921 if (PyObject_HasAttrString(obj
, "func")) {
4923 tmp
= PyObject_GetAttrString(obj
, "func");
4924 if (tmp
== NULL
) goto failed
;
4925 res
= obj2ast_expr(tmp
, &func
, arena
);
4926 if (res
!= 0) goto failed
;
4930 PyErr_SetString(PyExc_TypeError
, "required field \"func\" missing from Call");
4933 if (PyObject_HasAttrString(obj
, "args")) {
4937 tmp
= PyObject_GetAttrString(obj
, "args");
4938 if (tmp
== NULL
) goto failed
;
4939 if (!PyList_Check(tmp
)) {
4940 PyErr_Format(PyExc_TypeError
, "Call field \"args\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4943 len
= PyList_GET_SIZE(tmp
);
4944 args
= asdl_seq_new(len
, arena
);
4945 if (args
== NULL
) goto failed
;
4946 for (i
= 0; i
< len
; i
++) {
4948 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4949 if (res
!= 0) goto failed
;
4950 asdl_seq_SET(args
, i
, value
);
4955 PyErr_SetString(PyExc_TypeError
, "required field \"args\" missing from Call");
4958 if (PyObject_HasAttrString(obj
, "keywords")) {
4962 tmp
= PyObject_GetAttrString(obj
, "keywords");
4963 if (tmp
== NULL
) goto failed
;
4964 if (!PyList_Check(tmp
)) {
4965 PyErr_Format(PyExc_TypeError
, "Call field \"keywords\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4968 len
= PyList_GET_SIZE(tmp
);
4969 keywords
= asdl_seq_new(len
, arena
);
4970 if (keywords
== NULL
) goto failed
;
4971 for (i
= 0; i
< len
; i
++) {
4973 res
= obj2ast_keyword(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4974 if (res
!= 0) goto failed
;
4975 asdl_seq_SET(keywords
, i
, value
);
4980 PyErr_SetString(PyExc_TypeError
, "required field \"keywords\" missing from Call");
4983 if (PyObject_HasAttrString(obj
, "starargs")) {
4985 tmp
= PyObject_GetAttrString(obj
, "starargs");
4986 if (tmp
== NULL
) goto failed
;
4987 res
= obj2ast_expr(tmp
, &starargs
, arena
);
4988 if (res
!= 0) goto failed
;
4994 if (PyObject_HasAttrString(obj
, "kwargs")) {
4996 tmp
= PyObject_GetAttrString(obj
, "kwargs");
4997 if (tmp
== NULL
) goto failed
;
4998 res
= obj2ast_expr(tmp
, &kwargs
, arena
);
4999 if (res
!= 0) goto failed
;
5005 *out
= Call(func
, args
, keywords
, starargs
, kwargs
, lineno
,
5007 if (*out
== NULL
) goto failed
;
5010 if (PyObject_IsInstance(obj
, (PyObject
*)Repr_type
)) {
5013 if (PyObject_HasAttrString(obj
, "value")) {
5015 tmp
= PyObject_GetAttrString(obj
, "value");
5016 if (tmp
== NULL
) goto failed
;
5017 res
= obj2ast_expr(tmp
, &value
, arena
);
5018 if (res
!= 0) goto failed
;
5022 PyErr_SetString(PyExc_TypeError
, "required field \"value\" missing from Repr");
5025 *out
= Repr(value
, lineno
, col_offset
, arena
);
5026 if (*out
== NULL
) goto failed
;
5029 if (PyObject_IsInstance(obj
, (PyObject
*)Num_type
)) {
5032 if (PyObject_HasAttrString(obj
, "n")) {
5034 tmp
= PyObject_GetAttrString(obj
, "n");
5035 if (tmp
== NULL
) goto failed
;
5036 res
= obj2ast_object(tmp
, &n
, arena
);
5037 if (res
!= 0) goto failed
;
5041 PyErr_SetString(PyExc_TypeError
, "required field \"n\" missing from Num");
5044 *out
= Num(n
, lineno
, col_offset
, arena
);
5045 if (*out
== NULL
) goto failed
;
5048 if (PyObject_IsInstance(obj
, (PyObject
*)Str_type
)) {
5051 if (PyObject_HasAttrString(obj
, "s")) {
5053 tmp
= PyObject_GetAttrString(obj
, "s");
5054 if (tmp
== NULL
) goto failed
;
5055 res
= obj2ast_string(tmp
, &s
, arena
);
5056 if (res
!= 0) goto failed
;
5060 PyErr_SetString(PyExc_TypeError
, "required field \"s\" missing from Str");
5063 *out
= Str(s
, lineno
, col_offset
, arena
);
5064 if (*out
== NULL
) goto failed
;
5067 if (PyObject_IsInstance(obj
, (PyObject
*)Attribute_type
)) {
5070 expr_context_ty ctx
;
5072 if (PyObject_HasAttrString(obj
, "value")) {
5074 tmp
= PyObject_GetAttrString(obj
, "value");
5075 if (tmp
== NULL
) goto failed
;
5076 res
= obj2ast_expr(tmp
, &value
, arena
);
5077 if (res
!= 0) goto failed
;
5081 PyErr_SetString(PyExc_TypeError
, "required field \"value\" missing from Attribute");
5084 if (PyObject_HasAttrString(obj
, "attr")) {
5086 tmp
= PyObject_GetAttrString(obj
, "attr");
5087 if (tmp
== NULL
) goto failed
;
5088 res
= obj2ast_identifier(tmp
, &attr
, arena
);
5089 if (res
!= 0) goto failed
;
5093 PyErr_SetString(PyExc_TypeError
, "required field \"attr\" missing from Attribute");
5096 if (PyObject_HasAttrString(obj
, "ctx")) {
5098 tmp
= PyObject_GetAttrString(obj
, "ctx");
5099 if (tmp
== NULL
) goto failed
;
5100 res
= obj2ast_expr_context(tmp
, &ctx
, arena
);
5101 if (res
!= 0) goto failed
;
5105 PyErr_SetString(PyExc_TypeError
, "required field \"ctx\" missing from Attribute");
5108 *out
= Attribute(value
, attr
, ctx
, lineno
, col_offset
, arena
);
5109 if (*out
== NULL
) goto failed
;
5112 if (PyObject_IsInstance(obj
, (PyObject
*)Subscript_type
)) {
5115 expr_context_ty ctx
;
5117 if (PyObject_HasAttrString(obj
, "value")) {
5119 tmp
= PyObject_GetAttrString(obj
, "value");
5120 if (tmp
== NULL
) goto failed
;
5121 res
= obj2ast_expr(tmp
, &value
, arena
);
5122 if (res
!= 0) goto failed
;
5126 PyErr_SetString(PyExc_TypeError
, "required field \"value\" missing from Subscript");
5129 if (PyObject_HasAttrString(obj
, "slice")) {
5131 tmp
= PyObject_GetAttrString(obj
, "slice");
5132 if (tmp
== NULL
) goto failed
;
5133 res
= obj2ast_slice(tmp
, &slice
, arena
);
5134 if (res
!= 0) goto failed
;
5138 PyErr_SetString(PyExc_TypeError
, "required field \"slice\" missing from Subscript");
5141 if (PyObject_HasAttrString(obj
, "ctx")) {
5143 tmp
= PyObject_GetAttrString(obj
, "ctx");
5144 if (tmp
== NULL
) goto failed
;
5145 res
= obj2ast_expr_context(tmp
, &ctx
, arena
);
5146 if (res
!= 0) goto failed
;
5150 PyErr_SetString(PyExc_TypeError
, "required field \"ctx\" missing from Subscript");
5153 *out
= Subscript(value
, slice
, ctx
, lineno
, col_offset
, arena
);
5154 if (*out
== NULL
) goto failed
;
5157 if (PyObject_IsInstance(obj
, (PyObject
*)Name_type
)) {
5159 expr_context_ty ctx
;
5161 if (PyObject_HasAttrString(obj
, "id")) {
5163 tmp
= PyObject_GetAttrString(obj
, "id");
5164 if (tmp
== NULL
) goto failed
;
5165 res
= obj2ast_identifier(tmp
, &id
, arena
);
5166 if (res
!= 0) goto failed
;
5170 PyErr_SetString(PyExc_TypeError
, "required field \"id\" missing from Name");
5173 if (PyObject_HasAttrString(obj
, "ctx")) {
5175 tmp
= PyObject_GetAttrString(obj
, "ctx");
5176 if (tmp
== NULL
) goto failed
;
5177 res
= obj2ast_expr_context(tmp
, &ctx
, arena
);
5178 if (res
!= 0) goto failed
;
5182 PyErr_SetString(PyExc_TypeError
, "required field \"ctx\" missing from Name");
5185 *out
= Name(id
, ctx
, lineno
, col_offset
, arena
);
5186 if (*out
== NULL
) goto failed
;
5189 if (PyObject_IsInstance(obj
, (PyObject
*)List_type
)) {
5191 expr_context_ty ctx
;
5193 if (PyObject_HasAttrString(obj
, "elts")) {
5197 tmp
= PyObject_GetAttrString(obj
, "elts");
5198 if (tmp
== NULL
) goto failed
;
5199 if (!PyList_Check(tmp
)) {
5200 PyErr_Format(PyExc_TypeError
, "List field \"elts\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5203 len
= PyList_GET_SIZE(tmp
);
5204 elts
= asdl_seq_new(len
, arena
);
5205 if (elts
== NULL
) goto failed
;
5206 for (i
= 0; i
< len
; i
++) {
5208 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5209 if (res
!= 0) goto failed
;
5210 asdl_seq_SET(elts
, i
, value
);
5215 PyErr_SetString(PyExc_TypeError
, "required field \"elts\" missing from List");
5218 if (PyObject_HasAttrString(obj
, "ctx")) {
5220 tmp
= PyObject_GetAttrString(obj
, "ctx");
5221 if (tmp
== NULL
) goto failed
;
5222 res
= obj2ast_expr_context(tmp
, &ctx
, arena
);
5223 if (res
!= 0) goto failed
;
5227 PyErr_SetString(PyExc_TypeError
, "required field \"ctx\" missing from List");
5230 *out
= List(elts
, ctx
, lineno
, col_offset
, arena
);
5231 if (*out
== NULL
) goto failed
;
5234 if (PyObject_IsInstance(obj
, (PyObject
*)Tuple_type
)) {
5236 expr_context_ty ctx
;
5238 if (PyObject_HasAttrString(obj
, "elts")) {
5242 tmp
= PyObject_GetAttrString(obj
, "elts");
5243 if (tmp
== NULL
) goto failed
;
5244 if (!PyList_Check(tmp
)) {
5245 PyErr_Format(PyExc_TypeError
, "Tuple field \"elts\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5248 len
= PyList_GET_SIZE(tmp
);
5249 elts
= asdl_seq_new(len
, arena
);
5250 if (elts
== NULL
) goto failed
;
5251 for (i
= 0; i
< len
; i
++) {
5253 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5254 if (res
!= 0) goto failed
;
5255 asdl_seq_SET(elts
, i
, value
);
5260 PyErr_SetString(PyExc_TypeError
, "required field \"elts\" missing from Tuple");
5263 if (PyObject_HasAttrString(obj
, "ctx")) {
5265 tmp
= PyObject_GetAttrString(obj
, "ctx");
5266 if (tmp
== NULL
) goto failed
;
5267 res
= obj2ast_expr_context(tmp
, &ctx
, arena
);
5268 if (res
!= 0) goto failed
;
5272 PyErr_SetString(PyExc_TypeError
, "required field \"ctx\" missing from Tuple");
5275 *out
= Tuple(elts
, ctx
, lineno
, col_offset
, arena
);
5276 if (*out
== NULL
) goto failed
;
5280 tmp
= PyObject_Repr(obj
);
5281 if (tmp
== NULL
) goto failed
;
5282 PyErr_Format(PyExc_TypeError
, "expected some sort of expr, but got %.400s", PyString_AS_STRING(tmp
));
5289 obj2ast_expr_context(PyObject
* obj
, expr_context_ty
* out
, PyArena
* arena
)
5291 PyObject
* tmp
= NULL
;
5293 if (PyObject_IsInstance(obj
, (PyObject
*)Load_type
)) {
5297 if (PyObject_IsInstance(obj
, (PyObject
*)Store_type
)) {
5301 if (PyObject_IsInstance(obj
, (PyObject
*)Del_type
)) {
5305 if (PyObject_IsInstance(obj
, (PyObject
*)AugLoad_type
)) {
5309 if (PyObject_IsInstance(obj
, (PyObject
*)AugStore_type
)) {
5313 if (PyObject_IsInstance(obj
, (PyObject
*)Param_type
)) {
5318 tmp
= PyObject_Repr(obj
);
5319 if (tmp
== NULL
) goto failed
;
5320 PyErr_Format(PyExc_TypeError
, "expected some sort of expr_context, but got %.400s", PyString_AS_STRING(tmp
));
5327 obj2ast_slice(PyObject
* obj
, slice_ty
* out
, PyArena
* arena
)
5329 PyObject
* tmp
= NULL
;
5332 if (obj
== Py_None
) {
5336 if (PyObject_IsInstance(obj
, (PyObject
*)Ellipsis_type
)) {
5338 *out
= Ellipsis(arena
);
5339 if (*out
== NULL
) goto failed
;
5342 if (PyObject_IsInstance(obj
, (PyObject
*)Slice_type
)) {
5347 if (PyObject_HasAttrString(obj
, "lower")) {
5349 tmp
= PyObject_GetAttrString(obj
, "lower");
5350 if (tmp
== NULL
) goto failed
;
5351 res
= obj2ast_expr(tmp
, &lower
, arena
);
5352 if (res
!= 0) goto failed
;
5358 if (PyObject_HasAttrString(obj
, "upper")) {
5360 tmp
= PyObject_GetAttrString(obj
, "upper");
5361 if (tmp
== NULL
) goto failed
;
5362 res
= obj2ast_expr(tmp
, &upper
, arena
);
5363 if (res
!= 0) goto failed
;
5369 if (PyObject_HasAttrString(obj
, "step")) {
5371 tmp
= PyObject_GetAttrString(obj
, "step");
5372 if (tmp
== NULL
) goto failed
;
5373 res
= obj2ast_expr(tmp
, &step
, arena
);
5374 if (res
!= 0) goto failed
;
5380 *out
= Slice(lower
, upper
, step
, arena
);
5381 if (*out
== NULL
) goto failed
;
5384 if (PyObject_IsInstance(obj
, (PyObject
*)ExtSlice_type
)) {
5387 if (PyObject_HasAttrString(obj
, "dims")) {
5391 tmp
= PyObject_GetAttrString(obj
, "dims");
5392 if (tmp
== NULL
) goto failed
;
5393 if (!PyList_Check(tmp
)) {
5394 PyErr_Format(PyExc_TypeError
, "ExtSlice field \"dims\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5397 len
= PyList_GET_SIZE(tmp
);
5398 dims
= asdl_seq_new(len
, arena
);
5399 if (dims
== NULL
) goto failed
;
5400 for (i
= 0; i
< len
; i
++) {
5402 res
= obj2ast_slice(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5403 if (res
!= 0) goto failed
;
5404 asdl_seq_SET(dims
, i
, value
);
5409 PyErr_SetString(PyExc_TypeError
, "required field \"dims\" missing from ExtSlice");
5412 *out
= ExtSlice(dims
, arena
);
5413 if (*out
== NULL
) goto failed
;
5416 if (PyObject_IsInstance(obj
, (PyObject
*)Index_type
)) {
5419 if (PyObject_HasAttrString(obj
, "value")) {
5421 tmp
= PyObject_GetAttrString(obj
, "value");
5422 if (tmp
== NULL
) goto failed
;
5423 res
= obj2ast_expr(tmp
, &value
, arena
);
5424 if (res
!= 0) goto failed
;
5428 PyErr_SetString(PyExc_TypeError
, "required field \"value\" missing from Index");
5431 *out
= Index(value
, arena
);
5432 if (*out
== NULL
) goto failed
;
5436 tmp
= PyObject_Repr(obj
);
5437 if (tmp
== NULL
) goto failed
;
5438 PyErr_Format(PyExc_TypeError
, "expected some sort of slice, but got %.400s", PyString_AS_STRING(tmp
));
5445 obj2ast_boolop(PyObject
* obj
, boolop_ty
* out
, PyArena
* arena
)
5447 PyObject
* tmp
= NULL
;
5449 if (PyObject_IsInstance(obj
, (PyObject
*)And_type
)) {
5453 if (PyObject_IsInstance(obj
, (PyObject
*)Or_type
)) {
5458 tmp
= PyObject_Repr(obj
);
5459 if (tmp
== NULL
) goto failed
;
5460 PyErr_Format(PyExc_TypeError
, "expected some sort of boolop, but got %.400s", PyString_AS_STRING(tmp
));
5467 obj2ast_operator(PyObject
* obj
, operator_ty
* out
, PyArena
* arena
)
5469 PyObject
* tmp
= NULL
;
5471 if (PyObject_IsInstance(obj
, (PyObject
*)Add_type
)) {
5475 if (PyObject_IsInstance(obj
, (PyObject
*)Sub_type
)) {
5479 if (PyObject_IsInstance(obj
, (PyObject
*)Mult_type
)) {
5483 if (PyObject_IsInstance(obj
, (PyObject
*)Div_type
)) {
5487 if (PyObject_IsInstance(obj
, (PyObject
*)Mod_type
)) {
5491 if (PyObject_IsInstance(obj
, (PyObject
*)Pow_type
)) {
5495 if (PyObject_IsInstance(obj
, (PyObject
*)LShift_type
)) {
5499 if (PyObject_IsInstance(obj
, (PyObject
*)RShift_type
)) {
5503 if (PyObject_IsInstance(obj
, (PyObject
*)BitOr_type
)) {
5507 if (PyObject_IsInstance(obj
, (PyObject
*)BitXor_type
)) {
5511 if (PyObject_IsInstance(obj
, (PyObject
*)BitAnd_type
)) {
5515 if (PyObject_IsInstance(obj
, (PyObject
*)FloorDiv_type
)) {
5520 tmp
= PyObject_Repr(obj
);
5521 if (tmp
== NULL
) goto failed
;
5522 PyErr_Format(PyExc_TypeError
, "expected some sort of operator, but got %.400s", PyString_AS_STRING(tmp
));
5529 obj2ast_unaryop(PyObject
* obj
, unaryop_ty
* out
, PyArena
* arena
)
5531 PyObject
* tmp
= NULL
;
5533 if (PyObject_IsInstance(obj
, (PyObject
*)Invert_type
)) {
5537 if (PyObject_IsInstance(obj
, (PyObject
*)Not_type
)) {
5541 if (PyObject_IsInstance(obj
, (PyObject
*)UAdd_type
)) {
5545 if (PyObject_IsInstance(obj
, (PyObject
*)USub_type
)) {
5550 tmp
= PyObject_Repr(obj
);
5551 if (tmp
== NULL
) goto failed
;
5552 PyErr_Format(PyExc_TypeError
, "expected some sort of unaryop, but got %.400s", PyString_AS_STRING(tmp
));
5559 obj2ast_cmpop(PyObject
* obj
, cmpop_ty
* out
, PyArena
* arena
)
5561 PyObject
* tmp
= NULL
;
5563 if (PyObject_IsInstance(obj
, (PyObject
*)Eq_type
)) {
5567 if (PyObject_IsInstance(obj
, (PyObject
*)NotEq_type
)) {
5571 if (PyObject_IsInstance(obj
, (PyObject
*)Lt_type
)) {
5575 if (PyObject_IsInstance(obj
, (PyObject
*)LtE_type
)) {
5579 if (PyObject_IsInstance(obj
, (PyObject
*)Gt_type
)) {
5583 if (PyObject_IsInstance(obj
, (PyObject
*)GtE_type
)) {
5587 if (PyObject_IsInstance(obj
, (PyObject
*)Is_type
)) {
5591 if (PyObject_IsInstance(obj
, (PyObject
*)IsNot_type
)) {
5595 if (PyObject_IsInstance(obj
, (PyObject
*)In_type
)) {
5599 if (PyObject_IsInstance(obj
, (PyObject
*)NotIn_type
)) {
5604 tmp
= PyObject_Repr(obj
);
5605 if (tmp
== NULL
) goto failed
;
5606 PyErr_Format(PyExc_TypeError
, "expected some sort of cmpop, but got %.400s", PyString_AS_STRING(tmp
));
5613 obj2ast_comprehension(PyObject
* obj
, comprehension_ty
* out
, PyArena
* arena
)
5615 PyObject
* tmp
= NULL
;
5620 if (PyObject_HasAttrString(obj
, "target")) {
5622 tmp
= PyObject_GetAttrString(obj
, "target");
5623 if (tmp
== NULL
) goto failed
;
5624 res
= obj2ast_expr(tmp
, &target
, arena
);
5625 if (res
!= 0) goto failed
;
5629 PyErr_SetString(PyExc_TypeError
, "required field \"target\" missing from comprehension");
5632 if (PyObject_HasAttrString(obj
, "iter")) {
5634 tmp
= PyObject_GetAttrString(obj
, "iter");
5635 if (tmp
== NULL
) goto failed
;
5636 res
= obj2ast_expr(tmp
, &iter
, arena
);
5637 if (res
!= 0) goto failed
;
5641 PyErr_SetString(PyExc_TypeError
, "required field \"iter\" missing from comprehension");
5644 if (PyObject_HasAttrString(obj
, "ifs")) {
5648 tmp
= PyObject_GetAttrString(obj
, "ifs");
5649 if (tmp
== NULL
) goto failed
;
5650 if (!PyList_Check(tmp
)) {
5651 PyErr_Format(PyExc_TypeError
, "comprehension field \"ifs\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5654 len
= PyList_GET_SIZE(tmp
);
5655 ifs
= asdl_seq_new(len
, arena
);
5656 if (ifs
== NULL
) goto failed
;
5657 for (i
= 0; i
< len
; i
++) {
5659 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5660 if (res
!= 0) goto failed
;
5661 asdl_seq_SET(ifs
, i
, value
);
5666 PyErr_SetString(PyExc_TypeError
, "required field \"ifs\" missing from comprehension");
5669 *out
= comprehension(target
, iter
, ifs
, arena
);
5677 obj2ast_excepthandler(PyObject
* obj
, excepthandler_ty
* out
, PyArena
* arena
)
5679 PyObject
* tmp
= NULL
;
5684 if (obj
== Py_None
) {
5688 if (PyObject_HasAttrString(obj
, "lineno")) {
5690 tmp
= PyObject_GetAttrString(obj
, "lineno");
5691 if (tmp
== NULL
) goto failed
;
5692 res
= obj2ast_int(tmp
, &lineno
, arena
);
5693 if (res
!= 0) goto failed
;
5697 PyErr_SetString(PyExc_TypeError
, "required field \"lineno\" missing from excepthandler");
5700 if (PyObject_HasAttrString(obj
, "col_offset")) {
5702 tmp
= PyObject_GetAttrString(obj
, "col_offset");
5703 if (tmp
== NULL
) goto failed
;
5704 res
= obj2ast_int(tmp
, &col_offset
, arena
);
5705 if (res
!= 0) goto failed
;
5709 PyErr_SetString(PyExc_TypeError
, "required field \"col_offset\" missing from excepthandler");
5712 if (PyObject_IsInstance(obj
, (PyObject
*)ExceptHandler_type
)) {
5717 if (PyObject_HasAttrString(obj
, "type")) {
5719 tmp
= PyObject_GetAttrString(obj
, "type");
5720 if (tmp
== NULL
) goto failed
;
5721 res
= obj2ast_expr(tmp
, &type
, arena
);
5722 if (res
!= 0) goto failed
;
5728 if (PyObject_HasAttrString(obj
, "name")) {
5730 tmp
= PyObject_GetAttrString(obj
, "name");
5731 if (tmp
== NULL
) goto failed
;
5732 res
= obj2ast_expr(tmp
, &name
, arena
);
5733 if (res
!= 0) goto failed
;
5739 if (PyObject_HasAttrString(obj
, "body")) {
5743 tmp
= PyObject_GetAttrString(obj
, "body");
5744 if (tmp
== NULL
) goto failed
;
5745 if (!PyList_Check(tmp
)) {
5746 PyErr_Format(PyExc_TypeError
, "ExceptHandler field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5749 len
= PyList_GET_SIZE(tmp
);
5750 body
= asdl_seq_new(len
, arena
);
5751 if (body
== NULL
) goto failed
;
5752 for (i
= 0; i
< len
; i
++) {
5754 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5755 if (res
!= 0) goto failed
;
5756 asdl_seq_SET(body
, i
, value
);
5761 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from ExceptHandler");
5764 *out
= ExceptHandler(type
, name
, body
, lineno
, col_offset
,
5766 if (*out
== NULL
) goto failed
;
5770 tmp
= PyObject_Repr(obj
);
5771 if (tmp
== NULL
) goto failed
;
5772 PyErr_Format(PyExc_TypeError
, "expected some sort of excepthandler, but got %.400s", PyString_AS_STRING(tmp
));
5779 obj2ast_arguments(PyObject
* obj
, arguments_ty
* out
, PyArena
* arena
)
5781 PyObject
* tmp
= NULL
;
5787 if (PyObject_HasAttrString(obj
, "args")) {
5791 tmp
= PyObject_GetAttrString(obj
, "args");
5792 if (tmp
== NULL
) goto failed
;
5793 if (!PyList_Check(tmp
)) {
5794 PyErr_Format(PyExc_TypeError
, "arguments field \"args\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5797 len
= PyList_GET_SIZE(tmp
);
5798 args
= asdl_seq_new(len
, arena
);
5799 if (args
== NULL
) goto failed
;
5800 for (i
= 0; i
< len
; i
++) {
5802 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5803 if (res
!= 0) goto failed
;
5804 asdl_seq_SET(args
, i
, value
);
5809 PyErr_SetString(PyExc_TypeError
, "required field \"args\" missing from arguments");
5812 if (PyObject_HasAttrString(obj
, "vararg")) {
5814 tmp
= PyObject_GetAttrString(obj
, "vararg");
5815 if (tmp
== NULL
) goto failed
;
5816 res
= obj2ast_identifier(tmp
, &vararg
, arena
);
5817 if (res
!= 0) goto failed
;
5823 if (PyObject_HasAttrString(obj
, "kwarg")) {
5825 tmp
= PyObject_GetAttrString(obj
, "kwarg");
5826 if (tmp
== NULL
) goto failed
;
5827 res
= obj2ast_identifier(tmp
, &kwarg
, arena
);
5828 if (res
!= 0) goto failed
;
5834 if (PyObject_HasAttrString(obj
, "defaults")) {
5838 tmp
= PyObject_GetAttrString(obj
, "defaults");
5839 if (tmp
== NULL
) goto failed
;
5840 if (!PyList_Check(tmp
)) {
5841 PyErr_Format(PyExc_TypeError
, "arguments field \"defaults\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5844 len
= PyList_GET_SIZE(tmp
);
5845 defaults
= asdl_seq_new(len
, arena
);
5846 if (defaults
== NULL
) goto failed
;
5847 for (i
= 0; i
< len
; i
++) {
5849 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5850 if (res
!= 0) goto failed
;
5851 asdl_seq_SET(defaults
, i
, value
);
5856 PyErr_SetString(PyExc_TypeError
, "required field \"defaults\" missing from arguments");
5859 *out
= arguments(args
, vararg
, kwarg
, defaults
, arena
);
5867 obj2ast_keyword(PyObject
* obj
, keyword_ty
* out
, PyArena
* arena
)
5869 PyObject
* tmp
= NULL
;
5873 if (PyObject_HasAttrString(obj
, "arg")) {
5875 tmp
= PyObject_GetAttrString(obj
, "arg");
5876 if (tmp
== NULL
) goto failed
;
5877 res
= obj2ast_identifier(tmp
, &arg
, arena
);
5878 if (res
!= 0) goto failed
;
5882 PyErr_SetString(PyExc_TypeError
, "required field \"arg\" missing from keyword");
5885 if (PyObject_HasAttrString(obj
, "value")) {
5887 tmp
= PyObject_GetAttrString(obj
, "value");
5888 if (tmp
== NULL
) goto failed
;
5889 res
= obj2ast_expr(tmp
, &value
, arena
);
5890 if (res
!= 0) goto failed
;
5894 PyErr_SetString(PyExc_TypeError
, "required field \"value\" missing from keyword");
5897 *out
= keyword(arg
, value
, arena
);
5905 obj2ast_alias(PyObject
* obj
, alias_ty
* out
, PyArena
* arena
)
5907 PyObject
* tmp
= NULL
;
5911 if (PyObject_HasAttrString(obj
, "name")) {
5913 tmp
= PyObject_GetAttrString(obj
, "name");
5914 if (tmp
== NULL
) goto failed
;
5915 res
= obj2ast_identifier(tmp
, &name
, arena
);
5916 if (res
!= 0) goto failed
;
5920 PyErr_SetString(PyExc_TypeError
, "required field \"name\" missing from alias");
5923 if (PyObject_HasAttrString(obj
, "asname")) {
5925 tmp
= PyObject_GetAttrString(obj
, "asname");
5926 if (tmp
== NULL
) goto failed
;
5927 res
= obj2ast_identifier(tmp
, &asname
, arena
);
5928 if (res
!= 0) goto failed
;
5934 *out
= alias(name
, asname
, arena
);
5946 if (!init_types()) return;
5947 m
= Py_InitModule3("_ast", NULL
, NULL
);
5949 d
= PyModule_GetDict(m
);
5950 if (PyDict_SetItemString(d
, "AST", (PyObject
*)&AST_type
) < 0) return;
5951 if (PyModule_AddIntConstant(m
, "PyCF_ONLY_AST", PyCF_ONLY_AST
) < 0)
5953 if (PyModule_AddStringConstant(m
, "__version__", "62047") < 0)
5955 if (PyDict_SetItemString(d
, "mod", (PyObject
*)mod_type
) < 0) return;
5956 if (PyDict_SetItemString(d
, "Module", (PyObject
*)Module_type
) < 0)
5958 if (PyDict_SetItemString(d
, "Interactive", (PyObject
*)Interactive_type
)
5960 if (PyDict_SetItemString(d
, "Expression", (PyObject
*)Expression_type
) <
5962 if (PyDict_SetItemString(d
, "Suite", (PyObject
*)Suite_type
) < 0) return;
5963 if (PyDict_SetItemString(d
, "stmt", (PyObject
*)stmt_type
) < 0) return;
5964 if (PyDict_SetItemString(d
, "FunctionDef", (PyObject
*)FunctionDef_type
)
5966 if (PyDict_SetItemString(d
, "ClassDef", (PyObject
*)ClassDef_type
) < 0)
5968 if (PyDict_SetItemString(d
, "Return", (PyObject
*)Return_type
) < 0)
5970 if (PyDict_SetItemString(d
, "Delete", (PyObject
*)Delete_type
) < 0)
5972 if (PyDict_SetItemString(d
, "Assign", (PyObject
*)Assign_type
) < 0)
5974 if (PyDict_SetItemString(d
, "AugAssign", (PyObject
*)AugAssign_type
) <
5976 if (PyDict_SetItemString(d
, "Print", (PyObject
*)Print_type
) < 0) return;
5977 if (PyDict_SetItemString(d
, "For", (PyObject
*)For_type
) < 0) return;
5978 if (PyDict_SetItemString(d
, "While", (PyObject
*)While_type
) < 0) return;
5979 if (PyDict_SetItemString(d
, "If", (PyObject
*)If_type
) < 0) return;
5980 if (PyDict_SetItemString(d
, "With", (PyObject
*)With_type
) < 0) return;
5981 if (PyDict_SetItemString(d
, "Raise", (PyObject
*)Raise_type
) < 0) return;
5982 if (PyDict_SetItemString(d
, "TryExcept", (PyObject
*)TryExcept_type
) <
5984 if (PyDict_SetItemString(d
, "TryFinally", (PyObject
*)TryFinally_type
) <
5986 if (PyDict_SetItemString(d
, "Assert", (PyObject
*)Assert_type
) < 0)
5988 if (PyDict_SetItemString(d
, "Import", (PyObject
*)Import_type
) < 0)
5990 if (PyDict_SetItemString(d
, "ImportFrom", (PyObject
*)ImportFrom_type
) <
5992 if (PyDict_SetItemString(d
, "Exec", (PyObject
*)Exec_type
) < 0) return;
5993 if (PyDict_SetItemString(d
, "Global", (PyObject
*)Global_type
) < 0)
5995 if (PyDict_SetItemString(d
, "Expr", (PyObject
*)Expr_type
) < 0) return;
5996 if (PyDict_SetItemString(d
, "Pass", (PyObject
*)Pass_type
) < 0) return;
5997 if (PyDict_SetItemString(d
, "Break", (PyObject
*)Break_type
) < 0) return;
5998 if (PyDict_SetItemString(d
, "Continue", (PyObject
*)Continue_type
) < 0)
6000 if (PyDict_SetItemString(d
, "expr", (PyObject
*)expr_type
) < 0) return;
6001 if (PyDict_SetItemString(d
, "BoolOp", (PyObject
*)BoolOp_type
) < 0)
6003 if (PyDict_SetItemString(d
, "BinOp", (PyObject
*)BinOp_type
) < 0) return;
6004 if (PyDict_SetItemString(d
, "UnaryOp", (PyObject
*)UnaryOp_type
) < 0)
6006 if (PyDict_SetItemString(d
, "Lambda", (PyObject
*)Lambda_type
) < 0)
6008 if (PyDict_SetItemString(d
, "IfExp", (PyObject
*)IfExp_type
) < 0) return;
6009 if (PyDict_SetItemString(d
, "Dict", (PyObject
*)Dict_type
) < 0) return;
6010 if (PyDict_SetItemString(d
, "ListComp", (PyObject
*)ListComp_type
) < 0)
6012 if (PyDict_SetItemString(d
, "GeneratorExp",
6013 (PyObject
*)GeneratorExp_type
) < 0) return;
6014 if (PyDict_SetItemString(d
, "Yield", (PyObject
*)Yield_type
) < 0) return;
6015 if (PyDict_SetItemString(d
, "Compare", (PyObject
*)Compare_type
) < 0)
6017 if (PyDict_SetItemString(d
, "Call", (PyObject
*)Call_type
) < 0) return;
6018 if (PyDict_SetItemString(d
, "Repr", (PyObject
*)Repr_type
) < 0) return;
6019 if (PyDict_SetItemString(d
, "Num", (PyObject
*)Num_type
) < 0) return;
6020 if (PyDict_SetItemString(d
, "Str", (PyObject
*)Str_type
) < 0) return;
6021 if (PyDict_SetItemString(d
, "Attribute", (PyObject
*)Attribute_type
) <
6023 if (PyDict_SetItemString(d
, "Subscript", (PyObject
*)Subscript_type
) <
6025 if (PyDict_SetItemString(d
, "Name", (PyObject
*)Name_type
) < 0) return;
6026 if (PyDict_SetItemString(d
, "List", (PyObject
*)List_type
) < 0) return;
6027 if (PyDict_SetItemString(d
, "Tuple", (PyObject
*)Tuple_type
) < 0) return;
6028 if (PyDict_SetItemString(d
, "expr_context",
6029 (PyObject
*)expr_context_type
) < 0) return;
6030 if (PyDict_SetItemString(d
, "Load", (PyObject
*)Load_type
) < 0) return;
6031 if (PyDict_SetItemString(d
, "Store", (PyObject
*)Store_type
) < 0) return;
6032 if (PyDict_SetItemString(d
, "Del", (PyObject
*)Del_type
) < 0) return;
6033 if (PyDict_SetItemString(d
, "AugLoad", (PyObject
*)AugLoad_type
) < 0)
6035 if (PyDict_SetItemString(d
, "AugStore", (PyObject
*)AugStore_type
) < 0)
6037 if (PyDict_SetItemString(d
, "Param", (PyObject
*)Param_type
) < 0) return;
6038 if (PyDict_SetItemString(d
, "slice", (PyObject
*)slice_type
) < 0) return;
6039 if (PyDict_SetItemString(d
, "Ellipsis", (PyObject
*)Ellipsis_type
) < 0)
6041 if (PyDict_SetItemString(d
, "Slice", (PyObject
*)Slice_type
) < 0) return;
6042 if (PyDict_SetItemString(d
, "ExtSlice", (PyObject
*)ExtSlice_type
) < 0)
6044 if (PyDict_SetItemString(d
, "Index", (PyObject
*)Index_type
) < 0) return;
6045 if (PyDict_SetItemString(d
, "boolop", (PyObject
*)boolop_type
) < 0)
6047 if (PyDict_SetItemString(d
, "And", (PyObject
*)And_type
) < 0) return;
6048 if (PyDict_SetItemString(d
, "Or", (PyObject
*)Or_type
) < 0) return;
6049 if (PyDict_SetItemString(d
, "operator", (PyObject
*)operator_type
) < 0)
6051 if (PyDict_SetItemString(d
, "Add", (PyObject
*)Add_type
) < 0) return;
6052 if (PyDict_SetItemString(d
, "Sub", (PyObject
*)Sub_type
) < 0) return;
6053 if (PyDict_SetItemString(d
, "Mult", (PyObject
*)Mult_type
) < 0) return;
6054 if (PyDict_SetItemString(d
, "Div", (PyObject
*)Div_type
) < 0) return;
6055 if (PyDict_SetItemString(d
, "Mod", (PyObject
*)Mod_type
) < 0) return;
6056 if (PyDict_SetItemString(d
, "Pow", (PyObject
*)Pow_type
) < 0) return;
6057 if (PyDict_SetItemString(d
, "LShift", (PyObject
*)LShift_type
) < 0)
6059 if (PyDict_SetItemString(d
, "RShift", (PyObject
*)RShift_type
) < 0)
6061 if (PyDict_SetItemString(d
, "BitOr", (PyObject
*)BitOr_type
) < 0) return;
6062 if (PyDict_SetItemString(d
, "BitXor", (PyObject
*)BitXor_type
) < 0)
6064 if (PyDict_SetItemString(d
, "BitAnd", (PyObject
*)BitAnd_type
) < 0)
6066 if (PyDict_SetItemString(d
, "FloorDiv", (PyObject
*)FloorDiv_type
) < 0)
6068 if (PyDict_SetItemString(d
, "unaryop", (PyObject
*)unaryop_type
) < 0)
6070 if (PyDict_SetItemString(d
, "Invert", (PyObject
*)Invert_type
) < 0)
6072 if (PyDict_SetItemString(d
, "Not", (PyObject
*)Not_type
) < 0) return;
6073 if (PyDict_SetItemString(d
, "UAdd", (PyObject
*)UAdd_type
) < 0) return;
6074 if (PyDict_SetItemString(d
, "USub", (PyObject
*)USub_type
) < 0) return;
6075 if (PyDict_SetItemString(d
, "cmpop", (PyObject
*)cmpop_type
) < 0) return;
6076 if (PyDict_SetItemString(d
, "Eq", (PyObject
*)Eq_type
) < 0) return;
6077 if (PyDict_SetItemString(d
, "NotEq", (PyObject
*)NotEq_type
) < 0) return;
6078 if (PyDict_SetItemString(d
, "Lt", (PyObject
*)Lt_type
) < 0) return;
6079 if (PyDict_SetItemString(d
, "LtE", (PyObject
*)LtE_type
) < 0) return;
6080 if (PyDict_SetItemString(d
, "Gt", (PyObject
*)Gt_type
) < 0) return;
6081 if (PyDict_SetItemString(d
, "GtE", (PyObject
*)GtE_type
) < 0) return;
6082 if (PyDict_SetItemString(d
, "Is", (PyObject
*)Is_type
) < 0) return;
6083 if (PyDict_SetItemString(d
, "IsNot", (PyObject
*)IsNot_type
) < 0) return;
6084 if (PyDict_SetItemString(d
, "In", (PyObject
*)In_type
) < 0) return;
6085 if (PyDict_SetItemString(d
, "NotIn", (PyObject
*)NotIn_type
) < 0) return;
6086 if (PyDict_SetItemString(d
, "comprehension",
6087 (PyObject
*)comprehension_type
) < 0) return;
6088 if (PyDict_SetItemString(d
, "excepthandler",
6089 (PyObject
*)excepthandler_type
) < 0) return;
6090 if (PyDict_SetItemString(d
, "ExceptHandler",
6091 (PyObject
*)ExceptHandler_type
) < 0) return;
6092 if (PyDict_SetItemString(d
, "arguments", (PyObject
*)arguments_type
) <
6094 if (PyDict_SetItemString(d
, "keyword", (PyObject
*)keyword_type
) < 0)
6096 if (PyDict_SetItemString(d
, "alias", (PyObject
*)alias_type
) < 0) return;
6100 PyObject
* PyAST_mod2obj(mod_ty t
)
6103 return ast2obj_mod(t
);
6106 /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */
6107 mod_ty
PyAST_obj2mod(PyObject
* ast
, PyArena
* arena
, int mode
)
6110 PyObject
*req_type
[] = {(PyObject
*)Module_type
, (PyObject
*)Expression_type
,
6111 (PyObject
*)Interactive_type
};
6112 char *req_name
[] = {"Module", "Expression", "Interactive"};
6113 assert(0 <= mode
&& mode
<= 2);
6117 if (!PyObject_IsInstance(ast
, req_type
[mode
])) {
6118 PyErr_Format(PyExc_TypeError
, "expected %s node, got %.400s",
6119 req_name
[mode
], Py_TYPE(ast
)->tp_name
);
6122 if (obj2ast_mod(ast
, &res
, arena
) != 0)
6128 int PyAST_Check(PyObject
* obj
)
6131 return PyObject_IsInstance(obj
, (PyObject
*)&AST_type
);