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
*Set_type
;
192 static char *Set_fields
[]={
195 static PyTypeObject
*ListComp_type
;
196 static char *ListComp_fields
[]={
200 static PyTypeObject
*SetComp_type
;
201 static char *SetComp_fields
[]={
205 static PyTypeObject
*DictComp_type
;
206 static char *DictComp_fields
[]={
211 static PyTypeObject
*GeneratorExp_type
;
212 static char *GeneratorExp_fields
[]={
216 static PyTypeObject
*Yield_type
;
217 static char *Yield_fields
[]={
220 static PyTypeObject
*Compare_type
;
221 static char *Compare_fields
[]={
226 static PyTypeObject
*Call_type
;
227 static char *Call_fields
[]={
234 static PyTypeObject
*Repr_type
;
235 static char *Repr_fields
[]={
238 static PyTypeObject
*Num_type
;
239 static char *Num_fields
[]={
242 static PyTypeObject
*Str_type
;
243 static char *Str_fields
[]={
246 static PyTypeObject
*Attribute_type
;
247 static char *Attribute_fields
[]={
252 static PyTypeObject
*Subscript_type
;
253 static char *Subscript_fields
[]={
258 static PyTypeObject
*Name_type
;
259 static char *Name_fields
[]={
263 static PyTypeObject
*List_type
;
264 static char *List_fields
[]={
268 static PyTypeObject
*Tuple_type
;
269 static char *Tuple_fields
[]={
273 static PyTypeObject
*expr_context_type
;
274 static PyObject
*Load_singleton
, *Store_singleton
, *Del_singleton
,
275 *AugLoad_singleton
, *AugStore_singleton
, *Param_singleton
;
276 static PyObject
* ast2obj_expr_context(expr_context_ty
);
277 static PyTypeObject
*Load_type
;
278 static PyTypeObject
*Store_type
;
279 static PyTypeObject
*Del_type
;
280 static PyTypeObject
*AugLoad_type
;
281 static PyTypeObject
*AugStore_type
;
282 static PyTypeObject
*Param_type
;
283 static PyTypeObject
*slice_type
;
284 static PyObject
* ast2obj_slice(void*);
285 static PyTypeObject
*Ellipsis_type
;
286 static PyTypeObject
*Slice_type
;
287 static char *Slice_fields
[]={
292 static PyTypeObject
*ExtSlice_type
;
293 static char *ExtSlice_fields
[]={
296 static PyTypeObject
*Index_type
;
297 static char *Index_fields
[]={
300 static PyTypeObject
*boolop_type
;
301 static PyObject
*And_singleton
, *Or_singleton
;
302 static PyObject
* ast2obj_boolop(boolop_ty
);
303 static PyTypeObject
*And_type
;
304 static PyTypeObject
*Or_type
;
305 static PyTypeObject
*operator_type
;
306 static PyObject
*Add_singleton
, *Sub_singleton
, *Mult_singleton
,
307 *Div_singleton
, *Mod_singleton
, *Pow_singleton
, *LShift_singleton
,
308 *RShift_singleton
, *BitOr_singleton
, *BitXor_singleton
, *BitAnd_singleton
,
310 static PyObject
* ast2obj_operator(operator_ty
);
311 static PyTypeObject
*Add_type
;
312 static PyTypeObject
*Sub_type
;
313 static PyTypeObject
*Mult_type
;
314 static PyTypeObject
*Div_type
;
315 static PyTypeObject
*Mod_type
;
316 static PyTypeObject
*Pow_type
;
317 static PyTypeObject
*LShift_type
;
318 static PyTypeObject
*RShift_type
;
319 static PyTypeObject
*BitOr_type
;
320 static PyTypeObject
*BitXor_type
;
321 static PyTypeObject
*BitAnd_type
;
322 static PyTypeObject
*FloorDiv_type
;
323 static PyTypeObject
*unaryop_type
;
324 static PyObject
*Invert_singleton
, *Not_singleton
, *UAdd_singleton
,
326 static PyObject
* ast2obj_unaryop(unaryop_ty
);
327 static PyTypeObject
*Invert_type
;
328 static PyTypeObject
*Not_type
;
329 static PyTypeObject
*UAdd_type
;
330 static PyTypeObject
*USub_type
;
331 static PyTypeObject
*cmpop_type
;
332 static PyObject
*Eq_singleton
, *NotEq_singleton
, *Lt_singleton
, *LtE_singleton
,
333 *Gt_singleton
, *GtE_singleton
, *Is_singleton
, *IsNot_singleton
, *In_singleton
,
335 static PyObject
* ast2obj_cmpop(cmpop_ty
);
336 static PyTypeObject
*Eq_type
;
337 static PyTypeObject
*NotEq_type
;
338 static PyTypeObject
*Lt_type
;
339 static PyTypeObject
*LtE_type
;
340 static PyTypeObject
*Gt_type
;
341 static PyTypeObject
*GtE_type
;
342 static PyTypeObject
*Is_type
;
343 static PyTypeObject
*IsNot_type
;
344 static PyTypeObject
*In_type
;
345 static PyTypeObject
*NotIn_type
;
346 static PyTypeObject
*comprehension_type
;
347 static PyObject
* ast2obj_comprehension(void*);
348 static char *comprehension_fields
[]={
353 static PyTypeObject
*excepthandler_type
;
354 static char *excepthandler_attributes
[] = {
358 static PyObject
* ast2obj_excepthandler(void*);
359 static PyTypeObject
*ExceptHandler_type
;
360 static char *ExceptHandler_fields
[]={
365 static PyTypeObject
*arguments_type
;
366 static PyObject
* ast2obj_arguments(void*);
367 static char *arguments_fields
[]={
373 static PyTypeObject
*keyword_type
;
374 static PyObject
* ast2obj_keyword(void*);
375 static char *keyword_fields
[]={
379 static PyTypeObject
*alias_type
;
380 static PyObject
* ast2obj_alias(void*);
381 static char *alias_fields
[]={
388 ast_type_init(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
390 Py_ssize_t i
, numfields
= 0;
392 PyObject
*key
, *value
, *fields
;
393 fields
= PyObject_GetAttrString((PyObject
*)Py_TYPE(self
), "_fields");
397 numfields
= PySequence_Size(fields
);
401 res
= 0; /* if no error occurs, this stays 0 to the end */
402 if (PyTuple_GET_SIZE(args
) > 0) {
403 if (numfields
!= PyTuple_GET_SIZE(args
)) {
404 PyErr_Format(PyExc_TypeError
, "%.400s constructor takes %s"
405 "%zd positional argument%s",
406 Py_TYPE(self
)->tp_name
,
407 numfields
== 0 ? "" : "either 0 or ",
408 numfields
, numfields
== 1 ? "" : "s");
412 for (i
= 0; i
< PyTuple_GET_SIZE(args
); i
++) {
413 /* cannot be reached when fields is NULL */
414 PyObject
*name
= PySequence_GetItem(fields
, i
);
419 res
= PyObject_SetAttr(self
, name
, PyTuple_GET_ITEM(args
, i
));
426 i
= 0; /* needed by PyDict_Next */
427 while (PyDict_Next(kw
, &i
, &key
, &value
)) {
428 res
= PyObject_SetAttr(self
, key
, value
);
438 /* Pickling support */
440 ast_type_reduce(PyObject
*self
, PyObject
*unused
)
443 PyObject
*dict
= PyObject_GetAttrString(self
, "__dict__");
445 if (PyErr_ExceptionMatches(PyExc_AttributeError
))
451 res
= Py_BuildValue("O()O", Py_TYPE(self
), dict
);
455 return Py_BuildValue("O()", Py_TYPE(self
));
458 static PyMethodDef ast_type_methods
[] = {
459 {"__reduce__", ast_type_reduce
, METH_NOARGS
, NULL
},
463 static PyTypeObject AST_type
= {
464 PyVarObject_HEAD_INIT(&PyType_Type
, 0)
474 0, /* tp_as_number */
475 0, /* tp_as_sequence */
476 0, /* tp_as_mapping */
480 PyObject_GenericGetAttr
, /* tp_getattro */
481 PyObject_GenericSetAttr
, /* tp_setattro */
482 0, /* tp_as_buffer */
483 Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_BASETYPE
, /* tp_flags */
487 0, /* tp_richcompare */
488 0, /* tp_weaklistoffset */
491 ast_type_methods
, /* tp_methods */
496 0, /* tp_descr_get */
497 0, /* tp_descr_set */
498 0, /* tp_dictoffset */
499 (initproc
)ast_type_init
, /* tp_init */
500 PyType_GenericAlloc
, /* tp_alloc */
501 PyType_GenericNew
, /* tp_new */
502 PyObject_Del
, /* tp_free */
506 static PyTypeObject
* make_type(char *type
, PyTypeObject
* base
, char**fields
, int num_fields
)
508 PyObject
*fnames
, *result
;
510 fnames
= PyTuple_New(num_fields
);
511 if (!fnames
) return NULL
;
512 for (i
= 0; i
< num_fields
; i
++) {
513 PyObject
*field
= PyString_FromString(fields
[i
]);
518 PyTuple_SET_ITEM(fnames
, i
, field
);
520 result
= PyObject_CallFunction((PyObject
*)&PyType_Type
, "s(O){sOss}",
521 type
, base
, "_fields", fnames
, "__module__", "_ast");
523 return (PyTypeObject
*)result
;
526 static int add_attributes(PyTypeObject
* type
, char**attrs
, int num_fields
)
529 PyObject
*s
, *l
= PyTuple_New(num_fields
);
532 for (i
= 0; i
< num_fields
; i
++) {
533 s
= PyString_FromString(attrs
[i
]);
538 PyTuple_SET_ITEM(l
, i
, s
);
540 result
= PyObject_SetAttrString((PyObject
*)type
, "_attributes", l
) >= 0;
545 /* Conversion AST -> Python */
547 static PyObject
* ast2obj_list(asdl_seq
*seq
, PyObject
* (*func
)(void*))
549 int i
, n
= asdl_seq_LEN(seq
);
550 PyObject
*result
= PyList_New(n
);
554 for (i
= 0; i
< n
; i
++) {
555 value
= func(asdl_seq_GET(seq
, i
));
560 PyList_SET_ITEM(result
, i
, value
);
565 static PyObject
* ast2obj_object(void *o
)
569 Py_INCREF((PyObject
*)o
);
572 #define ast2obj_identifier ast2obj_object
573 #define ast2obj_string ast2obj_object
574 static PyObject
* ast2obj_bool(bool b
)
576 return PyBool_FromLong(b
);
579 static PyObject
* ast2obj_int(long b
)
581 return PyInt_FromLong(b
);
584 /* Conversion Python -> AST */
586 static int obj2ast_object(PyObject
* obj
, PyObject
** out
, PyArena
* arena
)
591 PyArena_AddPyObject(arena
, obj
);
597 static int obj2ast_identifier(PyObject
* obj
, PyObject
** out
, PyArena
* arena
)
599 if (!PyString_CheckExact(obj
) && obj
!= Py_None
) {
600 PyErr_Format(PyExc_TypeError
,
601 "AST identifier must be of type str");
604 return obj2ast_object(obj
, out
, arena
);
607 static int obj2ast_string(PyObject
* obj
, PyObject
** out
, PyArena
* arena
)
609 if (!PyString_CheckExact(obj
) && !PyUnicode_CheckExact(obj
)) {
610 PyErr_SetString(PyExc_TypeError
,
611 "AST string must be of type str or unicode");
614 return obj2ast_object(obj
, out
, arena
);
617 static int obj2ast_int(PyObject
* obj
, int* out
, PyArena
* arena
)
620 if (!PyInt_Check(obj
) && !PyLong_Check(obj
)) {
621 PyObject
*s
= PyObject_Repr(obj
);
622 if (s
== NULL
) return 1;
623 PyErr_Format(PyExc_ValueError
, "invalid integer value: %.400s",
624 PyString_AS_STRING(s
));
629 i
= (int)PyLong_AsLong(obj
);
630 if (i
== -1 && PyErr_Occurred())
636 static int obj2ast_bool(PyObject
* obj
, bool* out
, PyArena
* arena
)
638 if (!PyBool_Check(obj
)) {
639 PyObject
*s
= PyObject_Repr(obj
);
640 if (s
== NULL
) return 1;
641 PyErr_Format(PyExc_ValueError
, "invalid boolean value: %.400s",
642 PyString_AS_STRING(s
));
647 *out
= (obj
== Py_True
);
651 static int add_ast_fields(void)
653 PyObject
*empty_tuple
, *d
;
654 if (PyType_Ready(&AST_type
) < 0)
656 d
= AST_type
.tp_dict
;
657 empty_tuple
= PyTuple_New(0);
659 PyDict_SetItemString(d
, "_fields", empty_tuple
) < 0 ||
660 PyDict_SetItemString(d
, "_attributes", empty_tuple
) < 0) {
661 Py_XDECREF(empty_tuple
);
664 Py_DECREF(empty_tuple
);
669 static int init_types(void)
671 static int initialized
;
672 if (initialized
) return 1;
673 if (add_ast_fields() < 0) return 0;
674 mod_type
= make_type("mod", &AST_type
, NULL
, 0);
675 if (!mod_type
) return 0;
676 if (!add_attributes(mod_type
, NULL
, 0)) return 0;
677 Module_type
= make_type("Module", mod_type
, Module_fields
, 1);
678 if (!Module_type
) return 0;
679 Interactive_type
= make_type("Interactive", mod_type
,
680 Interactive_fields
, 1);
681 if (!Interactive_type
) return 0;
682 Expression_type
= make_type("Expression", mod_type
, Expression_fields
,
684 if (!Expression_type
) return 0;
685 Suite_type
= make_type("Suite", mod_type
, Suite_fields
, 1);
686 if (!Suite_type
) return 0;
687 stmt_type
= make_type("stmt", &AST_type
, NULL
, 0);
688 if (!stmt_type
) return 0;
689 if (!add_attributes(stmt_type
, stmt_attributes
, 2)) return 0;
690 FunctionDef_type
= make_type("FunctionDef", stmt_type
,
691 FunctionDef_fields
, 4);
692 if (!FunctionDef_type
) return 0;
693 ClassDef_type
= make_type("ClassDef", stmt_type
, ClassDef_fields
, 4);
694 if (!ClassDef_type
) return 0;
695 Return_type
= make_type("Return", stmt_type
, Return_fields
, 1);
696 if (!Return_type
) return 0;
697 Delete_type
= make_type("Delete", stmt_type
, Delete_fields
, 1);
698 if (!Delete_type
) return 0;
699 Assign_type
= make_type("Assign", stmt_type
, Assign_fields
, 2);
700 if (!Assign_type
) return 0;
701 AugAssign_type
= make_type("AugAssign", stmt_type
, AugAssign_fields
, 3);
702 if (!AugAssign_type
) return 0;
703 Print_type
= make_type("Print", stmt_type
, Print_fields
, 3);
704 if (!Print_type
) return 0;
705 For_type
= make_type("For", stmt_type
, For_fields
, 4);
706 if (!For_type
) return 0;
707 While_type
= make_type("While", stmt_type
, While_fields
, 3);
708 if (!While_type
) return 0;
709 If_type
= make_type("If", stmt_type
, If_fields
, 3);
710 if (!If_type
) return 0;
711 With_type
= make_type("With", stmt_type
, With_fields
, 3);
712 if (!With_type
) return 0;
713 Raise_type
= make_type("Raise", stmt_type
, Raise_fields
, 3);
714 if (!Raise_type
) return 0;
715 TryExcept_type
= make_type("TryExcept", stmt_type
, TryExcept_fields
, 3);
716 if (!TryExcept_type
) return 0;
717 TryFinally_type
= make_type("TryFinally", stmt_type
, TryFinally_fields
,
719 if (!TryFinally_type
) return 0;
720 Assert_type
= make_type("Assert", stmt_type
, Assert_fields
, 2);
721 if (!Assert_type
) return 0;
722 Import_type
= make_type("Import", stmt_type
, Import_fields
, 1);
723 if (!Import_type
) return 0;
724 ImportFrom_type
= make_type("ImportFrom", stmt_type
, ImportFrom_fields
,
726 if (!ImportFrom_type
) return 0;
727 Exec_type
= make_type("Exec", stmt_type
, Exec_fields
, 3);
728 if (!Exec_type
) return 0;
729 Global_type
= make_type("Global", stmt_type
, Global_fields
, 1);
730 if (!Global_type
) return 0;
731 Expr_type
= make_type("Expr", stmt_type
, Expr_fields
, 1);
732 if (!Expr_type
) return 0;
733 Pass_type
= make_type("Pass", stmt_type
, NULL
, 0);
734 if (!Pass_type
) return 0;
735 Break_type
= make_type("Break", stmt_type
, NULL
, 0);
736 if (!Break_type
) return 0;
737 Continue_type
= make_type("Continue", stmt_type
, NULL
, 0);
738 if (!Continue_type
) return 0;
739 expr_type
= make_type("expr", &AST_type
, NULL
, 0);
740 if (!expr_type
) return 0;
741 if (!add_attributes(expr_type
, expr_attributes
, 2)) return 0;
742 BoolOp_type
= make_type("BoolOp", expr_type
, BoolOp_fields
, 2);
743 if (!BoolOp_type
) return 0;
744 BinOp_type
= make_type("BinOp", expr_type
, BinOp_fields
, 3);
745 if (!BinOp_type
) return 0;
746 UnaryOp_type
= make_type("UnaryOp", expr_type
, UnaryOp_fields
, 2);
747 if (!UnaryOp_type
) return 0;
748 Lambda_type
= make_type("Lambda", expr_type
, Lambda_fields
, 2);
749 if (!Lambda_type
) return 0;
750 IfExp_type
= make_type("IfExp", expr_type
, IfExp_fields
, 3);
751 if (!IfExp_type
) return 0;
752 Dict_type
= make_type("Dict", expr_type
, Dict_fields
, 2);
753 if (!Dict_type
) return 0;
754 Set_type
= make_type("Set", expr_type
, Set_fields
, 1);
755 if (!Set_type
) return 0;
756 ListComp_type
= make_type("ListComp", expr_type
, ListComp_fields
, 2);
757 if (!ListComp_type
) return 0;
758 SetComp_type
= make_type("SetComp", expr_type
, SetComp_fields
, 2);
759 if (!SetComp_type
) return 0;
760 DictComp_type
= make_type("DictComp", expr_type
, DictComp_fields
, 3);
761 if (!DictComp_type
) return 0;
762 GeneratorExp_type
= make_type("GeneratorExp", expr_type
,
763 GeneratorExp_fields
, 2);
764 if (!GeneratorExp_type
) return 0;
765 Yield_type
= make_type("Yield", expr_type
, Yield_fields
, 1);
766 if (!Yield_type
) return 0;
767 Compare_type
= make_type("Compare", expr_type
, Compare_fields
, 3);
768 if (!Compare_type
) return 0;
769 Call_type
= make_type("Call", expr_type
, Call_fields
, 5);
770 if (!Call_type
) return 0;
771 Repr_type
= make_type("Repr", expr_type
, Repr_fields
, 1);
772 if (!Repr_type
) return 0;
773 Num_type
= make_type("Num", expr_type
, Num_fields
, 1);
774 if (!Num_type
) return 0;
775 Str_type
= make_type("Str", expr_type
, Str_fields
, 1);
776 if (!Str_type
) return 0;
777 Attribute_type
= make_type("Attribute", expr_type
, Attribute_fields
, 3);
778 if (!Attribute_type
) return 0;
779 Subscript_type
= make_type("Subscript", expr_type
, Subscript_fields
, 3);
780 if (!Subscript_type
) return 0;
781 Name_type
= make_type("Name", expr_type
, Name_fields
, 2);
782 if (!Name_type
) return 0;
783 List_type
= make_type("List", expr_type
, List_fields
, 2);
784 if (!List_type
) return 0;
785 Tuple_type
= make_type("Tuple", expr_type
, Tuple_fields
, 2);
786 if (!Tuple_type
) return 0;
787 expr_context_type
= make_type("expr_context", &AST_type
, NULL
, 0);
788 if (!expr_context_type
) return 0;
789 if (!add_attributes(expr_context_type
, NULL
, 0)) return 0;
790 Load_type
= make_type("Load", expr_context_type
, NULL
, 0);
791 if (!Load_type
) return 0;
792 Load_singleton
= PyType_GenericNew(Load_type
, NULL
, NULL
);
793 if (!Load_singleton
) return 0;
794 Store_type
= make_type("Store", expr_context_type
, NULL
, 0);
795 if (!Store_type
) return 0;
796 Store_singleton
= PyType_GenericNew(Store_type
, NULL
, NULL
);
797 if (!Store_singleton
) return 0;
798 Del_type
= make_type("Del", expr_context_type
, NULL
, 0);
799 if (!Del_type
) return 0;
800 Del_singleton
= PyType_GenericNew(Del_type
, NULL
, NULL
);
801 if (!Del_singleton
) return 0;
802 AugLoad_type
= make_type("AugLoad", expr_context_type
, NULL
, 0);
803 if (!AugLoad_type
) return 0;
804 AugLoad_singleton
= PyType_GenericNew(AugLoad_type
, NULL
, NULL
);
805 if (!AugLoad_singleton
) return 0;
806 AugStore_type
= make_type("AugStore", expr_context_type
, NULL
, 0);
807 if (!AugStore_type
) return 0;
808 AugStore_singleton
= PyType_GenericNew(AugStore_type
, NULL
, NULL
);
809 if (!AugStore_singleton
) return 0;
810 Param_type
= make_type("Param", expr_context_type
, NULL
, 0);
811 if (!Param_type
) return 0;
812 Param_singleton
= PyType_GenericNew(Param_type
, NULL
, NULL
);
813 if (!Param_singleton
) return 0;
814 slice_type
= make_type("slice", &AST_type
, NULL
, 0);
815 if (!slice_type
) return 0;
816 if (!add_attributes(slice_type
, NULL
, 0)) return 0;
817 Ellipsis_type
= make_type("Ellipsis", slice_type
, NULL
, 0);
818 if (!Ellipsis_type
) return 0;
819 Slice_type
= make_type("Slice", slice_type
, Slice_fields
, 3);
820 if (!Slice_type
) return 0;
821 ExtSlice_type
= make_type("ExtSlice", slice_type
, ExtSlice_fields
, 1);
822 if (!ExtSlice_type
) return 0;
823 Index_type
= make_type("Index", slice_type
, Index_fields
, 1);
824 if (!Index_type
) return 0;
825 boolop_type
= make_type("boolop", &AST_type
, NULL
, 0);
826 if (!boolop_type
) return 0;
827 if (!add_attributes(boolop_type
, NULL
, 0)) return 0;
828 And_type
= make_type("And", boolop_type
, NULL
, 0);
829 if (!And_type
) return 0;
830 And_singleton
= PyType_GenericNew(And_type
, NULL
, NULL
);
831 if (!And_singleton
) return 0;
832 Or_type
= make_type("Or", boolop_type
, NULL
, 0);
833 if (!Or_type
) return 0;
834 Or_singleton
= PyType_GenericNew(Or_type
, NULL
, NULL
);
835 if (!Or_singleton
) return 0;
836 operator_type
= make_type("operator", &AST_type
, NULL
, 0);
837 if (!operator_type
) return 0;
838 if (!add_attributes(operator_type
, NULL
, 0)) return 0;
839 Add_type
= make_type("Add", operator_type
, NULL
, 0);
840 if (!Add_type
) return 0;
841 Add_singleton
= PyType_GenericNew(Add_type
, NULL
, NULL
);
842 if (!Add_singleton
) return 0;
843 Sub_type
= make_type("Sub", operator_type
, NULL
, 0);
844 if (!Sub_type
) return 0;
845 Sub_singleton
= PyType_GenericNew(Sub_type
, NULL
, NULL
);
846 if (!Sub_singleton
) return 0;
847 Mult_type
= make_type("Mult", operator_type
, NULL
, 0);
848 if (!Mult_type
) return 0;
849 Mult_singleton
= PyType_GenericNew(Mult_type
, NULL
, NULL
);
850 if (!Mult_singleton
) return 0;
851 Div_type
= make_type("Div", operator_type
, NULL
, 0);
852 if (!Div_type
) return 0;
853 Div_singleton
= PyType_GenericNew(Div_type
, NULL
, NULL
);
854 if (!Div_singleton
) return 0;
855 Mod_type
= make_type("Mod", operator_type
, NULL
, 0);
856 if (!Mod_type
) return 0;
857 Mod_singleton
= PyType_GenericNew(Mod_type
, NULL
, NULL
);
858 if (!Mod_singleton
) return 0;
859 Pow_type
= make_type("Pow", operator_type
, NULL
, 0);
860 if (!Pow_type
) return 0;
861 Pow_singleton
= PyType_GenericNew(Pow_type
, NULL
, NULL
);
862 if (!Pow_singleton
) return 0;
863 LShift_type
= make_type("LShift", operator_type
, NULL
, 0);
864 if (!LShift_type
) return 0;
865 LShift_singleton
= PyType_GenericNew(LShift_type
, NULL
, NULL
);
866 if (!LShift_singleton
) return 0;
867 RShift_type
= make_type("RShift", operator_type
, NULL
, 0);
868 if (!RShift_type
) return 0;
869 RShift_singleton
= PyType_GenericNew(RShift_type
, NULL
, NULL
);
870 if (!RShift_singleton
) return 0;
871 BitOr_type
= make_type("BitOr", operator_type
, NULL
, 0);
872 if (!BitOr_type
) return 0;
873 BitOr_singleton
= PyType_GenericNew(BitOr_type
, NULL
, NULL
);
874 if (!BitOr_singleton
) return 0;
875 BitXor_type
= make_type("BitXor", operator_type
, NULL
, 0);
876 if (!BitXor_type
) return 0;
877 BitXor_singleton
= PyType_GenericNew(BitXor_type
, NULL
, NULL
);
878 if (!BitXor_singleton
) return 0;
879 BitAnd_type
= make_type("BitAnd", operator_type
, NULL
, 0);
880 if (!BitAnd_type
) return 0;
881 BitAnd_singleton
= PyType_GenericNew(BitAnd_type
, NULL
, NULL
);
882 if (!BitAnd_singleton
) return 0;
883 FloorDiv_type
= make_type("FloorDiv", operator_type
, NULL
, 0);
884 if (!FloorDiv_type
) return 0;
885 FloorDiv_singleton
= PyType_GenericNew(FloorDiv_type
, NULL
, NULL
);
886 if (!FloorDiv_singleton
) return 0;
887 unaryop_type
= make_type("unaryop", &AST_type
, NULL
, 0);
888 if (!unaryop_type
) return 0;
889 if (!add_attributes(unaryop_type
, NULL
, 0)) return 0;
890 Invert_type
= make_type("Invert", unaryop_type
, NULL
, 0);
891 if (!Invert_type
) return 0;
892 Invert_singleton
= PyType_GenericNew(Invert_type
, NULL
, NULL
);
893 if (!Invert_singleton
) return 0;
894 Not_type
= make_type("Not", unaryop_type
, NULL
, 0);
895 if (!Not_type
) return 0;
896 Not_singleton
= PyType_GenericNew(Not_type
, NULL
, NULL
);
897 if (!Not_singleton
) return 0;
898 UAdd_type
= make_type("UAdd", unaryop_type
, NULL
, 0);
899 if (!UAdd_type
) return 0;
900 UAdd_singleton
= PyType_GenericNew(UAdd_type
, NULL
, NULL
);
901 if (!UAdd_singleton
) return 0;
902 USub_type
= make_type("USub", unaryop_type
, NULL
, 0);
903 if (!USub_type
) return 0;
904 USub_singleton
= PyType_GenericNew(USub_type
, NULL
, NULL
);
905 if (!USub_singleton
) return 0;
906 cmpop_type
= make_type("cmpop", &AST_type
, NULL
, 0);
907 if (!cmpop_type
) return 0;
908 if (!add_attributes(cmpop_type
, NULL
, 0)) return 0;
909 Eq_type
= make_type("Eq", cmpop_type
, NULL
, 0);
910 if (!Eq_type
) return 0;
911 Eq_singleton
= PyType_GenericNew(Eq_type
, NULL
, NULL
);
912 if (!Eq_singleton
) return 0;
913 NotEq_type
= make_type("NotEq", cmpop_type
, NULL
, 0);
914 if (!NotEq_type
) return 0;
915 NotEq_singleton
= PyType_GenericNew(NotEq_type
, NULL
, NULL
);
916 if (!NotEq_singleton
) return 0;
917 Lt_type
= make_type("Lt", cmpop_type
, NULL
, 0);
918 if (!Lt_type
) return 0;
919 Lt_singleton
= PyType_GenericNew(Lt_type
, NULL
, NULL
);
920 if (!Lt_singleton
) return 0;
921 LtE_type
= make_type("LtE", cmpop_type
, NULL
, 0);
922 if (!LtE_type
) return 0;
923 LtE_singleton
= PyType_GenericNew(LtE_type
, NULL
, NULL
);
924 if (!LtE_singleton
) return 0;
925 Gt_type
= make_type("Gt", cmpop_type
, NULL
, 0);
926 if (!Gt_type
) return 0;
927 Gt_singleton
= PyType_GenericNew(Gt_type
, NULL
, NULL
);
928 if (!Gt_singleton
) return 0;
929 GtE_type
= make_type("GtE", cmpop_type
, NULL
, 0);
930 if (!GtE_type
) return 0;
931 GtE_singleton
= PyType_GenericNew(GtE_type
, NULL
, NULL
);
932 if (!GtE_singleton
) return 0;
933 Is_type
= make_type("Is", cmpop_type
, NULL
, 0);
934 if (!Is_type
) return 0;
935 Is_singleton
= PyType_GenericNew(Is_type
, NULL
, NULL
);
936 if (!Is_singleton
) return 0;
937 IsNot_type
= make_type("IsNot", cmpop_type
, NULL
, 0);
938 if (!IsNot_type
) return 0;
939 IsNot_singleton
= PyType_GenericNew(IsNot_type
, NULL
, NULL
);
940 if (!IsNot_singleton
) return 0;
941 In_type
= make_type("In", cmpop_type
, NULL
, 0);
942 if (!In_type
) return 0;
943 In_singleton
= PyType_GenericNew(In_type
, NULL
, NULL
);
944 if (!In_singleton
) return 0;
945 NotIn_type
= make_type("NotIn", cmpop_type
, NULL
, 0);
946 if (!NotIn_type
) return 0;
947 NotIn_singleton
= PyType_GenericNew(NotIn_type
, NULL
, NULL
);
948 if (!NotIn_singleton
) return 0;
949 comprehension_type
= make_type("comprehension", &AST_type
,
950 comprehension_fields
, 3);
951 if (!comprehension_type
) return 0;
952 excepthandler_type
= make_type("excepthandler", &AST_type
, NULL
, 0);
953 if (!excepthandler_type
) return 0;
954 if (!add_attributes(excepthandler_type
, excepthandler_attributes
, 2))
956 ExceptHandler_type
= make_type("ExceptHandler", excepthandler_type
,
957 ExceptHandler_fields
, 3);
958 if (!ExceptHandler_type
) return 0;
959 arguments_type
= make_type("arguments", &AST_type
, arguments_fields
, 4);
960 if (!arguments_type
) return 0;
961 keyword_type
= make_type("keyword", &AST_type
, keyword_fields
, 2);
962 if (!keyword_type
) return 0;
963 alias_type
= make_type("alias", &AST_type
, alias_fields
, 2);
964 if (!alias_type
) return 0;
969 static int obj2ast_mod(PyObject
* obj
, mod_ty
* out
, PyArena
* arena
);
970 static int obj2ast_stmt(PyObject
* obj
, stmt_ty
* out
, PyArena
* arena
);
971 static int obj2ast_expr(PyObject
* obj
, expr_ty
* out
, PyArena
* arena
);
972 static int obj2ast_expr_context(PyObject
* obj
, expr_context_ty
* out
, PyArena
*
974 static int obj2ast_slice(PyObject
* obj
, slice_ty
* out
, PyArena
* arena
);
975 static int obj2ast_boolop(PyObject
* obj
, boolop_ty
* out
, PyArena
* arena
);
976 static int obj2ast_operator(PyObject
* obj
, operator_ty
* out
, PyArena
* arena
);
977 static int obj2ast_unaryop(PyObject
* obj
, unaryop_ty
* out
, PyArena
* arena
);
978 static int obj2ast_cmpop(PyObject
* obj
, cmpop_ty
* out
, PyArena
* arena
);
979 static int obj2ast_comprehension(PyObject
* obj
, comprehension_ty
* out
, PyArena
*
981 static int obj2ast_excepthandler(PyObject
* obj
, excepthandler_ty
* out
, PyArena
*
983 static int obj2ast_arguments(PyObject
* obj
, arguments_ty
* out
, PyArena
* arena
);
984 static int obj2ast_keyword(PyObject
* obj
, keyword_ty
* out
, PyArena
* arena
);
985 static int obj2ast_alias(PyObject
* obj
, alias_ty
* out
, PyArena
* arena
);
988 Module(asdl_seq
* body
, PyArena
*arena
)
991 p
= (mod_ty
)PyArena_Malloc(arena
, sizeof(*p
));
994 p
->kind
= Module_kind
;
995 p
->v
.Module
.body
= body
;
1000 Interactive(asdl_seq
* body
, PyArena
*arena
)
1003 p
= (mod_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1006 p
->kind
= Interactive_kind
;
1007 p
->v
.Interactive
.body
= body
;
1012 Expression(expr_ty body
, PyArena
*arena
)
1016 PyErr_SetString(PyExc_ValueError
,
1017 "field body is required for Expression");
1020 p
= (mod_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1023 p
->kind
= Expression_kind
;
1024 p
->v
.Expression
.body
= body
;
1029 Suite(asdl_seq
* body
, PyArena
*arena
)
1032 p
= (mod_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1035 p
->kind
= Suite_kind
;
1036 p
->v
.Suite
.body
= body
;
1041 FunctionDef(identifier name
, arguments_ty args
, asdl_seq
* body
, asdl_seq
*
1042 decorator_list
, int lineno
, int col_offset
, PyArena
*arena
)
1046 PyErr_SetString(PyExc_ValueError
,
1047 "field name is required for FunctionDef");
1051 PyErr_SetString(PyExc_ValueError
,
1052 "field args is required for FunctionDef");
1055 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1058 p
->kind
= FunctionDef_kind
;
1059 p
->v
.FunctionDef
.name
= name
;
1060 p
->v
.FunctionDef
.args
= args
;
1061 p
->v
.FunctionDef
.body
= body
;
1062 p
->v
.FunctionDef
.decorator_list
= decorator_list
;
1064 p
->col_offset
= col_offset
;
1069 ClassDef(identifier name
, asdl_seq
* bases
, asdl_seq
* body
, asdl_seq
*
1070 decorator_list
, int lineno
, int col_offset
, PyArena
*arena
)
1074 PyErr_SetString(PyExc_ValueError
,
1075 "field name is required for ClassDef");
1078 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1081 p
->kind
= ClassDef_kind
;
1082 p
->v
.ClassDef
.name
= name
;
1083 p
->v
.ClassDef
.bases
= bases
;
1084 p
->v
.ClassDef
.body
= body
;
1085 p
->v
.ClassDef
.decorator_list
= decorator_list
;
1087 p
->col_offset
= col_offset
;
1092 Return(expr_ty value
, int lineno
, int col_offset
, PyArena
*arena
)
1095 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1098 p
->kind
= Return_kind
;
1099 p
->v
.Return
.value
= value
;
1101 p
->col_offset
= col_offset
;
1106 Delete(asdl_seq
* targets
, int lineno
, int col_offset
, PyArena
*arena
)
1109 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1112 p
->kind
= Delete_kind
;
1113 p
->v
.Delete
.targets
= targets
;
1115 p
->col_offset
= col_offset
;
1120 Assign(asdl_seq
* targets
, expr_ty value
, int lineno
, int col_offset
, PyArena
1125 PyErr_SetString(PyExc_ValueError
,
1126 "field value is required for Assign");
1129 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1132 p
->kind
= Assign_kind
;
1133 p
->v
.Assign
.targets
= targets
;
1134 p
->v
.Assign
.value
= value
;
1136 p
->col_offset
= col_offset
;
1141 AugAssign(expr_ty target
, operator_ty op
, expr_ty value
, int lineno
, int
1142 col_offset
, PyArena
*arena
)
1146 PyErr_SetString(PyExc_ValueError
,
1147 "field target is required for AugAssign");
1151 PyErr_SetString(PyExc_ValueError
,
1152 "field op is required for AugAssign");
1156 PyErr_SetString(PyExc_ValueError
,
1157 "field value is required for AugAssign");
1160 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1163 p
->kind
= AugAssign_kind
;
1164 p
->v
.AugAssign
.target
= target
;
1165 p
->v
.AugAssign
.op
= op
;
1166 p
->v
.AugAssign
.value
= value
;
1168 p
->col_offset
= col_offset
;
1173 Print(expr_ty dest
, asdl_seq
* values
, bool nl
, int lineno
, int col_offset
,
1177 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1180 p
->kind
= Print_kind
;
1181 p
->v
.Print
.dest
= dest
;
1182 p
->v
.Print
.values
= values
;
1185 p
->col_offset
= col_offset
;
1190 For(expr_ty target
, expr_ty iter
, asdl_seq
* body
, asdl_seq
* orelse
, int
1191 lineno
, int col_offset
, PyArena
*arena
)
1195 PyErr_SetString(PyExc_ValueError
,
1196 "field target is required for For");
1200 PyErr_SetString(PyExc_ValueError
,
1201 "field iter is required for For");
1204 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1208 p
->v
.For
.target
= target
;
1209 p
->v
.For
.iter
= iter
;
1210 p
->v
.For
.body
= body
;
1211 p
->v
.For
.orelse
= orelse
;
1213 p
->col_offset
= col_offset
;
1218 While(expr_ty test
, asdl_seq
* body
, asdl_seq
* orelse
, int lineno
, int
1219 col_offset
, PyArena
*arena
)
1223 PyErr_SetString(PyExc_ValueError
,
1224 "field test is required for While");
1227 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1230 p
->kind
= While_kind
;
1231 p
->v
.While
.test
= test
;
1232 p
->v
.While
.body
= body
;
1233 p
->v
.While
.orelse
= orelse
;
1235 p
->col_offset
= col_offset
;
1240 If(expr_ty test
, asdl_seq
* body
, asdl_seq
* orelse
, int lineno
, int
1241 col_offset
, PyArena
*arena
)
1245 PyErr_SetString(PyExc_ValueError
,
1246 "field test is required for If");
1249 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1253 p
->v
.If
.test
= test
;
1254 p
->v
.If
.body
= body
;
1255 p
->v
.If
.orelse
= orelse
;
1257 p
->col_offset
= col_offset
;
1262 With(expr_ty context_expr
, expr_ty optional_vars
, asdl_seq
* body
, int lineno
,
1263 int col_offset
, PyArena
*arena
)
1266 if (!context_expr
) {
1267 PyErr_SetString(PyExc_ValueError
,
1268 "field context_expr is required for With");
1271 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1274 p
->kind
= With_kind
;
1275 p
->v
.With
.context_expr
= context_expr
;
1276 p
->v
.With
.optional_vars
= optional_vars
;
1277 p
->v
.With
.body
= body
;
1279 p
->col_offset
= col_offset
;
1284 Raise(expr_ty type
, expr_ty inst
, expr_ty tback
, int lineno
, int col_offset
,
1288 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1291 p
->kind
= Raise_kind
;
1292 p
->v
.Raise
.type
= type
;
1293 p
->v
.Raise
.inst
= inst
;
1294 p
->v
.Raise
.tback
= tback
;
1296 p
->col_offset
= col_offset
;
1301 TryExcept(asdl_seq
* body
, asdl_seq
* handlers
, asdl_seq
* orelse
, int lineno
,
1302 int col_offset
, PyArena
*arena
)
1305 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1308 p
->kind
= TryExcept_kind
;
1309 p
->v
.TryExcept
.body
= body
;
1310 p
->v
.TryExcept
.handlers
= handlers
;
1311 p
->v
.TryExcept
.orelse
= orelse
;
1313 p
->col_offset
= col_offset
;
1318 TryFinally(asdl_seq
* body
, asdl_seq
* finalbody
, int lineno
, int col_offset
,
1322 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1325 p
->kind
= TryFinally_kind
;
1326 p
->v
.TryFinally
.body
= body
;
1327 p
->v
.TryFinally
.finalbody
= finalbody
;
1329 p
->col_offset
= col_offset
;
1334 Assert(expr_ty test
, expr_ty msg
, int lineno
, int col_offset
, PyArena
*arena
)
1338 PyErr_SetString(PyExc_ValueError
,
1339 "field test is required for Assert");
1342 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1345 p
->kind
= Assert_kind
;
1346 p
->v
.Assert
.test
= test
;
1347 p
->v
.Assert
.msg
= msg
;
1349 p
->col_offset
= col_offset
;
1354 Import(asdl_seq
* names
, int lineno
, int col_offset
, PyArena
*arena
)
1357 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1360 p
->kind
= Import_kind
;
1361 p
->v
.Import
.names
= names
;
1363 p
->col_offset
= col_offset
;
1368 ImportFrom(identifier module
, asdl_seq
* names
, int level
, int lineno
, int
1369 col_offset
, PyArena
*arena
)
1372 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1375 p
->kind
= ImportFrom_kind
;
1376 p
->v
.ImportFrom
.module
= module
;
1377 p
->v
.ImportFrom
.names
= names
;
1378 p
->v
.ImportFrom
.level
= level
;
1380 p
->col_offset
= col_offset
;
1385 Exec(expr_ty body
, expr_ty globals
, expr_ty locals
, int lineno
, int col_offset
,
1390 PyErr_SetString(PyExc_ValueError
,
1391 "field body is required for Exec");
1394 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1397 p
->kind
= Exec_kind
;
1398 p
->v
.Exec
.body
= body
;
1399 p
->v
.Exec
.globals
= globals
;
1400 p
->v
.Exec
.locals
= locals
;
1402 p
->col_offset
= col_offset
;
1407 Global(asdl_seq
* names
, int lineno
, int col_offset
, PyArena
*arena
)
1410 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1413 p
->kind
= Global_kind
;
1414 p
->v
.Global
.names
= names
;
1416 p
->col_offset
= col_offset
;
1421 Expr(expr_ty value
, int lineno
, int col_offset
, PyArena
*arena
)
1425 PyErr_SetString(PyExc_ValueError
,
1426 "field value is required for Expr");
1429 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1432 p
->kind
= Expr_kind
;
1433 p
->v
.Expr
.value
= value
;
1435 p
->col_offset
= col_offset
;
1440 Pass(int lineno
, int col_offset
, PyArena
*arena
)
1443 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1446 p
->kind
= Pass_kind
;
1448 p
->col_offset
= col_offset
;
1453 Break(int lineno
, int col_offset
, PyArena
*arena
)
1456 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1459 p
->kind
= Break_kind
;
1461 p
->col_offset
= col_offset
;
1466 Continue(int lineno
, int col_offset
, PyArena
*arena
)
1469 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1472 p
->kind
= Continue_kind
;
1474 p
->col_offset
= col_offset
;
1479 BoolOp(boolop_ty op
, asdl_seq
* values
, int lineno
, int col_offset
, PyArena
1484 PyErr_SetString(PyExc_ValueError
,
1485 "field op is required for BoolOp");
1488 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1491 p
->kind
= BoolOp_kind
;
1492 p
->v
.BoolOp
.op
= op
;
1493 p
->v
.BoolOp
.values
= values
;
1495 p
->col_offset
= col_offset
;
1500 BinOp(expr_ty left
, operator_ty op
, expr_ty right
, int lineno
, int col_offset
,
1505 PyErr_SetString(PyExc_ValueError
,
1506 "field left is required for BinOp");
1510 PyErr_SetString(PyExc_ValueError
,
1511 "field op is required for BinOp");
1515 PyErr_SetString(PyExc_ValueError
,
1516 "field right is required for BinOp");
1519 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1522 p
->kind
= BinOp_kind
;
1523 p
->v
.BinOp
.left
= left
;
1525 p
->v
.BinOp
.right
= right
;
1527 p
->col_offset
= col_offset
;
1532 UnaryOp(unaryop_ty op
, expr_ty operand
, int lineno
, int col_offset
, PyArena
1537 PyErr_SetString(PyExc_ValueError
,
1538 "field op is required for UnaryOp");
1542 PyErr_SetString(PyExc_ValueError
,
1543 "field operand is required for UnaryOp");
1546 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1549 p
->kind
= UnaryOp_kind
;
1550 p
->v
.UnaryOp
.op
= op
;
1551 p
->v
.UnaryOp
.operand
= operand
;
1553 p
->col_offset
= col_offset
;
1558 Lambda(arguments_ty args
, expr_ty body
, int lineno
, int col_offset
, PyArena
1563 PyErr_SetString(PyExc_ValueError
,
1564 "field args is required for Lambda");
1568 PyErr_SetString(PyExc_ValueError
,
1569 "field body is required for Lambda");
1572 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1575 p
->kind
= Lambda_kind
;
1576 p
->v
.Lambda
.args
= args
;
1577 p
->v
.Lambda
.body
= body
;
1579 p
->col_offset
= col_offset
;
1584 IfExp(expr_ty test
, expr_ty body
, expr_ty orelse
, int lineno
, int col_offset
,
1589 PyErr_SetString(PyExc_ValueError
,
1590 "field test is required for IfExp");
1594 PyErr_SetString(PyExc_ValueError
,
1595 "field body is required for IfExp");
1599 PyErr_SetString(PyExc_ValueError
,
1600 "field orelse is required for IfExp");
1603 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1606 p
->kind
= IfExp_kind
;
1607 p
->v
.IfExp
.test
= test
;
1608 p
->v
.IfExp
.body
= body
;
1609 p
->v
.IfExp
.orelse
= orelse
;
1611 p
->col_offset
= col_offset
;
1616 Dict(asdl_seq
* keys
, asdl_seq
* values
, int lineno
, int col_offset
, PyArena
1620 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1623 p
->kind
= Dict_kind
;
1624 p
->v
.Dict
.keys
= keys
;
1625 p
->v
.Dict
.values
= values
;
1627 p
->col_offset
= col_offset
;
1632 Set(asdl_seq
* elts
, int lineno
, int col_offset
, PyArena
*arena
)
1635 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1639 p
->v
.Set
.elts
= elts
;
1641 p
->col_offset
= col_offset
;
1646 ListComp(expr_ty elt
, asdl_seq
* generators
, int lineno
, int col_offset
,
1651 PyErr_SetString(PyExc_ValueError
,
1652 "field elt is required for ListComp");
1655 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1658 p
->kind
= ListComp_kind
;
1659 p
->v
.ListComp
.elt
= elt
;
1660 p
->v
.ListComp
.generators
= generators
;
1662 p
->col_offset
= col_offset
;
1667 SetComp(expr_ty elt
, asdl_seq
* generators
, int lineno
, int col_offset
, PyArena
1672 PyErr_SetString(PyExc_ValueError
,
1673 "field elt is required for SetComp");
1676 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1679 p
->kind
= SetComp_kind
;
1680 p
->v
.SetComp
.elt
= elt
;
1681 p
->v
.SetComp
.generators
= generators
;
1683 p
->col_offset
= col_offset
;
1688 DictComp(expr_ty key
, expr_ty value
, asdl_seq
* generators
, int lineno
, int
1689 col_offset
, PyArena
*arena
)
1693 PyErr_SetString(PyExc_ValueError
,
1694 "field key is required for DictComp");
1698 PyErr_SetString(PyExc_ValueError
,
1699 "field value is required for DictComp");
1702 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1705 p
->kind
= DictComp_kind
;
1706 p
->v
.DictComp
.key
= key
;
1707 p
->v
.DictComp
.value
= value
;
1708 p
->v
.DictComp
.generators
= generators
;
1710 p
->col_offset
= col_offset
;
1715 GeneratorExp(expr_ty elt
, asdl_seq
* generators
, int lineno
, int col_offset
,
1720 PyErr_SetString(PyExc_ValueError
,
1721 "field elt is required for GeneratorExp");
1724 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1727 p
->kind
= GeneratorExp_kind
;
1728 p
->v
.GeneratorExp
.elt
= elt
;
1729 p
->v
.GeneratorExp
.generators
= generators
;
1731 p
->col_offset
= col_offset
;
1736 Yield(expr_ty value
, int lineno
, int col_offset
, PyArena
*arena
)
1739 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1742 p
->kind
= Yield_kind
;
1743 p
->v
.Yield
.value
= value
;
1745 p
->col_offset
= col_offset
;
1750 Compare(expr_ty left
, asdl_int_seq
* ops
, asdl_seq
* comparators
, int lineno
,
1751 int col_offset
, PyArena
*arena
)
1755 PyErr_SetString(PyExc_ValueError
,
1756 "field left is required for Compare");
1759 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1762 p
->kind
= Compare_kind
;
1763 p
->v
.Compare
.left
= left
;
1764 p
->v
.Compare
.ops
= ops
;
1765 p
->v
.Compare
.comparators
= comparators
;
1767 p
->col_offset
= col_offset
;
1772 Call(expr_ty func
, asdl_seq
* args
, asdl_seq
* keywords
, expr_ty starargs
,
1773 expr_ty kwargs
, int lineno
, int col_offset
, PyArena
*arena
)
1777 PyErr_SetString(PyExc_ValueError
,
1778 "field func is required for Call");
1781 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1784 p
->kind
= Call_kind
;
1785 p
->v
.Call
.func
= func
;
1786 p
->v
.Call
.args
= args
;
1787 p
->v
.Call
.keywords
= keywords
;
1788 p
->v
.Call
.starargs
= starargs
;
1789 p
->v
.Call
.kwargs
= kwargs
;
1791 p
->col_offset
= col_offset
;
1796 Repr(expr_ty value
, int lineno
, int col_offset
, PyArena
*arena
)
1800 PyErr_SetString(PyExc_ValueError
,
1801 "field value is required for Repr");
1804 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1807 p
->kind
= Repr_kind
;
1808 p
->v
.Repr
.value
= value
;
1810 p
->col_offset
= col_offset
;
1815 Num(object n
, int lineno
, int col_offset
, PyArena
*arena
)
1819 PyErr_SetString(PyExc_ValueError
,
1820 "field n is required for Num");
1823 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1829 p
->col_offset
= col_offset
;
1834 Str(string s
, int lineno
, int col_offset
, PyArena
*arena
)
1838 PyErr_SetString(PyExc_ValueError
,
1839 "field s is required for Str");
1842 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1848 p
->col_offset
= col_offset
;
1853 Attribute(expr_ty value
, identifier attr
, expr_context_ty ctx
, int lineno
, int
1854 col_offset
, PyArena
*arena
)
1858 PyErr_SetString(PyExc_ValueError
,
1859 "field value is required for Attribute");
1863 PyErr_SetString(PyExc_ValueError
,
1864 "field attr is required for Attribute");
1868 PyErr_SetString(PyExc_ValueError
,
1869 "field ctx is required for Attribute");
1872 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1875 p
->kind
= Attribute_kind
;
1876 p
->v
.Attribute
.value
= value
;
1877 p
->v
.Attribute
.attr
= attr
;
1878 p
->v
.Attribute
.ctx
= ctx
;
1880 p
->col_offset
= col_offset
;
1885 Subscript(expr_ty value
, slice_ty slice
, expr_context_ty ctx
, int lineno
, int
1886 col_offset
, PyArena
*arena
)
1890 PyErr_SetString(PyExc_ValueError
,
1891 "field value is required for Subscript");
1895 PyErr_SetString(PyExc_ValueError
,
1896 "field slice is required for Subscript");
1900 PyErr_SetString(PyExc_ValueError
,
1901 "field ctx is required for Subscript");
1904 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1907 p
->kind
= Subscript_kind
;
1908 p
->v
.Subscript
.value
= value
;
1909 p
->v
.Subscript
.slice
= slice
;
1910 p
->v
.Subscript
.ctx
= ctx
;
1912 p
->col_offset
= col_offset
;
1917 Name(identifier id
, expr_context_ty ctx
, int lineno
, int col_offset
, PyArena
1922 PyErr_SetString(PyExc_ValueError
,
1923 "field id is required for Name");
1927 PyErr_SetString(PyExc_ValueError
,
1928 "field ctx is required for Name");
1931 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1934 p
->kind
= Name_kind
;
1936 p
->v
.Name
.ctx
= ctx
;
1938 p
->col_offset
= col_offset
;
1943 List(asdl_seq
* elts
, expr_context_ty ctx
, int lineno
, int col_offset
, PyArena
1948 PyErr_SetString(PyExc_ValueError
,
1949 "field ctx is required for List");
1952 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1955 p
->kind
= List_kind
;
1956 p
->v
.List
.elts
= elts
;
1957 p
->v
.List
.ctx
= ctx
;
1959 p
->col_offset
= col_offset
;
1964 Tuple(asdl_seq
* elts
, expr_context_ty ctx
, int lineno
, int col_offset
, PyArena
1969 PyErr_SetString(PyExc_ValueError
,
1970 "field ctx is required for Tuple");
1973 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1976 p
->kind
= Tuple_kind
;
1977 p
->v
.Tuple
.elts
= elts
;
1978 p
->v
.Tuple
.ctx
= ctx
;
1980 p
->col_offset
= col_offset
;
1985 Ellipsis(PyArena
*arena
)
1988 p
= (slice_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1991 p
->kind
= Ellipsis_kind
;
1996 Slice(expr_ty lower
, expr_ty upper
, expr_ty step
, PyArena
*arena
)
1999 p
= (slice_ty
)PyArena_Malloc(arena
, sizeof(*p
));
2002 p
->kind
= Slice_kind
;
2003 p
->v
.Slice
.lower
= lower
;
2004 p
->v
.Slice
.upper
= upper
;
2005 p
->v
.Slice
.step
= step
;
2010 ExtSlice(asdl_seq
* dims
, PyArena
*arena
)
2013 p
= (slice_ty
)PyArena_Malloc(arena
, sizeof(*p
));
2016 p
->kind
= ExtSlice_kind
;
2017 p
->v
.ExtSlice
.dims
= dims
;
2022 Index(expr_ty value
, PyArena
*arena
)
2026 PyErr_SetString(PyExc_ValueError
,
2027 "field value is required for Index");
2030 p
= (slice_ty
)PyArena_Malloc(arena
, sizeof(*p
));
2033 p
->kind
= Index_kind
;
2034 p
->v
.Index
.value
= value
;
2039 comprehension(expr_ty target
, expr_ty iter
, asdl_seq
* ifs
, PyArena
*arena
)
2043 PyErr_SetString(PyExc_ValueError
,
2044 "field target is required for comprehension");
2048 PyErr_SetString(PyExc_ValueError
,
2049 "field iter is required for comprehension");
2052 p
= (comprehension_ty
)PyArena_Malloc(arena
, sizeof(*p
));
2062 ExceptHandler(expr_ty type
, expr_ty name
, asdl_seq
* body
, int lineno
, int
2063 col_offset
, PyArena
*arena
)
2066 p
= (excepthandler_ty
)PyArena_Malloc(arena
, sizeof(*p
));
2069 p
->kind
= ExceptHandler_kind
;
2070 p
->v
.ExceptHandler
.type
= type
;
2071 p
->v
.ExceptHandler
.name
= name
;
2072 p
->v
.ExceptHandler
.body
= body
;
2074 p
->col_offset
= col_offset
;
2079 arguments(asdl_seq
* args
, identifier vararg
, identifier kwarg
, asdl_seq
*
2080 defaults
, PyArena
*arena
)
2083 p
= (arguments_ty
)PyArena_Malloc(arena
, sizeof(*p
));
2089 p
->defaults
= defaults
;
2094 keyword(identifier arg
, expr_ty value
, PyArena
*arena
)
2098 PyErr_SetString(PyExc_ValueError
,
2099 "field arg is required for keyword");
2103 PyErr_SetString(PyExc_ValueError
,
2104 "field value is required for keyword");
2107 p
= (keyword_ty
)PyArena_Malloc(arena
, sizeof(*p
));
2116 alias(identifier name
, identifier asname
, PyArena
*arena
)
2120 PyErr_SetString(PyExc_ValueError
,
2121 "field name is required for alias");
2124 p
= (alias_ty
)PyArena_Malloc(arena
, sizeof(*p
));
2134 ast2obj_mod(void* _o
)
2136 mod_ty o
= (mod_ty
)_o
;
2137 PyObject
*result
= NULL
, *value
= NULL
;
2145 result
= PyType_GenericNew(Module_type
, NULL
, NULL
);
2146 if (!result
) goto failed
;
2147 value
= ast2obj_list(o
->v
.Module
.body
, ast2obj_stmt
);
2148 if (!value
) goto failed
;
2149 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2153 case Interactive_kind
:
2154 result
= PyType_GenericNew(Interactive_type
, NULL
, NULL
);
2155 if (!result
) goto failed
;
2156 value
= ast2obj_list(o
->v
.Interactive
.body
, ast2obj_stmt
);
2157 if (!value
) goto failed
;
2158 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2162 case Expression_kind
:
2163 result
= PyType_GenericNew(Expression_type
, NULL
, NULL
);
2164 if (!result
) goto failed
;
2165 value
= ast2obj_expr(o
->v
.Expression
.body
);
2166 if (!value
) goto failed
;
2167 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2172 result
= PyType_GenericNew(Suite_type
, NULL
, NULL
);
2173 if (!result
) goto failed
;
2174 value
= ast2obj_list(o
->v
.Suite
.body
, ast2obj_stmt
);
2175 if (!value
) goto failed
;
2176 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2189 ast2obj_stmt(void* _o
)
2191 stmt_ty o
= (stmt_ty
)_o
;
2192 PyObject
*result
= NULL
, *value
= NULL
;
2199 case FunctionDef_kind
:
2200 result
= PyType_GenericNew(FunctionDef_type
, NULL
, NULL
);
2201 if (!result
) goto failed
;
2202 value
= ast2obj_identifier(o
->v
.FunctionDef
.name
);
2203 if (!value
) goto failed
;
2204 if (PyObject_SetAttrString(result
, "name", value
) == -1)
2207 value
= ast2obj_arguments(o
->v
.FunctionDef
.args
);
2208 if (!value
) goto failed
;
2209 if (PyObject_SetAttrString(result
, "args", value
) == -1)
2212 value
= ast2obj_list(o
->v
.FunctionDef
.body
, ast2obj_stmt
);
2213 if (!value
) goto failed
;
2214 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2217 value
= ast2obj_list(o
->v
.FunctionDef
.decorator_list
,
2219 if (!value
) goto failed
;
2220 if (PyObject_SetAttrString(result
, "decorator_list", value
) ==
2226 result
= PyType_GenericNew(ClassDef_type
, NULL
, NULL
);
2227 if (!result
) goto failed
;
2228 value
= ast2obj_identifier(o
->v
.ClassDef
.name
);
2229 if (!value
) goto failed
;
2230 if (PyObject_SetAttrString(result
, "name", value
) == -1)
2233 value
= ast2obj_list(o
->v
.ClassDef
.bases
, ast2obj_expr
);
2234 if (!value
) goto failed
;
2235 if (PyObject_SetAttrString(result
, "bases", value
) == -1)
2238 value
= ast2obj_list(o
->v
.ClassDef
.body
, ast2obj_stmt
);
2239 if (!value
) goto failed
;
2240 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2243 value
= ast2obj_list(o
->v
.ClassDef
.decorator_list
,
2245 if (!value
) goto failed
;
2246 if (PyObject_SetAttrString(result
, "decorator_list", value
) ==
2252 result
= PyType_GenericNew(Return_type
, NULL
, NULL
);
2253 if (!result
) goto failed
;
2254 value
= ast2obj_expr(o
->v
.Return
.value
);
2255 if (!value
) goto failed
;
2256 if (PyObject_SetAttrString(result
, "value", value
) == -1)
2261 result
= PyType_GenericNew(Delete_type
, NULL
, NULL
);
2262 if (!result
) goto failed
;
2263 value
= ast2obj_list(o
->v
.Delete
.targets
, ast2obj_expr
);
2264 if (!value
) goto failed
;
2265 if (PyObject_SetAttrString(result
, "targets", value
) == -1)
2270 result
= PyType_GenericNew(Assign_type
, NULL
, NULL
);
2271 if (!result
) goto failed
;
2272 value
= ast2obj_list(o
->v
.Assign
.targets
, ast2obj_expr
);
2273 if (!value
) goto failed
;
2274 if (PyObject_SetAttrString(result
, "targets", value
) == -1)
2277 value
= ast2obj_expr(o
->v
.Assign
.value
);
2278 if (!value
) goto failed
;
2279 if (PyObject_SetAttrString(result
, "value", value
) == -1)
2283 case AugAssign_kind
:
2284 result
= PyType_GenericNew(AugAssign_type
, NULL
, NULL
);
2285 if (!result
) goto failed
;
2286 value
= ast2obj_expr(o
->v
.AugAssign
.target
);
2287 if (!value
) goto failed
;
2288 if (PyObject_SetAttrString(result
, "target", value
) == -1)
2291 value
= ast2obj_operator(o
->v
.AugAssign
.op
);
2292 if (!value
) goto failed
;
2293 if (PyObject_SetAttrString(result
, "op", value
) == -1)
2296 value
= ast2obj_expr(o
->v
.AugAssign
.value
);
2297 if (!value
) goto failed
;
2298 if (PyObject_SetAttrString(result
, "value", value
) == -1)
2303 result
= PyType_GenericNew(Print_type
, NULL
, NULL
);
2304 if (!result
) goto failed
;
2305 value
= ast2obj_expr(o
->v
.Print
.dest
);
2306 if (!value
) goto failed
;
2307 if (PyObject_SetAttrString(result
, "dest", value
) == -1)
2310 value
= ast2obj_list(o
->v
.Print
.values
, ast2obj_expr
);
2311 if (!value
) goto failed
;
2312 if (PyObject_SetAttrString(result
, "values", value
) == -1)
2315 value
= ast2obj_bool(o
->v
.Print
.nl
);
2316 if (!value
) goto failed
;
2317 if (PyObject_SetAttrString(result
, "nl", value
) == -1)
2322 result
= PyType_GenericNew(For_type
, NULL
, NULL
);
2323 if (!result
) goto failed
;
2324 value
= ast2obj_expr(o
->v
.For
.target
);
2325 if (!value
) goto failed
;
2326 if (PyObject_SetAttrString(result
, "target", value
) == -1)
2329 value
= ast2obj_expr(o
->v
.For
.iter
);
2330 if (!value
) goto failed
;
2331 if (PyObject_SetAttrString(result
, "iter", value
) == -1)
2334 value
= ast2obj_list(o
->v
.For
.body
, ast2obj_stmt
);
2335 if (!value
) goto failed
;
2336 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2339 value
= ast2obj_list(o
->v
.For
.orelse
, ast2obj_stmt
);
2340 if (!value
) goto failed
;
2341 if (PyObject_SetAttrString(result
, "orelse", value
) == -1)
2346 result
= PyType_GenericNew(While_type
, NULL
, NULL
);
2347 if (!result
) goto failed
;
2348 value
= ast2obj_expr(o
->v
.While
.test
);
2349 if (!value
) goto failed
;
2350 if (PyObject_SetAttrString(result
, "test", value
) == -1)
2353 value
= ast2obj_list(o
->v
.While
.body
, ast2obj_stmt
);
2354 if (!value
) goto failed
;
2355 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2358 value
= ast2obj_list(o
->v
.While
.orelse
, ast2obj_stmt
);
2359 if (!value
) goto failed
;
2360 if (PyObject_SetAttrString(result
, "orelse", value
) == -1)
2365 result
= PyType_GenericNew(If_type
, NULL
, NULL
);
2366 if (!result
) goto failed
;
2367 value
= ast2obj_expr(o
->v
.If
.test
);
2368 if (!value
) goto failed
;
2369 if (PyObject_SetAttrString(result
, "test", value
) == -1)
2372 value
= ast2obj_list(o
->v
.If
.body
, ast2obj_stmt
);
2373 if (!value
) goto failed
;
2374 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2377 value
= ast2obj_list(o
->v
.If
.orelse
, ast2obj_stmt
);
2378 if (!value
) goto failed
;
2379 if (PyObject_SetAttrString(result
, "orelse", value
) == -1)
2384 result
= PyType_GenericNew(With_type
, NULL
, NULL
);
2385 if (!result
) goto failed
;
2386 value
= ast2obj_expr(o
->v
.With
.context_expr
);
2387 if (!value
) goto failed
;
2388 if (PyObject_SetAttrString(result
, "context_expr", value
) == -1)
2391 value
= ast2obj_expr(o
->v
.With
.optional_vars
);
2392 if (!value
) goto failed
;
2393 if (PyObject_SetAttrString(result
, "optional_vars", value
) ==
2397 value
= ast2obj_list(o
->v
.With
.body
, ast2obj_stmt
);
2398 if (!value
) goto failed
;
2399 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2404 result
= PyType_GenericNew(Raise_type
, NULL
, NULL
);
2405 if (!result
) goto failed
;
2406 value
= ast2obj_expr(o
->v
.Raise
.type
);
2407 if (!value
) goto failed
;
2408 if (PyObject_SetAttrString(result
, "type", value
) == -1)
2411 value
= ast2obj_expr(o
->v
.Raise
.inst
);
2412 if (!value
) goto failed
;
2413 if (PyObject_SetAttrString(result
, "inst", value
) == -1)
2416 value
= ast2obj_expr(o
->v
.Raise
.tback
);
2417 if (!value
) goto failed
;
2418 if (PyObject_SetAttrString(result
, "tback", value
) == -1)
2422 case TryExcept_kind
:
2423 result
= PyType_GenericNew(TryExcept_type
, NULL
, NULL
);
2424 if (!result
) goto failed
;
2425 value
= ast2obj_list(o
->v
.TryExcept
.body
, ast2obj_stmt
);
2426 if (!value
) goto failed
;
2427 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2430 value
= ast2obj_list(o
->v
.TryExcept
.handlers
,
2431 ast2obj_excepthandler
);
2432 if (!value
) goto failed
;
2433 if (PyObject_SetAttrString(result
, "handlers", value
) == -1)
2436 value
= ast2obj_list(o
->v
.TryExcept
.orelse
, ast2obj_stmt
);
2437 if (!value
) goto failed
;
2438 if (PyObject_SetAttrString(result
, "orelse", value
) == -1)
2442 case TryFinally_kind
:
2443 result
= PyType_GenericNew(TryFinally_type
, NULL
, NULL
);
2444 if (!result
) goto failed
;
2445 value
= ast2obj_list(o
->v
.TryFinally
.body
, ast2obj_stmt
);
2446 if (!value
) goto failed
;
2447 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2450 value
= ast2obj_list(o
->v
.TryFinally
.finalbody
, ast2obj_stmt
);
2451 if (!value
) goto failed
;
2452 if (PyObject_SetAttrString(result
, "finalbody", value
) == -1)
2457 result
= PyType_GenericNew(Assert_type
, NULL
, NULL
);
2458 if (!result
) goto failed
;
2459 value
= ast2obj_expr(o
->v
.Assert
.test
);
2460 if (!value
) goto failed
;
2461 if (PyObject_SetAttrString(result
, "test", value
) == -1)
2464 value
= ast2obj_expr(o
->v
.Assert
.msg
);
2465 if (!value
) goto failed
;
2466 if (PyObject_SetAttrString(result
, "msg", value
) == -1)
2471 result
= PyType_GenericNew(Import_type
, NULL
, NULL
);
2472 if (!result
) goto failed
;
2473 value
= ast2obj_list(o
->v
.Import
.names
, ast2obj_alias
);
2474 if (!value
) goto failed
;
2475 if (PyObject_SetAttrString(result
, "names", value
) == -1)
2479 case ImportFrom_kind
:
2480 result
= PyType_GenericNew(ImportFrom_type
, NULL
, NULL
);
2481 if (!result
) goto failed
;
2482 value
= ast2obj_identifier(o
->v
.ImportFrom
.module
);
2483 if (!value
) goto failed
;
2484 if (PyObject_SetAttrString(result
, "module", value
) == -1)
2487 value
= ast2obj_list(o
->v
.ImportFrom
.names
, ast2obj_alias
);
2488 if (!value
) goto failed
;
2489 if (PyObject_SetAttrString(result
, "names", value
) == -1)
2492 value
= ast2obj_int(o
->v
.ImportFrom
.level
);
2493 if (!value
) goto failed
;
2494 if (PyObject_SetAttrString(result
, "level", value
) == -1)
2499 result
= PyType_GenericNew(Exec_type
, NULL
, NULL
);
2500 if (!result
) goto failed
;
2501 value
= ast2obj_expr(o
->v
.Exec
.body
);
2502 if (!value
) goto failed
;
2503 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2506 value
= ast2obj_expr(o
->v
.Exec
.globals
);
2507 if (!value
) goto failed
;
2508 if (PyObject_SetAttrString(result
, "globals", value
) == -1)
2511 value
= ast2obj_expr(o
->v
.Exec
.locals
);
2512 if (!value
) goto failed
;
2513 if (PyObject_SetAttrString(result
, "locals", value
) == -1)
2518 result
= PyType_GenericNew(Global_type
, NULL
, NULL
);
2519 if (!result
) goto failed
;
2520 value
= ast2obj_list(o
->v
.Global
.names
, ast2obj_identifier
);
2521 if (!value
) goto failed
;
2522 if (PyObject_SetAttrString(result
, "names", value
) == -1)
2527 result
= PyType_GenericNew(Expr_type
, NULL
, NULL
);
2528 if (!result
) goto failed
;
2529 value
= ast2obj_expr(o
->v
.Expr
.value
);
2530 if (!value
) goto failed
;
2531 if (PyObject_SetAttrString(result
, "value", value
) == -1)
2536 result
= PyType_GenericNew(Pass_type
, NULL
, NULL
);
2537 if (!result
) goto failed
;
2540 result
= PyType_GenericNew(Break_type
, NULL
, NULL
);
2541 if (!result
) goto failed
;
2544 result
= PyType_GenericNew(Continue_type
, NULL
, NULL
);
2545 if (!result
) goto failed
;
2548 value
= ast2obj_int(o
->lineno
);
2549 if (!value
) goto failed
;
2550 if (PyObject_SetAttrString(result
, "lineno", value
) < 0)
2553 value
= ast2obj_int(o
->col_offset
);
2554 if (!value
) goto failed
;
2555 if (PyObject_SetAttrString(result
, "col_offset", value
) < 0)
2566 ast2obj_expr(void* _o
)
2568 expr_ty o
= (expr_ty
)_o
;
2569 PyObject
*result
= NULL
, *value
= NULL
;
2577 result
= PyType_GenericNew(BoolOp_type
, NULL
, NULL
);
2578 if (!result
) goto failed
;
2579 value
= ast2obj_boolop(o
->v
.BoolOp
.op
);
2580 if (!value
) goto failed
;
2581 if (PyObject_SetAttrString(result
, "op", value
) == -1)
2584 value
= ast2obj_list(o
->v
.BoolOp
.values
, ast2obj_expr
);
2585 if (!value
) goto failed
;
2586 if (PyObject_SetAttrString(result
, "values", value
) == -1)
2591 result
= PyType_GenericNew(BinOp_type
, NULL
, NULL
);
2592 if (!result
) goto failed
;
2593 value
= ast2obj_expr(o
->v
.BinOp
.left
);
2594 if (!value
) goto failed
;
2595 if (PyObject_SetAttrString(result
, "left", value
) == -1)
2598 value
= ast2obj_operator(o
->v
.BinOp
.op
);
2599 if (!value
) goto failed
;
2600 if (PyObject_SetAttrString(result
, "op", value
) == -1)
2603 value
= ast2obj_expr(o
->v
.BinOp
.right
);
2604 if (!value
) goto failed
;
2605 if (PyObject_SetAttrString(result
, "right", value
) == -1)
2610 result
= PyType_GenericNew(UnaryOp_type
, NULL
, NULL
);
2611 if (!result
) goto failed
;
2612 value
= ast2obj_unaryop(o
->v
.UnaryOp
.op
);
2613 if (!value
) goto failed
;
2614 if (PyObject_SetAttrString(result
, "op", value
) == -1)
2617 value
= ast2obj_expr(o
->v
.UnaryOp
.operand
);
2618 if (!value
) goto failed
;
2619 if (PyObject_SetAttrString(result
, "operand", value
) == -1)
2624 result
= PyType_GenericNew(Lambda_type
, NULL
, NULL
);
2625 if (!result
) goto failed
;
2626 value
= ast2obj_arguments(o
->v
.Lambda
.args
);
2627 if (!value
) goto failed
;
2628 if (PyObject_SetAttrString(result
, "args", value
) == -1)
2631 value
= ast2obj_expr(o
->v
.Lambda
.body
);
2632 if (!value
) goto failed
;
2633 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2638 result
= PyType_GenericNew(IfExp_type
, NULL
, NULL
);
2639 if (!result
) goto failed
;
2640 value
= ast2obj_expr(o
->v
.IfExp
.test
);
2641 if (!value
) goto failed
;
2642 if (PyObject_SetAttrString(result
, "test", value
) == -1)
2645 value
= ast2obj_expr(o
->v
.IfExp
.body
);
2646 if (!value
) goto failed
;
2647 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2650 value
= ast2obj_expr(o
->v
.IfExp
.orelse
);
2651 if (!value
) goto failed
;
2652 if (PyObject_SetAttrString(result
, "orelse", value
) == -1)
2657 result
= PyType_GenericNew(Dict_type
, NULL
, NULL
);
2658 if (!result
) goto failed
;
2659 value
= ast2obj_list(o
->v
.Dict
.keys
, ast2obj_expr
);
2660 if (!value
) goto failed
;
2661 if (PyObject_SetAttrString(result
, "keys", value
) == -1)
2664 value
= ast2obj_list(o
->v
.Dict
.values
, ast2obj_expr
);
2665 if (!value
) goto failed
;
2666 if (PyObject_SetAttrString(result
, "values", value
) == -1)
2671 result
= PyType_GenericNew(Set_type
, NULL
, NULL
);
2672 if (!result
) goto failed
;
2673 value
= ast2obj_list(o
->v
.Set
.elts
, ast2obj_expr
);
2674 if (!value
) goto failed
;
2675 if (PyObject_SetAttrString(result
, "elts", value
) == -1)
2680 result
= PyType_GenericNew(ListComp_type
, NULL
, NULL
);
2681 if (!result
) goto failed
;
2682 value
= ast2obj_expr(o
->v
.ListComp
.elt
);
2683 if (!value
) goto failed
;
2684 if (PyObject_SetAttrString(result
, "elt", value
) == -1)
2687 value
= ast2obj_list(o
->v
.ListComp
.generators
,
2688 ast2obj_comprehension
);
2689 if (!value
) goto failed
;
2690 if (PyObject_SetAttrString(result
, "generators", value
) == -1)
2695 result
= PyType_GenericNew(SetComp_type
, NULL
, NULL
);
2696 if (!result
) goto failed
;
2697 value
= ast2obj_expr(o
->v
.SetComp
.elt
);
2698 if (!value
) goto failed
;
2699 if (PyObject_SetAttrString(result
, "elt", value
) == -1)
2702 value
= ast2obj_list(o
->v
.SetComp
.generators
,
2703 ast2obj_comprehension
);
2704 if (!value
) goto failed
;
2705 if (PyObject_SetAttrString(result
, "generators", value
) == -1)
2710 result
= PyType_GenericNew(DictComp_type
, NULL
, NULL
);
2711 if (!result
) goto failed
;
2712 value
= ast2obj_expr(o
->v
.DictComp
.key
);
2713 if (!value
) goto failed
;
2714 if (PyObject_SetAttrString(result
, "key", value
) == -1)
2717 value
= ast2obj_expr(o
->v
.DictComp
.value
);
2718 if (!value
) goto failed
;
2719 if (PyObject_SetAttrString(result
, "value", value
) == -1)
2722 value
= ast2obj_list(o
->v
.DictComp
.generators
,
2723 ast2obj_comprehension
);
2724 if (!value
) goto failed
;
2725 if (PyObject_SetAttrString(result
, "generators", value
) == -1)
2729 case GeneratorExp_kind
:
2730 result
= PyType_GenericNew(GeneratorExp_type
, NULL
, NULL
);
2731 if (!result
) goto failed
;
2732 value
= ast2obj_expr(o
->v
.GeneratorExp
.elt
);
2733 if (!value
) goto failed
;
2734 if (PyObject_SetAttrString(result
, "elt", value
) == -1)
2737 value
= ast2obj_list(o
->v
.GeneratorExp
.generators
,
2738 ast2obj_comprehension
);
2739 if (!value
) goto failed
;
2740 if (PyObject_SetAttrString(result
, "generators", value
) == -1)
2745 result
= PyType_GenericNew(Yield_type
, NULL
, NULL
);
2746 if (!result
) goto failed
;
2747 value
= ast2obj_expr(o
->v
.Yield
.value
);
2748 if (!value
) goto failed
;
2749 if (PyObject_SetAttrString(result
, "value", value
) == -1)
2754 result
= PyType_GenericNew(Compare_type
, NULL
, NULL
);
2755 if (!result
) goto failed
;
2756 value
= ast2obj_expr(o
->v
.Compare
.left
);
2757 if (!value
) goto failed
;
2758 if (PyObject_SetAttrString(result
, "left", value
) == -1)
2762 int i
, n
= asdl_seq_LEN(o
->v
.Compare
.ops
);
2763 value
= PyList_New(n
);
2764 if (!value
) goto failed
;
2765 for(i
= 0; i
< n
; i
++)
2766 PyList_SET_ITEM(value
, i
, ast2obj_cmpop((cmpop_ty
)asdl_seq_GET(o
->v
.Compare
.ops
, i
)));
2768 if (!value
) goto failed
;
2769 if (PyObject_SetAttrString(result
, "ops", value
) == -1)
2772 value
= ast2obj_list(o
->v
.Compare
.comparators
, ast2obj_expr
);
2773 if (!value
) goto failed
;
2774 if (PyObject_SetAttrString(result
, "comparators", value
) == -1)
2779 result
= PyType_GenericNew(Call_type
, NULL
, NULL
);
2780 if (!result
) goto failed
;
2781 value
= ast2obj_expr(o
->v
.Call
.func
);
2782 if (!value
) goto failed
;
2783 if (PyObject_SetAttrString(result
, "func", value
) == -1)
2786 value
= ast2obj_list(o
->v
.Call
.args
, ast2obj_expr
);
2787 if (!value
) goto failed
;
2788 if (PyObject_SetAttrString(result
, "args", value
) == -1)
2791 value
= ast2obj_list(o
->v
.Call
.keywords
, ast2obj_keyword
);
2792 if (!value
) goto failed
;
2793 if (PyObject_SetAttrString(result
, "keywords", value
) == -1)
2796 value
= ast2obj_expr(o
->v
.Call
.starargs
);
2797 if (!value
) goto failed
;
2798 if (PyObject_SetAttrString(result
, "starargs", value
) == -1)
2801 value
= ast2obj_expr(o
->v
.Call
.kwargs
);
2802 if (!value
) goto failed
;
2803 if (PyObject_SetAttrString(result
, "kwargs", value
) == -1)
2808 result
= PyType_GenericNew(Repr_type
, NULL
, NULL
);
2809 if (!result
) goto failed
;
2810 value
= ast2obj_expr(o
->v
.Repr
.value
);
2811 if (!value
) goto failed
;
2812 if (PyObject_SetAttrString(result
, "value", value
) == -1)
2817 result
= PyType_GenericNew(Num_type
, NULL
, NULL
);
2818 if (!result
) goto failed
;
2819 value
= ast2obj_object(o
->v
.Num
.n
);
2820 if (!value
) goto failed
;
2821 if (PyObject_SetAttrString(result
, "n", value
) == -1)
2826 result
= PyType_GenericNew(Str_type
, NULL
, NULL
);
2827 if (!result
) goto failed
;
2828 value
= ast2obj_string(o
->v
.Str
.s
);
2829 if (!value
) goto failed
;
2830 if (PyObject_SetAttrString(result
, "s", value
) == -1)
2834 case Attribute_kind
:
2835 result
= PyType_GenericNew(Attribute_type
, NULL
, NULL
);
2836 if (!result
) goto failed
;
2837 value
= ast2obj_expr(o
->v
.Attribute
.value
);
2838 if (!value
) goto failed
;
2839 if (PyObject_SetAttrString(result
, "value", value
) == -1)
2842 value
= ast2obj_identifier(o
->v
.Attribute
.attr
);
2843 if (!value
) goto failed
;
2844 if (PyObject_SetAttrString(result
, "attr", value
) == -1)
2847 value
= ast2obj_expr_context(o
->v
.Attribute
.ctx
);
2848 if (!value
) goto failed
;
2849 if (PyObject_SetAttrString(result
, "ctx", value
) == -1)
2853 case Subscript_kind
:
2854 result
= PyType_GenericNew(Subscript_type
, NULL
, NULL
);
2855 if (!result
) goto failed
;
2856 value
= ast2obj_expr(o
->v
.Subscript
.value
);
2857 if (!value
) goto failed
;
2858 if (PyObject_SetAttrString(result
, "value", value
) == -1)
2861 value
= ast2obj_slice(o
->v
.Subscript
.slice
);
2862 if (!value
) goto failed
;
2863 if (PyObject_SetAttrString(result
, "slice", value
) == -1)
2866 value
= ast2obj_expr_context(o
->v
.Subscript
.ctx
);
2867 if (!value
) goto failed
;
2868 if (PyObject_SetAttrString(result
, "ctx", value
) == -1)
2873 result
= PyType_GenericNew(Name_type
, NULL
, NULL
);
2874 if (!result
) goto failed
;
2875 value
= ast2obj_identifier(o
->v
.Name
.id
);
2876 if (!value
) goto failed
;
2877 if (PyObject_SetAttrString(result
, "id", value
) == -1)
2880 value
= ast2obj_expr_context(o
->v
.Name
.ctx
);
2881 if (!value
) goto failed
;
2882 if (PyObject_SetAttrString(result
, "ctx", value
) == -1)
2887 result
= PyType_GenericNew(List_type
, NULL
, NULL
);
2888 if (!result
) goto failed
;
2889 value
= ast2obj_list(o
->v
.List
.elts
, ast2obj_expr
);
2890 if (!value
) goto failed
;
2891 if (PyObject_SetAttrString(result
, "elts", value
) == -1)
2894 value
= ast2obj_expr_context(o
->v
.List
.ctx
);
2895 if (!value
) goto failed
;
2896 if (PyObject_SetAttrString(result
, "ctx", value
) == -1)
2901 result
= PyType_GenericNew(Tuple_type
, NULL
, NULL
);
2902 if (!result
) goto failed
;
2903 value
= ast2obj_list(o
->v
.Tuple
.elts
, ast2obj_expr
);
2904 if (!value
) goto failed
;
2905 if (PyObject_SetAttrString(result
, "elts", value
) == -1)
2908 value
= ast2obj_expr_context(o
->v
.Tuple
.ctx
);
2909 if (!value
) goto failed
;
2910 if (PyObject_SetAttrString(result
, "ctx", value
) == -1)
2915 value
= ast2obj_int(o
->lineno
);
2916 if (!value
) goto failed
;
2917 if (PyObject_SetAttrString(result
, "lineno", value
) < 0)
2920 value
= ast2obj_int(o
->col_offset
);
2921 if (!value
) goto failed
;
2922 if (PyObject_SetAttrString(result
, "col_offset", value
) < 0)
2932 PyObject
* ast2obj_expr_context(expr_context_ty o
)
2936 Py_INCREF(Load_singleton
);
2937 return Load_singleton
;
2939 Py_INCREF(Store_singleton
);
2940 return Store_singleton
;
2942 Py_INCREF(Del_singleton
);
2943 return Del_singleton
;
2945 Py_INCREF(AugLoad_singleton
);
2946 return AugLoad_singleton
;
2948 Py_INCREF(AugStore_singleton
);
2949 return AugStore_singleton
;
2951 Py_INCREF(Param_singleton
);
2952 return Param_singleton
;
2954 /* should never happen, but just in case ... */
2955 PyErr_Format(PyExc_SystemError
, "unknown expr_context found");
2960 ast2obj_slice(void* _o
)
2962 slice_ty o
= (slice_ty
)_o
;
2963 PyObject
*result
= NULL
, *value
= NULL
;
2971 result
= PyType_GenericNew(Ellipsis_type
, NULL
, NULL
);
2972 if (!result
) goto failed
;
2975 result
= PyType_GenericNew(Slice_type
, NULL
, NULL
);
2976 if (!result
) goto failed
;
2977 value
= ast2obj_expr(o
->v
.Slice
.lower
);
2978 if (!value
) goto failed
;
2979 if (PyObject_SetAttrString(result
, "lower", value
) == -1)
2982 value
= ast2obj_expr(o
->v
.Slice
.upper
);
2983 if (!value
) goto failed
;
2984 if (PyObject_SetAttrString(result
, "upper", value
) == -1)
2987 value
= ast2obj_expr(o
->v
.Slice
.step
);
2988 if (!value
) goto failed
;
2989 if (PyObject_SetAttrString(result
, "step", value
) == -1)
2994 result
= PyType_GenericNew(ExtSlice_type
, NULL
, NULL
);
2995 if (!result
) goto failed
;
2996 value
= ast2obj_list(o
->v
.ExtSlice
.dims
, ast2obj_slice
);
2997 if (!value
) goto failed
;
2998 if (PyObject_SetAttrString(result
, "dims", value
) == -1)
3003 result
= PyType_GenericNew(Index_type
, NULL
, NULL
);
3004 if (!result
) goto failed
;
3005 value
= ast2obj_expr(o
->v
.Index
.value
);
3006 if (!value
) goto failed
;
3007 if (PyObject_SetAttrString(result
, "value", value
) == -1)
3019 PyObject
* ast2obj_boolop(boolop_ty o
)
3023 Py_INCREF(And_singleton
);
3024 return And_singleton
;
3026 Py_INCREF(Or_singleton
);
3027 return Or_singleton
;
3029 /* should never happen, but just in case ... */
3030 PyErr_Format(PyExc_SystemError
, "unknown boolop found");
3034 PyObject
* ast2obj_operator(operator_ty o
)
3038 Py_INCREF(Add_singleton
);
3039 return Add_singleton
;
3041 Py_INCREF(Sub_singleton
);
3042 return Sub_singleton
;
3044 Py_INCREF(Mult_singleton
);
3045 return Mult_singleton
;
3047 Py_INCREF(Div_singleton
);
3048 return Div_singleton
;
3050 Py_INCREF(Mod_singleton
);
3051 return Mod_singleton
;
3053 Py_INCREF(Pow_singleton
);
3054 return Pow_singleton
;
3056 Py_INCREF(LShift_singleton
);
3057 return LShift_singleton
;
3059 Py_INCREF(RShift_singleton
);
3060 return RShift_singleton
;
3062 Py_INCREF(BitOr_singleton
);
3063 return BitOr_singleton
;
3065 Py_INCREF(BitXor_singleton
);
3066 return BitXor_singleton
;
3068 Py_INCREF(BitAnd_singleton
);
3069 return BitAnd_singleton
;
3071 Py_INCREF(FloorDiv_singleton
);
3072 return FloorDiv_singleton
;
3074 /* should never happen, but just in case ... */
3075 PyErr_Format(PyExc_SystemError
, "unknown operator found");
3079 PyObject
* ast2obj_unaryop(unaryop_ty o
)
3083 Py_INCREF(Invert_singleton
);
3084 return Invert_singleton
;
3086 Py_INCREF(Not_singleton
);
3087 return Not_singleton
;
3089 Py_INCREF(UAdd_singleton
);
3090 return UAdd_singleton
;
3092 Py_INCREF(USub_singleton
);
3093 return USub_singleton
;
3095 /* should never happen, but just in case ... */
3096 PyErr_Format(PyExc_SystemError
, "unknown unaryop found");
3100 PyObject
* ast2obj_cmpop(cmpop_ty o
)
3104 Py_INCREF(Eq_singleton
);
3105 return Eq_singleton
;
3107 Py_INCREF(NotEq_singleton
);
3108 return NotEq_singleton
;
3110 Py_INCREF(Lt_singleton
);
3111 return Lt_singleton
;
3113 Py_INCREF(LtE_singleton
);
3114 return LtE_singleton
;
3116 Py_INCREF(Gt_singleton
);
3117 return Gt_singleton
;
3119 Py_INCREF(GtE_singleton
);
3120 return GtE_singleton
;
3122 Py_INCREF(Is_singleton
);
3123 return Is_singleton
;
3125 Py_INCREF(IsNot_singleton
);
3126 return IsNot_singleton
;
3128 Py_INCREF(In_singleton
);
3129 return In_singleton
;
3131 Py_INCREF(NotIn_singleton
);
3132 return NotIn_singleton
;
3134 /* should never happen, but just in case ... */
3135 PyErr_Format(PyExc_SystemError
, "unknown cmpop found");
3140 ast2obj_comprehension(void* _o
)
3142 comprehension_ty o
= (comprehension_ty
)_o
;
3143 PyObject
*result
= NULL
, *value
= NULL
;
3149 result
= PyType_GenericNew(comprehension_type
, NULL
, NULL
);
3150 if (!result
) return NULL
;
3151 value
= ast2obj_expr(o
->target
);
3152 if (!value
) goto failed
;
3153 if (PyObject_SetAttrString(result
, "target", value
) == -1)
3156 value
= ast2obj_expr(o
->iter
);
3157 if (!value
) goto failed
;
3158 if (PyObject_SetAttrString(result
, "iter", value
) == -1)
3161 value
= ast2obj_list(o
->ifs
, ast2obj_expr
);
3162 if (!value
) goto failed
;
3163 if (PyObject_SetAttrString(result
, "ifs", value
) == -1)
3174 ast2obj_excepthandler(void* _o
)
3176 excepthandler_ty o
= (excepthandler_ty
)_o
;
3177 PyObject
*result
= NULL
, *value
= NULL
;
3184 case ExceptHandler_kind
:
3185 result
= PyType_GenericNew(ExceptHandler_type
, NULL
, NULL
);
3186 if (!result
) goto failed
;
3187 value
= ast2obj_expr(o
->v
.ExceptHandler
.type
);
3188 if (!value
) goto failed
;
3189 if (PyObject_SetAttrString(result
, "type", value
) == -1)
3192 value
= ast2obj_expr(o
->v
.ExceptHandler
.name
);
3193 if (!value
) goto failed
;
3194 if (PyObject_SetAttrString(result
, "name", value
) == -1)
3197 value
= ast2obj_list(o
->v
.ExceptHandler
.body
, ast2obj_stmt
);
3198 if (!value
) goto failed
;
3199 if (PyObject_SetAttrString(result
, "body", value
) == -1)
3204 value
= ast2obj_int(o
->lineno
);
3205 if (!value
) goto failed
;
3206 if (PyObject_SetAttrString(result
, "lineno", value
) < 0)
3209 value
= ast2obj_int(o
->col_offset
);
3210 if (!value
) goto failed
;
3211 if (PyObject_SetAttrString(result
, "col_offset", value
) < 0)
3222 ast2obj_arguments(void* _o
)
3224 arguments_ty o
= (arguments_ty
)_o
;
3225 PyObject
*result
= NULL
, *value
= NULL
;
3231 result
= PyType_GenericNew(arguments_type
, NULL
, NULL
);
3232 if (!result
) return NULL
;
3233 value
= ast2obj_list(o
->args
, ast2obj_expr
);
3234 if (!value
) goto failed
;
3235 if (PyObject_SetAttrString(result
, "args", value
) == -1)
3238 value
= ast2obj_identifier(o
->vararg
);
3239 if (!value
) goto failed
;
3240 if (PyObject_SetAttrString(result
, "vararg", value
) == -1)
3243 value
= ast2obj_identifier(o
->kwarg
);
3244 if (!value
) goto failed
;
3245 if (PyObject_SetAttrString(result
, "kwarg", value
) == -1)
3248 value
= ast2obj_list(o
->defaults
, ast2obj_expr
);
3249 if (!value
) goto failed
;
3250 if (PyObject_SetAttrString(result
, "defaults", value
) == -1)
3261 ast2obj_keyword(void* _o
)
3263 keyword_ty o
= (keyword_ty
)_o
;
3264 PyObject
*result
= NULL
, *value
= NULL
;
3270 result
= PyType_GenericNew(keyword_type
, NULL
, NULL
);
3271 if (!result
) return NULL
;
3272 value
= ast2obj_identifier(o
->arg
);
3273 if (!value
) goto failed
;
3274 if (PyObject_SetAttrString(result
, "arg", value
) == -1)
3277 value
= ast2obj_expr(o
->value
);
3278 if (!value
) goto failed
;
3279 if (PyObject_SetAttrString(result
, "value", value
) == -1)
3290 ast2obj_alias(void* _o
)
3292 alias_ty o
= (alias_ty
)_o
;
3293 PyObject
*result
= NULL
, *value
= NULL
;
3299 result
= PyType_GenericNew(alias_type
, NULL
, NULL
);
3300 if (!result
) return NULL
;
3301 value
= ast2obj_identifier(o
->name
);
3302 if (!value
) goto failed
;
3303 if (PyObject_SetAttrString(result
, "name", value
) == -1)
3306 value
= ast2obj_identifier(o
->asname
);
3307 if (!value
) goto failed
;
3308 if (PyObject_SetAttrString(result
, "asname", value
) == -1)
3320 obj2ast_mod(PyObject
* obj
, mod_ty
* out
, PyArena
* arena
)
3322 PyObject
* tmp
= NULL
;
3326 if (obj
== Py_None
) {
3330 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Module_type
);
3331 if (isinstance
== -1) {
3337 if (PyObject_HasAttrString(obj
, "body")) {
3341 tmp
= PyObject_GetAttrString(obj
, "body");
3342 if (tmp
== NULL
) goto failed
;
3343 if (!PyList_Check(tmp
)) {
3344 PyErr_Format(PyExc_TypeError
, "Module field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3347 len
= PyList_GET_SIZE(tmp
);
3348 body
= asdl_seq_new(len
, arena
);
3349 if (body
== NULL
) goto failed
;
3350 for (i
= 0; i
< len
; i
++) {
3352 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3353 if (res
!= 0) goto failed
;
3354 asdl_seq_SET(body
, i
, value
);
3359 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from Module");
3362 *out
= Module(body
, arena
);
3363 if (*out
== NULL
) goto failed
;
3366 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Interactive_type
);
3367 if (isinstance
== -1) {
3373 if (PyObject_HasAttrString(obj
, "body")) {
3377 tmp
= PyObject_GetAttrString(obj
, "body");
3378 if (tmp
== NULL
) goto failed
;
3379 if (!PyList_Check(tmp
)) {
3380 PyErr_Format(PyExc_TypeError
, "Interactive field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3383 len
= PyList_GET_SIZE(tmp
);
3384 body
= asdl_seq_new(len
, arena
);
3385 if (body
== NULL
) goto failed
;
3386 for (i
= 0; i
< len
; i
++) {
3388 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3389 if (res
!= 0) goto failed
;
3390 asdl_seq_SET(body
, i
, value
);
3395 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from Interactive");
3398 *out
= Interactive(body
, arena
);
3399 if (*out
== NULL
) goto failed
;
3402 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Expression_type
);
3403 if (isinstance
== -1) {
3409 if (PyObject_HasAttrString(obj
, "body")) {
3411 tmp
= PyObject_GetAttrString(obj
, "body");
3412 if (tmp
== NULL
) goto failed
;
3413 res
= obj2ast_expr(tmp
, &body
, arena
);
3414 if (res
!= 0) goto failed
;
3418 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from Expression");
3421 *out
= Expression(body
, arena
);
3422 if (*out
== NULL
) goto failed
;
3425 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Suite_type
);
3426 if (isinstance
== -1) {
3432 if (PyObject_HasAttrString(obj
, "body")) {
3436 tmp
= PyObject_GetAttrString(obj
, "body");
3437 if (tmp
== NULL
) goto failed
;
3438 if (!PyList_Check(tmp
)) {
3439 PyErr_Format(PyExc_TypeError
, "Suite field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3442 len
= PyList_GET_SIZE(tmp
);
3443 body
= asdl_seq_new(len
, arena
);
3444 if (body
== NULL
) goto failed
;
3445 for (i
= 0; i
< len
; i
++) {
3447 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3448 if (res
!= 0) goto failed
;
3449 asdl_seq_SET(body
, i
, value
);
3454 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from Suite");
3457 *out
= Suite(body
, arena
);
3458 if (*out
== NULL
) goto failed
;
3462 tmp
= PyObject_Repr(obj
);
3463 if (tmp
== NULL
) goto failed
;
3464 PyErr_Format(PyExc_TypeError
, "expected some sort of mod, but got %.400s", PyString_AS_STRING(tmp
));
3471 obj2ast_stmt(PyObject
* obj
, stmt_ty
* out
, PyArena
* arena
)
3473 PyObject
* tmp
= NULL
;
3479 if (obj
== Py_None
) {
3483 if (PyObject_HasAttrString(obj
, "lineno")) {
3485 tmp
= PyObject_GetAttrString(obj
, "lineno");
3486 if (tmp
== NULL
) goto failed
;
3487 res
= obj2ast_int(tmp
, &lineno
, arena
);
3488 if (res
!= 0) goto failed
;
3492 PyErr_SetString(PyExc_TypeError
, "required field \"lineno\" missing from stmt");
3495 if (PyObject_HasAttrString(obj
, "col_offset")) {
3497 tmp
= PyObject_GetAttrString(obj
, "col_offset");
3498 if (tmp
== NULL
) goto failed
;
3499 res
= obj2ast_int(tmp
, &col_offset
, arena
);
3500 if (res
!= 0) goto failed
;
3504 PyErr_SetString(PyExc_TypeError
, "required field \"col_offset\" missing from stmt");
3507 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)FunctionDef_type
);
3508 if (isinstance
== -1) {
3515 asdl_seq
* decorator_list
;
3517 if (PyObject_HasAttrString(obj
, "name")) {
3519 tmp
= PyObject_GetAttrString(obj
, "name");
3520 if (tmp
== NULL
) goto failed
;
3521 res
= obj2ast_identifier(tmp
, &name
, arena
);
3522 if (res
!= 0) goto failed
;
3526 PyErr_SetString(PyExc_TypeError
, "required field \"name\" missing from FunctionDef");
3529 if (PyObject_HasAttrString(obj
, "args")) {
3531 tmp
= PyObject_GetAttrString(obj
, "args");
3532 if (tmp
== NULL
) goto failed
;
3533 res
= obj2ast_arguments(tmp
, &args
, arena
);
3534 if (res
!= 0) goto failed
;
3538 PyErr_SetString(PyExc_TypeError
, "required field \"args\" missing from FunctionDef");
3541 if (PyObject_HasAttrString(obj
, "body")) {
3545 tmp
= PyObject_GetAttrString(obj
, "body");
3546 if (tmp
== NULL
) goto failed
;
3547 if (!PyList_Check(tmp
)) {
3548 PyErr_Format(PyExc_TypeError
, "FunctionDef field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3551 len
= PyList_GET_SIZE(tmp
);
3552 body
= asdl_seq_new(len
, arena
);
3553 if (body
== NULL
) goto failed
;
3554 for (i
= 0; i
< len
; i
++) {
3556 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3557 if (res
!= 0) goto failed
;
3558 asdl_seq_SET(body
, i
, value
);
3563 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from FunctionDef");
3566 if (PyObject_HasAttrString(obj
, "decorator_list")) {
3570 tmp
= PyObject_GetAttrString(obj
, "decorator_list");
3571 if (tmp
== NULL
) goto failed
;
3572 if (!PyList_Check(tmp
)) {
3573 PyErr_Format(PyExc_TypeError
, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3576 len
= PyList_GET_SIZE(tmp
);
3577 decorator_list
= asdl_seq_new(len
, arena
);
3578 if (decorator_list
== NULL
) goto failed
;
3579 for (i
= 0; i
< len
; i
++) {
3581 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3582 if (res
!= 0) goto failed
;
3583 asdl_seq_SET(decorator_list
, i
, value
);
3588 PyErr_SetString(PyExc_TypeError
, "required field \"decorator_list\" missing from FunctionDef");
3591 *out
= FunctionDef(name
, args
, body
, decorator_list
, lineno
,
3593 if (*out
== NULL
) goto failed
;
3596 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)ClassDef_type
);
3597 if (isinstance
== -1) {
3604 asdl_seq
* decorator_list
;
3606 if (PyObject_HasAttrString(obj
, "name")) {
3608 tmp
= PyObject_GetAttrString(obj
, "name");
3609 if (tmp
== NULL
) goto failed
;
3610 res
= obj2ast_identifier(tmp
, &name
, arena
);
3611 if (res
!= 0) goto failed
;
3615 PyErr_SetString(PyExc_TypeError
, "required field \"name\" missing from ClassDef");
3618 if (PyObject_HasAttrString(obj
, "bases")) {
3622 tmp
= PyObject_GetAttrString(obj
, "bases");
3623 if (tmp
== NULL
) goto failed
;
3624 if (!PyList_Check(tmp
)) {
3625 PyErr_Format(PyExc_TypeError
, "ClassDef field \"bases\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3628 len
= PyList_GET_SIZE(tmp
);
3629 bases
= asdl_seq_new(len
, arena
);
3630 if (bases
== NULL
) goto failed
;
3631 for (i
= 0; i
< len
; i
++) {
3633 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3634 if (res
!= 0) goto failed
;
3635 asdl_seq_SET(bases
, i
, value
);
3640 PyErr_SetString(PyExc_TypeError
, "required field \"bases\" missing from ClassDef");
3643 if (PyObject_HasAttrString(obj
, "body")) {
3647 tmp
= PyObject_GetAttrString(obj
, "body");
3648 if (tmp
== NULL
) goto failed
;
3649 if (!PyList_Check(tmp
)) {
3650 PyErr_Format(PyExc_TypeError
, "ClassDef field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3653 len
= PyList_GET_SIZE(tmp
);
3654 body
= asdl_seq_new(len
, arena
);
3655 if (body
== NULL
) goto failed
;
3656 for (i
= 0; i
< len
; i
++) {
3658 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3659 if (res
!= 0) goto failed
;
3660 asdl_seq_SET(body
, i
, value
);
3665 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from ClassDef");
3668 if (PyObject_HasAttrString(obj
, "decorator_list")) {
3672 tmp
= PyObject_GetAttrString(obj
, "decorator_list");
3673 if (tmp
== NULL
) goto failed
;
3674 if (!PyList_Check(tmp
)) {
3675 PyErr_Format(PyExc_TypeError
, "ClassDef field \"decorator_list\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3678 len
= PyList_GET_SIZE(tmp
);
3679 decorator_list
= asdl_seq_new(len
, arena
);
3680 if (decorator_list
== NULL
) goto failed
;
3681 for (i
= 0; i
< len
; i
++) {
3683 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3684 if (res
!= 0) goto failed
;
3685 asdl_seq_SET(decorator_list
, i
, value
);
3690 PyErr_SetString(PyExc_TypeError
, "required field \"decorator_list\" missing from ClassDef");
3693 *out
= ClassDef(name
, bases
, body
, decorator_list
, lineno
,
3695 if (*out
== NULL
) goto failed
;
3698 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Return_type
);
3699 if (isinstance
== -1) {
3705 if (PyObject_HasAttrString(obj
, "value")) {
3707 tmp
= PyObject_GetAttrString(obj
, "value");
3708 if (tmp
== NULL
) goto failed
;
3709 res
= obj2ast_expr(tmp
, &value
, arena
);
3710 if (res
!= 0) goto failed
;
3716 *out
= Return(value
, lineno
, col_offset
, arena
);
3717 if (*out
== NULL
) goto failed
;
3720 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Delete_type
);
3721 if (isinstance
== -1) {
3727 if (PyObject_HasAttrString(obj
, "targets")) {
3731 tmp
= PyObject_GetAttrString(obj
, "targets");
3732 if (tmp
== NULL
) goto failed
;
3733 if (!PyList_Check(tmp
)) {
3734 PyErr_Format(PyExc_TypeError
, "Delete field \"targets\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3737 len
= PyList_GET_SIZE(tmp
);
3738 targets
= asdl_seq_new(len
, arena
);
3739 if (targets
== NULL
) goto failed
;
3740 for (i
= 0; i
< len
; i
++) {
3742 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3743 if (res
!= 0) goto failed
;
3744 asdl_seq_SET(targets
, i
, value
);
3749 PyErr_SetString(PyExc_TypeError
, "required field \"targets\" missing from Delete");
3752 *out
= Delete(targets
, lineno
, col_offset
, arena
);
3753 if (*out
== NULL
) goto failed
;
3756 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Assign_type
);
3757 if (isinstance
== -1) {
3764 if (PyObject_HasAttrString(obj
, "targets")) {
3768 tmp
= PyObject_GetAttrString(obj
, "targets");
3769 if (tmp
== NULL
) goto failed
;
3770 if (!PyList_Check(tmp
)) {
3771 PyErr_Format(PyExc_TypeError
, "Assign field \"targets\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3774 len
= PyList_GET_SIZE(tmp
);
3775 targets
= asdl_seq_new(len
, arena
);
3776 if (targets
== NULL
) goto failed
;
3777 for (i
= 0; i
< len
; i
++) {
3779 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3780 if (res
!= 0) goto failed
;
3781 asdl_seq_SET(targets
, i
, value
);
3786 PyErr_SetString(PyExc_TypeError
, "required field \"targets\" missing from Assign");
3789 if (PyObject_HasAttrString(obj
, "value")) {
3791 tmp
= PyObject_GetAttrString(obj
, "value");
3792 if (tmp
== NULL
) goto failed
;
3793 res
= obj2ast_expr(tmp
, &value
, arena
);
3794 if (res
!= 0) goto failed
;
3798 PyErr_SetString(PyExc_TypeError
, "required field \"value\" missing from Assign");
3801 *out
= Assign(targets
, value
, lineno
, col_offset
, arena
);
3802 if (*out
== NULL
) goto failed
;
3805 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)AugAssign_type
);
3806 if (isinstance
== -1) {
3814 if (PyObject_HasAttrString(obj
, "target")) {
3816 tmp
= PyObject_GetAttrString(obj
, "target");
3817 if (tmp
== NULL
) goto failed
;
3818 res
= obj2ast_expr(tmp
, &target
, arena
);
3819 if (res
!= 0) goto failed
;
3823 PyErr_SetString(PyExc_TypeError
, "required field \"target\" missing from AugAssign");
3826 if (PyObject_HasAttrString(obj
, "op")) {
3828 tmp
= PyObject_GetAttrString(obj
, "op");
3829 if (tmp
== NULL
) goto failed
;
3830 res
= obj2ast_operator(tmp
, &op
, arena
);
3831 if (res
!= 0) goto failed
;
3835 PyErr_SetString(PyExc_TypeError
, "required field \"op\" missing from AugAssign");
3838 if (PyObject_HasAttrString(obj
, "value")) {
3840 tmp
= PyObject_GetAttrString(obj
, "value");
3841 if (tmp
== NULL
) goto failed
;
3842 res
= obj2ast_expr(tmp
, &value
, arena
);
3843 if (res
!= 0) goto failed
;
3847 PyErr_SetString(PyExc_TypeError
, "required field \"value\" missing from AugAssign");
3850 *out
= AugAssign(target
, op
, value
, lineno
, col_offset
, arena
);
3851 if (*out
== NULL
) goto failed
;
3854 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Print_type
);
3855 if (isinstance
== -1) {
3863 if (PyObject_HasAttrString(obj
, "dest")) {
3865 tmp
= PyObject_GetAttrString(obj
, "dest");
3866 if (tmp
== NULL
) goto failed
;
3867 res
= obj2ast_expr(tmp
, &dest
, arena
);
3868 if (res
!= 0) goto failed
;
3874 if (PyObject_HasAttrString(obj
, "values")) {
3878 tmp
= PyObject_GetAttrString(obj
, "values");
3879 if (tmp
== NULL
) goto failed
;
3880 if (!PyList_Check(tmp
)) {
3881 PyErr_Format(PyExc_TypeError
, "Print field \"values\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3884 len
= PyList_GET_SIZE(tmp
);
3885 values
= asdl_seq_new(len
, arena
);
3886 if (values
== NULL
) goto failed
;
3887 for (i
= 0; i
< len
; i
++) {
3889 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3890 if (res
!= 0) goto failed
;
3891 asdl_seq_SET(values
, i
, value
);
3896 PyErr_SetString(PyExc_TypeError
, "required field \"values\" missing from Print");
3899 if (PyObject_HasAttrString(obj
, "nl")) {
3901 tmp
= PyObject_GetAttrString(obj
, "nl");
3902 if (tmp
== NULL
) goto failed
;
3903 res
= obj2ast_bool(tmp
, &nl
, arena
);
3904 if (res
!= 0) goto failed
;
3908 PyErr_SetString(PyExc_TypeError
, "required field \"nl\" missing from Print");
3911 *out
= Print(dest
, values
, nl
, lineno
, col_offset
, arena
);
3912 if (*out
== NULL
) goto failed
;
3915 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)For_type
);
3916 if (isinstance
== -1) {
3925 if (PyObject_HasAttrString(obj
, "target")) {
3927 tmp
= PyObject_GetAttrString(obj
, "target");
3928 if (tmp
== NULL
) goto failed
;
3929 res
= obj2ast_expr(tmp
, &target
, arena
);
3930 if (res
!= 0) goto failed
;
3934 PyErr_SetString(PyExc_TypeError
, "required field \"target\" missing from For");
3937 if (PyObject_HasAttrString(obj
, "iter")) {
3939 tmp
= PyObject_GetAttrString(obj
, "iter");
3940 if (tmp
== NULL
) goto failed
;
3941 res
= obj2ast_expr(tmp
, &iter
, arena
);
3942 if (res
!= 0) goto failed
;
3946 PyErr_SetString(PyExc_TypeError
, "required field \"iter\" missing from For");
3949 if (PyObject_HasAttrString(obj
, "body")) {
3953 tmp
= PyObject_GetAttrString(obj
, "body");
3954 if (tmp
== NULL
) goto failed
;
3955 if (!PyList_Check(tmp
)) {
3956 PyErr_Format(PyExc_TypeError
, "For field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3959 len
= PyList_GET_SIZE(tmp
);
3960 body
= asdl_seq_new(len
, arena
);
3961 if (body
== NULL
) goto failed
;
3962 for (i
= 0; i
< len
; i
++) {
3964 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3965 if (res
!= 0) goto failed
;
3966 asdl_seq_SET(body
, i
, value
);
3971 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from For");
3974 if (PyObject_HasAttrString(obj
, "orelse")) {
3978 tmp
= PyObject_GetAttrString(obj
, "orelse");
3979 if (tmp
== NULL
) goto failed
;
3980 if (!PyList_Check(tmp
)) {
3981 PyErr_Format(PyExc_TypeError
, "For field \"orelse\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3984 len
= PyList_GET_SIZE(tmp
);
3985 orelse
= asdl_seq_new(len
, arena
);
3986 if (orelse
== NULL
) goto failed
;
3987 for (i
= 0; i
< len
; i
++) {
3989 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3990 if (res
!= 0) goto failed
;
3991 asdl_seq_SET(orelse
, i
, value
);
3996 PyErr_SetString(PyExc_TypeError
, "required field \"orelse\" missing from For");
3999 *out
= For(target
, iter
, body
, orelse
, lineno
, col_offset
,
4001 if (*out
== NULL
) goto failed
;
4004 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)While_type
);
4005 if (isinstance
== -1) {
4013 if (PyObject_HasAttrString(obj
, "test")) {
4015 tmp
= PyObject_GetAttrString(obj
, "test");
4016 if (tmp
== NULL
) goto failed
;
4017 res
= obj2ast_expr(tmp
, &test
, arena
);
4018 if (res
!= 0) goto failed
;
4022 PyErr_SetString(PyExc_TypeError
, "required field \"test\" missing from While");
4025 if (PyObject_HasAttrString(obj
, "body")) {
4029 tmp
= PyObject_GetAttrString(obj
, "body");
4030 if (tmp
== NULL
) goto failed
;
4031 if (!PyList_Check(tmp
)) {
4032 PyErr_Format(PyExc_TypeError
, "While field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4035 len
= PyList_GET_SIZE(tmp
);
4036 body
= asdl_seq_new(len
, arena
);
4037 if (body
== NULL
) goto failed
;
4038 for (i
= 0; i
< len
; i
++) {
4040 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4041 if (res
!= 0) goto failed
;
4042 asdl_seq_SET(body
, i
, value
);
4047 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from While");
4050 if (PyObject_HasAttrString(obj
, "orelse")) {
4054 tmp
= PyObject_GetAttrString(obj
, "orelse");
4055 if (tmp
== NULL
) goto failed
;
4056 if (!PyList_Check(tmp
)) {
4057 PyErr_Format(PyExc_TypeError
, "While field \"orelse\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4060 len
= PyList_GET_SIZE(tmp
);
4061 orelse
= asdl_seq_new(len
, arena
);
4062 if (orelse
== NULL
) goto failed
;
4063 for (i
= 0; i
< len
; i
++) {
4065 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4066 if (res
!= 0) goto failed
;
4067 asdl_seq_SET(orelse
, i
, value
);
4072 PyErr_SetString(PyExc_TypeError
, "required field \"orelse\" missing from While");
4075 *out
= While(test
, body
, orelse
, lineno
, col_offset
, arena
);
4076 if (*out
== NULL
) goto failed
;
4079 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)If_type
);
4080 if (isinstance
== -1) {
4088 if (PyObject_HasAttrString(obj
, "test")) {
4090 tmp
= PyObject_GetAttrString(obj
, "test");
4091 if (tmp
== NULL
) goto failed
;
4092 res
= obj2ast_expr(tmp
, &test
, arena
);
4093 if (res
!= 0) goto failed
;
4097 PyErr_SetString(PyExc_TypeError
, "required field \"test\" missing from If");
4100 if (PyObject_HasAttrString(obj
, "body")) {
4104 tmp
= PyObject_GetAttrString(obj
, "body");
4105 if (tmp
== NULL
) goto failed
;
4106 if (!PyList_Check(tmp
)) {
4107 PyErr_Format(PyExc_TypeError
, "If field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4110 len
= PyList_GET_SIZE(tmp
);
4111 body
= asdl_seq_new(len
, arena
);
4112 if (body
== NULL
) goto failed
;
4113 for (i
= 0; i
< len
; i
++) {
4115 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4116 if (res
!= 0) goto failed
;
4117 asdl_seq_SET(body
, i
, value
);
4122 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from If");
4125 if (PyObject_HasAttrString(obj
, "orelse")) {
4129 tmp
= PyObject_GetAttrString(obj
, "orelse");
4130 if (tmp
== NULL
) goto failed
;
4131 if (!PyList_Check(tmp
)) {
4132 PyErr_Format(PyExc_TypeError
, "If field \"orelse\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4135 len
= PyList_GET_SIZE(tmp
);
4136 orelse
= asdl_seq_new(len
, arena
);
4137 if (orelse
== NULL
) goto failed
;
4138 for (i
= 0; i
< len
; i
++) {
4140 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4141 if (res
!= 0) goto failed
;
4142 asdl_seq_SET(orelse
, i
, value
);
4147 PyErr_SetString(PyExc_TypeError
, "required field \"orelse\" missing from If");
4150 *out
= If(test
, body
, orelse
, lineno
, col_offset
, arena
);
4151 if (*out
== NULL
) goto failed
;
4154 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)With_type
);
4155 if (isinstance
== -1) {
4159 expr_ty context_expr
;
4160 expr_ty optional_vars
;
4163 if (PyObject_HasAttrString(obj
, "context_expr")) {
4165 tmp
= PyObject_GetAttrString(obj
, "context_expr");
4166 if (tmp
== NULL
) goto failed
;
4167 res
= obj2ast_expr(tmp
, &context_expr
, arena
);
4168 if (res
!= 0) goto failed
;
4172 PyErr_SetString(PyExc_TypeError
, "required field \"context_expr\" missing from With");
4175 if (PyObject_HasAttrString(obj
, "optional_vars")) {
4177 tmp
= PyObject_GetAttrString(obj
, "optional_vars");
4178 if (tmp
== NULL
) goto failed
;
4179 res
= obj2ast_expr(tmp
, &optional_vars
, arena
);
4180 if (res
!= 0) goto failed
;
4184 optional_vars
= NULL
;
4186 if (PyObject_HasAttrString(obj
, "body")) {
4190 tmp
= PyObject_GetAttrString(obj
, "body");
4191 if (tmp
== NULL
) goto failed
;
4192 if (!PyList_Check(tmp
)) {
4193 PyErr_Format(PyExc_TypeError
, "With field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4196 len
= PyList_GET_SIZE(tmp
);
4197 body
= asdl_seq_new(len
, arena
);
4198 if (body
== NULL
) goto failed
;
4199 for (i
= 0; i
< len
; i
++) {
4201 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4202 if (res
!= 0) goto failed
;
4203 asdl_seq_SET(body
, i
, value
);
4208 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from With");
4211 *out
= With(context_expr
, optional_vars
, body
, lineno
,
4213 if (*out
== NULL
) goto failed
;
4216 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Raise_type
);
4217 if (isinstance
== -1) {
4225 if (PyObject_HasAttrString(obj
, "type")) {
4227 tmp
= PyObject_GetAttrString(obj
, "type");
4228 if (tmp
== NULL
) goto failed
;
4229 res
= obj2ast_expr(tmp
, &type
, arena
);
4230 if (res
!= 0) goto failed
;
4236 if (PyObject_HasAttrString(obj
, "inst")) {
4238 tmp
= PyObject_GetAttrString(obj
, "inst");
4239 if (tmp
== NULL
) goto failed
;
4240 res
= obj2ast_expr(tmp
, &inst
, arena
);
4241 if (res
!= 0) goto failed
;
4247 if (PyObject_HasAttrString(obj
, "tback")) {
4249 tmp
= PyObject_GetAttrString(obj
, "tback");
4250 if (tmp
== NULL
) goto failed
;
4251 res
= obj2ast_expr(tmp
, &tback
, arena
);
4252 if (res
!= 0) goto failed
;
4258 *out
= Raise(type
, inst
, tback
, lineno
, col_offset
, arena
);
4259 if (*out
== NULL
) goto failed
;
4262 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)TryExcept_type
);
4263 if (isinstance
== -1) {
4271 if (PyObject_HasAttrString(obj
, "body")) {
4275 tmp
= PyObject_GetAttrString(obj
, "body");
4276 if (tmp
== NULL
) goto failed
;
4277 if (!PyList_Check(tmp
)) {
4278 PyErr_Format(PyExc_TypeError
, "TryExcept field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4281 len
= PyList_GET_SIZE(tmp
);
4282 body
= asdl_seq_new(len
, arena
);
4283 if (body
== NULL
) goto failed
;
4284 for (i
= 0; i
< len
; i
++) {
4286 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4287 if (res
!= 0) goto failed
;
4288 asdl_seq_SET(body
, i
, value
);
4293 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from TryExcept");
4296 if (PyObject_HasAttrString(obj
, "handlers")) {
4300 tmp
= PyObject_GetAttrString(obj
, "handlers");
4301 if (tmp
== NULL
) goto failed
;
4302 if (!PyList_Check(tmp
)) {
4303 PyErr_Format(PyExc_TypeError
, "TryExcept field \"handlers\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4306 len
= PyList_GET_SIZE(tmp
);
4307 handlers
= asdl_seq_new(len
, arena
);
4308 if (handlers
== NULL
) goto failed
;
4309 for (i
= 0; i
< len
; i
++) {
4310 excepthandler_ty value
;
4311 res
= obj2ast_excepthandler(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4312 if (res
!= 0) goto failed
;
4313 asdl_seq_SET(handlers
, i
, value
);
4318 PyErr_SetString(PyExc_TypeError
, "required field \"handlers\" missing from TryExcept");
4321 if (PyObject_HasAttrString(obj
, "orelse")) {
4325 tmp
= PyObject_GetAttrString(obj
, "orelse");
4326 if (tmp
== NULL
) goto failed
;
4327 if (!PyList_Check(tmp
)) {
4328 PyErr_Format(PyExc_TypeError
, "TryExcept field \"orelse\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4331 len
= PyList_GET_SIZE(tmp
);
4332 orelse
= asdl_seq_new(len
, arena
);
4333 if (orelse
== NULL
) goto failed
;
4334 for (i
= 0; i
< len
; i
++) {
4336 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4337 if (res
!= 0) goto failed
;
4338 asdl_seq_SET(orelse
, i
, value
);
4343 PyErr_SetString(PyExc_TypeError
, "required field \"orelse\" missing from TryExcept");
4346 *out
= TryExcept(body
, handlers
, orelse
, lineno
, col_offset
,
4348 if (*out
== NULL
) goto failed
;
4351 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)TryFinally_type
);
4352 if (isinstance
== -1) {
4357 asdl_seq
* finalbody
;
4359 if (PyObject_HasAttrString(obj
, "body")) {
4363 tmp
= PyObject_GetAttrString(obj
, "body");
4364 if (tmp
== NULL
) goto failed
;
4365 if (!PyList_Check(tmp
)) {
4366 PyErr_Format(PyExc_TypeError
, "TryFinally field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4369 len
= PyList_GET_SIZE(tmp
);
4370 body
= asdl_seq_new(len
, arena
);
4371 if (body
== NULL
) goto failed
;
4372 for (i
= 0; i
< len
; i
++) {
4374 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4375 if (res
!= 0) goto failed
;
4376 asdl_seq_SET(body
, i
, value
);
4381 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from TryFinally");
4384 if (PyObject_HasAttrString(obj
, "finalbody")) {
4388 tmp
= PyObject_GetAttrString(obj
, "finalbody");
4389 if (tmp
== NULL
) goto failed
;
4390 if (!PyList_Check(tmp
)) {
4391 PyErr_Format(PyExc_TypeError
, "TryFinally field \"finalbody\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4394 len
= PyList_GET_SIZE(tmp
);
4395 finalbody
= asdl_seq_new(len
, arena
);
4396 if (finalbody
== NULL
) goto failed
;
4397 for (i
= 0; i
< len
; i
++) {
4399 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4400 if (res
!= 0) goto failed
;
4401 asdl_seq_SET(finalbody
, i
, value
);
4406 PyErr_SetString(PyExc_TypeError
, "required field \"finalbody\" missing from TryFinally");
4409 *out
= TryFinally(body
, finalbody
, lineno
, col_offset
, arena
);
4410 if (*out
== NULL
) goto failed
;
4413 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Assert_type
);
4414 if (isinstance
== -1) {
4421 if (PyObject_HasAttrString(obj
, "test")) {
4423 tmp
= PyObject_GetAttrString(obj
, "test");
4424 if (tmp
== NULL
) goto failed
;
4425 res
= obj2ast_expr(tmp
, &test
, arena
);
4426 if (res
!= 0) goto failed
;
4430 PyErr_SetString(PyExc_TypeError
, "required field \"test\" missing from Assert");
4433 if (PyObject_HasAttrString(obj
, "msg")) {
4435 tmp
= PyObject_GetAttrString(obj
, "msg");
4436 if (tmp
== NULL
) goto failed
;
4437 res
= obj2ast_expr(tmp
, &msg
, arena
);
4438 if (res
!= 0) goto failed
;
4444 *out
= Assert(test
, msg
, lineno
, col_offset
, arena
);
4445 if (*out
== NULL
) goto failed
;
4448 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Import_type
);
4449 if (isinstance
== -1) {
4455 if (PyObject_HasAttrString(obj
, "names")) {
4459 tmp
= PyObject_GetAttrString(obj
, "names");
4460 if (tmp
== NULL
) goto failed
;
4461 if (!PyList_Check(tmp
)) {
4462 PyErr_Format(PyExc_TypeError
, "Import field \"names\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4465 len
= PyList_GET_SIZE(tmp
);
4466 names
= asdl_seq_new(len
, arena
);
4467 if (names
== NULL
) goto failed
;
4468 for (i
= 0; i
< len
; i
++) {
4470 res
= obj2ast_alias(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4471 if (res
!= 0) goto failed
;
4472 asdl_seq_SET(names
, i
, value
);
4477 PyErr_SetString(PyExc_TypeError
, "required field \"names\" missing from Import");
4480 *out
= Import(names
, lineno
, col_offset
, arena
);
4481 if (*out
== NULL
) goto failed
;
4484 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)ImportFrom_type
);
4485 if (isinstance
== -1) {
4493 if (PyObject_HasAttrString(obj
, "module")) {
4495 tmp
= PyObject_GetAttrString(obj
, "module");
4496 if (tmp
== NULL
) goto failed
;
4497 res
= obj2ast_identifier(tmp
, &module
, arena
);
4498 if (res
!= 0) goto failed
;
4504 if (PyObject_HasAttrString(obj
, "names")) {
4508 tmp
= PyObject_GetAttrString(obj
, "names");
4509 if (tmp
== NULL
) goto failed
;
4510 if (!PyList_Check(tmp
)) {
4511 PyErr_Format(PyExc_TypeError
, "ImportFrom field \"names\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4514 len
= PyList_GET_SIZE(tmp
);
4515 names
= asdl_seq_new(len
, arena
);
4516 if (names
== NULL
) goto failed
;
4517 for (i
= 0; i
< len
; i
++) {
4519 res
= obj2ast_alias(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4520 if (res
!= 0) goto failed
;
4521 asdl_seq_SET(names
, i
, value
);
4526 PyErr_SetString(PyExc_TypeError
, "required field \"names\" missing from ImportFrom");
4529 if (PyObject_HasAttrString(obj
, "level")) {
4531 tmp
= PyObject_GetAttrString(obj
, "level");
4532 if (tmp
== NULL
) goto failed
;
4533 res
= obj2ast_int(tmp
, &level
, arena
);
4534 if (res
!= 0) goto failed
;
4540 *out
= ImportFrom(module
, names
, level
, lineno
, col_offset
,
4542 if (*out
== NULL
) goto failed
;
4545 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Exec_type
);
4546 if (isinstance
== -1) {
4554 if (PyObject_HasAttrString(obj
, "body")) {
4556 tmp
= PyObject_GetAttrString(obj
, "body");
4557 if (tmp
== NULL
) goto failed
;
4558 res
= obj2ast_expr(tmp
, &body
, arena
);
4559 if (res
!= 0) goto failed
;
4563 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from Exec");
4566 if (PyObject_HasAttrString(obj
, "globals")) {
4568 tmp
= PyObject_GetAttrString(obj
, "globals");
4569 if (tmp
== NULL
) goto failed
;
4570 res
= obj2ast_expr(tmp
, &globals
, arena
);
4571 if (res
!= 0) goto failed
;
4577 if (PyObject_HasAttrString(obj
, "locals")) {
4579 tmp
= PyObject_GetAttrString(obj
, "locals");
4580 if (tmp
== NULL
) goto failed
;
4581 res
= obj2ast_expr(tmp
, &locals
, arena
);
4582 if (res
!= 0) goto failed
;
4588 *out
= Exec(body
, globals
, locals
, lineno
, col_offset
, arena
);
4589 if (*out
== NULL
) goto failed
;
4592 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Global_type
);
4593 if (isinstance
== -1) {
4599 if (PyObject_HasAttrString(obj
, "names")) {
4603 tmp
= PyObject_GetAttrString(obj
, "names");
4604 if (tmp
== NULL
) goto failed
;
4605 if (!PyList_Check(tmp
)) {
4606 PyErr_Format(PyExc_TypeError
, "Global field \"names\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4609 len
= PyList_GET_SIZE(tmp
);
4610 names
= asdl_seq_new(len
, arena
);
4611 if (names
== NULL
) goto failed
;
4612 for (i
= 0; i
< len
; i
++) {
4614 res
= obj2ast_identifier(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4615 if (res
!= 0) goto failed
;
4616 asdl_seq_SET(names
, i
, value
);
4621 PyErr_SetString(PyExc_TypeError
, "required field \"names\" missing from Global");
4624 *out
= Global(names
, lineno
, col_offset
, arena
);
4625 if (*out
== NULL
) goto failed
;
4628 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Expr_type
);
4629 if (isinstance
== -1) {
4635 if (PyObject_HasAttrString(obj
, "value")) {
4637 tmp
= PyObject_GetAttrString(obj
, "value");
4638 if (tmp
== NULL
) goto failed
;
4639 res
= obj2ast_expr(tmp
, &value
, arena
);
4640 if (res
!= 0) goto failed
;
4644 PyErr_SetString(PyExc_TypeError
, "required field \"value\" missing from Expr");
4647 *out
= Expr(value
, lineno
, col_offset
, arena
);
4648 if (*out
== NULL
) goto failed
;
4651 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Pass_type
);
4652 if (isinstance
== -1) {
4657 *out
= Pass(lineno
, col_offset
, arena
);
4658 if (*out
== NULL
) goto failed
;
4661 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Break_type
);
4662 if (isinstance
== -1) {
4667 *out
= Break(lineno
, col_offset
, arena
);
4668 if (*out
== NULL
) goto failed
;
4671 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Continue_type
);
4672 if (isinstance
== -1) {
4677 *out
= Continue(lineno
, col_offset
, arena
);
4678 if (*out
== NULL
) goto failed
;
4682 tmp
= PyObject_Repr(obj
);
4683 if (tmp
== NULL
) goto failed
;
4684 PyErr_Format(PyExc_TypeError
, "expected some sort of stmt, but got %.400s", PyString_AS_STRING(tmp
));
4691 obj2ast_expr(PyObject
* obj
, expr_ty
* out
, PyArena
* arena
)
4693 PyObject
* tmp
= NULL
;
4699 if (obj
== Py_None
) {
4703 if (PyObject_HasAttrString(obj
, "lineno")) {
4705 tmp
= PyObject_GetAttrString(obj
, "lineno");
4706 if (tmp
== NULL
) goto failed
;
4707 res
= obj2ast_int(tmp
, &lineno
, arena
);
4708 if (res
!= 0) goto failed
;
4712 PyErr_SetString(PyExc_TypeError
, "required field \"lineno\" missing from expr");
4715 if (PyObject_HasAttrString(obj
, "col_offset")) {
4717 tmp
= PyObject_GetAttrString(obj
, "col_offset");
4718 if (tmp
== NULL
) goto failed
;
4719 res
= obj2ast_int(tmp
, &col_offset
, arena
);
4720 if (res
!= 0) goto failed
;
4724 PyErr_SetString(PyExc_TypeError
, "required field \"col_offset\" missing from expr");
4727 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)BoolOp_type
);
4728 if (isinstance
== -1) {
4735 if (PyObject_HasAttrString(obj
, "op")) {
4737 tmp
= PyObject_GetAttrString(obj
, "op");
4738 if (tmp
== NULL
) goto failed
;
4739 res
= obj2ast_boolop(tmp
, &op
, arena
);
4740 if (res
!= 0) goto failed
;
4744 PyErr_SetString(PyExc_TypeError
, "required field \"op\" missing from BoolOp");
4747 if (PyObject_HasAttrString(obj
, "values")) {
4751 tmp
= PyObject_GetAttrString(obj
, "values");
4752 if (tmp
== NULL
) goto failed
;
4753 if (!PyList_Check(tmp
)) {
4754 PyErr_Format(PyExc_TypeError
, "BoolOp field \"values\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4757 len
= PyList_GET_SIZE(tmp
);
4758 values
= asdl_seq_new(len
, arena
);
4759 if (values
== NULL
) goto failed
;
4760 for (i
= 0; i
< len
; i
++) {
4762 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4763 if (res
!= 0) goto failed
;
4764 asdl_seq_SET(values
, i
, value
);
4769 PyErr_SetString(PyExc_TypeError
, "required field \"values\" missing from BoolOp");
4772 *out
= BoolOp(op
, values
, lineno
, col_offset
, arena
);
4773 if (*out
== NULL
) goto failed
;
4776 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)BinOp_type
);
4777 if (isinstance
== -1) {
4785 if (PyObject_HasAttrString(obj
, "left")) {
4787 tmp
= PyObject_GetAttrString(obj
, "left");
4788 if (tmp
== NULL
) goto failed
;
4789 res
= obj2ast_expr(tmp
, &left
, arena
);
4790 if (res
!= 0) goto failed
;
4794 PyErr_SetString(PyExc_TypeError
, "required field \"left\" missing from BinOp");
4797 if (PyObject_HasAttrString(obj
, "op")) {
4799 tmp
= PyObject_GetAttrString(obj
, "op");
4800 if (tmp
== NULL
) goto failed
;
4801 res
= obj2ast_operator(tmp
, &op
, arena
);
4802 if (res
!= 0) goto failed
;
4806 PyErr_SetString(PyExc_TypeError
, "required field \"op\" missing from BinOp");
4809 if (PyObject_HasAttrString(obj
, "right")) {
4811 tmp
= PyObject_GetAttrString(obj
, "right");
4812 if (tmp
== NULL
) goto failed
;
4813 res
= obj2ast_expr(tmp
, &right
, arena
);
4814 if (res
!= 0) goto failed
;
4818 PyErr_SetString(PyExc_TypeError
, "required field \"right\" missing from BinOp");
4821 *out
= BinOp(left
, op
, right
, lineno
, col_offset
, arena
);
4822 if (*out
== NULL
) goto failed
;
4825 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)UnaryOp_type
);
4826 if (isinstance
== -1) {
4833 if (PyObject_HasAttrString(obj
, "op")) {
4835 tmp
= PyObject_GetAttrString(obj
, "op");
4836 if (tmp
== NULL
) goto failed
;
4837 res
= obj2ast_unaryop(tmp
, &op
, arena
);
4838 if (res
!= 0) goto failed
;
4842 PyErr_SetString(PyExc_TypeError
, "required field \"op\" missing from UnaryOp");
4845 if (PyObject_HasAttrString(obj
, "operand")) {
4847 tmp
= PyObject_GetAttrString(obj
, "operand");
4848 if (tmp
== NULL
) goto failed
;
4849 res
= obj2ast_expr(tmp
, &operand
, arena
);
4850 if (res
!= 0) goto failed
;
4854 PyErr_SetString(PyExc_TypeError
, "required field \"operand\" missing from UnaryOp");
4857 *out
= UnaryOp(op
, operand
, lineno
, col_offset
, arena
);
4858 if (*out
== NULL
) goto failed
;
4861 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Lambda_type
);
4862 if (isinstance
== -1) {
4869 if (PyObject_HasAttrString(obj
, "args")) {
4871 tmp
= PyObject_GetAttrString(obj
, "args");
4872 if (tmp
== NULL
) goto failed
;
4873 res
= obj2ast_arguments(tmp
, &args
, arena
);
4874 if (res
!= 0) goto failed
;
4878 PyErr_SetString(PyExc_TypeError
, "required field \"args\" missing from Lambda");
4881 if (PyObject_HasAttrString(obj
, "body")) {
4883 tmp
= PyObject_GetAttrString(obj
, "body");
4884 if (tmp
== NULL
) goto failed
;
4885 res
= obj2ast_expr(tmp
, &body
, arena
);
4886 if (res
!= 0) goto failed
;
4890 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from Lambda");
4893 *out
= Lambda(args
, body
, lineno
, col_offset
, arena
);
4894 if (*out
== NULL
) goto failed
;
4897 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)IfExp_type
);
4898 if (isinstance
== -1) {
4906 if (PyObject_HasAttrString(obj
, "test")) {
4908 tmp
= PyObject_GetAttrString(obj
, "test");
4909 if (tmp
== NULL
) goto failed
;
4910 res
= obj2ast_expr(tmp
, &test
, arena
);
4911 if (res
!= 0) goto failed
;
4915 PyErr_SetString(PyExc_TypeError
, "required field \"test\" missing from IfExp");
4918 if (PyObject_HasAttrString(obj
, "body")) {
4920 tmp
= PyObject_GetAttrString(obj
, "body");
4921 if (tmp
== NULL
) goto failed
;
4922 res
= obj2ast_expr(tmp
, &body
, arena
);
4923 if (res
!= 0) goto failed
;
4927 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from IfExp");
4930 if (PyObject_HasAttrString(obj
, "orelse")) {
4932 tmp
= PyObject_GetAttrString(obj
, "orelse");
4933 if (tmp
== NULL
) goto failed
;
4934 res
= obj2ast_expr(tmp
, &orelse
, arena
);
4935 if (res
!= 0) goto failed
;
4939 PyErr_SetString(PyExc_TypeError
, "required field \"orelse\" missing from IfExp");
4942 *out
= IfExp(test
, body
, orelse
, lineno
, col_offset
, arena
);
4943 if (*out
== NULL
) goto failed
;
4946 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Dict_type
);
4947 if (isinstance
== -1) {
4954 if (PyObject_HasAttrString(obj
, "keys")) {
4958 tmp
= PyObject_GetAttrString(obj
, "keys");
4959 if (tmp
== NULL
) goto failed
;
4960 if (!PyList_Check(tmp
)) {
4961 PyErr_Format(PyExc_TypeError
, "Dict field \"keys\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4964 len
= PyList_GET_SIZE(tmp
);
4965 keys
= asdl_seq_new(len
, arena
);
4966 if (keys
== NULL
) goto failed
;
4967 for (i
= 0; i
< len
; i
++) {
4969 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4970 if (res
!= 0) goto failed
;
4971 asdl_seq_SET(keys
, i
, value
);
4976 PyErr_SetString(PyExc_TypeError
, "required field \"keys\" missing from Dict");
4979 if (PyObject_HasAttrString(obj
, "values")) {
4983 tmp
= PyObject_GetAttrString(obj
, "values");
4984 if (tmp
== NULL
) goto failed
;
4985 if (!PyList_Check(tmp
)) {
4986 PyErr_Format(PyExc_TypeError
, "Dict field \"values\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4989 len
= PyList_GET_SIZE(tmp
);
4990 values
= asdl_seq_new(len
, arena
);
4991 if (values
== NULL
) goto failed
;
4992 for (i
= 0; i
< len
; i
++) {
4994 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4995 if (res
!= 0) goto failed
;
4996 asdl_seq_SET(values
, i
, value
);
5001 PyErr_SetString(PyExc_TypeError
, "required field \"values\" missing from Dict");
5004 *out
= Dict(keys
, values
, lineno
, col_offset
, arena
);
5005 if (*out
== NULL
) goto failed
;
5008 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Set_type
);
5009 if (isinstance
== -1) {
5015 if (PyObject_HasAttrString(obj
, "elts")) {
5019 tmp
= PyObject_GetAttrString(obj
, "elts");
5020 if (tmp
== NULL
) goto failed
;
5021 if (!PyList_Check(tmp
)) {
5022 PyErr_Format(PyExc_TypeError
, "Set field \"elts\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5025 len
= PyList_GET_SIZE(tmp
);
5026 elts
= asdl_seq_new(len
, arena
);
5027 if (elts
== NULL
) goto failed
;
5028 for (i
= 0; i
< len
; i
++) {
5030 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5031 if (res
!= 0) goto failed
;
5032 asdl_seq_SET(elts
, i
, value
);
5037 PyErr_SetString(PyExc_TypeError
, "required field \"elts\" missing from Set");
5040 *out
= Set(elts
, lineno
, col_offset
, arena
);
5041 if (*out
== NULL
) goto failed
;
5044 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)ListComp_type
);
5045 if (isinstance
== -1) {
5050 asdl_seq
* generators
;
5052 if (PyObject_HasAttrString(obj
, "elt")) {
5054 tmp
= PyObject_GetAttrString(obj
, "elt");
5055 if (tmp
== NULL
) goto failed
;
5056 res
= obj2ast_expr(tmp
, &elt
, arena
);
5057 if (res
!= 0) goto failed
;
5061 PyErr_SetString(PyExc_TypeError
, "required field \"elt\" missing from ListComp");
5064 if (PyObject_HasAttrString(obj
, "generators")) {
5068 tmp
= PyObject_GetAttrString(obj
, "generators");
5069 if (tmp
== NULL
) goto failed
;
5070 if (!PyList_Check(tmp
)) {
5071 PyErr_Format(PyExc_TypeError
, "ListComp field \"generators\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5074 len
= PyList_GET_SIZE(tmp
);
5075 generators
= asdl_seq_new(len
, arena
);
5076 if (generators
== NULL
) goto failed
;
5077 for (i
= 0; i
< len
; i
++) {
5078 comprehension_ty value
;
5079 res
= obj2ast_comprehension(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5080 if (res
!= 0) goto failed
;
5081 asdl_seq_SET(generators
, i
, value
);
5086 PyErr_SetString(PyExc_TypeError
, "required field \"generators\" missing from ListComp");
5089 *out
= ListComp(elt
, generators
, lineno
, col_offset
, arena
);
5090 if (*out
== NULL
) goto failed
;
5093 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)SetComp_type
);
5094 if (isinstance
== -1) {
5099 asdl_seq
* generators
;
5101 if (PyObject_HasAttrString(obj
, "elt")) {
5103 tmp
= PyObject_GetAttrString(obj
, "elt");
5104 if (tmp
== NULL
) goto failed
;
5105 res
= obj2ast_expr(tmp
, &elt
, arena
);
5106 if (res
!= 0) goto failed
;
5110 PyErr_SetString(PyExc_TypeError
, "required field \"elt\" missing from SetComp");
5113 if (PyObject_HasAttrString(obj
, "generators")) {
5117 tmp
= PyObject_GetAttrString(obj
, "generators");
5118 if (tmp
== NULL
) goto failed
;
5119 if (!PyList_Check(tmp
)) {
5120 PyErr_Format(PyExc_TypeError
, "SetComp field \"generators\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5123 len
= PyList_GET_SIZE(tmp
);
5124 generators
= asdl_seq_new(len
, arena
);
5125 if (generators
== NULL
) goto failed
;
5126 for (i
= 0; i
< len
; i
++) {
5127 comprehension_ty value
;
5128 res
= obj2ast_comprehension(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5129 if (res
!= 0) goto failed
;
5130 asdl_seq_SET(generators
, i
, value
);
5135 PyErr_SetString(PyExc_TypeError
, "required field \"generators\" missing from SetComp");
5138 *out
= SetComp(elt
, generators
, lineno
, col_offset
, arena
);
5139 if (*out
== NULL
) goto failed
;
5142 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)DictComp_type
);
5143 if (isinstance
== -1) {
5149 asdl_seq
* generators
;
5151 if (PyObject_HasAttrString(obj
, "key")) {
5153 tmp
= PyObject_GetAttrString(obj
, "key");
5154 if (tmp
== NULL
) goto failed
;
5155 res
= obj2ast_expr(tmp
, &key
, arena
);
5156 if (res
!= 0) goto failed
;
5160 PyErr_SetString(PyExc_TypeError
, "required field \"key\" missing from DictComp");
5163 if (PyObject_HasAttrString(obj
, "value")) {
5165 tmp
= PyObject_GetAttrString(obj
, "value");
5166 if (tmp
== NULL
) goto failed
;
5167 res
= obj2ast_expr(tmp
, &value
, arena
);
5168 if (res
!= 0) goto failed
;
5172 PyErr_SetString(PyExc_TypeError
, "required field \"value\" missing from DictComp");
5175 if (PyObject_HasAttrString(obj
, "generators")) {
5179 tmp
= PyObject_GetAttrString(obj
, "generators");
5180 if (tmp
== NULL
) goto failed
;
5181 if (!PyList_Check(tmp
)) {
5182 PyErr_Format(PyExc_TypeError
, "DictComp field \"generators\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5185 len
= PyList_GET_SIZE(tmp
);
5186 generators
= asdl_seq_new(len
, arena
);
5187 if (generators
== NULL
) goto failed
;
5188 for (i
= 0; i
< len
; i
++) {
5189 comprehension_ty value
;
5190 res
= obj2ast_comprehension(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5191 if (res
!= 0) goto failed
;
5192 asdl_seq_SET(generators
, i
, value
);
5197 PyErr_SetString(PyExc_TypeError
, "required field \"generators\" missing from DictComp");
5200 *out
= DictComp(key
, value
, generators
, lineno
, col_offset
,
5202 if (*out
== NULL
) goto failed
;
5205 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)GeneratorExp_type
);
5206 if (isinstance
== -1) {
5211 asdl_seq
* generators
;
5213 if (PyObject_HasAttrString(obj
, "elt")) {
5215 tmp
= PyObject_GetAttrString(obj
, "elt");
5216 if (tmp
== NULL
) goto failed
;
5217 res
= obj2ast_expr(tmp
, &elt
, arena
);
5218 if (res
!= 0) goto failed
;
5222 PyErr_SetString(PyExc_TypeError
, "required field \"elt\" missing from GeneratorExp");
5225 if (PyObject_HasAttrString(obj
, "generators")) {
5229 tmp
= PyObject_GetAttrString(obj
, "generators");
5230 if (tmp
== NULL
) goto failed
;
5231 if (!PyList_Check(tmp
)) {
5232 PyErr_Format(PyExc_TypeError
, "GeneratorExp field \"generators\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5235 len
= PyList_GET_SIZE(tmp
);
5236 generators
= asdl_seq_new(len
, arena
);
5237 if (generators
== NULL
) goto failed
;
5238 for (i
= 0; i
< len
; i
++) {
5239 comprehension_ty value
;
5240 res
= obj2ast_comprehension(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5241 if (res
!= 0) goto failed
;
5242 asdl_seq_SET(generators
, i
, value
);
5247 PyErr_SetString(PyExc_TypeError
, "required field \"generators\" missing from GeneratorExp");
5250 *out
= GeneratorExp(elt
, generators
, lineno
, col_offset
, arena
);
5251 if (*out
== NULL
) goto failed
;
5254 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Yield_type
);
5255 if (isinstance
== -1) {
5261 if (PyObject_HasAttrString(obj
, "value")) {
5263 tmp
= PyObject_GetAttrString(obj
, "value");
5264 if (tmp
== NULL
) goto failed
;
5265 res
= obj2ast_expr(tmp
, &value
, arena
);
5266 if (res
!= 0) goto failed
;
5272 *out
= Yield(value
, lineno
, col_offset
, arena
);
5273 if (*out
== NULL
) goto failed
;
5276 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Compare_type
);
5277 if (isinstance
== -1) {
5283 asdl_seq
* comparators
;
5285 if (PyObject_HasAttrString(obj
, "left")) {
5287 tmp
= PyObject_GetAttrString(obj
, "left");
5288 if (tmp
== NULL
) goto failed
;
5289 res
= obj2ast_expr(tmp
, &left
, arena
);
5290 if (res
!= 0) goto failed
;
5294 PyErr_SetString(PyExc_TypeError
, "required field \"left\" missing from Compare");
5297 if (PyObject_HasAttrString(obj
, "ops")) {
5301 tmp
= PyObject_GetAttrString(obj
, "ops");
5302 if (tmp
== NULL
) goto failed
;
5303 if (!PyList_Check(tmp
)) {
5304 PyErr_Format(PyExc_TypeError
, "Compare field \"ops\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5307 len
= PyList_GET_SIZE(tmp
);
5308 ops
= asdl_int_seq_new(len
, arena
);
5309 if (ops
== NULL
) goto failed
;
5310 for (i
= 0; i
< len
; i
++) {
5312 res
= obj2ast_cmpop(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5313 if (res
!= 0) goto failed
;
5314 asdl_seq_SET(ops
, i
, value
);
5319 PyErr_SetString(PyExc_TypeError
, "required field \"ops\" missing from Compare");
5322 if (PyObject_HasAttrString(obj
, "comparators")) {
5326 tmp
= PyObject_GetAttrString(obj
, "comparators");
5327 if (tmp
== NULL
) goto failed
;
5328 if (!PyList_Check(tmp
)) {
5329 PyErr_Format(PyExc_TypeError
, "Compare field \"comparators\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5332 len
= PyList_GET_SIZE(tmp
);
5333 comparators
= asdl_seq_new(len
, arena
);
5334 if (comparators
== NULL
) goto failed
;
5335 for (i
= 0; i
< len
; i
++) {
5337 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5338 if (res
!= 0) goto failed
;
5339 asdl_seq_SET(comparators
, i
, value
);
5344 PyErr_SetString(PyExc_TypeError
, "required field \"comparators\" missing from Compare");
5347 *out
= Compare(left
, ops
, comparators
, lineno
, col_offset
,
5349 if (*out
== NULL
) goto failed
;
5352 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Call_type
);
5353 if (isinstance
== -1) {
5363 if (PyObject_HasAttrString(obj
, "func")) {
5365 tmp
= PyObject_GetAttrString(obj
, "func");
5366 if (tmp
== NULL
) goto failed
;
5367 res
= obj2ast_expr(tmp
, &func
, arena
);
5368 if (res
!= 0) goto failed
;
5372 PyErr_SetString(PyExc_TypeError
, "required field \"func\" missing from Call");
5375 if (PyObject_HasAttrString(obj
, "args")) {
5379 tmp
= PyObject_GetAttrString(obj
, "args");
5380 if (tmp
== NULL
) goto failed
;
5381 if (!PyList_Check(tmp
)) {
5382 PyErr_Format(PyExc_TypeError
, "Call field \"args\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5385 len
= PyList_GET_SIZE(tmp
);
5386 args
= asdl_seq_new(len
, arena
);
5387 if (args
== NULL
) goto failed
;
5388 for (i
= 0; i
< len
; i
++) {
5390 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5391 if (res
!= 0) goto failed
;
5392 asdl_seq_SET(args
, i
, value
);
5397 PyErr_SetString(PyExc_TypeError
, "required field \"args\" missing from Call");
5400 if (PyObject_HasAttrString(obj
, "keywords")) {
5404 tmp
= PyObject_GetAttrString(obj
, "keywords");
5405 if (tmp
== NULL
) goto failed
;
5406 if (!PyList_Check(tmp
)) {
5407 PyErr_Format(PyExc_TypeError
, "Call field \"keywords\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5410 len
= PyList_GET_SIZE(tmp
);
5411 keywords
= asdl_seq_new(len
, arena
);
5412 if (keywords
== NULL
) goto failed
;
5413 for (i
= 0; i
< len
; i
++) {
5415 res
= obj2ast_keyword(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5416 if (res
!= 0) goto failed
;
5417 asdl_seq_SET(keywords
, i
, value
);
5422 PyErr_SetString(PyExc_TypeError
, "required field \"keywords\" missing from Call");
5425 if (PyObject_HasAttrString(obj
, "starargs")) {
5427 tmp
= PyObject_GetAttrString(obj
, "starargs");
5428 if (tmp
== NULL
) goto failed
;
5429 res
= obj2ast_expr(tmp
, &starargs
, arena
);
5430 if (res
!= 0) goto failed
;
5436 if (PyObject_HasAttrString(obj
, "kwargs")) {
5438 tmp
= PyObject_GetAttrString(obj
, "kwargs");
5439 if (tmp
== NULL
) goto failed
;
5440 res
= obj2ast_expr(tmp
, &kwargs
, arena
);
5441 if (res
!= 0) goto failed
;
5447 *out
= Call(func
, args
, keywords
, starargs
, kwargs
, lineno
,
5449 if (*out
== NULL
) goto failed
;
5452 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Repr_type
);
5453 if (isinstance
== -1) {
5459 if (PyObject_HasAttrString(obj
, "value")) {
5461 tmp
= PyObject_GetAttrString(obj
, "value");
5462 if (tmp
== NULL
) goto failed
;
5463 res
= obj2ast_expr(tmp
, &value
, arena
);
5464 if (res
!= 0) goto failed
;
5468 PyErr_SetString(PyExc_TypeError
, "required field \"value\" missing from Repr");
5471 *out
= Repr(value
, lineno
, col_offset
, arena
);
5472 if (*out
== NULL
) goto failed
;
5475 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Num_type
);
5476 if (isinstance
== -1) {
5482 if (PyObject_HasAttrString(obj
, "n")) {
5484 tmp
= PyObject_GetAttrString(obj
, "n");
5485 if (tmp
== NULL
) goto failed
;
5486 res
= obj2ast_object(tmp
, &n
, arena
);
5487 if (res
!= 0) goto failed
;
5491 PyErr_SetString(PyExc_TypeError
, "required field \"n\" missing from Num");
5494 *out
= Num(n
, lineno
, col_offset
, arena
);
5495 if (*out
== NULL
) goto failed
;
5498 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Str_type
);
5499 if (isinstance
== -1) {
5505 if (PyObject_HasAttrString(obj
, "s")) {
5507 tmp
= PyObject_GetAttrString(obj
, "s");
5508 if (tmp
== NULL
) goto failed
;
5509 res
= obj2ast_string(tmp
, &s
, arena
);
5510 if (res
!= 0) goto failed
;
5514 PyErr_SetString(PyExc_TypeError
, "required field \"s\" missing from Str");
5517 *out
= Str(s
, lineno
, col_offset
, arena
);
5518 if (*out
== NULL
) goto failed
;
5521 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Attribute_type
);
5522 if (isinstance
== -1) {
5528 expr_context_ty ctx
;
5530 if (PyObject_HasAttrString(obj
, "value")) {
5532 tmp
= PyObject_GetAttrString(obj
, "value");
5533 if (tmp
== NULL
) goto failed
;
5534 res
= obj2ast_expr(tmp
, &value
, arena
);
5535 if (res
!= 0) goto failed
;
5539 PyErr_SetString(PyExc_TypeError
, "required field \"value\" missing from Attribute");
5542 if (PyObject_HasAttrString(obj
, "attr")) {
5544 tmp
= PyObject_GetAttrString(obj
, "attr");
5545 if (tmp
== NULL
) goto failed
;
5546 res
= obj2ast_identifier(tmp
, &attr
, arena
);
5547 if (res
!= 0) goto failed
;
5551 PyErr_SetString(PyExc_TypeError
, "required field \"attr\" missing from Attribute");
5554 if (PyObject_HasAttrString(obj
, "ctx")) {
5556 tmp
= PyObject_GetAttrString(obj
, "ctx");
5557 if (tmp
== NULL
) goto failed
;
5558 res
= obj2ast_expr_context(tmp
, &ctx
, arena
);
5559 if (res
!= 0) goto failed
;
5563 PyErr_SetString(PyExc_TypeError
, "required field \"ctx\" missing from Attribute");
5566 *out
= Attribute(value
, attr
, ctx
, lineno
, col_offset
, arena
);
5567 if (*out
== NULL
) goto failed
;
5570 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Subscript_type
);
5571 if (isinstance
== -1) {
5577 expr_context_ty ctx
;
5579 if (PyObject_HasAttrString(obj
, "value")) {
5581 tmp
= PyObject_GetAttrString(obj
, "value");
5582 if (tmp
== NULL
) goto failed
;
5583 res
= obj2ast_expr(tmp
, &value
, arena
);
5584 if (res
!= 0) goto failed
;
5588 PyErr_SetString(PyExc_TypeError
, "required field \"value\" missing from Subscript");
5591 if (PyObject_HasAttrString(obj
, "slice")) {
5593 tmp
= PyObject_GetAttrString(obj
, "slice");
5594 if (tmp
== NULL
) goto failed
;
5595 res
= obj2ast_slice(tmp
, &slice
, arena
);
5596 if (res
!= 0) goto failed
;
5600 PyErr_SetString(PyExc_TypeError
, "required field \"slice\" missing from Subscript");
5603 if (PyObject_HasAttrString(obj
, "ctx")) {
5605 tmp
= PyObject_GetAttrString(obj
, "ctx");
5606 if (tmp
== NULL
) goto failed
;
5607 res
= obj2ast_expr_context(tmp
, &ctx
, arena
);
5608 if (res
!= 0) goto failed
;
5612 PyErr_SetString(PyExc_TypeError
, "required field \"ctx\" missing from Subscript");
5615 *out
= Subscript(value
, slice
, ctx
, lineno
, col_offset
, arena
);
5616 if (*out
== NULL
) goto failed
;
5619 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Name_type
);
5620 if (isinstance
== -1) {
5625 expr_context_ty ctx
;
5627 if (PyObject_HasAttrString(obj
, "id")) {
5629 tmp
= PyObject_GetAttrString(obj
, "id");
5630 if (tmp
== NULL
) goto failed
;
5631 res
= obj2ast_identifier(tmp
, &id
, arena
);
5632 if (res
!= 0) goto failed
;
5636 PyErr_SetString(PyExc_TypeError
, "required field \"id\" missing from Name");
5639 if (PyObject_HasAttrString(obj
, "ctx")) {
5641 tmp
= PyObject_GetAttrString(obj
, "ctx");
5642 if (tmp
== NULL
) goto failed
;
5643 res
= obj2ast_expr_context(tmp
, &ctx
, arena
);
5644 if (res
!= 0) goto failed
;
5648 PyErr_SetString(PyExc_TypeError
, "required field \"ctx\" missing from Name");
5651 *out
= Name(id
, ctx
, lineno
, col_offset
, arena
);
5652 if (*out
== NULL
) goto failed
;
5655 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)List_type
);
5656 if (isinstance
== -1) {
5661 expr_context_ty ctx
;
5663 if (PyObject_HasAttrString(obj
, "elts")) {
5667 tmp
= PyObject_GetAttrString(obj
, "elts");
5668 if (tmp
== NULL
) goto failed
;
5669 if (!PyList_Check(tmp
)) {
5670 PyErr_Format(PyExc_TypeError
, "List field \"elts\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5673 len
= PyList_GET_SIZE(tmp
);
5674 elts
= asdl_seq_new(len
, arena
);
5675 if (elts
== NULL
) goto failed
;
5676 for (i
= 0; i
< len
; i
++) {
5678 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5679 if (res
!= 0) goto failed
;
5680 asdl_seq_SET(elts
, i
, value
);
5685 PyErr_SetString(PyExc_TypeError
, "required field \"elts\" missing from List");
5688 if (PyObject_HasAttrString(obj
, "ctx")) {
5690 tmp
= PyObject_GetAttrString(obj
, "ctx");
5691 if (tmp
== NULL
) goto failed
;
5692 res
= obj2ast_expr_context(tmp
, &ctx
, arena
);
5693 if (res
!= 0) goto failed
;
5697 PyErr_SetString(PyExc_TypeError
, "required field \"ctx\" missing from List");
5700 *out
= List(elts
, ctx
, lineno
, col_offset
, arena
);
5701 if (*out
== NULL
) goto failed
;
5704 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Tuple_type
);
5705 if (isinstance
== -1) {
5710 expr_context_ty ctx
;
5712 if (PyObject_HasAttrString(obj
, "elts")) {
5716 tmp
= PyObject_GetAttrString(obj
, "elts");
5717 if (tmp
== NULL
) goto failed
;
5718 if (!PyList_Check(tmp
)) {
5719 PyErr_Format(PyExc_TypeError
, "Tuple field \"elts\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5722 len
= PyList_GET_SIZE(tmp
);
5723 elts
= asdl_seq_new(len
, arena
);
5724 if (elts
== NULL
) goto failed
;
5725 for (i
= 0; i
< len
; i
++) {
5727 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5728 if (res
!= 0) goto failed
;
5729 asdl_seq_SET(elts
, i
, value
);
5734 PyErr_SetString(PyExc_TypeError
, "required field \"elts\" missing from Tuple");
5737 if (PyObject_HasAttrString(obj
, "ctx")) {
5739 tmp
= PyObject_GetAttrString(obj
, "ctx");
5740 if (tmp
== NULL
) goto failed
;
5741 res
= obj2ast_expr_context(tmp
, &ctx
, arena
);
5742 if (res
!= 0) goto failed
;
5746 PyErr_SetString(PyExc_TypeError
, "required field \"ctx\" missing from Tuple");
5749 *out
= Tuple(elts
, ctx
, lineno
, col_offset
, arena
);
5750 if (*out
== NULL
) goto failed
;
5754 tmp
= PyObject_Repr(obj
);
5755 if (tmp
== NULL
) goto failed
;
5756 PyErr_Format(PyExc_TypeError
, "expected some sort of expr, but got %.400s", PyString_AS_STRING(tmp
));
5763 obj2ast_expr_context(PyObject
* obj
, expr_context_ty
* out
, PyArena
* arena
)
5765 PyObject
* tmp
= NULL
;
5768 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Load_type
);
5769 if (isinstance
== -1) {
5776 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Store_type
);
5777 if (isinstance
== -1) {
5784 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Del_type
);
5785 if (isinstance
== -1) {
5792 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)AugLoad_type
);
5793 if (isinstance
== -1) {
5800 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)AugStore_type
);
5801 if (isinstance
== -1) {
5808 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Param_type
);
5809 if (isinstance
== -1) {
5817 tmp
= PyObject_Repr(obj
);
5818 if (tmp
== NULL
) goto failed
;
5819 PyErr_Format(PyExc_TypeError
, "expected some sort of expr_context, but got %.400s", PyString_AS_STRING(tmp
));
5826 obj2ast_slice(PyObject
* obj
, slice_ty
* out
, PyArena
* arena
)
5828 PyObject
* tmp
= NULL
;
5832 if (obj
== Py_None
) {
5836 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Ellipsis_type
);
5837 if (isinstance
== -1) {
5842 *out
= Ellipsis(arena
);
5843 if (*out
== NULL
) goto failed
;
5846 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Slice_type
);
5847 if (isinstance
== -1) {
5855 if (PyObject_HasAttrString(obj
, "lower")) {
5857 tmp
= PyObject_GetAttrString(obj
, "lower");
5858 if (tmp
== NULL
) goto failed
;
5859 res
= obj2ast_expr(tmp
, &lower
, arena
);
5860 if (res
!= 0) goto failed
;
5866 if (PyObject_HasAttrString(obj
, "upper")) {
5868 tmp
= PyObject_GetAttrString(obj
, "upper");
5869 if (tmp
== NULL
) goto failed
;
5870 res
= obj2ast_expr(tmp
, &upper
, arena
);
5871 if (res
!= 0) goto failed
;
5877 if (PyObject_HasAttrString(obj
, "step")) {
5879 tmp
= PyObject_GetAttrString(obj
, "step");
5880 if (tmp
== NULL
) goto failed
;
5881 res
= obj2ast_expr(tmp
, &step
, arena
);
5882 if (res
!= 0) goto failed
;
5888 *out
= Slice(lower
, upper
, step
, arena
);
5889 if (*out
== NULL
) goto failed
;
5892 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)ExtSlice_type
);
5893 if (isinstance
== -1) {
5899 if (PyObject_HasAttrString(obj
, "dims")) {
5903 tmp
= PyObject_GetAttrString(obj
, "dims");
5904 if (tmp
== NULL
) goto failed
;
5905 if (!PyList_Check(tmp
)) {
5906 PyErr_Format(PyExc_TypeError
, "ExtSlice field \"dims\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5909 len
= PyList_GET_SIZE(tmp
);
5910 dims
= asdl_seq_new(len
, arena
);
5911 if (dims
== NULL
) goto failed
;
5912 for (i
= 0; i
< len
; i
++) {
5914 res
= obj2ast_slice(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5915 if (res
!= 0) goto failed
;
5916 asdl_seq_SET(dims
, i
, value
);
5921 PyErr_SetString(PyExc_TypeError
, "required field \"dims\" missing from ExtSlice");
5924 *out
= ExtSlice(dims
, arena
);
5925 if (*out
== NULL
) goto failed
;
5928 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Index_type
);
5929 if (isinstance
== -1) {
5935 if (PyObject_HasAttrString(obj
, "value")) {
5937 tmp
= PyObject_GetAttrString(obj
, "value");
5938 if (tmp
== NULL
) goto failed
;
5939 res
= obj2ast_expr(tmp
, &value
, arena
);
5940 if (res
!= 0) goto failed
;
5944 PyErr_SetString(PyExc_TypeError
, "required field \"value\" missing from Index");
5947 *out
= Index(value
, arena
);
5948 if (*out
== NULL
) goto failed
;
5952 tmp
= PyObject_Repr(obj
);
5953 if (tmp
== NULL
) goto failed
;
5954 PyErr_Format(PyExc_TypeError
, "expected some sort of slice, but got %.400s", PyString_AS_STRING(tmp
));
5961 obj2ast_boolop(PyObject
* obj
, boolop_ty
* out
, PyArena
* arena
)
5963 PyObject
* tmp
= NULL
;
5966 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)And_type
);
5967 if (isinstance
== -1) {
5974 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Or_type
);
5975 if (isinstance
== -1) {
5983 tmp
= PyObject_Repr(obj
);
5984 if (tmp
== NULL
) goto failed
;
5985 PyErr_Format(PyExc_TypeError
, "expected some sort of boolop, but got %.400s", PyString_AS_STRING(tmp
));
5992 obj2ast_operator(PyObject
* obj
, operator_ty
* out
, PyArena
* arena
)
5994 PyObject
* tmp
= NULL
;
5997 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Add_type
);
5998 if (isinstance
== -1) {
6005 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Sub_type
);
6006 if (isinstance
== -1) {
6013 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Mult_type
);
6014 if (isinstance
== -1) {
6021 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Div_type
);
6022 if (isinstance
== -1) {
6029 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Mod_type
);
6030 if (isinstance
== -1) {
6037 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Pow_type
);
6038 if (isinstance
== -1) {
6045 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)LShift_type
);
6046 if (isinstance
== -1) {
6053 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)RShift_type
);
6054 if (isinstance
== -1) {
6061 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)BitOr_type
);
6062 if (isinstance
== -1) {
6069 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)BitXor_type
);
6070 if (isinstance
== -1) {
6077 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)BitAnd_type
);
6078 if (isinstance
== -1) {
6085 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)FloorDiv_type
);
6086 if (isinstance
== -1) {
6094 tmp
= PyObject_Repr(obj
);
6095 if (tmp
== NULL
) goto failed
;
6096 PyErr_Format(PyExc_TypeError
, "expected some sort of operator, but got %.400s", PyString_AS_STRING(tmp
));
6103 obj2ast_unaryop(PyObject
* obj
, unaryop_ty
* out
, PyArena
* arena
)
6105 PyObject
* tmp
= NULL
;
6108 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Invert_type
);
6109 if (isinstance
== -1) {
6116 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Not_type
);
6117 if (isinstance
== -1) {
6124 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)UAdd_type
);
6125 if (isinstance
== -1) {
6132 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)USub_type
);
6133 if (isinstance
== -1) {
6141 tmp
= PyObject_Repr(obj
);
6142 if (tmp
== NULL
) goto failed
;
6143 PyErr_Format(PyExc_TypeError
, "expected some sort of unaryop, but got %.400s", PyString_AS_STRING(tmp
));
6150 obj2ast_cmpop(PyObject
* obj
, cmpop_ty
* out
, PyArena
* arena
)
6152 PyObject
* tmp
= NULL
;
6155 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Eq_type
);
6156 if (isinstance
== -1) {
6163 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)NotEq_type
);
6164 if (isinstance
== -1) {
6171 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Lt_type
);
6172 if (isinstance
== -1) {
6179 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)LtE_type
);
6180 if (isinstance
== -1) {
6187 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Gt_type
);
6188 if (isinstance
== -1) {
6195 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)GtE_type
);
6196 if (isinstance
== -1) {
6203 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Is_type
);
6204 if (isinstance
== -1) {
6211 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)IsNot_type
);
6212 if (isinstance
== -1) {
6219 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)In_type
);
6220 if (isinstance
== -1) {
6227 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)NotIn_type
);
6228 if (isinstance
== -1) {
6236 tmp
= PyObject_Repr(obj
);
6237 if (tmp
== NULL
) goto failed
;
6238 PyErr_Format(PyExc_TypeError
, "expected some sort of cmpop, but got %.400s", PyString_AS_STRING(tmp
));
6245 obj2ast_comprehension(PyObject
* obj
, comprehension_ty
* out
, PyArena
* arena
)
6247 PyObject
* tmp
= NULL
;
6252 if (PyObject_HasAttrString(obj
, "target")) {
6254 tmp
= PyObject_GetAttrString(obj
, "target");
6255 if (tmp
== NULL
) goto failed
;
6256 res
= obj2ast_expr(tmp
, &target
, arena
);
6257 if (res
!= 0) goto failed
;
6261 PyErr_SetString(PyExc_TypeError
, "required field \"target\" missing from comprehension");
6264 if (PyObject_HasAttrString(obj
, "iter")) {
6266 tmp
= PyObject_GetAttrString(obj
, "iter");
6267 if (tmp
== NULL
) goto failed
;
6268 res
= obj2ast_expr(tmp
, &iter
, arena
);
6269 if (res
!= 0) goto failed
;
6273 PyErr_SetString(PyExc_TypeError
, "required field \"iter\" missing from comprehension");
6276 if (PyObject_HasAttrString(obj
, "ifs")) {
6280 tmp
= PyObject_GetAttrString(obj
, "ifs");
6281 if (tmp
== NULL
) goto failed
;
6282 if (!PyList_Check(tmp
)) {
6283 PyErr_Format(PyExc_TypeError
, "comprehension field \"ifs\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
6286 len
= PyList_GET_SIZE(tmp
);
6287 ifs
= asdl_seq_new(len
, arena
);
6288 if (ifs
== NULL
) goto failed
;
6289 for (i
= 0; i
< len
; i
++) {
6291 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
6292 if (res
!= 0) goto failed
;
6293 asdl_seq_SET(ifs
, i
, value
);
6298 PyErr_SetString(PyExc_TypeError
, "required field \"ifs\" missing from comprehension");
6301 *out
= comprehension(target
, iter
, ifs
, arena
);
6309 obj2ast_excepthandler(PyObject
* obj
, excepthandler_ty
* out
, PyArena
* arena
)
6311 PyObject
* tmp
= NULL
;
6317 if (obj
== Py_None
) {
6321 if (PyObject_HasAttrString(obj
, "lineno")) {
6323 tmp
= PyObject_GetAttrString(obj
, "lineno");
6324 if (tmp
== NULL
) goto failed
;
6325 res
= obj2ast_int(tmp
, &lineno
, arena
);
6326 if (res
!= 0) goto failed
;
6330 PyErr_SetString(PyExc_TypeError
, "required field \"lineno\" missing from excepthandler");
6333 if (PyObject_HasAttrString(obj
, "col_offset")) {
6335 tmp
= PyObject_GetAttrString(obj
, "col_offset");
6336 if (tmp
== NULL
) goto failed
;
6337 res
= obj2ast_int(tmp
, &col_offset
, arena
);
6338 if (res
!= 0) goto failed
;
6342 PyErr_SetString(PyExc_TypeError
, "required field \"col_offset\" missing from excepthandler");
6345 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)ExceptHandler_type
);
6346 if (isinstance
== -1) {
6354 if (PyObject_HasAttrString(obj
, "type")) {
6356 tmp
= PyObject_GetAttrString(obj
, "type");
6357 if (tmp
== NULL
) goto failed
;
6358 res
= obj2ast_expr(tmp
, &type
, arena
);
6359 if (res
!= 0) goto failed
;
6365 if (PyObject_HasAttrString(obj
, "name")) {
6367 tmp
= PyObject_GetAttrString(obj
, "name");
6368 if (tmp
== NULL
) goto failed
;
6369 res
= obj2ast_expr(tmp
, &name
, arena
);
6370 if (res
!= 0) goto failed
;
6376 if (PyObject_HasAttrString(obj
, "body")) {
6380 tmp
= PyObject_GetAttrString(obj
, "body");
6381 if (tmp
== NULL
) goto failed
;
6382 if (!PyList_Check(tmp
)) {
6383 PyErr_Format(PyExc_TypeError
, "ExceptHandler field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
6386 len
= PyList_GET_SIZE(tmp
);
6387 body
= asdl_seq_new(len
, arena
);
6388 if (body
== NULL
) goto failed
;
6389 for (i
= 0; i
< len
; i
++) {
6391 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
6392 if (res
!= 0) goto failed
;
6393 asdl_seq_SET(body
, i
, value
);
6398 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from ExceptHandler");
6401 *out
= ExceptHandler(type
, name
, body
, lineno
, col_offset
,
6403 if (*out
== NULL
) goto failed
;
6407 tmp
= PyObject_Repr(obj
);
6408 if (tmp
== NULL
) goto failed
;
6409 PyErr_Format(PyExc_TypeError
, "expected some sort of excepthandler, but got %.400s", PyString_AS_STRING(tmp
));
6416 obj2ast_arguments(PyObject
* obj
, arguments_ty
* out
, PyArena
* arena
)
6418 PyObject
* tmp
= NULL
;
6424 if (PyObject_HasAttrString(obj
, "args")) {
6428 tmp
= PyObject_GetAttrString(obj
, "args");
6429 if (tmp
== NULL
) goto failed
;
6430 if (!PyList_Check(tmp
)) {
6431 PyErr_Format(PyExc_TypeError
, "arguments field \"args\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
6434 len
= PyList_GET_SIZE(tmp
);
6435 args
= asdl_seq_new(len
, arena
);
6436 if (args
== NULL
) goto failed
;
6437 for (i
= 0; i
< len
; i
++) {
6439 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
6440 if (res
!= 0) goto failed
;
6441 asdl_seq_SET(args
, i
, value
);
6446 PyErr_SetString(PyExc_TypeError
, "required field \"args\" missing from arguments");
6449 if (PyObject_HasAttrString(obj
, "vararg")) {
6451 tmp
= PyObject_GetAttrString(obj
, "vararg");
6452 if (tmp
== NULL
) goto failed
;
6453 res
= obj2ast_identifier(tmp
, &vararg
, arena
);
6454 if (res
!= 0) goto failed
;
6460 if (PyObject_HasAttrString(obj
, "kwarg")) {
6462 tmp
= PyObject_GetAttrString(obj
, "kwarg");
6463 if (tmp
== NULL
) goto failed
;
6464 res
= obj2ast_identifier(tmp
, &kwarg
, arena
);
6465 if (res
!= 0) goto failed
;
6471 if (PyObject_HasAttrString(obj
, "defaults")) {
6475 tmp
= PyObject_GetAttrString(obj
, "defaults");
6476 if (tmp
== NULL
) goto failed
;
6477 if (!PyList_Check(tmp
)) {
6478 PyErr_Format(PyExc_TypeError
, "arguments field \"defaults\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
6481 len
= PyList_GET_SIZE(tmp
);
6482 defaults
= asdl_seq_new(len
, arena
);
6483 if (defaults
== NULL
) goto failed
;
6484 for (i
= 0; i
< len
; i
++) {
6486 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
6487 if (res
!= 0) goto failed
;
6488 asdl_seq_SET(defaults
, i
, value
);
6493 PyErr_SetString(PyExc_TypeError
, "required field \"defaults\" missing from arguments");
6496 *out
= arguments(args
, vararg
, kwarg
, defaults
, arena
);
6504 obj2ast_keyword(PyObject
* obj
, keyword_ty
* out
, PyArena
* arena
)
6506 PyObject
* tmp
= NULL
;
6510 if (PyObject_HasAttrString(obj
, "arg")) {
6512 tmp
= PyObject_GetAttrString(obj
, "arg");
6513 if (tmp
== NULL
) goto failed
;
6514 res
= obj2ast_identifier(tmp
, &arg
, arena
);
6515 if (res
!= 0) goto failed
;
6519 PyErr_SetString(PyExc_TypeError
, "required field \"arg\" missing from keyword");
6522 if (PyObject_HasAttrString(obj
, "value")) {
6524 tmp
= PyObject_GetAttrString(obj
, "value");
6525 if (tmp
== NULL
) goto failed
;
6526 res
= obj2ast_expr(tmp
, &value
, arena
);
6527 if (res
!= 0) goto failed
;
6531 PyErr_SetString(PyExc_TypeError
, "required field \"value\" missing from keyword");
6534 *out
= keyword(arg
, value
, arena
);
6542 obj2ast_alias(PyObject
* obj
, alias_ty
* out
, PyArena
* arena
)
6544 PyObject
* tmp
= NULL
;
6548 if (PyObject_HasAttrString(obj
, "name")) {
6550 tmp
= PyObject_GetAttrString(obj
, "name");
6551 if (tmp
== NULL
) goto failed
;
6552 res
= obj2ast_identifier(tmp
, &name
, arena
);
6553 if (res
!= 0) goto failed
;
6557 PyErr_SetString(PyExc_TypeError
, "required field \"name\" missing from alias");
6560 if (PyObject_HasAttrString(obj
, "asname")) {
6562 tmp
= PyObject_GetAttrString(obj
, "asname");
6563 if (tmp
== NULL
) goto failed
;
6564 res
= obj2ast_identifier(tmp
, &asname
, arena
);
6565 if (res
!= 0) goto failed
;
6571 *out
= alias(name
, asname
, arena
);
6583 if (!init_types()) return;
6584 m
= Py_InitModule3("_ast", NULL
, NULL
);
6586 d
= PyModule_GetDict(m
);
6587 if (PyDict_SetItemString(d
, "AST", (PyObject
*)&AST_type
) < 0) return;
6588 if (PyModule_AddIntConstant(m
, "PyCF_ONLY_AST", PyCF_ONLY_AST
) < 0)
6590 if (PyModule_AddStringConstant(m
, "__version__", "82160") < 0)
6592 if (PyDict_SetItemString(d
, "mod", (PyObject
*)mod_type
) < 0) return;
6593 if (PyDict_SetItemString(d
, "Module", (PyObject
*)Module_type
) < 0)
6595 if (PyDict_SetItemString(d
, "Interactive", (PyObject
*)Interactive_type
)
6597 if (PyDict_SetItemString(d
, "Expression", (PyObject
*)Expression_type
) <
6599 if (PyDict_SetItemString(d
, "Suite", (PyObject
*)Suite_type
) < 0) return;
6600 if (PyDict_SetItemString(d
, "stmt", (PyObject
*)stmt_type
) < 0) return;
6601 if (PyDict_SetItemString(d
, "FunctionDef", (PyObject
*)FunctionDef_type
)
6603 if (PyDict_SetItemString(d
, "ClassDef", (PyObject
*)ClassDef_type
) < 0)
6605 if (PyDict_SetItemString(d
, "Return", (PyObject
*)Return_type
) < 0)
6607 if (PyDict_SetItemString(d
, "Delete", (PyObject
*)Delete_type
) < 0)
6609 if (PyDict_SetItemString(d
, "Assign", (PyObject
*)Assign_type
) < 0)
6611 if (PyDict_SetItemString(d
, "AugAssign", (PyObject
*)AugAssign_type
) <
6613 if (PyDict_SetItemString(d
, "Print", (PyObject
*)Print_type
) < 0) return;
6614 if (PyDict_SetItemString(d
, "For", (PyObject
*)For_type
) < 0) return;
6615 if (PyDict_SetItemString(d
, "While", (PyObject
*)While_type
) < 0) return;
6616 if (PyDict_SetItemString(d
, "If", (PyObject
*)If_type
) < 0) return;
6617 if (PyDict_SetItemString(d
, "With", (PyObject
*)With_type
) < 0) return;
6618 if (PyDict_SetItemString(d
, "Raise", (PyObject
*)Raise_type
) < 0) return;
6619 if (PyDict_SetItemString(d
, "TryExcept", (PyObject
*)TryExcept_type
) <
6621 if (PyDict_SetItemString(d
, "TryFinally", (PyObject
*)TryFinally_type
) <
6623 if (PyDict_SetItemString(d
, "Assert", (PyObject
*)Assert_type
) < 0)
6625 if (PyDict_SetItemString(d
, "Import", (PyObject
*)Import_type
) < 0)
6627 if (PyDict_SetItemString(d
, "ImportFrom", (PyObject
*)ImportFrom_type
) <
6629 if (PyDict_SetItemString(d
, "Exec", (PyObject
*)Exec_type
) < 0) return;
6630 if (PyDict_SetItemString(d
, "Global", (PyObject
*)Global_type
) < 0)
6632 if (PyDict_SetItemString(d
, "Expr", (PyObject
*)Expr_type
) < 0) return;
6633 if (PyDict_SetItemString(d
, "Pass", (PyObject
*)Pass_type
) < 0) return;
6634 if (PyDict_SetItemString(d
, "Break", (PyObject
*)Break_type
) < 0) return;
6635 if (PyDict_SetItemString(d
, "Continue", (PyObject
*)Continue_type
) < 0)
6637 if (PyDict_SetItemString(d
, "expr", (PyObject
*)expr_type
) < 0) return;
6638 if (PyDict_SetItemString(d
, "BoolOp", (PyObject
*)BoolOp_type
) < 0)
6640 if (PyDict_SetItemString(d
, "BinOp", (PyObject
*)BinOp_type
) < 0) return;
6641 if (PyDict_SetItemString(d
, "UnaryOp", (PyObject
*)UnaryOp_type
) < 0)
6643 if (PyDict_SetItemString(d
, "Lambda", (PyObject
*)Lambda_type
) < 0)
6645 if (PyDict_SetItemString(d
, "IfExp", (PyObject
*)IfExp_type
) < 0) return;
6646 if (PyDict_SetItemString(d
, "Dict", (PyObject
*)Dict_type
) < 0) return;
6647 if (PyDict_SetItemString(d
, "Set", (PyObject
*)Set_type
) < 0) return;
6648 if (PyDict_SetItemString(d
, "ListComp", (PyObject
*)ListComp_type
) < 0)
6650 if (PyDict_SetItemString(d
, "SetComp", (PyObject
*)SetComp_type
) < 0)
6652 if (PyDict_SetItemString(d
, "DictComp", (PyObject
*)DictComp_type
) < 0)
6654 if (PyDict_SetItemString(d
, "GeneratorExp",
6655 (PyObject
*)GeneratorExp_type
) < 0) return;
6656 if (PyDict_SetItemString(d
, "Yield", (PyObject
*)Yield_type
) < 0) return;
6657 if (PyDict_SetItemString(d
, "Compare", (PyObject
*)Compare_type
) < 0)
6659 if (PyDict_SetItemString(d
, "Call", (PyObject
*)Call_type
) < 0) return;
6660 if (PyDict_SetItemString(d
, "Repr", (PyObject
*)Repr_type
) < 0) return;
6661 if (PyDict_SetItemString(d
, "Num", (PyObject
*)Num_type
) < 0) return;
6662 if (PyDict_SetItemString(d
, "Str", (PyObject
*)Str_type
) < 0) return;
6663 if (PyDict_SetItemString(d
, "Attribute", (PyObject
*)Attribute_type
) <
6665 if (PyDict_SetItemString(d
, "Subscript", (PyObject
*)Subscript_type
) <
6667 if (PyDict_SetItemString(d
, "Name", (PyObject
*)Name_type
) < 0) return;
6668 if (PyDict_SetItemString(d
, "List", (PyObject
*)List_type
) < 0) return;
6669 if (PyDict_SetItemString(d
, "Tuple", (PyObject
*)Tuple_type
) < 0) return;
6670 if (PyDict_SetItemString(d
, "expr_context",
6671 (PyObject
*)expr_context_type
) < 0) return;
6672 if (PyDict_SetItemString(d
, "Load", (PyObject
*)Load_type
) < 0) return;
6673 if (PyDict_SetItemString(d
, "Store", (PyObject
*)Store_type
) < 0) return;
6674 if (PyDict_SetItemString(d
, "Del", (PyObject
*)Del_type
) < 0) return;
6675 if (PyDict_SetItemString(d
, "AugLoad", (PyObject
*)AugLoad_type
) < 0)
6677 if (PyDict_SetItemString(d
, "AugStore", (PyObject
*)AugStore_type
) < 0)
6679 if (PyDict_SetItemString(d
, "Param", (PyObject
*)Param_type
) < 0) return;
6680 if (PyDict_SetItemString(d
, "slice", (PyObject
*)slice_type
) < 0) return;
6681 if (PyDict_SetItemString(d
, "Ellipsis", (PyObject
*)Ellipsis_type
) < 0)
6683 if (PyDict_SetItemString(d
, "Slice", (PyObject
*)Slice_type
) < 0) return;
6684 if (PyDict_SetItemString(d
, "ExtSlice", (PyObject
*)ExtSlice_type
) < 0)
6686 if (PyDict_SetItemString(d
, "Index", (PyObject
*)Index_type
) < 0) return;
6687 if (PyDict_SetItemString(d
, "boolop", (PyObject
*)boolop_type
) < 0)
6689 if (PyDict_SetItemString(d
, "And", (PyObject
*)And_type
) < 0) return;
6690 if (PyDict_SetItemString(d
, "Or", (PyObject
*)Or_type
) < 0) return;
6691 if (PyDict_SetItemString(d
, "operator", (PyObject
*)operator_type
) < 0)
6693 if (PyDict_SetItemString(d
, "Add", (PyObject
*)Add_type
) < 0) return;
6694 if (PyDict_SetItemString(d
, "Sub", (PyObject
*)Sub_type
) < 0) return;
6695 if (PyDict_SetItemString(d
, "Mult", (PyObject
*)Mult_type
) < 0) return;
6696 if (PyDict_SetItemString(d
, "Div", (PyObject
*)Div_type
) < 0) return;
6697 if (PyDict_SetItemString(d
, "Mod", (PyObject
*)Mod_type
) < 0) return;
6698 if (PyDict_SetItemString(d
, "Pow", (PyObject
*)Pow_type
) < 0) return;
6699 if (PyDict_SetItemString(d
, "LShift", (PyObject
*)LShift_type
) < 0)
6701 if (PyDict_SetItemString(d
, "RShift", (PyObject
*)RShift_type
) < 0)
6703 if (PyDict_SetItemString(d
, "BitOr", (PyObject
*)BitOr_type
) < 0) return;
6704 if (PyDict_SetItemString(d
, "BitXor", (PyObject
*)BitXor_type
) < 0)
6706 if (PyDict_SetItemString(d
, "BitAnd", (PyObject
*)BitAnd_type
) < 0)
6708 if (PyDict_SetItemString(d
, "FloorDiv", (PyObject
*)FloorDiv_type
) < 0)
6710 if (PyDict_SetItemString(d
, "unaryop", (PyObject
*)unaryop_type
) < 0)
6712 if (PyDict_SetItemString(d
, "Invert", (PyObject
*)Invert_type
) < 0)
6714 if (PyDict_SetItemString(d
, "Not", (PyObject
*)Not_type
) < 0) return;
6715 if (PyDict_SetItemString(d
, "UAdd", (PyObject
*)UAdd_type
) < 0) return;
6716 if (PyDict_SetItemString(d
, "USub", (PyObject
*)USub_type
) < 0) return;
6717 if (PyDict_SetItemString(d
, "cmpop", (PyObject
*)cmpop_type
) < 0) return;
6718 if (PyDict_SetItemString(d
, "Eq", (PyObject
*)Eq_type
) < 0) return;
6719 if (PyDict_SetItemString(d
, "NotEq", (PyObject
*)NotEq_type
) < 0) return;
6720 if (PyDict_SetItemString(d
, "Lt", (PyObject
*)Lt_type
) < 0) return;
6721 if (PyDict_SetItemString(d
, "LtE", (PyObject
*)LtE_type
) < 0) return;
6722 if (PyDict_SetItemString(d
, "Gt", (PyObject
*)Gt_type
) < 0) return;
6723 if (PyDict_SetItemString(d
, "GtE", (PyObject
*)GtE_type
) < 0) return;
6724 if (PyDict_SetItemString(d
, "Is", (PyObject
*)Is_type
) < 0) return;
6725 if (PyDict_SetItemString(d
, "IsNot", (PyObject
*)IsNot_type
) < 0) return;
6726 if (PyDict_SetItemString(d
, "In", (PyObject
*)In_type
) < 0) return;
6727 if (PyDict_SetItemString(d
, "NotIn", (PyObject
*)NotIn_type
) < 0) return;
6728 if (PyDict_SetItemString(d
, "comprehension",
6729 (PyObject
*)comprehension_type
) < 0) return;
6730 if (PyDict_SetItemString(d
, "excepthandler",
6731 (PyObject
*)excepthandler_type
) < 0) return;
6732 if (PyDict_SetItemString(d
, "ExceptHandler",
6733 (PyObject
*)ExceptHandler_type
) < 0) return;
6734 if (PyDict_SetItemString(d
, "arguments", (PyObject
*)arguments_type
) <
6736 if (PyDict_SetItemString(d
, "keyword", (PyObject
*)keyword_type
) < 0)
6738 if (PyDict_SetItemString(d
, "alias", (PyObject
*)alias_type
) < 0) return;
6742 PyObject
* PyAST_mod2obj(mod_ty t
)
6745 return ast2obj_mod(t
);
6748 /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */
6749 mod_ty
PyAST_obj2mod(PyObject
* ast
, PyArena
* arena
, int mode
)
6752 PyObject
*req_type
[3];
6756 req_type
[0] = (PyObject
*)Module_type
;
6757 req_type
[1] = (PyObject
*)Expression_type
;
6758 req_type
[2] = (PyObject
*)Interactive_type
;
6760 req_name
[0] = "Module";
6761 req_name
[1] = "Expression";
6762 req_name
[2] = "Interactive";
6764 assert(0 <= mode
&& mode
<= 2);
6768 isinstance
= PyObject_IsInstance(ast
, req_type
[mode
]);
6769 if (isinstance
== -1)
6772 PyErr_Format(PyExc_TypeError
, "expected %s node, got %.400s",
6773 req_name
[mode
], Py_TYPE(ast
)->tp_name
);
6776 if (obj2ast_mod(ast
, &res
, arena
) != 0)
6782 int PyAST_Check(PyObject
* obj
)
6785 return PyObject_IsInstance(obj
, (PyObject
*)&AST_type
);