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
[]={
48 static PyTypeObject
*ClassDef_type
;
49 static char *ClassDef_fields
[]={
58 static PyTypeObject
*Return_type
;
59 static char *Return_fields
[]={
62 static PyTypeObject
*Delete_type
;
63 static char *Delete_fields
[]={
66 static PyTypeObject
*Assign_type
;
67 static char *Assign_fields
[]={
71 static PyTypeObject
*AugAssign_type
;
72 static char *AugAssign_fields
[]={
77 static PyTypeObject
*For_type
;
78 static char *For_fields
[]={
84 static PyTypeObject
*While_type
;
85 static char *While_fields
[]={
90 static PyTypeObject
*If_type
;
91 static char *If_fields
[]={
96 static PyTypeObject
*With_type
;
97 static char *With_fields
[]={
102 static PyTypeObject
*Raise_type
;
103 static char *Raise_fields
[]={
107 static PyTypeObject
*TryExcept_type
;
108 static char *TryExcept_fields
[]={
113 static PyTypeObject
*TryFinally_type
;
114 static char *TryFinally_fields
[]={
118 static PyTypeObject
*Assert_type
;
119 static char *Assert_fields
[]={
123 static PyTypeObject
*Import_type
;
124 static char *Import_fields
[]={
127 static PyTypeObject
*ImportFrom_type
;
128 static char *ImportFrom_fields
[]={
133 static PyTypeObject
*Global_type
;
134 static char *Global_fields
[]={
137 static PyTypeObject
*Nonlocal_type
;
138 static char *Nonlocal_fields
[]={
141 static PyTypeObject
*Expr_type
;
142 static char *Expr_fields
[]={
145 static PyTypeObject
*Pass_type
;
146 static PyTypeObject
*Break_type
;
147 static PyTypeObject
*Continue_type
;
148 static PyTypeObject
*expr_type
;
149 static char *expr_attributes
[] = {
153 static PyObject
* ast2obj_expr(void*);
154 static PyTypeObject
*BoolOp_type
;
155 static char *BoolOp_fields
[]={
159 static PyTypeObject
*BinOp_type
;
160 static char *BinOp_fields
[]={
165 static PyTypeObject
*UnaryOp_type
;
166 static char *UnaryOp_fields
[]={
170 static PyTypeObject
*Lambda_type
;
171 static char *Lambda_fields
[]={
175 static PyTypeObject
*IfExp_type
;
176 static char *IfExp_fields
[]={
181 static PyTypeObject
*Dict_type
;
182 static char *Dict_fields
[]={
186 static PyTypeObject
*Set_type
;
187 static char *Set_fields
[]={
190 static PyTypeObject
*ListComp_type
;
191 static char *ListComp_fields
[]={
195 static PyTypeObject
*SetComp_type
;
196 static char *SetComp_fields
[]={
200 static PyTypeObject
*DictComp_type
;
201 static char *DictComp_fields
[]={
206 static PyTypeObject
*GeneratorExp_type
;
207 static char *GeneratorExp_fields
[]={
211 static PyTypeObject
*Yield_type
;
212 static char *Yield_fields
[]={
215 static PyTypeObject
*Compare_type
;
216 static char *Compare_fields
[]={
221 static PyTypeObject
*Call_type
;
222 static char *Call_fields
[]={
229 static PyTypeObject
*Num_type
;
230 static char *Num_fields
[]={
233 static PyTypeObject
*Str_type
;
234 static char *Str_fields
[]={
237 static PyTypeObject
*Bytes_type
;
238 static char *Bytes_fields
[]={
241 static PyTypeObject
*Ellipsis_type
;
242 static PyTypeObject
*Attribute_type
;
243 static char *Attribute_fields
[]={
248 static PyTypeObject
*Subscript_type
;
249 static char *Subscript_fields
[]={
254 static PyTypeObject
*Starred_type
;
255 static char *Starred_fields
[]={
259 static PyTypeObject
*Name_type
;
260 static char *Name_fields
[]={
264 static PyTypeObject
*List_type
;
265 static char *List_fields
[]={
269 static PyTypeObject
*Tuple_type
;
270 static char *Tuple_fields
[]={
274 static PyTypeObject
*expr_context_type
;
275 static PyObject
*Load_singleton
, *Store_singleton
, *Del_singleton
,
276 *AugLoad_singleton
, *AugStore_singleton
, *Param_singleton
;
277 static PyObject
* ast2obj_expr_context(expr_context_ty
);
278 static PyTypeObject
*Load_type
;
279 static PyTypeObject
*Store_type
;
280 static PyTypeObject
*Del_type
;
281 static PyTypeObject
*AugLoad_type
;
282 static PyTypeObject
*AugStore_type
;
283 static PyTypeObject
*Param_type
;
284 static PyTypeObject
*slice_type
;
285 static PyObject
* ast2obj_slice(void*);
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
[]={
377 static PyTypeObject
*arg_type
;
378 static PyObject
* ast2obj_arg(void*);
379 static char *arg_fields
[]={
383 static PyTypeObject
*keyword_type
;
384 static PyObject
* ast2obj_keyword(void*);
385 static char *keyword_fields
[]={
389 static PyTypeObject
*alias_type
;
390 static PyObject
* ast2obj_alias(void*);
391 static char *alias_fields
[]={
398 ast_type_init(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
400 Py_ssize_t i
, numfields
= 0;
402 PyObject
*key
, *value
, *fields
;
403 fields
= PyObject_GetAttrString((PyObject
*)Py_TYPE(self
), "_fields");
407 numfields
= PySequence_Size(fields
);
411 res
= 0; /* if no error occurs, this stays 0 to the end */
412 if (PyTuple_GET_SIZE(args
) > 0) {
413 if (numfields
!= PyTuple_GET_SIZE(args
)) {
414 PyErr_Format(PyExc_TypeError
, "%.400s constructor takes %s"
415 "%zd positional argument%s",
416 Py_TYPE(self
)->tp_name
,
417 numfields
== 0 ? "" : "either 0 or ",
418 numfields
, numfields
== 1 ? "" : "s");
422 for (i
= 0; i
< PyTuple_GET_SIZE(args
); i
++) {
423 /* cannot be reached when fields is NULL */
424 PyObject
*name
= PySequence_GetItem(fields
, i
);
429 res
= PyObject_SetAttr(self
, name
, PyTuple_GET_ITEM(args
, i
));
436 i
= 0; /* needed by PyDict_Next */
437 while (PyDict_Next(kw
, &i
, &key
, &value
)) {
438 res
= PyObject_SetAttr(self
, key
, value
);
448 /* Pickling support */
450 ast_type_reduce(PyObject
*self
, PyObject
*unused
)
453 PyObject
*dict
= PyObject_GetAttrString(self
, "__dict__");
455 if (PyErr_ExceptionMatches(PyExc_AttributeError
))
461 res
= Py_BuildValue("O()O", Py_TYPE(self
), dict
);
465 return Py_BuildValue("O()", Py_TYPE(self
));
468 static PyMethodDef ast_type_methods
[] = {
469 {"__reduce__", ast_type_reduce
, METH_NOARGS
, NULL
},
473 static PyTypeObject AST_type
= {
474 PyVarObject_HEAD_INIT(&PyType_Type
, 0)
484 0, /* tp_as_number */
485 0, /* tp_as_sequence */
486 0, /* tp_as_mapping */
490 PyObject_GenericGetAttr
, /* tp_getattro */
491 PyObject_GenericSetAttr
, /* tp_setattro */
492 0, /* tp_as_buffer */
493 Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_BASETYPE
, /* tp_flags */
497 0, /* tp_richcompare */
498 0, /* tp_weaklistoffset */
501 ast_type_methods
, /* tp_methods */
506 0, /* tp_descr_get */
507 0, /* tp_descr_set */
508 0, /* tp_dictoffset */
509 (initproc
)ast_type_init
, /* tp_init */
510 PyType_GenericAlloc
, /* tp_alloc */
511 PyType_GenericNew
, /* tp_new */
512 PyObject_Del
, /* tp_free */
516 static PyTypeObject
* make_type(char *type
, PyTypeObject
* base
, char**fields
, int num_fields
)
518 PyObject
*fnames
, *result
;
520 fnames
= PyTuple_New(num_fields
);
521 if (!fnames
) return NULL
;
522 for (i
= 0; i
< num_fields
; i
++) {
523 PyObject
*field
= PyUnicode_FromString(fields
[i
]);
528 PyTuple_SET_ITEM(fnames
, i
, field
);
530 result
= PyObject_CallFunction((PyObject
*)&PyType_Type
, "U(O){sOss}",
531 type
, base
, "_fields", fnames
, "__module__", "_ast");
533 return (PyTypeObject
*)result
;
536 static int add_attributes(PyTypeObject
* type
, char**attrs
, int num_fields
)
539 PyObject
*s
, *l
= PyTuple_New(num_fields
);
541 for(i
= 0; i
< num_fields
; i
++) {
542 s
= PyUnicode_FromString(attrs
[i
]);
547 PyTuple_SET_ITEM(l
, i
, s
);
549 result
= PyObject_SetAttrString((PyObject
*)type
, "_attributes", l
) >= 0;
554 /* Conversion AST -> Python */
556 static PyObject
* ast2obj_list(asdl_seq
*seq
, PyObject
* (*func
)(void*))
558 int i
, n
= asdl_seq_LEN(seq
);
559 PyObject
*result
= PyList_New(n
);
563 for (i
= 0; i
< n
; i
++) {
564 value
= func(asdl_seq_GET(seq
, i
));
569 PyList_SET_ITEM(result
, i
, value
);
574 static PyObject
* ast2obj_object(void *o
)
578 Py_INCREF((PyObject
*)o
);
581 #define ast2obj_identifier ast2obj_object
582 #define ast2obj_string ast2obj_object
584 static PyObject
* ast2obj_int(long b
)
586 return PyLong_FromLong(b
);
589 /* Conversion Python -> AST */
591 static int obj2ast_object(PyObject
* obj
, PyObject
** out
, PyArena
* arena
)
596 PyArena_AddPyObject(arena
, obj
);
602 #define obj2ast_identifier obj2ast_object
603 #define obj2ast_string obj2ast_object
605 static int obj2ast_int(PyObject
* obj
, int* out
, PyArena
* arena
)
608 if (!PyLong_Check(obj
)) {
609 PyObject
*s
= PyObject_Repr(obj
);
610 if (s
== NULL
) return 1;
611 PyErr_Format(PyExc_ValueError
, "invalid integer value: %.400s",
612 PyBytes_AS_STRING(s
));
617 i
= (int)PyLong_AsLong(obj
);
618 if (i
== -1 && PyErr_Occurred())
624 static int add_ast_fields(void)
626 PyObject
*empty_tuple
, *d
;
627 if (PyType_Ready(&AST_type
) < 0)
629 d
= AST_type
.tp_dict
;
630 empty_tuple
= PyTuple_New(0);
632 PyDict_SetItemString(d
, "_fields", empty_tuple
) < 0 ||
633 PyDict_SetItemString(d
, "_attributes", empty_tuple
) < 0) {
634 Py_XDECREF(empty_tuple
);
637 Py_DECREF(empty_tuple
);
642 static int init_types(void)
644 static int initialized
;
645 if (initialized
) return 1;
646 if (add_ast_fields() < 0) return 0;
647 mod_type
= make_type("mod", &AST_type
, NULL
, 0);
648 if (!mod_type
) return 0;
649 if (!add_attributes(mod_type
, NULL
, 0)) return 0;
650 Module_type
= make_type("Module", mod_type
, Module_fields
, 1);
651 if (!Module_type
) return 0;
652 Interactive_type
= make_type("Interactive", mod_type
,
653 Interactive_fields
, 1);
654 if (!Interactive_type
) return 0;
655 Expression_type
= make_type("Expression", mod_type
, Expression_fields
,
657 if (!Expression_type
) return 0;
658 Suite_type
= make_type("Suite", mod_type
, Suite_fields
, 1);
659 if (!Suite_type
) return 0;
660 stmt_type
= make_type("stmt", &AST_type
, NULL
, 0);
661 if (!stmt_type
) return 0;
662 if (!add_attributes(stmt_type
, stmt_attributes
, 2)) return 0;
663 FunctionDef_type
= make_type("FunctionDef", stmt_type
,
664 FunctionDef_fields
, 5);
665 if (!FunctionDef_type
) return 0;
666 ClassDef_type
= make_type("ClassDef", stmt_type
, ClassDef_fields
, 7);
667 if (!ClassDef_type
) return 0;
668 Return_type
= make_type("Return", stmt_type
, Return_fields
, 1);
669 if (!Return_type
) return 0;
670 Delete_type
= make_type("Delete", stmt_type
, Delete_fields
, 1);
671 if (!Delete_type
) return 0;
672 Assign_type
= make_type("Assign", stmt_type
, Assign_fields
, 2);
673 if (!Assign_type
) return 0;
674 AugAssign_type
= make_type("AugAssign", stmt_type
, AugAssign_fields
, 3);
675 if (!AugAssign_type
) return 0;
676 For_type
= make_type("For", stmt_type
, For_fields
, 4);
677 if (!For_type
) return 0;
678 While_type
= make_type("While", stmt_type
, While_fields
, 3);
679 if (!While_type
) return 0;
680 If_type
= make_type("If", stmt_type
, If_fields
, 3);
681 if (!If_type
) return 0;
682 With_type
= make_type("With", stmt_type
, With_fields
, 3);
683 if (!With_type
) return 0;
684 Raise_type
= make_type("Raise", stmt_type
, Raise_fields
, 2);
685 if (!Raise_type
) return 0;
686 TryExcept_type
= make_type("TryExcept", stmt_type
, TryExcept_fields
, 3);
687 if (!TryExcept_type
) return 0;
688 TryFinally_type
= make_type("TryFinally", stmt_type
, TryFinally_fields
,
690 if (!TryFinally_type
) return 0;
691 Assert_type
= make_type("Assert", stmt_type
, Assert_fields
, 2);
692 if (!Assert_type
) return 0;
693 Import_type
= make_type("Import", stmt_type
, Import_fields
, 1);
694 if (!Import_type
) return 0;
695 ImportFrom_type
= make_type("ImportFrom", stmt_type
, ImportFrom_fields
,
697 if (!ImportFrom_type
) return 0;
698 Global_type
= make_type("Global", stmt_type
, Global_fields
, 1);
699 if (!Global_type
) return 0;
700 Nonlocal_type
= make_type("Nonlocal", stmt_type
, Nonlocal_fields
, 1);
701 if (!Nonlocal_type
) return 0;
702 Expr_type
= make_type("Expr", stmt_type
, Expr_fields
, 1);
703 if (!Expr_type
) return 0;
704 Pass_type
= make_type("Pass", stmt_type
, NULL
, 0);
705 if (!Pass_type
) return 0;
706 Break_type
= make_type("Break", stmt_type
, NULL
, 0);
707 if (!Break_type
) return 0;
708 Continue_type
= make_type("Continue", stmt_type
, NULL
, 0);
709 if (!Continue_type
) return 0;
710 expr_type
= make_type("expr", &AST_type
, NULL
, 0);
711 if (!expr_type
) return 0;
712 if (!add_attributes(expr_type
, expr_attributes
, 2)) return 0;
713 BoolOp_type
= make_type("BoolOp", expr_type
, BoolOp_fields
, 2);
714 if (!BoolOp_type
) return 0;
715 BinOp_type
= make_type("BinOp", expr_type
, BinOp_fields
, 3);
716 if (!BinOp_type
) return 0;
717 UnaryOp_type
= make_type("UnaryOp", expr_type
, UnaryOp_fields
, 2);
718 if (!UnaryOp_type
) return 0;
719 Lambda_type
= make_type("Lambda", expr_type
, Lambda_fields
, 2);
720 if (!Lambda_type
) return 0;
721 IfExp_type
= make_type("IfExp", expr_type
, IfExp_fields
, 3);
722 if (!IfExp_type
) return 0;
723 Dict_type
= make_type("Dict", expr_type
, Dict_fields
, 2);
724 if (!Dict_type
) return 0;
725 Set_type
= make_type("Set", expr_type
, Set_fields
, 1);
726 if (!Set_type
) return 0;
727 ListComp_type
= make_type("ListComp", expr_type
, ListComp_fields
, 2);
728 if (!ListComp_type
) return 0;
729 SetComp_type
= make_type("SetComp", expr_type
, SetComp_fields
, 2);
730 if (!SetComp_type
) return 0;
731 DictComp_type
= make_type("DictComp", expr_type
, DictComp_fields
, 3);
732 if (!DictComp_type
) return 0;
733 GeneratorExp_type
= make_type("GeneratorExp", expr_type
,
734 GeneratorExp_fields
, 2);
735 if (!GeneratorExp_type
) return 0;
736 Yield_type
= make_type("Yield", expr_type
, Yield_fields
, 1);
737 if (!Yield_type
) return 0;
738 Compare_type
= make_type("Compare", expr_type
, Compare_fields
, 3);
739 if (!Compare_type
) return 0;
740 Call_type
= make_type("Call", expr_type
, Call_fields
, 5);
741 if (!Call_type
) return 0;
742 Num_type
= make_type("Num", expr_type
, Num_fields
, 1);
743 if (!Num_type
) return 0;
744 Str_type
= make_type("Str", expr_type
, Str_fields
, 1);
745 if (!Str_type
) return 0;
746 Bytes_type
= make_type("Bytes", expr_type
, Bytes_fields
, 1);
747 if (!Bytes_type
) return 0;
748 Ellipsis_type
= make_type("Ellipsis", expr_type
, NULL
, 0);
749 if (!Ellipsis_type
) return 0;
750 Attribute_type
= make_type("Attribute", expr_type
, Attribute_fields
, 3);
751 if (!Attribute_type
) return 0;
752 Subscript_type
= make_type("Subscript", expr_type
, Subscript_fields
, 3);
753 if (!Subscript_type
) return 0;
754 Starred_type
= make_type("Starred", expr_type
, Starred_fields
, 2);
755 if (!Starred_type
) return 0;
756 Name_type
= make_type("Name", expr_type
, Name_fields
, 2);
757 if (!Name_type
) return 0;
758 List_type
= make_type("List", expr_type
, List_fields
, 2);
759 if (!List_type
) return 0;
760 Tuple_type
= make_type("Tuple", expr_type
, Tuple_fields
, 2);
761 if (!Tuple_type
) return 0;
762 expr_context_type
= make_type("expr_context", &AST_type
, NULL
, 0);
763 if (!expr_context_type
) return 0;
764 if (!add_attributes(expr_context_type
, NULL
, 0)) return 0;
765 Load_type
= make_type("Load", expr_context_type
, NULL
, 0);
766 if (!Load_type
) return 0;
767 Load_singleton
= PyType_GenericNew(Load_type
, NULL
, NULL
);
768 if (!Load_singleton
) return 0;
769 Store_type
= make_type("Store", expr_context_type
, NULL
, 0);
770 if (!Store_type
) return 0;
771 Store_singleton
= PyType_GenericNew(Store_type
, NULL
, NULL
);
772 if (!Store_singleton
) return 0;
773 Del_type
= make_type("Del", expr_context_type
, NULL
, 0);
774 if (!Del_type
) return 0;
775 Del_singleton
= PyType_GenericNew(Del_type
, NULL
, NULL
);
776 if (!Del_singleton
) return 0;
777 AugLoad_type
= make_type("AugLoad", expr_context_type
, NULL
, 0);
778 if (!AugLoad_type
) return 0;
779 AugLoad_singleton
= PyType_GenericNew(AugLoad_type
, NULL
, NULL
);
780 if (!AugLoad_singleton
) return 0;
781 AugStore_type
= make_type("AugStore", expr_context_type
, NULL
, 0);
782 if (!AugStore_type
) return 0;
783 AugStore_singleton
= PyType_GenericNew(AugStore_type
, NULL
, NULL
);
784 if (!AugStore_singleton
) return 0;
785 Param_type
= make_type("Param", expr_context_type
, NULL
, 0);
786 if (!Param_type
) return 0;
787 Param_singleton
= PyType_GenericNew(Param_type
, NULL
, NULL
);
788 if (!Param_singleton
) return 0;
789 slice_type
= make_type("slice", &AST_type
, NULL
, 0);
790 if (!slice_type
) return 0;
791 if (!add_attributes(slice_type
, NULL
, 0)) return 0;
792 Slice_type
= make_type("Slice", slice_type
, Slice_fields
, 3);
793 if (!Slice_type
) return 0;
794 ExtSlice_type
= make_type("ExtSlice", slice_type
, ExtSlice_fields
, 1);
795 if (!ExtSlice_type
) return 0;
796 Index_type
= make_type("Index", slice_type
, Index_fields
, 1);
797 if (!Index_type
) return 0;
798 boolop_type
= make_type("boolop", &AST_type
, NULL
, 0);
799 if (!boolop_type
) return 0;
800 if (!add_attributes(boolop_type
, NULL
, 0)) return 0;
801 And_type
= make_type("And", boolop_type
, NULL
, 0);
802 if (!And_type
) return 0;
803 And_singleton
= PyType_GenericNew(And_type
, NULL
, NULL
);
804 if (!And_singleton
) return 0;
805 Or_type
= make_type("Or", boolop_type
, NULL
, 0);
806 if (!Or_type
) return 0;
807 Or_singleton
= PyType_GenericNew(Or_type
, NULL
, NULL
);
808 if (!Or_singleton
) return 0;
809 operator_type
= make_type("operator", &AST_type
, NULL
, 0);
810 if (!operator_type
) return 0;
811 if (!add_attributes(operator_type
, NULL
, 0)) return 0;
812 Add_type
= make_type("Add", operator_type
, NULL
, 0);
813 if (!Add_type
) return 0;
814 Add_singleton
= PyType_GenericNew(Add_type
, NULL
, NULL
);
815 if (!Add_singleton
) return 0;
816 Sub_type
= make_type("Sub", operator_type
, NULL
, 0);
817 if (!Sub_type
) return 0;
818 Sub_singleton
= PyType_GenericNew(Sub_type
, NULL
, NULL
);
819 if (!Sub_singleton
) return 0;
820 Mult_type
= make_type("Mult", operator_type
, NULL
, 0);
821 if (!Mult_type
) return 0;
822 Mult_singleton
= PyType_GenericNew(Mult_type
, NULL
, NULL
);
823 if (!Mult_singleton
) return 0;
824 Div_type
= make_type("Div", operator_type
, NULL
, 0);
825 if (!Div_type
) return 0;
826 Div_singleton
= PyType_GenericNew(Div_type
, NULL
, NULL
);
827 if (!Div_singleton
) return 0;
828 Mod_type
= make_type("Mod", operator_type
, NULL
, 0);
829 if (!Mod_type
) return 0;
830 Mod_singleton
= PyType_GenericNew(Mod_type
, NULL
, NULL
);
831 if (!Mod_singleton
) return 0;
832 Pow_type
= make_type("Pow", operator_type
, NULL
, 0);
833 if (!Pow_type
) return 0;
834 Pow_singleton
= PyType_GenericNew(Pow_type
, NULL
, NULL
);
835 if (!Pow_singleton
) return 0;
836 LShift_type
= make_type("LShift", operator_type
, NULL
, 0);
837 if (!LShift_type
) return 0;
838 LShift_singleton
= PyType_GenericNew(LShift_type
, NULL
, NULL
);
839 if (!LShift_singleton
) return 0;
840 RShift_type
= make_type("RShift", operator_type
, NULL
, 0);
841 if (!RShift_type
) return 0;
842 RShift_singleton
= PyType_GenericNew(RShift_type
, NULL
, NULL
);
843 if (!RShift_singleton
) return 0;
844 BitOr_type
= make_type("BitOr", operator_type
, NULL
, 0);
845 if (!BitOr_type
) return 0;
846 BitOr_singleton
= PyType_GenericNew(BitOr_type
, NULL
, NULL
);
847 if (!BitOr_singleton
) return 0;
848 BitXor_type
= make_type("BitXor", operator_type
, NULL
, 0);
849 if (!BitXor_type
) return 0;
850 BitXor_singleton
= PyType_GenericNew(BitXor_type
, NULL
, NULL
);
851 if (!BitXor_singleton
) return 0;
852 BitAnd_type
= make_type("BitAnd", operator_type
, NULL
, 0);
853 if (!BitAnd_type
) return 0;
854 BitAnd_singleton
= PyType_GenericNew(BitAnd_type
, NULL
, NULL
);
855 if (!BitAnd_singleton
) return 0;
856 FloorDiv_type
= make_type("FloorDiv", operator_type
, NULL
, 0);
857 if (!FloorDiv_type
) return 0;
858 FloorDiv_singleton
= PyType_GenericNew(FloorDiv_type
, NULL
, NULL
);
859 if (!FloorDiv_singleton
) return 0;
860 unaryop_type
= make_type("unaryop", &AST_type
, NULL
, 0);
861 if (!unaryop_type
) return 0;
862 if (!add_attributes(unaryop_type
, NULL
, 0)) return 0;
863 Invert_type
= make_type("Invert", unaryop_type
, NULL
, 0);
864 if (!Invert_type
) return 0;
865 Invert_singleton
= PyType_GenericNew(Invert_type
, NULL
, NULL
);
866 if (!Invert_singleton
) return 0;
867 Not_type
= make_type("Not", unaryop_type
, NULL
, 0);
868 if (!Not_type
) return 0;
869 Not_singleton
= PyType_GenericNew(Not_type
, NULL
, NULL
);
870 if (!Not_singleton
) return 0;
871 UAdd_type
= make_type("UAdd", unaryop_type
, NULL
, 0);
872 if (!UAdd_type
) return 0;
873 UAdd_singleton
= PyType_GenericNew(UAdd_type
, NULL
, NULL
);
874 if (!UAdd_singleton
) return 0;
875 USub_type
= make_type("USub", unaryop_type
, NULL
, 0);
876 if (!USub_type
) return 0;
877 USub_singleton
= PyType_GenericNew(USub_type
, NULL
, NULL
);
878 if (!USub_singleton
) return 0;
879 cmpop_type
= make_type("cmpop", &AST_type
, NULL
, 0);
880 if (!cmpop_type
) return 0;
881 if (!add_attributes(cmpop_type
, NULL
, 0)) return 0;
882 Eq_type
= make_type("Eq", cmpop_type
, NULL
, 0);
883 if (!Eq_type
) return 0;
884 Eq_singleton
= PyType_GenericNew(Eq_type
, NULL
, NULL
);
885 if (!Eq_singleton
) return 0;
886 NotEq_type
= make_type("NotEq", cmpop_type
, NULL
, 0);
887 if (!NotEq_type
) return 0;
888 NotEq_singleton
= PyType_GenericNew(NotEq_type
, NULL
, NULL
);
889 if (!NotEq_singleton
) return 0;
890 Lt_type
= make_type("Lt", cmpop_type
, NULL
, 0);
891 if (!Lt_type
) return 0;
892 Lt_singleton
= PyType_GenericNew(Lt_type
, NULL
, NULL
);
893 if (!Lt_singleton
) return 0;
894 LtE_type
= make_type("LtE", cmpop_type
, NULL
, 0);
895 if (!LtE_type
) return 0;
896 LtE_singleton
= PyType_GenericNew(LtE_type
, NULL
, NULL
);
897 if (!LtE_singleton
) return 0;
898 Gt_type
= make_type("Gt", cmpop_type
, NULL
, 0);
899 if (!Gt_type
) return 0;
900 Gt_singleton
= PyType_GenericNew(Gt_type
, NULL
, NULL
);
901 if (!Gt_singleton
) return 0;
902 GtE_type
= make_type("GtE", cmpop_type
, NULL
, 0);
903 if (!GtE_type
) return 0;
904 GtE_singleton
= PyType_GenericNew(GtE_type
, NULL
, NULL
);
905 if (!GtE_singleton
) return 0;
906 Is_type
= make_type("Is", cmpop_type
, NULL
, 0);
907 if (!Is_type
) return 0;
908 Is_singleton
= PyType_GenericNew(Is_type
, NULL
, NULL
);
909 if (!Is_singleton
) return 0;
910 IsNot_type
= make_type("IsNot", cmpop_type
, NULL
, 0);
911 if (!IsNot_type
) return 0;
912 IsNot_singleton
= PyType_GenericNew(IsNot_type
, NULL
, NULL
);
913 if (!IsNot_singleton
) return 0;
914 In_type
= make_type("In", cmpop_type
, NULL
, 0);
915 if (!In_type
) return 0;
916 In_singleton
= PyType_GenericNew(In_type
, NULL
, NULL
);
917 if (!In_singleton
) return 0;
918 NotIn_type
= make_type("NotIn", cmpop_type
, NULL
, 0);
919 if (!NotIn_type
) return 0;
920 NotIn_singleton
= PyType_GenericNew(NotIn_type
, NULL
, NULL
);
921 if (!NotIn_singleton
) return 0;
922 comprehension_type
= make_type("comprehension", &AST_type
,
923 comprehension_fields
, 3);
924 if (!comprehension_type
) return 0;
925 excepthandler_type
= make_type("excepthandler", &AST_type
, NULL
, 0);
926 if (!excepthandler_type
) return 0;
927 if (!add_attributes(excepthandler_type
, excepthandler_attributes
, 2))
929 ExceptHandler_type
= make_type("ExceptHandler", excepthandler_type
,
930 ExceptHandler_fields
, 3);
931 if (!ExceptHandler_type
) return 0;
932 arguments_type
= make_type("arguments", &AST_type
, arguments_fields
, 8);
933 if (!arguments_type
) return 0;
934 arg_type
= make_type("arg", &AST_type
, arg_fields
, 2);
935 if (!arg_type
) return 0;
936 keyword_type
= make_type("keyword", &AST_type
, keyword_fields
, 2);
937 if (!keyword_type
) return 0;
938 alias_type
= make_type("alias", &AST_type
, alias_fields
, 2);
939 if (!alias_type
) return 0;
944 static int obj2ast_mod(PyObject
* obj
, mod_ty
* out
, PyArena
* arena
);
945 static int obj2ast_stmt(PyObject
* obj
, stmt_ty
* out
, PyArena
* arena
);
946 static int obj2ast_expr(PyObject
* obj
, expr_ty
* out
, PyArena
* arena
);
947 static int obj2ast_expr_context(PyObject
* obj
, expr_context_ty
* out
, PyArena
*
949 static int obj2ast_slice(PyObject
* obj
, slice_ty
* out
, PyArena
* arena
);
950 static int obj2ast_boolop(PyObject
* obj
, boolop_ty
* out
, PyArena
* arena
);
951 static int obj2ast_operator(PyObject
* obj
, operator_ty
* out
, PyArena
* arena
);
952 static int obj2ast_unaryop(PyObject
* obj
, unaryop_ty
* out
, PyArena
* arena
);
953 static int obj2ast_cmpop(PyObject
* obj
, cmpop_ty
* out
, PyArena
* arena
);
954 static int obj2ast_comprehension(PyObject
* obj
, comprehension_ty
* out
, PyArena
*
956 static int obj2ast_excepthandler(PyObject
* obj
, excepthandler_ty
* out
, PyArena
*
958 static int obj2ast_arguments(PyObject
* obj
, arguments_ty
* out
, PyArena
* arena
);
959 static int obj2ast_arg(PyObject
* obj
, arg_ty
* out
, PyArena
* arena
);
960 static int obj2ast_keyword(PyObject
* obj
, keyword_ty
* out
, PyArena
* arena
);
961 static int obj2ast_alias(PyObject
* obj
, alias_ty
* out
, PyArena
* arena
);
964 Module(asdl_seq
* body
, PyArena
*arena
)
967 p
= (mod_ty
)PyArena_Malloc(arena
, sizeof(*p
));
970 p
->kind
= Module_kind
;
971 p
->v
.Module
.body
= body
;
976 Interactive(asdl_seq
* body
, PyArena
*arena
)
979 p
= (mod_ty
)PyArena_Malloc(arena
, sizeof(*p
));
982 p
->kind
= Interactive_kind
;
983 p
->v
.Interactive
.body
= body
;
988 Expression(expr_ty body
, PyArena
*arena
)
992 PyErr_SetString(PyExc_ValueError
,
993 "field body is required for Expression");
996 p
= (mod_ty
)PyArena_Malloc(arena
, sizeof(*p
));
999 p
->kind
= Expression_kind
;
1000 p
->v
.Expression
.body
= body
;
1005 Suite(asdl_seq
* body
, PyArena
*arena
)
1008 p
= (mod_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1011 p
->kind
= Suite_kind
;
1012 p
->v
.Suite
.body
= body
;
1017 FunctionDef(identifier name
, arguments_ty args
, asdl_seq
* body
, asdl_seq
*
1018 decorator_list
, expr_ty returns
, int lineno
, int col_offset
,
1023 PyErr_SetString(PyExc_ValueError
,
1024 "field name is required for FunctionDef");
1028 PyErr_SetString(PyExc_ValueError
,
1029 "field args is required for FunctionDef");
1032 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1035 p
->kind
= FunctionDef_kind
;
1036 p
->v
.FunctionDef
.name
= name
;
1037 p
->v
.FunctionDef
.args
= args
;
1038 p
->v
.FunctionDef
.body
= body
;
1039 p
->v
.FunctionDef
.decorator_list
= decorator_list
;
1040 p
->v
.FunctionDef
.returns
= returns
;
1042 p
->col_offset
= col_offset
;
1047 ClassDef(identifier name
, asdl_seq
* bases
, asdl_seq
* keywords
, expr_ty
1048 starargs
, expr_ty kwargs
, asdl_seq
* body
, asdl_seq
* decorator_list
,
1049 int lineno
, int col_offset
, PyArena
*arena
)
1053 PyErr_SetString(PyExc_ValueError
,
1054 "field name is required for ClassDef");
1057 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1060 p
->kind
= ClassDef_kind
;
1061 p
->v
.ClassDef
.name
= name
;
1062 p
->v
.ClassDef
.bases
= bases
;
1063 p
->v
.ClassDef
.keywords
= keywords
;
1064 p
->v
.ClassDef
.starargs
= starargs
;
1065 p
->v
.ClassDef
.kwargs
= kwargs
;
1066 p
->v
.ClassDef
.body
= body
;
1067 p
->v
.ClassDef
.decorator_list
= decorator_list
;
1069 p
->col_offset
= col_offset
;
1074 Return(expr_ty value
, int lineno
, int col_offset
, PyArena
*arena
)
1077 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1080 p
->kind
= Return_kind
;
1081 p
->v
.Return
.value
= value
;
1083 p
->col_offset
= col_offset
;
1088 Delete(asdl_seq
* targets
, int lineno
, int col_offset
, PyArena
*arena
)
1091 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1094 p
->kind
= Delete_kind
;
1095 p
->v
.Delete
.targets
= targets
;
1097 p
->col_offset
= col_offset
;
1102 Assign(asdl_seq
* targets
, expr_ty value
, int lineno
, int col_offset
, PyArena
1107 PyErr_SetString(PyExc_ValueError
,
1108 "field value is required for Assign");
1111 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1114 p
->kind
= Assign_kind
;
1115 p
->v
.Assign
.targets
= targets
;
1116 p
->v
.Assign
.value
= value
;
1118 p
->col_offset
= col_offset
;
1123 AugAssign(expr_ty target
, operator_ty op
, expr_ty value
, int lineno
, int
1124 col_offset
, PyArena
*arena
)
1128 PyErr_SetString(PyExc_ValueError
,
1129 "field target is required for AugAssign");
1133 PyErr_SetString(PyExc_ValueError
,
1134 "field op is required for AugAssign");
1138 PyErr_SetString(PyExc_ValueError
,
1139 "field value is required for AugAssign");
1142 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1145 p
->kind
= AugAssign_kind
;
1146 p
->v
.AugAssign
.target
= target
;
1147 p
->v
.AugAssign
.op
= op
;
1148 p
->v
.AugAssign
.value
= value
;
1150 p
->col_offset
= col_offset
;
1155 For(expr_ty target
, expr_ty iter
, asdl_seq
* body
, asdl_seq
* orelse
, int
1156 lineno
, int col_offset
, PyArena
*arena
)
1160 PyErr_SetString(PyExc_ValueError
,
1161 "field target is required for For");
1165 PyErr_SetString(PyExc_ValueError
,
1166 "field iter is required for For");
1169 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1173 p
->v
.For
.target
= target
;
1174 p
->v
.For
.iter
= iter
;
1175 p
->v
.For
.body
= body
;
1176 p
->v
.For
.orelse
= orelse
;
1178 p
->col_offset
= col_offset
;
1183 While(expr_ty test
, asdl_seq
* body
, asdl_seq
* orelse
, int lineno
, int
1184 col_offset
, PyArena
*arena
)
1188 PyErr_SetString(PyExc_ValueError
,
1189 "field test is required for While");
1192 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1195 p
->kind
= While_kind
;
1196 p
->v
.While
.test
= test
;
1197 p
->v
.While
.body
= body
;
1198 p
->v
.While
.orelse
= orelse
;
1200 p
->col_offset
= col_offset
;
1205 If(expr_ty test
, asdl_seq
* body
, asdl_seq
* orelse
, int lineno
, int
1206 col_offset
, PyArena
*arena
)
1210 PyErr_SetString(PyExc_ValueError
,
1211 "field test is required for If");
1214 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1218 p
->v
.If
.test
= test
;
1219 p
->v
.If
.body
= body
;
1220 p
->v
.If
.orelse
= orelse
;
1222 p
->col_offset
= col_offset
;
1227 With(expr_ty context_expr
, expr_ty optional_vars
, asdl_seq
* body
, int lineno
,
1228 int col_offset
, PyArena
*arena
)
1231 if (!context_expr
) {
1232 PyErr_SetString(PyExc_ValueError
,
1233 "field context_expr is required for With");
1236 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1239 p
->kind
= With_kind
;
1240 p
->v
.With
.context_expr
= context_expr
;
1241 p
->v
.With
.optional_vars
= optional_vars
;
1242 p
->v
.With
.body
= body
;
1244 p
->col_offset
= col_offset
;
1249 Raise(expr_ty exc
, expr_ty cause
, int lineno
, int col_offset
, PyArena
*arena
)
1252 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1255 p
->kind
= Raise_kind
;
1256 p
->v
.Raise
.exc
= exc
;
1257 p
->v
.Raise
.cause
= cause
;
1259 p
->col_offset
= col_offset
;
1264 TryExcept(asdl_seq
* body
, asdl_seq
* handlers
, asdl_seq
* orelse
, int lineno
,
1265 int col_offset
, PyArena
*arena
)
1268 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1271 p
->kind
= TryExcept_kind
;
1272 p
->v
.TryExcept
.body
= body
;
1273 p
->v
.TryExcept
.handlers
= handlers
;
1274 p
->v
.TryExcept
.orelse
= orelse
;
1276 p
->col_offset
= col_offset
;
1281 TryFinally(asdl_seq
* body
, asdl_seq
* finalbody
, int lineno
, int col_offset
,
1285 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1288 p
->kind
= TryFinally_kind
;
1289 p
->v
.TryFinally
.body
= body
;
1290 p
->v
.TryFinally
.finalbody
= finalbody
;
1292 p
->col_offset
= col_offset
;
1297 Assert(expr_ty test
, expr_ty msg
, int lineno
, int col_offset
, PyArena
*arena
)
1301 PyErr_SetString(PyExc_ValueError
,
1302 "field test is required for Assert");
1305 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1308 p
->kind
= Assert_kind
;
1309 p
->v
.Assert
.test
= test
;
1310 p
->v
.Assert
.msg
= msg
;
1312 p
->col_offset
= col_offset
;
1317 Import(asdl_seq
* names
, int lineno
, int col_offset
, PyArena
*arena
)
1320 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1323 p
->kind
= Import_kind
;
1324 p
->v
.Import
.names
= names
;
1326 p
->col_offset
= col_offset
;
1331 ImportFrom(identifier module
, asdl_seq
* names
, int level
, int lineno
, int
1332 col_offset
, PyArena
*arena
)
1336 PyErr_SetString(PyExc_ValueError
,
1337 "field module is required for ImportFrom");
1340 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1343 p
->kind
= ImportFrom_kind
;
1344 p
->v
.ImportFrom
.module
= module
;
1345 p
->v
.ImportFrom
.names
= names
;
1346 p
->v
.ImportFrom
.level
= level
;
1348 p
->col_offset
= col_offset
;
1353 Global(asdl_seq
* names
, int lineno
, int col_offset
, PyArena
*arena
)
1356 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1359 p
->kind
= Global_kind
;
1360 p
->v
.Global
.names
= names
;
1362 p
->col_offset
= col_offset
;
1367 Nonlocal(asdl_seq
* names
, int lineno
, int col_offset
, PyArena
*arena
)
1370 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1373 p
->kind
= Nonlocal_kind
;
1374 p
->v
.Nonlocal
.names
= names
;
1376 p
->col_offset
= col_offset
;
1381 Expr(expr_ty value
, int lineno
, int col_offset
, PyArena
*arena
)
1385 PyErr_SetString(PyExc_ValueError
,
1386 "field value is required for Expr");
1389 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1392 p
->kind
= Expr_kind
;
1393 p
->v
.Expr
.value
= value
;
1395 p
->col_offset
= col_offset
;
1400 Pass(int lineno
, int col_offset
, PyArena
*arena
)
1403 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1406 p
->kind
= Pass_kind
;
1408 p
->col_offset
= col_offset
;
1413 Break(int lineno
, int col_offset
, PyArena
*arena
)
1416 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1419 p
->kind
= Break_kind
;
1421 p
->col_offset
= col_offset
;
1426 Continue(int lineno
, int col_offset
, PyArena
*arena
)
1429 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1432 p
->kind
= Continue_kind
;
1434 p
->col_offset
= col_offset
;
1439 BoolOp(boolop_ty op
, asdl_seq
* values
, int lineno
, int col_offset
, PyArena
1444 PyErr_SetString(PyExc_ValueError
,
1445 "field op is required for BoolOp");
1448 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1451 p
->kind
= BoolOp_kind
;
1452 p
->v
.BoolOp
.op
= op
;
1453 p
->v
.BoolOp
.values
= values
;
1455 p
->col_offset
= col_offset
;
1460 BinOp(expr_ty left
, operator_ty op
, expr_ty right
, int lineno
, int col_offset
,
1465 PyErr_SetString(PyExc_ValueError
,
1466 "field left is required for BinOp");
1470 PyErr_SetString(PyExc_ValueError
,
1471 "field op is required for BinOp");
1475 PyErr_SetString(PyExc_ValueError
,
1476 "field right is required for BinOp");
1479 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1482 p
->kind
= BinOp_kind
;
1483 p
->v
.BinOp
.left
= left
;
1485 p
->v
.BinOp
.right
= right
;
1487 p
->col_offset
= col_offset
;
1492 UnaryOp(unaryop_ty op
, expr_ty operand
, int lineno
, int col_offset
, PyArena
1497 PyErr_SetString(PyExc_ValueError
,
1498 "field op is required for UnaryOp");
1502 PyErr_SetString(PyExc_ValueError
,
1503 "field operand is required for UnaryOp");
1506 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1509 p
->kind
= UnaryOp_kind
;
1510 p
->v
.UnaryOp
.op
= op
;
1511 p
->v
.UnaryOp
.operand
= operand
;
1513 p
->col_offset
= col_offset
;
1518 Lambda(arguments_ty args
, expr_ty body
, int lineno
, int col_offset
, PyArena
1523 PyErr_SetString(PyExc_ValueError
,
1524 "field args is required for Lambda");
1528 PyErr_SetString(PyExc_ValueError
,
1529 "field body is required for Lambda");
1532 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1535 p
->kind
= Lambda_kind
;
1536 p
->v
.Lambda
.args
= args
;
1537 p
->v
.Lambda
.body
= body
;
1539 p
->col_offset
= col_offset
;
1544 IfExp(expr_ty test
, expr_ty body
, expr_ty orelse
, int lineno
, int col_offset
,
1549 PyErr_SetString(PyExc_ValueError
,
1550 "field test is required for IfExp");
1554 PyErr_SetString(PyExc_ValueError
,
1555 "field body is required for IfExp");
1559 PyErr_SetString(PyExc_ValueError
,
1560 "field orelse is required for IfExp");
1563 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1566 p
->kind
= IfExp_kind
;
1567 p
->v
.IfExp
.test
= test
;
1568 p
->v
.IfExp
.body
= body
;
1569 p
->v
.IfExp
.orelse
= orelse
;
1571 p
->col_offset
= col_offset
;
1576 Dict(asdl_seq
* keys
, asdl_seq
* values
, int lineno
, int col_offset
, PyArena
1580 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1583 p
->kind
= Dict_kind
;
1584 p
->v
.Dict
.keys
= keys
;
1585 p
->v
.Dict
.values
= values
;
1587 p
->col_offset
= col_offset
;
1592 Set(asdl_seq
* elts
, int lineno
, int col_offset
, PyArena
*arena
)
1595 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1599 p
->v
.Set
.elts
= elts
;
1601 p
->col_offset
= col_offset
;
1606 ListComp(expr_ty elt
, asdl_seq
* generators
, int lineno
, int col_offset
,
1611 PyErr_SetString(PyExc_ValueError
,
1612 "field elt is required for ListComp");
1615 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1618 p
->kind
= ListComp_kind
;
1619 p
->v
.ListComp
.elt
= elt
;
1620 p
->v
.ListComp
.generators
= generators
;
1622 p
->col_offset
= col_offset
;
1627 SetComp(expr_ty elt
, asdl_seq
* generators
, int lineno
, int col_offset
, PyArena
1632 PyErr_SetString(PyExc_ValueError
,
1633 "field elt is required for SetComp");
1636 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1639 p
->kind
= SetComp_kind
;
1640 p
->v
.SetComp
.elt
= elt
;
1641 p
->v
.SetComp
.generators
= generators
;
1643 p
->col_offset
= col_offset
;
1648 DictComp(expr_ty key
, expr_ty value
, asdl_seq
* generators
, int lineno
, int
1649 col_offset
, PyArena
*arena
)
1653 PyErr_SetString(PyExc_ValueError
,
1654 "field key is required for DictComp");
1658 PyErr_SetString(PyExc_ValueError
,
1659 "field value is required for DictComp");
1662 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1665 p
->kind
= DictComp_kind
;
1666 p
->v
.DictComp
.key
= key
;
1667 p
->v
.DictComp
.value
= value
;
1668 p
->v
.DictComp
.generators
= generators
;
1670 p
->col_offset
= col_offset
;
1675 GeneratorExp(expr_ty elt
, asdl_seq
* generators
, int lineno
, int col_offset
,
1680 PyErr_SetString(PyExc_ValueError
,
1681 "field elt is required for GeneratorExp");
1684 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1687 p
->kind
= GeneratorExp_kind
;
1688 p
->v
.GeneratorExp
.elt
= elt
;
1689 p
->v
.GeneratorExp
.generators
= generators
;
1691 p
->col_offset
= col_offset
;
1696 Yield(expr_ty value
, int lineno
, int col_offset
, PyArena
*arena
)
1699 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1702 p
->kind
= Yield_kind
;
1703 p
->v
.Yield
.value
= value
;
1705 p
->col_offset
= col_offset
;
1710 Compare(expr_ty left
, asdl_int_seq
* ops
, asdl_seq
* comparators
, int lineno
,
1711 int col_offset
, PyArena
*arena
)
1715 PyErr_SetString(PyExc_ValueError
,
1716 "field left is required for Compare");
1719 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1722 p
->kind
= Compare_kind
;
1723 p
->v
.Compare
.left
= left
;
1724 p
->v
.Compare
.ops
= ops
;
1725 p
->v
.Compare
.comparators
= comparators
;
1727 p
->col_offset
= col_offset
;
1732 Call(expr_ty func
, asdl_seq
* args
, asdl_seq
* keywords
, expr_ty starargs
,
1733 expr_ty kwargs
, int lineno
, int col_offset
, PyArena
*arena
)
1737 PyErr_SetString(PyExc_ValueError
,
1738 "field func is required for Call");
1741 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1744 p
->kind
= Call_kind
;
1745 p
->v
.Call
.func
= func
;
1746 p
->v
.Call
.args
= args
;
1747 p
->v
.Call
.keywords
= keywords
;
1748 p
->v
.Call
.starargs
= starargs
;
1749 p
->v
.Call
.kwargs
= kwargs
;
1751 p
->col_offset
= col_offset
;
1756 Num(object n
, int lineno
, int col_offset
, PyArena
*arena
)
1760 PyErr_SetString(PyExc_ValueError
,
1761 "field n is required for Num");
1764 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1770 p
->col_offset
= col_offset
;
1775 Str(string s
, int lineno
, int col_offset
, PyArena
*arena
)
1779 PyErr_SetString(PyExc_ValueError
,
1780 "field s is required for Str");
1783 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1789 p
->col_offset
= col_offset
;
1794 Bytes(string s
, int lineno
, int col_offset
, PyArena
*arena
)
1798 PyErr_SetString(PyExc_ValueError
,
1799 "field s is required for Bytes");
1802 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1805 p
->kind
= Bytes_kind
;
1808 p
->col_offset
= col_offset
;
1813 Ellipsis(int lineno
, int col_offset
, PyArena
*arena
)
1816 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1819 p
->kind
= Ellipsis_kind
;
1821 p
->col_offset
= col_offset
;
1826 Attribute(expr_ty value
, identifier attr
, expr_context_ty ctx
, int lineno
, int
1827 col_offset
, PyArena
*arena
)
1831 PyErr_SetString(PyExc_ValueError
,
1832 "field value is required for Attribute");
1836 PyErr_SetString(PyExc_ValueError
,
1837 "field attr is required for Attribute");
1841 PyErr_SetString(PyExc_ValueError
,
1842 "field ctx is required for Attribute");
1845 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1848 p
->kind
= Attribute_kind
;
1849 p
->v
.Attribute
.value
= value
;
1850 p
->v
.Attribute
.attr
= attr
;
1851 p
->v
.Attribute
.ctx
= ctx
;
1853 p
->col_offset
= col_offset
;
1858 Subscript(expr_ty value
, slice_ty slice
, expr_context_ty ctx
, int lineno
, int
1859 col_offset
, PyArena
*arena
)
1863 PyErr_SetString(PyExc_ValueError
,
1864 "field value is required for Subscript");
1868 PyErr_SetString(PyExc_ValueError
,
1869 "field slice is required for Subscript");
1873 PyErr_SetString(PyExc_ValueError
,
1874 "field ctx is required for Subscript");
1877 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1880 p
->kind
= Subscript_kind
;
1881 p
->v
.Subscript
.value
= value
;
1882 p
->v
.Subscript
.slice
= slice
;
1883 p
->v
.Subscript
.ctx
= ctx
;
1885 p
->col_offset
= col_offset
;
1890 Starred(expr_ty value
, expr_context_ty ctx
, int lineno
, int col_offset
, PyArena
1895 PyErr_SetString(PyExc_ValueError
,
1896 "field value is required for Starred");
1900 PyErr_SetString(PyExc_ValueError
,
1901 "field ctx is required for Starred");
1904 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1907 p
->kind
= Starred_kind
;
1908 p
->v
.Starred
.value
= value
;
1909 p
->v
.Starred
.ctx
= ctx
;
1911 p
->col_offset
= col_offset
;
1916 Name(identifier id
, expr_context_ty ctx
, int lineno
, int col_offset
, PyArena
1921 PyErr_SetString(PyExc_ValueError
,
1922 "field id is required for Name");
1926 PyErr_SetString(PyExc_ValueError
,
1927 "field ctx is required for Name");
1930 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1933 p
->kind
= Name_kind
;
1935 p
->v
.Name
.ctx
= ctx
;
1937 p
->col_offset
= col_offset
;
1942 List(asdl_seq
* elts
, expr_context_ty ctx
, int lineno
, int col_offset
, PyArena
1947 PyErr_SetString(PyExc_ValueError
,
1948 "field ctx is required for List");
1951 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1954 p
->kind
= List_kind
;
1955 p
->v
.List
.elts
= elts
;
1956 p
->v
.List
.ctx
= ctx
;
1958 p
->col_offset
= col_offset
;
1963 Tuple(asdl_seq
* elts
, expr_context_ty ctx
, int lineno
, int col_offset
, PyArena
1968 PyErr_SetString(PyExc_ValueError
,
1969 "field ctx is required for Tuple");
1972 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1975 p
->kind
= Tuple_kind
;
1976 p
->v
.Tuple
.elts
= elts
;
1977 p
->v
.Tuple
.ctx
= ctx
;
1979 p
->col_offset
= col_offset
;
1984 Slice(expr_ty lower
, expr_ty upper
, expr_ty step
, PyArena
*arena
)
1987 p
= (slice_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1990 p
->kind
= Slice_kind
;
1991 p
->v
.Slice
.lower
= lower
;
1992 p
->v
.Slice
.upper
= upper
;
1993 p
->v
.Slice
.step
= step
;
1998 ExtSlice(asdl_seq
* dims
, PyArena
*arena
)
2001 p
= (slice_ty
)PyArena_Malloc(arena
, sizeof(*p
));
2004 p
->kind
= ExtSlice_kind
;
2005 p
->v
.ExtSlice
.dims
= dims
;
2010 Index(expr_ty value
, PyArena
*arena
)
2014 PyErr_SetString(PyExc_ValueError
,
2015 "field value is required for Index");
2018 p
= (slice_ty
)PyArena_Malloc(arena
, sizeof(*p
));
2021 p
->kind
= Index_kind
;
2022 p
->v
.Index
.value
= value
;
2027 comprehension(expr_ty target
, expr_ty iter
, asdl_seq
* ifs
, PyArena
*arena
)
2031 PyErr_SetString(PyExc_ValueError
,
2032 "field target is required for comprehension");
2036 PyErr_SetString(PyExc_ValueError
,
2037 "field iter is required for comprehension");
2040 p
= (comprehension_ty
)PyArena_Malloc(arena
, sizeof(*p
));
2050 ExceptHandler(expr_ty type
, identifier name
, asdl_seq
* body
, int lineno
, int
2051 col_offset
, PyArena
*arena
)
2054 p
= (excepthandler_ty
)PyArena_Malloc(arena
, sizeof(*p
));
2057 p
->kind
= ExceptHandler_kind
;
2058 p
->v
.ExceptHandler
.type
= type
;
2059 p
->v
.ExceptHandler
.name
= name
;
2060 p
->v
.ExceptHandler
.body
= body
;
2062 p
->col_offset
= col_offset
;
2067 arguments(asdl_seq
* args
, identifier vararg
, expr_ty varargannotation
,
2068 asdl_seq
* kwonlyargs
, identifier kwarg
, expr_ty kwargannotation
,
2069 asdl_seq
* defaults
, asdl_seq
* kw_defaults
, PyArena
*arena
)
2072 p
= (arguments_ty
)PyArena_Malloc(arena
, sizeof(*p
));
2077 p
->varargannotation
= varargannotation
;
2078 p
->kwonlyargs
= kwonlyargs
;
2080 p
->kwargannotation
= kwargannotation
;
2081 p
->defaults
= defaults
;
2082 p
->kw_defaults
= kw_defaults
;
2087 arg(identifier arg
, expr_ty annotation
, PyArena
*arena
)
2091 PyErr_SetString(PyExc_ValueError
,
2092 "field arg is required for arg");
2095 p
= (arg_ty
)PyArena_Malloc(arena
, sizeof(*p
));
2099 p
->annotation
= annotation
;
2104 keyword(identifier arg
, expr_ty value
, PyArena
*arena
)
2108 PyErr_SetString(PyExc_ValueError
,
2109 "field arg is required for keyword");
2113 PyErr_SetString(PyExc_ValueError
,
2114 "field value is required for keyword");
2117 p
= (keyword_ty
)PyArena_Malloc(arena
, sizeof(*p
));
2126 alias(identifier name
, identifier asname
, PyArena
*arena
)
2130 PyErr_SetString(PyExc_ValueError
,
2131 "field name is required for alias");
2134 p
= (alias_ty
)PyArena_Malloc(arena
, sizeof(*p
));
2144 ast2obj_mod(void* _o
)
2146 mod_ty o
= (mod_ty
)_o
;
2147 PyObject
*result
= NULL
, *value
= NULL
;
2155 result
= PyType_GenericNew(Module_type
, NULL
, NULL
);
2156 if (!result
) goto failed
;
2157 value
= ast2obj_list(o
->v
.Module
.body
, ast2obj_stmt
);
2158 if (!value
) goto failed
;
2159 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2163 case Interactive_kind
:
2164 result
= PyType_GenericNew(Interactive_type
, NULL
, NULL
);
2165 if (!result
) goto failed
;
2166 value
= ast2obj_list(o
->v
.Interactive
.body
, ast2obj_stmt
);
2167 if (!value
) goto failed
;
2168 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2172 case Expression_kind
:
2173 result
= PyType_GenericNew(Expression_type
, NULL
, NULL
);
2174 if (!result
) goto failed
;
2175 value
= ast2obj_expr(o
->v
.Expression
.body
);
2176 if (!value
) goto failed
;
2177 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2182 result
= PyType_GenericNew(Suite_type
, NULL
, NULL
);
2183 if (!result
) goto failed
;
2184 value
= ast2obj_list(o
->v
.Suite
.body
, ast2obj_stmt
);
2185 if (!value
) goto failed
;
2186 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2199 ast2obj_stmt(void* _o
)
2201 stmt_ty o
= (stmt_ty
)_o
;
2202 PyObject
*result
= NULL
, *value
= NULL
;
2209 case FunctionDef_kind
:
2210 result
= PyType_GenericNew(FunctionDef_type
, NULL
, NULL
);
2211 if (!result
) goto failed
;
2212 value
= ast2obj_identifier(o
->v
.FunctionDef
.name
);
2213 if (!value
) goto failed
;
2214 if (PyObject_SetAttrString(result
, "name", value
) == -1)
2217 value
= ast2obj_arguments(o
->v
.FunctionDef
.args
);
2218 if (!value
) goto failed
;
2219 if (PyObject_SetAttrString(result
, "args", value
) == -1)
2222 value
= ast2obj_list(o
->v
.FunctionDef
.body
, ast2obj_stmt
);
2223 if (!value
) goto failed
;
2224 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2227 value
= ast2obj_list(o
->v
.FunctionDef
.decorator_list
,
2229 if (!value
) goto failed
;
2230 if (PyObject_SetAttrString(result
, "decorator_list", value
) ==
2234 value
= ast2obj_expr(o
->v
.FunctionDef
.returns
);
2235 if (!value
) goto failed
;
2236 if (PyObject_SetAttrString(result
, "returns", value
) == -1)
2241 result
= PyType_GenericNew(ClassDef_type
, NULL
, NULL
);
2242 if (!result
) goto failed
;
2243 value
= ast2obj_identifier(o
->v
.ClassDef
.name
);
2244 if (!value
) goto failed
;
2245 if (PyObject_SetAttrString(result
, "name", value
) == -1)
2248 value
= ast2obj_list(o
->v
.ClassDef
.bases
, ast2obj_expr
);
2249 if (!value
) goto failed
;
2250 if (PyObject_SetAttrString(result
, "bases", value
) == -1)
2253 value
= ast2obj_list(o
->v
.ClassDef
.keywords
, ast2obj_keyword
);
2254 if (!value
) goto failed
;
2255 if (PyObject_SetAttrString(result
, "keywords", value
) == -1)
2258 value
= ast2obj_expr(o
->v
.ClassDef
.starargs
);
2259 if (!value
) goto failed
;
2260 if (PyObject_SetAttrString(result
, "starargs", value
) == -1)
2263 value
= ast2obj_expr(o
->v
.ClassDef
.kwargs
);
2264 if (!value
) goto failed
;
2265 if (PyObject_SetAttrString(result
, "kwargs", value
) == -1)
2268 value
= ast2obj_list(o
->v
.ClassDef
.body
, ast2obj_stmt
);
2269 if (!value
) goto failed
;
2270 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2273 value
= ast2obj_list(o
->v
.ClassDef
.decorator_list
,
2275 if (!value
) goto failed
;
2276 if (PyObject_SetAttrString(result
, "decorator_list", value
) ==
2282 result
= PyType_GenericNew(Return_type
, NULL
, NULL
);
2283 if (!result
) goto failed
;
2284 value
= ast2obj_expr(o
->v
.Return
.value
);
2285 if (!value
) goto failed
;
2286 if (PyObject_SetAttrString(result
, "value", value
) == -1)
2291 result
= PyType_GenericNew(Delete_type
, NULL
, NULL
);
2292 if (!result
) goto failed
;
2293 value
= ast2obj_list(o
->v
.Delete
.targets
, ast2obj_expr
);
2294 if (!value
) goto failed
;
2295 if (PyObject_SetAttrString(result
, "targets", value
) == -1)
2300 result
= PyType_GenericNew(Assign_type
, NULL
, NULL
);
2301 if (!result
) goto failed
;
2302 value
= ast2obj_list(o
->v
.Assign
.targets
, ast2obj_expr
);
2303 if (!value
) goto failed
;
2304 if (PyObject_SetAttrString(result
, "targets", value
) == -1)
2307 value
= ast2obj_expr(o
->v
.Assign
.value
);
2308 if (!value
) goto failed
;
2309 if (PyObject_SetAttrString(result
, "value", value
) == -1)
2313 case AugAssign_kind
:
2314 result
= PyType_GenericNew(AugAssign_type
, NULL
, NULL
);
2315 if (!result
) goto failed
;
2316 value
= ast2obj_expr(o
->v
.AugAssign
.target
);
2317 if (!value
) goto failed
;
2318 if (PyObject_SetAttrString(result
, "target", value
) == -1)
2321 value
= ast2obj_operator(o
->v
.AugAssign
.op
);
2322 if (!value
) goto failed
;
2323 if (PyObject_SetAttrString(result
, "op", value
) == -1)
2326 value
= ast2obj_expr(o
->v
.AugAssign
.value
);
2327 if (!value
) goto failed
;
2328 if (PyObject_SetAttrString(result
, "value", value
) == -1)
2333 result
= PyType_GenericNew(For_type
, NULL
, NULL
);
2334 if (!result
) goto failed
;
2335 value
= ast2obj_expr(o
->v
.For
.target
);
2336 if (!value
) goto failed
;
2337 if (PyObject_SetAttrString(result
, "target", value
) == -1)
2340 value
= ast2obj_expr(o
->v
.For
.iter
);
2341 if (!value
) goto failed
;
2342 if (PyObject_SetAttrString(result
, "iter", value
) == -1)
2345 value
= ast2obj_list(o
->v
.For
.body
, ast2obj_stmt
);
2346 if (!value
) goto failed
;
2347 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2350 value
= ast2obj_list(o
->v
.For
.orelse
, ast2obj_stmt
);
2351 if (!value
) goto failed
;
2352 if (PyObject_SetAttrString(result
, "orelse", value
) == -1)
2357 result
= PyType_GenericNew(While_type
, NULL
, NULL
);
2358 if (!result
) goto failed
;
2359 value
= ast2obj_expr(o
->v
.While
.test
);
2360 if (!value
) goto failed
;
2361 if (PyObject_SetAttrString(result
, "test", value
) == -1)
2364 value
= ast2obj_list(o
->v
.While
.body
, ast2obj_stmt
);
2365 if (!value
) goto failed
;
2366 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2369 value
= ast2obj_list(o
->v
.While
.orelse
, ast2obj_stmt
);
2370 if (!value
) goto failed
;
2371 if (PyObject_SetAttrString(result
, "orelse", value
) == -1)
2376 result
= PyType_GenericNew(If_type
, NULL
, NULL
);
2377 if (!result
) goto failed
;
2378 value
= ast2obj_expr(o
->v
.If
.test
);
2379 if (!value
) goto failed
;
2380 if (PyObject_SetAttrString(result
, "test", value
) == -1)
2383 value
= ast2obj_list(o
->v
.If
.body
, ast2obj_stmt
);
2384 if (!value
) goto failed
;
2385 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2388 value
= ast2obj_list(o
->v
.If
.orelse
, ast2obj_stmt
);
2389 if (!value
) goto failed
;
2390 if (PyObject_SetAttrString(result
, "orelse", value
) == -1)
2395 result
= PyType_GenericNew(With_type
, NULL
, NULL
);
2396 if (!result
) goto failed
;
2397 value
= ast2obj_expr(o
->v
.With
.context_expr
);
2398 if (!value
) goto failed
;
2399 if (PyObject_SetAttrString(result
, "context_expr", value
) == -1)
2402 value
= ast2obj_expr(o
->v
.With
.optional_vars
);
2403 if (!value
) goto failed
;
2404 if (PyObject_SetAttrString(result
, "optional_vars", value
) ==
2408 value
= ast2obj_list(o
->v
.With
.body
, ast2obj_stmt
);
2409 if (!value
) goto failed
;
2410 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2415 result
= PyType_GenericNew(Raise_type
, NULL
, NULL
);
2416 if (!result
) goto failed
;
2417 value
= ast2obj_expr(o
->v
.Raise
.exc
);
2418 if (!value
) goto failed
;
2419 if (PyObject_SetAttrString(result
, "exc", value
) == -1)
2422 value
= ast2obj_expr(o
->v
.Raise
.cause
);
2423 if (!value
) goto failed
;
2424 if (PyObject_SetAttrString(result
, "cause", value
) == -1)
2428 case TryExcept_kind
:
2429 result
= PyType_GenericNew(TryExcept_type
, NULL
, NULL
);
2430 if (!result
) goto failed
;
2431 value
= ast2obj_list(o
->v
.TryExcept
.body
, ast2obj_stmt
);
2432 if (!value
) goto failed
;
2433 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2436 value
= ast2obj_list(o
->v
.TryExcept
.handlers
,
2437 ast2obj_excepthandler
);
2438 if (!value
) goto failed
;
2439 if (PyObject_SetAttrString(result
, "handlers", value
) == -1)
2442 value
= ast2obj_list(o
->v
.TryExcept
.orelse
, ast2obj_stmt
);
2443 if (!value
) goto failed
;
2444 if (PyObject_SetAttrString(result
, "orelse", value
) == -1)
2448 case TryFinally_kind
:
2449 result
= PyType_GenericNew(TryFinally_type
, NULL
, NULL
);
2450 if (!result
) goto failed
;
2451 value
= ast2obj_list(o
->v
.TryFinally
.body
, ast2obj_stmt
);
2452 if (!value
) goto failed
;
2453 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2456 value
= ast2obj_list(o
->v
.TryFinally
.finalbody
, ast2obj_stmt
);
2457 if (!value
) goto failed
;
2458 if (PyObject_SetAttrString(result
, "finalbody", value
) == -1)
2463 result
= PyType_GenericNew(Assert_type
, NULL
, NULL
);
2464 if (!result
) goto failed
;
2465 value
= ast2obj_expr(o
->v
.Assert
.test
);
2466 if (!value
) goto failed
;
2467 if (PyObject_SetAttrString(result
, "test", value
) == -1)
2470 value
= ast2obj_expr(o
->v
.Assert
.msg
);
2471 if (!value
) goto failed
;
2472 if (PyObject_SetAttrString(result
, "msg", value
) == -1)
2477 result
= PyType_GenericNew(Import_type
, NULL
, NULL
);
2478 if (!result
) goto failed
;
2479 value
= ast2obj_list(o
->v
.Import
.names
, ast2obj_alias
);
2480 if (!value
) goto failed
;
2481 if (PyObject_SetAttrString(result
, "names", value
) == -1)
2485 case ImportFrom_kind
:
2486 result
= PyType_GenericNew(ImportFrom_type
, NULL
, NULL
);
2487 if (!result
) goto failed
;
2488 value
= ast2obj_identifier(o
->v
.ImportFrom
.module
);
2489 if (!value
) goto failed
;
2490 if (PyObject_SetAttrString(result
, "module", value
) == -1)
2493 value
= ast2obj_list(o
->v
.ImportFrom
.names
, ast2obj_alias
);
2494 if (!value
) goto failed
;
2495 if (PyObject_SetAttrString(result
, "names", value
) == -1)
2498 value
= ast2obj_int(o
->v
.ImportFrom
.level
);
2499 if (!value
) goto failed
;
2500 if (PyObject_SetAttrString(result
, "level", value
) == -1)
2505 result
= PyType_GenericNew(Global_type
, NULL
, NULL
);
2506 if (!result
) goto failed
;
2507 value
= ast2obj_list(o
->v
.Global
.names
, ast2obj_identifier
);
2508 if (!value
) goto failed
;
2509 if (PyObject_SetAttrString(result
, "names", value
) == -1)
2514 result
= PyType_GenericNew(Nonlocal_type
, NULL
, NULL
);
2515 if (!result
) goto failed
;
2516 value
= ast2obj_list(o
->v
.Nonlocal
.names
, ast2obj_identifier
);
2517 if (!value
) goto failed
;
2518 if (PyObject_SetAttrString(result
, "names", value
) == -1)
2523 result
= PyType_GenericNew(Expr_type
, NULL
, NULL
);
2524 if (!result
) goto failed
;
2525 value
= ast2obj_expr(o
->v
.Expr
.value
);
2526 if (!value
) goto failed
;
2527 if (PyObject_SetAttrString(result
, "value", value
) == -1)
2532 result
= PyType_GenericNew(Pass_type
, NULL
, NULL
);
2533 if (!result
) goto failed
;
2536 result
= PyType_GenericNew(Break_type
, NULL
, NULL
);
2537 if (!result
) goto failed
;
2540 result
= PyType_GenericNew(Continue_type
, NULL
, NULL
);
2541 if (!result
) goto failed
;
2544 value
= ast2obj_int(o
->lineno
);
2545 if (!value
) goto failed
;
2546 if (PyObject_SetAttrString(result
, "lineno", value
) < 0)
2549 value
= ast2obj_int(o
->col_offset
);
2550 if (!value
) goto failed
;
2551 if (PyObject_SetAttrString(result
, "col_offset", value
) < 0)
2562 ast2obj_expr(void* _o
)
2564 expr_ty o
= (expr_ty
)_o
;
2565 PyObject
*result
= NULL
, *value
= NULL
;
2573 result
= PyType_GenericNew(BoolOp_type
, NULL
, NULL
);
2574 if (!result
) goto failed
;
2575 value
= ast2obj_boolop(o
->v
.BoolOp
.op
);
2576 if (!value
) goto failed
;
2577 if (PyObject_SetAttrString(result
, "op", value
) == -1)
2580 value
= ast2obj_list(o
->v
.BoolOp
.values
, ast2obj_expr
);
2581 if (!value
) goto failed
;
2582 if (PyObject_SetAttrString(result
, "values", value
) == -1)
2587 result
= PyType_GenericNew(BinOp_type
, NULL
, NULL
);
2588 if (!result
) goto failed
;
2589 value
= ast2obj_expr(o
->v
.BinOp
.left
);
2590 if (!value
) goto failed
;
2591 if (PyObject_SetAttrString(result
, "left", value
) == -1)
2594 value
= ast2obj_operator(o
->v
.BinOp
.op
);
2595 if (!value
) goto failed
;
2596 if (PyObject_SetAttrString(result
, "op", value
) == -1)
2599 value
= ast2obj_expr(o
->v
.BinOp
.right
);
2600 if (!value
) goto failed
;
2601 if (PyObject_SetAttrString(result
, "right", value
) == -1)
2606 result
= PyType_GenericNew(UnaryOp_type
, NULL
, NULL
);
2607 if (!result
) goto failed
;
2608 value
= ast2obj_unaryop(o
->v
.UnaryOp
.op
);
2609 if (!value
) goto failed
;
2610 if (PyObject_SetAttrString(result
, "op", value
) == -1)
2613 value
= ast2obj_expr(o
->v
.UnaryOp
.operand
);
2614 if (!value
) goto failed
;
2615 if (PyObject_SetAttrString(result
, "operand", value
) == -1)
2620 result
= PyType_GenericNew(Lambda_type
, NULL
, NULL
);
2621 if (!result
) goto failed
;
2622 value
= ast2obj_arguments(o
->v
.Lambda
.args
);
2623 if (!value
) goto failed
;
2624 if (PyObject_SetAttrString(result
, "args", value
) == -1)
2627 value
= ast2obj_expr(o
->v
.Lambda
.body
);
2628 if (!value
) goto failed
;
2629 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2634 result
= PyType_GenericNew(IfExp_type
, NULL
, NULL
);
2635 if (!result
) goto failed
;
2636 value
= ast2obj_expr(o
->v
.IfExp
.test
);
2637 if (!value
) goto failed
;
2638 if (PyObject_SetAttrString(result
, "test", value
) == -1)
2641 value
= ast2obj_expr(o
->v
.IfExp
.body
);
2642 if (!value
) goto failed
;
2643 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2646 value
= ast2obj_expr(o
->v
.IfExp
.orelse
);
2647 if (!value
) goto failed
;
2648 if (PyObject_SetAttrString(result
, "orelse", value
) == -1)
2653 result
= PyType_GenericNew(Dict_type
, NULL
, NULL
);
2654 if (!result
) goto failed
;
2655 value
= ast2obj_list(o
->v
.Dict
.keys
, ast2obj_expr
);
2656 if (!value
) goto failed
;
2657 if (PyObject_SetAttrString(result
, "keys", value
) == -1)
2660 value
= ast2obj_list(o
->v
.Dict
.values
, ast2obj_expr
);
2661 if (!value
) goto failed
;
2662 if (PyObject_SetAttrString(result
, "values", value
) == -1)
2667 result
= PyType_GenericNew(Set_type
, NULL
, NULL
);
2668 if (!result
) goto failed
;
2669 value
= ast2obj_list(o
->v
.Set
.elts
, ast2obj_expr
);
2670 if (!value
) goto failed
;
2671 if (PyObject_SetAttrString(result
, "elts", value
) == -1)
2676 result
= PyType_GenericNew(ListComp_type
, NULL
, NULL
);
2677 if (!result
) goto failed
;
2678 value
= ast2obj_expr(o
->v
.ListComp
.elt
);
2679 if (!value
) goto failed
;
2680 if (PyObject_SetAttrString(result
, "elt", value
) == -1)
2683 value
= ast2obj_list(o
->v
.ListComp
.generators
,
2684 ast2obj_comprehension
);
2685 if (!value
) goto failed
;
2686 if (PyObject_SetAttrString(result
, "generators", value
) == -1)
2691 result
= PyType_GenericNew(SetComp_type
, NULL
, NULL
);
2692 if (!result
) goto failed
;
2693 value
= ast2obj_expr(o
->v
.SetComp
.elt
);
2694 if (!value
) goto failed
;
2695 if (PyObject_SetAttrString(result
, "elt", value
) == -1)
2698 value
= ast2obj_list(o
->v
.SetComp
.generators
,
2699 ast2obj_comprehension
);
2700 if (!value
) goto failed
;
2701 if (PyObject_SetAttrString(result
, "generators", value
) == -1)
2706 result
= PyType_GenericNew(DictComp_type
, NULL
, NULL
);
2707 if (!result
) goto failed
;
2708 value
= ast2obj_expr(o
->v
.DictComp
.key
);
2709 if (!value
) goto failed
;
2710 if (PyObject_SetAttrString(result
, "key", value
) == -1)
2713 value
= ast2obj_expr(o
->v
.DictComp
.value
);
2714 if (!value
) goto failed
;
2715 if (PyObject_SetAttrString(result
, "value", value
) == -1)
2718 value
= ast2obj_list(o
->v
.DictComp
.generators
,
2719 ast2obj_comprehension
);
2720 if (!value
) goto failed
;
2721 if (PyObject_SetAttrString(result
, "generators", value
) == -1)
2725 case GeneratorExp_kind
:
2726 result
= PyType_GenericNew(GeneratorExp_type
, NULL
, NULL
);
2727 if (!result
) goto failed
;
2728 value
= ast2obj_expr(o
->v
.GeneratorExp
.elt
);
2729 if (!value
) goto failed
;
2730 if (PyObject_SetAttrString(result
, "elt", value
) == -1)
2733 value
= ast2obj_list(o
->v
.GeneratorExp
.generators
,
2734 ast2obj_comprehension
);
2735 if (!value
) goto failed
;
2736 if (PyObject_SetAttrString(result
, "generators", value
) == -1)
2741 result
= PyType_GenericNew(Yield_type
, NULL
, NULL
);
2742 if (!result
) goto failed
;
2743 value
= ast2obj_expr(o
->v
.Yield
.value
);
2744 if (!value
) goto failed
;
2745 if (PyObject_SetAttrString(result
, "value", value
) == -1)
2750 result
= PyType_GenericNew(Compare_type
, NULL
, NULL
);
2751 if (!result
) goto failed
;
2752 value
= ast2obj_expr(o
->v
.Compare
.left
);
2753 if (!value
) goto failed
;
2754 if (PyObject_SetAttrString(result
, "left", value
) == -1)
2758 int i
, n
= asdl_seq_LEN(o
->v
.Compare
.ops
);
2759 value
= PyList_New(n
);
2760 if (!value
) goto failed
;
2761 for(i
= 0; i
< n
; i
++)
2762 PyList_SET_ITEM(value
, i
, ast2obj_cmpop((cmpop_ty
)asdl_seq_GET(o
->v
.Compare
.ops
, i
)));
2764 if (!value
) goto failed
;
2765 if (PyObject_SetAttrString(result
, "ops", value
) == -1)
2768 value
= ast2obj_list(o
->v
.Compare
.comparators
, ast2obj_expr
);
2769 if (!value
) goto failed
;
2770 if (PyObject_SetAttrString(result
, "comparators", value
) == -1)
2775 result
= PyType_GenericNew(Call_type
, NULL
, NULL
);
2776 if (!result
) goto failed
;
2777 value
= ast2obj_expr(o
->v
.Call
.func
);
2778 if (!value
) goto failed
;
2779 if (PyObject_SetAttrString(result
, "func", value
) == -1)
2782 value
= ast2obj_list(o
->v
.Call
.args
, ast2obj_expr
);
2783 if (!value
) goto failed
;
2784 if (PyObject_SetAttrString(result
, "args", value
) == -1)
2787 value
= ast2obj_list(o
->v
.Call
.keywords
, ast2obj_keyword
);
2788 if (!value
) goto failed
;
2789 if (PyObject_SetAttrString(result
, "keywords", value
) == -1)
2792 value
= ast2obj_expr(o
->v
.Call
.starargs
);
2793 if (!value
) goto failed
;
2794 if (PyObject_SetAttrString(result
, "starargs", value
) == -1)
2797 value
= ast2obj_expr(o
->v
.Call
.kwargs
);
2798 if (!value
) goto failed
;
2799 if (PyObject_SetAttrString(result
, "kwargs", value
) == -1)
2804 result
= PyType_GenericNew(Num_type
, NULL
, NULL
);
2805 if (!result
) goto failed
;
2806 value
= ast2obj_object(o
->v
.Num
.n
);
2807 if (!value
) goto failed
;
2808 if (PyObject_SetAttrString(result
, "n", value
) == -1)
2813 result
= PyType_GenericNew(Str_type
, NULL
, NULL
);
2814 if (!result
) goto failed
;
2815 value
= ast2obj_string(o
->v
.Str
.s
);
2816 if (!value
) goto failed
;
2817 if (PyObject_SetAttrString(result
, "s", value
) == -1)
2822 result
= PyType_GenericNew(Bytes_type
, NULL
, NULL
);
2823 if (!result
) goto failed
;
2824 value
= ast2obj_string(o
->v
.Bytes
.s
);
2825 if (!value
) goto failed
;
2826 if (PyObject_SetAttrString(result
, "s", value
) == -1)
2831 result
= PyType_GenericNew(Ellipsis_type
, NULL
, NULL
);
2832 if (!result
) goto failed
;
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(Starred_type
, NULL
, NULL
);
2874 if (!result
) goto failed
;
2875 value
= ast2obj_expr(o
->v
.Starred
.value
);
2876 if (!value
) goto failed
;
2877 if (PyObject_SetAttrString(result
, "value", value
) == -1)
2880 value
= ast2obj_expr_context(o
->v
.Starred
.ctx
);
2881 if (!value
) goto failed
;
2882 if (PyObject_SetAttrString(result
, "ctx", value
) == -1)
2887 result
= PyType_GenericNew(Name_type
, NULL
, NULL
);
2888 if (!result
) goto failed
;
2889 value
= ast2obj_identifier(o
->v
.Name
.id
);
2890 if (!value
) goto failed
;
2891 if (PyObject_SetAttrString(result
, "id", value
) == -1)
2894 value
= ast2obj_expr_context(o
->v
.Name
.ctx
);
2895 if (!value
) goto failed
;
2896 if (PyObject_SetAttrString(result
, "ctx", value
) == -1)
2901 result
= PyType_GenericNew(List_type
, NULL
, NULL
);
2902 if (!result
) goto failed
;
2903 value
= ast2obj_list(o
->v
.List
.elts
, ast2obj_expr
);
2904 if (!value
) goto failed
;
2905 if (PyObject_SetAttrString(result
, "elts", value
) == -1)
2908 value
= ast2obj_expr_context(o
->v
.List
.ctx
);
2909 if (!value
) goto failed
;
2910 if (PyObject_SetAttrString(result
, "ctx", value
) == -1)
2915 result
= PyType_GenericNew(Tuple_type
, NULL
, NULL
);
2916 if (!result
) goto failed
;
2917 value
= ast2obj_list(o
->v
.Tuple
.elts
, ast2obj_expr
);
2918 if (!value
) goto failed
;
2919 if (PyObject_SetAttrString(result
, "elts", value
) == -1)
2922 value
= ast2obj_expr_context(o
->v
.Tuple
.ctx
);
2923 if (!value
) goto failed
;
2924 if (PyObject_SetAttrString(result
, "ctx", value
) == -1)
2929 value
= ast2obj_int(o
->lineno
);
2930 if (!value
) goto failed
;
2931 if (PyObject_SetAttrString(result
, "lineno", value
) < 0)
2934 value
= ast2obj_int(o
->col_offset
);
2935 if (!value
) goto failed
;
2936 if (PyObject_SetAttrString(result
, "col_offset", value
) < 0)
2946 PyObject
* ast2obj_expr_context(expr_context_ty o
)
2950 Py_INCREF(Load_singleton
);
2951 return Load_singleton
;
2953 Py_INCREF(Store_singleton
);
2954 return Store_singleton
;
2956 Py_INCREF(Del_singleton
);
2957 return Del_singleton
;
2959 Py_INCREF(AugLoad_singleton
);
2960 return AugLoad_singleton
;
2962 Py_INCREF(AugStore_singleton
);
2963 return AugStore_singleton
;
2965 Py_INCREF(Param_singleton
);
2966 return Param_singleton
;
2968 /* should never happen, but just in case ... */
2969 PyErr_Format(PyExc_SystemError
, "unknown expr_context found");
2974 ast2obj_slice(void* _o
)
2976 slice_ty o
= (slice_ty
)_o
;
2977 PyObject
*result
= NULL
, *value
= NULL
;
2985 result
= PyType_GenericNew(Slice_type
, NULL
, NULL
);
2986 if (!result
) goto failed
;
2987 value
= ast2obj_expr(o
->v
.Slice
.lower
);
2988 if (!value
) goto failed
;
2989 if (PyObject_SetAttrString(result
, "lower", value
) == -1)
2992 value
= ast2obj_expr(o
->v
.Slice
.upper
);
2993 if (!value
) goto failed
;
2994 if (PyObject_SetAttrString(result
, "upper", value
) == -1)
2997 value
= ast2obj_expr(o
->v
.Slice
.step
);
2998 if (!value
) goto failed
;
2999 if (PyObject_SetAttrString(result
, "step", value
) == -1)
3004 result
= PyType_GenericNew(ExtSlice_type
, NULL
, NULL
);
3005 if (!result
) goto failed
;
3006 value
= ast2obj_list(o
->v
.ExtSlice
.dims
, ast2obj_slice
);
3007 if (!value
) goto failed
;
3008 if (PyObject_SetAttrString(result
, "dims", value
) == -1)
3013 result
= PyType_GenericNew(Index_type
, NULL
, NULL
);
3014 if (!result
) goto failed
;
3015 value
= ast2obj_expr(o
->v
.Index
.value
);
3016 if (!value
) goto failed
;
3017 if (PyObject_SetAttrString(result
, "value", value
) == -1)
3029 PyObject
* ast2obj_boolop(boolop_ty o
)
3033 Py_INCREF(And_singleton
);
3034 return And_singleton
;
3036 Py_INCREF(Or_singleton
);
3037 return Or_singleton
;
3039 /* should never happen, but just in case ... */
3040 PyErr_Format(PyExc_SystemError
, "unknown boolop found");
3044 PyObject
* ast2obj_operator(operator_ty o
)
3048 Py_INCREF(Add_singleton
);
3049 return Add_singleton
;
3051 Py_INCREF(Sub_singleton
);
3052 return Sub_singleton
;
3054 Py_INCREF(Mult_singleton
);
3055 return Mult_singleton
;
3057 Py_INCREF(Div_singleton
);
3058 return Div_singleton
;
3060 Py_INCREF(Mod_singleton
);
3061 return Mod_singleton
;
3063 Py_INCREF(Pow_singleton
);
3064 return Pow_singleton
;
3066 Py_INCREF(LShift_singleton
);
3067 return LShift_singleton
;
3069 Py_INCREF(RShift_singleton
);
3070 return RShift_singleton
;
3072 Py_INCREF(BitOr_singleton
);
3073 return BitOr_singleton
;
3075 Py_INCREF(BitXor_singleton
);
3076 return BitXor_singleton
;
3078 Py_INCREF(BitAnd_singleton
);
3079 return BitAnd_singleton
;
3081 Py_INCREF(FloorDiv_singleton
);
3082 return FloorDiv_singleton
;
3084 /* should never happen, but just in case ... */
3085 PyErr_Format(PyExc_SystemError
, "unknown operator found");
3089 PyObject
* ast2obj_unaryop(unaryop_ty o
)
3093 Py_INCREF(Invert_singleton
);
3094 return Invert_singleton
;
3096 Py_INCREF(Not_singleton
);
3097 return Not_singleton
;
3099 Py_INCREF(UAdd_singleton
);
3100 return UAdd_singleton
;
3102 Py_INCREF(USub_singleton
);
3103 return USub_singleton
;
3105 /* should never happen, but just in case ... */
3106 PyErr_Format(PyExc_SystemError
, "unknown unaryop found");
3110 PyObject
* ast2obj_cmpop(cmpop_ty o
)
3114 Py_INCREF(Eq_singleton
);
3115 return Eq_singleton
;
3117 Py_INCREF(NotEq_singleton
);
3118 return NotEq_singleton
;
3120 Py_INCREF(Lt_singleton
);
3121 return Lt_singleton
;
3123 Py_INCREF(LtE_singleton
);
3124 return LtE_singleton
;
3126 Py_INCREF(Gt_singleton
);
3127 return Gt_singleton
;
3129 Py_INCREF(GtE_singleton
);
3130 return GtE_singleton
;
3132 Py_INCREF(Is_singleton
);
3133 return Is_singleton
;
3135 Py_INCREF(IsNot_singleton
);
3136 return IsNot_singleton
;
3138 Py_INCREF(In_singleton
);
3139 return In_singleton
;
3141 Py_INCREF(NotIn_singleton
);
3142 return NotIn_singleton
;
3144 /* should never happen, but just in case ... */
3145 PyErr_Format(PyExc_SystemError
, "unknown cmpop found");
3150 ast2obj_comprehension(void* _o
)
3152 comprehension_ty o
= (comprehension_ty
)_o
;
3153 PyObject
*result
= NULL
, *value
= NULL
;
3159 result
= PyType_GenericNew(comprehension_type
, NULL
, NULL
);
3160 if (!result
) return NULL
;
3161 value
= ast2obj_expr(o
->target
);
3162 if (!value
) goto failed
;
3163 if (PyObject_SetAttrString(result
, "target", value
) == -1)
3166 value
= ast2obj_expr(o
->iter
);
3167 if (!value
) goto failed
;
3168 if (PyObject_SetAttrString(result
, "iter", value
) == -1)
3171 value
= ast2obj_list(o
->ifs
, ast2obj_expr
);
3172 if (!value
) goto failed
;
3173 if (PyObject_SetAttrString(result
, "ifs", value
) == -1)
3184 ast2obj_excepthandler(void* _o
)
3186 excepthandler_ty o
= (excepthandler_ty
)_o
;
3187 PyObject
*result
= NULL
, *value
= NULL
;
3194 case ExceptHandler_kind
:
3195 result
= PyType_GenericNew(ExceptHandler_type
, NULL
, NULL
);
3196 if (!result
) goto failed
;
3197 value
= ast2obj_expr(o
->v
.ExceptHandler
.type
);
3198 if (!value
) goto failed
;
3199 if (PyObject_SetAttrString(result
, "type", value
) == -1)
3202 value
= ast2obj_identifier(o
->v
.ExceptHandler
.name
);
3203 if (!value
) goto failed
;
3204 if (PyObject_SetAttrString(result
, "name", value
) == -1)
3207 value
= ast2obj_list(o
->v
.ExceptHandler
.body
, ast2obj_stmt
);
3208 if (!value
) goto failed
;
3209 if (PyObject_SetAttrString(result
, "body", value
) == -1)
3214 value
= ast2obj_int(o
->lineno
);
3215 if (!value
) goto failed
;
3216 if (PyObject_SetAttrString(result
, "lineno", value
) < 0)
3219 value
= ast2obj_int(o
->col_offset
);
3220 if (!value
) goto failed
;
3221 if (PyObject_SetAttrString(result
, "col_offset", value
) < 0)
3232 ast2obj_arguments(void* _o
)
3234 arguments_ty o
= (arguments_ty
)_o
;
3235 PyObject
*result
= NULL
, *value
= NULL
;
3241 result
= PyType_GenericNew(arguments_type
, NULL
, NULL
);
3242 if (!result
) return NULL
;
3243 value
= ast2obj_list(o
->args
, ast2obj_arg
);
3244 if (!value
) goto failed
;
3245 if (PyObject_SetAttrString(result
, "args", value
) == -1)
3248 value
= ast2obj_identifier(o
->vararg
);
3249 if (!value
) goto failed
;
3250 if (PyObject_SetAttrString(result
, "vararg", value
) == -1)
3253 value
= ast2obj_expr(o
->varargannotation
);
3254 if (!value
) goto failed
;
3255 if (PyObject_SetAttrString(result
, "varargannotation", value
) == -1)
3258 value
= ast2obj_list(o
->kwonlyargs
, ast2obj_arg
);
3259 if (!value
) goto failed
;
3260 if (PyObject_SetAttrString(result
, "kwonlyargs", value
) == -1)
3263 value
= ast2obj_identifier(o
->kwarg
);
3264 if (!value
) goto failed
;
3265 if (PyObject_SetAttrString(result
, "kwarg", value
) == -1)
3268 value
= ast2obj_expr(o
->kwargannotation
);
3269 if (!value
) goto failed
;
3270 if (PyObject_SetAttrString(result
, "kwargannotation", value
) == -1)
3273 value
= ast2obj_list(o
->defaults
, ast2obj_expr
);
3274 if (!value
) goto failed
;
3275 if (PyObject_SetAttrString(result
, "defaults", value
) == -1)
3278 value
= ast2obj_list(o
->kw_defaults
, ast2obj_expr
);
3279 if (!value
) goto failed
;
3280 if (PyObject_SetAttrString(result
, "kw_defaults", value
) == -1)
3291 ast2obj_arg(void* _o
)
3293 arg_ty o
= (arg_ty
)_o
;
3294 PyObject
*result
= NULL
, *value
= NULL
;
3300 result
= PyType_GenericNew(arg_type
, NULL
, NULL
);
3301 if (!result
) return NULL
;
3302 value
= ast2obj_identifier(o
->arg
);
3303 if (!value
) goto failed
;
3304 if (PyObject_SetAttrString(result
, "arg", value
) == -1)
3307 value
= ast2obj_expr(o
->annotation
);
3308 if (!value
) goto failed
;
3309 if (PyObject_SetAttrString(result
, "annotation", value
) == -1)
3320 ast2obj_keyword(void* _o
)
3322 keyword_ty o
= (keyword_ty
)_o
;
3323 PyObject
*result
= NULL
, *value
= NULL
;
3329 result
= PyType_GenericNew(keyword_type
, NULL
, NULL
);
3330 if (!result
) return NULL
;
3331 value
= ast2obj_identifier(o
->arg
);
3332 if (!value
) goto failed
;
3333 if (PyObject_SetAttrString(result
, "arg", value
) == -1)
3336 value
= ast2obj_expr(o
->value
);
3337 if (!value
) goto failed
;
3338 if (PyObject_SetAttrString(result
, "value", value
) == -1)
3349 ast2obj_alias(void* _o
)
3351 alias_ty o
= (alias_ty
)_o
;
3352 PyObject
*result
= NULL
, *value
= NULL
;
3358 result
= PyType_GenericNew(alias_type
, NULL
, NULL
);
3359 if (!result
) return NULL
;
3360 value
= ast2obj_identifier(o
->name
);
3361 if (!value
) goto failed
;
3362 if (PyObject_SetAttrString(result
, "name", value
) == -1)
3365 value
= ast2obj_identifier(o
->asname
);
3366 if (!value
) goto failed
;
3367 if (PyObject_SetAttrString(result
, "asname", value
) == -1)
3379 obj2ast_mod(PyObject
* obj
, mod_ty
* out
, PyArena
* arena
)
3381 PyObject
* tmp
= NULL
;
3385 if (obj
== Py_None
) {
3389 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Module_type
);
3390 if (isinstance
== -1) {
3396 if (PyObject_HasAttrString(obj
, "body")) {
3400 tmp
= PyObject_GetAttrString(obj
, "body");
3401 if (tmp
== NULL
) goto failed
;
3402 if (!PyList_Check(tmp
)) {
3403 PyErr_Format(PyExc_TypeError
, "Module field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3406 len
= PyList_GET_SIZE(tmp
);
3407 body
= asdl_seq_new(len
, arena
);
3408 if (body
== NULL
) goto failed
;
3409 for (i
= 0; i
< len
; i
++) {
3411 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3412 if (res
!= 0) goto failed
;
3413 asdl_seq_SET(body
, i
, value
);
3418 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from Module");
3421 *out
= Module(body
, arena
);
3422 if (*out
== NULL
) goto failed
;
3425 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Interactive_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
, "Interactive 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 Interactive");
3457 *out
= Interactive(body
, arena
);
3458 if (*out
== NULL
) goto failed
;
3461 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Expression_type
);
3462 if (isinstance
== -1) {
3468 if (PyObject_HasAttrString(obj
, "body")) {
3470 tmp
= PyObject_GetAttrString(obj
, "body");
3471 if (tmp
== NULL
) goto failed
;
3472 res
= obj2ast_expr(tmp
, &body
, arena
);
3473 if (res
!= 0) goto failed
;
3477 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from Expression");
3480 *out
= Expression(body
, arena
);
3481 if (*out
== NULL
) goto failed
;
3484 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Suite_type
);
3485 if (isinstance
== -1) {
3491 if (PyObject_HasAttrString(obj
, "body")) {
3495 tmp
= PyObject_GetAttrString(obj
, "body");
3496 if (tmp
== NULL
) goto failed
;
3497 if (!PyList_Check(tmp
)) {
3498 PyErr_Format(PyExc_TypeError
, "Suite field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3501 len
= PyList_GET_SIZE(tmp
);
3502 body
= asdl_seq_new(len
, arena
);
3503 if (body
== NULL
) goto failed
;
3504 for (i
= 0; i
< len
; i
++) {
3506 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3507 if (res
!= 0) goto failed
;
3508 asdl_seq_SET(body
, i
, value
);
3513 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from Suite");
3516 *out
= Suite(body
, arena
);
3517 if (*out
== NULL
) goto failed
;
3521 tmp
= PyObject_Repr(obj
);
3522 if (tmp
== NULL
) goto failed
;
3523 PyErr_Format(PyExc_TypeError
, "expected some sort of mod, but got %.400s", PyBytes_AS_STRING(tmp
));
3530 obj2ast_stmt(PyObject
* obj
, stmt_ty
* out
, PyArena
* arena
)
3532 PyObject
* tmp
= NULL
;
3538 if (obj
== Py_None
) {
3542 if (PyObject_HasAttrString(obj
, "lineno")) {
3544 tmp
= PyObject_GetAttrString(obj
, "lineno");
3545 if (tmp
== NULL
) goto failed
;
3546 res
= obj2ast_int(tmp
, &lineno
, arena
);
3547 if (res
!= 0) goto failed
;
3551 PyErr_SetString(PyExc_TypeError
, "required field \"lineno\" missing from stmt");
3554 if (PyObject_HasAttrString(obj
, "col_offset")) {
3556 tmp
= PyObject_GetAttrString(obj
, "col_offset");
3557 if (tmp
== NULL
) goto failed
;
3558 res
= obj2ast_int(tmp
, &col_offset
, arena
);
3559 if (res
!= 0) goto failed
;
3563 PyErr_SetString(PyExc_TypeError
, "required field \"col_offset\" missing from stmt");
3566 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)FunctionDef_type
);
3567 if (isinstance
== -1) {
3574 asdl_seq
* decorator_list
;
3577 if (PyObject_HasAttrString(obj
, "name")) {
3579 tmp
= PyObject_GetAttrString(obj
, "name");
3580 if (tmp
== NULL
) goto failed
;
3581 res
= obj2ast_identifier(tmp
, &name
, arena
);
3582 if (res
!= 0) goto failed
;
3586 PyErr_SetString(PyExc_TypeError
, "required field \"name\" missing from FunctionDef");
3589 if (PyObject_HasAttrString(obj
, "args")) {
3591 tmp
= PyObject_GetAttrString(obj
, "args");
3592 if (tmp
== NULL
) goto failed
;
3593 res
= obj2ast_arguments(tmp
, &args
, arena
);
3594 if (res
!= 0) goto failed
;
3598 PyErr_SetString(PyExc_TypeError
, "required field \"args\" missing from FunctionDef");
3601 if (PyObject_HasAttrString(obj
, "body")) {
3605 tmp
= PyObject_GetAttrString(obj
, "body");
3606 if (tmp
== NULL
) goto failed
;
3607 if (!PyList_Check(tmp
)) {
3608 PyErr_Format(PyExc_TypeError
, "FunctionDef field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3611 len
= PyList_GET_SIZE(tmp
);
3612 body
= asdl_seq_new(len
, arena
);
3613 if (body
== NULL
) goto failed
;
3614 for (i
= 0; i
< len
; i
++) {
3616 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3617 if (res
!= 0) goto failed
;
3618 asdl_seq_SET(body
, i
, value
);
3623 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from FunctionDef");
3626 if (PyObject_HasAttrString(obj
, "decorator_list")) {
3630 tmp
= PyObject_GetAttrString(obj
, "decorator_list");
3631 if (tmp
== NULL
) goto failed
;
3632 if (!PyList_Check(tmp
)) {
3633 PyErr_Format(PyExc_TypeError
, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3636 len
= PyList_GET_SIZE(tmp
);
3637 decorator_list
= asdl_seq_new(len
, arena
);
3638 if (decorator_list
== NULL
) goto failed
;
3639 for (i
= 0; i
< len
; i
++) {
3641 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3642 if (res
!= 0) goto failed
;
3643 asdl_seq_SET(decorator_list
, i
, value
);
3648 PyErr_SetString(PyExc_TypeError
, "required field \"decorator_list\" missing from FunctionDef");
3651 if (PyObject_HasAttrString(obj
, "returns")) {
3653 tmp
= PyObject_GetAttrString(obj
, "returns");
3654 if (tmp
== NULL
) goto failed
;
3655 res
= obj2ast_expr(tmp
, &returns
, arena
);
3656 if (res
!= 0) goto failed
;
3662 *out
= FunctionDef(name
, args
, body
, decorator_list
, returns
,
3663 lineno
, col_offset
, arena
);
3664 if (*out
== NULL
) goto failed
;
3667 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)ClassDef_type
);
3668 if (isinstance
== -1) {
3678 asdl_seq
* decorator_list
;
3680 if (PyObject_HasAttrString(obj
, "name")) {
3682 tmp
= PyObject_GetAttrString(obj
, "name");
3683 if (tmp
== NULL
) goto failed
;
3684 res
= obj2ast_identifier(tmp
, &name
, arena
);
3685 if (res
!= 0) goto failed
;
3689 PyErr_SetString(PyExc_TypeError
, "required field \"name\" missing from ClassDef");
3692 if (PyObject_HasAttrString(obj
, "bases")) {
3696 tmp
= PyObject_GetAttrString(obj
, "bases");
3697 if (tmp
== NULL
) goto failed
;
3698 if (!PyList_Check(tmp
)) {
3699 PyErr_Format(PyExc_TypeError
, "ClassDef field \"bases\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3702 len
= PyList_GET_SIZE(tmp
);
3703 bases
= asdl_seq_new(len
, arena
);
3704 if (bases
== NULL
) goto failed
;
3705 for (i
= 0; i
< len
; i
++) {
3707 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3708 if (res
!= 0) goto failed
;
3709 asdl_seq_SET(bases
, i
, value
);
3714 PyErr_SetString(PyExc_TypeError
, "required field \"bases\" missing from ClassDef");
3717 if (PyObject_HasAttrString(obj
, "keywords")) {
3721 tmp
= PyObject_GetAttrString(obj
, "keywords");
3722 if (tmp
== NULL
) goto failed
;
3723 if (!PyList_Check(tmp
)) {
3724 PyErr_Format(PyExc_TypeError
, "ClassDef field \"keywords\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3727 len
= PyList_GET_SIZE(tmp
);
3728 keywords
= asdl_seq_new(len
, arena
);
3729 if (keywords
== NULL
) goto failed
;
3730 for (i
= 0; i
< len
; i
++) {
3732 res
= obj2ast_keyword(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3733 if (res
!= 0) goto failed
;
3734 asdl_seq_SET(keywords
, i
, value
);
3739 PyErr_SetString(PyExc_TypeError
, "required field \"keywords\" missing from ClassDef");
3742 if (PyObject_HasAttrString(obj
, "starargs")) {
3744 tmp
= PyObject_GetAttrString(obj
, "starargs");
3745 if (tmp
== NULL
) goto failed
;
3746 res
= obj2ast_expr(tmp
, &starargs
, arena
);
3747 if (res
!= 0) goto failed
;
3753 if (PyObject_HasAttrString(obj
, "kwargs")) {
3755 tmp
= PyObject_GetAttrString(obj
, "kwargs");
3756 if (tmp
== NULL
) goto failed
;
3757 res
= obj2ast_expr(tmp
, &kwargs
, arena
);
3758 if (res
!= 0) goto failed
;
3764 if (PyObject_HasAttrString(obj
, "body")) {
3768 tmp
= PyObject_GetAttrString(obj
, "body");
3769 if (tmp
== NULL
) goto failed
;
3770 if (!PyList_Check(tmp
)) {
3771 PyErr_Format(PyExc_TypeError
, "ClassDef field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3774 len
= PyList_GET_SIZE(tmp
);
3775 body
= asdl_seq_new(len
, arena
);
3776 if (body
== NULL
) goto failed
;
3777 for (i
= 0; i
< len
; i
++) {
3779 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3780 if (res
!= 0) goto failed
;
3781 asdl_seq_SET(body
, i
, value
);
3786 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from ClassDef");
3789 if (PyObject_HasAttrString(obj
, "decorator_list")) {
3793 tmp
= PyObject_GetAttrString(obj
, "decorator_list");
3794 if (tmp
== NULL
) goto failed
;
3795 if (!PyList_Check(tmp
)) {
3796 PyErr_Format(PyExc_TypeError
, "ClassDef field \"decorator_list\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3799 len
= PyList_GET_SIZE(tmp
);
3800 decorator_list
= asdl_seq_new(len
, arena
);
3801 if (decorator_list
== NULL
) goto failed
;
3802 for (i
= 0; i
< len
; i
++) {
3804 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3805 if (res
!= 0) goto failed
;
3806 asdl_seq_SET(decorator_list
, i
, value
);
3811 PyErr_SetString(PyExc_TypeError
, "required field \"decorator_list\" missing from ClassDef");
3814 *out
= ClassDef(name
, bases
, keywords
, starargs
, kwargs
, body
,
3815 decorator_list
, lineno
, col_offset
, arena
);
3816 if (*out
== NULL
) goto failed
;
3819 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Return_type
);
3820 if (isinstance
== -1) {
3826 if (PyObject_HasAttrString(obj
, "value")) {
3828 tmp
= PyObject_GetAttrString(obj
, "value");
3829 if (tmp
== NULL
) goto failed
;
3830 res
= obj2ast_expr(tmp
, &value
, arena
);
3831 if (res
!= 0) goto failed
;
3837 *out
= Return(value
, lineno
, col_offset
, arena
);
3838 if (*out
== NULL
) goto failed
;
3841 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Delete_type
);
3842 if (isinstance
== -1) {
3848 if (PyObject_HasAttrString(obj
, "targets")) {
3852 tmp
= PyObject_GetAttrString(obj
, "targets");
3853 if (tmp
== NULL
) goto failed
;
3854 if (!PyList_Check(tmp
)) {
3855 PyErr_Format(PyExc_TypeError
, "Delete field \"targets\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3858 len
= PyList_GET_SIZE(tmp
);
3859 targets
= asdl_seq_new(len
, arena
);
3860 if (targets
== NULL
) goto failed
;
3861 for (i
= 0; i
< len
; i
++) {
3863 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3864 if (res
!= 0) goto failed
;
3865 asdl_seq_SET(targets
, i
, value
);
3870 PyErr_SetString(PyExc_TypeError
, "required field \"targets\" missing from Delete");
3873 *out
= Delete(targets
, lineno
, col_offset
, arena
);
3874 if (*out
== NULL
) goto failed
;
3877 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Assign_type
);
3878 if (isinstance
== -1) {
3885 if (PyObject_HasAttrString(obj
, "targets")) {
3889 tmp
= PyObject_GetAttrString(obj
, "targets");
3890 if (tmp
== NULL
) goto failed
;
3891 if (!PyList_Check(tmp
)) {
3892 PyErr_Format(PyExc_TypeError
, "Assign field \"targets\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3895 len
= PyList_GET_SIZE(tmp
);
3896 targets
= asdl_seq_new(len
, arena
);
3897 if (targets
== NULL
) goto failed
;
3898 for (i
= 0; i
< len
; i
++) {
3900 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3901 if (res
!= 0) goto failed
;
3902 asdl_seq_SET(targets
, i
, value
);
3907 PyErr_SetString(PyExc_TypeError
, "required field \"targets\" missing from Assign");
3910 if (PyObject_HasAttrString(obj
, "value")) {
3912 tmp
= PyObject_GetAttrString(obj
, "value");
3913 if (tmp
== NULL
) goto failed
;
3914 res
= obj2ast_expr(tmp
, &value
, arena
);
3915 if (res
!= 0) goto failed
;
3919 PyErr_SetString(PyExc_TypeError
, "required field \"value\" missing from Assign");
3922 *out
= Assign(targets
, value
, lineno
, col_offset
, arena
);
3923 if (*out
== NULL
) goto failed
;
3926 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)AugAssign_type
);
3927 if (isinstance
== -1) {
3935 if (PyObject_HasAttrString(obj
, "target")) {
3937 tmp
= PyObject_GetAttrString(obj
, "target");
3938 if (tmp
== NULL
) goto failed
;
3939 res
= obj2ast_expr(tmp
, &target
, arena
);
3940 if (res
!= 0) goto failed
;
3944 PyErr_SetString(PyExc_TypeError
, "required field \"target\" missing from AugAssign");
3947 if (PyObject_HasAttrString(obj
, "op")) {
3949 tmp
= PyObject_GetAttrString(obj
, "op");
3950 if (tmp
== NULL
) goto failed
;
3951 res
= obj2ast_operator(tmp
, &op
, arena
);
3952 if (res
!= 0) goto failed
;
3956 PyErr_SetString(PyExc_TypeError
, "required field \"op\" missing from AugAssign");
3959 if (PyObject_HasAttrString(obj
, "value")) {
3961 tmp
= PyObject_GetAttrString(obj
, "value");
3962 if (tmp
== NULL
) goto failed
;
3963 res
= obj2ast_expr(tmp
, &value
, arena
);
3964 if (res
!= 0) goto failed
;
3968 PyErr_SetString(PyExc_TypeError
, "required field \"value\" missing from AugAssign");
3971 *out
= AugAssign(target
, op
, value
, lineno
, col_offset
, arena
);
3972 if (*out
== NULL
) goto failed
;
3975 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)For_type
);
3976 if (isinstance
== -1) {
3985 if (PyObject_HasAttrString(obj
, "target")) {
3987 tmp
= PyObject_GetAttrString(obj
, "target");
3988 if (tmp
== NULL
) goto failed
;
3989 res
= obj2ast_expr(tmp
, &target
, arena
);
3990 if (res
!= 0) goto failed
;
3994 PyErr_SetString(PyExc_TypeError
, "required field \"target\" missing from For");
3997 if (PyObject_HasAttrString(obj
, "iter")) {
3999 tmp
= PyObject_GetAttrString(obj
, "iter");
4000 if (tmp
== NULL
) goto failed
;
4001 res
= obj2ast_expr(tmp
, &iter
, arena
);
4002 if (res
!= 0) goto failed
;
4006 PyErr_SetString(PyExc_TypeError
, "required field \"iter\" missing from For");
4009 if (PyObject_HasAttrString(obj
, "body")) {
4013 tmp
= PyObject_GetAttrString(obj
, "body");
4014 if (tmp
== NULL
) goto failed
;
4015 if (!PyList_Check(tmp
)) {
4016 PyErr_Format(PyExc_TypeError
, "For field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4019 len
= PyList_GET_SIZE(tmp
);
4020 body
= asdl_seq_new(len
, arena
);
4021 if (body
== NULL
) goto failed
;
4022 for (i
= 0; i
< len
; i
++) {
4024 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4025 if (res
!= 0) goto failed
;
4026 asdl_seq_SET(body
, i
, value
);
4031 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from For");
4034 if (PyObject_HasAttrString(obj
, "orelse")) {
4038 tmp
= PyObject_GetAttrString(obj
, "orelse");
4039 if (tmp
== NULL
) goto failed
;
4040 if (!PyList_Check(tmp
)) {
4041 PyErr_Format(PyExc_TypeError
, "For field \"orelse\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4044 len
= PyList_GET_SIZE(tmp
);
4045 orelse
= asdl_seq_new(len
, arena
);
4046 if (orelse
== NULL
) goto failed
;
4047 for (i
= 0; i
< len
; i
++) {
4049 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4050 if (res
!= 0) goto failed
;
4051 asdl_seq_SET(orelse
, i
, value
);
4056 PyErr_SetString(PyExc_TypeError
, "required field \"orelse\" missing from For");
4059 *out
= For(target
, iter
, body
, orelse
, lineno
, col_offset
,
4061 if (*out
== NULL
) goto failed
;
4064 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)While_type
);
4065 if (isinstance
== -1) {
4073 if (PyObject_HasAttrString(obj
, "test")) {
4075 tmp
= PyObject_GetAttrString(obj
, "test");
4076 if (tmp
== NULL
) goto failed
;
4077 res
= obj2ast_expr(tmp
, &test
, arena
);
4078 if (res
!= 0) goto failed
;
4082 PyErr_SetString(PyExc_TypeError
, "required field \"test\" missing from While");
4085 if (PyObject_HasAttrString(obj
, "body")) {
4089 tmp
= PyObject_GetAttrString(obj
, "body");
4090 if (tmp
== NULL
) goto failed
;
4091 if (!PyList_Check(tmp
)) {
4092 PyErr_Format(PyExc_TypeError
, "While field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4095 len
= PyList_GET_SIZE(tmp
);
4096 body
= asdl_seq_new(len
, arena
);
4097 if (body
== NULL
) goto failed
;
4098 for (i
= 0; i
< len
; i
++) {
4100 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4101 if (res
!= 0) goto failed
;
4102 asdl_seq_SET(body
, i
, value
);
4107 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from While");
4110 if (PyObject_HasAttrString(obj
, "orelse")) {
4114 tmp
= PyObject_GetAttrString(obj
, "orelse");
4115 if (tmp
== NULL
) goto failed
;
4116 if (!PyList_Check(tmp
)) {
4117 PyErr_Format(PyExc_TypeError
, "While field \"orelse\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4120 len
= PyList_GET_SIZE(tmp
);
4121 orelse
= asdl_seq_new(len
, arena
);
4122 if (orelse
== NULL
) goto failed
;
4123 for (i
= 0; i
< len
; i
++) {
4125 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4126 if (res
!= 0) goto failed
;
4127 asdl_seq_SET(orelse
, i
, value
);
4132 PyErr_SetString(PyExc_TypeError
, "required field \"orelse\" missing from While");
4135 *out
= While(test
, body
, orelse
, lineno
, col_offset
, arena
);
4136 if (*out
== NULL
) goto failed
;
4139 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)If_type
);
4140 if (isinstance
== -1) {
4148 if (PyObject_HasAttrString(obj
, "test")) {
4150 tmp
= PyObject_GetAttrString(obj
, "test");
4151 if (tmp
== NULL
) goto failed
;
4152 res
= obj2ast_expr(tmp
, &test
, arena
);
4153 if (res
!= 0) goto failed
;
4157 PyErr_SetString(PyExc_TypeError
, "required field \"test\" missing from If");
4160 if (PyObject_HasAttrString(obj
, "body")) {
4164 tmp
= PyObject_GetAttrString(obj
, "body");
4165 if (tmp
== NULL
) goto failed
;
4166 if (!PyList_Check(tmp
)) {
4167 PyErr_Format(PyExc_TypeError
, "If field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4170 len
= PyList_GET_SIZE(tmp
);
4171 body
= asdl_seq_new(len
, arena
);
4172 if (body
== NULL
) goto failed
;
4173 for (i
= 0; i
< len
; i
++) {
4175 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4176 if (res
!= 0) goto failed
;
4177 asdl_seq_SET(body
, i
, value
);
4182 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from If");
4185 if (PyObject_HasAttrString(obj
, "orelse")) {
4189 tmp
= PyObject_GetAttrString(obj
, "orelse");
4190 if (tmp
== NULL
) goto failed
;
4191 if (!PyList_Check(tmp
)) {
4192 PyErr_Format(PyExc_TypeError
, "If field \"orelse\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4195 len
= PyList_GET_SIZE(tmp
);
4196 orelse
= asdl_seq_new(len
, arena
);
4197 if (orelse
== NULL
) goto failed
;
4198 for (i
= 0; i
< len
; i
++) {
4200 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4201 if (res
!= 0) goto failed
;
4202 asdl_seq_SET(orelse
, i
, value
);
4207 PyErr_SetString(PyExc_TypeError
, "required field \"orelse\" missing from If");
4210 *out
= If(test
, body
, orelse
, lineno
, col_offset
, arena
);
4211 if (*out
== NULL
) goto failed
;
4214 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)With_type
);
4215 if (isinstance
== -1) {
4219 expr_ty context_expr
;
4220 expr_ty optional_vars
;
4223 if (PyObject_HasAttrString(obj
, "context_expr")) {
4225 tmp
= PyObject_GetAttrString(obj
, "context_expr");
4226 if (tmp
== NULL
) goto failed
;
4227 res
= obj2ast_expr(tmp
, &context_expr
, arena
);
4228 if (res
!= 0) goto failed
;
4232 PyErr_SetString(PyExc_TypeError
, "required field \"context_expr\" missing from With");
4235 if (PyObject_HasAttrString(obj
, "optional_vars")) {
4237 tmp
= PyObject_GetAttrString(obj
, "optional_vars");
4238 if (tmp
== NULL
) goto failed
;
4239 res
= obj2ast_expr(tmp
, &optional_vars
, arena
);
4240 if (res
!= 0) goto failed
;
4244 optional_vars
= NULL
;
4246 if (PyObject_HasAttrString(obj
, "body")) {
4250 tmp
= PyObject_GetAttrString(obj
, "body");
4251 if (tmp
== NULL
) goto failed
;
4252 if (!PyList_Check(tmp
)) {
4253 PyErr_Format(PyExc_TypeError
, "With field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4256 len
= PyList_GET_SIZE(tmp
);
4257 body
= asdl_seq_new(len
, arena
);
4258 if (body
== NULL
) goto failed
;
4259 for (i
= 0; i
< len
; i
++) {
4261 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4262 if (res
!= 0) goto failed
;
4263 asdl_seq_SET(body
, i
, value
);
4268 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from With");
4271 *out
= With(context_expr
, optional_vars
, body
, lineno
,
4273 if (*out
== NULL
) goto failed
;
4276 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Raise_type
);
4277 if (isinstance
== -1) {
4284 if (PyObject_HasAttrString(obj
, "exc")) {
4286 tmp
= PyObject_GetAttrString(obj
, "exc");
4287 if (tmp
== NULL
) goto failed
;
4288 res
= obj2ast_expr(tmp
, &exc
, arena
);
4289 if (res
!= 0) goto failed
;
4295 if (PyObject_HasAttrString(obj
, "cause")) {
4297 tmp
= PyObject_GetAttrString(obj
, "cause");
4298 if (tmp
== NULL
) goto failed
;
4299 res
= obj2ast_expr(tmp
, &cause
, arena
);
4300 if (res
!= 0) goto failed
;
4306 *out
= Raise(exc
, cause
, lineno
, col_offset
, arena
);
4307 if (*out
== NULL
) goto failed
;
4310 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)TryExcept_type
);
4311 if (isinstance
== -1) {
4319 if (PyObject_HasAttrString(obj
, "body")) {
4323 tmp
= PyObject_GetAttrString(obj
, "body");
4324 if (tmp
== NULL
) goto failed
;
4325 if (!PyList_Check(tmp
)) {
4326 PyErr_Format(PyExc_TypeError
, "TryExcept field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4329 len
= PyList_GET_SIZE(tmp
);
4330 body
= asdl_seq_new(len
, arena
);
4331 if (body
== NULL
) goto failed
;
4332 for (i
= 0; i
< len
; i
++) {
4334 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4335 if (res
!= 0) goto failed
;
4336 asdl_seq_SET(body
, i
, value
);
4341 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from TryExcept");
4344 if (PyObject_HasAttrString(obj
, "handlers")) {
4348 tmp
= PyObject_GetAttrString(obj
, "handlers");
4349 if (tmp
== NULL
) goto failed
;
4350 if (!PyList_Check(tmp
)) {
4351 PyErr_Format(PyExc_TypeError
, "TryExcept field \"handlers\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4354 len
= PyList_GET_SIZE(tmp
);
4355 handlers
= asdl_seq_new(len
, arena
);
4356 if (handlers
== NULL
) goto failed
;
4357 for (i
= 0; i
< len
; i
++) {
4358 excepthandler_ty value
;
4359 res
= obj2ast_excepthandler(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4360 if (res
!= 0) goto failed
;
4361 asdl_seq_SET(handlers
, i
, value
);
4366 PyErr_SetString(PyExc_TypeError
, "required field \"handlers\" missing from TryExcept");
4369 if (PyObject_HasAttrString(obj
, "orelse")) {
4373 tmp
= PyObject_GetAttrString(obj
, "orelse");
4374 if (tmp
== NULL
) goto failed
;
4375 if (!PyList_Check(tmp
)) {
4376 PyErr_Format(PyExc_TypeError
, "TryExcept field \"orelse\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4379 len
= PyList_GET_SIZE(tmp
);
4380 orelse
= asdl_seq_new(len
, arena
);
4381 if (orelse
== NULL
) goto failed
;
4382 for (i
= 0; i
< len
; i
++) {
4384 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4385 if (res
!= 0) goto failed
;
4386 asdl_seq_SET(orelse
, i
, value
);
4391 PyErr_SetString(PyExc_TypeError
, "required field \"orelse\" missing from TryExcept");
4394 *out
= TryExcept(body
, handlers
, orelse
, lineno
, col_offset
,
4396 if (*out
== NULL
) goto failed
;
4399 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)TryFinally_type
);
4400 if (isinstance
== -1) {
4405 asdl_seq
* finalbody
;
4407 if (PyObject_HasAttrString(obj
, "body")) {
4411 tmp
= PyObject_GetAttrString(obj
, "body");
4412 if (tmp
== NULL
) goto failed
;
4413 if (!PyList_Check(tmp
)) {
4414 PyErr_Format(PyExc_TypeError
, "TryFinally field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4417 len
= PyList_GET_SIZE(tmp
);
4418 body
= asdl_seq_new(len
, arena
);
4419 if (body
== NULL
) goto failed
;
4420 for (i
= 0; i
< len
; i
++) {
4422 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4423 if (res
!= 0) goto failed
;
4424 asdl_seq_SET(body
, i
, value
);
4429 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from TryFinally");
4432 if (PyObject_HasAttrString(obj
, "finalbody")) {
4436 tmp
= PyObject_GetAttrString(obj
, "finalbody");
4437 if (tmp
== NULL
) goto failed
;
4438 if (!PyList_Check(tmp
)) {
4439 PyErr_Format(PyExc_TypeError
, "TryFinally field \"finalbody\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4442 len
= PyList_GET_SIZE(tmp
);
4443 finalbody
= asdl_seq_new(len
, arena
);
4444 if (finalbody
== NULL
) goto failed
;
4445 for (i
= 0; i
< len
; i
++) {
4447 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4448 if (res
!= 0) goto failed
;
4449 asdl_seq_SET(finalbody
, i
, value
);
4454 PyErr_SetString(PyExc_TypeError
, "required field \"finalbody\" missing from TryFinally");
4457 *out
= TryFinally(body
, finalbody
, lineno
, col_offset
, arena
);
4458 if (*out
== NULL
) goto failed
;
4461 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Assert_type
);
4462 if (isinstance
== -1) {
4469 if (PyObject_HasAttrString(obj
, "test")) {
4471 tmp
= PyObject_GetAttrString(obj
, "test");
4472 if (tmp
== NULL
) goto failed
;
4473 res
= obj2ast_expr(tmp
, &test
, arena
);
4474 if (res
!= 0) goto failed
;
4478 PyErr_SetString(PyExc_TypeError
, "required field \"test\" missing from Assert");
4481 if (PyObject_HasAttrString(obj
, "msg")) {
4483 tmp
= PyObject_GetAttrString(obj
, "msg");
4484 if (tmp
== NULL
) goto failed
;
4485 res
= obj2ast_expr(tmp
, &msg
, arena
);
4486 if (res
!= 0) goto failed
;
4492 *out
= Assert(test
, msg
, lineno
, col_offset
, arena
);
4493 if (*out
== NULL
) goto failed
;
4496 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Import_type
);
4497 if (isinstance
== -1) {
4503 if (PyObject_HasAttrString(obj
, "names")) {
4507 tmp
= PyObject_GetAttrString(obj
, "names");
4508 if (tmp
== NULL
) goto failed
;
4509 if (!PyList_Check(tmp
)) {
4510 PyErr_Format(PyExc_TypeError
, "Import field \"names\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4513 len
= PyList_GET_SIZE(tmp
);
4514 names
= asdl_seq_new(len
, arena
);
4515 if (names
== NULL
) goto failed
;
4516 for (i
= 0; i
< len
; i
++) {
4518 res
= obj2ast_alias(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4519 if (res
!= 0) goto failed
;
4520 asdl_seq_SET(names
, i
, value
);
4525 PyErr_SetString(PyExc_TypeError
, "required field \"names\" missing from Import");
4528 *out
= Import(names
, lineno
, col_offset
, arena
);
4529 if (*out
== NULL
) goto failed
;
4532 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)ImportFrom_type
);
4533 if (isinstance
== -1) {
4541 if (PyObject_HasAttrString(obj
, "module")) {
4543 tmp
= PyObject_GetAttrString(obj
, "module");
4544 if (tmp
== NULL
) goto failed
;
4545 res
= obj2ast_identifier(tmp
, &module
, arena
);
4546 if (res
!= 0) goto failed
;
4550 PyErr_SetString(PyExc_TypeError
, "required field \"module\" missing from ImportFrom");
4553 if (PyObject_HasAttrString(obj
, "names")) {
4557 tmp
= PyObject_GetAttrString(obj
, "names");
4558 if (tmp
== NULL
) goto failed
;
4559 if (!PyList_Check(tmp
)) {
4560 PyErr_Format(PyExc_TypeError
, "ImportFrom field \"names\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4563 len
= PyList_GET_SIZE(tmp
);
4564 names
= asdl_seq_new(len
, arena
);
4565 if (names
== NULL
) goto failed
;
4566 for (i
= 0; i
< len
; i
++) {
4568 res
= obj2ast_alias(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4569 if (res
!= 0) goto failed
;
4570 asdl_seq_SET(names
, i
, value
);
4575 PyErr_SetString(PyExc_TypeError
, "required field \"names\" missing from ImportFrom");
4578 if (PyObject_HasAttrString(obj
, "level")) {
4580 tmp
= PyObject_GetAttrString(obj
, "level");
4581 if (tmp
== NULL
) goto failed
;
4582 res
= obj2ast_int(tmp
, &level
, arena
);
4583 if (res
!= 0) goto failed
;
4589 *out
= ImportFrom(module
, names
, level
, lineno
, col_offset
,
4591 if (*out
== NULL
) goto failed
;
4594 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Global_type
);
4595 if (isinstance
== -1) {
4601 if (PyObject_HasAttrString(obj
, "names")) {
4605 tmp
= PyObject_GetAttrString(obj
, "names");
4606 if (tmp
== NULL
) goto failed
;
4607 if (!PyList_Check(tmp
)) {
4608 PyErr_Format(PyExc_TypeError
, "Global field \"names\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4611 len
= PyList_GET_SIZE(tmp
);
4612 names
= asdl_seq_new(len
, arena
);
4613 if (names
== NULL
) goto failed
;
4614 for (i
= 0; i
< len
; i
++) {
4616 res
= obj2ast_identifier(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4617 if (res
!= 0) goto failed
;
4618 asdl_seq_SET(names
, i
, value
);
4623 PyErr_SetString(PyExc_TypeError
, "required field \"names\" missing from Global");
4626 *out
= Global(names
, lineno
, col_offset
, arena
);
4627 if (*out
== NULL
) goto failed
;
4630 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Nonlocal_type
);
4631 if (isinstance
== -1) {
4637 if (PyObject_HasAttrString(obj
, "names")) {
4641 tmp
= PyObject_GetAttrString(obj
, "names");
4642 if (tmp
== NULL
) goto failed
;
4643 if (!PyList_Check(tmp
)) {
4644 PyErr_Format(PyExc_TypeError
, "Nonlocal field \"names\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4647 len
= PyList_GET_SIZE(tmp
);
4648 names
= asdl_seq_new(len
, arena
);
4649 if (names
== NULL
) goto failed
;
4650 for (i
= 0; i
< len
; i
++) {
4652 res
= obj2ast_identifier(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4653 if (res
!= 0) goto failed
;
4654 asdl_seq_SET(names
, i
, value
);
4659 PyErr_SetString(PyExc_TypeError
, "required field \"names\" missing from Nonlocal");
4662 *out
= Nonlocal(names
, lineno
, col_offset
, arena
);
4663 if (*out
== NULL
) goto failed
;
4666 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Expr_type
);
4667 if (isinstance
== -1) {
4673 if (PyObject_HasAttrString(obj
, "value")) {
4675 tmp
= PyObject_GetAttrString(obj
, "value");
4676 if (tmp
== NULL
) goto failed
;
4677 res
= obj2ast_expr(tmp
, &value
, arena
);
4678 if (res
!= 0) goto failed
;
4682 PyErr_SetString(PyExc_TypeError
, "required field \"value\" missing from Expr");
4685 *out
= Expr(value
, lineno
, col_offset
, arena
);
4686 if (*out
== NULL
) goto failed
;
4689 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Pass_type
);
4690 if (isinstance
== -1) {
4695 *out
= Pass(lineno
, col_offset
, arena
);
4696 if (*out
== NULL
) goto failed
;
4699 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Break_type
);
4700 if (isinstance
== -1) {
4705 *out
= Break(lineno
, col_offset
, arena
);
4706 if (*out
== NULL
) goto failed
;
4709 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Continue_type
);
4710 if (isinstance
== -1) {
4715 *out
= Continue(lineno
, col_offset
, arena
);
4716 if (*out
== NULL
) goto failed
;
4720 tmp
= PyObject_Repr(obj
);
4721 if (tmp
== NULL
) goto failed
;
4722 PyErr_Format(PyExc_TypeError
, "expected some sort of stmt, but got %.400s", PyBytes_AS_STRING(tmp
));
4729 obj2ast_expr(PyObject
* obj
, expr_ty
* out
, PyArena
* arena
)
4731 PyObject
* tmp
= NULL
;
4737 if (obj
== Py_None
) {
4741 if (PyObject_HasAttrString(obj
, "lineno")) {
4743 tmp
= PyObject_GetAttrString(obj
, "lineno");
4744 if (tmp
== NULL
) goto failed
;
4745 res
= obj2ast_int(tmp
, &lineno
, arena
);
4746 if (res
!= 0) goto failed
;
4750 PyErr_SetString(PyExc_TypeError
, "required field \"lineno\" missing from expr");
4753 if (PyObject_HasAttrString(obj
, "col_offset")) {
4755 tmp
= PyObject_GetAttrString(obj
, "col_offset");
4756 if (tmp
== NULL
) goto failed
;
4757 res
= obj2ast_int(tmp
, &col_offset
, arena
);
4758 if (res
!= 0) goto failed
;
4762 PyErr_SetString(PyExc_TypeError
, "required field \"col_offset\" missing from expr");
4765 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)BoolOp_type
);
4766 if (isinstance
== -1) {
4773 if (PyObject_HasAttrString(obj
, "op")) {
4775 tmp
= PyObject_GetAttrString(obj
, "op");
4776 if (tmp
== NULL
) goto failed
;
4777 res
= obj2ast_boolop(tmp
, &op
, arena
);
4778 if (res
!= 0) goto failed
;
4782 PyErr_SetString(PyExc_TypeError
, "required field \"op\" missing from BoolOp");
4785 if (PyObject_HasAttrString(obj
, "values")) {
4789 tmp
= PyObject_GetAttrString(obj
, "values");
4790 if (tmp
== NULL
) goto failed
;
4791 if (!PyList_Check(tmp
)) {
4792 PyErr_Format(PyExc_TypeError
, "BoolOp field \"values\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4795 len
= PyList_GET_SIZE(tmp
);
4796 values
= asdl_seq_new(len
, arena
);
4797 if (values
== NULL
) goto failed
;
4798 for (i
= 0; i
< len
; i
++) {
4800 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4801 if (res
!= 0) goto failed
;
4802 asdl_seq_SET(values
, i
, value
);
4807 PyErr_SetString(PyExc_TypeError
, "required field \"values\" missing from BoolOp");
4810 *out
= BoolOp(op
, values
, lineno
, col_offset
, arena
);
4811 if (*out
== NULL
) goto failed
;
4814 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)BinOp_type
);
4815 if (isinstance
== -1) {
4823 if (PyObject_HasAttrString(obj
, "left")) {
4825 tmp
= PyObject_GetAttrString(obj
, "left");
4826 if (tmp
== NULL
) goto failed
;
4827 res
= obj2ast_expr(tmp
, &left
, arena
);
4828 if (res
!= 0) goto failed
;
4832 PyErr_SetString(PyExc_TypeError
, "required field \"left\" missing from BinOp");
4835 if (PyObject_HasAttrString(obj
, "op")) {
4837 tmp
= PyObject_GetAttrString(obj
, "op");
4838 if (tmp
== NULL
) goto failed
;
4839 res
= obj2ast_operator(tmp
, &op
, arena
);
4840 if (res
!= 0) goto failed
;
4844 PyErr_SetString(PyExc_TypeError
, "required field \"op\" missing from BinOp");
4847 if (PyObject_HasAttrString(obj
, "right")) {
4849 tmp
= PyObject_GetAttrString(obj
, "right");
4850 if (tmp
== NULL
) goto failed
;
4851 res
= obj2ast_expr(tmp
, &right
, arena
);
4852 if (res
!= 0) goto failed
;
4856 PyErr_SetString(PyExc_TypeError
, "required field \"right\" missing from BinOp");
4859 *out
= BinOp(left
, op
, right
, lineno
, col_offset
, arena
);
4860 if (*out
== NULL
) goto failed
;
4863 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)UnaryOp_type
);
4864 if (isinstance
== -1) {
4871 if (PyObject_HasAttrString(obj
, "op")) {
4873 tmp
= PyObject_GetAttrString(obj
, "op");
4874 if (tmp
== NULL
) goto failed
;
4875 res
= obj2ast_unaryop(tmp
, &op
, arena
);
4876 if (res
!= 0) goto failed
;
4880 PyErr_SetString(PyExc_TypeError
, "required field \"op\" missing from UnaryOp");
4883 if (PyObject_HasAttrString(obj
, "operand")) {
4885 tmp
= PyObject_GetAttrString(obj
, "operand");
4886 if (tmp
== NULL
) goto failed
;
4887 res
= obj2ast_expr(tmp
, &operand
, arena
);
4888 if (res
!= 0) goto failed
;
4892 PyErr_SetString(PyExc_TypeError
, "required field \"operand\" missing from UnaryOp");
4895 *out
= UnaryOp(op
, operand
, lineno
, col_offset
, arena
);
4896 if (*out
== NULL
) goto failed
;
4899 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Lambda_type
);
4900 if (isinstance
== -1) {
4907 if (PyObject_HasAttrString(obj
, "args")) {
4909 tmp
= PyObject_GetAttrString(obj
, "args");
4910 if (tmp
== NULL
) goto failed
;
4911 res
= obj2ast_arguments(tmp
, &args
, arena
);
4912 if (res
!= 0) goto failed
;
4916 PyErr_SetString(PyExc_TypeError
, "required field \"args\" missing from Lambda");
4919 if (PyObject_HasAttrString(obj
, "body")) {
4921 tmp
= PyObject_GetAttrString(obj
, "body");
4922 if (tmp
== NULL
) goto failed
;
4923 res
= obj2ast_expr(tmp
, &body
, arena
);
4924 if (res
!= 0) goto failed
;
4928 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from Lambda");
4931 *out
= Lambda(args
, body
, lineno
, col_offset
, arena
);
4932 if (*out
== NULL
) goto failed
;
4935 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)IfExp_type
);
4936 if (isinstance
== -1) {
4944 if (PyObject_HasAttrString(obj
, "test")) {
4946 tmp
= PyObject_GetAttrString(obj
, "test");
4947 if (tmp
== NULL
) goto failed
;
4948 res
= obj2ast_expr(tmp
, &test
, arena
);
4949 if (res
!= 0) goto failed
;
4953 PyErr_SetString(PyExc_TypeError
, "required field \"test\" missing from IfExp");
4956 if (PyObject_HasAttrString(obj
, "body")) {
4958 tmp
= PyObject_GetAttrString(obj
, "body");
4959 if (tmp
== NULL
) goto failed
;
4960 res
= obj2ast_expr(tmp
, &body
, arena
);
4961 if (res
!= 0) goto failed
;
4965 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from IfExp");
4968 if (PyObject_HasAttrString(obj
, "orelse")) {
4970 tmp
= PyObject_GetAttrString(obj
, "orelse");
4971 if (tmp
== NULL
) goto failed
;
4972 res
= obj2ast_expr(tmp
, &orelse
, arena
);
4973 if (res
!= 0) goto failed
;
4977 PyErr_SetString(PyExc_TypeError
, "required field \"orelse\" missing from IfExp");
4980 *out
= IfExp(test
, body
, orelse
, lineno
, col_offset
, arena
);
4981 if (*out
== NULL
) goto failed
;
4984 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Dict_type
);
4985 if (isinstance
== -1) {
4992 if (PyObject_HasAttrString(obj
, "keys")) {
4996 tmp
= PyObject_GetAttrString(obj
, "keys");
4997 if (tmp
== NULL
) goto failed
;
4998 if (!PyList_Check(tmp
)) {
4999 PyErr_Format(PyExc_TypeError
, "Dict field \"keys\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5002 len
= PyList_GET_SIZE(tmp
);
5003 keys
= asdl_seq_new(len
, arena
);
5004 if (keys
== NULL
) goto failed
;
5005 for (i
= 0; i
< len
; i
++) {
5007 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5008 if (res
!= 0) goto failed
;
5009 asdl_seq_SET(keys
, i
, value
);
5014 PyErr_SetString(PyExc_TypeError
, "required field \"keys\" missing from Dict");
5017 if (PyObject_HasAttrString(obj
, "values")) {
5021 tmp
= PyObject_GetAttrString(obj
, "values");
5022 if (tmp
== NULL
) goto failed
;
5023 if (!PyList_Check(tmp
)) {
5024 PyErr_Format(PyExc_TypeError
, "Dict field \"values\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5027 len
= PyList_GET_SIZE(tmp
);
5028 values
= asdl_seq_new(len
, arena
);
5029 if (values
== NULL
) goto failed
;
5030 for (i
= 0; i
< len
; i
++) {
5032 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5033 if (res
!= 0) goto failed
;
5034 asdl_seq_SET(values
, i
, value
);
5039 PyErr_SetString(PyExc_TypeError
, "required field \"values\" missing from Dict");
5042 *out
= Dict(keys
, values
, lineno
, col_offset
, arena
);
5043 if (*out
== NULL
) goto failed
;
5046 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Set_type
);
5047 if (isinstance
== -1) {
5053 if (PyObject_HasAttrString(obj
, "elts")) {
5057 tmp
= PyObject_GetAttrString(obj
, "elts");
5058 if (tmp
== NULL
) goto failed
;
5059 if (!PyList_Check(tmp
)) {
5060 PyErr_Format(PyExc_TypeError
, "Set field \"elts\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5063 len
= PyList_GET_SIZE(tmp
);
5064 elts
= asdl_seq_new(len
, arena
);
5065 if (elts
== NULL
) goto failed
;
5066 for (i
= 0; i
< len
; i
++) {
5068 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5069 if (res
!= 0) goto failed
;
5070 asdl_seq_SET(elts
, i
, value
);
5075 PyErr_SetString(PyExc_TypeError
, "required field \"elts\" missing from Set");
5078 *out
= Set(elts
, lineno
, col_offset
, arena
);
5079 if (*out
== NULL
) goto failed
;
5082 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)ListComp_type
);
5083 if (isinstance
== -1) {
5088 asdl_seq
* generators
;
5090 if (PyObject_HasAttrString(obj
, "elt")) {
5092 tmp
= PyObject_GetAttrString(obj
, "elt");
5093 if (tmp
== NULL
) goto failed
;
5094 res
= obj2ast_expr(tmp
, &elt
, arena
);
5095 if (res
!= 0) goto failed
;
5099 PyErr_SetString(PyExc_TypeError
, "required field \"elt\" missing from ListComp");
5102 if (PyObject_HasAttrString(obj
, "generators")) {
5106 tmp
= PyObject_GetAttrString(obj
, "generators");
5107 if (tmp
== NULL
) goto failed
;
5108 if (!PyList_Check(tmp
)) {
5109 PyErr_Format(PyExc_TypeError
, "ListComp field \"generators\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5112 len
= PyList_GET_SIZE(tmp
);
5113 generators
= asdl_seq_new(len
, arena
);
5114 if (generators
== NULL
) goto failed
;
5115 for (i
= 0; i
< len
; i
++) {
5116 comprehension_ty value
;
5117 res
= obj2ast_comprehension(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5118 if (res
!= 0) goto failed
;
5119 asdl_seq_SET(generators
, i
, value
);
5124 PyErr_SetString(PyExc_TypeError
, "required field \"generators\" missing from ListComp");
5127 *out
= ListComp(elt
, generators
, lineno
, col_offset
, arena
);
5128 if (*out
== NULL
) goto failed
;
5131 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)SetComp_type
);
5132 if (isinstance
== -1) {
5137 asdl_seq
* generators
;
5139 if (PyObject_HasAttrString(obj
, "elt")) {
5141 tmp
= PyObject_GetAttrString(obj
, "elt");
5142 if (tmp
== NULL
) goto failed
;
5143 res
= obj2ast_expr(tmp
, &elt
, arena
);
5144 if (res
!= 0) goto failed
;
5148 PyErr_SetString(PyExc_TypeError
, "required field \"elt\" missing from SetComp");
5151 if (PyObject_HasAttrString(obj
, "generators")) {
5155 tmp
= PyObject_GetAttrString(obj
, "generators");
5156 if (tmp
== NULL
) goto failed
;
5157 if (!PyList_Check(tmp
)) {
5158 PyErr_Format(PyExc_TypeError
, "SetComp field \"generators\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5161 len
= PyList_GET_SIZE(tmp
);
5162 generators
= asdl_seq_new(len
, arena
);
5163 if (generators
== NULL
) goto failed
;
5164 for (i
= 0; i
< len
; i
++) {
5165 comprehension_ty value
;
5166 res
= obj2ast_comprehension(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5167 if (res
!= 0) goto failed
;
5168 asdl_seq_SET(generators
, i
, value
);
5173 PyErr_SetString(PyExc_TypeError
, "required field \"generators\" missing from SetComp");
5176 *out
= SetComp(elt
, generators
, lineno
, col_offset
, arena
);
5177 if (*out
== NULL
) goto failed
;
5180 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)DictComp_type
);
5181 if (isinstance
== -1) {
5187 asdl_seq
* generators
;
5189 if (PyObject_HasAttrString(obj
, "key")) {
5191 tmp
= PyObject_GetAttrString(obj
, "key");
5192 if (tmp
== NULL
) goto failed
;
5193 res
= obj2ast_expr(tmp
, &key
, arena
);
5194 if (res
!= 0) goto failed
;
5198 PyErr_SetString(PyExc_TypeError
, "required field \"key\" missing from DictComp");
5201 if (PyObject_HasAttrString(obj
, "value")) {
5203 tmp
= PyObject_GetAttrString(obj
, "value");
5204 if (tmp
== NULL
) goto failed
;
5205 res
= obj2ast_expr(tmp
, &value
, arena
);
5206 if (res
!= 0) goto failed
;
5210 PyErr_SetString(PyExc_TypeError
, "required field \"value\" missing from DictComp");
5213 if (PyObject_HasAttrString(obj
, "generators")) {
5217 tmp
= PyObject_GetAttrString(obj
, "generators");
5218 if (tmp
== NULL
) goto failed
;
5219 if (!PyList_Check(tmp
)) {
5220 PyErr_Format(PyExc_TypeError
, "DictComp field \"generators\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5223 len
= PyList_GET_SIZE(tmp
);
5224 generators
= asdl_seq_new(len
, arena
);
5225 if (generators
== NULL
) goto failed
;
5226 for (i
= 0; i
< len
; i
++) {
5227 comprehension_ty value
;
5228 res
= obj2ast_comprehension(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5229 if (res
!= 0) goto failed
;
5230 asdl_seq_SET(generators
, i
, value
);
5235 PyErr_SetString(PyExc_TypeError
, "required field \"generators\" missing from DictComp");
5238 *out
= DictComp(key
, value
, generators
, lineno
, col_offset
,
5240 if (*out
== NULL
) goto failed
;
5243 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)GeneratorExp_type
);
5244 if (isinstance
== -1) {
5249 asdl_seq
* generators
;
5251 if (PyObject_HasAttrString(obj
, "elt")) {
5253 tmp
= PyObject_GetAttrString(obj
, "elt");
5254 if (tmp
== NULL
) goto failed
;
5255 res
= obj2ast_expr(tmp
, &elt
, arena
);
5256 if (res
!= 0) goto failed
;
5260 PyErr_SetString(PyExc_TypeError
, "required field \"elt\" missing from GeneratorExp");
5263 if (PyObject_HasAttrString(obj
, "generators")) {
5267 tmp
= PyObject_GetAttrString(obj
, "generators");
5268 if (tmp
== NULL
) goto failed
;
5269 if (!PyList_Check(tmp
)) {
5270 PyErr_Format(PyExc_TypeError
, "GeneratorExp field \"generators\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5273 len
= PyList_GET_SIZE(tmp
);
5274 generators
= asdl_seq_new(len
, arena
);
5275 if (generators
== NULL
) goto failed
;
5276 for (i
= 0; i
< len
; i
++) {
5277 comprehension_ty value
;
5278 res
= obj2ast_comprehension(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5279 if (res
!= 0) goto failed
;
5280 asdl_seq_SET(generators
, i
, value
);
5285 PyErr_SetString(PyExc_TypeError
, "required field \"generators\" missing from GeneratorExp");
5288 *out
= GeneratorExp(elt
, generators
, lineno
, col_offset
, arena
);
5289 if (*out
== NULL
) goto failed
;
5292 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Yield_type
);
5293 if (isinstance
== -1) {
5299 if (PyObject_HasAttrString(obj
, "value")) {
5301 tmp
= PyObject_GetAttrString(obj
, "value");
5302 if (tmp
== NULL
) goto failed
;
5303 res
= obj2ast_expr(tmp
, &value
, arena
);
5304 if (res
!= 0) goto failed
;
5310 *out
= Yield(value
, lineno
, col_offset
, arena
);
5311 if (*out
== NULL
) goto failed
;
5314 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Compare_type
);
5315 if (isinstance
== -1) {
5321 asdl_seq
* comparators
;
5323 if (PyObject_HasAttrString(obj
, "left")) {
5325 tmp
= PyObject_GetAttrString(obj
, "left");
5326 if (tmp
== NULL
) goto failed
;
5327 res
= obj2ast_expr(tmp
, &left
, arena
);
5328 if (res
!= 0) goto failed
;
5332 PyErr_SetString(PyExc_TypeError
, "required field \"left\" missing from Compare");
5335 if (PyObject_HasAttrString(obj
, "ops")) {
5339 tmp
= PyObject_GetAttrString(obj
, "ops");
5340 if (tmp
== NULL
) goto failed
;
5341 if (!PyList_Check(tmp
)) {
5342 PyErr_Format(PyExc_TypeError
, "Compare field \"ops\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5345 len
= PyList_GET_SIZE(tmp
);
5346 ops
= asdl_int_seq_new(len
, arena
);
5347 if (ops
== NULL
) goto failed
;
5348 for (i
= 0; i
< len
; i
++) {
5350 res
= obj2ast_cmpop(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5351 if (res
!= 0) goto failed
;
5352 asdl_seq_SET(ops
, i
, value
);
5357 PyErr_SetString(PyExc_TypeError
, "required field \"ops\" missing from Compare");
5360 if (PyObject_HasAttrString(obj
, "comparators")) {
5364 tmp
= PyObject_GetAttrString(obj
, "comparators");
5365 if (tmp
== NULL
) goto failed
;
5366 if (!PyList_Check(tmp
)) {
5367 PyErr_Format(PyExc_TypeError
, "Compare field \"comparators\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5370 len
= PyList_GET_SIZE(tmp
);
5371 comparators
= asdl_seq_new(len
, arena
);
5372 if (comparators
== NULL
) goto failed
;
5373 for (i
= 0; i
< len
; i
++) {
5375 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5376 if (res
!= 0) goto failed
;
5377 asdl_seq_SET(comparators
, i
, value
);
5382 PyErr_SetString(PyExc_TypeError
, "required field \"comparators\" missing from Compare");
5385 *out
= Compare(left
, ops
, comparators
, lineno
, col_offset
,
5387 if (*out
== NULL
) goto failed
;
5390 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Call_type
);
5391 if (isinstance
== -1) {
5401 if (PyObject_HasAttrString(obj
, "func")) {
5403 tmp
= PyObject_GetAttrString(obj
, "func");
5404 if (tmp
== NULL
) goto failed
;
5405 res
= obj2ast_expr(tmp
, &func
, arena
);
5406 if (res
!= 0) goto failed
;
5410 PyErr_SetString(PyExc_TypeError
, "required field \"func\" missing from Call");
5413 if (PyObject_HasAttrString(obj
, "args")) {
5417 tmp
= PyObject_GetAttrString(obj
, "args");
5418 if (tmp
== NULL
) goto failed
;
5419 if (!PyList_Check(tmp
)) {
5420 PyErr_Format(PyExc_TypeError
, "Call field \"args\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5423 len
= PyList_GET_SIZE(tmp
);
5424 args
= asdl_seq_new(len
, arena
);
5425 if (args
== NULL
) goto failed
;
5426 for (i
= 0; i
< len
; i
++) {
5428 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5429 if (res
!= 0) goto failed
;
5430 asdl_seq_SET(args
, i
, value
);
5435 PyErr_SetString(PyExc_TypeError
, "required field \"args\" missing from Call");
5438 if (PyObject_HasAttrString(obj
, "keywords")) {
5442 tmp
= PyObject_GetAttrString(obj
, "keywords");
5443 if (tmp
== NULL
) goto failed
;
5444 if (!PyList_Check(tmp
)) {
5445 PyErr_Format(PyExc_TypeError
, "Call field \"keywords\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5448 len
= PyList_GET_SIZE(tmp
);
5449 keywords
= asdl_seq_new(len
, arena
);
5450 if (keywords
== NULL
) goto failed
;
5451 for (i
= 0; i
< len
; i
++) {
5453 res
= obj2ast_keyword(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5454 if (res
!= 0) goto failed
;
5455 asdl_seq_SET(keywords
, i
, value
);
5460 PyErr_SetString(PyExc_TypeError
, "required field \"keywords\" missing from Call");
5463 if (PyObject_HasAttrString(obj
, "starargs")) {
5465 tmp
= PyObject_GetAttrString(obj
, "starargs");
5466 if (tmp
== NULL
) goto failed
;
5467 res
= obj2ast_expr(tmp
, &starargs
, arena
);
5468 if (res
!= 0) goto failed
;
5474 if (PyObject_HasAttrString(obj
, "kwargs")) {
5476 tmp
= PyObject_GetAttrString(obj
, "kwargs");
5477 if (tmp
== NULL
) goto failed
;
5478 res
= obj2ast_expr(tmp
, &kwargs
, arena
);
5479 if (res
!= 0) goto failed
;
5485 *out
= Call(func
, args
, keywords
, starargs
, kwargs
, lineno
,
5487 if (*out
== NULL
) goto failed
;
5490 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Num_type
);
5491 if (isinstance
== -1) {
5497 if (PyObject_HasAttrString(obj
, "n")) {
5499 tmp
= PyObject_GetAttrString(obj
, "n");
5500 if (tmp
== NULL
) goto failed
;
5501 res
= obj2ast_object(tmp
, &n
, arena
);
5502 if (res
!= 0) goto failed
;
5506 PyErr_SetString(PyExc_TypeError
, "required field \"n\" missing from Num");
5509 *out
= Num(n
, lineno
, col_offset
, arena
);
5510 if (*out
== NULL
) goto failed
;
5513 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Str_type
);
5514 if (isinstance
== -1) {
5520 if (PyObject_HasAttrString(obj
, "s")) {
5522 tmp
= PyObject_GetAttrString(obj
, "s");
5523 if (tmp
== NULL
) goto failed
;
5524 res
= obj2ast_string(tmp
, &s
, arena
);
5525 if (res
!= 0) goto failed
;
5529 PyErr_SetString(PyExc_TypeError
, "required field \"s\" missing from Str");
5532 *out
= Str(s
, lineno
, col_offset
, arena
);
5533 if (*out
== NULL
) goto failed
;
5536 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Bytes_type
);
5537 if (isinstance
== -1) {
5543 if (PyObject_HasAttrString(obj
, "s")) {
5545 tmp
= PyObject_GetAttrString(obj
, "s");
5546 if (tmp
== NULL
) goto failed
;
5547 res
= obj2ast_string(tmp
, &s
, arena
);
5548 if (res
!= 0) goto failed
;
5552 PyErr_SetString(PyExc_TypeError
, "required field \"s\" missing from Bytes");
5555 *out
= Bytes(s
, lineno
, col_offset
, arena
);
5556 if (*out
== NULL
) goto failed
;
5559 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Ellipsis_type
);
5560 if (isinstance
== -1) {
5565 *out
= Ellipsis(lineno
, col_offset
, arena
);
5566 if (*out
== NULL
) goto failed
;
5569 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Attribute_type
);
5570 if (isinstance
== -1) {
5576 expr_context_ty ctx
;
5578 if (PyObject_HasAttrString(obj
, "value")) {
5580 tmp
= PyObject_GetAttrString(obj
, "value");
5581 if (tmp
== NULL
) goto failed
;
5582 res
= obj2ast_expr(tmp
, &value
, arena
);
5583 if (res
!= 0) goto failed
;
5587 PyErr_SetString(PyExc_TypeError
, "required field \"value\" missing from Attribute");
5590 if (PyObject_HasAttrString(obj
, "attr")) {
5592 tmp
= PyObject_GetAttrString(obj
, "attr");
5593 if (tmp
== NULL
) goto failed
;
5594 res
= obj2ast_identifier(tmp
, &attr
, arena
);
5595 if (res
!= 0) goto failed
;
5599 PyErr_SetString(PyExc_TypeError
, "required field \"attr\" missing from Attribute");
5602 if (PyObject_HasAttrString(obj
, "ctx")) {
5604 tmp
= PyObject_GetAttrString(obj
, "ctx");
5605 if (tmp
== NULL
) goto failed
;
5606 res
= obj2ast_expr_context(tmp
, &ctx
, arena
);
5607 if (res
!= 0) goto failed
;
5611 PyErr_SetString(PyExc_TypeError
, "required field \"ctx\" missing from Attribute");
5614 *out
= Attribute(value
, attr
, ctx
, lineno
, col_offset
, arena
);
5615 if (*out
== NULL
) goto failed
;
5618 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Subscript_type
);
5619 if (isinstance
== -1) {
5625 expr_context_ty ctx
;
5627 if (PyObject_HasAttrString(obj
, "value")) {
5629 tmp
= PyObject_GetAttrString(obj
, "value");
5630 if (tmp
== NULL
) goto failed
;
5631 res
= obj2ast_expr(tmp
, &value
, arena
);
5632 if (res
!= 0) goto failed
;
5636 PyErr_SetString(PyExc_TypeError
, "required field \"value\" missing from Subscript");
5639 if (PyObject_HasAttrString(obj
, "slice")) {
5641 tmp
= PyObject_GetAttrString(obj
, "slice");
5642 if (tmp
== NULL
) goto failed
;
5643 res
= obj2ast_slice(tmp
, &slice
, arena
);
5644 if (res
!= 0) goto failed
;
5648 PyErr_SetString(PyExc_TypeError
, "required field \"slice\" missing from Subscript");
5651 if (PyObject_HasAttrString(obj
, "ctx")) {
5653 tmp
= PyObject_GetAttrString(obj
, "ctx");
5654 if (tmp
== NULL
) goto failed
;
5655 res
= obj2ast_expr_context(tmp
, &ctx
, arena
);
5656 if (res
!= 0) goto failed
;
5660 PyErr_SetString(PyExc_TypeError
, "required field \"ctx\" missing from Subscript");
5663 *out
= Subscript(value
, slice
, ctx
, lineno
, col_offset
, arena
);
5664 if (*out
== NULL
) goto failed
;
5667 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Starred_type
);
5668 if (isinstance
== -1) {
5673 expr_context_ty ctx
;
5675 if (PyObject_HasAttrString(obj
, "value")) {
5677 tmp
= PyObject_GetAttrString(obj
, "value");
5678 if (tmp
== NULL
) goto failed
;
5679 res
= obj2ast_expr(tmp
, &value
, arena
);
5680 if (res
!= 0) goto failed
;
5684 PyErr_SetString(PyExc_TypeError
, "required field \"value\" missing from Starred");
5687 if (PyObject_HasAttrString(obj
, "ctx")) {
5689 tmp
= PyObject_GetAttrString(obj
, "ctx");
5690 if (tmp
== NULL
) goto failed
;
5691 res
= obj2ast_expr_context(tmp
, &ctx
, arena
);
5692 if (res
!= 0) goto failed
;
5696 PyErr_SetString(PyExc_TypeError
, "required field \"ctx\" missing from Starred");
5699 *out
= Starred(value
, ctx
, lineno
, col_offset
, arena
);
5700 if (*out
== NULL
) goto failed
;
5703 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Name_type
);
5704 if (isinstance
== -1) {
5709 expr_context_ty ctx
;
5711 if (PyObject_HasAttrString(obj
, "id")) {
5713 tmp
= PyObject_GetAttrString(obj
, "id");
5714 if (tmp
== NULL
) goto failed
;
5715 res
= obj2ast_identifier(tmp
, &id
, arena
);
5716 if (res
!= 0) goto failed
;
5720 PyErr_SetString(PyExc_TypeError
, "required field \"id\" missing from Name");
5723 if (PyObject_HasAttrString(obj
, "ctx")) {
5725 tmp
= PyObject_GetAttrString(obj
, "ctx");
5726 if (tmp
== NULL
) goto failed
;
5727 res
= obj2ast_expr_context(tmp
, &ctx
, arena
);
5728 if (res
!= 0) goto failed
;
5732 PyErr_SetString(PyExc_TypeError
, "required field \"ctx\" missing from Name");
5735 *out
= Name(id
, ctx
, lineno
, col_offset
, arena
);
5736 if (*out
== NULL
) goto failed
;
5739 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)List_type
);
5740 if (isinstance
== -1) {
5745 expr_context_ty ctx
;
5747 if (PyObject_HasAttrString(obj
, "elts")) {
5751 tmp
= PyObject_GetAttrString(obj
, "elts");
5752 if (tmp
== NULL
) goto failed
;
5753 if (!PyList_Check(tmp
)) {
5754 PyErr_Format(PyExc_TypeError
, "List field \"elts\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5757 len
= PyList_GET_SIZE(tmp
);
5758 elts
= asdl_seq_new(len
, arena
);
5759 if (elts
== NULL
) goto failed
;
5760 for (i
= 0; i
< len
; i
++) {
5762 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5763 if (res
!= 0) goto failed
;
5764 asdl_seq_SET(elts
, i
, value
);
5769 PyErr_SetString(PyExc_TypeError
, "required field \"elts\" missing from List");
5772 if (PyObject_HasAttrString(obj
, "ctx")) {
5774 tmp
= PyObject_GetAttrString(obj
, "ctx");
5775 if (tmp
== NULL
) goto failed
;
5776 res
= obj2ast_expr_context(tmp
, &ctx
, arena
);
5777 if (res
!= 0) goto failed
;
5781 PyErr_SetString(PyExc_TypeError
, "required field \"ctx\" missing from List");
5784 *out
= List(elts
, ctx
, lineno
, col_offset
, arena
);
5785 if (*out
== NULL
) goto failed
;
5788 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Tuple_type
);
5789 if (isinstance
== -1) {
5794 expr_context_ty ctx
;
5796 if (PyObject_HasAttrString(obj
, "elts")) {
5800 tmp
= PyObject_GetAttrString(obj
, "elts");
5801 if (tmp
== NULL
) goto failed
;
5802 if (!PyList_Check(tmp
)) {
5803 PyErr_Format(PyExc_TypeError
, "Tuple field \"elts\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5806 len
= PyList_GET_SIZE(tmp
);
5807 elts
= asdl_seq_new(len
, arena
);
5808 if (elts
== NULL
) goto failed
;
5809 for (i
= 0; i
< len
; i
++) {
5811 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5812 if (res
!= 0) goto failed
;
5813 asdl_seq_SET(elts
, i
, value
);
5818 PyErr_SetString(PyExc_TypeError
, "required field \"elts\" missing from Tuple");
5821 if (PyObject_HasAttrString(obj
, "ctx")) {
5823 tmp
= PyObject_GetAttrString(obj
, "ctx");
5824 if (tmp
== NULL
) goto failed
;
5825 res
= obj2ast_expr_context(tmp
, &ctx
, arena
);
5826 if (res
!= 0) goto failed
;
5830 PyErr_SetString(PyExc_TypeError
, "required field \"ctx\" missing from Tuple");
5833 *out
= Tuple(elts
, ctx
, lineno
, col_offset
, arena
);
5834 if (*out
== NULL
) goto failed
;
5838 tmp
= PyObject_Repr(obj
);
5839 if (tmp
== NULL
) goto failed
;
5840 PyErr_Format(PyExc_TypeError
, "expected some sort of expr, but got %.400s", PyBytes_AS_STRING(tmp
));
5847 obj2ast_expr_context(PyObject
* obj
, expr_context_ty
* out
, PyArena
* arena
)
5849 PyObject
* tmp
= NULL
;
5852 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Load_type
);
5853 if (isinstance
== -1) {
5860 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Store_type
);
5861 if (isinstance
== -1) {
5868 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Del_type
);
5869 if (isinstance
== -1) {
5876 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)AugLoad_type
);
5877 if (isinstance
== -1) {
5884 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)AugStore_type
);
5885 if (isinstance
== -1) {
5892 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Param_type
);
5893 if (isinstance
== -1) {
5901 tmp
= PyObject_Repr(obj
);
5902 if (tmp
== NULL
) goto failed
;
5903 PyErr_Format(PyExc_TypeError
, "expected some sort of expr_context, but got %.400s", PyBytes_AS_STRING(tmp
));
5910 obj2ast_slice(PyObject
* obj
, slice_ty
* out
, PyArena
* arena
)
5912 PyObject
* tmp
= NULL
;
5916 if (obj
== Py_None
) {
5920 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Slice_type
);
5921 if (isinstance
== -1) {
5929 if (PyObject_HasAttrString(obj
, "lower")) {
5931 tmp
= PyObject_GetAttrString(obj
, "lower");
5932 if (tmp
== NULL
) goto failed
;
5933 res
= obj2ast_expr(tmp
, &lower
, arena
);
5934 if (res
!= 0) goto failed
;
5940 if (PyObject_HasAttrString(obj
, "upper")) {
5942 tmp
= PyObject_GetAttrString(obj
, "upper");
5943 if (tmp
== NULL
) goto failed
;
5944 res
= obj2ast_expr(tmp
, &upper
, arena
);
5945 if (res
!= 0) goto failed
;
5951 if (PyObject_HasAttrString(obj
, "step")) {
5953 tmp
= PyObject_GetAttrString(obj
, "step");
5954 if (tmp
== NULL
) goto failed
;
5955 res
= obj2ast_expr(tmp
, &step
, arena
);
5956 if (res
!= 0) goto failed
;
5962 *out
= Slice(lower
, upper
, step
, arena
);
5963 if (*out
== NULL
) goto failed
;
5966 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)ExtSlice_type
);
5967 if (isinstance
== -1) {
5973 if (PyObject_HasAttrString(obj
, "dims")) {
5977 tmp
= PyObject_GetAttrString(obj
, "dims");
5978 if (tmp
== NULL
) goto failed
;
5979 if (!PyList_Check(tmp
)) {
5980 PyErr_Format(PyExc_TypeError
, "ExtSlice field \"dims\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5983 len
= PyList_GET_SIZE(tmp
);
5984 dims
= asdl_seq_new(len
, arena
);
5985 if (dims
== NULL
) goto failed
;
5986 for (i
= 0; i
< len
; i
++) {
5988 res
= obj2ast_slice(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5989 if (res
!= 0) goto failed
;
5990 asdl_seq_SET(dims
, i
, value
);
5995 PyErr_SetString(PyExc_TypeError
, "required field \"dims\" missing from ExtSlice");
5998 *out
= ExtSlice(dims
, arena
);
5999 if (*out
== NULL
) goto failed
;
6002 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Index_type
);
6003 if (isinstance
== -1) {
6009 if (PyObject_HasAttrString(obj
, "value")) {
6011 tmp
= PyObject_GetAttrString(obj
, "value");
6012 if (tmp
== NULL
) goto failed
;
6013 res
= obj2ast_expr(tmp
, &value
, arena
);
6014 if (res
!= 0) goto failed
;
6018 PyErr_SetString(PyExc_TypeError
, "required field \"value\" missing from Index");
6021 *out
= Index(value
, arena
);
6022 if (*out
== NULL
) goto failed
;
6026 tmp
= PyObject_Repr(obj
);
6027 if (tmp
== NULL
) goto failed
;
6028 PyErr_Format(PyExc_TypeError
, "expected some sort of slice, but got %.400s", PyBytes_AS_STRING(tmp
));
6035 obj2ast_boolop(PyObject
* obj
, boolop_ty
* out
, PyArena
* arena
)
6037 PyObject
* tmp
= NULL
;
6040 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)And_type
);
6041 if (isinstance
== -1) {
6048 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Or_type
);
6049 if (isinstance
== -1) {
6057 tmp
= PyObject_Repr(obj
);
6058 if (tmp
== NULL
) goto failed
;
6059 PyErr_Format(PyExc_TypeError
, "expected some sort of boolop, but got %.400s", PyBytes_AS_STRING(tmp
));
6066 obj2ast_operator(PyObject
* obj
, operator_ty
* out
, PyArena
* arena
)
6068 PyObject
* tmp
= NULL
;
6071 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Add_type
);
6072 if (isinstance
== -1) {
6079 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Sub_type
);
6080 if (isinstance
== -1) {
6087 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Mult_type
);
6088 if (isinstance
== -1) {
6095 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Div_type
);
6096 if (isinstance
== -1) {
6103 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Mod_type
);
6104 if (isinstance
== -1) {
6111 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Pow_type
);
6112 if (isinstance
== -1) {
6119 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)LShift_type
);
6120 if (isinstance
== -1) {
6127 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)RShift_type
);
6128 if (isinstance
== -1) {
6135 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)BitOr_type
);
6136 if (isinstance
== -1) {
6143 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)BitXor_type
);
6144 if (isinstance
== -1) {
6151 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)BitAnd_type
);
6152 if (isinstance
== -1) {
6159 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)FloorDiv_type
);
6160 if (isinstance
== -1) {
6168 tmp
= PyObject_Repr(obj
);
6169 if (tmp
== NULL
) goto failed
;
6170 PyErr_Format(PyExc_TypeError
, "expected some sort of operator, but got %.400s", PyBytes_AS_STRING(tmp
));
6177 obj2ast_unaryop(PyObject
* obj
, unaryop_ty
* out
, PyArena
* arena
)
6179 PyObject
* tmp
= NULL
;
6182 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Invert_type
);
6183 if (isinstance
== -1) {
6190 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Not_type
);
6191 if (isinstance
== -1) {
6198 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)UAdd_type
);
6199 if (isinstance
== -1) {
6206 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)USub_type
);
6207 if (isinstance
== -1) {
6215 tmp
= PyObject_Repr(obj
);
6216 if (tmp
== NULL
) goto failed
;
6217 PyErr_Format(PyExc_TypeError
, "expected some sort of unaryop, but got %.400s", PyBytes_AS_STRING(tmp
));
6224 obj2ast_cmpop(PyObject
* obj
, cmpop_ty
* out
, PyArena
* arena
)
6226 PyObject
* tmp
= NULL
;
6229 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Eq_type
);
6230 if (isinstance
== -1) {
6237 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)NotEq_type
);
6238 if (isinstance
== -1) {
6245 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Lt_type
);
6246 if (isinstance
== -1) {
6253 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)LtE_type
);
6254 if (isinstance
== -1) {
6261 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Gt_type
);
6262 if (isinstance
== -1) {
6269 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)GtE_type
);
6270 if (isinstance
== -1) {
6277 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Is_type
);
6278 if (isinstance
== -1) {
6285 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)IsNot_type
);
6286 if (isinstance
== -1) {
6293 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)In_type
);
6294 if (isinstance
== -1) {
6301 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)NotIn_type
);
6302 if (isinstance
== -1) {
6310 tmp
= PyObject_Repr(obj
);
6311 if (tmp
== NULL
) goto failed
;
6312 PyErr_Format(PyExc_TypeError
, "expected some sort of cmpop, but got %.400s", PyBytes_AS_STRING(tmp
));
6319 obj2ast_comprehension(PyObject
* obj
, comprehension_ty
* out
, PyArena
* arena
)
6321 PyObject
* tmp
= NULL
;
6326 if (PyObject_HasAttrString(obj
, "target")) {
6328 tmp
= PyObject_GetAttrString(obj
, "target");
6329 if (tmp
== NULL
) goto failed
;
6330 res
= obj2ast_expr(tmp
, &target
, arena
);
6331 if (res
!= 0) goto failed
;
6335 PyErr_SetString(PyExc_TypeError
, "required field \"target\" missing from comprehension");
6338 if (PyObject_HasAttrString(obj
, "iter")) {
6340 tmp
= PyObject_GetAttrString(obj
, "iter");
6341 if (tmp
== NULL
) goto failed
;
6342 res
= obj2ast_expr(tmp
, &iter
, arena
);
6343 if (res
!= 0) goto failed
;
6347 PyErr_SetString(PyExc_TypeError
, "required field \"iter\" missing from comprehension");
6350 if (PyObject_HasAttrString(obj
, "ifs")) {
6354 tmp
= PyObject_GetAttrString(obj
, "ifs");
6355 if (tmp
== NULL
) goto failed
;
6356 if (!PyList_Check(tmp
)) {
6357 PyErr_Format(PyExc_TypeError
, "comprehension field \"ifs\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
6360 len
= PyList_GET_SIZE(tmp
);
6361 ifs
= asdl_seq_new(len
, arena
);
6362 if (ifs
== NULL
) goto failed
;
6363 for (i
= 0; i
< len
; i
++) {
6365 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
6366 if (res
!= 0) goto failed
;
6367 asdl_seq_SET(ifs
, i
, value
);
6372 PyErr_SetString(PyExc_TypeError
, "required field \"ifs\" missing from comprehension");
6375 *out
= comprehension(target
, iter
, ifs
, arena
);
6383 obj2ast_excepthandler(PyObject
* obj
, excepthandler_ty
* out
, PyArena
* arena
)
6385 PyObject
* tmp
= NULL
;
6391 if (obj
== Py_None
) {
6395 if (PyObject_HasAttrString(obj
, "lineno")) {
6397 tmp
= PyObject_GetAttrString(obj
, "lineno");
6398 if (tmp
== NULL
) goto failed
;
6399 res
= obj2ast_int(tmp
, &lineno
, arena
);
6400 if (res
!= 0) goto failed
;
6404 PyErr_SetString(PyExc_TypeError
, "required field \"lineno\" missing from excepthandler");
6407 if (PyObject_HasAttrString(obj
, "col_offset")) {
6409 tmp
= PyObject_GetAttrString(obj
, "col_offset");
6410 if (tmp
== NULL
) goto failed
;
6411 res
= obj2ast_int(tmp
, &col_offset
, arena
);
6412 if (res
!= 0) goto failed
;
6416 PyErr_SetString(PyExc_TypeError
, "required field \"col_offset\" missing from excepthandler");
6419 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)ExceptHandler_type
);
6420 if (isinstance
== -1) {
6428 if (PyObject_HasAttrString(obj
, "type")) {
6430 tmp
= PyObject_GetAttrString(obj
, "type");
6431 if (tmp
== NULL
) goto failed
;
6432 res
= obj2ast_expr(tmp
, &type
, arena
);
6433 if (res
!= 0) goto failed
;
6439 if (PyObject_HasAttrString(obj
, "name")) {
6441 tmp
= PyObject_GetAttrString(obj
, "name");
6442 if (tmp
== NULL
) goto failed
;
6443 res
= obj2ast_identifier(tmp
, &name
, arena
);
6444 if (res
!= 0) goto failed
;
6450 if (PyObject_HasAttrString(obj
, "body")) {
6454 tmp
= PyObject_GetAttrString(obj
, "body");
6455 if (tmp
== NULL
) goto failed
;
6456 if (!PyList_Check(tmp
)) {
6457 PyErr_Format(PyExc_TypeError
, "ExceptHandler field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
6460 len
= PyList_GET_SIZE(tmp
);
6461 body
= asdl_seq_new(len
, arena
);
6462 if (body
== NULL
) goto failed
;
6463 for (i
= 0; i
< len
; i
++) {
6465 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
6466 if (res
!= 0) goto failed
;
6467 asdl_seq_SET(body
, i
, value
);
6472 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from ExceptHandler");
6475 *out
= ExceptHandler(type
, name
, body
, lineno
, col_offset
,
6477 if (*out
== NULL
) goto failed
;
6481 tmp
= PyObject_Repr(obj
);
6482 if (tmp
== NULL
) goto failed
;
6483 PyErr_Format(PyExc_TypeError
, "expected some sort of excepthandler, but got %.400s", PyBytes_AS_STRING(tmp
));
6490 obj2ast_arguments(PyObject
* obj
, arguments_ty
* out
, PyArena
* arena
)
6492 PyObject
* tmp
= NULL
;
6495 expr_ty varargannotation
;
6496 asdl_seq
* kwonlyargs
;
6498 expr_ty kwargannotation
;
6500 asdl_seq
* kw_defaults
;
6502 if (PyObject_HasAttrString(obj
, "args")) {
6506 tmp
= PyObject_GetAttrString(obj
, "args");
6507 if (tmp
== NULL
) goto failed
;
6508 if (!PyList_Check(tmp
)) {
6509 PyErr_Format(PyExc_TypeError
, "arguments field \"args\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
6512 len
= PyList_GET_SIZE(tmp
);
6513 args
= asdl_seq_new(len
, arena
);
6514 if (args
== NULL
) goto failed
;
6515 for (i
= 0; i
< len
; i
++) {
6517 res
= obj2ast_arg(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
6518 if (res
!= 0) goto failed
;
6519 asdl_seq_SET(args
, i
, value
);
6524 PyErr_SetString(PyExc_TypeError
, "required field \"args\" missing from arguments");
6527 if (PyObject_HasAttrString(obj
, "vararg")) {
6529 tmp
= PyObject_GetAttrString(obj
, "vararg");
6530 if (tmp
== NULL
) goto failed
;
6531 res
= obj2ast_identifier(tmp
, &vararg
, arena
);
6532 if (res
!= 0) goto failed
;
6538 if (PyObject_HasAttrString(obj
, "varargannotation")) {
6540 tmp
= PyObject_GetAttrString(obj
, "varargannotation");
6541 if (tmp
== NULL
) goto failed
;
6542 res
= obj2ast_expr(tmp
, &varargannotation
, arena
);
6543 if (res
!= 0) goto failed
;
6547 varargannotation
= NULL
;
6549 if (PyObject_HasAttrString(obj
, "kwonlyargs")) {
6553 tmp
= PyObject_GetAttrString(obj
, "kwonlyargs");
6554 if (tmp
== NULL
) goto failed
;
6555 if (!PyList_Check(tmp
)) {
6556 PyErr_Format(PyExc_TypeError
, "arguments field \"kwonlyargs\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
6559 len
= PyList_GET_SIZE(tmp
);
6560 kwonlyargs
= asdl_seq_new(len
, arena
);
6561 if (kwonlyargs
== NULL
) goto failed
;
6562 for (i
= 0; i
< len
; i
++) {
6564 res
= obj2ast_arg(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
6565 if (res
!= 0) goto failed
;
6566 asdl_seq_SET(kwonlyargs
, i
, value
);
6571 PyErr_SetString(PyExc_TypeError
, "required field \"kwonlyargs\" missing from arguments");
6574 if (PyObject_HasAttrString(obj
, "kwarg")) {
6576 tmp
= PyObject_GetAttrString(obj
, "kwarg");
6577 if (tmp
== NULL
) goto failed
;
6578 res
= obj2ast_identifier(tmp
, &kwarg
, arena
);
6579 if (res
!= 0) goto failed
;
6585 if (PyObject_HasAttrString(obj
, "kwargannotation")) {
6587 tmp
= PyObject_GetAttrString(obj
, "kwargannotation");
6588 if (tmp
== NULL
) goto failed
;
6589 res
= obj2ast_expr(tmp
, &kwargannotation
, arena
);
6590 if (res
!= 0) goto failed
;
6594 kwargannotation
= NULL
;
6596 if (PyObject_HasAttrString(obj
, "defaults")) {
6600 tmp
= PyObject_GetAttrString(obj
, "defaults");
6601 if (tmp
== NULL
) goto failed
;
6602 if (!PyList_Check(tmp
)) {
6603 PyErr_Format(PyExc_TypeError
, "arguments field \"defaults\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
6606 len
= PyList_GET_SIZE(tmp
);
6607 defaults
= asdl_seq_new(len
, arena
);
6608 if (defaults
== NULL
) goto failed
;
6609 for (i
= 0; i
< len
; i
++) {
6611 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
6612 if (res
!= 0) goto failed
;
6613 asdl_seq_SET(defaults
, i
, value
);
6618 PyErr_SetString(PyExc_TypeError
, "required field \"defaults\" missing from arguments");
6621 if (PyObject_HasAttrString(obj
, "kw_defaults")) {
6625 tmp
= PyObject_GetAttrString(obj
, "kw_defaults");
6626 if (tmp
== NULL
) goto failed
;
6627 if (!PyList_Check(tmp
)) {
6628 PyErr_Format(PyExc_TypeError
, "arguments field \"kw_defaults\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
6631 len
= PyList_GET_SIZE(tmp
);
6632 kw_defaults
= asdl_seq_new(len
, arena
);
6633 if (kw_defaults
== NULL
) goto failed
;
6634 for (i
= 0; i
< len
; i
++) {
6636 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
6637 if (res
!= 0) goto failed
;
6638 asdl_seq_SET(kw_defaults
, i
, value
);
6643 PyErr_SetString(PyExc_TypeError
, "required field \"kw_defaults\" missing from arguments");
6646 *out
= arguments(args
, vararg
, varargannotation
, kwonlyargs
, kwarg
,
6647 kwargannotation
, defaults
, kw_defaults
, arena
);
6655 obj2ast_arg(PyObject
* obj
, arg_ty
* out
, PyArena
* arena
)
6657 PyObject
* tmp
= NULL
;
6661 if (PyObject_HasAttrString(obj
, "arg")) {
6663 tmp
= PyObject_GetAttrString(obj
, "arg");
6664 if (tmp
== NULL
) goto failed
;
6665 res
= obj2ast_identifier(tmp
, &arg
, arena
);
6666 if (res
!= 0) goto failed
;
6670 PyErr_SetString(PyExc_TypeError
, "required field \"arg\" missing from arg");
6673 if (PyObject_HasAttrString(obj
, "annotation")) {
6675 tmp
= PyObject_GetAttrString(obj
, "annotation");
6676 if (tmp
== NULL
) goto failed
;
6677 res
= obj2ast_expr(tmp
, &annotation
, arena
);
6678 if (res
!= 0) goto failed
;
6684 *out
= arg(arg
, annotation
, arena
);
6692 obj2ast_keyword(PyObject
* obj
, keyword_ty
* out
, PyArena
* arena
)
6694 PyObject
* tmp
= NULL
;
6698 if (PyObject_HasAttrString(obj
, "arg")) {
6700 tmp
= PyObject_GetAttrString(obj
, "arg");
6701 if (tmp
== NULL
) goto failed
;
6702 res
= obj2ast_identifier(tmp
, &arg
, arena
);
6703 if (res
!= 0) goto failed
;
6707 PyErr_SetString(PyExc_TypeError
, "required field \"arg\" missing from keyword");
6710 if (PyObject_HasAttrString(obj
, "value")) {
6712 tmp
= PyObject_GetAttrString(obj
, "value");
6713 if (tmp
== NULL
) goto failed
;
6714 res
= obj2ast_expr(tmp
, &value
, arena
);
6715 if (res
!= 0) goto failed
;
6719 PyErr_SetString(PyExc_TypeError
, "required field \"value\" missing from keyword");
6722 *out
= keyword(arg
, value
, arena
);
6730 obj2ast_alias(PyObject
* obj
, alias_ty
* out
, PyArena
* arena
)
6732 PyObject
* tmp
= NULL
;
6736 if (PyObject_HasAttrString(obj
, "name")) {
6738 tmp
= PyObject_GetAttrString(obj
, "name");
6739 if (tmp
== NULL
) goto failed
;
6740 res
= obj2ast_identifier(tmp
, &name
, arena
);
6741 if (res
!= 0) goto failed
;
6745 PyErr_SetString(PyExc_TypeError
, "required field \"name\" missing from alias");
6748 if (PyObject_HasAttrString(obj
, "asname")) {
6750 tmp
= PyObject_GetAttrString(obj
, "asname");
6751 if (tmp
== NULL
) goto failed
;
6752 res
= obj2ast_identifier(tmp
, &asname
, arena
);
6753 if (res
!= 0) goto failed
;
6759 *out
= alias(name
, asname
, arena
);
6767 static struct PyModuleDef _astmodule
= {
6768 PyModuleDef_HEAD_INIT
, "_ast"
6774 if (!init_types()) return NULL
;
6775 m
= PyModule_Create(&_astmodule
);
6776 if (!m
) return NULL
;
6777 d
= PyModule_GetDict(m
);
6778 if (PyDict_SetItemString(d
, "AST", (PyObject
*)&AST_type
) < 0) return
6780 if (PyModule_AddIntConstant(m
, "PyCF_ONLY_AST", PyCF_ONLY_AST
) < 0)
6782 if (PyModule_AddStringConstant(m
, "__version__", "67616") < 0)
6784 if (PyDict_SetItemString(d
, "mod", (PyObject
*)mod_type
) < 0) return
6786 if (PyDict_SetItemString(d
, "Module", (PyObject
*)Module_type
) < 0)
6788 if (PyDict_SetItemString(d
, "Interactive", (PyObject
*)Interactive_type
)
6790 if (PyDict_SetItemString(d
, "Expression", (PyObject
*)Expression_type
) <
6792 if (PyDict_SetItemString(d
, "Suite", (PyObject
*)Suite_type
) < 0) return
6794 if (PyDict_SetItemString(d
, "stmt", (PyObject
*)stmt_type
) < 0) return
6796 if (PyDict_SetItemString(d
, "FunctionDef", (PyObject
*)FunctionDef_type
)
6798 if (PyDict_SetItemString(d
, "ClassDef", (PyObject
*)ClassDef_type
) < 0)
6800 if (PyDict_SetItemString(d
, "Return", (PyObject
*)Return_type
) < 0)
6802 if (PyDict_SetItemString(d
, "Delete", (PyObject
*)Delete_type
) < 0)
6804 if (PyDict_SetItemString(d
, "Assign", (PyObject
*)Assign_type
) < 0)
6806 if (PyDict_SetItemString(d
, "AugAssign", (PyObject
*)AugAssign_type
) <
6808 if (PyDict_SetItemString(d
, "For", (PyObject
*)For_type
) < 0) return
6810 if (PyDict_SetItemString(d
, "While", (PyObject
*)While_type
) < 0) return
6812 if (PyDict_SetItemString(d
, "If", (PyObject
*)If_type
) < 0) return NULL
;
6813 if (PyDict_SetItemString(d
, "With", (PyObject
*)With_type
) < 0) return
6815 if (PyDict_SetItemString(d
, "Raise", (PyObject
*)Raise_type
) < 0) return
6817 if (PyDict_SetItemString(d
, "TryExcept", (PyObject
*)TryExcept_type
) <
6819 if (PyDict_SetItemString(d
, "TryFinally", (PyObject
*)TryFinally_type
) <
6821 if (PyDict_SetItemString(d
, "Assert", (PyObject
*)Assert_type
) < 0)
6823 if (PyDict_SetItemString(d
, "Import", (PyObject
*)Import_type
) < 0)
6825 if (PyDict_SetItemString(d
, "ImportFrom", (PyObject
*)ImportFrom_type
) <
6827 if (PyDict_SetItemString(d
, "Global", (PyObject
*)Global_type
) < 0)
6829 if (PyDict_SetItemString(d
, "Nonlocal", (PyObject
*)Nonlocal_type
) < 0)
6831 if (PyDict_SetItemString(d
, "Expr", (PyObject
*)Expr_type
) < 0) return
6833 if (PyDict_SetItemString(d
, "Pass", (PyObject
*)Pass_type
) < 0) return
6835 if (PyDict_SetItemString(d
, "Break", (PyObject
*)Break_type
) < 0) return
6837 if (PyDict_SetItemString(d
, "Continue", (PyObject
*)Continue_type
) < 0)
6839 if (PyDict_SetItemString(d
, "expr", (PyObject
*)expr_type
) < 0) return
6841 if (PyDict_SetItemString(d
, "BoolOp", (PyObject
*)BoolOp_type
) < 0)
6843 if (PyDict_SetItemString(d
, "BinOp", (PyObject
*)BinOp_type
) < 0) return
6845 if (PyDict_SetItemString(d
, "UnaryOp", (PyObject
*)UnaryOp_type
) < 0)
6847 if (PyDict_SetItemString(d
, "Lambda", (PyObject
*)Lambda_type
) < 0)
6849 if (PyDict_SetItemString(d
, "IfExp", (PyObject
*)IfExp_type
) < 0) return
6851 if (PyDict_SetItemString(d
, "Dict", (PyObject
*)Dict_type
) < 0) return
6853 if (PyDict_SetItemString(d
, "Set", (PyObject
*)Set_type
) < 0) return
6855 if (PyDict_SetItemString(d
, "ListComp", (PyObject
*)ListComp_type
) < 0)
6857 if (PyDict_SetItemString(d
, "SetComp", (PyObject
*)SetComp_type
) < 0)
6859 if (PyDict_SetItemString(d
, "DictComp", (PyObject
*)DictComp_type
) < 0)
6861 if (PyDict_SetItemString(d
, "GeneratorExp",
6862 (PyObject
*)GeneratorExp_type
) < 0) return NULL
;
6863 if (PyDict_SetItemString(d
, "Yield", (PyObject
*)Yield_type
) < 0) return
6865 if (PyDict_SetItemString(d
, "Compare", (PyObject
*)Compare_type
) < 0)
6867 if (PyDict_SetItemString(d
, "Call", (PyObject
*)Call_type
) < 0) return
6869 if (PyDict_SetItemString(d
, "Num", (PyObject
*)Num_type
) < 0) return
6871 if (PyDict_SetItemString(d
, "Str", (PyObject
*)Str_type
) < 0) return
6873 if (PyDict_SetItemString(d
, "Bytes", (PyObject
*)Bytes_type
) < 0) return
6875 if (PyDict_SetItemString(d
, "Ellipsis", (PyObject
*)Ellipsis_type
) < 0)
6877 if (PyDict_SetItemString(d
, "Attribute", (PyObject
*)Attribute_type
) <
6879 if (PyDict_SetItemString(d
, "Subscript", (PyObject
*)Subscript_type
) <
6881 if (PyDict_SetItemString(d
, "Starred", (PyObject
*)Starred_type
) < 0)
6883 if (PyDict_SetItemString(d
, "Name", (PyObject
*)Name_type
) < 0) return
6885 if (PyDict_SetItemString(d
, "List", (PyObject
*)List_type
) < 0) return
6887 if (PyDict_SetItemString(d
, "Tuple", (PyObject
*)Tuple_type
) < 0) return
6889 if (PyDict_SetItemString(d
, "expr_context",
6890 (PyObject
*)expr_context_type
) < 0) return NULL
;
6891 if (PyDict_SetItemString(d
, "Load", (PyObject
*)Load_type
) < 0) return
6893 if (PyDict_SetItemString(d
, "Store", (PyObject
*)Store_type
) < 0) return
6895 if (PyDict_SetItemString(d
, "Del", (PyObject
*)Del_type
) < 0) return
6897 if (PyDict_SetItemString(d
, "AugLoad", (PyObject
*)AugLoad_type
) < 0)
6899 if (PyDict_SetItemString(d
, "AugStore", (PyObject
*)AugStore_type
) < 0)
6901 if (PyDict_SetItemString(d
, "Param", (PyObject
*)Param_type
) < 0) return
6903 if (PyDict_SetItemString(d
, "slice", (PyObject
*)slice_type
) < 0) return
6905 if (PyDict_SetItemString(d
, "Slice", (PyObject
*)Slice_type
) < 0) return
6907 if (PyDict_SetItemString(d
, "ExtSlice", (PyObject
*)ExtSlice_type
) < 0)
6909 if (PyDict_SetItemString(d
, "Index", (PyObject
*)Index_type
) < 0) return
6911 if (PyDict_SetItemString(d
, "boolop", (PyObject
*)boolop_type
) < 0)
6913 if (PyDict_SetItemString(d
, "And", (PyObject
*)And_type
) < 0) return
6915 if (PyDict_SetItemString(d
, "Or", (PyObject
*)Or_type
) < 0) return NULL
;
6916 if (PyDict_SetItemString(d
, "operator", (PyObject
*)operator_type
) < 0)
6918 if (PyDict_SetItemString(d
, "Add", (PyObject
*)Add_type
) < 0) return
6920 if (PyDict_SetItemString(d
, "Sub", (PyObject
*)Sub_type
) < 0) return
6922 if (PyDict_SetItemString(d
, "Mult", (PyObject
*)Mult_type
) < 0) return
6924 if (PyDict_SetItemString(d
, "Div", (PyObject
*)Div_type
) < 0) return
6926 if (PyDict_SetItemString(d
, "Mod", (PyObject
*)Mod_type
) < 0) return
6928 if (PyDict_SetItemString(d
, "Pow", (PyObject
*)Pow_type
) < 0) return
6930 if (PyDict_SetItemString(d
, "LShift", (PyObject
*)LShift_type
) < 0)
6932 if (PyDict_SetItemString(d
, "RShift", (PyObject
*)RShift_type
) < 0)
6934 if (PyDict_SetItemString(d
, "BitOr", (PyObject
*)BitOr_type
) < 0) return
6936 if (PyDict_SetItemString(d
, "BitXor", (PyObject
*)BitXor_type
) < 0)
6938 if (PyDict_SetItemString(d
, "BitAnd", (PyObject
*)BitAnd_type
) < 0)
6940 if (PyDict_SetItemString(d
, "FloorDiv", (PyObject
*)FloorDiv_type
) < 0)
6942 if (PyDict_SetItemString(d
, "unaryop", (PyObject
*)unaryop_type
) < 0)
6944 if (PyDict_SetItemString(d
, "Invert", (PyObject
*)Invert_type
) < 0)
6946 if (PyDict_SetItemString(d
, "Not", (PyObject
*)Not_type
) < 0) return
6948 if (PyDict_SetItemString(d
, "UAdd", (PyObject
*)UAdd_type
) < 0) return
6950 if (PyDict_SetItemString(d
, "USub", (PyObject
*)USub_type
) < 0) return
6952 if (PyDict_SetItemString(d
, "cmpop", (PyObject
*)cmpop_type
) < 0) return
6954 if (PyDict_SetItemString(d
, "Eq", (PyObject
*)Eq_type
) < 0) return NULL
;
6955 if (PyDict_SetItemString(d
, "NotEq", (PyObject
*)NotEq_type
) < 0) return
6957 if (PyDict_SetItemString(d
, "Lt", (PyObject
*)Lt_type
) < 0) return NULL
;
6958 if (PyDict_SetItemString(d
, "LtE", (PyObject
*)LtE_type
) < 0) return
6960 if (PyDict_SetItemString(d
, "Gt", (PyObject
*)Gt_type
) < 0) return NULL
;
6961 if (PyDict_SetItemString(d
, "GtE", (PyObject
*)GtE_type
) < 0) return
6963 if (PyDict_SetItemString(d
, "Is", (PyObject
*)Is_type
) < 0) return NULL
;
6964 if (PyDict_SetItemString(d
, "IsNot", (PyObject
*)IsNot_type
) < 0) return
6966 if (PyDict_SetItemString(d
, "In", (PyObject
*)In_type
) < 0) return NULL
;
6967 if (PyDict_SetItemString(d
, "NotIn", (PyObject
*)NotIn_type
) < 0) return
6969 if (PyDict_SetItemString(d
, "comprehension",
6970 (PyObject
*)comprehension_type
) < 0) return NULL
;
6971 if (PyDict_SetItemString(d
, "excepthandler",
6972 (PyObject
*)excepthandler_type
) < 0) return NULL
;
6973 if (PyDict_SetItemString(d
, "ExceptHandler",
6974 (PyObject
*)ExceptHandler_type
) < 0) return NULL
;
6975 if (PyDict_SetItemString(d
, "arguments", (PyObject
*)arguments_type
) <
6977 if (PyDict_SetItemString(d
, "arg", (PyObject
*)arg_type
) < 0) return
6979 if (PyDict_SetItemString(d
, "keyword", (PyObject
*)keyword_type
) < 0)
6981 if (PyDict_SetItemString(d
, "alias", (PyObject
*)alias_type
) < 0) return
6987 PyObject
* PyAST_mod2obj(mod_ty t
)
6990 return ast2obj_mod(t
);
6993 /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */
6994 mod_ty
PyAST_obj2mod(PyObject
* ast
, PyArena
* arena
, int mode
)
6997 PyObject
*req_type
[] = {(PyObject
*)Module_type
, (PyObject
*)Expression_type
,
6998 (PyObject
*)Interactive_type
};
6999 char *req_name
[] = {"Module", "Expression", "Interactive"};
7001 assert(0 <= mode
&& mode
<= 2);
7005 isinstance
= PyObject_IsInstance(ast
, req_type
[mode
]);
7006 if (isinstance
== -1)
7009 PyErr_Format(PyExc_TypeError
, "expected %s node, got %.400s",
7010 req_name
[mode
], Py_TYPE(ast
)->tp_name
);
7013 if (obj2ast_mod(ast
, &res
, arena
) != 0)
7019 int PyAST_Check(PyObject
* obj
)
7022 return PyObject_IsInstance(obj
, (PyObject
*)&AST_type
);