Catch situations where currentframe() returns None. See SF patch #1447410, this is...
[python.git] / Python / Python-ast.c
blob3f8345ebf483107499593052c841e5afd813c61a
1 /* File automatically generated by Parser/asdl_c.py */
3 #include "Python.h"
4 #include "Python-ast.h"
6 static PyTypeObject* AST_type;
7 static PyTypeObject *mod_type;
8 static PyObject* ast2obj_mod(void*);
9 static PyTypeObject *Module_type;
10 static char *Module_fields[]={
11 "body",
13 static PyTypeObject *Interactive_type;
14 static char *Interactive_fields[]={
15 "body",
17 static PyTypeObject *Expression_type;
18 static char *Expression_fields[]={
19 "body",
21 static PyTypeObject *Suite_type;
22 static char *Suite_fields[]={
23 "body",
25 static PyTypeObject *stmt_type;
26 static char *stmt_attributes[] = {
27 "lineno",
28 "col_offset",
30 static PyObject* ast2obj_stmt(void*);
31 static PyTypeObject *FunctionDef_type;
32 static char *FunctionDef_fields[]={
33 "name",
34 "args",
35 "body",
36 "decorators",
38 static PyTypeObject *ClassDef_type;
39 static char *ClassDef_fields[]={
40 "name",
41 "bases",
42 "body",
44 static PyTypeObject *Return_type;
45 static char *Return_fields[]={
46 "value",
48 static PyTypeObject *Delete_type;
49 static char *Delete_fields[]={
50 "targets",
52 static PyTypeObject *Assign_type;
53 static char *Assign_fields[]={
54 "targets",
55 "value",
57 static PyTypeObject *AugAssign_type;
58 static char *AugAssign_fields[]={
59 "target",
60 "op",
61 "value",
63 static PyTypeObject *Print_type;
64 static char *Print_fields[]={
65 "dest",
66 "values",
67 "nl",
69 static PyTypeObject *For_type;
70 static char *For_fields[]={
71 "target",
72 "iter",
73 "body",
74 "orelse",
76 static PyTypeObject *While_type;
77 static char *While_fields[]={
78 "test",
79 "body",
80 "orelse",
82 static PyTypeObject *If_type;
83 static char *If_fields[]={
84 "test",
85 "body",
86 "orelse",
88 static PyTypeObject *With_type;
89 static char *With_fields[]={
90 "context_expr",
91 "optional_vars",
92 "body",
94 static PyTypeObject *Raise_type;
95 static char *Raise_fields[]={
96 "type",
97 "inst",
98 "tback",
100 static PyTypeObject *TryExcept_type;
101 static char *TryExcept_fields[]={
102 "body",
103 "handlers",
104 "orelse",
106 static PyTypeObject *TryFinally_type;
107 static char *TryFinally_fields[]={
108 "body",
109 "finalbody",
111 static PyTypeObject *Assert_type;
112 static char *Assert_fields[]={
113 "test",
114 "msg",
116 static PyTypeObject *Import_type;
117 static char *Import_fields[]={
118 "names",
120 static PyTypeObject *ImportFrom_type;
121 static char *ImportFrom_fields[]={
122 "module",
123 "names",
124 "level",
126 static PyTypeObject *Exec_type;
127 static char *Exec_fields[]={
128 "body",
129 "globals",
130 "locals",
132 static PyTypeObject *Global_type;
133 static char *Global_fields[]={
134 "names",
136 static PyTypeObject *Expr_type;
137 static char *Expr_fields[]={
138 "value",
140 static PyTypeObject *Pass_type;
141 static PyTypeObject *Break_type;
142 static PyTypeObject *Continue_type;
143 static PyTypeObject *expr_type;
144 static char *expr_attributes[] = {
145 "lineno",
146 "col_offset",
148 static PyObject* ast2obj_expr(void*);
149 static PyTypeObject *BoolOp_type;
150 static char *BoolOp_fields[]={
151 "op",
152 "values",
154 static PyTypeObject *BinOp_type;
155 static char *BinOp_fields[]={
156 "left",
157 "op",
158 "right",
160 static PyTypeObject *UnaryOp_type;
161 static char *UnaryOp_fields[]={
162 "op",
163 "operand",
165 static PyTypeObject *Lambda_type;
166 static char *Lambda_fields[]={
167 "args",
168 "body",
170 static PyTypeObject *IfExp_type;
171 static char *IfExp_fields[]={
172 "test",
173 "body",
174 "orelse",
176 static PyTypeObject *Dict_type;
177 static char *Dict_fields[]={
178 "keys",
179 "values",
181 static PyTypeObject *ListComp_type;
182 static char *ListComp_fields[]={
183 "elt",
184 "generators",
186 static PyTypeObject *GeneratorExp_type;
187 static char *GeneratorExp_fields[]={
188 "elt",
189 "generators",
191 static PyTypeObject *Yield_type;
192 static char *Yield_fields[]={
193 "value",
195 static PyTypeObject *Compare_type;
196 static char *Compare_fields[]={
197 "left",
198 "ops",
199 "comparators",
201 static PyTypeObject *Call_type;
202 static char *Call_fields[]={
203 "func",
204 "args",
205 "keywords",
206 "starargs",
207 "kwargs",
209 static PyTypeObject *Repr_type;
210 static char *Repr_fields[]={
211 "value",
213 static PyTypeObject *Num_type;
214 static char *Num_fields[]={
215 "n",
217 static PyTypeObject *Str_type;
218 static char *Str_fields[]={
219 "s",
221 static PyTypeObject *Attribute_type;
222 static char *Attribute_fields[]={
223 "value",
224 "attr",
225 "ctx",
227 static PyTypeObject *Subscript_type;
228 static char *Subscript_fields[]={
229 "value",
230 "slice",
231 "ctx",
233 static PyTypeObject *Name_type;
234 static char *Name_fields[]={
235 "id",
236 "ctx",
238 static PyTypeObject *List_type;
239 static char *List_fields[]={
240 "elts",
241 "ctx",
243 static PyTypeObject *Tuple_type;
244 static char *Tuple_fields[]={
245 "elts",
246 "ctx",
248 static PyTypeObject *expr_context_type;
249 static PyObject *Load_singleton, *Store_singleton, *Del_singleton,
250 *AugLoad_singleton, *AugStore_singleton, *Param_singleton;
251 static PyObject* ast2obj_expr_context(expr_context_ty);
252 static PyTypeObject *Load_type;
253 static PyTypeObject *Store_type;
254 static PyTypeObject *Del_type;
255 static PyTypeObject *AugLoad_type;
256 static PyTypeObject *AugStore_type;
257 static PyTypeObject *Param_type;
258 static PyTypeObject *slice_type;
259 static PyObject* ast2obj_slice(void*);
260 static PyTypeObject *Ellipsis_type;
261 static PyTypeObject *Slice_type;
262 static char *Slice_fields[]={
263 "lower",
264 "upper",
265 "step",
267 static PyTypeObject *ExtSlice_type;
268 static char *ExtSlice_fields[]={
269 "dims",
271 static PyTypeObject *Index_type;
272 static char *Index_fields[]={
273 "value",
275 static PyTypeObject *boolop_type;
276 static PyObject *And_singleton, *Or_singleton;
277 static PyObject* ast2obj_boolop(boolop_ty);
278 static PyTypeObject *And_type;
279 static PyTypeObject *Or_type;
280 static PyTypeObject *operator_type;
281 static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton,
282 *Div_singleton, *Mod_singleton, *Pow_singleton, *LShift_singleton,
283 *RShift_singleton, *BitOr_singleton, *BitXor_singleton, *BitAnd_singleton,
284 *FloorDiv_singleton;
285 static PyObject* ast2obj_operator(operator_ty);
286 static PyTypeObject *Add_type;
287 static PyTypeObject *Sub_type;
288 static PyTypeObject *Mult_type;
289 static PyTypeObject *Div_type;
290 static PyTypeObject *Mod_type;
291 static PyTypeObject *Pow_type;
292 static PyTypeObject *LShift_type;
293 static PyTypeObject *RShift_type;
294 static PyTypeObject *BitOr_type;
295 static PyTypeObject *BitXor_type;
296 static PyTypeObject *BitAnd_type;
297 static PyTypeObject *FloorDiv_type;
298 static PyTypeObject *unaryop_type;
299 static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton,
300 *USub_singleton;
301 static PyObject* ast2obj_unaryop(unaryop_ty);
302 static PyTypeObject *Invert_type;
303 static PyTypeObject *Not_type;
304 static PyTypeObject *UAdd_type;
305 static PyTypeObject *USub_type;
306 static PyTypeObject *cmpop_type;
307 static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton,
308 *Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton,
309 *NotIn_singleton;
310 static PyObject* ast2obj_cmpop(cmpop_ty);
311 static PyTypeObject *Eq_type;
312 static PyTypeObject *NotEq_type;
313 static PyTypeObject *Lt_type;
314 static PyTypeObject *LtE_type;
315 static PyTypeObject *Gt_type;
316 static PyTypeObject *GtE_type;
317 static PyTypeObject *Is_type;
318 static PyTypeObject *IsNot_type;
319 static PyTypeObject *In_type;
320 static PyTypeObject *NotIn_type;
321 static PyTypeObject *comprehension_type;
322 static PyObject* ast2obj_comprehension(void*);
323 static char *comprehension_fields[]={
324 "target",
325 "iter",
326 "ifs",
328 static PyTypeObject *excepthandler_type;
329 static PyObject* ast2obj_excepthandler(void*);
330 static char *excepthandler_fields[]={
331 "type",
332 "name",
333 "body",
335 static PyTypeObject *arguments_type;
336 static PyObject* ast2obj_arguments(void*);
337 static char *arguments_fields[]={
338 "args",
339 "vararg",
340 "kwarg",
341 "defaults",
343 static PyTypeObject *keyword_type;
344 static PyObject* ast2obj_keyword(void*);
345 static char *keyword_fields[]={
346 "arg",
347 "value",
349 static PyTypeObject *alias_type;
350 static PyObject* ast2obj_alias(void*);
351 static char *alias_fields[]={
352 "name",
353 "asname",
357 static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields)
359 PyObject *fnames, *result;
360 int i;
361 if (num_fields) {
362 fnames = PyTuple_New(num_fields);
363 if (!fnames) return NULL;
364 } else {
365 fnames = Py_None;
366 Py_INCREF(Py_None);
368 for(i=0; i < num_fields; i++) {
369 PyObject *field = PyString_FromString(fields[i]);
370 if (!field) {
371 Py_DECREF(fnames);
372 return NULL;
374 PyTuple_SET_ITEM(fnames, i, field);
376 result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}",
377 type, base, "_fields", fnames, "__module__", "_ast");
378 Py_DECREF(fnames);
379 return (PyTypeObject*)result;
382 static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)
384 int i;
385 PyObject *s, *l = PyList_New(num_fields);
386 if (!l) return 0;
387 for(i=0; i < num_fields; i++) {
388 s = PyString_FromString(attrs[i]);
389 if (!s) {
390 Py_DECREF(l);
391 return 0;
393 PyList_SET_ITEM(l, i, s);
395 return PyObject_SetAttrString((PyObject*)type, "_attributes", l) >=0;
398 static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
400 int i, n = asdl_seq_LEN(seq);
401 PyObject *result = PyList_New(n);
402 PyObject *value;
403 if (!result)
404 return NULL;
405 for (i = 0; i < n; i++) {
406 value = func(asdl_seq_GET(seq, i));
407 if (!value) {
408 Py_DECREF(result);
409 return NULL;
411 PyList_SET_ITEM(result, i, value);
413 return result;
416 static PyObject* ast2obj_object(void *o)
418 if (!o)
419 o = Py_None;
420 Py_INCREF((PyObject*)o);
421 return (PyObject*)o;
423 #define ast2obj_identifier ast2obj_object
424 #define ast2obj_string ast2obj_object
425 static PyObject* ast2obj_bool(bool b)
427 return PyBool_FromLong(b);
430 static PyObject* ast2obj_int(bool b)
432 return PyInt_FromLong(b);
435 static int initialized;
436 static int init_types(void)
438 if (initialized) return 1;
439 AST_type = make_type("AST", &PyBaseObject_Type, NULL, 0);
440 mod_type = make_type("mod", AST_type, NULL, 0);
441 if (!mod_type) return 0;
442 if (!add_attributes(mod_type, NULL, 0)) return 0;
443 Module_type = make_type("Module", mod_type, Module_fields, 1);
444 if (!Module_type) return 0;
445 Interactive_type = make_type("Interactive", mod_type,
446 Interactive_fields, 1);
447 if (!Interactive_type) return 0;
448 Expression_type = make_type("Expression", mod_type, Expression_fields,
450 if (!Expression_type) return 0;
451 Suite_type = make_type("Suite", mod_type, Suite_fields, 1);
452 if (!Suite_type) return 0;
453 stmt_type = make_type("stmt", AST_type, NULL, 0);
454 if (!stmt_type) return 0;
455 if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0;
456 FunctionDef_type = make_type("FunctionDef", stmt_type,
457 FunctionDef_fields, 4);
458 if (!FunctionDef_type) return 0;
459 ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 3);
460 if (!ClassDef_type) return 0;
461 Return_type = make_type("Return", stmt_type, Return_fields, 1);
462 if (!Return_type) return 0;
463 Delete_type = make_type("Delete", stmt_type, Delete_fields, 1);
464 if (!Delete_type) return 0;
465 Assign_type = make_type("Assign", stmt_type, Assign_fields, 2);
466 if (!Assign_type) return 0;
467 AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3);
468 if (!AugAssign_type) return 0;
469 Print_type = make_type("Print", stmt_type, Print_fields, 3);
470 if (!Print_type) return 0;
471 For_type = make_type("For", stmt_type, For_fields, 4);
472 if (!For_type) return 0;
473 While_type = make_type("While", stmt_type, While_fields, 3);
474 if (!While_type) return 0;
475 If_type = make_type("If", stmt_type, If_fields, 3);
476 if (!If_type) return 0;
477 With_type = make_type("With", stmt_type, With_fields, 3);
478 if (!With_type) return 0;
479 Raise_type = make_type("Raise", stmt_type, Raise_fields, 3);
480 if (!Raise_type) return 0;
481 TryExcept_type = make_type("TryExcept", stmt_type, TryExcept_fields, 3);
482 if (!TryExcept_type) return 0;
483 TryFinally_type = make_type("TryFinally", stmt_type, TryFinally_fields,
485 if (!TryFinally_type) return 0;
486 Assert_type = make_type("Assert", stmt_type, Assert_fields, 2);
487 if (!Assert_type) return 0;
488 Import_type = make_type("Import", stmt_type, Import_fields, 1);
489 if (!Import_type) return 0;
490 ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields,
492 if (!ImportFrom_type) return 0;
493 Exec_type = make_type("Exec", stmt_type, Exec_fields, 3);
494 if (!Exec_type) return 0;
495 Global_type = make_type("Global", stmt_type, Global_fields, 1);
496 if (!Global_type) return 0;
497 Expr_type = make_type("Expr", stmt_type, Expr_fields, 1);
498 if (!Expr_type) return 0;
499 Pass_type = make_type("Pass", stmt_type, NULL, 0);
500 if (!Pass_type) return 0;
501 Break_type = make_type("Break", stmt_type, NULL, 0);
502 if (!Break_type) return 0;
503 Continue_type = make_type("Continue", stmt_type, NULL, 0);
504 if (!Continue_type) return 0;
505 expr_type = make_type("expr", AST_type, NULL, 0);
506 if (!expr_type) return 0;
507 if (!add_attributes(expr_type, expr_attributes, 2)) return 0;
508 BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2);
509 if (!BoolOp_type) return 0;
510 BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3);
511 if (!BinOp_type) return 0;
512 UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2);
513 if (!UnaryOp_type) return 0;
514 Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2);
515 if (!Lambda_type) return 0;
516 IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3);
517 if (!IfExp_type) return 0;
518 Dict_type = make_type("Dict", expr_type, Dict_fields, 2);
519 if (!Dict_type) return 0;
520 ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2);
521 if (!ListComp_type) return 0;
522 GeneratorExp_type = make_type("GeneratorExp", expr_type,
523 GeneratorExp_fields, 2);
524 if (!GeneratorExp_type) return 0;
525 Yield_type = make_type("Yield", expr_type, Yield_fields, 1);
526 if (!Yield_type) return 0;
527 Compare_type = make_type("Compare", expr_type, Compare_fields, 3);
528 if (!Compare_type) return 0;
529 Call_type = make_type("Call", expr_type, Call_fields, 5);
530 if (!Call_type) return 0;
531 Repr_type = make_type("Repr", expr_type, Repr_fields, 1);
532 if (!Repr_type) return 0;
533 Num_type = make_type("Num", expr_type, Num_fields, 1);
534 if (!Num_type) return 0;
535 Str_type = make_type("Str", expr_type, Str_fields, 1);
536 if (!Str_type) return 0;
537 Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3);
538 if (!Attribute_type) return 0;
539 Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3);
540 if (!Subscript_type) return 0;
541 Name_type = make_type("Name", expr_type, Name_fields, 2);
542 if (!Name_type) return 0;
543 List_type = make_type("List", expr_type, List_fields, 2);
544 if (!List_type) return 0;
545 Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2);
546 if (!Tuple_type) return 0;
547 expr_context_type = make_type("expr_context", AST_type, NULL, 0);
548 if (!expr_context_type) return 0;
549 if (!add_attributes(expr_context_type, NULL, 0)) return 0;
550 Load_type = make_type("Load", expr_context_type, NULL, 0);
551 if (!Load_type) return 0;
552 Load_singleton = PyType_GenericNew(Load_type, NULL, NULL);
553 if (!Load_singleton) return 0;
554 Store_type = make_type("Store", expr_context_type, NULL, 0);
555 if (!Store_type) return 0;
556 Store_singleton = PyType_GenericNew(Store_type, NULL, NULL);
557 if (!Store_singleton) return 0;
558 Del_type = make_type("Del", expr_context_type, NULL, 0);
559 if (!Del_type) return 0;
560 Del_singleton = PyType_GenericNew(Del_type, NULL, NULL);
561 if (!Del_singleton) return 0;
562 AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0);
563 if (!AugLoad_type) return 0;
564 AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL);
565 if (!AugLoad_singleton) return 0;
566 AugStore_type = make_type("AugStore", expr_context_type, NULL, 0);
567 if (!AugStore_type) return 0;
568 AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL);
569 if (!AugStore_singleton) return 0;
570 Param_type = make_type("Param", expr_context_type, NULL, 0);
571 if (!Param_type) return 0;
572 Param_singleton = PyType_GenericNew(Param_type, NULL, NULL);
573 if (!Param_singleton) return 0;
574 slice_type = make_type("slice", AST_type, NULL, 0);
575 if (!slice_type) return 0;
576 if (!add_attributes(slice_type, NULL, 0)) return 0;
577 Ellipsis_type = make_type("Ellipsis", slice_type, NULL, 0);
578 if (!Ellipsis_type) return 0;
579 Slice_type = make_type("Slice", slice_type, Slice_fields, 3);
580 if (!Slice_type) return 0;
581 ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1);
582 if (!ExtSlice_type) return 0;
583 Index_type = make_type("Index", slice_type, Index_fields, 1);
584 if (!Index_type) return 0;
585 boolop_type = make_type("boolop", AST_type, NULL, 0);
586 if (!boolop_type) return 0;
587 if (!add_attributes(boolop_type, NULL, 0)) return 0;
588 And_type = make_type("And", boolop_type, NULL, 0);
589 if (!And_type) return 0;
590 And_singleton = PyType_GenericNew(And_type, NULL, NULL);
591 if (!And_singleton) return 0;
592 Or_type = make_type("Or", boolop_type, NULL, 0);
593 if (!Or_type) return 0;
594 Or_singleton = PyType_GenericNew(Or_type, NULL, NULL);
595 if (!Or_singleton) return 0;
596 operator_type = make_type("operator", AST_type, NULL, 0);
597 if (!operator_type) return 0;
598 if (!add_attributes(operator_type, NULL, 0)) return 0;
599 Add_type = make_type("Add", operator_type, NULL, 0);
600 if (!Add_type) return 0;
601 Add_singleton = PyType_GenericNew(Add_type, NULL, NULL);
602 if (!Add_singleton) return 0;
603 Sub_type = make_type("Sub", operator_type, NULL, 0);
604 if (!Sub_type) return 0;
605 Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL);
606 if (!Sub_singleton) return 0;
607 Mult_type = make_type("Mult", operator_type, NULL, 0);
608 if (!Mult_type) return 0;
609 Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL);
610 if (!Mult_singleton) return 0;
611 Div_type = make_type("Div", operator_type, NULL, 0);
612 if (!Div_type) return 0;
613 Div_singleton = PyType_GenericNew(Div_type, NULL, NULL);
614 if (!Div_singleton) return 0;
615 Mod_type = make_type("Mod", operator_type, NULL, 0);
616 if (!Mod_type) return 0;
617 Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL);
618 if (!Mod_singleton) return 0;
619 Pow_type = make_type("Pow", operator_type, NULL, 0);
620 if (!Pow_type) return 0;
621 Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL);
622 if (!Pow_singleton) return 0;
623 LShift_type = make_type("LShift", operator_type, NULL, 0);
624 if (!LShift_type) return 0;
625 LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL);
626 if (!LShift_singleton) return 0;
627 RShift_type = make_type("RShift", operator_type, NULL, 0);
628 if (!RShift_type) return 0;
629 RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL);
630 if (!RShift_singleton) return 0;
631 BitOr_type = make_type("BitOr", operator_type, NULL, 0);
632 if (!BitOr_type) return 0;
633 BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL);
634 if (!BitOr_singleton) return 0;
635 BitXor_type = make_type("BitXor", operator_type, NULL, 0);
636 if (!BitXor_type) return 0;
637 BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL);
638 if (!BitXor_singleton) return 0;
639 BitAnd_type = make_type("BitAnd", operator_type, NULL, 0);
640 if (!BitAnd_type) return 0;
641 BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL);
642 if (!BitAnd_singleton) return 0;
643 FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0);
644 if (!FloorDiv_type) return 0;
645 FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL);
646 if (!FloorDiv_singleton) return 0;
647 unaryop_type = make_type("unaryop", AST_type, NULL, 0);
648 if (!unaryop_type) return 0;
649 if (!add_attributes(unaryop_type, NULL, 0)) return 0;
650 Invert_type = make_type("Invert", unaryop_type, NULL, 0);
651 if (!Invert_type) return 0;
652 Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL);
653 if (!Invert_singleton) return 0;
654 Not_type = make_type("Not", unaryop_type, NULL, 0);
655 if (!Not_type) return 0;
656 Not_singleton = PyType_GenericNew(Not_type, NULL, NULL);
657 if (!Not_singleton) return 0;
658 UAdd_type = make_type("UAdd", unaryop_type, NULL, 0);
659 if (!UAdd_type) return 0;
660 UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL);
661 if (!UAdd_singleton) return 0;
662 USub_type = make_type("USub", unaryop_type, NULL, 0);
663 if (!USub_type) return 0;
664 USub_singleton = PyType_GenericNew(USub_type, NULL, NULL);
665 if (!USub_singleton) return 0;
666 cmpop_type = make_type("cmpop", AST_type, NULL, 0);
667 if (!cmpop_type) return 0;
668 if (!add_attributes(cmpop_type, NULL, 0)) return 0;
669 Eq_type = make_type("Eq", cmpop_type, NULL, 0);
670 if (!Eq_type) return 0;
671 Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL);
672 if (!Eq_singleton) return 0;
673 NotEq_type = make_type("NotEq", cmpop_type, NULL, 0);
674 if (!NotEq_type) return 0;
675 NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL);
676 if (!NotEq_singleton) return 0;
677 Lt_type = make_type("Lt", cmpop_type, NULL, 0);
678 if (!Lt_type) return 0;
679 Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL);
680 if (!Lt_singleton) return 0;
681 LtE_type = make_type("LtE", cmpop_type, NULL, 0);
682 if (!LtE_type) return 0;
683 LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL);
684 if (!LtE_singleton) return 0;
685 Gt_type = make_type("Gt", cmpop_type, NULL, 0);
686 if (!Gt_type) return 0;
687 Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL);
688 if (!Gt_singleton) return 0;
689 GtE_type = make_type("GtE", cmpop_type, NULL, 0);
690 if (!GtE_type) return 0;
691 GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL);
692 if (!GtE_singleton) return 0;
693 Is_type = make_type("Is", cmpop_type, NULL, 0);
694 if (!Is_type) return 0;
695 Is_singleton = PyType_GenericNew(Is_type, NULL, NULL);
696 if (!Is_singleton) return 0;
697 IsNot_type = make_type("IsNot", cmpop_type, NULL, 0);
698 if (!IsNot_type) return 0;
699 IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL);
700 if (!IsNot_singleton) return 0;
701 In_type = make_type("In", cmpop_type, NULL, 0);
702 if (!In_type) return 0;
703 In_singleton = PyType_GenericNew(In_type, NULL, NULL);
704 if (!In_singleton) return 0;
705 NotIn_type = make_type("NotIn", cmpop_type, NULL, 0);
706 if (!NotIn_type) return 0;
707 NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL);
708 if (!NotIn_singleton) return 0;
709 comprehension_type = make_type("comprehension", AST_type,
710 comprehension_fields, 3);
711 if (!comprehension_type) return 0;
712 excepthandler_type = make_type("excepthandler", AST_type,
713 excepthandler_fields, 3);
714 if (!excepthandler_type) return 0;
715 arguments_type = make_type("arguments", AST_type, arguments_fields, 4);
716 if (!arguments_type) return 0;
717 keyword_type = make_type("keyword", AST_type, keyword_fields, 2);
718 if (!keyword_type) return 0;
719 alias_type = make_type("alias", AST_type, alias_fields, 2);
720 if (!alias_type) return 0;
721 initialized = 1;
722 return 1;
725 mod_ty
726 Module(asdl_seq * body, PyArena *arena)
728 mod_ty p;
729 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
730 if (!p) {
731 PyErr_NoMemory();
732 return NULL;
734 p->kind = Module_kind;
735 p->v.Module.body = body;
736 return p;
739 mod_ty
740 Interactive(asdl_seq * body, PyArena *arena)
742 mod_ty p;
743 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
744 if (!p) {
745 PyErr_NoMemory();
746 return NULL;
748 p->kind = Interactive_kind;
749 p->v.Interactive.body = body;
750 return p;
753 mod_ty
754 Expression(expr_ty body, PyArena *arena)
756 mod_ty p;
757 if (!body) {
758 PyErr_SetString(PyExc_ValueError,
759 "field body is required for Expression");
760 return NULL;
762 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
763 if (!p) {
764 PyErr_NoMemory();
765 return NULL;
767 p->kind = Expression_kind;
768 p->v.Expression.body = body;
769 return p;
772 mod_ty
773 Suite(asdl_seq * body, PyArena *arena)
775 mod_ty p;
776 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
777 if (!p) {
778 PyErr_NoMemory();
779 return NULL;
781 p->kind = Suite_kind;
782 p->v.Suite.body = body;
783 return p;
786 stmt_ty
787 FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
788 decorators, int lineno, int col_offset, PyArena *arena)
790 stmt_ty p;
791 if (!name) {
792 PyErr_SetString(PyExc_ValueError,
793 "field name is required for FunctionDef");
794 return NULL;
796 if (!args) {
797 PyErr_SetString(PyExc_ValueError,
798 "field args is required for FunctionDef");
799 return NULL;
801 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
802 if (!p) {
803 PyErr_NoMemory();
804 return NULL;
806 p->kind = FunctionDef_kind;
807 p->v.FunctionDef.name = name;
808 p->v.FunctionDef.args = args;
809 p->v.FunctionDef.body = body;
810 p->v.FunctionDef.decorators = decorators;
811 p->lineno = lineno;
812 p->col_offset = col_offset;
813 return p;
816 stmt_ty
817 ClassDef(identifier name, asdl_seq * bases, asdl_seq * body, int lineno, int
818 col_offset, PyArena *arena)
820 stmt_ty p;
821 if (!name) {
822 PyErr_SetString(PyExc_ValueError,
823 "field name is required for ClassDef");
824 return NULL;
826 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
827 if (!p) {
828 PyErr_NoMemory();
829 return NULL;
831 p->kind = ClassDef_kind;
832 p->v.ClassDef.name = name;
833 p->v.ClassDef.bases = bases;
834 p->v.ClassDef.body = body;
835 p->lineno = lineno;
836 p->col_offset = col_offset;
837 return p;
840 stmt_ty
841 Return(expr_ty value, int lineno, int col_offset, PyArena *arena)
843 stmt_ty p;
844 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
845 if (!p) {
846 PyErr_NoMemory();
847 return NULL;
849 p->kind = Return_kind;
850 p->v.Return.value = value;
851 p->lineno = lineno;
852 p->col_offset = col_offset;
853 return p;
856 stmt_ty
857 Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena)
859 stmt_ty p;
860 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
861 if (!p) {
862 PyErr_NoMemory();
863 return NULL;
865 p->kind = Delete_kind;
866 p->v.Delete.targets = targets;
867 p->lineno = lineno;
868 p->col_offset = col_offset;
869 return p;
872 stmt_ty
873 Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena
874 *arena)
876 stmt_ty p;
877 if (!value) {
878 PyErr_SetString(PyExc_ValueError,
879 "field value is required for Assign");
880 return NULL;
882 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
883 if (!p) {
884 PyErr_NoMemory();
885 return NULL;
887 p->kind = Assign_kind;
888 p->v.Assign.targets = targets;
889 p->v.Assign.value = value;
890 p->lineno = lineno;
891 p->col_offset = col_offset;
892 return p;
895 stmt_ty
896 AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
897 col_offset, PyArena *arena)
899 stmt_ty p;
900 if (!target) {
901 PyErr_SetString(PyExc_ValueError,
902 "field target is required for AugAssign");
903 return NULL;
905 if (!op) {
906 PyErr_SetString(PyExc_ValueError,
907 "field op is required for AugAssign");
908 return NULL;
910 if (!value) {
911 PyErr_SetString(PyExc_ValueError,
912 "field value is required for AugAssign");
913 return NULL;
915 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
916 if (!p) {
917 PyErr_NoMemory();
918 return NULL;
920 p->kind = AugAssign_kind;
921 p->v.AugAssign.target = target;
922 p->v.AugAssign.op = op;
923 p->v.AugAssign.value = value;
924 p->lineno = lineno;
925 p->col_offset = col_offset;
926 return p;
929 stmt_ty
930 Print(expr_ty dest, asdl_seq * values, bool nl, int lineno, int col_offset,
931 PyArena *arena)
933 stmt_ty p;
934 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
935 if (!p) {
936 PyErr_NoMemory();
937 return NULL;
939 p->kind = Print_kind;
940 p->v.Print.dest = dest;
941 p->v.Print.values = values;
942 p->v.Print.nl = nl;
943 p->lineno = lineno;
944 p->col_offset = col_offset;
945 return p;
948 stmt_ty
949 For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int
950 lineno, int col_offset, PyArena *arena)
952 stmt_ty p;
953 if (!target) {
954 PyErr_SetString(PyExc_ValueError,
955 "field target is required for For");
956 return NULL;
958 if (!iter) {
959 PyErr_SetString(PyExc_ValueError,
960 "field iter is required for For");
961 return NULL;
963 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
964 if (!p) {
965 PyErr_NoMemory();
966 return NULL;
968 p->kind = For_kind;
969 p->v.For.target = target;
970 p->v.For.iter = iter;
971 p->v.For.body = body;
972 p->v.For.orelse = orelse;
973 p->lineno = lineno;
974 p->col_offset = col_offset;
975 return p;
978 stmt_ty
979 While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
980 col_offset, PyArena *arena)
982 stmt_ty p;
983 if (!test) {
984 PyErr_SetString(PyExc_ValueError,
985 "field test is required for While");
986 return NULL;
988 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
989 if (!p) {
990 PyErr_NoMemory();
991 return NULL;
993 p->kind = While_kind;
994 p->v.While.test = test;
995 p->v.While.body = body;
996 p->v.While.orelse = orelse;
997 p->lineno = lineno;
998 p->col_offset = col_offset;
999 return p;
1002 stmt_ty
1003 If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
1004 col_offset, PyArena *arena)
1006 stmt_ty p;
1007 if (!test) {
1008 PyErr_SetString(PyExc_ValueError,
1009 "field test is required for If");
1010 return NULL;
1012 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1013 if (!p) {
1014 PyErr_NoMemory();
1015 return NULL;
1017 p->kind = If_kind;
1018 p->v.If.test = test;
1019 p->v.If.body = body;
1020 p->v.If.orelse = orelse;
1021 p->lineno = lineno;
1022 p->col_offset = col_offset;
1023 return p;
1026 stmt_ty
1027 With(expr_ty context_expr, expr_ty optional_vars, asdl_seq * body, int lineno,
1028 int col_offset, PyArena *arena)
1030 stmt_ty p;
1031 if (!context_expr) {
1032 PyErr_SetString(PyExc_ValueError,
1033 "field context_expr is required for With");
1034 return NULL;
1036 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1037 if (!p) {
1038 PyErr_NoMemory();
1039 return NULL;
1041 p->kind = With_kind;
1042 p->v.With.context_expr = context_expr;
1043 p->v.With.optional_vars = optional_vars;
1044 p->v.With.body = body;
1045 p->lineno = lineno;
1046 p->col_offset = col_offset;
1047 return p;
1050 stmt_ty
1051 Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno, int col_offset,
1052 PyArena *arena)
1054 stmt_ty p;
1055 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1056 if (!p) {
1057 PyErr_NoMemory();
1058 return NULL;
1060 p->kind = Raise_kind;
1061 p->v.Raise.type = type;
1062 p->v.Raise.inst = inst;
1063 p->v.Raise.tback = tback;
1064 p->lineno = lineno;
1065 p->col_offset = col_offset;
1066 return p;
1069 stmt_ty
1070 TryExcept(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, int lineno,
1071 int col_offset, PyArena *arena)
1073 stmt_ty p;
1074 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1075 if (!p) {
1076 PyErr_NoMemory();
1077 return NULL;
1079 p->kind = TryExcept_kind;
1080 p->v.TryExcept.body = body;
1081 p->v.TryExcept.handlers = handlers;
1082 p->v.TryExcept.orelse = orelse;
1083 p->lineno = lineno;
1084 p->col_offset = col_offset;
1085 return p;
1088 stmt_ty
1089 TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, int col_offset,
1090 PyArena *arena)
1092 stmt_ty p;
1093 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1094 if (!p) {
1095 PyErr_NoMemory();
1096 return NULL;
1098 p->kind = TryFinally_kind;
1099 p->v.TryFinally.body = body;
1100 p->v.TryFinally.finalbody = finalbody;
1101 p->lineno = lineno;
1102 p->col_offset = col_offset;
1103 return p;
1106 stmt_ty
1107 Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, PyArena *arena)
1109 stmt_ty p;
1110 if (!test) {
1111 PyErr_SetString(PyExc_ValueError,
1112 "field test is required for Assert");
1113 return NULL;
1115 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1116 if (!p) {
1117 PyErr_NoMemory();
1118 return NULL;
1120 p->kind = Assert_kind;
1121 p->v.Assert.test = test;
1122 p->v.Assert.msg = msg;
1123 p->lineno = lineno;
1124 p->col_offset = col_offset;
1125 return p;
1128 stmt_ty
1129 Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
1131 stmt_ty p;
1132 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1133 if (!p) {
1134 PyErr_NoMemory();
1135 return NULL;
1137 p->kind = Import_kind;
1138 p->v.Import.names = names;
1139 p->lineno = lineno;
1140 p->col_offset = col_offset;
1141 return p;
1144 stmt_ty
1145 ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int
1146 col_offset, PyArena *arena)
1148 stmt_ty p;
1149 if (!module) {
1150 PyErr_SetString(PyExc_ValueError,
1151 "field module is required for ImportFrom");
1152 return NULL;
1154 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1155 if (!p) {
1156 PyErr_NoMemory();
1157 return NULL;
1159 p->kind = ImportFrom_kind;
1160 p->v.ImportFrom.module = module;
1161 p->v.ImportFrom.names = names;
1162 p->v.ImportFrom.level = level;
1163 p->lineno = lineno;
1164 p->col_offset = col_offset;
1165 return p;
1168 stmt_ty
1169 Exec(expr_ty body, expr_ty globals, expr_ty locals, int lineno, int col_offset,
1170 PyArena *arena)
1172 stmt_ty p;
1173 if (!body) {
1174 PyErr_SetString(PyExc_ValueError,
1175 "field body is required for Exec");
1176 return NULL;
1178 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1179 if (!p) {
1180 PyErr_NoMemory();
1181 return NULL;
1183 p->kind = Exec_kind;
1184 p->v.Exec.body = body;
1185 p->v.Exec.globals = globals;
1186 p->v.Exec.locals = locals;
1187 p->lineno = lineno;
1188 p->col_offset = col_offset;
1189 return p;
1192 stmt_ty
1193 Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
1195 stmt_ty p;
1196 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1197 if (!p) {
1198 PyErr_NoMemory();
1199 return NULL;
1201 p->kind = Global_kind;
1202 p->v.Global.names = names;
1203 p->lineno = lineno;
1204 p->col_offset = col_offset;
1205 return p;
1208 stmt_ty
1209 Expr(expr_ty value, int lineno, int col_offset, PyArena *arena)
1211 stmt_ty p;
1212 if (!value) {
1213 PyErr_SetString(PyExc_ValueError,
1214 "field value is required for Expr");
1215 return NULL;
1217 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1218 if (!p) {
1219 PyErr_NoMemory();
1220 return NULL;
1222 p->kind = Expr_kind;
1223 p->v.Expr.value = value;
1224 p->lineno = lineno;
1225 p->col_offset = col_offset;
1226 return p;
1229 stmt_ty
1230 Pass(int lineno, int col_offset, PyArena *arena)
1232 stmt_ty p;
1233 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1234 if (!p) {
1235 PyErr_NoMemory();
1236 return NULL;
1238 p->kind = Pass_kind;
1239 p->lineno = lineno;
1240 p->col_offset = col_offset;
1241 return p;
1244 stmt_ty
1245 Break(int lineno, int col_offset, PyArena *arena)
1247 stmt_ty p;
1248 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1249 if (!p) {
1250 PyErr_NoMemory();
1251 return NULL;
1253 p->kind = Break_kind;
1254 p->lineno = lineno;
1255 p->col_offset = col_offset;
1256 return p;
1259 stmt_ty
1260 Continue(int lineno, int col_offset, PyArena *arena)
1262 stmt_ty p;
1263 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1264 if (!p) {
1265 PyErr_NoMemory();
1266 return NULL;
1268 p->kind = Continue_kind;
1269 p->lineno = lineno;
1270 p->col_offset = col_offset;
1271 return p;
1274 expr_ty
1275 BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena
1276 *arena)
1278 expr_ty p;
1279 if (!op) {
1280 PyErr_SetString(PyExc_ValueError,
1281 "field op is required for BoolOp");
1282 return NULL;
1284 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1285 if (!p) {
1286 PyErr_NoMemory();
1287 return NULL;
1289 p->kind = BoolOp_kind;
1290 p->v.BoolOp.op = op;
1291 p->v.BoolOp.values = values;
1292 p->lineno = lineno;
1293 p->col_offset = col_offset;
1294 return p;
1297 expr_ty
1298 BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset,
1299 PyArena *arena)
1301 expr_ty p;
1302 if (!left) {
1303 PyErr_SetString(PyExc_ValueError,
1304 "field left is required for BinOp");
1305 return NULL;
1307 if (!op) {
1308 PyErr_SetString(PyExc_ValueError,
1309 "field op is required for BinOp");
1310 return NULL;
1312 if (!right) {
1313 PyErr_SetString(PyExc_ValueError,
1314 "field right is required for BinOp");
1315 return NULL;
1317 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1318 if (!p) {
1319 PyErr_NoMemory();
1320 return NULL;
1322 p->kind = BinOp_kind;
1323 p->v.BinOp.left = left;
1324 p->v.BinOp.op = op;
1325 p->v.BinOp.right = right;
1326 p->lineno = lineno;
1327 p->col_offset = col_offset;
1328 return p;
1331 expr_ty
1332 UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena
1333 *arena)
1335 expr_ty p;
1336 if (!op) {
1337 PyErr_SetString(PyExc_ValueError,
1338 "field op is required for UnaryOp");
1339 return NULL;
1341 if (!operand) {
1342 PyErr_SetString(PyExc_ValueError,
1343 "field operand is required for UnaryOp");
1344 return NULL;
1346 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1347 if (!p) {
1348 PyErr_NoMemory();
1349 return NULL;
1351 p->kind = UnaryOp_kind;
1352 p->v.UnaryOp.op = op;
1353 p->v.UnaryOp.operand = operand;
1354 p->lineno = lineno;
1355 p->col_offset = col_offset;
1356 return p;
1359 expr_ty
1360 Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena
1361 *arena)
1363 expr_ty p;
1364 if (!args) {
1365 PyErr_SetString(PyExc_ValueError,
1366 "field args is required for Lambda");
1367 return NULL;
1369 if (!body) {
1370 PyErr_SetString(PyExc_ValueError,
1371 "field body is required for Lambda");
1372 return NULL;
1374 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1375 if (!p) {
1376 PyErr_NoMemory();
1377 return NULL;
1379 p->kind = Lambda_kind;
1380 p->v.Lambda.args = args;
1381 p->v.Lambda.body = body;
1382 p->lineno = lineno;
1383 p->col_offset = col_offset;
1384 return p;
1387 expr_ty
1388 IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset,
1389 PyArena *arena)
1391 expr_ty p;
1392 if (!test) {
1393 PyErr_SetString(PyExc_ValueError,
1394 "field test is required for IfExp");
1395 return NULL;
1397 if (!body) {
1398 PyErr_SetString(PyExc_ValueError,
1399 "field body is required for IfExp");
1400 return NULL;
1402 if (!orelse) {
1403 PyErr_SetString(PyExc_ValueError,
1404 "field orelse is required for IfExp");
1405 return NULL;
1407 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1408 if (!p) {
1409 PyErr_NoMemory();
1410 return NULL;
1412 p->kind = IfExp_kind;
1413 p->v.IfExp.test = test;
1414 p->v.IfExp.body = body;
1415 p->v.IfExp.orelse = orelse;
1416 p->lineno = lineno;
1417 p->col_offset = col_offset;
1418 return p;
1421 expr_ty
1422 Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena
1423 *arena)
1425 expr_ty p;
1426 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1427 if (!p) {
1428 PyErr_NoMemory();
1429 return NULL;
1431 p->kind = Dict_kind;
1432 p->v.Dict.keys = keys;
1433 p->v.Dict.values = values;
1434 p->lineno = lineno;
1435 p->col_offset = col_offset;
1436 return p;
1439 expr_ty
1440 ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1441 PyArena *arena)
1443 expr_ty p;
1444 if (!elt) {
1445 PyErr_SetString(PyExc_ValueError,
1446 "field elt is required for ListComp");
1447 return NULL;
1449 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1450 if (!p) {
1451 PyErr_NoMemory();
1452 return NULL;
1454 p->kind = ListComp_kind;
1455 p->v.ListComp.elt = elt;
1456 p->v.ListComp.generators = generators;
1457 p->lineno = lineno;
1458 p->col_offset = col_offset;
1459 return p;
1462 expr_ty
1463 GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1464 PyArena *arena)
1466 expr_ty p;
1467 if (!elt) {
1468 PyErr_SetString(PyExc_ValueError,
1469 "field elt is required for GeneratorExp");
1470 return NULL;
1472 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1473 if (!p) {
1474 PyErr_NoMemory();
1475 return NULL;
1477 p->kind = GeneratorExp_kind;
1478 p->v.GeneratorExp.elt = elt;
1479 p->v.GeneratorExp.generators = generators;
1480 p->lineno = lineno;
1481 p->col_offset = col_offset;
1482 return p;
1485 expr_ty
1486 Yield(expr_ty value, int lineno, int col_offset, PyArena *arena)
1488 expr_ty p;
1489 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1490 if (!p) {
1491 PyErr_NoMemory();
1492 return NULL;
1494 p->kind = Yield_kind;
1495 p->v.Yield.value = value;
1496 p->lineno = lineno;
1497 p->col_offset = col_offset;
1498 return p;
1501 expr_ty
1502 Compare(expr_ty left, asdl_seq * ops, asdl_seq * comparators, int lineno, int
1503 col_offset, PyArena *arena)
1505 expr_ty p;
1506 if (!left) {
1507 PyErr_SetString(PyExc_ValueError,
1508 "field left is required for Compare");
1509 return NULL;
1511 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1512 if (!p) {
1513 PyErr_NoMemory();
1514 return NULL;
1516 p->kind = Compare_kind;
1517 p->v.Compare.left = left;
1518 p->v.Compare.ops = ops;
1519 p->v.Compare.comparators = comparators;
1520 p->lineno = lineno;
1521 p->col_offset = col_offset;
1522 return p;
1525 expr_ty
1526 Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, expr_ty starargs,
1527 expr_ty kwargs, int lineno, int col_offset, PyArena *arena)
1529 expr_ty p;
1530 if (!func) {
1531 PyErr_SetString(PyExc_ValueError,
1532 "field func is required for Call");
1533 return NULL;
1535 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1536 if (!p) {
1537 PyErr_NoMemory();
1538 return NULL;
1540 p->kind = Call_kind;
1541 p->v.Call.func = func;
1542 p->v.Call.args = args;
1543 p->v.Call.keywords = keywords;
1544 p->v.Call.starargs = starargs;
1545 p->v.Call.kwargs = kwargs;
1546 p->lineno = lineno;
1547 p->col_offset = col_offset;
1548 return p;
1551 expr_ty
1552 Repr(expr_ty value, int lineno, int col_offset, PyArena *arena)
1554 expr_ty p;
1555 if (!value) {
1556 PyErr_SetString(PyExc_ValueError,
1557 "field value is required for Repr");
1558 return NULL;
1560 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1561 if (!p) {
1562 PyErr_NoMemory();
1563 return NULL;
1565 p->kind = Repr_kind;
1566 p->v.Repr.value = value;
1567 p->lineno = lineno;
1568 p->col_offset = col_offset;
1569 return p;
1572 expr_ty
1573 Num(object n, int lineno, int col_offset, PyArena *arena)
1575 expr_ty p;
1576 if (!n) {
1577 PyErr_SetString(PyExc_ValueError,
1578 "field n is required for Num");
1579 return NULL;
1581 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1582 if (!p) {
1583 PyErr_NoMemory();
1584 return NULL;
1586 p->kind = Num_kind;
1587 p->v.Num.n = n;
1588 p->lineno = lineno;
1589 p->col_offset = col_offset;
1590 return p;
1593 expr_ty
1594 Str(string s, int lineno, int col_offset, PyArena *arena)
1596 expr_ty p;
1597 if (!s) {
1598 PyErr_SetString(PyExc_ValueError,
1599 "field s is required for Str");
1600 return NULL;
1602 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1603 if (!p) {
1604 PyErr_NoMemory();
1605 return NULL;
1607 p->kind = Str_kind;
1608 p->v.Str.s = s;
1609 p->lineno = lineno;
1610 p->col_offset = col_offset;
1611 return p;
1614 expr_ty
1615 Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int
1616 col_offset, PyArena *arena)
1618 expr_ty p;
1619 if (!value) {
1620 PyErr_SetString(PyExc_ValueError,
1621 "field value is required for Attribute");
1622 return NULL;
1624 if (!attr) {
1625 PyErr_SetString(PyExc_ValueError,
1626 "field attr is required for Attribute");
1627 return NULL;
1629 if (!ctx) {
1630 PyErr_SetString(PyExc_ValueError,
1631 "field ctx is required for Attribute");
1632 return NULL;
1634 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1635 if (!p) {
1636 PyErr_NoMemory();
1637 return NULL;
1639 p->kind = Attribute_kind;
1640 p->v.Attribute.value = value;
1641 p->v.Attribute.attr = attr;
1642 p->v.Attribute.ctx = ctx;
1643 p->lineno = lineno;
1644 p->col_offset = col_offset;
1645 return p;
1648 expr_ty
1649 Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int
1650 col_offset, PyArena *arena)
1652 expr_ty p;
1653 if (!value) {
1654 PyErr_SetString(PyExc_ValueError,
1655 "field value is required for Subscript");
1656 return NULL;
1658 if (!slice) {
1659 PyErr_SetString(PyExc_ValueError,
1660 "field slice is required for Subscript");
1661 return NULL;
1663 if (!ctx) {
1664 PyErr_SetString(PyExc_ValueError,
1665 "field ctx is required for Subscript");
1666 return NULL;
1668 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1669 if (!p) {
1670 PyErr_NoMemory();
1671 return NULL;
1673 p->kind = Subscript_kind;
1674 p->v.Subscript.value = value;
1675 p->v.Subscript.slice = slice;
1676 p->v.Subscript.ctx = ctx;
1677 p->lineno = lineno;
1678 p->col_offset = col_offset;
1679 return p;
1682 expr_ty
1683 Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena
1684 *arena)
1686 expr_ty p;
1687 if (!id) {
1688 PyErr_SetString(PyExc_ValueError,
1689 "field id is required for Name");
1690 return NULL;
1692 if (!ctx) {
1693 PyErr_SetString(PyExc_ValueError,
1694 "field ctx is required for Name");
1695 return NULL;
1697 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1698 if (!p) {
1699 PyErr_NoMemory();
1700 return NULL;
1702 p->kind = Name_kind;
1703 p->v.Name.id = id;
1704 p->v.Name.ctx = ctx;
1705 p->lineno = lineno;
1706 p->col_offset = col_offset;
1707 return p;
1710 expr_ty
1711 List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1712 *arena)
1714 expr_ty p;
1715 if (!ctx) {
1716 PyErr_SetString(PyExc_ValueError,
1717 "field ctx is required for List");
1718 return NULL;
1720 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1721 if (!p) {
1722 PyErr_NoMemory();
1723 return NULL;
1725 p->kind = List_kind;
1726 p->v.List.elts = elts;
1727 p->v.List.ctx = ctx;
1728 p->lineno = lineno;
1729 p->col_offset = col_offset;
1730 return p;
1733 expr_ty
1734 Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1735 *arena)
1737 expr_ty p;
1738 if (!ctx) {
1739 PyErr_SetString(PyExc_ValueError,
1740 "field ctx is required for Tuple");
1741 return NULL;
1743 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1744 if (!p) {
1745 PyErr_NoMemory();
1746 return NULL;
1748 p->kind = Tuple_kind;
1749 p->v.Tuple.elts = elts;
1750 p->v.Tuple.ctx = ctx;
1751 p->lineno = lineno;
1752 p->col_offset = col_offset;
1753 return p;
1756 slice_ty
1757 Ellipsis(PyArena *arena)
1759 slice_ty p;
1760 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
1761 if (!p) {
1762 PyErr_NoMemory();
1763 return NULL;
1765 p->kind = Ellipsis_kind;
1766 return p;
1769 slice_ty
1770 Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena)
1772 slice_ty p;
1773 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
1774 if (!p) {
1775 PyErr_NoMemory();
1776 return NULL;
1778 p->kind = Slice_kind;
1779 p->v.Slice.lower = lower;
1780 p->v.Slice.upper = upper;
1781 p->v.Slice.step = step;
1782 return p;
1785 slice_ty
1786 ExtSlice(asdl_seq * dims, PyArena *arena)
1788 slice_ty p;
1789 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
1790 if (!p) {
1791 PyErr_NoMemory();
1792 return NULL;
1794 p->kind = ExtSlice_kind;
1795 p->v.ExtSlice.dims = dims;
1796 return p;
1799 slice_ty
1800 Index(expr_ty value, PyArena *arena)
1802 slice_ty p;
1803 if (!value) {
1804 PyErr_SetString(PyExc_ValueError,
1805 "field value is required for Index");
1806 return NULL;
1808 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
1809 if (!p) {
1810 PyErr_NoMemory();
1811 return NULL;
1813 p->kind = Index_kind;
1814 p->v.Index.value = value;
1815 return p;
1818 comprehension_ty
1819 comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena)
1821 comprehension_ty p;
1822 if (!target) {
1823 PyErr_SetString(PyExc_ValueError,
1824 "field target is required for comprehension");
1825 return NULL;
1827 if (!iter) {
1828 PyErr_SetString(PyExc_ValueError,
1829 "field iter is required for comprehension");
1830 return NULL;
1832 p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));
1833 if (!p) {
1834 PyErr_NoMemory();
1835 return NULL;
1837 p->target = target;
1838 p->iter = iter;
1839 p->ifs = ifs;
1840 return p;
1843 excepthandler_ty
1844 excepthandler(expr_ty type, expr_ty name, asdl_seq * body, PyArena *arena)
1846 excepthandler_ty p;
1847 p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
1848 if (!p) {
1849 PyErr_NoMemory();
1850 return NULL;
1852 p->type = type;
1853 p->name = name;
1854 p->body = body;
1855 return p;
1858 arguments_ty
1859 arguments(asdl_seq * args, identifier vararg, identifier kwarg, asdl_seq *
1860 defaults, PyArena *arena)
1862 arguments_ty p;
1863 p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
1864 if (!p) {
1865 PyErr_NoMemory();
1866 return NULL;
1868 p->args = args;
1869 p->vararg = vararg;
1870 p->kwarg = kwarg;
1871 p->defaults = defaults;
1872 return p;
1875 keyword_ty
1876 keyword(identifier arg, expr_ty value, PyArena *arena)
1878 keyword_ty p;
1879 if (!arg) {
1880 PyErr_SetString(PyExc_ValueError,
1881 "field arg is required for keyword");
1882 return NULL;
1884 if (!value) {
1885 PyErr_SetString(PyExc_ValueError,
1886 "field value is required for keyword");
1887 return NULL;
1889 p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));
1890 if (!p) {
1891 PyErr_NoMemory();
1892 return NULL;
1894 p->arg = arg;
1895 p->value = value;
1896 return p;
1899 alias_ty
1900 alias(identifier name, identifier asname, PyArena *arena)
1902 alias_ty p;
1903 if (!name) {
1904 PyErr_SetString(PyExc_ValueError,
1905 "field name is required for alias");
1906 return NULL;
1908 p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));
1909 if (!p) {
1910 PyErr_NoMemory();
1911 return NULL;
1913 p->name = name;
1914 p->asname = asname;
1915 return p;
1919 PyObject*
1920 ast2obj_mod(void* _o)
1922 mod_ty o = (mod_ty)_o;
1923 PyObject *result = NULL, *value = NULL;
1924 if (!o) {
1925 Py_INCREF(Py_None);
1926 return Py_None;
1929 switch (o->kind) {
1930 case Module_kind:
1931 result = PyType_GenericNew(Module_type, NULL, NULL);
1932 if (!result) goto failed;
1933 value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
1934 if (!value) goto failed;
1935 if (PyObject_SetAttrString(result, "body", value) == -1)
1936 goto failed;
1937 Py_DECREF(value);
1938 break;
1939 case Interactive_kind:
1940 result = PyType_GenericNew(Interactive_type, NULL, NULL);
1941 if (!result) goto failed;
1942 value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
1943 if (!value) goto failed;
1944 if (PyObject_SetAttrString(result, "body", value) == -1)
1945 goto failed;
1946 Py_DECREF(value);
1947 break;
1948 case Expression_kind:
1949 result = PyType_GenericNew(Expression_type, NULL, NULL);
1950 if (!result) goto failed;
1951 value = ast2obj_expr(o->v.Expression.body);
1952 if (!value) goto failed;
1953 if (PyObject_SetAttrString(result, "body", value) == -1)
1954 goto failed;
1955 Py_DECREF(value);
1956 break;
1957 case Suite_kind:
1958 result = PyType_GenericNew(Suite_type, NULL, NULL);
1959 if (!result) goto failed;
1960 value = ast2obj_list(o->v.Suite.body, ast2obj_stmt);
1961 if (!value) goto failed;
1962 if (PyObject_SetAttrString(result, "body", value) == -1)
1963 goto failed;
1964 Py_DECREF(value);
1965 break;
1967 return result;
1968 failed:
1969 Py_XDECREF(value);
1970 Py_XDECREF(result);
1971 return NULL;
1974 PyObject*
1975 ast2obj_stmt(void* _o)
1977 stmt_ty o = (stmt_ty)_o;
1978 PyObject *result = NULL, *value = NULL;
1979 if (!o) {
1980 Py_INCREF(Py_None);
1981 return Py_None;
1984 switch (o->kind) {
1985 case FunctionDef_kind:
1986 result = PyType_GenericNew(FunctionDef_type, NULL, NULL);
1987 if (!result) goto failed;
1988 value = ast2obj_identifier(o->v.FunctionDef.name);
1989 if (!value) goto failed;
1990 if (PyObject_SetAttrString(result, "name", value) == -1)
1991 goto failed;
1992 Py_DECREF(value);
1993 value = ast2obj_arguments(o->v.FunctionDef.args);
1994 if (!value) goto failed;
1995 if (PyObject_SetAttrString(result, "args", value) == -1)
1996 goto failed;
1997 Py_DECREF(value);
1998 value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
1999 if (!value) goto failed;
2000 if (PyObject_SetAttrString(result, "body", value) == -1)
2001 goto failed;
2002 Py_DECREF(value);
2003 value = ast2obj_list(o->v.FunctionDef.decorators, ast2obj_expr);
2004 if (!value) goto failed;
2005 if (PyObject_SetAttrString(result, "decorators", value) == -1)
2006 goto failed;
2007 Py_DECREF(value);
2008 break;
2009 case ClassDef_kind:
2010 result = PyType_GenericNew(ClassDef_type, NULL, NULL);
2011 if (!result) goto failed;
2012 value = ast2obj_identifier(o->v.ClassDef.name);
2013 if (!value) goto failed;
2014 if (PyObject_SetAttrString(result, "name", value) == -1)
2015 goto failed;
2016 Py_DECREF(value);
2017 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
2018 if (!value) goto failed;
2019 if (PyObject_SetAttrString(result, "bases", value) == -1)
2020 goto failed;
2021 Py_DECREF(value);
2022 value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
2023 if (!value) goto failed;
2024 if (PyObject_SetAttrString(result, "body", value) == -1)
2025 goto failed;
2026 Py_DECREF(value);
2027 break;
2028 case Return_kind:
2029 result = PyType_GenericNew(Return_type, NULL, NULL);
2030 if (!result) goto failed;
2031 value = ast2obj_expr(o->v.Return.value);
2032 if (!value) goto failed;
2033 if (PyObject_SetAttrString(result, "value", value) == -1)
2034 goto failed;
2035 Py_DECREF(value);
2036 break;
2037 case Delete_kind:
2038 result = PyType_GenericNew(Delete_type, NULL, NULL);
2039 if (!result) goto failed;
2040 value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
2041 if (!value) goto failed;
2042 if (PyObject_SetAttrString(result, "targets", value) == -1)
2043 goto failed;
2044 Py_DECREF(value);
2045 break;
2046 case Assign_kind:
2047 result = PyType_GenericNew(Assign_type, NULL, NULL);
2048 if (!result) goto failed;
2049 value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
2050 if (!value) goto failed;
2051 if (PyObject_SetAttrString(result, "targets", value) == -1)
2052 goto failed;
2053 Py_DECREF(value);
2054 value = ast2obj_expr(o->v.Assign.value);
2055 if (!value) goto failed;
2056 if (PyObject_SetAttrString(result, "value", value) == -1)
2057 goto failed;
2058 Py_DECREF(value);
2059 break;
2060 case AugAssign_kind:
2061 result = PyType_GenericNew(AugAssign_type, NULL, NULL);
2062 if (!result) goto failed;
2063 value = ast2obj_expr(o->v.AugAssign.target);
2064 if (!value) goto failed;
2065 if (PyObject_SetAttrString(result, "target", value) == -1)
2066 goto failed;
2067 Py_DECREF(value);
2068 value = ast2obj_operator(o->v.AugAssign.op);
2069 if (!value) goto failed;
2070 if (PyObject_SetAttrString(result, "op", value) == -1)
2071 goto failed;
2072 Py_DECREF(value);
2073 value = ast2obj_expr(o->v.AugAssign.value);
2074 if (!value) goto failed;
2075 if (PyObject_SetAttrString(result, "value", value) == -1)
2076 goto failed;
2077 Py_DECREF(value);
2078 break;
2079 case Print_kind:
2080 result = PyType_GenericNew(Print_type, NULL, NULL);
2081 if (!result) goto failed;
2082 value = ast2obj_expr(o->v.Print.dest);
2083 if (!value) goto failed;
2084 if (PyObject_SetAttrString(result, "dest", value) == -1)
2085 goto failed;
2086 Py_DECREF(value);
2087 value = ast2obj_list(o->v.Print.values, ast2obj_expr);
2088 if (!value) goto failed;
2089 if (PyObject_SetAttrString(result, "values", value) == -1)
2090 goto failed;
2091 Py_DECREF(value);
2092 value = ast2obj_bool(o->v.Print.nl);
2093 if (!value) goto failed;
2094 if (PyObject_SetAttrString(result, "nl", value) == -1)
2095 goto failed;
2096 Py_DECREF(value);
2097 break;
2098 case For_kind:
2099 result = PyType_GenericNew(For_type, NULL, NULL);
2100 if (!result) goto failed;
2101 value = ast2obj_expr(o->v.For.target);
2102 if (!value) goto failed;
2103 if (PyObject_SetAttrString(result, "target", value) == -1)
2104 goto failed;
2105 Py_DECREF(value);
2106 value = ast2obj_expr(o->v.For.iter);
2107 if (!value) goto failed;
2108 if (PyObject_SetAttrString(result, "iter", value) == -1)
2109 goto failed;
2110 Py_DECREF(value);
2111 value = ast2obj_list(o->v.For.body, ast2obj_stmt);
2112 if (!value) goto failed;
2113 if (PyObject_SetAttrString(result, "body", value) == -1)
2114 goto failed;
2115 Py_DECREF(value);
2116 value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
2117 if (!value) goto failed;
2118 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2119 goto failed;
2120 Py_DECREF(value);
2121 break;
2122 case While_kind:
2123 result = PyType_GenericNew(While_type, NULL, NULL);
2124 if (!result) goto failed;
2125 value = ast2obj_expr(o->v.While.test);
2126 if (!value) goto failed;
2127 if (PyObject_SetAttrString(result, "test", value) == -1)
2128 goto failed;
2129 Py_DECREF(value);
2130 value = ast2obj_list(o->v.While.body, ast2obj_stmt);
2131 if (!value) goto failed;
2132 if (PyObject_SetAttrString(result, "body", value) == -1)
2133 goto failed;
2134 Py_DECREF(value);
2135 value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);
2136 if (!value) goto failed;
2137 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2138 goto failed;
2139 Py_DECREF(value);
2140 break;
2141 case If_kind:
2142 result = PyType_GenericNew(If_type, NULL, NULL);
2143 if (!result) goto failed;
2144 value = ast2obj_expr(o->v.If.test);
2145 if (!value) goto failed;
2146 if (PyObject_SetAttrString(result, "test", value) == -1)
2147 goto failed;
2148 Py_DECREF(value);
2149 value = ast2obj_list(o->v.If.body, ast2obj_stmt);
2150 if (!value) goto failed;
2151 if (PyObject_SetAttrString(result, "body", value) == -1)
2152 goto failed;
2153 Py_DECREF(value);
2154 value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
2155 if (!value) goto failed;
2156 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2157 goto failed;
2158 Py_DECREF(value);
2159 break;
2160 case With_kind:
2161 result = PyType_GenericNew(With_type, NULL, NULL);
2162 if (!result) goto failed;
2163 value = ast2obj_expr(o->v.With.context_expr);
2164 if (!value) goto failed;
2165 if (PyObject_SetAttrString(result, "context_expr", value) == -1)
2166 goto failed;
2167 Py_DECREF(value);
2168 value = ast2obj_expr(o->v.With.optional_vars);
2169 if (!value) goto failed;
2170 if (PyObject_SetAttrString(result, "optional_vars", value) ==
2172 goto failed;
2173 Py_DECREF(value);
2174 value = ast2obj_list(o->v.With.body, ast2obj_stmt);
2175 if (!value) goto failed;
2176 if (PyObject_SetAttrString(result, "body", value) == -1)
2177 goto failed;
2178 Py_DECREF(value);
2179 break;
2180 case Raise_kind:
2181 result = PyType_GenericNew(Raise_type, NULL, NULL);
2182 if (!result) goto failed;
2183 value = ast2obj_expr(o->v.Raise.type);
2184 if (!value) goto failed;
2185 if (PyObject_SetAttrString(result, "type", value) == -1)
2186 goto failed;
2187 Py_DECREF(value);
2188 value = ast2obj_expr(o->v.Raise.inst);
2189 if (!value) goto failed;
2190 if (PyObject_SetAttrString(result, "inst", value) == -1)
2191 goto failed;
2192 Py_DECREF(value);
2193 value = ast2obj_expr(o->v.Raise.tback);
2194 if (!value) goto failed;
2195 if (PyObject_SetAttrString(result, "tback", value) == -1)
2196 goto failed;
2197 Py_DECREF(value);
2198 break;
2199 case TryExcept_kind:
2200 result = PyType_GenericNew(TryExcept_type, NULL, NULL);
2201 if (!result) goto failed;
2202 value = ast2obj_list(o->v.TryExcept.body, ast2obj_stmt);
2203 if (!value) goto failed;
2204 if (PyObject_SetAttrString(result, "body", value) == -1)
2205 goto failed;
2206 Py_DECREF(value);
2207 value = ast2obj_list(o->v.TryExcept.handlers,
2208 ast2obj_excepthandler);
2209 if (!value) goto failed;
2210 if (PyObject_SetAttrString(result, "handlers", value) == -1)
2211 goto failed;
2212 Py_DECREF(value);
2213 value = ast2obj_list(o->v.TryExcept.orelse, ast2obj_stmt);
2214 if (!value) goto failed;
2215 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2216 goto failed;
2217 Py_DECREF(value);
2218 break;
2219 case TryFinally_kind:
2220 result = PyType_GenericNew(TryFinally_type, NULL, NULL);
2221 if (!result) goto failed;
2222 value = ast2obj_list(o->v.TryFinally.body, ast2obj_stmt);
2223 if (!value) goto failed;
2224 if (PyObject_SetAttrString(result, "body", value) == -1)
2225 goto failed;
2226 Py_DECREF(value);
2227 value = ast2obj_list(o->v.TryFinally.finalbody, ast2obj_stmt);
2228 if (!value) goto failed;
2229 if (PyObject_SetAttrString(result, "finalbody", value) == -1)
2230 goto failed;
2231 Py_DECREF(value);
2232 break;
2233 case Assert_kind:
2234 result = PyType_GenericNew(Assert_type, NULL, NULL);
2235 if (!result) goto failed;
2236 value = ast2obj_expr(o->v.Assert.test);
2237 if (!value) goto failed;
2238 if (PyObject_SetAttrString(result, "test", value) == -1)
2239 goto failed;
2240 Py_DECREF(value);
2241 value = ast2obj_expr(o->v.Assert.msg);
2242 if (!value) goto failed;
2243 if (PyObject_SetAttrString(result, "msg", value) == -1)
2244 goto failed;
2245 Py_DECREF(value);
2246 break;
2247 case Import_kind:
2248 result = PyType_GenericNew(Import_type, NULL, NULL);
2249 if (!result) goto failed;
2250 value = ast2obj_list(o->v.Import.names, ast2obj_alias);
2251 if (!value) goto failed;
2252 if (PyObject_SetAttrString(result, "names", value) == -1)
2253 goto failed;
2254 Py_DECREF(value);
2255 break;
2256 case ImportFrom_kind:
2257 result = PyType_GenericNew(ImportFrom_type, NULL, NULL);
2258 if (!result) goto failed;
2259 value = ast2obj_identifier(o->v.ImportFrom.module);
2260 if (!value) goto failed;
2261 if (PyObject_SetAttrString(result, "module", value) == -1)
2262 goto failed;
2263 Py_DECREF(value);
2264 value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
2265 if (!value) goto failed;
2266 if (PyObject_SetAttrString(result, "names", value) == -1)
2267 goto failed;
2268 Py_DECREF(value);
2269 value = ast2obj_int(o->v.ImportFrom.level);
2270 if (!value) goto failed;
2271 if (PyObject_SetAttrString(result, "level", value) == -1)
2272 goto failed;
2273 Py_DECREF(value);
2274 break;
2275 case Exec_kind:
2276 result = PyType_GenericNew(Exec_type, NULL, NULL);
2277 if (!result) goto failed;
2278 value = ast2obj_expr(o->v.Exec.body);
2279 if (!value) goto failed;
2280 if (PyObject_SetAttrString(result, "body", value) == -1)
2281 goto failed;
2282 Py_DECREF(value);
2283 value = ast2obj_expr(o->v.Exec.globals);
2284 if (!value) goto failed;
2285 if (PyObject_SetAttrString(result, "globals", value) == -1)
2286 goto failed;
2287 Py_DECREF(value);
2288 value = ast2obj_expr(o->v.Exec.locals);
2289 if (!value) goto failed;
2290 if (PyObject_SetAttrString(result, "locals", value) == -1)
2291 goto failed;
2292 Py_DECREF(value);
2293 break;
2294 case Global_kind:
2295 result = PyType_GenericNew(Global_type, NULL, NULL);
2296 if (!result) goto failed;
2297 value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
2298 if (!value) goto failed;
2299 if (PyObject_SetAttrString(result, "names", value) == -1)
2300 goto failed;
2301 Py_DECREF(value);
2302 break;
2303 case Expr_kind:
2304 result = PyType_GenericNew(Expr_type, NULL, NULL);
2305 if (!result) goto failed;
2306 value = ast2obj_expr(o->v.Expr.value);
2307 if (!value) goto failed;
2308 if (PyObject_SetAttrString(result, "value", value) == -1)
2309 goto failed;
2310 Py_DECREF(value);
2311 break;
2312 case Pass_kind:
2313 result = PyType_GenericNew(Pass_type, NULL, NULL);
2314 if (!result) goto failed;
2315 break;
2316 case Break_kind:
2317 result = PyType_GenericNew(Break_type, NULL, NULL);
2318 if (!result) goto failed;
2319 break;
2320 case Continue_kind:
2321 result = PyType_GenericNew(Continue_type, NULL, NULL);
2322 if (!result) goto failed;
2323 break;
2325 value = ast2obj_int(o->lineno);
2326 if (!value) goto failed;
2327 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2328 goto failed;
2329 Py_DECREF(value);
2330 value = ast2obj_int(o->col_offset);
2331 if (!value) goto failed;
2332 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2333 goto failed;
2334 Py_DECREF(value);
2335 return result;
2336 failed:
2337 Py_XDECREF(value);
2338 Py_XDECREF(result);
2339 return NULL;
2342 PyObject*
2343 ast2obj_expr(void* _o)
2345 expr_ty o = (expr_ty)_o;
2346 PyObject *result = NULL, *value = NULL;
2347 if (!o) {
2348 Py_INCREF(Py_None);
2349 return Py_None;
2352 switch (o->kind) {
2353 case BoolOp_kind:
2354 result = PyType_GenericNew(BoolOp_type, NULL, NULL);
2355 if (!result) goto failed;
2356 value = ast2obj_boolop(o->v.BoolOp.op);
2357 if (!value) goto failed;
2358 if (PyObject_SetAttrString(result, "op", value) == -1)
2359 goto failed;
2360 Py_DECREF(value);
2361 value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
2362 if (!value) goto failed;
2363 if (PyObject_SetAttrString(result, "values", value) == -1)
2364 goto failed;
2365 Py_DECREF(value);
2366 break;
2367 case BinOp_kind:
2368 result = PyType_GenericNew(BinOp_type, NULL, NULL);
2369 if (!result) goto failed;
2370 value = ast2obj_expr(o->v.BinOp.left);
2371 if (!value) goto failed;
2372 if (PyObject_SetAttrString(result, "left", value) == -1)
2373 goto failed;
2374 Py_DECREF(value);
2375 value = ast2obj_operator(o->v.BinOp.op);
2376 if (!value) goto failed;
2377 if (PyObject_SetAttrString(result, "op", value) == -1)
2378 goto failed;
2379 Py_DECREF(value);
2380 value = ast2obj_expr(o->v.BinOp.right);
2381 if (!value) goto failed;
2382 if (PyObject_SetAttrString(result, "right", value) == -1)
2383 goto failed;
2384 Py_DECREF(value);
2385 break;
2386 case UnaryOp_kind:
2387 result = PyType_GenericNew(UnaryOp_type, NULL, NULL);
2388 if (!result) goto failed;
2389 value = ast2obj_unaryop(o->v.UnaryOp.op);
2390 if (!value) goto failed;
2391 if (PyObject_SetAttrString(result, "op", value) == -1)
2392 goto failed;
2393 Py_DECREF(value);
2394 value = ast2obj_expr(o->v.UnaryOp.operand);
2395 if (!value) goto failed;
2396 if (PyObject_SetAttrString(result, "operand", value) == -1)
2397 goto failed;
2398 Py_DECREF(value);
2399 break;
2400 case Lambda_kind:
2401 result = PyType_GenericNew(Lambda_type, NULL, NULL);
2402 if (!result) goto failed;
2403 value = ast2obj_arguments(o->v.Lambda.args);
2404 if (!value) goto failed;
2405 if (PyObject_SetAttrString(result, "args", value) == -1)
2406 goto failed;
2407 Py_DECREF(value);
2408 value = ast2obj_expr(o->v.Lambda.body);
2409 if (!value) goto failed;
2410 if (PyObject_SetAttrString(result, "body", value) == -1)
2411 goto failed;
2412 Py_DECREF(value);
2413 break;
2414 case IfExp_kind:
2415 result = PyType_GenericNew(IfExp_type, NULL, NULL);
2416 if (!result) goto failed;
2417 value = ast2obj_expr(o->v.IfExp.test);
2418 if (!value) goto failed;
2419 if (PyObject_SetAttrString(result, "test", value) == -1)
2420 goto failed;
2421 Py_DECREF(value);
2422 value = ast2obj_expr(o->v.IfExp.body);
2423 if (!value) goto failed;
2424 if (PyObject_SetAttrString(result, "body", value) == -1)
2425 goto failed;
2426 Py_DECREF(value);
2427 value = ast2obj_expr(o->v.IfExp.orelse);
2428 if (!value) goto failed;
2429 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2430 goto failed;
2431 Py_DECREF(value);
2432 break;
2433 case Dict_kind:
2434 result = PyType_GenericNew(Dict_type, NULL, NULL);
2435 if (!result) goto failed;
2436 value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
2437 if (!value) goto failed;
2438 if (PyObject_SetAttrString(result, "keys", value) == -1)
2439 goto failed;
2440 Py_DECREF(value);
2441 value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
2442 if (!value) goto failed;
2443 if (PyObject_SetAttrString(result, "values", value) == -1)
2444 goto failed;
2445 Py_DECREF(value);
2446 break;
2447 case ListComp_kind:
2448 result = PyType_GenericNew(ListComp_type, NULL, NULL);
2449 if (!result) goto failed;
2450 value = ast2obj_expr(o->v.ListComp.elt);
2451 if (!value) goto failed;
2452 if (PyObject_SetAttrString(result, "elt", value) == -1)
2453 goto failed;
2454 Py_DECREF(value);
2455 value = ast2obj_list(o->v.ListComp.generators,
2456 ast2obj_comprehension);
2457 if (!value) goto failed;
2458 if (PyObject_SetAttrString(result, "generators", value) == -1)
2459 goto failed;
2460 Py_DECREF(value);
2461 break;
2462 case GeneratorExp_kind:
2463 result = PyType_GenericNew(GeneratorExp_type, NULL, NULL);
2464 if (!result) goto failed;
2465 value = ast2obj_expr(o->v.GeneratorExp.elt);
2466 if (!value) goto failed;
2467 if (PyObject_SetAttrString(result, "elt", value) == -1)
2468 goto failed;
2469 Py_DECREF(value);
2470 value = ast2obj_list(o->v.GeneratorExp.generators,
2471 ast2obj_comprehension);
2472 if (!value) goto failed;
2473 if (PyObject_SetAttrString(result, "generators", value) == -1)
2474 goto failed;
2475 Py_DECREF(value);
2476 break;
2477 case Yield_kind:
2478 result = PyType_GenericNew(Yield_type, NULL, NULL);
2479 if (!result) goto failed;
2480 value = ast2obj_expr(o->v.Yield.value);
2481 if (!value) goto failed;
2482 if (PyObject_SetAttrString(result, "value", value) == -1)
2483 goto failed;
2484 Py_DECREF(value);
2485 break;
2486 case Compare_kind:
2487 result = PyType_GenericNew(Compare_type, NULL, NULL);
2488 if (!result) goto failed;
2489 value = ast2obj_expr(o->v.Compare.left);
2490 if (!value) goto failed;
2491 if (PyObject_SetAttrString(result, "left", value) == -1)
2492 goto failed;
2493 Py_DECREF(value);
2495 int i, n = asdl_seq_LEN(o->v.Compare.ops);
2496 value = PyList_New(n);
2497 if (!value) goto failed;
2498 for(i = 0; i < n; i++)
2499 PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
2501 if (!value) goto failed;
2502 if (PyObject_SetAttrString(result, "ops", value) == -1)
2503 goto failed;
2504 Py_DECREF(value);
2505 value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
2506 if (!value) goto failed;
2507 if (PyObject_SetAttrString(result, "comparators", value) == -1)
2508 goto failed;
2509 Py_DECREF(value);
2510 break;
2511 case Call_kind:
2512 result = PyType_GenericNew(Call_type, NULL, NULL);
2513 if (!result) goto failed;
2514 value = ast2obj_expr(o->v.Call.func);
2515 if (!value) goto failed;
2516 if (PyObject_SetAttrString(result, "func", value) == -1)
2517 goto failed;
2518 Py_DECREF(value);
2519 value = ast2obj_list(o->v.Call.args, ast2obj_expr);
2520 if (!value) goto failed;
2521 if (PyObject_SetAttrString(result, "args", value) == -1)
2522 goto failed;
2523 Py_DECREF(value);
2524 value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
2525 if (!value) goto failed;
2526 if (PyObject_SetAttrString(result, "keywords", value) == -1)
2527 goto failed;
2528 Py_DECREF(value);
2529 value = ast2obj_expr(o->v.Call.starargs);
2530 if (!value) goto failed;
2531 if (PyObject_SetAttrString(result, "starargs", value) == -1)
2532 goto failed;
2533 Py_DECREF(value);
2534 value = ast2obj_expr(o->v.Call.kwargs);
2535 if (!value) goto failed;
2536 if (PyObject_SetAttrString(result, "kwargs", value) == -1)
2537 goto failed;
2538 Py_DECREF(value);
2539 break;
2540 case Repr_kind:
2541 result = PyType_GenericNew(Repr_type, NULL, NULL);
2542 if (!result) goto failed;
2543 value = ast2obj_expr(o->v.Repr.value);
2544 if (!value) goto failed;
2545 if (PyObject_SetAttrString(result, "value", value) == -1)
2546 goto failed;
2547 Py_DECREF(value);
2548 break;
2549 case Num_kind:
2550 result = PyType_GenericNew(Num_type, NULL, NULL);
2551 if (!result) goto failed;
2552 value = ast2obj_object(o->v.Num.n);
2553 if (!value) goto failed;
2554 if (PyObject_SetAttrString(result, "n", value) == -1)
2555 goto failed;
2556 Py_DECREF(value);
2557 break;
2558 case Str_kind:
2559 result = PyType_GenericNew(Str_type, NULL, NULL);
2560 if (!result) goto failed;
2561 value = ast2obj_string(o->v.Str.s);
2562 if (!value) goto failed;
2563 if (PyObject_SetAttrString(result, "s", value) == -1)
2564 goto failed;
2565 Py_DECREF(value);
2566 break;
2567 case Attribute_kind:
2568 result = PyType_GenericNew(Attribute_type, NULL, NULL);
2569 if (!result) goto failed;
2570 value = ast2obj_expr(o->v.Attribute.value);
2571 if (!value) goto failed;
2572 if (PyObject_SetAttrString(result, "value", value) == -1)
2573 goto failed;
2574 Py_DECREF(value);
2575 value = ast2obj_identifier(o->v.Attribute.attr);
2576 if (!value) goto failed;
2577 if (PyObject_SetAttrString(result, "attr", value) == -1)
2578 goto failed;
2579 Py_DECREF(value);
2580 value = ast2obj_expr_context(o->v.Attribute.ctx);
2581 if (!value) goto failed;
2582 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2583 goto failed;
2584 Py_DECREF(value);
2585 break;
2586 case Subscript_kind:
2587 result = PyType_GenericNew(Subscript_type, NULL, NULL);
2588 if (!result) goto failed;
2589 value = ast2obj_expr(o->v.Subscript.value);
2590 if (!value) goto failed;
2591 if (PyObject_SetAttrString(result, "value", value) == -1)
2592 goto failed;
2593 Py_DECREF(value);
2594 value = ast2obj_slice(o->v.Subscript.slice);
2595 if (!value) goto failed;
2596 if (PyObject_SetAttrString(result, "slice", value) == -1)
2597 goto failed;
2598 Py_DECREF(value);
2599 value = ast2obj_expr_context(o->v.Subscript.ctx);
2600 if (!value) goto failed;
2601 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2602 goto failed;
2603 Py_DECREF(value);
2604 break;
2605 case Name_kind:
2606 result = PyType_GenericNew(Name_type, NULL, NULL);
2607 if (!result) goto failed;
2608 value = ast2obj_identifier(o->v.Name.id);
2609 if (!value) goto failed;
2610 if (PyObject_SetAttrString(result, "id", value) == -1)
2611 goto failed;
2612 Py_DECREF(value);
2613 value = ast2obj_expr_context(o->v.Name.ctx);
2614 if (!value) goto failed;
2615 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2616 goto failed;
2617 Py_DECREF(value);
2618 break;
2619 case List_kind:
2620 result = PyType_GenericNew(List_type, NULL, NULL);
2621 if (!result) goto failed;
2622 value = ast2obj_list(o->v.List.elts, ast2obj_expr);
2623 if (!value) goto failed;
2624 if (PyObject_SetAttrString(result, "elts", value) == -1)
2625 goto failed;
2626 Py_DECREF(value);
2627 value = ast2obj_expr_context(o->v.List.ctx);
2628 if (!value) goto failed;
2629 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2630 goto failed;
2631 Py_DECREF(value);
2632 break;
2633 case Tuple_kind:
2634 result = PyType_GenericNew(Tuple_type, NULL, NULL);
2635 if (!result) goto failed;
2636 value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
2637 if (!value) goto failed;
2638 if (PyObject_SetAttrString(result, "elts", value) == -1)
2639 goto failed;
2640 Py_DECREF(value);
2641 value = ast2obj_expr_context(o->v.Tuple.ctx);
2642 if (!value) goto failed;
2643 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2644 goto failed;
2645 Py_DECREF(value);
2646 break;
2648 value = ast2obj_int(o->lineno);
2649 if (!value) goto failed;
2650 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2651 goto failed;
2652 Py_DECREF(value);
2653 value = ast2obj_int(o->col_offset);
2654 if (!value) goto failed;
2655 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2656 goto failed;
2657 Py_DECREF(value);
2658 return result;
2659 failed:
2660 Py_XDECREF(value);
2661 Py_XDECREF(result);
2662 return NULL;
2665 PyObject* ast2obj_expr_context(expr_context_ty o)
2667 switch(o) {
2668 case Load:
2669 Py_INCREF(Load_singleton);
2670 return Load_singleton;
2671 case Store:
2672 Py_INCREF(Store_singleton);
2673 return Store_singleton;
2674 case Del:
2675 Py_INCREF(Del_singleton);
2676 return Del_singleton;
2677 case AugLoad:
2678 Py_INCREF(AugLoad_singleton);
2679 return AugLoad_singleton;
2680 case AugStore:
2681 Py_INCREF(AugStore_singleton);
2682 return AugStore_singleton;
2683 case Param:
2684 Py_INCREF(Param_singleton);
2685 return Param_singleton;
2687 return NULL; /* cannot happen */
2689 PyObject*
2690 ast2obj_slice(void* _o)
2692 slice_ty o = (slice_ty)_o;
2693 PyObject *result = NULL, *value = NULL;
2694 if (!o) {
2695 Py_INCREF(Py_None);
2696 return Py_None;
2699 switch (o->kind) {
2700 case Ellipsis_kind:
2701 result = PyType_GenericNew(Ellipsis_type, NULL, NULL);
2702 if (!result) goto failed;
2703 break;
2704 case Slice_kind:
2705 result = PyType_GenericNew(Slice_type, NULL, NULL);
2706 if (!result) goto failed;
2707 value = ast2obj_expr(o->v.Slice.lower);
2708 if (!value) goto failed;
2709 if (PyObject_SetAttrString(result, "lower", value) == -1)
2710 goto failed;
2711 Py_DECREF(value);
2712 value = ast2obj_expr(o->v.Slice.upper);
2713 if (!value) goto failed;
2714 if (PyObject_SetAttrString(result, "upper", value) == -1)
2715 goto failed;
2716 Py_DECREF(value);
2717 value = ast2obj_expr(o->v.Slice.step);
2718 if (!value) goto failed;
2719 if (PyObject_SetAttrString(result, "step", value) == -1)
2720 goto failed;
2721 Py_DECREF(value);
2722 break;
2723 case ExtSlice_kind:
2724 result = PyType_GenericNew(ExtSlice_type, NULL, NULL);
2725 if (!result) goto failed;
2726 value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice);
2727 if (!value) goto failed;
2728 if (PyObject_SetAttrString(result, "dims", value) == -1)
2729 goto failed;
2730 Py_DECREF(value);
2731 break;
2732 case Index_kind:
2733 result = PyType_GenericNew(Index_type, NULL, NULL);
2734 if (!result) goto failed;
2735 value = ast2obj_expr(o->v.Index.value);
2736 if (!value) goto failed;
2737 if (PyObject_SetAttrString(result, "value", value) == -1)
2738 goto failed;
2739 Py_DECREF(value);
2740 break;
2742 return result;
2743 failed:
2744 Py_XDECREF(value);
2745 Py_XDECREF(result);
2746 return NULL;
2749 PyObject* ast2obj_boolop(boolop_ty o)
2751 switch(o) {
2752 case And:
2753 Py_INCREF(And_singleton);
2754 return And_singleton;
2755 case Or:
2756 Py_INCREF(Or_singleton);
2757 return Or_singleton;
2759 return NULL; /* cannot happen */
2761 PyObject* ast2obj_operator(operator_ty o)
2763 switch(o) {
2764 case Add:
2765 Py_INCREF(Add_singleton);
2766 return Add_singleton;
2767 case Sub:
2768 Py_INCREF(Sub_singleton);
2769 return Sub_singleton;
2770 case Mult:
2771 Py_INCREF(Mult_singleton);
2772 return Mult_singleton;
2773 case Div:
2774 Py_INCREF(Div_singleton);
2775 return Div_singleton;
2776 case Mod:
2777 Py_INCREF(Mod_singleton);
2778 return Mod_singleton;
2779 case Pow:
2780 Py_INCREF(Pow_singleton);
2781 return Pow_singleton;
2782 case LShift:
2783 Py_INCREF(LShift_singleton);
2784 return LShift_singleton;
2785 case RShift:
2786 Py_INCREF(RShift_singleton);
2787 return RShift_singleton;
2788 case BitOr:
2789 Py_INCREF(BitOr_singleton);
2790 return BitOr_singleton;
2791 case BitXor:
2792 Py_INCREF(BitXor_singleton);
2793 return BitXor_singleton;
2794 case BitAnd:
2795 Py_INCREF(BitAnd_singleton);
2796 return BitAnd_singleton;
2797 case FloorDiv:
2798 Py_INCREF(FloorDiv_singleton);
2799 return FloorDiv_singleton;
2801 return NULL; /* cannot happen */
2803 PyObject* ast2obj_unaryop(unaryop_ty o)
2805 switch(o) {
2806 case Invert:
2807 Py_INCREF(Invert_singleton);
2808 return Invert_singleton;
2809 case Not:
2810 Py_INCREF(Not_singleton);
2811 return Not_singleton;
2812 case UAdd:
2813 Py_INCREF(UAdd_singleton);
2814 return UAdd_singleton;
2815 case USub:
2816 Py_INCREF(USub_singleton);
2817 return USub_singleton;
2819 return NULL; /* cannot happen */
2821 PyObject* ast2obj_cmpop(cmpop_ty o)
2823 switch(o) {
2824 case Eq:
2825 Py_INCREF(Eq_singleton);
2826 return Eq_singleton;
2827 case NotEq:
2828 Py_INCREF(NotEq_singleton);
2829 return NotEq_singleton;
2830 case Lt:
2831 Py_INCREF(Lt_singleton);
2832 return Lt_singleton;
2833 case LtE:
2834 Py_INCREF(LtE_singleton);
2835 return LtE_singleton;
2836 case Gt:
2837 Py_INCREF(Gt_singleton);
2838 return Gt_singleton;
2839 case GtE:
2840 Py_INCREF(GtE_singleton);
2841 return GtE_singleton;
2842 case Is:
2843 Py_INCREF(Is_singleton);
2844 return Is_singleton;
2845 case IsNot:
2846 Py_INCREF(IsNot_singleton);
2847 return IsNot_singleton;
2848 case In:
2849 Py_INCREF(In_singleton);
2850 return In_singleton;
2851 case NotIn:
2852 Py_INCREF(NotIn_singleton);
2853 return NotIn_singleton;
2855 return NULL; /* cannot happen */
2857 PyObject*
2858 ast2obj_comprehension(void* _o)
2860 comprehension_ty o = (comprehension_ty)_o;
2861 PyObject *result = NULL, *value = NULL;
2862 if (!o) {
2863 Py_INCREF(Py_None);
2864 return Py_None;
2867 result = PyType_GenericNew(comprehension_type, NULL, NULL);
2868 if (!result) return NULL;
2869 value = ast2obj_expr(o->target);
2870 if (!value) goto failed;
2871 if (PyObject_SetAttrString(result, "target", value) == -1)
2872 goto failed;
2873 Py_DECREF(value);
2874 value = ast2obj_expr(o->iter);
2875 if (!value) goto failed;
2876 if (PyObject_SetAttrString(result, "iter", value) == -1)
2877 goto failed;
2878 Py_DECREF(value);
2879 value = ast2obj_list(o->ifs, ast2obj_expr);
2880 if (!value) goto failed;
2881 if (PyObject_SetAttrString(result, "ifs", value) == -1)
2882 goto failed;
2883 Py_DECREF(value);
2884 return result;
2885 failed:
2886 Py_XDECREF(value);
2887 Py_XDECREF(result);
2888 return NULL;
2891 PyObject*
2892 ast2obj_excepthandler(void* _o)
2894 excepthandler_ty o = (excepthandler_ty)_o;
2895 PyObject *result = NULL, *value = NULL;
2896 if (!o) {
2897 Py_INCREF(Py_None);
2898 return Py_None;
2901 result = PyType_GenericNew(excepthandler_type, NULL, NULL);
2902 if (!result) return NULL;
2903 value = ast2obj_expr(o->type);
2904 if (!value) goto failed;
2905 if (PyObject_SetAttrString(result, "type", value) == -1)
2906 goto failed;
2907 Py_DECREF(value);
2908 value = ast2obj_expr(o->name);
2909 if (!value) goto failed;
2910 if (PyObject_SetAttrString(result, "name", value) == -1)
2911 goto failed;
2912 Py_DECREF(value);
2913 value = ast2obj_list(o->body, ast2obj_stmt);
2914 if (!value) goto failed;
2915 if (PyObject_SetAttrString(result, "body", value) == -1)
2916 goto failed;
2917 Py_DECREF(value);
2918 return result;
2919 failed:
2920 Py_XDECREF(value);
2921 Py_XDECREF(result);
2922 return NULL;
2925 PyObject*
2926 ast2obj_arguments(void* _o)
2928 arguments_ty o = (arguments_ty)_o;
2929 PyObject *result = NULL, *value = NULL;
2930 if (!o) {
2931 Py_INCREF(Py_None);
2932 return Py_None;
2935 result = PyType_GenericNew(arguments_type, NULL, NULL);
2936 if (!result) return NULL;
2937 value = ast2obj_list(o->args, ast2obj_expr);
2938 if (!value) goto failed;
2939 if (PyObject_SetAttrString(result, "args", value) == -1)
2940 goto failed;
2941 Py_DECREF(value);
2942 value = ast2obj_identifier(o->vararg);
2943 if (!value) goto failed;
2944 if (PyObject_SetAttrString(result, "vararg", value) == -1)
2945 goto failed;
2946 Py_DECREF(value);
2947 value = ast2obj_identifier(o->kwarg);
2948 if (!value) goto failed;
2949 if (PyObject_SetAttrString(result, "kwarg", value) == -1)
2950 goto failed;
2951 Py_DECREF(value);
2952 value = ast2obj_list(o->defaults, ast2obj_expr);
2953 if (!value) goto failed;
2954 if (PyObject_SetAttrString(result, "defaults", value) == -1)
2955 goto failed;
2956 Py_DECREF(value);
2957 return result;
2958 failed:
2959 Py_XDECREF(value);
2960 Py_XDECREF(result);
2961 return NULL;
2964 PyObject*
2965 ast2obj_keyword(void* _o)
2967 keyword_ty o = (keyword_ty)_o;
2968 PyObject *result = NULL, *value = NULL;
2969 if (!o) {
2970 Py_INCREF(Py_None);
2971 return Py_None;
2974 result = PyType_GenericNew(keyword_type, NULL, NULL);
2975 if (!result) return NULL;
2976 value = ast2obj_identifier(o->arg);
2977 if (!value) goto failed;
2978 if (PyObject_SetAttrString(result, "arg", value) == -1)
2979 goto failed;
2980 Py_DECREF(value);
2981 value = ast2obj_expr(o->value);
2982 if (!value) goto failed;
2983 if (PyObject_SetAttrString(result, "value", value) == -1)
2984 goto failed;
2985 Py_DECREF(value);
2986 return result;
2987 failed:
2988 Py_XDECREF(value);
2989 Py_XDECREF(result);
2990 return NULL;
2993 PyObject*
2994 ast2obj_alias(void* _o)
2996 alias_ty o = (alias_ty)_o;
2997 PyObject *result = NULL, *value = NULL;
2998 if (!o) {
2999 Py_INCREF(Py_None);
3000 return Py_None;
3003 result = PyType_GenericNew(alias_type, NULL, NULL);
3004 if (!result) return NULL;
3005 value = ast2obj_identifier(o->name);
3006 if (!value) goto failed;
3007 if (PyObject_SetAttrString(result, "name", value) == -1)
3008 goto failed;
3009 Py_DECREF(value);
3010 value = ast2obj_identifier(o->asname);
3011 if (!value) goto failed;
3012 if (PyObject_SetAttrString(result, "asname", value) == -1)
3013 goto failed;
3014 Py_DECREF(value);
3015 return result;
3016 failed:
3017 Py_XDECREF(value);
3018 Py_XDECREF(result);
3019 return NULL;
3023 PyMODINIT_FUNC
3024 init_ast(void)
3026 PyObject *m, *d;
3027 if (!init_types()) return;
3028 m = Py_InitModule3("_ast", NULL, NULL);
3029 if (!m) return;
3030 d = PyModule_GetDict(m);
3031 if (PyDict_SetItemString(d, "AST", (PyObject*)AST_type) < 0) return;
3032 if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)
3033 return;
3034 if (PyModule_AddStringConstant(m, "__version__", "42753") < 0)
3035 return;
3036 if(PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return;
3037 if(PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0)
3038 return;
3039 if(PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type)
3040 < 0) return;
3041 if(PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) <
3042 0) return;
3043 if(PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return;
3044 if(PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return;
3045 if(PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type)
3046 < 0) return;
3047 if(PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0)
3048 return;
3049 if(PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0)
3050 return;
3051 if(PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0)
3052 return;
3053 if(PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0)
3054 return;
3055 if(PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) < 0)
3056 return;
3057 if(PyDict_SetItemString(d, "Print", (PyObject*)Print_type) < 0) return;
3058 if(PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return;
3059 if(PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return;
3060 if(PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return;
3061 if(PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return;
3062 if(PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return;
3063 if(PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) < 0)
3064 return;
3065 if(PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) <
3066 0) return;
3067 if(PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0)
3068 return;
3069 if(PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0)
3070 return;
3071 if(PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) <
3072 0) return;
3073 if(PyDict_SetItemString(d, "Exec", (PyObject*)Exec_type) < 0) return;
3074 if(PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0)
3075 return;
3076 if(PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return;
3077 if(PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return;
3078 if(PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return;
3079 if(PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0)
3080 return;
3081 if(PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return;
3082 if(PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0)
3083 return;
3084 if(PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return;
3085 if(PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0)
3086 return;
3087 if(PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0)
3088 return;
3089 if(PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return;
3090 if(PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return;
3091 if(PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0)
3092 return;
3093 if(PyDict_SetItemString(d, "GeneratorExp",
3094 (PyObject*)GeneratorExp_type) < 0) return;
3095 if(PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return;
3096 if(PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0)
3097 return;
3098 if(PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return;
3099 if(PyDict_SetItemString(d, "Repr", (PyObject*)Repr_type) < 0) return;
3100 if(PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return;
3101 if(PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return;
3102 if(PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) < 0)
3103 return;
3104 if(PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) < 0)
3105 return;
3106 if(PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return;
3107 if(PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return;
3108 if(PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return;
3109 if(PyDict_SetItemString(d, "expr_context",
3110 (PyObject*)expr_context_type) < 0) return;
3111 if(PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return;
3112 if(PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return;
3113 if(PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return;
3114 if(PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0)
3115 return;
3116 if(PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0)
3117 return;
3118 if(PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return;
3119 if(PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return;
3120 if(PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0)
3121 return;
3122 if(PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return;
3123 if(PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0)
3124 return;
3125 if(PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return;
3126 if(PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0)
3127 return;
3128 if(PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return;
3129 if(PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return;
3130 if(PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0)
3131 return;
3132 if(PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return;
3133 if(PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return;
3134 if(PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return;
3135 if(PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return;
3136 if(PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return;
3137 if(PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return;
3138 if(PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0)
3139 return;
3140 if(PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0)
3141 return;
3142 if(PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return;
3143 if(PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0)
3144 return;
3145 if(PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0)
3146 return;
3147 if(PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0)
3148 return;
3149 if(PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0)
3150 return;
3151 if(PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0)
3152 return;
3153 if(PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return;
3154 if(PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return;
3155 if(PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return;
3156 if(PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return;
3157 if(PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return;
3158 if(PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return;
3159 if(PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return;
3160 if(PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return;
3161 if(PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return;
3162 if(PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return;
3163 if(PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return;
3164 if(PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return;
3165 if(PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return;
3166 if(PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return;
3167 if(PyDict_SetItemString(d, "comprehension",
3168 (PyObject*)comprehension_type) < 0) return;
3169 if(PyDict_SetItemString(d, "excepthandler",
3170 (PyObject*)excepthandler_type) < 0) return;
3171 if(PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) < 0)
3172 return;
3173 if(PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0)
3174 return;
3175 if(PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return;
3179 PyObject* PyAST_mod2obj(mod_ty t)
3181 init_types();
3182 return ast2obj_mod(t);