1 /* File automatically generated by Parser/asdl_c.py. */
7 This module must be committed separately after each AST grammar change;
8 The __version__ number is set to the revision number of the commit
9 containing the grammar change.
13 #include "Python-ast.h"
15 static PyTypeObject AST_type
;
16 static PyTypeObject
*mod_type
;
17 static PyObject
* ast2obj_mod(void*);
18 static PyTypeObject
*Module_type
;
19 static char *Module_fields
[]={
22 static PyTypeObject
*Interactive_type
;
23 static char *Interactive_fields
[]={
26 static PyTypeObject
*Expression_type
;
27 static char *Expression_fields
[]={
30 static PyTypeObject
*Suite_type
;
31 static char *Suite_fields
[]={
34 static PyTypeObject
*stmt_type
;
35 static char *stmt_attributes
[] = {
39 static PyObject
* ast2obj_stmt(void*);
40 static PyTypeObject
*FunctionDef_type
;
41 static char *FunctionDef_fields
[]={
47 static PyTypeObject
*ClassDef_type
;
48 static char *ClassDef_fields
[]={
54 static PyTypeObject
*Return_type
;
55 static char *Return_fields
[]={
58 static PyTypeObject
*Delete_type
;
59 static char *Delete_fields
[]={
62 static PyTypeObject
*Assign_type
;
63 static char *Assign_fields
[]={
67 static PyTypeObject
*AugAssign_type
;
68 static char *AugAssign_fields
[]={
73 static PyTypeObject
*Print_type
;
74 static char *Print_fields
[]={
79 static PyTypeObject
*For_type
;
80 static char *For_fields
[]={
86 static PyTypeObject
*While_type
;
87 static char *While_fields
[]={
92 static PyTypeObject
*If_type
;
93 static char *If_fields
[]={
98 static PyTypeObject
*With_type
;
99 static char *With_fields
[]={
104 static PyTypeObject
*Raise_type
;
105 static char *Raise_fields
[]={
110 static PyTypeObject
*TryExcept_type
;
111 static char *TryExcept_fields
[]={
116 static PyTypeObject
*TryFinally_type
;
117 static char *TryFinally_fields
[]={
121 static PyTypeObject
*Assert_type
;
122 static char *Assert_fields
[]={
126 static PyTypeObject
*Import_type
;
127 static char *Import_fields
[]={
130 static PyTypeObject
*ImportFrom_type
;
131 static char *ImportFrom_fields
[]={
136 static PyTypeObject
*Exec_type
;
137 static char *Exec_fields
[]={
142 static PyTypeObject
*Global_type
;
143 static char *Global_fields
[]={
146 static PyTypeObject
*Expr_type
;
147 static char *Expr_fields
[]={
150 static PyTypeObject
*Pass_type
;
151 static PyTypeObject
*Break_type
;
152 static PyTypeObject
*Continue_type
;
153 static PyTypeObject
*expr_type
;
154 static char *expr_attributes
[] = {
158 static PyObject
* ast2obj_expr(void*);
159 static PyTypeObject
*BoolOp_type
;
160 static char *BoolOp_fields
[]={
164 static PyTypeObject
*BinOp_type
;
165 static char *BinOp_fields
[]={
170 static PyTypeObject
*UnaryOp_type
;
171 static char *UnaryOp_fields
[]={
175 static PyTypeObject
*Lambda_type
;
176 static char *Lambda_fields
[]={
180 static PyTypeObject
*IfExp_type
;
181 static char *IfExp_fields
[]={
186 static PyTypeObject
*Dict_type
;
187 static char *Dict_fields
[]={
191 static PyTypeObject
*Set_type
;
192 static char *Set_fields
[]={
195 static PyTypeObject
*ListComp_type
;
196 static char *ListComp_fields
[]={
200 static PyTypeObject
*SetComp_type
;
201 static char *SetComp_fields
[]={
205 static PyTypeObject
*DictComp_type
;
206 static char *DictComp_fields
[]={
211 static PyTypeObject
*GeneratorExp_type
;
212 static char *GeneratorExp_fields
[]={
216 static PyTypeObject
*Yield_type
;
217 static char *Yield_fields
[]={
220 static PyTypeObject
*Compare_type
;
221 static char *Compare_fields
[]={
226 static PyTypeObject
*Call_type
;
227 static char *Call_fields
[]={
234 static PyTypeObject
*Repr_type
;
235 static char *Repr_fields
[]={
238 static PyTypeObject
*Num_type
;
239 static char *Num_fields
[]={
242 static PyTypeObject
*Str_type
;
243 static char *Str_fields
[]={
246 static PyTypeObject
*Attribute_type
;
247 static char *Attribute_fields
[]={
252 static PyTypeObject
*Subscript_type
;
253 static char *Subscript_fields
[]={
258 static PyTypeObject
*Name_type
;
259 static char *Name_fields
[]={
263 static PyTypeObject
*List_type
;
264 static char *List_fields
[]={
268 static PyTypeObject
*Tuple_type
;
269 static char *Tuple_fields
[]={
273 static PyTypeObject
*expr_context_type
;
274 static PyObject
*Load_singleton
, *Store_singleton
, *Del_singleton
,
275 *AugLoad_singleton
, *AugStore_singleton
, *Param_singleton
;
276 static PyObject
* ast2obj_expr_context(expr_context_ty
);
277 static PyTypeObject
*Load_type
;
278 static PyTypeObject
*Store_type
;
279 static PyTypeObject
*Del_type
;
280 static PyTypeObject
*AugLoad_type
;
281 static PyTypeObject
*AugStore_type
;
282 static PyTypeObject
*Param_type
;
283 static PyTypeObject
*slice_type
;
284 static PyObject
* ast2obj_slice(void*);
285 static PyTypeObject
*Ellipsis_type
;
286 static PyTypeObject
*Slice_type
;
287 static char *Slice_fields
[]={
292 static PyTypeObject
*ExtSlice_type
;
293 static char *ExtSlice_fields
[]={
296 static PyTypeObject
*Index_type
;
297 static char *Index_fields
[]={
300 static PyTypeObject
*boolop_type
;
301 static PyObject
*And_singleton
, *Or_singleton
;
302 static PyObject
* ast2obj_boolop(boolop_ty
);
303 static PyTypeObject
*And_type
;
304 static PyTypeObject
*Or_type
;
305 static PyTypeObject
*operator_type
;
306 static PyObject
*Add_singleton
, *Sub_singleton
, *Mult_singleton
,
307 *Div_singleton
, *Mod_singleton
, *Pow_singleton
, *LShift_singleton
,
308 *RShift_singleton
, *BitOr_singleton
, *BitXor_singleton
, *BitAnd_singleton
,
310 static PyObject
* ast2obj_operator(operator_ty
);
311 static PyTypeObject
*Add_type
;
312 static PyTypeObject
*Sub_type
;
313 static PyTypeObject
*Mult_type
;
314 static PyTypeObject
*Div_type
;
315 static PyTypeObject
*Mod_type
;
316 static PyTypeObject
*Pow_type
;
317 static PyTypeObject
*LShift_type
;
318 static PyTypeObject
*RShift_type
;
319 static PyTypeObject
*BitOr_type
;
320 static PyTypeObject
*BitXor_type
;
321 static PyTypeObject
*BitAnd_type
;
322 static PyTypeObject
*FloorDiv_type
;
323 static PyTypeObject
*unaryop_type
;
324 static PyObject
*Invert_singleton
, *Not_singleton
, *UAdd_singleton
,
326 static PyObject
* ast2obj_unaryop(unaryop_ty
);
327 static PyTypeObject
*Invert_type
;
328 static PyTypeObject
*Not_type
;
329 static PyTypeObject
*UAdd_type
;
330 static PyTypeObject
*USub_type
;
331 static PyTypeObject
*cmpop_type
;
332 static PyObject
*Eq_singleton
, *NotEq_singleton
, *Lt_singleton
, *LtE_singleton
,
333 *Gt_singleton
, *GtE_singleton
, *Is_singleton
, *IsNot_singleton
, *In_singleton
,
335 static PyObject
* ast2obj_cmpop(cmpop_ty
);
336 static PyTypeObject
*Eq_type
;
337 static PyTypeObject
*NotEq_type
;
338 static PyTypeObject
*Lt_type
;
339 static PyTypeObject
*LtE_type
;
340 static PyTypeObject
*Gt_type
;
341 static PyTypeObject
*GtE_type
;
342 static PyTypeObject
*Is_type
;
343 static PyTypeObject
*IsNot_type
;
344 static PyTypeObject
*In_type
;
345 static PyTypeObject
*NotIn_type
;
346 static PyTypeObject
*comprehension_type
;
347 static PyObject
* ast2obj_comprehension(void*);
348 static char *comprehension_fields
[]={
353 static PyTypeObject
*excepthandler_type
;
354 static char *excepthandler_attributes
[] = {
358 static PyObject
* ast2obj_excepthandler(void*);
359 static PyTypeObject
*ExceptHandler_type
;
360 static char *ExceptHandler_fields
[]={
365 static PyTypeObject
*arguments_type
;
366 static PyObject
* ast2obj_arguments(void*);
367 static char *arguments_fields
[]={
373 static PyTypeObject
*keyword_type
;
374 static PyObject
* ast2obj_keyword(void*);
375 static char *keyword_fields
[]={
379 static PyTypeObject
*alias_type
;
380 static PyObject
* ast2obj_alias(void*);
381 static char *alias_fields
[]={
388 ast_type_init(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
390 Py_ssize_t i
, numfields
= 0;
392 PyObject
*key
, *value
, *fields
;
393 fields
= PyObject_GetAttrString((PyObject
*)Py_TYPE(self
), "_fields");
397 numfields
= PySequence_Size(fields
);
401 res
= 0; /* if no error occurs, this stays 0 to the end */
402 if (PyTuple_GET_SIZE(args
) > 0) {
403 if (numfields
!= PyTuple_GET_SIZE(args
)) {
404 PyErr_Format(PyExc_TypeError
, "%.400s constructor takes %s"
405 "%zd positional argument%s",
406 Py_TYPE(self
)->tp_name
,
407 numfields
== 0 ? "" : "either 0 or ",
408 numfields
, numfields
== 1 ? "" : "s");
412 for (i
= 0; i
< PyTuple_GET_SIZE(args
); i
++) {
413 /* cannot be reached when fields is NULL */
414 PyObject
*name
= PySequence_GetItem(fields
, i
);
419 res
= PyObject_SetAttr(self
, name
, PyTuple_GET_ITEM(args
, i
));
426 i
= 0; /* needed by PyDict_Next */
427 while (PyDict_Next(kw
, &i
, &key
, &value
)) {
428 res
= PyObject_SetAttr(self
, key
, value
);
438 /* Pickling support */
440 ast_type_reduce(PyObject
*self
, PyObject
*unused
)
443 PyObject
*dict
= PyObject_GetAttrString(self
, "__dict__");
445 if (PyErr_ExceptionMatches(PyExc_AttributeError
))
451 res
= Py_BuildValue("O()O", Py_TYPE(self
), dict
);
455 return Py_BuildValue("O()", Py_TYPE(self
));
458 static PyMethodDef ast_type_methods
[] = {
459 {"__reduce__", ast_type_reduce
, METH_NOARGS
, NULL
},
463 static PyTypeObject AST_type
= {
464 PyVarObject_HEAD_INIT(&PyType_Type
, 0)
474 0, /* tp_as_number */
475 0, /* tp_as_sequence */
476 0, /* tp_as_mapping */
480 PyObject_GenericGetAttr
, /* tp_getattro */
481 PyObject_GenericSetAttr
, /* tp_setattro */
482 0, /* tp_as_buffer */
483 Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_BASETYPE
, /* tp_flags */
487 0, /* tp_richcompare */
488 0, /* tp_weaklistoffset */
491 ast_type_methods
, /* tp_methods */
496 0, /* tp_descr_get */
497 0, /* tp_descr_set */
498 0, /* tp_dictoffset */
499 (initproc
)ast_type_init
, /* tp_init */
500 PyType_GenericAlloc
, /* tp_alloc */
501 PyType_GenericNew
, /* tp_new */
502 PyObject_Del
, /* tp_free */
506 static PyTypeObject
* make_type(char *type
, PyTypeObject
* base
, char**fields
, int num_fields
)
508 PyObject
*fnames
, *result
;
510 fnames
= PyTuple_New(num_fields
);
511 if (!fnames
) return NULL
;
512 for (i
= 0; i
< num_fields
; i
++) {
513 PyObject
*field
= PyString_FromString(fields
[i
]);
518 PyTuple_SET_ITEM(fnames
, i
, field
);
520 result
= PyObject_CallFunction((PyObject
*)&PyType_Type
, "s(O){sOss}",
521 type
, base
, "_fields", fnames
, "__module__", "_ast");
523 return (PyTypeObject
*)result
;
526 static int add_attributes(PyTypeObject
* type
, char**attrs
, int num_fields
)
529 PyObject
*s
, *l
= PyTuple_New(num_fields
);
531 for(i
= 0; i
< num_fields
; i
++) {
532 s
= PyString_FromString(attrs
[i
]);
537 PyTuple_SET_ITEM(l
, i
, s
);
539 result
= PyObject_SetAttrString((PyObject
*)type
, "_attributes", l
) >= 0;
544 /* Conversion AST -> Python */
546 static PyObject
* ast2obj_list(asdl_seq
*seq
, PyObject
* (*func
)(void*))
548 int i
, n
= asdl_seq_LEN(seq
);
549 PyObject
*result
= PyList_New(n
);
553 for (i
= 0; i
< n
; i
++) {
554 value
= func(asdl_seq_GET(seq
, i
));
559 PyList_SET_ITEM(result
, i
, value
);
564 static PyObject
* ast2obj_object(void *o
)
568 Py_INCREF((PyObject
*)o
);
571 #define ast2obj_identifier ast2obj_object
572 #define ast2obj_string ast2obj_object
573 static PyObject
* ast2obj_bool(bool b
)
575 return PyBool_FromLong(b
);
578 static PyObject
* ast2obj_int(long b
)
580 return PyInt_FromLong(b
);
583 /* Conversion Python -> AST */
585 static int obj2ast_object(PyObject
* obj
, PyObject
** out
, PyArena
* arena
)
590 PyArena_AddPyObject(arena
, obj
);
596 #define obj2ast_identifier obj2ast_object
597 #define obj2ast_string obj2ast_object
599 static int obj2ast_int(PyObject
* obj
, int* out
, PyArena
* arena
)
602 if (!PyInt_Check(obj
) && !PyLong_Check(obj
)) {
603 PyObject
*s
= PyObject_Repr(obj
);
604 if (s
== NULL
) return 1;
605 PyErr_Format(PyExc_ValueError
, "invalid integer value: %.400s",
606 PyString_AS_STRING(s
));
611 i
= (int)PyLong_AsLong(obj
);
612 if (i
== -1 && PyErr_Occurred())
618 static int obj2ast_bool(PyObject
* obj
, bool* out
, PyArena
* arena
)
620 if (!PyBool_Check(obj
)) {
621 PyObject
*s
= PyObject_Repr(obj
);
622 if (s
== NULL
) return 1;
623 PyErr_Format(PyExc_ValueError
, "invalid boolean value: %.400s",
624 PyString_AS_STRING(s
));
629 *out
= (obj
== Py_True
);
633 static int add_ast_fields(void)
635 PyObject
*empty_tuple
, *d
;
636 if (PyType_Ready(&AST_type
) < 0)
638 d
= AST_type
.tp_dict
;
639 empty_tuple
= PyTuple_New(0);
641 PyDict_SetItemString(d
, "_fields", empty_tuple
) < 0 ||
642 PyDict_SetItemString(d
, "_attributes", empty_tuple
) < 0) {
643 Py_XDECREF(empty_tuple
);
646 Py_DECREF(empty_tuple
);
651 static int init_types(void)
653 static int initialized
;
654 if (initialized
) return 1;
655 if (add_ast_fields() < 0) return 0;
656 mod_type
= make_type("mod", &AST_type
, NULL
, 0);
657 if (!mod_type
) return 0;
658 if (!add_attributes(mod_type
, NULL
, 0)) return 0;
659 Module_type
= make_type("Module", mod_type
, Module_fields
, 1);
660 if (!Module_type
) return 0;
661 Interactive_type
= make_type("Interactive", mod_type
,
662 Interactive_fields
, 1);
663 if (!Interactive_type
) return 0;
664 Expression_type
= make_type("Expression", mod_type
, Expression_fields
,
666 if (!Expression_type
) return 0;
667 Suite_type
= make_type("Suite", mod_type
, Suite_fields
, 1);
668 if (!Suite_type
) return 0;
669 stmt_type
= make_type("stmt", &AST_type
, NULL
, 0);
670 if (!stmt_type
) return 0;
671 if (!add_attributes(stmt_type
, stmt_attributes
, 2)) return 0;
672 FunctionDef_type
= make_type("FunctionDef", stmt_type
,
673 FunctionDef_fields
, 4);
674 if (!FunctionDef_type
) return 0;
675 ClassDef_type
= make_type("ClassDef", stmt_type
, ClassDef_fields
, 4);
676 if (!ClassDef_type
) return 0;
677 Return_type
= make_type("Return", stmt_type
, Return_fields
, 1);
678 if (!Return_type
) return 0;
679 Delete_type
= make_type("Delete", stmt_type
, Delete_fields
, 1);
680 if (!Delete_type
) return 0;
681 Assign_type
= make_type("Assign", stmt_type
, Assign_fields
, 2);
682 if (!Assign_type
) return 0;
683 AugAssign_type
= make_type("AugAssign", stmt_type
, AugAssign_fields
, 3);
684 if (!AugAssign_type
) return 0;
685 Print_type
= make_type("Print", stmt_type
, Print_fields
, 3);
686 if (!Print_type
) return 0;
687 For_type
= make_type("For", stmt_type
, For_fields
, 4);
688 if (!For_type
) return 0;
689 While_type
= make_type("While", stmt_type
, While_fields
, 3);
690 if (!While_type
) return 0;
691 If_type
= make_type("If", stmt_type
, If_fields
, 3);
692 if (!If_type
) return 0;
693 With_type
= make_type("With", stmt_type
, With_fields
, 3);
694 if (!With_type
) return 0;
695 Raise_type
= make_type("Raise", stmt_type
, Raise_fields
, 3);
696 if (!Raise_type
) return 0;
697 TryExcept_type
= make_type("TryExcept", stmt_type
, TryExcept_fields
, 3);
698 if (!TryExcept_type
) return 0;
699 TryFinally_type
= make_type("TryFinally", stmt_type
, TryFinally_fields
,
701 if (!TryFinally_type
) return 0;
702 Assert_type
= make_type("Assert", stmt_type
, Assert_fields
, 2);
703 if (!Assert_type
) return 0;
704 Import_type
= make_type("Import", stmt_type
, Import_fields
, 1);
705 if (!Import_type
) return 0;
706 ImportFrom_type
= make_type("ImportFrom", stmt_type
, ImportFrom_fields
,
708 if (!ImportFrom_type
) return 0;
709 Exec_type
= make_type("Exec", stmt_type
, Exec_fields
, 3);
710 if (!Exec_type
) return 0;
711 Global_type
= make_type("Global", stmt_type
, Global_fields
, 1);
712 if (!Global_type
) return 0;
713 Expr_type
= make_type("Expr", stmt_type
, Expr_fields
, 1);
714 if (!Expr_type
) return 0;
715 Pass_type
= make_type("Pass", stmt_type
, NULL
, 0);
716 if (!Pass_type
) return 0;
717 Break_type
= make_type("Break", stmt_type
, NULL
, 0);
718 if (!Break_type
) return 0;
719 Continue_type
= make_type("Continue", stmt_type
, NULL
, 0);
720 if (!Continue_type
) return 0;
721 expr_type
= make_type("expr", &AST_type
, NULL
, 0);
722 if (!expr_type
) return 0;
723 if (!add_attributes(expr_type
, expr_attributes
, 2)) return 0;
724 BoolOp_type
= make_type("BoolOp", expr_type
, BoolOp_fields
, 2);
725 if (!BoolOp_type
) return 0;
726 BinOp_type
= make_type("BinOp", expr_type
, BinOp_fields
, 3);
727 if (!BinOp_type
) return 0;
728 UnaryOp_type
= make_type("UnaryOp", expr_type
, UnaryOp_fields
, 2);
729 if (!UnaryOp_type
) return 0;
730 Lambda_type
= make_type("Lambda", expr_type
, Lambda_fields
, 2);
731 if (!Lambda_type
) return 0;
732 IfExp_type
= make_type("IfExp", expr_type
, IfExp_fields
, 3);
733 if (!IfExp_type
) return 0;
734 Dict_type
= make_type("Dict", expr_type
, Dict_fields
, 2);
735 if (!Dict_type
) return 0;
736 Set_type
= make_type("Set", expr_type
, Set_fields
, 1);
737 if (!Set_type
) return 0;
738 ListComp_type
= make_type("ListComp", expr_type
, ListComp_fields
, 2);
739 if (!ListComp_type
) return 0;
740 SetComp_type
= make_type("SetComp", expr_type
, SetComp_fields
, 2);
741 if (!SetComp_type
) return 0;
742 DictComp_type
= make_type("DictComp", expr_type
, DictComp_fields
, 3);
743 if (!DictComp_type
) return 0;
744 GeneratorExp_type
= make_type("GeneratorExp", expr_type
,
745 GeneratorExp_fields
, 2);
746 if (!GeneratorExp_type
) return 0;
747 Yield_type
= make_type("Yield", expr_type
, Yield_fields
, 1);
748 if (!Yield_type
) return 0;
749 Compare_type
= make_type("Compare", expr_type
, Compare_fields
, 3);
750 if (!Compare_type
) return 0;
751 Call_type
= make_type("Call", expr_type
, Call_fields
, 5);
752 if (!Call_type
) return 0;
753 Repr_type
= make_type("Repr", expr_type
, Repr_fields
, 1);
754 if (!Repr_type
) return 0;
755 Num_type
= make_type("Num", expr_type
, Num_fields
, 1);
756 if (!Num_type
) return 0;
757 Str_type
= make_type("Str", expr_type
, Str_fields
, 1);
758 if (!Str_type
) return 0;
759 Attribute_type
= make_type("Attribute", expr_type
, Attribute_fields
, 3);
760 if (!Attribute_type
) return 0;
761 Subscript_type
= make_type("Subscript", expr_type
, Subscript_fields
, 3);
762 if (!Subscript_type
) return 0;
763 Name_type
= make_type("Name", expr_type
, Name_fields
, 2);
764 if (!Name_type
) return 0;
765 List_type
= make_type("List", expr_type
, List_fields
, 2);
766 if (!List_type
) return 0;
767 Tuple_type
= make_type("Tuple", expr_type
, Tuple_fields
, 2);
768 if (!Tuple_type
) return 0;
769 expr_context_type
= make_type("expr_context", &AST_type
, NULL
, 0);
770 if (!expr_context_type
) return 0;
771 if (!add_attributes(expr_context_type
, NULL
, 0)) return 0;
772 Load_type
= make_type("Load", expr_context_type
, NULL
, 0);
773 if (!Load_type
) return 0;
774 Load_singleton
= PyType_GenericNew(Load_type
, NULL
, NULL
);
775 if (!Load_singleton
) return 0;
776 Store_type
= make_type("Store", expr_context_type
, NULL
, 0);
777 if (!Store_type
) return 0;
778 Store_singleton
= PyType_GenericNew(Store_type
, NULL
, NULL
);
779 if (!Store_singleton
) return 0;
780 Del_type
= make_type("Del", expr_context_type
, NULL
, 0);
781 if (!Del_type
) return 0;
782 Del_singleton
= PyType_GenericNew(Del_type
, NULL
, NULL
);
783 if (!Del_singleton
) return 0;
784 AugLoad_type
= make_type("AugLoad", expr_context_type
, NULL
, 0);
785 if (!AugLoad_type
) return 0;
786 AugLoad_singleton
= PyType_GenericNew(AugLoad_type
, NULL
, NULL
);
787 if (!AugLoad_singleton
) return 0;
788 AugStore_type
= make_type("AugStore", expr_context_type
, NULL
, 0);
789 if (!AugStore_type
) return 0;
790 AugStore_singleton
= PyType_GenericNew(AugStore_type
, NULL
, NULL
);
791 if (!AugStore_singleton
) return 0;
792 Param_type
= make_type("Param", expr_context_type
, NULL
, 0);
793 if (!Param_type
) return 0;
794 Param_singleton
= PyType_GenericNew(Param_type
, NULL
, NULL
);
795 if (!Param_singleton
) return 0;
796 slice_type
= make_type("slice", &AST_type
, NULL
, 0);
797 if (!slice_type
) return 0;
798 if (!add_attributes(slice_type
, NULL
, 0)) return 0;
799 Ellipsis_type
= make_type("Ellipsis", slice_type
, NULL
, 0);
800 if (!Ellipsis_type
) return 0;
801 Slice_type
= make_type("Slice", slice_type
, Slice_fields
, 3);
802 if (!Slice_type
) return 0;
803 ExtSlice_type
= make_type("ExtSlice", slice_type
, ExtSlice_fields
, 1);
804 if (!ExtSlice_type
) return 0;
805 Index_type
= make_type("Index", slice_type
, Index_fields
, 1);
806 if (!Index_type
) return 0;
807 boolop_type
= make_type("boolop", &AST_type
, NULL
, 0);
808 if (!boolop_type
) return 0;
809 if (!add_attributes(boolop_type
, NULL
, 0)) return 0;
810 And_type
= make_type("And", boolop_type
, NULL
, 0);
811 if (!And_type
) return 0;
812 And_singleton
= PyType_GenericNew(And_type
, NULL
, NULL
);
813 if (!And_singleton
) return 0;
814 Or_type
= make_type("Or", boolop_type
, NULL
, 0);
815 if (!Or_type
) return 0;
816 Or_singleton
= PyType_GenericNew(Or_type
, NULL
, NULL
);
817 if (!Or_singleton
) return 0;
818 operator_type
= make_type("operator", &AST_type
, NULL
, 0);
819 if (!operator_type
) return 0;
820 if (!add_attributes(operator_type
, NULL
, 0)) return 0;
821 Add_type
= make_type("Add", operator_type
, NULL
, 0);
822 if (!Add_type
) return 0;
823 Add_singleton
= PyType_GenericNew(Add_type
, NULL
, NULL
);
824 if (!Add_singleton
) return 0;
825 Sub_type
= make_type("Sub", operator_type
, NULL
, 0);
826 if (!Sub_type
) return 0;
827 Sub_singleton
= PyType_GenericNew(Sub_type
, NULL
, NULL
);
828 if (!Sub_singleton
) return 0;
829 Mult_type
= make_type("Mult", operator_type
, NULL
, 0);
830 if (!Mult_type
) return 0;
831 Mult_singleton
= PyType_GenericNew(Mult_type
, NULL
, NULL
);
832 if (!Mult_singleton
) return 0;
833 Div_type
= make_type("Div", operator_type
, NULL
, 0);
834 if (!Div_type
) return 0;
835 Div_singleton
= PyType_GenericNew(Div_type
, NULL
, NULL
);
836 if (!Div_singleton
) return 0;
837 Mod_type
= make_type("Mod", operator_type
, NULL
, 0);
838 if (!Mod_type
) return 0;
839 Mod_singleton
= PyType_GenericNew(Mod_type
, NULL
, NULL
);
840 if (!Mod_singleton
) return 0;
841 Pow_type
= make_type("Pow", operator_type
, NULL
, 0);
842 if (!Pow_type
) return 0;
843 Pow_singleton
= PyType_GenericNew(Pow_type
, NULL
, NULL
);
844 if (!Pow_singleton
) return 0;
845 LShift_type
= make_type("LShift", operator_type
, NULL
, 0);
846 if (!LShift_type
) return 0;
847 LShift_singleton
= PyType_GenericNew(LShift_type
, NULL
, NULL
);
848 if (!LShift_singleton
) return 0;
849 RShift_type
= make_type("RShift", operator_type
, NULL
, 0);
850 if (!RShift_type
) return 0;
851 RShift_singleton
= PyType_GenericNew(RShift_type
, NULL
, NULL
);
852 if (!RShift_singleton
) return 0;
853 BitOr_type
= make_type("BitOr", operator_type
, NULL
, 0);
854 if (!BitOr_type
) return 0;
855 BitOr_singleton
= PyType_GenericNew(BitOr_type
, NULL
, NULL
);
856 if (!BitOr_singleton
) return 0;
857 BitXor_type
= make_type("BitXor", operator_type
, NULL
, 0);
858 if (!BitXor_type
) return 0;
859 BitXor_singleton
= PyType_GenericNew(BitXor_type
, NULL
, NULL
);
860 if (!BitXor_singleton
) return 0;
861 BitAnd_type
= make_type("BitAnd", operator_type
, NULL
, 0);
862 if (!BitAnd_type
) return 0;
863 BitAnd_singleton
= PyType_GenericNew(BitAnd_type
, NULL
, NULL
);
864 if (!BitAnd_singleton
) return 0;
865 FloorDiv_type
= make_type("FloorDiv", operator_type
, NULL
, 0);
866 if (!FloorDiv_type
) return 0;
867 FloorDiv_singleton
= PyType_GenericNew(FloorDiv_type
, NULL
, NULL
);
868 if (!FloorDiv_singleton
) return 0;
869 unaryop_type
= make_type("unaryop", &AST_type
, NULL
, 0);
870 if (!unaryop_type
) return 0;
871 if (!add_attributes(unaryop_type
, NULL
, 0)) return 0;
872 Invert_type
= make_type("Invert", unaryop_type
, NULL
, 0);
873 if (!Invert_type
) return 0;
874 Invert_singleton
= PyType_GenericNew(Invert_type
, NULL
, NULL
);
875 if (!Invert_singleton
) return 0;
876 Not_type
= make_type("Not", unaryop_type
, NULL
, 0);
877 if (!Not_type
) return 0;
878 Not_singleton
= PyType_GenericNew(Not_type
, NULL
, NULL
);
879 if (!Not_singleton
) return 0;
880 UAdd_type
= make_type("UAdd", unaryop_type
, NULL
, 0);
881 if (!UAdd_type
) return 0;
882 UAdd_singleton
= PyType_GenericNew(UAdd_type
, NULL
, NULL
);
883 if (!UAdd_singleton
) return 0;
884 USub_type
= make_type("USub", unaryop_type
, NULL
, 0);
885 if (!USub_type
) return 0;
886 USub_singleton
= PyType_GenericNew(USub_type
, NULL
, NULL
);
887 if (!USub_singleton
) return 0;
888 cmpop_type
= make_type("cmpop", &AST_type
, NULL
, 0);
889 if (!cmpop_type
) return 0;
890 if (!add_attributes(cmpop_type
, NULL
, 0)) return 0;
891 Eq_type
= make_type("Eq", cmpop_type
, NULL
, 0);
892 if (!Eq_type
) return 0;
893 Eq_singleton
= PyType_GenericNew(Eq_type
, NULL
, NULL
);
894 if (!Eq_singleton
) return 0;
895 NotEq_type
= make_type("NotEq", cmpop_type
, NULL
, 0);
896 if (!NotEq_type
) return 0;
897 NotEq_singleton
= PyType_GenericNew(NotEq_type
, NULL
, NULL
);
898 if (!NotEq_singleton
) return 0;
899 Lt_type
= make_type("Lt", cmpop_type
, NULL
, 0);
900 if (!Lt_type
) return 0;
901 Lt_singleton
= PyType_GenericNew(Lt_type
, NULL
, NULL
);
902 if (!Lt_singleton
) return 0;
903 LtE_type
= make_type("LtE", cmpop_type
, NULL
, 0);
904 if (!LtE_type
) return 0;
905 LtE_singleton
= PyType_GenericNew(LtE_type
, NULL
, NULL
);
906 if (!LtE_singleton
) return 0;
907 Gt_type
= make_type("Gt", cmpop_type
, NULL
, 0);
908 if (!Gt_type
) return 0;
909 Gt_singleton
= PyType_GenericNew(Gt_type
, NULL
, NULL
);
910 if (!Gt_singleton
) return 0;
911 GtE_type
= make_type("GtE", cmpop_type
, NULL
, 0);
912 if (!GtE_type
) return 0;
913 GtE_singleton
= PyType_GenericNew(GtE_type
, NULL
, NULL
);
914 if (!GtE_singleton
) return 0;
915 Is_type
= make_type("Is", cmpop_type
, NULL
, 0);
916 if (!Is_type
) return 0;
917 Is_singleton
= PyType_GenericNew(Is_type
, NULL
, NULL
);
918 if (!Is_singleton
) return 0;
919 IsNot_type
= make_type("IsNot", cmpop_type
, NULL
, 0);
920 if (!IsNot_type
) return 0;
921 IsNot_singleton
= PyType_GenericNew(IsNot_type
, NULL
, NULL
);
922 if (!IsNot_singleton
) return 0;
923 In_type
= make_type("In", cmpop_type
, NULL
, 0);
924 if (!In_type
) return 0;
925 In_singleton
= PyType_GenericNew(In_type
, NULL
, NULL
);
926 if (!In_singleton
) return 0;
927 NotIn_type
= make_type("NotIn", cmpop_type
, NULL
, 0);
928 if (!NotIn_type
) return 0;
929 NotIn_singleton
= PyType_GenericNew(NotIn_type
, NULL
, NULL
);
930 if (!NotIn_singleton
) return 0;
931 comprehension_type
= make_type("comprehension", &AST_type
,
932 comprehension_fields
, 3);
933 if (!comprehension_type
) return 0;
934 excepthandler_type
= make_type("excepthandler", &AST_type
, NULL
, 0);
935 if (!excepthandler_type
) return 0;
936 if (!add_attributes(excepthandler_type
, excepthandler_attributes
, 2))
938 ExceptHandler_type
= make_type("ExceptHandler", excepthandler_type
,
939 ExceptHandler_fields
, 3);
940 if (!ExceptHandler_type
) return 0;
941 arguments_type
= make_type("arguments", &AST_type
, arguments_fields
, 4);
942 if (!arguments_type
) return 0;
943 keyword_type
= make_type("keyword", &AST_type
, keyword_fields
, 2);
944 if (!keyword_type
) return 0;
945 alias_type
= make_type("alias", &AST_type
, alias_fields
, 2);
946 if (!alias_type
) return 0;
951 static int obj2ast_mod(PyObject
* obj
, mod_ty
* out
, PyArena
* arena
);
952 static int obj2ast_stmt(PyObject
* obj
, stmt_ty
* out
, PyArena
* arena
);
953 static int obj2ast_expr(PyObject
* obj
, expr_ty
* out
, PyArena
* arena
);
954 static int obj2ast_expr_context(PyObject
* obj
, expr_context_ty
* out
, PyArena
*
956 static int obj2ast_slice(PyObject
* obj
, slice_ty
* out
, PyArena
* arena
);
957 static int obj2ast_boolop(PyObject
* obj
, boolop_ty
* out
, PyArena
* arena
);
958 static int obj2ast_operator(PyObject
* obj
, operator_ty
* out
, PyArena
* arena
);
959 static int obj2ast_unaryop(PyObject
* obj
, unaryop_ty
* out
, PyArena
* arena
);
960 static int obj2ast_cmpop(PyObject
* obj
, cmpop_ty
* out
, PyArena
* arena
);
961 static int obj2ast_comprehension(PyObject
* obj
, comprehension_ty
* out
, PyArena
*
963 static int obj2ast_excepthandler(PyObject
* obj
, excepthandler_ty
* out
, PyArena
*
965 static int obj2ast_arguments(PyObject
* obj
, arguments_ty
* out
, PyArena
* arena
);
966 static int obj2ast_keyword(PyObject
* obj
, keyword_ty
* out
, PyArena
* arena
);
967 static int obj2ast_alias(PyObject
* obj
, alias_ty
* out
, PyArena
* arena
);
970 Module(asdl_seq
* body
, PyArena
*arena
)
973 p
= (mod_ty
)PyArena_Malloc(arena
, sizeof(*p
));
976 p
->kind
= Module_kind
;
977 p
->v
.Module
.body
= body
;
982 Interactive(asdl_seq
* body
, PyArena
*arena
)
985 p
= (mod_ty
)PyArena_Malloc(arena
, sizeof(*p
));
988 p
->kind
= Interactive_kind
;
989 p
->v
.Interactive
.body
= body
;
994 Expression(expr_ty body
, PyArena
*arena
)
998 PyErr_SetString(PyExc_ValueError
,
999 "field body is required for Expression");
1002 p
= (mod_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1005 p
->kind
= Expression_kind
;
1006 p
->v
.Expression
.body
= body
;
1011 Suite(asdl_seq
* body
, PyArena
*arena
)
1014 p
= (mod_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1017 p
->kind
= Suite_kind
;
1018 p
->v
.Suite
.body
= body
;
1023 FunctionDef(identifier name
, arguments_ty args
, asdl_seq
* body
, asdl_seq
*
1024 decorator_list
, int lineno
, int col_offset
, PyArena
*arena
)
1028 PyErr_SetString(PyExc_ValueError
,
1029 "field name is required for FunctionDef");
1033 PyErr_SetString(PyExc_ValueError
,
1034 "field args is required for FunctionDef");
1037 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1040 p
->kind
= FunctionDef_kind
;
1041 p
->v
.FunctionDef
.name
= name
;
1042 p
->v
.FunctionDef
.args
= args
;
1043 p
->v
.FunctionDef
.body
= body
;
1044 p
->v
.FunctionDef
.decorator_list
= decorator_list
;
1046 p
->col_offset
= col_offset
;
1051 ClassDef(identifier name
, asdl_seq
* bases
, asdl_seq
* body
, asdl_seq
*
1052 decorator_list
, int lineno
, int col_offset
, PyArena
*arena
)
1056 PyErr_SetString(PyExc_ValueError
,
1057 "field name is required for ClassDef");
1060 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1063 p
->kind
= ClassDef_kind
;
1064 p
->v
.ClassDef
.name
= name
;
1065 p
->v
.ClassDef
.bases
= bases
;
1066 p
->v
.ClassDef
.body
= body
;
1067 p
->v
.ClassDef
.decorator_list
= decorator_list
;
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 Print(expr_ty dest
, asdl_seq
* values
, bool nl
, int lineno
, int col_offset
,
1159 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1162 p
->kind
= Print_kind
;
1163 p
->v
.Print
.dest
= dest
;
1164 p
->v
.Print
.values
= values
;
1167 p
->col_offset
= col_offset
;
1172 For(expr_ty target
, expr_ty iter
, asdl_seq
* body
, asdl_seq
* orelse
, int
1173 lineno
, int col_offset
, PyArena
*arena
)
1177 PyErr_SetString(PyExc_ValueError
,
1178 "field target is required for For");
1182 PyErr_SetString(PyExc_ValueError
,
1183 "field iter is required for For");
1186 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1190 p
->v
.For
.target
= target
;
1191 p
->v
.For
.iter
= iter
;
1192 p
->v
.For
.body
= body
;
1193 p
->v
.For
.orelse
= orelse
;
1195 p
->col_offset
= col_offset
;
1200 While(expr_ty test
, asdl_seq
* body
, asdl_seq
* orelse
, int lineno
, int
1201 col_offset
, PyArena
*arena
)
1205 PyErr_SetString(PyExc_ValueError
,
1206 "field test is required for While");
1209 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1212 p
->kind
= While_kind
;
1213 p
->v
.While
.test
= test
;
1214 p
->v
.While
.body
= body
;
1215 p
->v
.While
.orelse
= orelse
;
1217 p
->col_offset
= col_offset
;
1222 If(expr_ty test
, asdl_seq
* body
, asdl_seq
* orelse
, int lineno
, int
1223 col_offset
, PyArena
*arena
)
1227 PyErr_SetString(PyExc_ValueError
,
1228 "field test is required for If");
1231 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1235 p
->v
.If
.test
= test
;
1236 p
->v
.If
.body
= body
;
1237 p
->v
.If
.orelse
= orelse
;
1239 p
->col_offset
= col_offset
;
1244 With(expr_ty context_expr
, expr_ty optional_vars
, asdl_seq
* body
, int lineno
,
1245 int col_offset
, PyArena
*arena
)
1248 if (!context_expr
) {
1249 PyErr_SetString(PyExc_ValueError
,
1250 "field context_expr is required for With");
1253 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1256 p
->kind
= With_kind
;
1257 p
->v
.With
.context_expr
= context_expr
;
1258 p
->v
.With
.optional_vars
= optional_vars
;
1259 p
->v
.With
.body
= body
;
1261 p
->col_offset
= col_offset
;
1266 Raise(expr_ty type
, expr_ty inst
, expr_ty tback
, int lineno
, int col_offset
,
1270 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1273 p
->kind
= Raise_kind
;
1274 p
->v
.Raise
.type
= type
;
1275 p
->v
.Raise
.inst
= inst
;
1276 p
->v
.Raise
.tback
= tback
;
1278 p
->col_offset
= col_offset
;
1283 TryExcept(asdl_seq
* body
, asdl_seq
* handlers
, asdl_seq
* orelse
, int lineno
,
1284 int col_offset
, PyArena
*arena
)
1287 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1290 p
->kind
= TryExcept_kind
;
1291 p
->v
.TryExcept
.body
= body
;
1292 p
->v
.TryExcept
.handlers
= handlers
;
1293 p
->v
.TryExcept
.orelse
= orelse
;
1295 p
->col_offset
= col_offset
;
1300 TryFinally(asdl_seq
* body
, asdl_seq
* finalbody
, int lineno
, int col_offset
,
1304 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1307 p
->kind
= TryFinally_kind
;
1308 p
->v
.TryFinally
.body
= body
;
1309 p
->v
.TryFinally
.finalbody
= finalbody
;
1311 p
->col_offset
= col_offset
;
1316 Assert(expr_ty test
, expr_ty msg
, int lineno
, int col_offset
, PyArena
*arena
)
1320 PyErr_SetString(PyExc_ValueError
,
1321 "field test is required for Assert");
1324 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1327 p
->kind
= Assert_kind
;
1328 p
->v
.Assert
.test
= test
;
1329 p
->v
.Assert
.msg
= msg
;
1331 p
->col_offset
= col_offset
;
1336 Import(asdl_seq
* names
, int lineno
, int col_offset
, PyArena
*arena
)
1339 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1342 p
->kind
= Import_kind
;
1343 p
->v
.Import
.names
= names
;
1345 p
->col_offset
= col_offset
;
1350 ImportFrom(identifier module
, asdl_seq
* names
, int level
, int lineno
, int
1351 col_offset
, PyArena
*arena
)
1354 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1357 p
->kind
= ImportFrom_kind
;
1358 p
->v
.ImportFrom
.module
= module
;
1359 p
->v
.ImportFrom
.names
= names
;
1360 p
->v
.ImportFrom
.level
= level
;
1362 p
->col_offset
= col_offset
;
1367 Exec(expr_ty body
, expr_ty globals
, expr_ty locals
, int lineno
, int col_offset
,
1372 PyErr_SetString(PyExc_ValueError
,
1373 "field body is required for Exec");
1376 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1379 p
->kind
= Exec_kind
;
1380 p
->v
.Exec
.body
= body
;
1381 p
->v
.Exec
.globals
= globals
;
1382 p
->v
.Exec
.locals
= locals
;
1384 p
->col_offset
= col_offset
;
1389 Global(asdl_seq
* names
, int lineno
, int col_offset
, PyArena
*arena
)
1392 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1395 p
->kind
= Global_kind
;
1396 p
->v
.Global
.names
= names
;
1398 p
->col_offset
= col_offset
;
1403 Expr(expr_ty value
, int lineno
, int col_offset
, PyArena
*arena
)
1407 PyErr_SetString(PyExc_ValueError
,
1408 "field value is required for Expr");
1411 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1414 p
->kind
= Expr_kind
;
1415 p
->v
.Expr
.value
= value
;
1417 p
->col_offset
= col_offset
;
1422 Pass(int lineno
, int col_offset
, PyArena
*arena
)
1425 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1428 p
->kind
= Pass_kind
;
1430 p
->col_offset
= col_offset
;
1435 Break(int lineno
, int col_offset
, PyArena
*arena
)
1438 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1441 p
->kind
= Break_kind
;
1443 p
->col_offset
= col_offset
;
1448 Continue(int lineno
, int col_offset
, PyArena
*arena
)
1451 p
= (stmt_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1454 p
->kind
= Continue_kind
;
1456 p
->col_offset
= col_offset
;
1461 BoolOp(boolop_ty op
, asdl_seq
* values
, int lineno
, int col_offset
, PyArena
1466 PyErr_SetString(PyExc_ValueError
,
1467 "field op is required for BoolOp");
1470 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1473 p
->kind
= BoolOp_kind
;
1474 p
->v
.BoolOp
.op
= op
;
1475 p
->v
.BoolOp
.values
= values
;
1477 p
->col_offset
= col_offset
;
1482 BinOp(expr_ty left
, operator_ty op
, expr_ty right
, int lineno
, int col_offset
,
1487 PyErr_SetString(PyExc_ValueError
,
1488 "field left is required for BinOp");
1492 PyErr_SetString(PyExc_ValueError
,
1493 "field op is required for BinOp");
1497 PyErr_SetString(PyExc_ValueError
,
1498 "field right is required for BinOp");
1501 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1504 p
->kind
= BinOp_kind
;
1505 p
->v
.BinOp
.left
= left
;
1507 p
->v
.BinOp
.right
= right
;
1509 p
->col_offset
= col_offset
;
1514 UnaryOp(unaryop_ty op
, expr_ty operand
, int lineno
, int col_offset
, PyArena
1519 PyErr_SetString(PyExc_ValueError
,
1520 "field op is required for UnaryOp");
1524 PyErr_SetString(PyExc_ValueError
,
1525 "field operand is required for UnaryOp");
1528 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1531 p
->kind
= UnaryOp_kind
;
1532 p
->v
.UnaryOp
.op
= op
;
1533 p
->v
.UnaryOp
.operand
= operand
;
1535 p
->col_offset
= col_offset
;
1540 Lambda(arguments_ty args
, expr_ty body
, int lineno
, int col_offset
, PyArena
1545 PyErr_SetString(PyExc_ValueError
,
1546 "field args is required for Lambda");
1550 PyErr_SetString(PyExc_ValueError
,
1551 "field body is required for Lambda");
1554 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1557 p
->kind
= Lambda_kind
;
1558 p
->v
.Lambda
.args
= args
;
1559 p
->v
.Lambda
.body
= body
;
1561 p
->col_offset
= col_offset
;
1566 IfExp(expr_ty test
, expr_ty body
, expr_ty orelse
, int lineno
, int col_offset
,
1571 PyErr_SetString(PyExc_ValueError
,
1572 "field test is required for IfExp");
1576 PyErr_SetString(PyExc_ValueError
,
1577 "field body is required for IfExp");
1581 PyErr_SetString(PyExc_ValueError
,
1582 "field orelse is required for IfExp");
1585 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1588 p
->kind
= IfExp_kind
;
1589 p
->v
.IfExp
.test
= test
;
1590 p
->v
.IfExp
.body
= body
;
1591 p
->v
.IfExp
.orelse
= orelse
;
1593 p
->col_offset
= col_offset
;
1598 Dict(asdl_seq
* keys
, asdl_seq
* values
, int lineno
, int col_offset
, PyArena
1602 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1605 p
->kind
= Dict_kind
;
1606 p
->v
.Dict
.keys
= keys
;
1607 p
->v
.Dict
.values
= values
;
1609 p
->col_offset
= col_offset
;
1614 Set(asdl_seq
* elts
, int lineno
, int col_offset
, PyArena
*arena
)
1617 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1621 p
->v
.Set
.elts
= elts
;
1623 p
->col_offset
= col_offset
;
1628 ListComp(expr_ty elt
, asdl_seq
* generators
, int lineno
, int col_offset
,
1633 PyErr_SetString(PyExc_ValueError
,
1634 "field elt is required for ListComp");
1637 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1640 p
->kind
= ListComp_kind
;
1641 p
->v
.ListComp
.elt
= elt
;
1642 p
->v
.ListComp
.generators
= generators
;
1644 p
->col_offset
= col_offset
;
1649 SetComp(expr_ty elt
, asdl_seq
* generators
, int lineno
, int col_offset
, PyArena
1654 PyErr_SetString(PyExc_ValueError
,
1655 "field elt is required for SetComp");
1658 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1661 p
->kind
= SetComp_kind
;
1662 p
->v
.SetComp
.elt
= elt
;
1663 p
->v
.SetComp
.generators
= generators
;
1665 p
->col_offset
= col_offset
;
1670 DictComp(expr_ty key
, expr_ty value
, asdl_seq
* generators
, int lineno
, int
1671 col_offset
, PyArena
*arena
)
1675 PyErr_SetString(PyExc_ValueError
,
1676 "field key is required for DictComp");
1680 PyErr_SetString(PyExc_ValueError
,
1681 "field value is required for DictComp");
1684 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1687 p
->kind
= DictComp_kind
;
1688 p
->v
.DictComp
.key
= key
;
1689 p
->v
.DictComp
.value
= value
;
1690 p
->v
.DictComp
.generators
= generators
;
1692 p
->col_offset
= col_offset
;
1697 GeneratorExp(expr_ty elt
, asdl_seq
* generators
, int lineno
, int col_offset
,
1702 PyErr_SetString(PyExc_ValueError
,
1703 "field elt is required for GeneratorExp");
1706 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1709 p
->kind
= GeneratorExp_kind
;
1710 p
->v
.GeneratorExp
.elt
= elt
;
1711 p
->v
.GeneratorExp
.generators
= generators
;
1713 p
->col_offset
= col_offset
;
1718 Yield(expr_ty value
, int lineno
, int col_offset
, PyArena
*arena
)
1721 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1724 p
->kind
= Yield_kind
;
1725 p
->v
.Yield
.value
= value
;
1727 p
->col_offset
= col_offset
;
1732 Compare(expr_ty left
, asdl_int_seq
* ops
, asdl_seq
* comparators
, int lineno
,
1733 int col_offset
, PyArena
*arena
)
1737 PyErr_SetString(PyExc_ValueError
,
1738 "field left is required for Compare");
1741 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1744 p
->kind
= Compare_kind
;
1745 p
->v
.Compare
.left
= left
;
1746 p
->v
.Compare
.ops
= ops
;
1747 p
->v
.Compare
.comparators
= comparators
;
1749 p
->col_offset
= col_offset
;
1754 Call(expr_ty func
, asdl_seq
* args
, asdl_seq
* keywords
, expr_ty starargs
,
1755 expr_ty kwargs
, int lineno
, int col_offset
, PyArena
*arena
)
1759 PyErr_SetString(PyExc_ValueError
,
1760 "field func is required for Call");
1763 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1766 p
->kind
= Call_kind
;
1767 p
->v
.Call
.func
= func
;
1768 p
->v
.Call
.args
= args
;
1769 p
->v
.Call
.keywords
= keywords
;
1770 p
->v
.Call
.starargs
= starargs
;
1771 p
->v
.Call
.kwargs
= kwargs
;
1773 p
->col_offset
= col_offset
;
1778 Repr(expr_ty value
, int lineno
, int col_offset
, PyArena
*arena
)
1782 PyErr_SetString(PyExc_ValueError
,
1783 "field value is required for Repr");
1786 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1789 p
->kind
= Repr_kind
;
1790 p
->v
.Repr
.value
= value
;
1792 p
->col_offset
= col_offset
;
1797 Num(object n
, int lineno
, int col_offset
, PyArena
*arena
)
1801 PyErr_SetString(PyExc_ValueError
,
1802 "field n is required for Num");
1805 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1811 p
->col_offset
= col_offset
;
1816 Str(string s
, int lineno
, int col_offset
, PyArena
*arena
)
1820 PyErr_SetString(PyExc_ValueError
,
1821 "field s is required for Str");
1824 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1830 p
->col_offset
= col_offset
;
1835 Attribute(expr_ty value
, identifier attr
, expr_context_ty ctx
, int lineno
, int
1836 col_offset
, PyArena
*arena
)
1840 PyErr_SetString(PyExc_ValueError
,
1841 "field value is required for Attribute");
1845 PyErr_SetString(PyExc_ValueError
,
1846 "field attr is required for Attribute");
1850 PyErr_SetString(PyExc_ValueError
,
1851 "field ctx is required for Attribute");
1854 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1857 p
->kind
= Attribute_kind
;
1858 p
->v
.Attribute
.value
= value
;
1859 p
->v
.Attribute
.attr
= attr
;
1860 p
->v
.Attribute
.ctx
= ctx
;
1862 p
->col_offset
= col_offset
;
1867 Subscript(expr_ty value
, slice_ty slice
, expr_context_ty ctx
, int lineno
, int
1868 col_offset
, PyArena
*arena
)
1872 PyErr_SetString(PyExc_ValueError
,
1873 "field value is required for Subscript");
1877 PyErr_SetString(PyExc_ValueError
,
1878 "field slice is required for Subscript");
1882 PyErr_SetString(PyExc_ValueError
,
1883 "field ctx is required for Subscript");
1886 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1889 p
->kind
= Subscript_kind
;
1890 p
->v
.Subscript
.value
= value
;
1891 p
->v
.Subscript
.slice
= slice
;
1892 p
->v
.Subscript
.ctx
= ctx
;
1894 p
->col_offset
= col_offset
;
1899 Name(identifier id
, expr_context_ty ctx
, int lineno
, int col_offset
, PyArena
1904 PyErr_SetString(PyExc_ValueError
,
1905 "field id is required for Name");
1909 PyErr_SetString(PyExc_ValueError
,
1910 "field ctx is required for Name");
1913 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1916 p
->kind
= Name_kind
;
1918 p
->v
.Name
.ctx
= ctx
;
1920 p
->col_offset
= col_offset
;
1925 List(asdl_seq
* elts
, expr_context_ty ctx
, int lineno
, int col_offset
, PyArena
1930 PyErr_SetString(PyExc_ValueError
,
1931 "field ctx is required for List");
1934 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1937 p
->kind
= List_kind
;
1938 p
->v
.List
.elts
= elts
;
1939 p
->v
.List
.ctx
= ctx
;
1941 p
->col_offset
= col_offset
;
1946 Tuple(asdl_seq
* elts
, expr_context_ty ctx
, int lineno
, int col_offset
, PyArena
1951 PyErr_SetString(PyExc_ValueError
,
1952 "field ctx is required for Tuple");
1955 p
= (expr_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1958 p
->kind
= Tuple_kind
;
1959 p
->v
.Tuple
.elts
= elts
;
1960 p
->v
.Tuple
.ctx
= ctx
;
1962 p
->col_offset
= col_offset
;
1967 Ellipsis(PyArena
*arena
)
1970 p
= (slice_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1973 p
->kind
= Ellipsis_kind
;
1978 Slice(expr_ty lower
, expr_ty upper
, expr_ty step
, PyArena
*arena
)
1981 p
= (slice_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1984 p
->kind
= Slice_kind
;
1985 p
->v
.Slice
.lower
= lower
;
1986 p
->v
.Slice
.upper
= upper
;
1987 p
->v
.Slice
.step
= step
;
1992 ExtSlice(asdl_seq
* dims
, PyArena
*arena
)
1995 p
= (slice_ty
)PyArena_Malloc(arena
, sizeof(*p
));
1998 p
->kind
= ExtSlice_kind
;
1999 p
->v
.ExtSlice
.dims
= dims
;
2004 Index(expr_ty value
, PyArena
*arena
)
2008 PyErr_SetString(PyExc_ValueError
,
2009 "field value is required for Index");
2012 p
= (slice_ty
)PyArena_Malloc(arena
, sizeof(*p
));
2015 p
->kind
= Index_kind
;
2016 p
->v
.Index
.value
= value
;
2021 comprehension(expr_ty target
, expr_ty iter
, asdl_seq
* ifs
, PyArena
*arena
)
2025 PyErr_SetString(PyExc_ValueError
,
2026 "field target is required for comprehension");
2030 PyErr_SetString(PyExc_ValueError
,
2031 "field iter is required for comprehension");
2034 p
= (comprehension_ty
)PyArena_Malloc(arena
, sizeof(*p
));
2044 ExceptHandler(expr_ty type
, expr_ty name
, asdl_seq
* body
, int lineno
, int
2045 col_offset
, PyArena
*arena
)
2048 p
= (excepthandler_ty
)PyArena_Malloc(arena
, sizeof(*p
));
2051 p
->kind
= ExceptHandler_kind
;
2052 p
->v
.ExceptHandler
.type
= type
;
2053 p
->v
.ExceptHandler
.name
= name
;
2054 p
->v
.ExceptHandler
.body
= body
;
2056 p
->col_offset
= col_offset
;
2061 arguments(asdl_seq
* args
, identifier vararg
, identifier kwarg
, asdl_seq
*
2062 defaults
, PyArena
*arena
)
2065 p
= (arguments_ty
)PyArena_Malloc(arena
, sizeof(*p
));
2071 p
->defaults
= defaults
;
2076 keyword(identifier arg
, expr_ty value
, PyArena
*arena
)
2080 PyErr_SetString(PyExc_ValueError
,
2081 "field arg is required for keyword");
2085 PyErr_SetString(PyExc_ValueError
,
2086 "field value is required for keyword");
2089 p
= (keyword_ty
)PyArena_Malloc(arena
, sizeof(*p
));
2098 alias(identifier name
, identifier asname
, PyArena
*arena
)
2102 PyErr_SetString(PyExc_ValueError
,
2103 "field name is required for alias");
2106 p
= (alias_ty
)PyArena_Malloc(arena
, sizeof(*p
));
2116 ast2obj_mod(void* _o
)
2118 mod_ty o
= (mod_ty
)_o
;
2119 PyObject
*result
= NULL
, *value
= NULL
;
2127 result
= PyType_GenericNew(Module_type
, NULL
, NULL
);
2128 if (!result
) goto failed
;
2129 value
= ast2obj_list(o
->v
.Module
.body
, ast2obj_stmt
);
2130 if (!value
) goto failed
;
2131 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2135 case Interactive_kind
:
2136 result
= PyType_GenericNew(Interactive_type
, NULL
, NULL
);
2137 if (!result
) goto failed
;
2138 value
= ast2obj_list(o
->v
.Interactive
.body
, ast2obj_stmt
);
2139 if (!value
) goto failed
;
2140 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2144 case Expression_kind
:
2145 result
= PyType_GenericNew(Expression_type
, NULL
, NULL
);
2146 if (!result
) goto failed
;
2147 value
= ast2obj_expr(o
->v
.Expression
.body
);
2148 if (!value
) goto failed
;
2149 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2154 result
= PyType_GenericNew(Suite_type
, NULL
, NULL
);
2155 if (!result
) goto failed
;
2156 value
= ast2obj_list(o
->v
.Suite
.body
, ast2obj_stmt
);
2157 if (!value
) goto failed
;
2158 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2171 ast2obj_stmt(void* _o
)
2173 stmt_ty o
= (stmt_ty
)_o
;
2174 PyObject
*result
= NULL
, *value
= NULL
;
2181 case FunctionDef_kind
:
2182 result
= PyType_GenericNew(FunctionDef_type
, NULL
, NULL
);
2183 if (!result
) goto failed
;
2184 value
= ast2obj_identifier(o
->v
.FunctionDef
.name
);
2185 if (!value
) goto failed
;
2186 if (PyObject_SetAttrString(result
, "name", value
) == -1)
2189 value
= ast2obj_arguments(o
->v
.FunctionDef
.args
);
2190 if (!value
) goto failed
;
2191 if (PyObject_SetAttrString(result
, "args", value
) == -1)
2194 value
= ast2obj_list(o
->v
.FunctionDef
.body
, ast2obj_stmt
);
2195 if (!value
) goto failed
;
2196 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2199 value
= ast2obj_list(o
->v
.FunctionDef
.decorator_list
,
2201 if (!value
) goto failed
;
2202 if (PyObject_SetAttrString(result
, "decorator_list", value
) ==
2208 result
= PyType_GenericNew(ClassDef_type
, NULL
, NULL
);
2209 if (!result
) goto failed
;
2210 value
= ast2obj_identifier(o
->v
.ClassDef
.name
);
2211 if (!value
) goto failed
;
2212 if (PyObject_SetAttrString(result
, "name", value
) == -1)
2215 value
= ast2obj_list(o
->v
.ClassDef
.bases
, ast2obj_expr
);
2216 if (!value
) goto failed
;
2217 if (PyObject_SetAttrString(result
, "bases", value
) == -1)
2220 value
= ast2obj_list(o
->v
.ClassDef
.body
, ast2obj_stmt
);
2221 if (!value
) goto failed
;
2222 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2225 value
= ast2obj_list(o
->v
.ClassDef
.decorator_list
,
2227 if (!value
) goto failed
;
2228 if (PyObject_SetAttrString(result
, "decorator_list", value
) ==
2234 result
= PyType_GenericNew(Return_type
, NULL
, NULL
);
2235 if (!result
) goto failed
;
2236 value
= ast2obj_expr(o
->v
.Return
.value
);
2237 if (!value
) goto failed
;
2238 if (PyObject_SetAttrString(result
, "value", value
) == -1)
2243 result
= PyType_GenericNew(Delete_type
, NULL
, NULL
);
2244 if (!result
) goto failed
;
2245 value
= ast2obj_list(o
->v
.Delete
.targets
, ast2obj_expr
);
2246 if (!value
) goto failed
;
2247 if (PyObject_SetAttrString(result
, "targets", value
) == -1)
2252 result
= PyType_GenericNew(Assign_type
, NULL
, NULL
);
2253 if (!result
) goto failed
;
2254 value
= ast2obj_list(o
->v
.Assign
.targets
, ast2obj_expr
);
2255 if (!value
) goto failed
;
2256 if (PyObject_SetAttrString(result
, "targets", value
) == -1)
2259 value
= ast2obj_expr(o
->v
.Assign
.value
);
2260 if (!value
) goto failed
;
2261 if (PyObject_SetAttrString(result
, "value", value
) == -1)
2265 case AugAssign_kind
:
2266 result
= PyType_GenericNew(AugAssign_type
, NULL
, NULL
);
2267 if (!result
) goto failed
;
2268 value
= ast2obj_expr(o
->v
.AugAssign
.target
);
2269 if (!value
) goto failed
;
2270 if (PyObject_SetAttrString(result
, "target", value
) == -1)
2273 value
= ast2obj_operator(o
->v
.AugAssign
.op
);
2274 if (!value
) goto failed
;
2275 if (PyObject_SetAttrString(result
, "op", value
) == -1)
2278 value
= ast2obj_expr(o
->v
.AugAssign
.value
);
2279 if (!value
) goto failed
;
2280 if (PyObject_SetAttrString(result
, "value", value
) == -1)
2285 result
= PyType_GenericNew(Print_type
, NULL
, NULL
);
2286 if (!result
) goto failed
;
2287 value
= ast2obj_expr(o
->v
.Print
.dest
);
2288 if (!value
) goto failed
;
2289 if (PyObject_SetAttrString(result
, "dest", value
) == -1)
2292 value
= ast2obj_list(o
->v
.Print
.values
, ast2obj_expr
);
2293 if (!value
) goto failed
;
2294 if (PyObject_SetAttrString(result
, "values", value
) == -1)
2297 value
= ast2obj_bool(o
->v
.Print
.nl
);
2298 if (!value
) goto failed
;
2299 if (PyObject_SetAttrString(result
, "nl", value
) == -1)
2304 result
= PyType_GenericNew(For_type
, NULL
, NULL
);
2305 if (!result
) goto failed
;
2306 value
= ast2obj_expr(o
->v
.For
.target
);
2307 if (!value
) goto failed
;
2308 if (PyObject_SetAttrString(result
, "target", value
) == -1)
2311 value
= ast2obj_expr(o
->v
.For
.iter
);
2312 if (!value
) goto failed
;
2313 if (PyObject_SetAttrString(result
, "iter", value
) == -1)
2316 value
= ast2obj_list(o
->v
.For
.body
, ast2obj_stmt
);
2317 if (!value
) goto failed
;
2318 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2321 value
= ast2obj_list(o
->v
.For
.orelse
, ast2obj_stmt
);
2322 if (!value
) goto failed
;
2323 if (PyObject_SetAttrString(result
, "orelse", value
) == -1)
2328 result
= PyType_GenericNew(While_type
, NULL
, NULL
);
2329 if (!result
) goto failed
;
2330 value
= ast2obj_expr(o
->v
.While
.test
);
2331 if (!value
) goto failed
;
2332 if (PyObject_SetAttrString(result
, "test", value
) == -1)
2335 value
= ast2obj_list(o
->v
.While
.body
, ast2obj_stmt
);
2336 if (!value
) goto failed
;
2337 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2340 value
= ast2obj_list(o
->v
.While
.orelse
, ast2obj_stmt
);
2341 if (!value
) goto failed
;
2342 if (PyObject_SetAttrString(result
, "orelse", value
) == -1)
2347 result
= PyType_GenericNew(If_type
, NULL
, NULL
);
2348 if (!result
) goto failed
;
2349 value
= ast2obj_expr(o
->v
.If
.test
);
2350 if (!value
) goto failed
;
2351 if (PyObject_SetAttrString(result
, "test", value
) == -1)
2354 value
= ast2obj_list(o
->v
.If
.body
, ast2obj_stmt
);
2355 if (!value
) goto failed
;
2356 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2359 value
= ast2obj_list(o
->v
.If
.orelse
, ast2obj_stmt
);
2360 if (!value
) goto failed
;
2361 if (PyObject_SetAttrString(result
, "orelse", value
) == -1)
2366 result
= PyType_GenericNew(With_type
, NULL
, NULL
);
2367 if (!result
) goto failed
;
2368 value
= ast2obj_expr(o
->v
.With
.context_expr
);
2369 if (!value
) goto failed
;
2370 if (PyObject_SetAttrString(result
, "context_expr", value
) == -1)
2373 value
= ast2obj_expr(o
->v
.With
.optional_vars
);
2374 if (!value
) goto failed
;
2375 if (PyObject_SetAttrString(result
, "optional_vars", value
) ==
2379 value
= ast2obj_list(o
->v
.With
.body
, ast2obj_stmt
);
2380 if (!value
) goto failed
;
2381 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2386 result
= PyType_GenericNew(Raise_type
, NULL
, NULL
);
2387 if (!result
) goto failed
;
2388 value
= ast2obj_expr(o
->v
.Raise
.type
);
2389 if (!value
) goto failed
;
2390 if (PyObject_SetAttrString(result
, "type", value
) == -1)
2393 value
= ast2obj_expr(o
->v
.Raise
.inst
);
2394 if (!value
) goto failed
;
2395 if (PyObject_SetAttrString(result
, "inst", value
) == -1)
2398 value
= ast2obj_expr(o
->v
.Raise
.tback
);
2399 if (!value
) goto failed
;
2400 if (PyObject_SetAttrString(result
, "tback", value
) == -1)
2404 case TryExcept_kind
:
2405 result
= PyType_GenericNew(TryExcept_type
, NULL
, NULL
);
2406 if (!result
) goto failed
;
2407 value
= ast2obj_list(o
->v
.TryExcept
.body
, ast2obj_stmt
);
2408 if (!value
) goto failed
;
2409 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2412 value
= ast2obj_list(o
->v
.TryExcept
.handlers
,
2413 ast2obj_excepthandler
);
2414 if (!value
) goto failed
;
2415 if (PyObject_SetAttrString(result
, "handlers", value
) == -1)
2418 value
= ast2obj_list(o
->v
.TryExcept
.orelse
, ast2obj_stmt
);
2419 if (!value
) goto failed
;
2420 if (PyObject_SetAttrString(result
, "orelse", value
) == -1)
2424 case TryFinally_kind
:
2425 result
= PyType_GenericNew(TryFinally_type
, NULL
, NULL
);
2426 if (!result
) goto failed
;
2427 value
= ast2obj_list(o
->v
.TryFinally
.body
, ast2obj_stmt
);
2428 if (!value
) goto failed
;
2429 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2432 value
= ast2obj_list(o
->v
.TryFinally
.finalbody
, ast2obj_stmt
);
2433 if (!value
) goto failed
;
2434 if (PyObject_SetAttrString(result
, "finalbody", value
) == -1)
2439 result
= PyType_GenericNew(Assert_type
, NULL
, NULL
);
2440 if (!result
) goto failed
;
2441 value
= ast2obj_expr(o
->v
.Assert
.test
);
2442 if (!value
) goto failed
;
2443 if (PyObject_SetAttrString(result
, "test", value
) == -1)
2446 value
= ast2obj_expr(o
->v
.Assert
.msg
);
2447 if (!value
) goto failed
;
2448 if (PyObject_SetAttrString(result
, "msg", value
) == -1)
2453 result
= PyType_GenericNew(Import_type
, NULL
, NULL
);
2454 if (!result
) goto failed
;
2455 value
= ast2obj_list(o
->v
.Import
.names
, ast2obj_alias
);
2456 if (!value
) goto failed
;
2457 if (PyObject_SetAttrString(result
, "names", value
) == -1)
2461 case ImportFrom_kind
:
2462 result
= PyType_GenericNew(ImportFrom_type
, NULL
, NULL
);
2463 if (!result
) goto failed
;
2464 value
= ast2obj_identifier(o
->v
.ImportFrom
.module
);
2465 if (!value
) goto failed
;
2466 if (PyObject_SetAttrString(result
, "module", value
) == -1)
2469 value
= ast2obj_list(o
->v
.ImportFrom
.names
, ast2obj_alias
);
2470 if (!value
) goto failed
;
2471 if (PyObject_SetAttrString(result
, "names", value
) == -1)
2474 value
= ast2obj_int(o
->v
.ImportFrom
.level
);
2475 if (!value
) goto failed
;
2476 if (PyObject_SetAttrString(result
, "level", value
) == -1)
2481 result
= PyType_GenericNew(Exec_type
, NULL
, NULL
);
2482 if (!result
) goto failed
;
2483 value
= ast2obj_expr(o
->v
.Exec
.body
);
2484 if (!value
) goto failed
;
2485 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2488 value
= ast2obj_expr(o
->v
.Exec
.globals
);
2489 if (!value
) goto failed
;
2490 if (PyObject_SetAttrString(result
, "globals", value
) == -1)
2493 value
= ast2obj_expr(o
->v
.Exec
.locals
);
2494 if (!value
) goto failed
;
2495 if (PyObject_SetAttrString(result
, "locals", value
) == -1)
2500 result
= PyType_GenericNew(Global_type
, NULL
, NULL
);
2501 if (!result
) goto failed
;
2502 value
= ast2obj_list(o
->v
.Global
.names
, ast2obj_identifier
);
2503 if (!value
) goto failed
;
2504 if (PyObject_SetAttrString(result
, "names", value
) == -1)
2509 result
= PyType_GenericNew(Expr_type
, NULL
, NULL
);
2510 if (!result
) goto failed
;
2511 value
= ast2obj_expr(o
->v
.Expr
.value
);
2512 if (!value
) goto failed
;
2513 if (PyObject_SetAttrString(result
, "value", value
) == -1)
2518 result
= PyType_GenericNew(Pass_type
, NULL
, NULL
);
2519 if (!result
) goto failed
;
2522 result
= PyType_GenericNew(Break_type
, NULL
, NULL
);
2523 if (!result
) goto failed
;
2526 result
= PyType_GenericNew(Continue_type
, NULL
, NULL
);
2527 if (!result
) goto failed
;
2530 value
= ast2obj_int(o
->lineno
);
2531 if (!value
) goto failed
;
2532 if (PyObject_SetAttrString(result
, "lineno", value
) < 0)
2535 value
= ast2obj_int(o
->col_offset
);
2536 if (!value
) goto failed
;
2537 if (PyObject_SetAttrString(result
, "col_offset", value
) < 0)
2548 ast2obj_expr(void* _o
)
2550 expr_ty o
= (expr_ty
)_o
;
2551 PyObject
*result
= NULL
, *value
= NULL
;
2559 result
= PyType_GenericNew(BoolOp_type
, NULL
, NULL
);
2560 if (!result
) goto failed
;
2561 value
= ast2obj_boolop(o
->v
.BoolOp
.op
);
2562 if (!value
) goto failed
;
2563 if (PyObject_SetAttrString(result
, "op", value
) == -1)
2566 value
= ast2obj_list(o
->v
.BoolOp
.values
, ast2obj_expr
);
2567 if (!value
) goto failed
;
2568 if (PyObject_SetAttrString(result
, "values", value
) == -1)
2573 result
= PyType_GenericNew(BinOp_type
, NULL
, NULL
);
2574 if (!result
) goto failed
;
2575 value
= ast2obj_expr(o
->v
.BinOp
.left
);
2576 if (!value
) goto failed
;
2577 if (PyObject_SetAttrString(result
, "left", value
) == -1)
2580 value
= ast2obj_operator(o
->v
.BinOp
.op
);
2581 if (!value
) goto failed
;
2582 if (PyObject_SetAttrString(result
, "op", value
) == -1)
2585 value
= ast2obj_expr(o
->v
.BinOp
.right
);
2586 if (!value
) goto failed
;
2587 if (PyObject_SetAttrString(result
, "right", value
) == -1)
2592 result
= PyType_GenericNew(UnaryOp_type
, NULL
, NULL
);
2593 if (!result
) goto failed
;
2594 value
= ast2obj_unaryop(o
->v
.UnaryOp
.op
);
2595 if (!value
) goto failed
;
2596 if (PyObject_SetAttrString(result
, "op", value
) == -1)
2599 value
= ast2obj_expr(o
->v
.UnaryOp
.operand
);
2600 if (!value
) goto failed
;
2601 if (PyObject_SetAttrString(result
, "operand", value
) == -1)
2606 result
= PyType_GenericNew(Lambda_type
, NULL
, NULL
);
2607 if (!result
) goto failed
;
2608 value
= ast2obj_arguments(o
->v
.Lambda
.args
);
2609 if (!value
) goto failed
;
2610 if (PyObject_SetAttrString(result
, "args", value
) == -1)
2613 value
= ast2obj_expr(o
->v
.Lambda
.body
);
2614 if (!value
) goto failed
;
2615 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2620 result
= PyType_GenericNew(IfExp_type
, NULL
, NULL
);
2621 if (!result
) goto failed
;
2622 value
= ast2obj_expr(o
->v
.IfExp
.test
);
2623 if (!value
) goto failed
;
2624 if (PyObject_SetAttrString(result
, "test", value
) == -1)
2627 value
= ast2obj_expr(o
->v
.IfExp
.body
);
2628 if (!value
) goto failed
;
2629 if (PyObject_SetAttrString(result
, "body", value
) == -1)
2632 value
= ast2obj_expr(o
->v
.IfExp
.orelse
);
2633 if (!value
) goto failed
;
2634 if (PyObject_SetAttrString(result
, "orelse", value
) == -1)
2639 result
= PyType_GenericNew(Dict_type
, NULL
, NULL
);
2640 if (!result
) goto failed
;
2641 value
= ast2obj_list(o
->v
.Dict
.keys
, ast2obj_expr
);
2642 if (!value
) goto failed
;
2643 if (PyObject_SetAttrString(result
, "keys", value
) == -1)
2646 value
= ast2obj_list(o
->v
.Dict
.values
, ast2obj_expr
);
2647 if (!value
) goto failed
;
2648 if (PyObject_SetAttrString(result
, "values", value
) == -1)
2653 result
= PyType_GenericNew(Set_type
, NULL
, NULL
);
2654 if (!result
) goto failed
;
2655 value
= ast2obj_list(o
->v
.Set
.elts
, ast2obj_expr
);
2656 if (!value
) goto failed
;
2657 if (PyObject_SetAttrString(result
, "elts", value
) == -1)
2662 result
= PyType_GenericNew(ListComp_type
, NULL
, NULL
);
2663 if (!result
) goto failed
;
2664 value
= ast2obj_expr(o
->v
.ListComp
.elt
);
2665 if (!value
) goto failed
;
2666 if (PyObject_SetAttrString(result
, "elt", value
) == -1)
2669 value
= ast2obj_list(o
->v
.ListComp
.generators
,
2670 ast2obj_comprehension
);
2671 if (!value
) goto failed
;
2672 if (PyObject_SetAttrString(result
, "generators", value
) == -1)
2677 result
= PyType_GenericNew(SetComp_type
, NULL
, NULL
);
2678 if (!result
) goto failed
;
2679 value
= ast2obj_expr(o
->v
.SetComp
.elt
);
2680 if (!value
) goto failed
;
2681 if (PyObject_SetAttrString(result
, "elt", value
) == -1)
2684 value
= ast2obj_list(o
->v
.SetComp
.generators
,
2685 ast2obj_comprehension
);
2686 if (!value
) goto failed
;
2687 if (PyObject_SetAttrString(result
, "generators", value
) == -1)
2692 result
= PyType_GenericNew(DictComp_type
, NULL
, NULL
);
2693 if (!result
) goto failed
;
2694 value
= ast2obj_expr(o
->v
.DictComp
.key
);
2695 if (!value
) goto failed
;
2696 if (PyObject_SetAttrString(result
, "key", value
) == -1)
2699 value
= ast2obj_expr(o
->v
.DictComp
.value
);
2700 if (!value
) goto failed
;
2701 if (PyObject_SetAttrString(result
, "value", value
) == -1)
2704 value
= ast2obj_list(o
->v
.DictComp
.generators
,
2705 ast2obj_comprehension
);
2706 if (!value
) goto failed
;
2707 if (PyObject_SetAttrString(result
, "generators", value
) == -1)
2711 case GeneratorExp_kind
:
2712 result
= PyType_GenericNew(GeneratorExp_type
, NULL
, NULL
);
2713 if (!result
) goto failed
;
2714 value
= ast2obj_expr(o
->v
.GeneratorExp
.elt
);
2715 if (!value
) goto failed
;
2716 if (PyObject_SetAttrString(result
, "elt", value
) == -1)
2719 value
= ast2obj_list(o
->v
.GeneratorExp
.generators
,
2720 ast2obj_comprehension
);
2721 if (!value
) goto failed
;
2722 if (PyObject_SetAttrString(result
, "generators", value
) == -1)
2727 result
= PyType_GenericNew(Yield_type
, NULL
, NULL
);
2728 if (!result
) goto failed
;
2729 value
= ast2obj_expr(o
->v
.Yield
.value
);
2730 if (!value
) goto failed
;
2731 if (PyObject_SetAttrString(result
, "value", value
) == -1)
2736 result
= PyType_GenericNew(Compare_type
, NULL
, NULL
);
2737 if (!result
) goto failed
;
2738 value
= ast2obj_expr(o
->v
.Compare
.left
);
2739 if (!value
) goto failed
;
2740 if (PyObject_SetAttrString(result
, "left", value
) == -1)
2744 int i
, n
= asdl_seq_LEN(o
->v
.Compare
.ops
);
2745 value
= PyList_New(n
);
2746 if (!value
) goto failed
;
2747 for(i
= 0; i
< n
; i
++)
2748 PyList_SET_ITEM(value
, i
, ast2obj_cmpop((cmpop_ty
)asdl_seq_GET(o
->v
.Compare
.ops
, i
)));
2750 if (!value
) goto failed
;
2751 if (PyObject_SetAttrString(result
, "ops", value
) == -1)
2754 value
= ast2obj_list(o
->v
.Compare
.comparators
, ast2obj_expr
);
2755 if (!value
) goto failed
;
2756 if (PyObject_SetAttrString(result
, "comparators", value
) == -1)
2761 result
= PyType_GenericNew(Call_type
, NULL
, NULL
);
2762 if (!result
) goto failed
;
2763 value
= ast2obj_expr(o
->v
.Call
.func
);
2764 if (!value
) goto failed
;
2765 if (PyObject_SetAttrString(result
, "func", value
) == -1)
2768 value
= ast2obj_list(o
->v
.Call
.args
, ast2obj_expr
);
2769 if (!value
) goto failed
;
2770 if (PyObject_SetAttrString(result
, "args", value
) == -1)
2773 value
= ast2obj_list(o
->v
.Call
.keywords
, ast2obj_keyword
);
2774 if (!value
) goto failed
;
2775 if (PyObject_SetAttrString(result
, "keywords", value
) == -1)
2778 value
= ast2obj_expr(o
->v
.Call
.starargs
);
2779 if (!value
) goto failed
;
2780 if (PyObject_SetAttrString(result
, "starargs", value
) == -1)
2783 value
= ast2obj_expr(o
->v
.Call
.kwargs
);
2784 if (!value
) goto failed
;
2785 if (PyObject_SetAttrString(result
, "kwargs", value
) == -1)
2790 result
= PyType_GenericNew(Repr_type
, NULL
, NULL
);
2791 if (!result
) goto failed
;
2792 value
= ast2obj_expr(o
->v
.Repr
.value
);
2793 if (!value
) goto failed
;
2794 if (PyObject_SetAttrString(result
, "value", value
) == -1)
2799 result
= PyType_GenericNew(Num_type
, NULL
, NULL
);
2800 if (!result
) goto failed
;
2801 value
= ast2obj_object(o
->v
.Num
.n
);
2802 if (!value
) goto failed
;
2803 if (PyObject_SetAttrString(result
, "n", value
) == -1)
2808 result
= PyType_GenericNew(Str_type
, NULL
, NULL
);
2809 if (!result
) goto failed
;
2810 value
= ast2obj_string(o
->v
.Str
.s
);
2811 if (!value
) goto failed
;
2812 if (PyObject_SetAttrString(result
, "s", value
) == -1)
2816 case Attribute_kind
:
2817 result
= PyType_GenericNew(Attribute_type
, NULL
, NULL
);
2818 if (!result
) goto failed
;
2819 value
= ast2obj_expr(o
->v
.Attribute
.value
);
2820 if (!value
) goto failed
;
2821 if (PyObject_SetAttrString(result
, "value", value
) == -1)
2824 value
= ast2obj_identifier(o
->v
.Attribute
.attr
);
2825 if (!value
) goto failed
;
2826 if (PyObject_SetAttrString(result
, "attr", value
) == -1)
2829 value
= ast2obj_expr_context(o
->v
.Attribute
.ctx
);
2830 if (!value
) goto failed
;
2831 if (PyObject_SetAttrString(result
, "ctx", value
) == -1)
2835 case Subscript_kind
:
2836 result
= PyType_GenericNew(Subscript_type
, NULL
, NULL
);
2837 if (!result
) goto failed
;
2838 value
= ast2obj_expr(o
->v
.Subscript
.value
);
2839 if (!value
) goto failed
;
2840 if (PyObject_SetAttrString(result
, "value", value
) == -1)
2843 value
= ast2obj_slice(o
->v
.Subscript
.slice
);
2844 if (!value
) goto failed
;
2845 if (PyObject_SetAttrString(result
, "slice", value
) == -1)
2848 value
= ast2obj_expr_context(o
->v
.Subscript
.ctx
);
2849 if (!value
) goto failed
;
2850 if (PyObject_SetAttrString(result
, "ctx", value
) == -1)
2855 result
= PyType_GenericNew(Name_type
, NULL
, NULL
);
2856 if (!result
) goto failed
;
2857 value
= ast2obj_identifier(o
->v
.Name
.id
);
2858 if (!value
) goto failed
;
2859 if (PyObject_SetAttrString(result
, "id", value
) == -1)
2862 value
= ast2obj_expr_context(o
->v
.Name
.ctx
);
2863 if (!value
) goto failed
;
2864 if (PyObject_SetAttrString(result
, "ctx", value
) == -1)
2869 result
= PyType_GenericNew(List_type
, NULL
, NULL
);
2870 if (!result
) goto failed
;
2871 value
= ast2obj_list(o
->v
.List
.elts
, ast2obj_expr
);
2872 if (!value
) goto failed
;
2873 if (PyObject_SetAttrString(result
, "elts", value
) == -1)
2876 value
= ast2obj_expr_context(o
->v
.List
.ctx
);
2877 if (!value
) goto failed
;
2878 if (PyObject_SetAttrString(result
, "ctx", value
) == -1)
2883 result
= PyType_GenericNew(Tuple_type
, NULL
, NULL
);
2884 if (!result
) goto failed
;
2885 value
= ast2obj_list(o
->v
.Tuple
.elts
, ast2obj_expr
);
2886 if (!value
) goto failed
;
2887 if (PyObject_SetAttrString(result
, "elts", value
) == -1)
2890 value
= ast2obj_expr_context(o
->v
.Tuple
.ctx
);
2891 if (!value
) goto failed
;
2892 if (PyObject_SetAttrString(result
, "ctx", value
) == -1)
2897 value
= ast2obj_int(o
->lineno
);
2898 if (!value
) goto failed
;
2899 if (PyObject_SetAttrString(result
, "lineno", value
) < 0)
2902 value
= ast2obj_int(o
->col_offset
);
2903 if (!value
) goto failed
;
2904 if (PyObject_SetAttrString(result
, "col_offset", value
) < 0)
2914 PyObject
* ast2obj_expr_context(expr_context_ty o
)
2918 Py_INCREF(Load_singleton
);
2919 return Load_singleton
;
2921 Py_INCREF(Store_singleton
);
2922 return Store_singleton
;
2924 Py_INCREF(Del_singleton
);
2925 return Del_singleton
;
2927 Py_INCREF(AugLoad_singleton
);
2928 return AugLoad_singleton
;
2930 Py_INCREF(AugStore_singleton
);
2931 return AugStore_singleton
;
2933 Py_INCREF(Param_singleton
);
2934 return Param_singleton
;
2936 /* should never happen, but just in case ... */
2937 PyErr_Format(PyExc_SystemError
, "unknown expr_context found");
2942 ast2obj_slice(void* _o
)
2944 slice_ty o
= (slice_ty
)_o
;
2945 PyObject
*result
= NULL
, *value
= NULL
;
2953 result
= PyType_GenericNew(Ellipsis_type
, NULL
, NULL
);
2954 if (!result
) goto failed
;
2957 result
= PyType_GenericNew(Slice_type
, NULL
, NULL
);
2958 if (!result
) goto failed
;
2959 value
= ast2obj_expr(o
->v
.Slice
.lower
);
2960 if (!value
) goto failed
;
2961 if (PyObject_SetAttrString(result
, "lower", value
) == -1)
2964 value
= ast2obj_expr(o
->v
.Slice
.upper
);
2965 if (!value
) goto failed
;
2966 if (PyObject_SetAttrString(result
, "upper", value
) == -1)
2969 value
= ast2obj_expr(o
->v
.Slice
.step
);
2970 if (!value
) goto failed
;
2971 if (PyObject_SetAttrString(result
, "step", value
) == -1)
2976 result
= PyType_GenericNew(ExtSlice_type
, NULL
, NULL
);
2977 if (!result
) goto failed
;
2978 value
= ast2obj_list(o
->v
.ExtSlice
.dims
, ast2obj_slice
);
2979 if (!value
) goto failed
;
2980 if (PyObject_SetAttrString(result
, "dims", value
) == -1)
2985 result
= PyType_GenericNew(Index_type
, NULL
, NULL
);
2986 if (!result
) goto failed
;
2987 value
= ast2obj_expr(o
->v
.Index
.value
);
2988 if (!value
) goto failed
;
2989 if (PyObject_SetAttrString(result
, "value", value
) == -1)
3001 PyObject
* ast2obj_boolop(boolop_ty o
)
3005 Py_INCREF(And_singleton
);
3006 return And_singleton
;
3008 Py_INCREF(Or_singleton
);
3009 return Or_singleton
;
3011 /* should never happen, but just in case ... */
3012 PyErr_Format(PyExc_SystemError
, "unknown boolop found");
3016 PyObject
* ast2obj_operator(operator_ty o
)
3020 Py_INCREF(Add_singleton
);
3021 return Add_singleton
;
3023 Py_INCREF(Sub_singleton
);
3024 return Sub_singleton
;
3026 Py_INCREF(Mult_singleton
);
3027 return Mult_singleton
;
3029 Py_INCREF(Div_singleton
);
3030 return Div_singleton
;
3032 Py_INCREF(Mod_singleton
);
3033 return Mod_singleton
;
3035 Py_INCREF(Pow_singleton
);
3036 return Pow_singleton
;
3038 Py_INCREF(LShift_singleton
);
3039 return LShift_singleton
;
3041 Py_INCREF(RShift_singleton
);
3042 return RShift_singleton
;
3044 Py_INCREF(BitOr_singleton
);
3045 return BitOr_singleton
;
3047 Py_INCREF(BitXor_singleton
);
3048 return BitXor_singleton
;
3050 Py_INCREF(BitAnd_singleton
);
3051 return BitAnd_singleton
;
3053 Py_INCREF(FloorDiv_singleton
);
3054 return FloorDiv_singleton
;
3056 /* should never happen, but just in case ... */
3057 PyErr_Format(PyExc_SystemError
, "unknown operator found");
3061 PyObject
* ast2obj_unaryop(unaryop_ty o
)
3065 Py_INCREF(Invert_singleton
);
3066 return Invert_singleton
;
3068 Py_INCREF(Not_singleton
);
3069 return Not_singleton
;
3071 Py_INCREF(UAdd_singleton
);
3072 return UAdd_singleton
;
3074 Py_INCREF(USub_singleton
);
3075 return USub_singleton
;
3077 /* should never happen, but just in case ... */
3078 PyErr_Format(PyExc_SystemError
, "unknown unaryop found");
3082 PyObject
* ast2obj_cmpop(cmpop_ty o
)
3086 Py_INCREF(Eq_singleton
);
3087 return Eq_singleton
;
3089 Py_INCREF(NotEq_singleton
);
3090 return NotEq_singleton
;
3092 Py_INCREF(Lt_singleton
);
3093 return Lt_singleton
;
3095 Py_INCREF(LtE_singleton
);
3096 return LtE_singleton
;
3098 Py_INCREF(Gt_singleton
);
3099 return Gt_singleton
;
3101 Py_INCREF(GtE_singleton
);
3102 return GtE_singleton
;
3104 Py_INCREF(Is_singleton
);
3105 return Is_singleton
;
3107 Py_INCREF(IsNot_singleton
);
3108 return IsNot_singleton
;
3110 Py_INCREF(In_singleton
);
3111 return In_singleton
;
3113 Py_INCREF(NotIn_singleton
);
3114 return NotIn_singleton
;
3116 /* should never happen, but just in case ... */
3117 PyErr_Format(PyExc_SystemError
, "unknown cmpop found");
3122 ast2obj_comprehension(void* _o
)
3124 comprehension_ty o
= (comprehension_ty
)_o
;
3125 PyObject
*result
= NULL
, *value
= NULL
;
3131 result
= PyType_GenericNew(comprehension_type
, NULL
, NULL
);
3132 if (!result
) return NULL
;
3133 value
= ast2obj_expr(o
->target
);
3134 if (!value
) goto failed
;
3135 if (PyObject_SetAttrString(result
, "target", value
) == -1)
3138 value
= ast2obj_expr(o
->iter
);
3139 if (!value
) goto failed
;
3140 if (PyObject_SetAttrString(result
, "iter", value
) == -1)
3143 value
= ast2obj_list(o
->ifs
, ast2obj_expr
);
3144 if (!value
) goto failed
;
3145 if (PyObject_SetAttrString(result
, "ifs", value
) == -1)
3156 ast2obj_excepthandler(void* _o
)
3158 excepthandler_ty o
= (excepthandler_ty
)_o
;
3159 PyObject
*result
= NULL
, *value
= NULL
;
3166 case ExceptHandler_kind
:
3167 result
= PyType_GenericNew(ExceptHandler_type
, NULL
, NULL
);
3168 if (!result
) goto failed
;
3169 value
= ast2obj_expr(o
->v
.ExceptHandler
.type
);
3170 if (!value
) goto failed
;
3171 if (PyObject_SetAttrString(result
, "type", value
) == -1)
3174 value
= ast2obj_expr(o
->v
.ExceptHandler
.name
);
3175 if (!value
) goto failed
;
3176 if (PyObject_SetAttrString(result
, "name", value
) == -1)
3179 value
= ast2obj_list(o
->v
.ExceptHandler
.body
, ast2obj_stmt
);
3180 if (!value
) goto failed
;
3181 if (PyObject_SetAttrString(result
, "body", value
) == -1)
3186 value
= ast2obj_int(o
->lineno
);
3187 if (!value
) goto failed
;
3188 if (PyObject_SetAttrString(result
, "lineno", value
) < 0)
3191 value
= ast2obj_int(o
->col_offset
);
3192 if (!value
) goto failed
;
3193 if (PyObject_SetAttrString(result
, "col_offset", value
) < 0)
3204 ast2obj_arguments(void* _o
)
3206 arguments_ty o
= (arguments_ty
)_o
;
3207 PyObject
*result
= NULL
, *value
= NULL
;
3213 result
= PyType_GenericNew(arguments_type
, NULL
, NULL
);
3214 if (!result
) return NULL
;
3215 value
= ast2obj_list(o
->args
, ast2obj_expr
);
3216 if (!value
) goto failed
;
3217 if (PyObject_SetAttrString(result
, "args", value
) == -1)
3220 value
= ast2obj_identifier(o
->vararg
);
3221 if (!value
) goto failed
;
3222 if (PyObject_SetAttrString(result
, "vararg", value
) == -1)
3225 value
= ast2obj_identifier(o
->kwarg
);
3226 if (!value
) goto failed
;
3227 if (PyObject_SetAttrString(result
, "kwarg", value
) == -1)
3230 value
= ast2obj_list(o
->defaults
, ast2obj_expr
);
3231 if (!value
) goto failed
;
3232 if (PyObject_SetAttrString(result
, "defaults", value
) == -1)
3243 ast2obj_keyword(void* _o
)
3245 keyword_ty o
= (keyword_ty
)_o
;
3246 PyObject
*result
= NULL
, *value
= NULL
;
3252 result
= PyType_GenericNew(keyword_type
, NULL
, NULL
);
3253 if (!result
) return NULL
;
3254 value
= ast2obj_identifier(o
->arg
);
3255 if (!value
) goto failed
;
3256 if (PyObject_SetAttrString(result
, "arg", value
) == -1)
3259 value
= ast2obj_expr(o
->value
);
3260 if (!value
) goto failed
;
3261 if (PyObject_SetAttrString(result
, "value", value
) == -1)
3272 ast2obj_alias(void* _o
)
3274 alias_ty o
= (alias_ty
)_o
;
3275 PyObject
*result
= NULL
, *value
= NULL
;
3281 result
= PyType_GenericNew(alias_type
, NULL
, NULL
);
3282 if (!result
) return NULL
;
3283 value
= ast2obj_identifier(o
->name
);
3284 if (!value
) goto failed
;
3285 if (PyObject_SetAttrString(result
, "name", value
) == -1)
3288 value
= ast2obj_identifier(o
->asname
);
3289 if (!value
) goto failed
;
3290 if (PyObject_SetAttrString(result
, "asname", value
) == -1)
3302 obj2ast_mod(PyObject
* obj
, mod_ty
* out
, PyArena
* arena
)
3304 PyObject
* tmp
= NULL
;
3308 if (obj
== Py_None
) {
3312 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Module_type
);
3313 if (isinstance
== -1) {
3319 if (PyObject_HasAttrString(obj
, "body")) {
3323 tmp
= PyObject_GetAttrString(obj
, "body");
3324 if (tmp
== NULL
) goto failed
;
3325 if (!PyList_Check(tmp
)) {
3326 PyErr_Format(PyExc_TypeError
, "Module field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3329 len
= PyList_GET_SIZE(tmp
);
3330 body
= asdl_seq_new(len
, arena
);
3331 if (body
== NULL
) goto failed
;
3332 for (i
= 0; i
< len
; i
++) {
3334 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3335 if (res
!= 0) goto failed
;
3336 asdl_seq_SET(body
, i
, value
);
3341 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from Module");
3344 *out
= Module(body
, arena
);
3345 if (*out
== NULL
) goto failed
;
3348 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Interactive_type
);
3349 if (isinstance
== -1) {
3355 if (PyObject_HasAttrString(obj
, "body")) {
3359 tmp
= PyObject_GetAttrString(obj
, "body");
3360 if (tmp
== NULL
) goto failed
;
3361 if (!PyList_Check(tmp
)) {
3362 PyErr_Format(PyExc_TypeError
, "Interactive field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3365 len
= PyList_GET_SIZE(tmp
);
3366 body
= asdl_seq_new(len
, arena
);
3367 if (body
== NULL
) goto failed
;
3368 for (i
= 0; i
< len
; i
++) {
3370 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3371 if (res
!= 0) goto failed
;
3372 asdl_seq_SET(body
, i
, value
);
3377 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from Interactive");
3380 *out
= Interactive(body
, arena
);
3381 if (*out
== NULL
) goto failed
;
3384 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Expression_type
);
3385 if (isinstance
== -1) {
3391 if (PyObject_HasAttrString(obj
, "body")) {
3393 tmp
= PyObject_GetAttrString(obj
, "body");
3394 if (tmp
== NULL
) goto failed
;
3395 res
= obj2ast_expr(tmp
, &body
, arena
);
3396 if (res
!= 0) goto failed
;
3400 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from Expression");
3403 *out
= Expression(body
, arena
);
3404 if (*out
== NULL
) goto failed
;
3407 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Suite_type
);
3408 if (isinstance
== -1) {
3414 if (PyObject_HasAttrString(obj
, "body")) {
3418 tmp
= PyObject_GetAttrString(obj
, "body");
3419 if (tmp
== NULL
) goto failed
;
3420 if (!PyList_Check(tmp
)) {
3421 PyErr_Format(PyExc_TypeError
, "Suite field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3424 len
= PyList_GET_SIZE(tmp
);
3425 body
= asdl_seq_new(len
, arena
);
3426 if (body
== NULL
) goto failed
;
3427 for (i
= 0; i
< len
; i
++) {
3429 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3430 if (res
!= 0) goto failed
;
3431 asdl_seq_SET(body
, i
, value
);
3436 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from Suite");
3439 *out
= Suite(body
, arena
);
3440 if (*out
== NULL
) goto failed
;
3444 tmp
= PyObject_Repr(obj
);
3445 if (tmp
== NULL
) goto failed
;
3446 PyErr_Format(PyExc_TypeError
, "expected some sort of mod, but got %.400s", PyString_AS_STRING(tmp
));
3453 obj2ast_stmt(PyObject
* obj
, stmt_ty
* out
, PyArena
* arena
)
3455 PyObject
* tmp
= NULL
;
3461 if (obj
== Py_None
) {
3465 if (PyObject_HasAttrString(obj
, "lineno")) {
3467 tmp
= PyObject_GetAttrString(obj
, "lineno");
3468 if (tmp
== NULL
) goto failed
;
3469 res
= obj2ast_int(tmp
, &lineno
, arena
);
3470 if (res
!= 0) goto failed
;
3474 PyErr_SetString(PyExc_TypeError
, "required field \"lineno\" missing from stmt");
3477 if (PyObject_HasAttrString(obj
, "col_offset")) {
3479 tmp
= PyObject_GetAttrString(obj
, "col_offset");
3480 if (tmp
== NULL
) goto failed
;
3481 res
= obj2ast_int(tmp
, &col_offset
, arena
);
3482 if (res
!= 0) goto failed
;
3486 PyErr_SetString(PyExc_TypeError
, "required field \"col_offset\" missing from stmt");
3489 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)FunctionDef_type
);
3490 if (isinstance
== -1) {
3497 asdl_seq
* decorator_list
;
3499 if (PyObject_HasAttrString(obj
, "name")) {
3501 tmp
= PyObject_GetAttrString(obj
, "name");
3502 if (tmp
== NULL
) goto failed
;
3503 res
= obj2ast_identifier(tmp
, &name
, arena
);
3504 if (res
!= 0) goto failed
;
3508 PyErr_SetString(PyExc_TypeError
, "required field \"name\" missing from FunctionDef");
3511 if (PyObject_HasAttrString(obj
, "args")) {
3513 tmp
= PyObject_GetAttrString(obj
, "args");
3514 if (tmp
== NULL
) goto failed
;
3515 res
= obj2ast_arguments(tmp
, &args
, arena
);
3516 if (res
!= 0) goto failed
;
3520 PyErr_SetString(PyExc_TypeError
, "required field \"args\" missing from FunctionDef");
3523 if (PyObject_HasAttrString(obj
, "body")) {
3527 tmp
= PyObject_GetAttrString(obj
, "body");
3528 if (tmp
== NULL
) goto failed
;
3529 if (!PyList_Check(tmp
)) {
3530 PyErr_Format(PyExc_TypeError
, "FunctionDef field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3533 len
= PyList_GET_SIZE(tmp
);
3534 body
= asdl_seq_new(len
, arena
);
3535 if (body
== NULL
) goto failed
;
3536 for (i
= 0; i
< len
; i
++) {
3538 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3539 if (res
!= 0) goto failed
;
3540 asdl_seq_SET(body
, i
, value
);
3545 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from FunctionDef");
3548 if (PyObject_HasAttrString(obj
, "decorator_list")) {
3552 tmp
= PyObject_GetAttrString(obj
, "decorator_list");
3553 if (tmp
== NULL
) goto failed
;
3554 if (!PyList_Check(tmp
)) {
3555 PyErr_Format(PyExc_TypeError
, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3558 len
= PyList_GET_SIZE(tmp
);
3559 decorator_list
= asdl_seq_new(len
, arena
);
3560 if (decorator_list
== NULL
) goto failed
;
3561 for (i
= 0; i
< len
; i
++) {
3563 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3564 if (res
!= 0) goto failed
;
3565 asdl_seq_SET(decorator_list
, i
, value
);
3570 PyErr_SetString(PyExc_TypeError
, "required field \"decorator_list\" missing from FunctionDef");
3573 *out
= FunctionDef(name
, args
, body
, decorator_list
, lineno
,
3575 if (*out
== NULL
) goto failed
;
3578 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)ClassDef_type
);
3579 if (isinstance
== -1) {
3586 asdl_seq
* decorator_list
;
3588 if (PyObject_HasAttrString(obj
, "name")) {
3590 tmp
= PyObject_GetAttrString(obj
, "name");
3591 if (tmp
== NULL
) goto failed
;
3592 res
= obj2ast_identifier(tmp
, &name
, arena
);
3593 if (res
!= 0) goto failed
;
3597 PyErr_SetString(PyExc_TypeError
, "required field \"name\" missing from ClassDef");
3600 if (PyObject_HasAttrString(obj
, "bases")) {
3604 tmp
= PyObject_GetAttrString(obj
, "bases");
3605 if (tmp
== NULL
) goto failed
;
3606 if (!PyList_Check(tmp
)) {
3607 PyErr_Format(PyExc_TypeError
, "ClassDef field \"bases\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3610 len
= PyList_GET_SIZE(tmp
);
3611 bases
= asdl_seq_new(len
, arena
);
3612 if (bases
== NULL
) goto failed
;
3613 for (i
= 0; i
< len
; i
++) {
3615 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3616 if (res
!= 0) goto failed
;
3617 asdl_seq_SET(bases
, i
, value
);
3622 PyErr_SetString(PyExc_TypeError
, "required field \"bases\" missing from ClassDef");
3625 if (PyObject_HasAttrString(obj
, "body")) {
3629 tmp
= PyObject_GetAttrString(obj
, "body");
3630 if (tmp
== NULL
) goto failed
;
3631 if (!PyList_Check(tmp
)) {
3632 PyErr_Format(PyExc_TypeError
, "ClassDef field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3635 len
= PyList_GET_SIZE(tmp
);
3636 body
= asdl_seq_new(len
, arena
);
3637 if (body
== NULL
) goto failed
;
3638 for (i
= 0; i
< len
; i
++) {
3640 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3641 if (res
!= 0) goto failed
;
3642 asdl_seq_SET(body
, i
, value
);
3647 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from ClassDef");
3650 if (PyObject_HasAttrString(obj
, "decorator_list")) {
3654 tmp
= PyObject_GetAttrString(obj
, "decorator_list");
3655 if (tmp
== NULL
) goto failed
;
3656 if (!PyList_Check(tmp
)) {
3657 PyErr_Format(PyExc_TypeError
, "ClassDef field \"decorator_list\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3660 len
= PyList_GET_SIZE(tmp
);
3661 decorator_list
= asdl_seq_new(len
, arena
);
3662 if (decorator_list
== NULL
) goto failed
;
3663 for (i
= 0; i
< len
; i
++) {
3665 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3666 if (res
!= 0) goto failed
;
3667 asdl_seq_SET(decorator_list
, i
, value
);
3672 PyErr_SetString(PyExc_TypeError
, "required field \"decorator_list\" missing from ClassDef");
3675 *out
= ClassDef(name
, bases
, body
, decorator_list
, lineno
,
3677 if (*out
== NULL
) goto failed
;
3680 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Return_type
);
3681 if (isinstance
== -1) {
3687 if (PyObject_HasAttrString(obj
, "value")) {
3689 tmp
= PyObject_GetAttrString(obj
, "value");
3690 if (tmp
== NULL
) goto failed
;
3691 res
= obj2ast_expr(tmp
, &value
, arena
);
3692 if (res
!= 0) goto failed
;
3698 *out
= Return(value
, lineno
, col_offset
, arena
);
3699 if (*out
== NULL
) goto failed
;
3702 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Delete_type
);
3703 if (isinstance
== -1) {
3709 if (PyObject_HasAttrString(obj
, "targets")) {
3713 tmp
= PyObject_GetAttrString(obj
, "targets");
3714 if (tmp
== NULL
) goto failed
;
3715 if (!PyList_Check(tmp
)) {
3716 PyErr_Format(PyExc_TypeError
, "Delete field \"targets\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3719 len
= PyList_GET_SIZE(tmp
);
3720 targets
= asdl_seq_new(len
, arena
);
3721 if (targets
== NULL
) goto failed
;
3722 for (i
= 0; i
< len
; i
++) {
3724 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3725 if (res
!= 0) goto failed
;
3726 asdl_seq_SET(targets
, i
, value
);
3731 PyErr_SetString(PyExc_TypeError
, "required field \"targets\" missing from Delete");
3734 *out
= Delete(targets
, lineno
, col_offset
, arena
);
3735 if (*out
== NULL
) goto failed
;
3738 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Assign_type
);
3739 if (isinstance
== -1) {
3746 if (PyObject_HasAttrString(obj
, "targets")) {
3750 tmp
= PyObject_GetAttrString(obj
, "targets");
3751 if (tmp
== NULL
) goto failed
;
3752 if (!PyList_Check(tmp
)) {
3753 PyErr_Format(PyExc_TypeError
, "Assign field \"targets\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3756 len
= PyList_GET_SIZE(tmp
);
3757 targets
= asdl_seq_new(len
, arena
);
3758 if (targets
== NULL
) goto failed
;
3759 for (i
= 0; i
< len
; i
++) {
3761 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3762 if (res
!= 0) goto failed
;
3763 asdl_seq_SET(targets
, i
, value
);
3768 PyErr_SetString(PyExc_TypeError
, "required field \"targets\" missing from Assign");
3771 if (PyObject_HasAttrString(obj
, "value")) {
3773 tmp
= PyObject_GetAttrString(obj
, "value");
3774 if (tmp
== NULL
) goto failed
;
3775 res
= obj2ast_expr(tmp
, &value
, arena
);
3776 if (res
!= 0) goto failed
;
3780 PyErr_SetString(PyExc_TypeError
, "required field \"value\" missing from Assign");
3783 *out
= Assign(targets
, value
, lineno
, col_offset
, arena
);
3784 if (*out
== NULL
) goto failed
;
3787 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)AugAssign_type
);
3788 if (isinstance
== -1) {
3796 if (PyObject_HasAttrString(obj
, "target")) {
3798 tmp
= PyObject_GetAttrString(obj
, "target");
3799 if (tmp
== NULL
) goto failed
;
3800 res
= obj2ast_expr(tmp
, &target
, arena
);
3801 if (res
!= 0) goto failed
;
3805 PyErr_SetString(PyExc_TypeError
, "required field \"target\" missing from AugAssign");
3808 if (PyObject_HasAttrString(obj
, "op")) {
3810 tmp
= PyObject_GetAttrString(obj
, "op");
3811 if (tmp
== NULL
) goto failed
;
3812 res
= obj2ast_operator(tmp
, &op
, arena
);
3813 if (res
!= 0) goto failed
;
3817 PyErr_SetString(PyExc_TypeError
, "required field \"op\" missing from AugAssign");
3820 if (PyObject_HasAttrString(obj
, "value")) {
3822 tmp
= PyObject_GetAttrString(obj
, "value");
3823 if (tmp
== NULL
) goto failed
;
3824 res
= obj2ast_expr(tmp
, &value
, arena
);
3825 if (res
!= 0) goto failed
;
3829 PyErr_SetString(PyExc_TypeError
, "required field \"value\" missing from AugAssign");
3832 *out
= AugAssign(target
, op
, value
, lineno
, col_offset
, arena
);
3833 if (*out
== NULL
) goto failed
;
3836 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Print_type
);
3837 if (isinstance
== -1) {
3845 if (PyObject_HasAttrString(obj
, "dest")) {
3847 tmp
= PyObject_GetAttrString(obj
, "dest");
3848 if (tmp
== NULL
) goto failed
;
3849 res
= obj2ast_expr(tmp
, &dest
, arena
);
3850 if (res
!= 0) goto failed
;
3856 if (PyObject_HasAttrString(obj
, "values")) {
3860 tmp
= PyObject_GetAttrString(obj
, "values");
3861 if (tmp
== NULL
) goto failed
;
3862 if (!PyList_Check(tmp
)) {
3863 PyErr_Format(PyExc_TypeError
, "Print field \"values\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3866 len
= PyList_GET_SIZE(tmp
);
3867 values
= asdl_seq_new(len
, arena
);
3868 if (values
== NULL
) goto failed
;
3869 for (i
= 0; i
< len
; i
++) {
3871 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3872 if (res
!= 0) goto failed
;
3873 asdl_seq_SET(values
, i
, value
);
3878 PyErr_SetString(PyExc_TypeError
, "required field \"values\" missing from Print");
3881 if (PyObject_HasAttrString(obj
, "nl")) {
3883 tmp
= PyObject_GetAttrString(obj
, "nl");
3884 if (tmp
== NULL
) goto failed
;
3885 res
= obj2ast_bool(tmp
, &nl
, arena
);
3886 if (res
!= 0) goto failed
;
3890 PyErr_SetString(PyExc_TypeError
, "required field \"nl\" missing from Print");
3893 *out
= Print(dest
, values
, nl
, lineno
, col_offset
, arena
);
3894 if (*out
== NULL
) goto failed
;
3897 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)For_type
);
3898 if (isinstance
== -1) {
3907 if (PyObject_HasAttrString(obj
, "target")) {
3909 tmp
= PyObject_GetAttrString(obj
, "target");
3910 if (tmp
== NULL
) goto failed
;
3911 res
= obj2ast_expr(tmp
, &target
, arena
);
3912 if (res
!= 0) goto failed
;
3916 PyErr_SetString(PyExc_TypeError
, "required field \"target\" missing from For");
3919 if (PyObject_HasAttrString(obj
, "iter")) {
3921 tmp
= PyObject_GetAttrString(obj
, "iter");
3922 if (tmp
== NULL
) goto failed
;
3923 res
= obj2ast_expr(tmp
, &iter
, arena
);
3924 if (res
!= 0) goto failed
;
3928 PyErr_SetString(PyExc_TypeError
, "required field \"iter\" missing from For");
3931 if (PyObject_HasAttrString(obj
, "body")) {
3935 tmp
= PyObject_GetAttrString(obj
, "body");
3936 if (tmp
== NULL
) goto failed
;
3937 if (!PyList_Check(tmp
)) {
3938 PyErr_Format(PyExc_TypeError
, "For field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3941 len
= PyList_GET_SIZE(tmp
);
3942 body
= asdl_seq_new(len
, arena
);
3943 if (body
== NULL
) goto failed
;
3944 for (i
= 0; i
< len
; i
++) {
3946 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3947 if (res
!= 0) goto failed
;
3948 asdl_seq_SET(body
, i
, value
);
3953 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from For");
3956 if (PyObject_HasAttrString(obj
, "orelse")) {
3960 tmp
= PyObject_GetAttrString(obj
, "orelse");
3961 if (tmp
== NULL
) goto failed
;
3962 if (!PyList_Check(tmp
)) {
3963 PyErr_Format(PyExc_TypeError
, "For field \"orelse\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
3966 len
= PyList_GET_SIZE(tmp
);
3967 orelse
= asdl_seq_new(len
, arena
);
3968 if (orelse
== NULL
) goto failed
;
3969 for (i
= 0; i
< len
; i
++) {
3971 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
3972 if (res
!= 0) goto failed
;
3973 asdl_seq_SET(orelse
, i
, value
);
3978 PyErr_SetString(PyExc_TypeError
, "required field \"orelse\" missing from For");
3981 *out
= For(target
, iter
, body
, orelse
, lineno
, col_offset
,
3983 if (*out
== NULL
) goto failed
;
3986 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)While_type
);
3987 if (isinstance
== -1) {
3995 if (PyObject_HasAttrString(obj
, "test")) {
3997 tmp
= PyObject_GetAttrString(obj
, "test");
3998 if (tmp
== NULL
) goto failed
;
3999 res
= obj2ast_expr(tmp
, &test
, arena
);
4000 if (res
!= 0) goto failed
;
4004 PyErr_SetString(PyExc_TypeError
, "required field \"test\" missing from While");
4007 if (PyObject_HasAttrString(obj
, "body")) {
4011 tmp
= PyObject_GetAttrString(obj
, "body");
4012 if (tmp
== NULL
) goto failed
;
4013 if (!PyList_Check(tmp
)) {
4014 PyErr_Format(PyExc_TypeError
, "While field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4017 len
= PyList_GET_SIZE(tmp
);
4018 body
= asdl_seq_new(len
, arena
);
4019 if (body
== NULL
) goto failed
;
4020 for (i
= 0; i
< len
; i
++) {
4022 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4023 if (res
!= 0) goto failed
;
4024 asdl_seq_SET(body
, i
, value
);
4029 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from While");
4032 if (PyObject_HasAttrString(obj
, "orelse")) {
4036 tmp
= PyObject_GetAttrString(obj
, "orelse");
4037 if (tmp
== NULL
) goto failed
;
4038 if (!PyList_Check(tmp
)) {
4039 PyErr_Format(PyExc_TypeError
, "While field \"orelse\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4042 len
= PyList_GET_SIZE(tmp
);
4043 orelse
= asdl_seq_new(len
, arena
);
4044 if (orelse
== NULL
) goto failed
;
4045 for (i
= 0; i
< len
; i
++) {
4047 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4048 if (res
!= 0) goto failed
;
4049 asdl_seq_SET(orelse
, i
, value
);
4054 PyErr_SetString(PyExc_TypeError
, "required field \"orelse\" missing from While");
4057 *out
= While(test
, body
, orelse
, lineno
, col_offset
, arena
);
4058 if (*out
== NULL
) goto failed
;
4061 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)If_type
);
4062 if (isinstance
== -1) {
4070 if (PyObject_HasAttrString(obj
, "test")) {
4072 tmp
= PyObject_GetAttrString(obj
, "test");
4073 if (tmp
== NULL
) goto failed
;
4074 res
= obj2ast_expr(tmp
, &test
, arena
);
4075 if (res
!= 0) goto failed
;
4079 PyErr_SetString(PyExc_TypeError
, "required field \"test\" missing from If");
4082 if (PyObject_HasAttrString(obj
, "body")) {
4086 tmp
= PyObject_GetAttrString(obj
, "body");
4087 if (tmp
== NULL
) goto failed
;
4088 if (!PyList_Check(tmp
)) {
4089 PyErr_Format(PyExc_TypeError
, "If field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4092 len
= PyList_GET_SIZE(tmp
);
4093 body
= asdl_seq_new(len
, arena
);
4094 if (body
== NULL
) goto failed
;
4095 for (i
= 0; i
< len
; i
++) {
4097 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4098 if (res
!= 0) goto failed
;
4099 asdl_seq_SET(body
, i
, value
);
4104 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from If");
4107 if (PyObject_HasAttrString(obj
, "orelse")) {
4111 tmp
= PyObject_GetAttrString(obj
, "orelse");
4112 if (tmp
== NULL
) goto failed
;
4113 if (!PyList_Check(tmp
)) {
4114 PyErr_Format(PyExc_TypeError
, "If field \"orelse\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4117 len
= PyList_GET_SIZE(tmp
);
4118 orelse
= asdl_seq_new(len
, arena
);
4119 if (orelse
== NULL
) goto failed
;
4120 for (i
= 0; i
< len
; i
++) {
4122 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4123 if (res
!= 0) goto failed
;
4124 asdl_seq_SET(orelse
, i
, value
);
4129 PyErr_SetString(PyExc_TypeError
, "required field \"orelse\" missing from If");
4132 *out
= If(test
, body
, orelse
, lineno
, col_offset
, arena
);
4133 if (*out
== NULL
) goto failed
;
4136 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)With_type
);
4137 if (isinstance
== -1) {
4141 expr_ty context_expr
;
4142 expr_ty optional_vars
;
4145 if (PyObject_HasAttrString(obj
, "context_expr")) {
4147 tmp
= PyObject_GetAttrString(obj
, "context_expr");
4148 if (tmp
== NULL
) goto failed
;
4149 res
= obj2ast_expr(tmp
, &context_expr
, arena
);
4150 if (res
!= 0) goto failed
;
4154 PyErr_SetString(PyExc_TypeError
, "required field \"context_expr\" missing from With");
4157 if (PyObject_HasAttrString(obj
, "optional_vars")) {
4159 tmp
= PyObject_GetAttrString(obj
, "optional_vars");
4160 if (tmp
== NULL
) goto failed
;
4161 res
= obj2ast_expr(tmp
, &optional_vars
, arena
);
4162 if (res
!= 0) goto failed
;
4166 optional_vars
= NULL
;
4168 if (PyObject_HasAttrString(obj
, "body")) {
4172 tmp
= PyObject_GetAttrString(obj
, "body");
4173 if (tmp
== NULL
) goto failed
;
4174 if (!PyList_Check(tmp
)) {
4175 PyErr_Format(PyExc_TypeError
, "With field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4178 len
= PyList_GET_SIZE(tmp
);
4179 body
= asdl_seq_new(len
, arena
);
4180 if (body
== NULL
) goto failed
;
4181 for (i
= 0; i
< len
; i
++) {
4183 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4184 if (res
!= 0) goto failed
;
4185 asdl_seq_SET(body
, i
, value
);
4190 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from With");
4193 *out
= With(context_expr
, optional_vars
, body
, lineno
,
4195 if (*out
== NULL
) goto failed
;
4198 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Raise_type
);
4199 if (isinstance
== -1) {
4207 if (PyObject_HasAttrString(obj
, "type")) {
4209 tmp
= PyObject_GetAttrString(obj
, "type");
4210 if (tmp
== NULL
) goto failed
;
4211 res
= obj2ast_expr(tmp
, &type
, arena
);
4212 if (res
!= 0) goto failed
;
4218 if (PyObject_HasAttrString(obj
, "inst")) {
4220 tmp
= PyObject_GetAttrString(obj
, "inst");
4221 if (tmp
== NULL
) goto failed
;
4222 res
= obj2ast_expr(tmp
, &inst
, arena
);
4223 if (res
!= 0) goto failed
;
4229 if (PyObject_HasAttrString(obj
, "tback")) {
4231 tmp
= PyObject_GetAttrString(obj
, "tback");
4232 if (tmp
== NULL
) goto failed
;
4233 res
= obj2ast_expr(tmp
, &tback
, arena
);
4234 if (res
!= 0) goto failed
;
4240 *out
= Raise(type
, inst
, tback
, lineno
, col_offset
, arena
);
4241 if (*out
== NULL
) goto failed
;
4244 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)TryExcept_type
);
4245 if (isinstance
== -1) {
4253 if (PyObject_HasAttrString(obj
, "body")) {
4257 tmp
= PyObject_GetAttrString(obj
, "body");
4258 if (tmp
== NULL
) goto failed
;
4259 if (!PyList_Check(tmp
)) {
4260 PyErr_Format(PyExc_TypeError
, "TryExcept field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4263 len
= PyList_GET_SIZE(tmp
);
4264 body
= asdl_seq_new(len
, arena
);
4265 if (body
== NULL
) goto failed
;
4266 for (i
= 0; i
< len
; i
++) {
4268 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4269 if (res
!= 0) goto failed
;
4270 asdl_seq_SET(body
, i
, value
);
4275 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from TryExcept");
4278 if (PyObject_HasAttrString(obj
, "handlers")) {
4282 tmp
= PyObject_GetAttrString(obj
, "handlers");
4283 if (tmp
== NULL
) goto failed
;
4284 if (!PyList_Check(tmp
)) {
4285 PyErr_Format(PyExc_TypeError
, "TryExcept field \"handlers\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4288 len
= PyList_GET_SIZE(tmp
);
4289 handlers
= asdl_seq_new(len
, arena
);
4290 if (handlers
== NULL
) goto failed
;
4291 for (i
= 0; i
< len
; i
++) {
4292 excepthandler_ty value
;
4293 res
= obj2ast_excepthandler(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4294 if (res
!= 0) goto failed
;
4295 asdl_seq_SET(handlers
, i
, value
);
4300 PyErr_SetString(PyExc_TypeError
, "required field \"handlers\" missing from TryExcept");
4303 if (PyObject_HasAttrString(obj
, "orelse")) {
4307 tmp
= PyObject_GetAttrString(obj
, "orelse");
4308 if (tmp
== NULL
) goto failed
;
4309 if (!PyList_Check(tmp
)) {
4310 PyErr_Format(PyExc_TypeError
, "TryExcept field \"orelse\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4313 len
= PyList_GET_SIZE(tmp
);
4314 orelse
= asdl_seq_new(len
, arena
);
4315 if (orelse
== NULL
) goto failed
;
4316 for (i
= 0; i
< len
; i
++) {
4318 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4319 if (res
!= 0) goto failed
;
4320 asdl_seq_SET(orelse
, i
, value
);
4325 PyErr_SetString(PyExc_TypeError
, "required field \"orelse\" missing from TryExcept");
4328 *out
= TryExcept(body
, handlers
, orelse
, lineno
, col_offset
,
4330 if (*out
== NULL
) goto failed
;
4333 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)TryFinally_type
);
4334 if (isinstance
== -1) {
4339 asdl_seq
* finalbody
;
4341 if (PyObject_HasAttrString(obj
, "body")) {
4345 tmp
= PyObject_GetAttrString(obj
, "body");
4346 if (tmp
== NULL
) goto failed
;
4347 if (!PyList_Check(tmp
)) {
4348 PyErr_Format(PyExc_TypeError
, "TryFinally field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4351 len
= PyList_GET_SIZE(tmp
);
4352 body
= asdl_seq_new(len
, arena
);
4353 if (body
== NULL
) goto failed
;
4354 for (i
= 0; i
< len
; i
++) {
4356 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4357 if (res
!= 0) goto failed
;
4358 asdl_seq_SET(body
, i
, value
);
4363 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from TryFinally");
4366 if (PyObject_HasAttrString(obj
, "finalbody")) {
4370 tmp
= PyObject_GetAttrString(obj
, "finalbody");
4371 if (tmp
== NULL
) goto failed
;
4372 if (!PyList_Check(tmp
)) {
4373 PyErr_Format(PyExc_TypeError
, "TryFinally field \"finalbody\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4376 len
= PyList_GET_SIZE(tmp
);
4377 finalbody
= asdl_seq_new(len
, arena
);
4378 if (finalbody
== NULL
) goto failed
;
4379 for (i
= 0; i
< len
; i
++) {
4381 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4382 if (res
!= 0) goto failed
;
4383 asdl_seq_SET(finalbody
, i
, value
);
4388 PyErr_SetString(PyExc_TypeError
, "required field \"finalbody\" missing from TryFinally");
4391 *out
= TryFinally(body
, finalbody
, lineno
, col_offset
, arena
);
4392 if (*out
== NULL
) goto failed
;
4395 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Assert_type
);
4396 if (isinstance
== -1) {
4403 if (PyObject_HasAttrString(obj
, "test")) {
4405 tmp
= PyObject_GetAttrString(obj
, "test");
4406 if (tmp
== NULL
) goto failed
;
4407 res
= obj2ast_expr(tmp
, &test
, arena
);
4408 if (res
!= 0) goto failed
;
4412 PyErr_SetString(PyExc_TypeError
, "required field \"test\" missing from Assert");
4415 if (PyObject_HasAttrString(obj
, "msg")) {
4417 tmp
= PyObject_GetAttrString(obj
, "msg");
4418 if (tmp
== NULL
) goto failed
;
4419 res
= obj2ast_expr(tmp
, &msg
, arena
);
4420 if (res
!= 0) goto failed
;
4426 *out
= Assert(test
, msg
, lineno
, col_offset
, arena
);
4427 if (*out
== NULL
) goto failed
;
4430 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Import_type
);
4431 if (isinstance
== -1) {
4437 if (PyObject_HasAttrString(obj
, "names")) {
4441 tmp
= PyObject_GetAttrString(obj
, "names");
4442 if (tmp
== NULL
) goto failed
;
4443 if (!PyList_Check(tmp
)) {
4444 PyErr_Format(PyExc_TypeError
, "Import field \"names\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4447 len
= PyList_GET_SIZE(tmp
);
4448 names
= asdl_seq_new(len
, arena
);
4449 if (names
== NULL
) goto failed
;
4450 for (i
= 0; i
< len
; i
++) {
4452 res
= obj2ast_alias(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4453 if (res
!= 0) goto failed
;
4454 asdl_seq_SET(names
, i
, value
);
4459 PyErr_SetString(PyExc_TypeError
, "required field \"names\" missing from Import");
4462 *out
= Import(names
, lineno
, col_offset
, arena
);
4463 if (*out
== NULL
) goto failed
;
4466 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)ImportFrom_type
);
4467 if (isinstance
== -1) {
4475 if (PyObject_HasAttrString(obj
, "module")) {
4477 tmp
= PyObject_GetAttrString(obj
, "module");
4478 if (tmp
== NULL
) goto failed
;
4479 res
= obj2ast_identifier(tmp
, &module
, arena
);
4480 if (res
!= 0) goto failed
;
4486 if (PyObject_HasAttrString(obj
, "names")) {
4490 tmp
= PyObject_GetAttrString(obj
, "names");
4491 if (tmp
== NULL
) goto failed
;
4492 if (!PyList_Check(tmp
)) {
4493 PyErr_Format(PyExc_TypeError
, "ImportFrom field \"names\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4496 len
= PyList_GET_SIZE(tmp
);
4497 names
= asdl_seq_new(len
, arena
);
4498 if (names
== NULL
) goto failed
;
4499 for (i
= 0; i
< len
; i
++) {
4501 res
= obj2ast_alias(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4502 if (res
!= 0) goto failed
;
4503 asdl_seq_SET(names
, i
, value
);
4508 PyErr_SetString(PyExc_TypeError
, "required field \"names\" missing from ImportFrom");
4511 if (PyObject_HasAttrString(obj
, "level")) {
4513 tmp
= PyObject_GetAttrString(obj
, "level");
4514 if (tmp
== NULL
) goto failed
;
4515 res
= obj2ast_int(tmp
, &level
, arena
);
4516 if (res
!= 0) goto failed
;
4522 *out
= ImportFrom(module
, names
, level
, lineno
, col_offset
,
4524 if (*out
== NULL
) goto failed
;
4527 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Exec_type
);
4528 if (isinstance
== -1) {
4536 if (PyObject_HasAttrString(obj
, "body")) {
4538 tmp
= PyObject_GetAttrString(obj
, "body");
4539 if (tmp
== NULL
) goto failed
;
4540 res
= obj2ast_expr(tmp
, &body
, arena
);
4541 if (res
!= 0) goto failed
;
4545 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from Exec");
4548 if (PyObject_HasAttrString(obj
, "globals")) {
4550 tmp
= PyObject_GetAttrString(obj
, "globals");
4551 if (tmp
== NULL
) goto failed
;
4552 res
= obj2ast_expr(tmp
, &globals
, arena
);
4553 if (res
!= 0) goto failed
;
4559 if (PyObject_HasAttrString(obj
, "locals")) {
4561 tmp
= PyObject_GetAttrString(obj
, "locals");
4562 if (tmp
== NULL
) goto failed
;
4563 res
= obj2ast_expr(tmp
, &locals
, arena
);
4564 if (res
!= 0) goto failed
;
4570 *out
= Exec(body
, globals
, locals
, lineno
, col_offset
, arena
);
4571 if (*out
== NULL
) goto failed
;
4574 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Global_type
);
4575 if (isinstance
== -1) {
4581 if (PyObject_HasAttrString(obj
, "names")) {
4585 tmp
= PyObject_GetAttrString(obj
, "names");
4586 if (tmp
== NULL
) goto failed
;
4587 if (!PyList_Check(tmp
)) {
4588 PyErr_Format(PyExc_TypeError
, "Global field \"names\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4591 len
= PyList_GET_SIZE(tmp
);
4592 names
= asdl_seq_new(len
, arena
);
4593 if (names
== NULL
) goto failed
;
4594 for (i
= 0; i
< len
; i
++) {
4596 res
= obj2ast_identifier(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4597 if (res
!= 0) goto failed
;
4598 asdl_seq_SET(names
, i
, value
);
4603 PyErr_SetString(PyExc_TypeError
, "required field \"names\" missing from Global");
4606 *out
= Global(names
, lineno
, col_offset
, arena
);
4607 if (*out
== NULL
) goto failed
;
4610 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Expr_type
);
4611 if (isinstance
== -1) {
4617 if (PyObject_HasAttrString(obj
, "value")) {
4619 tmp
= PyObject_GetAttrString(obj
, "value");
4620 if (tmp
== NULL
) goto failed
;
4621 res
= obj2ast_expr(tmp
, &value
, arena
);
4622 if (res
!= 0) goto failed
;
4626 PyErr_SetString(PyExc_TypeError
, "required field \"value\" missing from Expr");
4629 *out
= Expr(value
, lineno
, col_offset
, arena
);
4630 if (*out
== NULL
) goto failed
;
4633 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Pass_type
);
4634 if (isinstance
== -1) {
4639 *out
= Pass(lineno
, col_offset
, arena
);
4640 if (*out
== NULL
) goto failed
;
4643 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Break_type
);
4644 if (isinstance
== -1) {
4649 *out
= Break(lineno
, col_offset
, arena
);
4650 if (*out
== NULL
) goto failed
;
4653 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Continue_type
);
4654 if (isinstance
== -1) {
4659 *out
= Continue(lineno
, col_offset
, arena
);
4660 if (*out
== NULL
) goto failed
;
4664 tmp
= PyObject_Repr(obj
);
4665 if (tmp
== NULL
) goto failed
;
4666 PyErr_Format(PyExc_TypeError
, "expected some sort of stmt, but got %.400s", PyString_AS_STRING(tmp
));
4673 obj2ast_expr(PyObject
* obj
, expr_ty
* out
, PyArena
* arena
)
4675 PyObject
* tmp
= NULL
;
4681 if (obj
== Py_None
) {
4685 if (PyObject_HasAttrString(obj
, "lineno")) {
4687 tmp
= PyObject_GetAttrString(obj
, "lineno");
4688 if (tmp
== NULL
) goto failed
;
4689 res
= obj2ast_int(tmp
, &lineno
, arena
);
4690 if (res
!= 0) goto failed
;
4694 PyErr_SetString(PyExc_TypeError
, "required field \"lineno\" missing from expr");
4697 if (PyObject_HasAttrString(obj
, "col_offset")) {
4699 tmp
= PyObject_GetAttrString(obj
, "col_offset");
4700 if (tmp
== NULL
) goto failed
;
4701 res
= obj2ast_int(tmp
, &col_offset
, arena
);
4702 if (res
!= 0) goto failed
;
4706 PyErr_SetString(PyExc_TypeError
, "required field \"col_offset\" missing from expr");
4709 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)BoolOp_type
);
4710 if (isinstance
== -1) {
4717 if (PyObject_HasAttrString(obj
, "op")) {
4719 tmp
= PyObject_GetAttrString(obj
, "op");
4720 if (tmp
== NULL
) goto failed
;
4721 res
= obj2ast_boolop(tmp
, &op
, arena
);
4722 if (res
!= 0) goto failed
;
4726 PyErr_SetString(PyExc_TypeError
, "required field \"op\" missing from BoolOp");
4729 if (PyObject_HasAttrString(obj
, "values")) {
4733 tmp
= PyObject_GetAttrString(obj
, "values");
4734 if (tmp
== NULL
) goto failed
;
4735 if (!PyList_Check(tmp
)) {
4736 PyErr_Format(PyExc_TypeError
, "BoolOp field \"values\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4739 len
= PyList_GET_SIZE(tmp
);
4740 values
= asdl_seq_new(len
, arena
);
4741 if (values
== NULL
) goto failed
;
4742 for (i
= 0; i
< len
; i
++) {
4744 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4745 if (res
!= 0) goto failed
;
4746 asdl_seq_SET(values
, i
, value
);
4751 PyErr_SetString(PyExc_TypeError
, "required field \"values\" missing from BoolOp");
4754 *out
= BoolOp(op
, values
, lineno
, col_offset
, arena
);
4755 if (*out
== NULL
) goto failed
;
4758 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)BinOp_type
);
4759 if (isinstance
== -1) {
4767 if (PyObject_HasAttrString(obj
, "left")) {
4769 tmp
= PyObject_GetAttrString(obj
, "left");
4770 if (tmp
== NULL
) goto failed
;
4771 res
= obj2ast_expr(tmp
, &left
, arena
);
4772 if (res
!= 0) goto failed
;
4776 PyErr_SetString(PyExc_TypeError
, "required field \"left\" missing from BinOp");
4779 if (PyObject_HasAttrString(obj
, "op")) {
4781 tmp
= PyObject_GetAttrString(obj
, "op");
4782 if (tmp
== NULL
) goto failed
;
4783 res
= obj2ast_operator(tmp
, &op
, arena
);
4784 if (res
!= 0) goto failed
;
4788 PyErr_SetString(PyExc_TypeError
, "required field \"op\" missing from BinOp");
4791 if (PyObject_HasAttrString(obj
, "right")) {
4793 tmp
= PyObject_GetAttrString(obj
, "right");
4794 if (tmp
== NULL
) goto failed
;
4795 res
= obj2ast_expr(tmp
, &right
, arena
);
4796 if (res
!= 0) goto failed
;
4800 PyErr_SetString(PyExc_TypeError
, "required field \"right\" missing from BinOp");
4803 *out
= BinOp(left
, op
, right
, lineno
, col_offset
, arena
);
4804 if (*out
== NULL
) goto failed
;
4807 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)UnaryOp_type
);
4808 if (isinstance
== -1) {
4815 if (PyObject_HasAttrString(obj
, "op")) {
4817 tmp
= PyObject_GetAttrString(obj
, "op");
4818 if (tmp
== NULL
) goto failed
;
4819 res
= obj2ast_unaryop(tmp
, &op
, arena
);
4820 if (res
!= 0) goto failed
;
4824 PyErr_SetString(PyExc_TypeError
, "required field \"op\" missing from UnaryOp");
4827 if (PyObject_HasAttrString(obj
, "operand")) {
4829 tmp
= PyObject_GetAttrString(obj
, "operand");
4830 if (tmp
== NULL
) goto failed
;
4831 res
= obj2ast_expr(tmp
, &operand
, arena
);
4832 if (res
!= 0) goto failed
;
4836 PyErr_SetString(PyExc_TypeError
, "required field \"operand\" missing from UnaryOp");
4839 *out
= UnaryOp(op
, operand
, lineno
, col_offset
, arena
);
4840 if (*out
== NULL
) goto failed
;
4843 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Lambda_type
);
4844 if (isinstance
== -1) {
4851 if (PyObject_HasAttrString(obj
, "args")) {
4853 tmp
= PyObject_GetAttrString(obj
, "args");
4854 if (tmp
== NULL
) goto failed
;
4855 res
= obj2ast_arguments(tmp
, &args
, arena
);
4856 if (res
!= 0) goto failed
;
4860 PyErr_SetString(PyExc_TypeError
, "required field \"args\" missing from Lambda");
4863 if (PyObject_HasAttrString(obj
, "body")) {
4865 tmp
= PyObject_GetAttrString(obj
, "body");
4866 if (tmp
== NULL
) goto failed
;
4867 res
= obj2ast_expr(tmp
, &body
, arena
);
4868 if (res
!= 0) goto failed
;
4872 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from Lambda");
4875 *out
= Lambda(args
, body
, lineno
, col_offset
, arena
);
4876 if (*out
== NULL
) goto failed
;
4879 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)IfExp_type
);
4880 if (isinstance
== -1) {
4888 if (PyObject_HasAttrString(obj
, "test")) {
4890 tmp
= PyObject_GetAttrString(obj
, "test");
4891 if (tmp
== NULL
) goto failed
;
4892 res
= obj2ast_expr(tmp
, &test
, arena
);
4893 if (res
!= 0) goto failed
;
4897 PyErr_SetString(PyExc_TypeError
, "required field \"test\" missing from IfExp");
4900 if (PyObject_HasAttrString(obj
, "body")) {
4902 tmp
= PyObject_GetAttrString(obj
, "body");
4903 if (tmp
== NULL
) goto failed
;
4904 res
= obj2ast_expr(tmp
, &body
, arena
);
4905 if (res
!= 0) goto failed
;
4909 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from IfExp");
4912 if (PyObject_HasAttrString(obj
, "orelse")) {
4914 tmp
= PyObject_GetAttrString(obj
, "orelse");
4915 if (tmp
== NULL
) goto failed
;
4916 res
= obj2ast_expr(tmp
, &orelse
, arena
);
4917 if (res
!= 0) goto failed
;
4921 PyErr_SetString(PyExc_TypeError
, "required field \"orelse\" missing from IfExp");
4924 *out
= IfExp(test
, body
, orelse
, lineno
, col_offset
, arena
);
4925 if (*out
== NULL
) goto failed
;
4928 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Dict_type
);
4929 if (isinstance
== -1) {
4936 if (PyObject_HasAttrString(obj
, "keys")) {
4940 tmp
= PyObject_GetAttrString(obj
, "keys");
4941 if (tmp
== NULL
) goto failed
;
4942 if (!PyList_Check(tmp
)) {
4943 PyErr_Format(PyExc_TypeError
, "Dict field \"keys\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4946 len
= PyList_GET_SIZE(tmp
);
4947 keys
= asdl_seq_new(len
, arena
);
4948 if (keys
== NULL
) goto failed
;
4949 for (i
= 0; i
< len
; i
++) {
4951 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4952 if (res
!= 0) goto failed
;
4953 asdl_seq_SET(keys
, i
, value
);
4958 PyErr_SetString(PyExc_TypeError
, "required field \"keys\" missing from Dict");
4961 if (PyObject_HasAttrString(obj
, "values")) {
4965 tmp
= PyObject_GetAttrString(obj
, "values");
4966 if (tmp
== NULL
) goto failed
;
4967 if (!PyList_Check(tmp
)) {
4968 PyErr_Format(PyExc_TypeError
, "Dict field \"values\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
4971 len
= PyList_GET_SIZE(tmp
);
4972 values
= asdl_seq_new(len
, arena
);
4973 if (values
== NULL
) goto failed
;
4974 for (i
= 0; i
< len
; i
++) {
4976 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
4977 if (res
!= 0) goto failed
;
4978 asdl_seq_SET(values
, i
, value
);
4983 PyErr_SetString(PyExc_TypeError
, "required field \"values\" missing from Dict");
4986 *out
= Dict(keys
, values
, lineno
, col_offset
, arena
);
4987 if (*out
== NULL
) goto failed
;
4990 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Set_type
);
4991 if (isinstance
== -1) {
4997 if (PyObject_HasAttrString(obj
, "elts")) {
5001 tmp
= PyObject_GetAttrString(obj
, "elts");
5002 if (tmp
== NULL
) goto failed
;
5003 if (!PyList_Check(tmp
)) {
5004 PyErr_Format(PyExc_TypeError
, "Set field \"elts\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5007 len
= PyList_GET_SIZE(tmp
);
5008 elts
= asdl_seq_new(len
, arena
);
5009 if (elts
== NULL
) goto failed
;
5010 for (i
= 0; i
< len
; i
++) {
5012 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5013 if (res
!= 0) goto failed
;
5014 asdl_seq_SET(elts
, i
, value
);
5019 PyErr_SetString(PyExc_TypeError
, "required field \"elts\" missing from Set");
5022 *out
= Set(elts
, lineno
, col_offset
, arena
);
5023 if (*out
== NULL
) goto failed
;
5026 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)ListComp_type
);
5027 if (isinstance
== -1) {
5032 asdl_seq
* generators
;
5034 if (PyObject_HasAttrString(obj
, "elt")) {
5036 tmp
= PyObject_GetAttrString(obj
, "elt");
5037 if (tmp
== NULL
) goto failed
;
5038 res
= obj2ast_expr(tmp
, &elt
, arena
);
5039 if (res
!= 0) goto failed
;
5043 PyErr_SetString(PyExc_TypeError
, "required field \"elt\" missing from ListComp");
5046 if (PyObject_HasAttrString(obj
, "generators")) {
5050 tmp
= PyObject_GetAttrString(obj
, "generators");
5051 if (tmp
== NULL
) goto failed
;
5052 if (!PyList_Check(tmp
)) {
5053 PyErr_Format(PyExc_TypeError
, "ListComp field \"generators\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5056 len
= PyList_GET_SIZE(tmp
);
5057 generators
= asdl_seq_new(len
, arena
);
5058 if (generators
== NULL
) goto failed
;
5059 for (i
= 0; i
< len
; i
++) {
5060 comprehension_ty value
;
5061 res
= obj2ast_comprehension(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5062 if (res
!= 0) goto failed
;
5063 asdl_seq_SET(generators
, i
, value
);
5068 PyErr_SetString(PyExc_TypeError
, "required field \"generators\" missing from ListComp");
5071 *out
= ListComp(elt
, generators
, lineno
, col_offset
, arena
);
5072 if (*out
== NULL
) goto failed
;
5075 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)SetComp_type
);
5076 if (isinstance
== -1) {
5081 asdl_seq
* generators
;
5083 if (PyObject_HasAttrString(obj
, "elt")) {
5085 tmp
= PyObject_GetAttrString(obj
, "elt");
5086 if (tmp
== NULL
) goto failed
;
5087 res
= obj2ast_expr(tmp
, &elt
, arena
);
5088 if (res
!= 0) goto failed
;
5092 PyErr_SetString(PyExc_TypeError
, "required field \"elt\" missing from SetComp");
5095 if (PyObject_HasAttrString(obj
, "generators")) {
5099 tmp
= PyObject_GetAttrString(obj
, "generators");
5100 if (tmp
== NULL
) goto failed
;
5101 if (!PyList_Check(tmp
)) {
5102 PyErr_Format(PyExc_TypeError
, "SetComp field \"generators\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5105 len
= PyList_GET_SIZE(tmp
);
5106 generators
= asdl_seq_new(len
, arena
);
5107 if (generators
== NULL
) goto failed
;
5108 for (i
= 0; i
< len
; i
++) {
5109 comprehension_ty value
;
5110 res
= obj2ast_comprehension(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5111 if (res
!= 0) goto failed
;
5112 asdl_seq_SET(generators
, i
, value
);
5117 PyErr_SetString(PyExc_TypeError
, "required field \"generators\" missing from SetComp");
5120 *out
= SetComp(elt
, generators
, lineno
, col_offset
, arena
);
5121 if (*out
== NULL
) goto failed
;
5124 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)DictComp_type
);
5125 if (isinstance
== -1) {
5131 asdl_seq
* generators
;
5133 if (PyObject_HasAttrString(obj
, "key")) {
5135 tmp
= PyObject_GetAttrString(obj
, "key");
5136 if (tmp
== NULL
) goto failed
;
5137 res
= obj2ast_expr(tmp
, &key
, arena
);
5138 if (res
!= 0) goto failed
;
5142 PyErr_SetString(PyExc_TypeError
, "required field \"key\" missing from DictComp");
5145 if (PyObject_HasAttrString(obj
, "value")) {
5147 tmp
= PyObject_GetAttrString(obj
, "value");
5148 if (tmp
== NULL
) goto failed
;
5149 res
= obj2ast_expr(tmp
, &value
, arena
);
5150 if (res
!= 0) goto failed
;
5154 PyErr_SetString(PyExc_TypeError
, "required field \"value\" missing from DictComp");
5157 if (PyObject_HasAttrString(obj
, "generators")) {
5161 tmp
= PyObject_GetAttrString(obj
, "generators");
5162 if (tmp
== NULL
) goto failed
;
5163 if (!PyList_Check(tmp
)) {
5164 PyErr_Format(PyExc_TypeError
, "DictComp field \"generators\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5167 len
= PyList_GET_SIZE(tmp
);
5168 generators
= asdl_seq_new(len
, arena
);
5169 if (generators
== NULL
) goto failed
;
5170 for (i
= 0; i
< len
; i
++) {
5171 comprehension_ty value
;
5172 res
= obj2ast_comprehension(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5173 if (res
!= 0) goto failed
;
5174 asdl_seq_SET(generators
, i
, value
);
5179 PyErr_SetString(PyExc_TypeError
, "required field \"generators\" missing from DictComp");
5182 *out
= DictComp(key
, value
, generators
, lineno
, col_offset
,
5184 if (*out
== NULL
) goto failed
;
5187 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)GeneratorExp_type
);
5188 if (isinstance
== -1) {
5193 asdl_seq
* generators
;
5195 if (PyObject_HasAttrString(obj
, "elt")) {
5197 tmp
= PyObject_GetAttrString(obj
, "elt");
5198 if (tmp
== NULL
) goto failed
;
5199 res
= obj2ast_expr(tmp
, &elt
, arena
);
5200 if (res
!= 0) goto failed
;
5204 PyErr_SetString(PyExc_TypeError
, "required field \"elt\" missing from GeneratorExp");
5207 if (PyObject_HasAttrString(obj
, "generators")) {
5211 tmp
= PyObject_GetAttrString(obj
, "generators");
5212 if (tmp
== NULL
) goto failed
;
5213 if (!PyList_Check(tmp
)) {
5214 PyErr_Format(PyExc_TypeError
, "GeneratorExp field \"generators\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5217 len
= PyList_GET_SIZE(tmp
);
5218 generators
= asdl_seq_new(len
, arena
);
5219 if (generators
== NULL
) goto failed
;
5220 for (i
= 0; i
< len
; i
++) {
5221 comprehension_ty value
;
5222 res
= obj2ast_comprehension(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5223 if (res
!= 0) goto failed
;
5224 asdl_seq_SET(generators
, i
, value
);
5229 PyErr_SetString(PyExc_TypeError
, "required field \"generators\" missing from GeneratorExp");
5232 *out
= GeneratorExp(elt
, generators
, lineno
, col_offset
, arena
);
5233 if (*out
== NULL
) goto failed
;
5236 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Yield_type
);
5237 if (isinstance
== -1) {
5243 if (PyObject_HasAttrString(obj
, "value")) {
5245 tmp
= PyObject_GetAttrString(obj
, "value");
5246 if (tmp
== NULL
) goto failed
;
5247 res
= obj2ast_expr(tmp
, &value
, arena
);
5248 if (res
!= 0) goto failed
;
5254 *out
= Yield(value
, lineno
, col_offset
, arena
);
5255 if (*out
== NULL
) goto failed
;
5258 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Compare_type
);
5259 if (isinstance
== -1) {
5265 asdl_seq
* comparators
;
5267 if (PyObject_HasAttrString(obj
, "left")) {
5269 tmp
= PyObject_GetAttrString(obj
, "left");
5270 if (tmp
== NULL
) goto failed
;
5271 res
= obj2ast_expr(tmp
, &left
, arena
);
5272 if (res
!= 0) goto failed
;
5276 PyErr_SetString(PyExc_TypeError
, "required field \"left\" missing from Compare");
5279 if (PyObject_HasAttrString(obj
, "ops")) {
5283 tmp
= PyObject_GetAttrString(obj
, "ops");
5284 if (tmp
== NULL
) goto failed
;
5285 if (!PyList_Check(tmp
)) {
5286 PyErr_Format(PyExc_TypeError
, "Compare field \"ops\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5289 len
= PyList_GET_SIZE(tmp
);
5290 ops
= asdl_int_seq_new(len
, arena
);
5291 if (ops
== NULL
) goto failed
;
5292 for (i
= 0; i
< len
; i
++) {
5294 res
= obj2ast_cmpop(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5295 if (res
!= 0) goto failed
;
5296 asdl_seq_SET(ops
, i
, value
);
5301 PyErr_SetString(PyExc_TypeError
, "required field \"ops\" missing from Compare");
5304 if (PyObject_HasAttrString(obj
, "comparators")) {
5308 tmp
= PyObject_GetAttrString(obj
, "comparators");
5309 if (tmp
== NULL
) goto failed
;
5310 if (!PyList_Check(tmp
)) {
5311 PyErr_Format(PyExc_TypeError
, "Compare field \"comparators\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5314 len
= PyList_GET_SIZE(tmp
);
5315 comparators
= asdl_seq_new(len
, arena
);
5316 if (comparators
== NULL
) goto failed
;
5317 for (i
= 0; i
< len
; i
++) {
5319 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5320 if (res
!= 0) goto failed
;
5321 asdl_seq_SET(comparators
, i
, value
);
5326 PyErr_SetString(PyExc_TypeError
, "required field \"comparators\" missing from Compare");
5329 *out
= Compare(left
, ops
, comparators
, lineno
, col_offset
,
5331 if (*out
== NULL
) goto failed
;
5334 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Call_type
);
5335 if (isinstance
== -1) {
5345 if (PyObject_HasAttrString(obj
, "func")) {
5347 tmp
= PyObject_GetAttrString(obj
, "func");
5348 if (tmp
== NULL
) goto failed
;
5349 res
= obj2ast_expr(tmp
, &func
, arena
);
5350 if (res
!= 0) goto failed
;
5354 PyErr_SetString(PyExc_TypeError
, "required field \"func\" missing from Call");
5357 if (PyObject_HasAttrString(obj
, "args")) {
5361 tmp
= PyObject_GetAttrString(obj
, "args");
5362 if (tmp
== NULL
) goto failed
;
5363 if (!PyList_Check(tmp
)) {
5364 PyErr_Format(PyExc_TypeError
, "Call field \"args\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5367 len
= PyList_GET_SIZE(tmp
);
5368 args
= asdl_seq_new(len
, arena
);
5369 if (args
== NULL
) goto failed
;
5370 for (i
= 0; i
< len
; i
++) {
5372 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5373 if (res
!= 0) goto failed
;
5374 asdl_seq_SET(args
, i
, value
);
5379 PyErr_SetString(PyExc_TypeError
, "required field \"args\" missing from Call");
5382 if (PyObject_HasAttrString(obj
, "keywords")) {
5386 tmp
= PyObject_GetAttrString(obj
, "keywords");
5387 if (tmp
== NULL
) goto failed
;
5388 if (!PyList_Check(tmp
)) {
5389 PyErr_Format(PyExc_TypeError
, "Call field \"keywords\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5392 len
= PyList_GET_SIZE(tmp
);
5393 keywords
= asdl_seq_new(len
, arena
);
5394 if (keywords
== NULL
) goto failed
;
5395 for (i
= 0; i
< len
; i
++) {
5397 res
= obj2ast_keyword(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5398 if (res
!= 0) goto failed
;
5399 asdl_seq_SET(keywords
, i
, value
);
5404 PyErr_SetString(PyExc_TypeError
, "required field \"keywords\" missing from Call");
5407 if (PyObject_HasAttrString(obj
, "starargs")) {
5409 tmp
= PyObject_GetAttrString(obj
, "starargs");
5410 if (tmp
== NULL
) goto failed
;
5411 res
= obj2ast_expr(tmp
, &starargs
, arena
);
5412 if (res
!= 0) goto failed
;
5418 if (PyObject_HasAttrString(obj
, "kwargs")) {
5420 tmp
= PyObject_GetAttrString(obj
, "kwargs");
5421 if (tmp
== NULL
) goto failed
;
5422 res
= obj2ast_expr(tmp
, &kwargs
, arena
);
5423 if (res
!= 0) goto failed
;
5429 *out
= Call(func
, args
, keywords
, starargs
, kwargs
, lineno
,
5431 if (*out
== NULL
) goto failed
;
5434 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Repr_type
);
5435 if (isinstance
== -1) {
5441 if (PyObject_HasAttrString(obj
, "value")) {
5443 tmp
= PyObject_GetAttrString(obj
, "value");
5444 if (tmp
== NULL
) goto failed
;
5445 res
= obj2ast_expr(tmp
, &value
, arena
);
5446 if (res
!= 0) goto failed
;
5450 PyErr_SetString(PyExc_TypeError
, "required field \"value\" missing from Repr");
5453 *out
= Repr(value
, lineno
, col_offset
, arena
);
5454 if (*out
== NULL
) goto failed
;
5457 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Num_type
);
5458 if (isinstance
== -1) {
5464 if (PyObject_HasAttrString(obj
, "n")) {
5466 tmp
= PyObject_GetAttrString(obj
, "n");
5467 if (tmp
== NULL
) goto failed
;
5468 res
= obj2ast_object(tmp
, &n
, arena
);
5469 if (res
!= 0) goto failed
;
5473 PyErr_SetString(PyExc_TypeError
, "required field \"n\" missing from Num");
5476 *out
= Num(n
, lineno
, col_offset
, arena
);
5477 if (*out
== NULL
) goto failed
;
5480 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Str_type
);
5481 if (isinstance
== -1) {
5487 if (PyObject_HasAttrString(obj
, "s")) {
5489 tmp
= PyObject_GetAttrString(obj
, "s");
5490 if (tmp
== NULL
) goto failed
;
5491 res
= obj2ast_string(tmp
, &s
, arena
);
5492 if (res
!= 0) goto failed
;
5496 PyErr_SetString(PyExc_TypeError
, "required field \"s\" missing from Str");
5499 *out
= Str(s
, lineno
, col_offset
, arena
);
5500 if (*out
== NULL
) goto failed
;
5503 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Attribute_type
);
5504 if (isinstance
== -1) {
5510 expr_context_ty ctx
;
5512 if (PyObject_HasAttrString(obj
, "value")) {
5514 tmp
= PyObject_GetAttrString(obj
, "value");
5515 if (tmp
== NULL
) goto failed
;
5516 res
= obj2ast_expr(tmp
, &value
, arena
);
5517 if (res
!= 0) goto failed
;
5521 PyErr_SetString(PyExc_TypeError
, "required field \"value\" missing from Attribute");
5524 if (PyObject_HasAttrString(obj
, "attr")) {
5526 tmp
= PyObject_GetAttrString(obj
, "attr");
5527 if (tmp
== NULL
) goto failed
;
5528 res
= obj2ast_identifier(tmp
, &attr
, arena
);
5529 if (res
!= 0) goto failed
;
5533 PyErr_SetString(PyExc_TypeError
, "required field \"attr\" missing from Attribute");
5536 if (PyObject_HasAttrString(obj
, "ctx")) {
5538 tmp
= PyObject_GetAttrString(obj
, "ctx");
5539 if (tmp
== NULL
) goto failed
;
5540 res
= obj2ast_expr_context(tmp
, &ctx
, arena
);
5541 if (res
!= 0) goto failed
;
5545 PyErr_SetString(PyExc_TypeError
, "required field \"ctx\" missing from Attribute");
5548 *out
= Attribute(value
, attr
, ctx
, lineno
, col_offset
, arena
);
5549 if (*out
== NULL
) goto failed
;
5552 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Subscript_type
);
5553 if (isinstance
== -1) {
5559 expr_context_ty ctx
;
5561 if (PyObject_HasAttrString(obj
, "value")) {
5563 tmp
= PyObject_GetAttrString(obj
, "value");
5564 if (tmp
== NULL
) goto failed
;
5565 res
= obj2ast_expr(tmp
, &value
, arena
);
5566 if (res
!= 0) goto failed
;
5570 PyErr_SetString(PyExc_TypeError
, "required field \"value\" missing from Subscript");
5573 if (PyObject_HasAttrString(obj
, "slice")) {
5575 tmp
= PyObject_GetAttrString(obj
, "slice");
5576 if (tmp
== NULL
) goto failed
;
5577 res
= obj2ast_slice(tmp
, &slice
, arena
);
5578 if (res
!= 0) goto failed
;
5582 PyErr_SetString(PyExc_TypeError
, "required field \"slice\" missing from Subscript");
5585 if (PyObject_HasAttrString(obj
, "ctx")) {
5587 tmp
= PyObject_GetAttrString(obj
, "ctx");
5588 if (tmp
== NULL
) goto failed
;
5589 res
= obj2ast_expr_context(tmp
, &ctx
, arena
);
5590 if (res
!= 0) goto failed
;
5594 PyErr_SetString(PyExc_TypeError
, "required field \"ctx\" missing from Subscript");
5597 *out
= Subscript(value
, slice
, ctx
, lineno
, col_offset
, arena
);
5598 if (*out
== NULL
) goto failed
;
5601 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Name_type
);
5602 if (isinstance
== -1) {
5607 expr_context_ty ctx
;
5609 if (PyObject_HasAttrString(obj
, "id")) {
5611 tmp
= PyObject_GetAttrString(obj
, "id");
5612 if (tmp
== NULL
) goto failed
;
5613 res
= obj2ast_identifier(tmp
, &id
, arena
);
5614 if (res
!= 0) goto failed
;
5618 PyErr_SetString(PyExc_TypeError
, "required field \"id\" missing from Name");
5621 if (PyObject_HasAttrString(obj
, "ctx")) {
5623 tmp
= PyObject_GetAttrString(obj
, "ctx");
5624 if (tmp
== NULL
) goto failed
;
5625 res
= obj2ast_expr_context(tmp
, &ctx
, arena
);
5626 if (res
!= 0) goto failed
;
5630 PyErr_SetString(PyExc_TypeError
, "required field \"ctx\" missing from Name");
5633 *out
= Name(id
, ctx
, lineno
, col_offset
, arena
);
5634 if (*out
== NULL
) goto failed
;
5637 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)List_type
);
5638 if (isinstance
== -1) {
5643 expr_context_ty ctx
;
5645 if (PyObject_HasAttrString(obj
, "elts")) {
5649 tmp
= PyObject_GetAttrString(obj
, "elts");
5650 if (tmp
== NULL
) goto failed
;
5651 if (!PyList_Check(tmp
)) {
5652 PyErr_Format(PyExc_TypeError
, "List field \"elts\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5655 len
= PyList_GET_SIZE(tmp
);
5656 elts
= asdl_seq_new(len
, arena
);
5657 if (elts
== NULL
) goto failed
;
5658 for (i
= 0; i
< len
; i
++) {
5660 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5661 if (res
!= 0) goto failed
;
5662 asdl_seq_SET(elts
, i
, value
);
5667 PyErr_SetString(PyExc_TypeError
, "required field \"elts\" missing from List");
5670 if (PyObject_HasAttrString(obj
, "ctx")) {
5672 tmp
= PyObject_GetAttrString(obj
, "ctx");
5673 if (tmp
== NULL
) goto failed
;
5674 res
= obj2ast_expr_context(tmp
, &ctx
, arena
);
5675 if (res
!= 0) goto failed
;
5679 PyErr_SetString(PyExc_TypeError
, "required field \"ctx\" missing from List");
5682 *out
= List(elts
, ctx
, lineno
, col_offset
, arena
);
5683 if (*out
== NULL
) goto failed
;
5686 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Tuple_type
);
5687 if (isinstance
== -1) {
5692 expr_context_ty ctx
;
5694 if (PyObject_HasAttrString(obj
, "elts")) {
5698 tmp
= PyObject_GetAttrString(obj
, "elts");
5699 if (tmp
== NULL
) goto failed
;
5700 if (!PyList_Check(tmp
)) {
5701 PyErr_Format(PyExc_TypeError
, "Tuple field \"elts\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5704 len
= PyList_GET_SIZE(tmp
);
5705 elts
= asdl_seq_new(len
, arena
);
5706 if (elts
== NULL
) goto failed
;
5707 for (i
= 0; i
< len
; i
++) {
5709 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5710 if (res
!= 0) goto failed
;
5711 asdl_seq_SET(elts
, i
, value
);
5716 PyErr_SetString(PyExc_TypeError
, "required field \"elts\" missing from Tuple");
5719 if (PyObject_HasAttrString(obj
, "ctx")) {
5721 tmp
= PyObject_GetAttrString(obj
, "ctx");
5722 if (tmp
== NULL
) goto failed
;
5723 res
= obj2ast_expr_context(tmp
, &ctx
, arena
);
5724 if (res
!= 0) goto failed
;
5728 PyErr_SetString(PyExc_TypeError
, "required field \"ctx\" missing from Tuple");
5731 *out
= Tuple(elts
, ctx
, lineno
, col_offset
, arena
);
5732 if (*out
== NULL
) goto failed
;
5736 tmp
= PyObject_Repr(obj
);
5737 if (tmp
== NULL
) goto failed
;
5738 PyErr_Format(PyExc_TypeError
, "expected some sort of expr, but got %.400s", PyString_AS_STRING(tmp
));
5745 obj2ast_expr_context(PyObject
* obj
, expr_context_ty
* out
, PyArena
* arena
)
5747 PyObject
* tmp
= NULL
;
5750 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Load_type
);
5751 if (isinstance
== -1) {
5758 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Store_type
);
5759 if (isinstance
== -1) {
5766 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Del_type
);
5767 if (isinstance
== -1) {
5774 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)AugLoad_type
);
5775 if (isinstance
== -1) {
5782 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)AugStore_type
);
5783 if (isinstance
== -1) {
5790 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Param_type
);
5791 if (isinstance
== -1) {
5799 tmp
= PyObject_Repr(obj
);
5800 if (tmp
== NULL
) goto failed
;
5801 PyErr_Format(PyExc_TypeError
, "expected some sort of expr_context, but got %.400s", PyString_AS_STRING(tmp
));
5808 obj2ast_slice(PyObject
* obj
, slice_ty
* out
, PyArena
* arena
)
5810 PyObject
* tmp
= NULL
;
5814 if (obj
== Py_None
) {
5818 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Ellipsis_type
);
5819 if (isinstance
== -1) {
5824 *out
= Ellipsis(arena
);
5825 if (*out
== NULL
) goto failed
;
5828 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Slice_type
);
5829 if (isinstance
== -1) {
5837 if (PyObject_HasAttrString(obj
, "lower")) {
5839 tmp
= PyObject_GetAttrString(obj
, "lower");
5840 if (tmp
== NULL
) goto failed
;
5841 res
= obj2ast_expr(tmp
, &lower
, arena
);
5842 if (res
!= 0) goto failed
;
5848 if (PyObject_HasAttrString(obj
, "upper")) {
5850 tmp
= PyObject_GetAttrString(obj
, "upper");
5851 if (tmp
== NULL
) goto failed
;
5852 res
= obj2ast_expr(tmp
, &upper
, arena
);
5853 if (res
!= 0) goto failed
;
5859 if (PyObject_HasAttrString(obj
, "step")) {
5861 tmp
= PyObject_GetAttrString(obj
, "step");
5862 if (tmp
== NULL
) goto failed
;
5863 res
= obj2ast_expr(tmp
, &step
, arena
);
5864 if (res
!= 0) goto failed
;
5870 *out
= Slice(lower
, upper
, step
, arena
);
5871 if (*out
== NULL
) goto failed
;
5874 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)ExtSlice_type
);
5875 if (isinstance
== -1) {
5881 if (PyObject_HasAttrString(obj
, "dims")) {
5885 tmp
= PyObject_GetAttrString(obj
, "dims");
5886 if (tmp
== NULL
) goto failed
;
5887 if (!PyList_Check(tmp
)) {
5888 PyErr_Format(PyExc_TypeError
, "ExtSlice field \"dims\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
5891 len
= PyList_GET_SIZE(tmp
);
5892 dims
= asdl_seq_new(len
, arena
);
5893 if (dims
== NULL
) goto failed
;
5894 for (i
= 0; i
< len
; i
++) {
5896 res
= obj2ast_slice(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
5897 if (res
!= 0) goto failed
;
5898 asdl_seq_SET(dims
, i
, value
);
5903 PyErr_SetString(PyExc_TypeError
, "required field \"dims\" missing from ExtSlice");
5906 *out
= ExtSlice(dims
, arena
);
5907 if (*out
== NULL
) goto failed
;
5910 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Index_type
);
5911 if (isinstance
== -1) {
5917 if (PyObject_HasAttrString(obj
, "value")) {
5919 tmp
= PyObject_GetAttrString(obj
, "value");
5920 if (tmp
== NULL
) goto failed
;
5921 res
= obj2ast_expr(tmp
, &value
, arena
);
5922 if (res
!= 0) goto failed
;
5926 PyErr_SetString(PyExc_TypeError
, "required field \"value\" missing from Index");
5929 *out
= Index(value
, arena
);
5930 if (*out
== NULL
) goto failed
;
5934 tmp
= PyObject_Repr(obj
);
5935 if (tmp
== NULL
) goto failed
;
5936 PyErr_Format(PyExc_TypeError
, "expected some sort of slice, but got %.400s", PyString_AS_STRING(tmp
));
5943 obj2ast_boolop(PyObject
* obj
, boolop_ty
* out
, PyArena
* arena
)
5945 PyObject
* tmp
= NULL
;
5948 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)And_type
);
5949 if (isinstance
== -1) {
5956 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Or_type
);
5957 if (isinstance
== -1) {
5965 tmp
= PyObject_Repr(obj
);
5966 if (tmp
== NULL
) goto failed
;
5967 PyErr_Format(PyExc_TypeError
, "expected some sort of boolop, but got %.400s", PyString_AS_STRING(tmp
));
5974 obj2ast_operator(PyObject
* obj
, operator_ty
* out
, PyArena
* arena
)
5976 PyObject
* tmp
= NULL
;
5979 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Add_type
);
5980 if (isinstance
== -1) {
5987 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Sub_type
);
5988 if (isinstance
== -1) {
5995 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Mult_type
);
5996 if (isinstance
== -1) {
6003 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Div_type
);
6004 if (isinstance
== -1) {
6011 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Mod_type
);
6012 if (isinstance
== -1) {
6019 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Pow_type
);
6020 if (isinstance
== -1) {
6027 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)LShift_type
);
6028 if (isinstance
== -1) {
6035 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)RShift_type
);
6036 if (isinstance
== -1) {
6043 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)BitOr_type
);
6044 if (isinstance
== -1) {
6051 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)BitXor_type
);
6052 if (isinstance
== -1) {
6059 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)BitAnd_type
);
6060 if (isinstance
== -1) {
6067 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)FloorDiv_type
);
6068 if (isinstance
== -1) {
6076 tmp
= PyObject_Repr(obj
);
6077 if (tmp
== NULL
) goto failed
;
6078 PyErr_Format(PyExc_TypeError
, "expected some sort of operator, but got %.400s", PyString_AS_STRING(tmp
));
6085 obj2ast_unaryop(PyObject
* obj
, unaryop_ty
* out
, PyArena
* arena
)
6087 PyObject
* tmp
= NULL
;
6090 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Invert_type
);
6091 if (isinstance
== -1) {
6098 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Not_type
);
6099 if (isinstance
== -1) {
6106 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)UAdd_type
);
6107 if (isinstance
== -1) {
6114 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)USub_type
);
6115 if (isinstance
== -1) {
6123 tmp
= PyObject_Repr(obj
);
6124 if (tmp
== NULL
) goto failed
;
6125 PyErr_Format(PyExc_TypeError
, "expected some sort of unaryop, but got %.400s", PyString_AS_STRING(tmp
));
6132 obj2ast_cmpop(PyObject
* obj
, cmpop_ty
* out
, PyArena
* arena
)
6134 PyObject
* tmp
= NULL
;
6137 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Eq_type
);
6138 if (isinstance
== -1) {
6145 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)NotEq_type
);
6146 if (isinstance
== -1) {
6153 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Lt_type
);
6154 if (isinstance
== -1) {
6161 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)LtE_type
);
6162 if (isinstance
== -1) {
6169 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Gt_type
);
6170 if (isinstance
== -1) {
6177 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)GtE_type
);
6178 if (isinstance
== -1) {
6185 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)Is_type
);
6186 if (isinstance
== -1) {
6193 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)IsNot_type
);
6194 if (isinstance
== -1) {
6201 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)In_type
);
6202 if (isinstance
== -1) {
6209 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)NotIn_type
);
6210 if (isinstance
== -1) {
6218 tmp
= PyObject_Repr(obj
);
6219 if (tmp
== NULL
) goto failed
;
6220 PyErr_Format(PyExc_TypeError
, "expected some sort of cmpop, but got %.400s", PyString_AS_STRING(tmp
));
6227 obj2ast_comprehension(PyObject
* obj
, comprehension_ty
* out
, PyArena
* arena
)
6229 PyObject
* tmp
= NULL
;
6234 if (PyObject_HasAttrString(obj
, "target")) {
6236 tmp
= PyObject_GetAttrString(obj
, "target");
6237 if (tmp
== NULL
) goto failed
;
6238 res
= obj2ast_expr(tmp
, &target
, arena
);
6239 if (res
!= 0) goto failed
;
6243 PyErr_SetString(PyExc_TypeError
, "required field \"target\" missing from comprehension");
6246 if (PyObject_HasAttrString(obj
, "iter")) {
6248 tmp
= PyObject_GetAttrString(obj
, "iter");
6249 if (tmp
== NULL
) goto failed
;
6250 res
= obj2ast_expr(tmp
, &iter
, arena
);
6251 if (res
!= 0) goto failed
;
6255 PyErr_SetString(PyExc_TypeError
, "required field \"iter\" missing from comprehension");
6258 if (PyObject_HasAttrString(obj
, "ifs")) {
6262 tmp
= PyObject_GetAttrString(obj
, "ifs");
6263 if (tmp
== NULL
) goto failed
;
6264 if (!PyList_Check(tmp
)) {
6265 PyErr_Format(PyExc_TypeError
, "comprehension field \"ifs\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
6268 len
= PyList_GET_SIZE(tmp
);
6269 ifs
= asdl_seq_new(len
, arena
);
6270 if (ifs
== NULL
) goto failed
;
6271 for (i
= 0; i
< len
; i
++) {
6273 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
6274 if (res
!= 0) goto failed
;
6275 asdl_seq_SET(ifs
, i
, value
);
6280 PyErr_SetString(PyExc_TypeError
, "required field \"ifs\" missing from comprehension");
6283 *out
= comprehension(target
, iter
, ifs
, arena
);
6291 obj2ast_excepthandler(PyObject
* obj
, excepthandler_ty
* out
, PyArena
* arena
)
6293 PyObject
* tmp
= NULL
;
6299 if (obj
== Py_None
) {
6303 if (PyObject_HasAttrString(obj
, "lineno")) {
6305 tmp
= PyObject_GetAttrString(obj
, "lineno");
6306 if (tmp
== NULL
) goto failed
;
6307 res
= obj2ast_int(tmp
, &lineno
, arena
);
6308 if (res
!= 0) goto failed
;
6312 PyErr_SetString(PyExc_TypeError
, "required field \"lineno\" missing from excepthandler");
6315 if (PyObject_HasAttrString(obj
, "col_offset")) {
6317 tmp
= PyObject_GetAttrString(obj
, "col_offset");
6318 if (tmp
== NULL
) goto failed
;
6319 res
= obj2ast_int(tmp
, &col_offset
, arena
);
6320 if (res
!= 0) goto failed
;
6324 PyErr_SetString(PyExc_TypeError
, "required field \"col_offset\" missing from excepthandler");
6327 isinstance
= PyObject_IsInstance(obj
, (PyObject
*)ExceptHandler_type
);
6328 if (isinstance
== -1) {
6336 if (PyObject_HasAttrString(obj
, "type")) {
6338 tmp
= PyObject_GetAttrString(obj
, "type");
6339 if (tmp
== NULL
) goto failed
;
6340 res
= obj2ast_expr(tmp
, &type
, arena
);
6341 if (res
!= 0) goto failed
;
6347 if (PyObject_HasAttrString(obj
, "name")) {
6349 tmp
= PyObject_GetAttrString(obj
, "name");
6350 if (tmp
== NULL
) goto failed
;
6351 res
= obj2ast_expr(tmp
, &name
, arena
);
6352 if (res
!= 0) goto failed
;
6358 if (PyObject_HasAttrString(obj
, "body")) {
6362 tmp
= PyObject_GetAttrString(obj
, "body");
6363 if (tmp
== NULL
) goto failed
;
6364 if (!PyList_Check(tmp
)) {
6365 PyErr_Format(PyExc_TypeError
, "ExceptHandler field \"body\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
6368 len
= PyList_GET_SIZE(tmp
);
6369 body
= asdl_seq_new(len
, arena
);
6370 if (body
== NULL
) goto failed
;
6371 for (i
= 0; i
< len
; i
++) {
6373 res
= obj2ast_stmt(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
6374 if (res
!= 0) goto failed
;
6375 asdl_seq_SET(body
, i
, value
);
6380 PyErr_SetString(PyExc_TypeError
, "required field \"body\" missing from ExceptHandler");
6383 *out
= ExceptHandler(type
, name
, body
, lineno
, col_offset
,
6385 if (*out
== NULL
) goto failed
;
6389 tmp
= PyObject_Repr(obj
);
6390 if (tmp
== NULL
) goto failed
;
6391 PyErr_Format(PyExc_TypeError
, "expected some sort of excepthandler, but got %.400s", PyString_AS_STRING(tmp
));
6398 obj2ast_arguments(PyObject
* obj
, arguments_ty
* out
, PyArena
* arena
)
6400 PyObject
* tmp
= NULL
;
6406 if (PyObject_HasAttrString(obj
, "args")) {
6410 tmp
= PyObject_GetAttrString(obj
, "args");
6411 if (tmp
== NULL
) goto failed
;
6412 if (!PyList_Check(tmp
)) {
6413 PyErr_Format(PyExc_TypeError
, "arguments field \"args\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
6416 len
= PyList_GET_SIZE(tmp
);
6417 args
= asdl_seq_new(len
, arena
);
6418 if (args
== NULL
) goto failed
;
6419 for (i
= 0; i
< len
; i
++) {
6421 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
6422 if (res
!= 0) goto failed
;
6423 asdl_seq_SET(args
, i
, value
);
6428 PyErr_SetString(PyExc_TypeError
, "required field \"args\" missing from arguments");
6431 if (PyObject_HasAttrString(obj
, "vararg")) {
6433 tmp
= PyObject_GetAttrString(obj
, "vararg");
6434 if (tmp
== NULL
) goto failed
;
6435 res
= obj2ast_identifier(tmp
, &vararg
, arena
);
6436 if (res
!= 0) goto failed
;
6442 if (PyObject_HasAttrString(obj
, "kwarg")) {
6444 tmp
= PyObject_GetAttrString(obj
, "kwarg");
6445 if (tmp
== NULL
) goto failed
;
6446 res
= obj2ast_identifier(tmp
, &kwarg
, arena
);
6447 if (res
!= 0) goto failed
;
6453 if (PyObject_HasAttrString(obj
, "defaults")) {
6457 tmp
= PyObject_GetAttrString(obj
, "defaults");
6458 if (tmp
== NULL
) goto failed
;
6459 if (!PyList_Check(tmp
)) {
6460 PyErr_Format(PyExc_TypeError
, "arguments field \"defaults\" must be a list, not a %.200s", tmp
->ob_type
->tp_name
);
6463 len
= PyList_GET_SIZE(tmp
);
6464 defaults
= asdl_seq_new(len
, arena
);
6465 if (defaults
== NULL
) goto failed
;
6466 for (i
= 0; i
< len
; i
++) {
6468 res
= obj2ast_expr(PyList_GET_ITEM(tmp
, i
), &value
, arena
);
6469 if (res
!= 0) goto failed
;
6470 asdl_seq_SET(defaults
, i
, value
);
6475 PyErr_SetString(PyExc_TypeError
, "required field \"defaults\" missing from arguments");
6478 *out
= arguments(args
, vararg
, kwarg
, defaults
, arena
);
6486 obj2ast_keyword(PyObject
* obj
, keyword_ty
* out
, PyArena
* arena
)
6488 PyObject
* tmp
= NULL
;
6492 if (PyObject_HasAttrString(obj
, "arg")) {
6494 tmp
= PyObject_GetAttrString(obj
, "arg");
6495 if (tmp
== NULL
) goto failed
;
6496 res
= obj2ast_identifier(tmp
, &arg
, arena
);
6497 if (res
!= 0) goto failed
;
6501 PyErr_SetString(PyExc_TypeError
, "required field \"arg\" missing from keyword");
6504 if (PyObject_HasAttrString(obj
, "value")) {
6506 tmp
= PyObject_GetAttrString(obj
, "value");
6507 if (tmp
== NULL
) goto failed
;
6508 res
= obj2ast_expr(tmp
, &value
, arena
);
6509 if (res
!= 0) goto failed
;
6513 PyErr_SetString(PyExc_TypeError
, "required field \"value\" missing from keyword");
6516 *out
= keyword(arg
, value
, arena
);
6524 obj2ast_alias(PyObject
* obj
, alias_ty
* out
, PyArena
* arena
)
6526 PyObject
* tmp
= NULL
;
6530 if (PyObject_HasAttrString(obj
, "name")) {
6532 tmp
= PyObject_GetAttrString(obj
, "name");
6533 if (tmp
== NULL
) goto failed
;
6534 res
= obj2ast_identifier(tmp
, &name
, arena
);
6535 if (res
!= 0) goto failed
;
6539 PyErr_SetString(PyExc_TypeError
, "required field \"name\" missing from alias");
6542 if (PyObject_HasAttrString(obj
, "asname")) {
6544 tmp
= PyObject_GetAttrString(obj
, "asname");
6545 if (tmp
== NULL
) goto failed
;
6546 res
= obj2ast_identifier(tmp
, &asname
, arena
);
6547 if (res
!= 0) goto failed
;
6553 *out
= alias(name
, asname
, arena
);
6565 if (!init_types()) return;
6566 m
= Py_InitModule3("_ast", NULL
, NULL
);
6568 d
= PyModule_GetDict(m
);
6569 if (PyDict_SetItemString(d
, "AST", (PyObject
*)&AST_type
) < 0) return;
6570 if (PyModule_AddIntConstant(m
, "PyCF_ONLY_AST", PyCF_ONLY_AST
) < 0)
6572 if (PyModule_AddStringConstant(m
, "__version__", "77422") < 0)
6574 if (PyDict_SetItemString(d
, "mod", (PyObject
*)mod_type
) < 0) return;
6575 if (PyDict_SetItemString(d
, "Module", (PyObject
*)Module_type
) < 0)
6577 if (PyDict_SetItemString(d
, "Interactive", (PyObject
*)Interactive_type
)
6579 if (PyDict_SetItemString(d
, "Expression", (PyObject
*)Expression_type
) <
6581 if (PyDict_SetItemString(d
, "Suite", (PyObject
*)Suite_type
) < 0) return;
6582 if (PyDict_SetItemString(d
, "stmt", (PyObject
*)stmt_type
) < 0) return;
6583 if (PyDict_SetItemString(d
, "FunctionDef", (PyObject
*)FunctionDef_type
)
6585 if (PyDict_SetItemString(d
, "ClassDef", (PyObject
*)ClassDef_type
) < 0)
6587 if (PyDict_SetItemString(d
, "Return", (PyObject
*)Return_type
) < 0)
6589 if (PyDict_SetItemString(d
, "Delete", (PyObject
*)Delete_type
) < 0)
6591 if (PyDict_SetItemString(d
, "Assign", (PyObject
*)Assign_type
) < 0)
6593 if (PyDict_SetItemString(d
, "AugAssign", (PyObject
*)AugAssign_type
) <
6595 if (PyDict_SetItemString(d
, "Print", (PyObject
*)Print_type
) < 0) return;
6596 if (PyDict_SetItemString(d
, "For", (PyObject
*)For_type
) < 0) return;
6597 if (PyDict_SetItemString(d
, "While", (PyObject
*)While_type
) < 0) return;
6598 if (PyDict_SetItemString(d
, "If", (PyObject
*)If_type
) < 0) return;
6599 if (PyDict_SetItemString(d
, "With", (PyObject
*)With_type
) < 0) return;
6600 if (PyDict_SetItemString(d
, "Raise", (PyObject
*)Raise_type
) < 0) return;
6601 if (PyDict_SetItemString(d
, "TryExcept", (PyObject
*)TryExcept_type
) <
6603 if (PyDict_SetItemString(d
, "TryFinally", (PyObject
*)TryFinally_type
) <
6605 if (PyDict_SetItemString(d
, "Assert", (PyObject
*)Assert_type
) < 0)
6607 if (PyDict_SetItemString(d
, "Import", (PyObject
*)Import_type
) < 0)
6609 if (PyDict_SetItemString(d
, "ImportFrom", (PyObject
*)ImportFrom_type
) <
6611 if (PyDict_SetItemString(d
, "Exec", (PyObject
*)Exec_type
) < 0) return;
6612 if (PyDict_SetItemString(d
, "Global", (PyObject
*)Global_type
) < 0)
6614 if (PyDict_SetItemString(d
, "Expr", (PyObject
*)Expr_type
) < 0) return;
6615 if (PyDict_SetItemString(d
, "Pass", (PyObject
*)Pass_type
) < 0) return;
6616 if (PyDict_SetItemString(d
, "Break", (PyObject
*)Break_type
) < 0) return;
6617 if (PyDict_SetItemString(d
, "Continue", (PyObject
*)Continue_type
) < 0)
6619 if (PyDict_SetItemString(d
, "expr", (PyObject
*)expr_type
) < 0) return;
6620 if (PyDict_SetItemString(d
, "BoolOp", (PyObject
*)BoolOp_type
) < 0)
6622 if (PyDict_SetItemString(d
, "BinOp", (PyObject
*)BinOp_type
) < 0) return;
6623 if (PyDict_SetItemString(d
, "UnaryOp", (PyObject
*)UnaryOp_type
) < 0)
6625 if (PyDict_SetItemString(d
, "Lambda", (PyObject
*)Lambda_type
) < 0)
6627 if (PyDict_SetItemString(d
, "IfExp", (PyObject
*)IfExp_type
) < 0) return;
6628 if (PyDict_SetItemString(d
, "Dict", (PyObject
*)Dict_type
) < 0) return;
6629 if (PyDict_SetItemString(d
, "Set", (PyObject
*)Set_type
) < 0) return;
6630 if (PyDict_SetItemString(d
, "ListComp", (PyObject
*)ListComp_type
) < 0)
6632 if (PyDict_SetItemString(d
, "SetComp", (PyObject
*)SetComp_type
) < 0)
6634 if (PyDict_SetItemString(d
, "DictComp", (PyObject
*)DictComp_type
) < 0)
6636 if (PyDict_SetItemString(d
, "GeneratorExp",
6637 (PyObject
*)GeneratorExp_type
) < 0) return;
6638 if (PyDict_SetItemString(d
, "Yield", (PyObject
*)Yield_type
) < 0) return;
6639 if (PyDict_SetItemString(d
, "Compare", (PyObject
*)Compare_type
) < 0)
6641 if (PyDict_SetItemString(d
, "Call", (PyObject
*)Call_type
) < 0) return;
6642 if (PyDict_SetItemString(d
, "Repr", (PyObject
*)Repr_type
) < 0) return;
6643 if (PyDict_SetItemString(d
, "Num", (PyObject
*)Num_type
) < 0) return;
6644 if (PyDict_SetItemString(d
, "Str", (PyObject
*)Str_type
) < 0) return;
6645 if (PyDict_SetItemString(d
, "Attribute", (PyObject
*)Attribute_type
) <
6647 if (PyDict_SetItemString(d
, "Subscript", (PyObject
*)Subscript_type
) <
6649 if (PyDict_SetItemString(d
, "Name", (PyObject
*)Name_type
) < 0) return;
6650 if (PyDict_SetItemString(d
, "List", (PyObject
*)List_type
) < 0) return;
6651 if (PyDict_SetItemString(d
, "Tuple", (PyObject
*)Tuple_type
) < 0) return;
6652 if (PyDict_SetItemString(d
, "expr_context",
6653 (PyObject
*)expr_context_type
) < 0) return;
6654 if (PyDict_SetItemString(d
, "Load", (PyObject
*)Load_type
) < 0) return;
6655 if (PyDict_SetItemString(d
, "Store", (PyObject
*)Store_type
) < 0) return;
6656 if (PyDict_SetItemString(d
, "Del", (PyObject
*)Del_type
) < 0) return;
6657 if (PyDict_SetItemString(d
, "AugLoad", (PyObject
*)AugLoad_type
) < 0)
6659 if (PyDict_SetItemString(d
, "AugStore", (PyObject
*)AugStore_type
) < 0)
6661 if (PyDict_SetItemString(d
, "Param", (PyObject
*)Param_type
) < 0) return;
6662 if (PyDict_SetItemString(d
, "slice", (PyObject
*)slice_type
) < 0) return;
6663 if (PyDict_SetItemString(d
, "Ellipsis", (PyObject
*)Ellipsis_type
) < 0)
6665 if (PyDict_SetItemString(d
, "Slice", (PyObject
*)Slice_type
) < 0) return;
6666 if (PyDict_SetItemString(d
, "ExtSlice", (PyObject
*)ExtSlice_type
) < 0)
6668 if (PyDict_SetItemString(d
, "Index", (PyObject
*)Index_type
) < 0) return;
6669 if (PyDict_SetItemString(d
, "boolop", (PyObject
*)boolop_type
) < 0)
6671 if (PyDict_SetItemString(d
, "And", (PyObject
*)And_type
) < 0) return;
6672 if (PyDict_SetItemString(d
, "Or", (PyObject
*)Or_type
) < 0) return;
6673 if (PyDict_SetItemString(d
, "operator", (PyObject
*)operator_type
) < 0)
6675 if (PyDict_SetItemString(d
, "Add", (PyObject
*)Add_type
) < 0) return;
6676 if (PyDict_SetItemString(d
, "Sub", (PyObject
*)Sub_type
) < 0) return;
6677 if (PyDict_SetItemString(d
, "Mult", (PyObject
*)Mult_type
) < 0) return;
6678 if (PyDict_SetItemString(d
, "Div", (PyObject
*)Div_type
) < 0) return;
6679 if (PyDict_SetItemString(d
, "Mod", (PyObject
*)Mod_type
) < 0) return;
6680 if (PyDict_SetItemString(d
, "Pow", (PyObject
*)Pow_type
) < 0) return;
6681 if (PyDict_SetItemString(d
, "LShift", (PyObject
*)LShift_type
) < 0)
6683 if (PyDict_SetItemString(d
, "RShift", (PyObject
*)RShift_type
) < 0)
6685 if (PyDict_SetItemString(d
, "BitOr", (PyObject
*)BitOr_type
) < 0) return;
6686 if (PyDict_SetItemString(d
, "BitXor", (PyObject
*)BitXor_type
) < 0)
6688 if (PyDict_SetItemString(d
, "BitAnd", (PyObject
*)BitAnd_type
) < 0)
6690 if (PyDict_SetItemString(d
, "FloorDiv", (PyObject
*)FloorDiv_type
) < 0)
6692 if (PyDict_SetItemString(d
, "unaryop", (PyObject
*)unaryop_type
) < 0)
6694 if (PyDict_SetItemString(d
, "Invert", (PyObject
*)Invert_type
) < 0)
6696 if (PyDict_SetItemString(d
, "Not", (PyObject
*)Not_type
) < 0) return;
6697 if (PyDict_SetItemString(d
, "UAdd", (PyObject
*)UAdd_type
) < 0) return;
6698 if (PyDict_SetItemString(d
, "USub", (PyObject
*)USub_type
) < 0) return;
6699 if (PyDict_SetItemString(d
, "cmpop", (PyObject
*)cmpop_type
) < 0) return;
6700 if (PyDict_SetItemString(d
, "Eq", (PyObject
*)Eq_type
) < 0) return;
6701 if (PyDict_SetItemString(d
, "NotEq", (PyObject
*)NotEq_type
) < 0) return;
6702 if (PyDict_SetItemString(d
, "Lt", (PyObject
*)Lt_type
) < 0) return;
6703 if (PyDict_SetItemString(d
, "LtE", (PyObject
*)LtE_type
) < 0) return;
6704 if (PyDict_SetItemString(d
, "Gt", (PyObject
*)Gt_type
) < 0) return;
6705 if (PyDict_SetItemString(d
, "GtE", (PyObject
*)GtE_type
) < 0) return;
6706 if (PyDict_SetItemString(d
, "Is", (PyObject
*)Is_type
) < 0) return;
6707 if (PyDict_SetItemString(d
, "IsNot", (PyObject
*)IsNot_type
) < 0) return;
6708 if (PyDict_SetItemString(d
, "In", (PyObject
*)In_type
) < 0) return;
6709 if (PyDict_SetItemString(d
, "NotIn", (PyObject
*)NotIn_type
) < 0) return;
6710 if (PyDict_SetItemString(d
, "comprehension",
6711 (PyObject
*)comprehension_type
) < 0) return;
6712 if (PyDict_SetItemString(d
, "excepthandler",
6713 (PyObject
*)excepthandler_type
) < 0) return;
6714 if (PyDict_SetItemString(d
, "ExceptHandler",
6715 (PyObject
*)ExceptHandler_type
) < 0) return;
6716 if (PyDict_SetItemString(d
, "arguments", (PyObject
*)arguments_type
) <
6718 if (PyDict_SetItemString(d
, "keyword", (PyObject
*)keyword_type
) < 0)
6720 if (PyDict_SetItemString(d
, "alias", (PyObject
*)alias_type
) < 0) return;
6724 PyObject
* PyAST_mod2obj(mod_ty t
)
6727 return ast2obj_mod(t
);
6730 /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */
6731 mod_ty
PyAST_obj2mod(PyObject
* ast
, PyArena
* arena
, int mode
)
6734 PyObject
*req_type
[] = {(PyObject
*)Module_type
, (PyObject
*)Expression_type
,
6735 (PyObject
*)Interactive_type
};
6736 char *req_name
[] = {"Module", "Expression", "Interactive"};
6738 assert(0 <= mode
&& mode
<= 2);
6742 isinstance
= PyObject_IsInstance(ast
, req_type
[mode
]);
6743 if (isinstance
== -1)
6746 PyErr_Format(PyExc_TypeError
, "expected %s node, got %.400s",
6747 req_name
[mode
], Py_TYPE(ast
)->tp_name
);
6750 if (obj2ast_mod(ast
, &res
, arena
) != 0)
6756 int PyAST_Check(PyObject
* obj
)
6759 return PyObject_IsInstance(obj
, (PyObject
*)&AST_type
);