Remove incorrect usage of :const: in documentation.
[python.git] / Python / Python-ast.c
blob421a2d17760d3b75c6e7042dea2128a8a67c47b9
1 /* File automatically generated by Parser/asdl_c.py. */
4 /*
5 __version__ 53731.
7 This module must be committed separately after each AST grammar change;
8 The __version__ number is set to the revision number of the commit
9 containing the grammar change.
12 #include "Python.h"
13 #include "Python-ast.h"
15 static PyTypeObject* AST_type;
16 static PyTypeObject *mod_type;
17 static PyObject* ast2obj_mod(void*);
18 static PyTypeObject *Module_type;
19 static char *Module_fields[]={
20 "body",
22 static PyTypeObject *Interactive_type;
23 static char *Interactive_fields[]={
24 "body",
26 static PyTypeObject *Expression_type;
27 static char *Expression_fields[]={
28 "body",
30 static PyTypeObject *Suite_type;
31 static char *Suite_fields[]={
32 "body",
34 static PyTypeObject *stmt_type;
35 static char *stmt_attributes[] = {
36 "lineno",
37 "col_offset",
39 static PyObject* ast2obj_stmt(void*);
40 static PyTypeObject *FunctionDef_type;
41 static char *FunctionDef_fields[]={
42 "name",
43 "args",
44 "body",
45 "decorators",
47 static PyTypeObject *ClassDef_type;
48 static char *ClassDef_fields[]={
49 "name",
50 "bases",
51 "body",
53 static PyTypeObject *Return_type;
54 static char *Return_fields[]={
55 "value",
57 static PyTypeObject *Delete_type;
58 static char *Delete_fields[]={
59 "targets",
61 static PyTypeObject *Assign_type;
62 static char *Assign_fields[]={
63 "targets",
64 "value",
66 static PyTypeObject *AugAssign_type;
67 static char *AugAssign_fields[]={
68 "target",
69 "op",
70 "value",
72 static PyTypeObject *Print_type;
73 static char *Print_fields[]={
74 "dest",
75 "values",
76 "nl",
78 static PyTypeObject *For_type;
79 static char *For_fields[]={
80 "target",
81 "iter",
82 "body",
83 "orelse",
85 static PyTypeObject *While_type;
86 static char *While_fields[]={
87 "test",
88 "body",
89 "orelse",
91 static PyTypeObject *If_type;
92 static char *If_fields[]={
93 "test",
94 "body",
95 "orelse",
97 static PyTypeObject *With_type;
98 static char *With_fields[]={
99 "context_expr",
100 "optional_vars",
101 "body",
103 static PyTypeObject *Raise_type;
104 static char *Raise_fields[]={
105 "type",
106 "inst",
107 "tback",
109 static PyTypeObject *TryExcept_type;
110 static char *TryExcept_fields[]={
111 "body",
112 "handlers",
113 "orelse",
115 static PyTypeObject *TryFinally_type;
116 static char *TryFinally_fields[]={
117 "body",
118 "finalbody",
120 static PyTypeObject *Assert_type;
121 static char *Assert_fields[]={
122 "test",
123 "msg",
125 static PyTypeObject *Import_type;
126 static char *Import_fields[]={
127 "names",
129 static PyTypeObject *ImportFrom_type;
130 static char *ImportFrom_fields[]={
131 "module",
132 "names",
133 "level",
135 static PyTypeObject *Exec_type;
136 static char *Exec_fields[]={
137 "body",
138 "globals",
139 "locals",
141 static PyTypeObject *Global_type;
142 static char *Global_fields[]={
143 "names",
145 static PyTypeObject *Expr_type;
146 static char *Expr_fields[]={
147 "value",
149 static PyTypeObject *Pass_type;
150 static PyTypeObject *Break_type;
151 static PyTypeObject *Continue_type;
152 static PyTypeObject *expr_type;
153 static char *expr_attributes[] = {
154 "lineno",
155 "col_offset",
157 static PyObject* ast2obj_expr(void*);
158 static PyTypeObject *BoolOp_type;
159 static char *BoolOp_fields[]={
160 "op",
161 "values",
163 static PyTypeObject *BinOp_type;
164 static char *BinOp_fields[]={
165 "left",
166 "op",
167 "right",
169 static PyTypeObject *UnaryOp_type;
170 static char *UnaryOp_fields[]={
171 "op",
172 "operand",
174 static PyTypeObject *Lambda_type;
175 static char *Lambda_fields[]={
176 "args",
177 "body",
179 static PyTypeObject *IfExp_type;
180 static char *IfExp_fields[]={
181 "test",
182 "body",
183 "orelse",
185 static PyTypeObject *Dict_type;
186 static char *Dict_fields[]={
187 "keys",
188 "values",
190 static PyTypeObject *ListComp_type;
191 static char *ListComp_fields[]={
192 "elt",
193 "generators",
195 static PyTypeObject *GeneratorExp_type;
196 static char *GeneratorExp_fields[]={
197 "elt",
198 "generators",
200 static PyTypeObject *Yield_type;
201 static char *Yield_fields[]={
202 "value",
204 static PyTypeObject *Compare_type;
205 static char *Compare_fields[]={
206 "left",
207 "ops",
208 "comparators",
210 static PyTypeObject *Call_type;
211 static char *Call_fields[]={
212 "func",
213 "args",
214 "keywords",
215 "starargs",
216 "kwargs",
218 static PyTypeObject *Repr_type;
219 static char *Repr_fields[]={
220 "value",
222 static PyTypeObject *Num_type;
223 static char *Num_fields[]={
224 "n",
226 static PyTypeObject *Str_type;
227 static char *Str_fields[]={
228 "s",
230 static PyTypeObject *Attribute_type;
231 static char *Attribute_fields[]={
232 "value",
233 "attr",
234 "ctx",
236 static PyTypeObject *Subscript_type;
237 static char *Subscript_fields[]={
238 "value",
239 "slice",
240 "ctx",
242 static PyTypeObject *Name_type;
243 static char *Name_fields[]={
244 "id",
245 "ctx",
247 static PyTypeObject *List_type;
248 static char *List_fields[]={
249 "elts",
250 "ctx",
252 static PyTypeObject *Tuple_type;
253 static char *Tuple_fields[]={
254 "elts",
255 "ctx",
257 static PyTypeObject *expr_context_type;
258 static PyObject *Load_singleton, *Store_singleton, *Del_singleton,
259 *AugLoad_singleton, *AugStore_singleton, *Param_singleton;
260 static PyObject* ast2obj_expr_context(expr_context_ty);
261 static PyTypeObject *Load_type;
262 static PyTypeObject *Store_type;
263 static PyTypeObject *Del_type;
264 static PyTypeObject *AugLoad_type;
265 static PyTypeObject *AugStore_type;
266 static PyTypeObject *Param_type;
267 static PyTypeObject *slice_type;
268 static PyObject* ast2obj_slice(void*);
269 static PyTypeObject *Ellipsis_type;
270 static PyTypeObject *Slice_type;
271 static char *Slice_fields[]={
272 "lower",
273 "upper",
274 "step",
276 static PyTypeObject *ExtSlice_type;
277 static char *ExtSlice_fields[]={
278 "dims",
280 static PyTypeObject *Index_type;
281 static char *Index_fields[]={
282 "value",
284 static PyTypeObject *boolop_type;
285 static PyObject *And_singleton, *Or_singleton;
286 static PyObject* ast2obj_boolop(boolop_ty);
287 static PyTypeObject *And_type;
288 static PyTypeObject *Or_type;
289 static PyTypeObject *operator_type;
290 static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton,
291 *Div_singleton, *Mod_singleton, *Pow_singleton, *LShift_singleton,
292 *RShift_singleton, *BitOr_singleton, *BitXor_singleton, *BitAnd_singleton,
293 *FloorDiv_singleton;
294 static PyObject* ast2obj_operator(operator_ty);
295 static PyTypeObject *Add_type;
296 static PyTypeObject *Sub_type;
297 static PyTypeObject *Mult_type;
298 static PyTypeObject *Div_type;
299 static PyTypeObject *Mod_type;
300 static PyTypeObject *Pow_type;
301 static PyTypeObject *LShift_type;
302 static PyTypeObject *RShift_type;
303 static PyTypeObject *BitOr_type;
304 static PyTypeObject *BitXor_type;
305 static PyTypeObject *BitAnd_type;
306 static PyTypeObject *FloorDiv_type;
307 static PyTypeObject *unaryop_type;
308 static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton,
309 *USub_singleton;
310 static PyObject* ast2obj_unaryop(unaryop_ty);
311 static PyTypeObject *Invert_type;
312 static PyTypeObject *Not_type;
313 static PyTypeObject *UAdd_type;
314 static PyTypeObject *USub_type;
315 static PyTypeObject *cmpop_type;
316 static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton,
317 *Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton,
318 *NotIn_singleton;
319 static PyObject* ast2obj_cmpop(cmpop_ty);
320 static PyTypeObject *Eq_type;
321 static PyTypeObject *NotEq_type;
322 static PyTypeObject *Lt_type;
323 static PyTypeObject *LtE_type;
324 static PyTypeObject *Gt_type;
325 static PyTypeObject *GtE_type;
326 static PyTypeObject *Is_type;
327 static PyTypeObject *IsNot_type;
328 static PyTypeObject *In_type;
329 static PyTypeObject *NotIn_type;
330 static PyTypeObject *comprehension_type;
331 static PyObject* ast2obj_comprehension(void*);
332 static char *comprehension_fields[]={
333 "target",
334 "iter",
335 "ifs",
337 static PyTypeObject *excepthandler_type;
338 static PyObject* ast2obj_excepthandler(void*);
339 static char *excepthandler_fields[]={
340 "type",
341 "name",
342 "body",
343 "lineno",
344 "col_offset",
346 static PyTypeObject *arguments_type;
347 static PyObject* ast2obj_arguments(void*);
348 static char *arguments_fields[]={
349 "args",
350 "vararg",
351 "kwarg",
352 "defaults",
354 static PyTypeObject *keyword_type;
355 static PyObject* ast2obj_keyword(void*);
356 static char *keyword_fields[]={
357 "arg",
358 "value",
360 static PyTypeObject *alias_type;
361 static PyObject* ast2obj_alias(void*);
362 static char *alias_fields[]={
363 "name",
364 "asname",
368 static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields)
370 PyObject *fnames, *result;
371 int i;
372 if (num_fields) {
373 fnames = PyTuple_New(num_fields);
374 if (!fnames) return NULL;
375 } else {
376 fnames = Py_None;
377 Py_INCREF(Py_None);
379 for(i=0; i < num_fields; i++) {
380 PyObject *field = PyString_FromString(fields[i]);
381 if (!field) {
382 Py_DECREF(fnames);
383 return NULL;
385 PyTuple_SET_ITEM(fnames, i, field);
387 result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}",
388 type, base, "_fields", fnames, "__module__", "_ast");
389 Py_DECREF(fnames);
390 return (PyTypeObject*)result;
393 static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)
395 int i, result;
396 PyObject *s, *l = PyList_New(num_fields);
397 if (!l) return 0;
398 for(i = 0; i < num_fields; i++) {
399 s = PyString_FromString(attrs[i]);
400 if (!s) {
401 Py_DECREF(l);
402 return 0;
404 PyList_SET_ITEM(l, i, s);
406 result = PyObject_SetAttrString((PyObject*)type, "_attributes", l) >= 0;
407 Py_DECREF(l);
408 return result;
411 static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
413 int i, n = asdl_seq_LEN(seq);
414 PyObject *result = PyList_New(n);
415 PyObject *value;
416 if (!result)
417 return NULL;
418 for (i = 0; i < n; i++) {
419 value = func(asdl_seq_GET(seq, i));
420 if (!value) {
421 Py_DECREF(result);
422 return NULL;
424 PyList_SET_ITEM(result, i, value);
426 return result;
429 static PyObject* ast2obj_object(void *o)
431 if (!o)
432 o = Py_None;
433 Py_INCREF((PyObject*)o);
434 return (PyObject*)o;
436 #define ast2obj_identifier ast2obj_object
437 #define ast2obj_string ast2obj_object
438 static PyObject* ast2obj_bool(bool b)
440 return PyBool_FromLong(b);
443 static PyObject* ast2obj_int(long b)
445 return PyInt_FromLong(b);
448 static int init_types(void)
450 static int initialized;
451 if (initialized) return 1;
452 AST_type = make_type("AST", &PyBaseObject_Type, NULL, 0);
453 mod_type = make_type("mod", AST_type, NULL, 0);
454 if (!mod_type) return 0;
455 if (!add_attributes(mod_type, NULL, 0)) return 0;
456 Module_type = make_type("Module", mod_type, Module_fields, 1);
457 if (!Module_type) return 0;
458 Interactive_type = make_type("Interactive", mod_type,
459 Interactive_fields, 1);
460 if (!Interactive_type) return 0;
461 Expression_type = make_type("Expression", mod_type, Expression_fields,
463 if (!Expression_type) return 0;
464 Suite_type = make_type("Suite", mod_type, Suite_fields, 1);
465 if (!Suite_type) return 0;
466 stmt_type = make_type("stmt", AST_type, NULL, 0);
467 if (!stmt_type) return 0;
468 if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0;
469 FunctionDef_type = make_type("FunctionDef", stmt_type,
470 FunctionDef_fields, 4);
471 if (!FunctionDef_type) return 0;
472 ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 3);
473 if (!ClassDef_type) return 0;
474 Return_type = make_type("Return", stmt_type, Return_fields, 1);
475 if (!Return_type) return 0;
476 Delete_type = make_type("Delete", stmt_type, Delete_fields, 1);
477 if (!Delete_type) return 0;
478 Assign_type = make_type("Assign", stmt_type, Assign_fields, 2);
479 if (!Assign_type) return 0;
480 AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3);
481 if (!AugAssign_type) return 0;
482 Print_type = make_type("Print", stmt_type, Print_fields, 3);
483 if (!Print_type) return 0;
484 For_type = make_type("For", stmt_type, For_fields, 4);
485 if (!For_type) return 0;
486 While_type = make_type("While", stmt_type, While_fields, 3);
487 if (!While_type) return 0;
488 If_type = make_type("If", stmt_type, If_fields, 3);
489 if (!If_type) return 0;
490 With_type = make_type("With", stmt_type, With_fields, 3);
491 if (!With_type) return 0;
492 Raise_type = make_type("Raise", stmt_type, Raise_fields, 3);
493 if (!Raise_type) return 0;
494 TryExcept_type = make_type("TryExcept", stmt_type, TryExcept_fields, 3);
495 if (!TryExcept_type) return 0;
496 TryFinally_type = make_type("TryFinally", stmt_type, TryFinally_fields,
498 if (!TryFinally_type) return 0;
499 Assert_type = make_type("Assert", stmt_type, Assert_fields, 2);
500 if (!Assert_type) return 0;
501 Import_type = make_type("Import", stmt_type, Import_fields, 1);
502 if (!Import_type) return 0;
503 ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields,
505 if (!ImportFrom_type) return 0;
506 Exec_type = make_type("Exec", stmt_type, Exec_fields, 3);
507 if (!Exec_type) return 0;
508 Global_type = make_type("Global", stmt_type, Global_fields, 1);
509 if (!Global_type) return 0;
510 Expr_type = make_type("Expr", stmt_type, Expr_fields, 1);
511 if (!Expr_type) return 0;
512 Pass_type = make_type("Pass", stmt_type, NULL, 0);
513 if (!Pass_type) return 0;
514 Break_type = make_type("Break", stmt_type, NULL, 0);
515 if (!Break_type) return 0;
516 Continue_type = make_type("Continue", stmt_type, NULL, 0);
517 if (!Continue_type) return 0;
518 expr_type = make_type("expr", AST_type, NULL, 0);
519 if (!expr_type) return 0;
520 if (!add_attributes(expr_type, expr_attributes, 2)) return 0;
521 BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2);
522 if (!BoolOp_type) return 0;
523 BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3);
524 if (!BinOp_type) return 0;
525 UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2);
526 if (!UnaryOp_type) return 0;
527 Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2);
528 if (!Lambda_type) return 0;
529 IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3);
530 if (!IfExp_type) return 0;
531 Dict_type = make_type("Dict", expr_type, Dict_fields, 2);
532 if (!Dict_type) return 0;
533 ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2);
534 if (!ListComp_type) return 0;
535 GeneratorExp_type = make_type("GeneratorExp", expr_type,
536 GeneratorExp_fields, 2);
537 if (!GeneratorExp_type) return 0;
538 Yield_type = make_type("Yield", expr_type, Yield_fields, 1);
539 if (!Yield_type) return 0;
540 Compare_type = make_type("Compare", expr_type, Compare_fields, 3);
541 if (!Compare_type) return 0;
542 Call_type = make_type("Call", expr_type, Call_fields, 5);
543 if (!Call_type) return 0;
544 Repr_type = make_type("Repr", expr_type, Repr_fields, 1);
545 if (!Repr_type) return 0;
546 Num_type = make_type("Num", expr_type, Num_fields, 1);
547 if (!Num_type) return 0;
548 Str_type = make_type("Str", expr_type, Str_fields, 1);
549 if (!Str_type) return 0;
550 Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3);
551 if (!Attribute_type) return 0;
552 Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3);
553 if (!Subscript_type) return 0;
554 Name_type = make_type("Name", expr_type, Name_fields, 2);
555 if (!Name_type) return 0;
556 List_type = make_type("List", expr_type, List_fields, 2);
557 if (!List_type) return 0;
558 Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2);
559 if (!Tuple_type) return 0;
560 expr_context_type = make_type("expr_context", AST_type, NULL, 0);
561 if (!expr_context_type) return 0;
562 if (!add_attributes(expr_context_type, NULL, 0)) return 0;
563 Load_type = make_type("Load", expr_context_type, NULL, 0);
564 if (!Load_type) return 0;
565 Load_singleton = PyType_GenericNew(Load_type, NULL, NULL);
566 if (!Load_singleton) return 0;
567 Store_type = make_type("Store", expr_context_type, NULL, 0);
568 if (!Store_type) return 0;
569 Store_singleton = PyType_GenericNew(Store_type, NULL, NULL);
570 if (!Store_singleton) return 0;
571 Del_type = make_type("Del", expr_context_type, NULL, 0);
572 if (!Del_type) return 0;
573 Del_singleton = PyType_GenericNew(Del_type, NULL, NULL);
574 if (!Del_singleton) return 0;
575 AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0);
576 if (!AugLoad_type) return 0;
577 AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL);
578 if (!AugLoad_singleton) return 0;
579 AugStore_type = make_type("AugStore", expr_context_type, NULL, 0);
580 if (!AugStore_type) return 0;
581 AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL);
582 if (!AugStore_singleton) return 0;
583 Param_type = make_type("Param", expr_context_type, NULL, 0);
584 if (!Param_type) return 0;
585 Param_singleton = PyType_GenericNew(Param_type, NULL, NULL);
586 if (!Param_singleton) return 0;
587 slice_type = make_type("slice", AST_type, NULL, 0);
588 if (!slice_type) return 0;
589 if (!add_attributes(slice_type, NULL, 0)) return 0;
590 Ellipsis_type = make_type("Ellipsis", slice_type, NULL, 0);
591 if (!Ellipsis_type) return 0;
592 Slice_type = make_type("Slice", slice_type, Slice_fields, 3);
593 if (!Slice_type) return 0;
594 ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1);
595 if (!ExtSlice_type) return 0;
596 Index_type = make_type("Index", slice_type, Index_fields, 1);
597 if (!Index_type) return 0;
598 boolop_type = make_type("boolop", AST_type, NULL, 0);
599 if (!boolop_type) return 0;
600 if (!add_attributes(boolop_type, NULL, 0)) return 0;
601 And_type = make_type("And", boolop_type, NULL, 0);
602 if (!And_type) return 0;
603 And_singleton = PyType_GenericNew(And_type, NULL, NULL);
604 if (!And_singleton) return 0;
605 Or_type = make_type("Or", boolop_type, NULL, 0);
606 if (!Or_type) return 0;
607 Or_singleton = PyType_GenericNew(Or_type, NULL, NULL);
608 if (!Or_singleton) return 0;
609 operator_type = make_type("operator", AST_type, NULL, 0);
610 if (!operator_type) return 0;
611 if (!add_attributes(operator_type, NULL, 0)) return 0;
612 Add_type = make_type("Add", operator_type, NULL, 0);
613 if (!Add_type) return 0;
614 Add_singleton = PyType_GenericNew(Add_type, NULL, NULL);
615 if (!Add_singleton) return 0;
616 Sub_type = make_type("Sub", operator_type, NULL, 0);
617 if (!Sub_type) return 0;
618 Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL);
619 if (!Sub_singleton) return 0;
620 Mult_type = make_type("Mult", operator_type, NULL, 0);
621 if (!Mult_type) return 0;
622 Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL);
623 if (!Mult_singleton) return 0;
624 Div_type = make_type("Div", operator_type, NULL, 0);
625 if (!Div_type) return 0;
626 Div_singleton = PyType_GenericNew(Div_type, NULL, NULL);
627 if (!Div_singleton) return 0;
628 Mod_type = make_type("Mod", operator_type, NULL, 0);
629 if (!Mod_type) return 0;
630 Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL);
631 if (!Mod_singleton) return 0;
632 Pow_type = make_type("Pow", operator_type, NULL, 0);
633 if (!Pow_type) return 0;
634 Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL);
635 if (!Pow_singleton) return 0;
636 LShift_type = make_type("LShift", operator_type, NULL, 0);
637 if (!LShift_type) return 0;
638 LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL);
639 if (!LShift_singleton) return 0;
640 RShift_type = make_type("RShift", operator_type, NULL, 0);
641 if (!RShift_type) return 0;
642 RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL);
643 if (!RShift_singleton) return 0;
644 BitOr_type = make_type("BitOr", operator_type, NULL, 0);
645 if (!BitOr_type) return 0;
646 BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL);
647 if (!BitOr_singleton) return 0;
648 BitXor_type = make_type("BitXor", operator_type, NULL, 0);
649 if (!BitXor_type) return 0;
650 BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL);
651 if (!BitXor_singleton) return 0;
652 BitAnd_type = make_type("BitAnd", operator_type, NULL, 0);
653 if (!BitAnd_type) return 0;
654 BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL);
655 if (!BitAnd_singleton) return 0;
656 FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0);
657 if (!FloorDiv_type) return 0;
658 FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL);
659 if (!FloorDiv_singleton) return 0;
660 unaryop_type = make_type("unaryop", AST_type, NULL, 0);
661 if (!unaryop_type) return 0;
662 if (!add_attributes(unaryop_type, NULL, 0)) return 0;
663 Invert_type = make_type("Invert", unaryop_type, NULL, 0);
664 if (!Invert_type) return 0;
665 Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL);
666 if (!Invert_singleton) return 0;
667 Not_type = make_type("Not", unaryop_type, NULL, 0);
668 if (!Not_type) return 0;
669 Not_singleton = PyType_GenericNew(Not_type, NULL, NULL);
670 if (!Not_singleton) return 0;
671 UAdd_type = make_type("UAdd", unaryop_type, NULL, 0);
672 if (!UAdd_type) return 0;
673 UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL);
674 if (!UAdd_singleton) return 0;
675 USub_type = make_type("USub", unaryop_type, NULL, 0);
676 if (!USub_type) return 0;
677 USub_singleton = PyType_GenericNew(USub_type, NULL, NULL);
678 if (!USub_singleton) return 0;
679 cmpop_type = make_type("cmpop", AST_type, NULL, 0);
680 if (!cmpop_type) return 0;
681 if (!add_attributes(cmpop_type, NULL, 0)) return 0;
682 Eq_type = make_type("Eq", cmpop_type, NULL, 0);
683 if (!Eq_type) return 0;
684 Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL);
685 if (!Eq_singleton) return 0;
686 NotEq_type = make_type("NotEq", cmpop_type, NULL, 0);
687 if (!NotEq_type) return 0;
688 NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL);
689 if (!NotEq_singleton) return 0;
690 Lt_type = make_type("Lt", cmpop_type, NULL, 0);
691 if (!Lt_type) return 0;
692 Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL);
693 if (!Lt_singleton) return 0;
694 LtE_type = make_type("LtE", cmpop_type, NULL, 0);
695 if (!LtE_type) return 0;
696 LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL);
697 if (!LtE_singleton) return 0;
698 Gt_type = make_type("Gt", cmpop_type, NULL, 0);
699 if (!Gt_type) return 0;
700 Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL);
701 if (!Gt_singleton) return 0;
702 GtE_type = make_type("GtE", cmpop_type, NULL, 0);
703 if (!GtE_type) return 0;
704 GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL);
705 if (!GtE_singleton) return 0;
706 Is_type = make_type("Is", cmpop_type, NULL, 0);
707 if (!Is_type) return 0;
708 Is_singleton = PyType_GenericNew(Is_type, NULL, NULL);
709 if (!Is_singleton) return 0;
710 IsNot_type = make_type("IsNot", cmpop_type, NULL, 0);
711 if (!IsNot_type) return 0;
712 IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL);
713 if (!IsNot_singleton) return 0;
714 In_type = make_type("In", cmpop_type, NULL, 0);
715 if (!In_type) return 0;
716 In_singleton = PyType_GenericNew(In_type, NULL, NULL);
717 if (!In_singleton) return 0;
718 NotIn_type = make_type("NotIn", cmpop_type, NULL, 0);
719 if (!NotIn_type) return 0;
720 NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL);
721 if (!NotIn_singleton) return 0;
722 comprehension_type = make_type("comprehension", AST_type,
723 comprehension_fields, 3);
724 if (!comprehension_type) return 0;
725 excepthandler_type = make_type("excepthandler", AST_type,
726 excepthandler_fields, 5);
727 if (!excepthandler_type) return 0;
728 arguments_type = make_type("arguments", AST_type, arguments_fields, 4);
729 if (!arguments_type) return 0;
730 keyword_type = make_type("keyword", AST_type, keyword_fields, 2);
731 if (!keyword_type) return 0;
732 alias_type = make_type("alias", AST_type, alias_fields, 2);
733 if (!alias_type) return 0;
734 initialized = 1;
735 return 1;
738 mod_ty
739 Module(asdl_seq * body, PyArena *arena)
741 mod_ty p;
742 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
743 if (!p)
744 return NULL;
745 p->kind = Module_kind;
746 p->v.Module.body = body;
747 return p;
750 mod_ty
751 Interactive(asdl_seq * body, PyArena *arena)
753 mod_ty p;
754 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
755 if (!p)
756 return NULL;
757 p->kind = Interactive_kind;
758 p->v.Interactive.body = body;
759 return p;
762 mod_ty
763 Expression(expr_ty body, PyArena *arena)
765 mod_ty p;
766 if (!body) {
767 PyErr_SetString(PyExc_ValueError,
768 "field body is required for Expression");
769 return NULL;
771 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
772 if (!p)
773 return NULL;
774 p->kind = Expression_kind;
775 p->v.Expression.body = body;
776 return p;
779 mod_ty
780 Suite(asdl_seq * body, PyArena *arena)
782 mod_ty p;
783 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
784 if (!p)
785 return NULL;
786 p->kind = Suite_kind;
787 p->v.Suite.body = body;
788 return p;
791 stmt_ty
792 FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
793 decorators, int lineno, int col_offset, PyArena *arena)
795 stmt_ty p;
796 if (!name) {
797 PyErr_SetString(PyExc_ValueError,
798 "field name is required for FunctionDef");
799 return NULL;
801 if (!args) {
802 PyErr_SetString(PyExc_ValueError,
803 "field args is required for FunctionDef");
804 return NULL;
806 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
807 if (!p)
808 return NULL;
809 p->kind = FunctionDef_kind;
810 p->v.FunctionDef.name = name;
811 p->v.FunctionDef.args = args;
812 p->v.FunctionDef.body = body;
813 p->v.FunctionDef.decorators = decorators;
814 p->lineno = lineno;
815 p->col_offset = col_offset;
816 return p;
819 stmt_ty
820 ClassDef(identifier name, asdl_seq * bases, asdl_seq * body, int lineno, int
821 col_offset, PyArena *arena)
823 stmt_ty p;
824 if (!name) {
825 PyErr_SetString(PyExc_ValueError,
826 "field name is required for ClassDef");
827 return NULL;
829 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
830 if (!p)
831 return NULL;
832 p->kind = ClassDef_kind;
833 p->v.ClassDef.name = name;
834 p->v.ClassDef.bases = bases;
835 p->v.ClassDef.body = body;
836 p->lineno = lineno;
837 p->col_offset = col_offset;
838 return p;
841 stmt_ty
842 Return(expr_ty value, int lineno, int col_offset, PyArena *arena)
844 stmt_ty p;
845 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
846 if (!p)
847 return NULL;
848 p->kind = Return_kind;
849 p->v.Return.value = value;
850 p->lineno = lineno;
851 p->col_offset = col_offset;
852 return p;
855 stmt_ty
856 Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena)
858 stmt_ty p;
859 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
860 if (!p)
861 return NULL;
862 p->kind = Delete_kind;
863 p->v.Delete.targets = targets;
864 p->lineno = lineno;
865 p->col_offset = col_offset;
866 return p;
869 stmt_ty
870 Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena
871 *arena)
873 stmt_ty p;
874 if (!value) {
875 PyErr_SetString(PyExc_ValueError,
876 "field value is required for Assign");
877 return NULL;
879 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
880 if (!p)
881 return NULL;
882 p->kind = Assign_kind;
883 p->v.Assign.targets = targets;
884 p->v.Assign.value = value;
885 p->lineno = lineno;
886 p->col_offset = col_offset;
887 return p;
890 stmt_ty
891 AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
892 col_offset, PyArena *arena)
894 stmt_ty p;
895 if (!target) {
896 PyErr_SetString(PyExc_ValueError,
897 "field target is required for AugAssign");
898 return NULL;
900 if (!op) {
901 PyErr_SetString(PyExc_ValueError,
902 "field op is required for AugAssign");
903 return NULL;
905 if (!value) {
906 PyErr_SetString(PyExc_ValueError,
907 "field value is required for AugAssign");
908 return NULL;
910 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
911 if (!p)
912 return NULL;
913 p->kind = AugAssign_kind;
914 p->v.AugAssign.target = target;
915 p->v.AugAssign.op = op;
916 p->v.AugAssign.value = value;
917 p->lineno = lineno;
918 p->col_offset = col_offset;
919 return p;
922 stmt_ty
923 Print(expr_ty dest, asdl_seq * values, bool nl, int lineno, int col_offset,
924 PyArena *arena)
926 stmt_ty p;
927 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
928 if (!p)
929 return NULL;
930 p->kind = Print_kind;
931 p->v.Print.dest = dest;
932 p->v.Print.values = values;
933 p->v.Print.nl = nl;
934 p->lineno = lineno;
935 p->col_offset = col_offset;
936 return p;
939 stmt_ty
940 For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int
941 lineno, int col_offset, PyArena *arena)
943 stmt_ty p;
944 if (!target) {
945 PyErr_SetString(PyExc_ValueError,
946 "field target is required for For");
947 return NULL;
949 if (!iter) {
950 PyErr_SetString(PyExc_ValueError,
951 "field iter is required for For");
952 return NULL;
954 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
955 if (!p)
956 return NULL;
957 p->kind = For_kind;
958 p->v.For.target = target;
959 p->v.For.iter = iter;
960 p->v.For.body = body;
961 p->v.For.orelse = orelse;
962 p->lineno = lineno;
963 p->col_offset = col_offset;
964 return p;
967 stmt_ty
968 While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
969 col_offset, PyArena *arena)
971 stmt_ty p;
972 if (!test) {
973 PyErr_SetString(PyExc_ValueError,
974 "field test is required for While");
975 return NULL;
977 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
978 if (!p)
979 return NULL;
980 p->kind = While_kind;
981 p->v.While.test = test;
982 p->v.While.body = body;
983 p->v.While.orelse = orelse;
984 p->lineno = lineno;
985 p->col_offset = col_offset;
986 return p;
989 stmt_ty
990 If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
991 col_offset, PyArena *arena)
993 stmt_ty p;
994 if (!test) {
995 PyErr_SetString(PyExc_ValueError,
996 "field test is required for If");
997 return NULL;
999 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1000 if (!p)
1001 return NULL;
1002 p->kind = If_kind;
1003 p->v.If.test = test;
1004 p->v.If.body = body;
1005 p->v.If.orelse = orelse;
1006 p->lineno = lineno;
1007 p->col_offset = col_offset;
1008 return p;
1011 stmt_ty
1012 With(expr_ty context_expr, expr_ty optional_vars, asdl_seq * body, int lineno,
1013 int col_offset, PyArena *arena)
1015 stmt_ty p;
1016 if (!context_expr) {
1017 PyErr_SetString(PyExc_ValueError,
1018 "field context_expr is required for With");
1019 return NULL;
1021 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1022 if (!p)
1023 return NULL;
1024 p->kind = With_kind;
1025 p->v.With.context_expr = context_expr;
1026 p->v.With.optional_vars = optional_vars;
1027 p->v.With.body = body;
1028 p->lineno = lineno;
1029 p->col_offset = col_offset;
1030 return p;
1033 stmt_ty
1034 Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno, int col_offset,
1035 PyArena *arena)
1037 stmt_ty p;
1038 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1039 if (!p)
1040 return NULL;
1041 p->kind = Raise_kind;
1042 p->v.Raise.type = type;
1043 p->v.Raise.inst = inst;
1044 p->v.Raise.tback = tback;
1045 p->lineno = lineno;
1046 p->col_offset = col_offset;
1047 return p;
1050 stmt_ty
1051 TryExcept(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, int lineno,
1052 int col_offset, PyArena *arena)
1054 stmt_ty p;
1055 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1056 if (!p)
1057 return NULL;
1058 p->kind = TryExcept_kind;
1059 p->v.TryExcept.body = body;
1060 p->v.TryExcept.handlers = handlers;
1061 p->v.TryExcept.orelse = orelse;
1062 p->lineno = lineno;
1063 p->col_offset = col_offset;
1064 return p;
1067 stmt_ty
1068 TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, int col_offset,
1069 PyArena *arena)
1071 stmt_ty p;
1072 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1073 if (!p)
1074 return NULL;
1075 p->kind = TryFinally_kind;
1076 p->v.TryFinally.body = body;
1077 p->v.TryFinally.finalbody = finalbody;
1078 p->lineno = lineno;
1079 p->col_offset = col_offset;
1080 return p;
1083 stmt_ty
1084 Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, PyArena *arena)
1086 stmt_ty p;
1087 if (!test) {
1088 PyErr_SetString(PyExc_ValueError,
1089 "field test is required for Assert");
1090 return NULL;
1092 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1093 if (!p)
1094 return NULL;
1095 p->kind = Assert_kind;
1096 p->v.Assert.test = test;
1097 p->v.Assert.msg = msg;
1098 p->lineno = lineno;
1099 p->col_offset = col_offset;
1100 return p;
1103 stmt_ty
1104 Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
1106 stmt_ty p;
1107 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1108 if (!p)
1109 return NULL;
1110 p->kind = Import_kind;
1111 p->v.Import.names = names;
1112 p->lineno = lineno;
1113 p->col_offset = col_offset;
1114 return p;
1117 stmt_ty
1118 ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int
1119 col_offset, PyArena *arena)
1121 stmt_ty p;
1122 if (!module) {
1123 PyErr_SetString(PyExc_ValueError,
1124 "field module is required for ImportFrom");
1125 return NULL;
1127 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1128 if (!p)
1129 return NULL;
1130 p->kind = ImportFrom_kind;
1131 p->v.ImportFrom.module = module;
1132 p->v.ImportFrom.names = names;
1133 p->v.ImportFrom.level = level;
1134 p->lineno = lineno;
1135 p->col_offset = col_offset;
1136 return p;
1139 stmt_ty
1140 Exec(expr_ty body, expr_ty globals, expr_ty locals, int lineno, int col_offset,
1141 PyArena *arena)
1143 stmt_ty p;
1144 if (!body) {
1145 PyErr_SetString(PyExc_ValueError,
1146 "field body is required for Exec");
1147 return NULL;
1149 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1150 if (!p)
1151 return NULL;
1152 p->kind = Exec_kind;
1153 p->v.Exec.body = body;
1154 p->v.Exec.globals = globals;
1155 p->v.Exec.locals = locals;
1156 p->lineno = lineno;
1157 p->col_offset = col_offset;
1158 return p;
1161 stmt_ty
1162 Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
1164 stmt_ty p;
1165 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1166 if (!p)
1167 return NULL;
1168 p->kind = Global_kind;
1169 p->v.Global.names = names;
1170 p->lineno = lineno;
1171 p->col_offset = col_offset;
1172 return p;
1175 stmt_ty
1176 Expr(expr_ty value, int lineno, int col_offset, PyArena *arena)
1178 stmt_ty p;
1179 if (!value) {
1180 PyErr_SetString(PyExc_ValueError,
1181 "field value is required for Expr");
1182 return NULL;
1184 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1185 if (!p)
1186 return NULL;
1187 p->kind = Expr_kind;
1188 p->v.Expr.value = value;
1189 p->lineno = lineno;
1190 p->col_offset = col_offset;
1191 return p;
1194 stmt_ty
1195 Pass(int lineno, int col_offset, PyArena *arena)
1197 stmt_ty p;
1198 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1199 if (!p)
1200 return NULL;
1201 p->kind = Pass_kind;
1202 p->lineno = lineno;
1203 p->col_offset = col_offset;
1204 return p;
1207 stmt_ty
1208 Break(int lineno, int col_offset, PyArena *arena)
1210 stmt_ty p;
1211 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1212 if (!p)
1213 return NULL;
1214 p->kind = Break_kind;
1215 p->lineno = lineno;
1216 p->col_offset = col_offset;
1217 return p;
1220 stmt_ty
1221 Continue(int lineno, int col_offset, PyArena *arena)
1223 stmt_ty p;
1224 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1225 if (!p)
1226 return NULL;
1227 p->kind = Continue_kind;
1228 p->lineno = lineno;
1229 p->col_offset = col_offset;
1230 return p;
1233 expr_ty
1234 BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena
1235 *arena)
1237 expr_ty p;
1238 if (!op) {
1239 PyErr_SetString(PyExc_ValueError,
1240 "field op is required for BoolOp");
1241 return NULL;
1243 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1244 if (!p)
1245 return NULL;
1246 p->kind = BoolOp_kind;
1247 p->v.BoolOp.op = op;
1248 p->v.BoolOp.values = values;
1249 p->lineno = lineno;
1250 p->col_offset = col_offset;
1251 return p;
1254 expr_ty
1255 BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset,
1256 PyArena *arena)
1258 expr_ty p;
1259 if (!left) {
1260 PyErr_SetString(PyExc_ValueError,
1261 "field left is required for BinOp");
1262 return NULL;
1264 if (!op) {
1265 PyErr_SetString(PyExc_ValueError,
1266 "field op is required for BinOp");
1267 return NULL;
1269 if (!right) {
1270 PyErr_SetString(PyExc_ValueError,
1271 "field right is required for BinOp");
1272 return NULL;
1274 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1275 if (!p)
1276 return NULL;
1277 p->kind = BinOp_kind;
1278 p->v.BinOp.left = left;
1279 p->v.BinOp.op = op;
1280 p->v.BinOp.right = right;
1281 p->lineno = lineno;
1282 p->col_offset = col_offset;
1283 return p;
1286 expr_ty
1287 UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena
1288 *arena)
1290 expr_ty p;
1291 if (!op) {
1292 PyErr_SetString(PyExc_ValueError,
1293 "field op is required for UnaryOp");
1294 return NULL;
1296 if (!operand) {
1297 PyErr_SetString(PyExc_ValueError,
1298 "field operand is required for UnaryOp");
1299 return NULL;
1301 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1302 if (!p)
1303 return NULL;
1304 p->kind = UnaryOp_kind;
1305 p->v.UnaryOp.op = op;
1306 p->v.UnaryOp.operand = operand;
1307 p->lineno = lineno;
1308 p->col_offset = col_offset;
1309 return p;
1312 expr_ty
1313 Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena
1314 *arena)
1316 expr_ty p;
1317 if (!args) {
1318 PyErr_SetString(PyExc_ValueError,
1319 "field args is required for Lambda");
1320 return NULL;
1322 if (!body) {
1323 PyErr_SetString(PyExc_ValueError,
1324 "field body is required for Lambda");
1325 return NULL;
1327 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1328 if (!p)
1329 return NULL;
1330 p->kind = Lambda_kind;
1331 p->v.Lambda.args = args;
1332 p->v.Lambda.body = body;
1333 p->lineno = lineno;
1334 p->col_offset = col_offset;
1335 return p;
1338 expr_ty
1339 IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset,
1340 PyArena *arena)
1342 expr_ty p;
1343 if (!test) {
1344 PyErr_SetString(PyExc_ValueError,
1345 "field test is required for IfExp");
1346 return NULL;
1348 if (!body) {
1349 PyErr_SetString(PyExc_ValueError,
1350 "field body is required for IfExp");
1351 return NULL;
1353 if (!orelse) {
1354 PyErr_SetString(PyExc_ValueError,
1355 "field orelse is required for IfExp");
1356 return NULL;
1358 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1359 if (!p)
1360 return NULL;
1361 p->kind = IfExp_kind;
1362 p->v.IfExp.test = test;
1363 p->v.IfExp.body = body;
1364 p->v.IfExp.orelse = orelse;
1365 p->lineno = lineno;
1366 p->col_offset = col_offset;
1367 return p;
1370 expr_ty
1371 Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena
1372 *arena)
1374 expr_ty p;
1375 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1376 if (!p)
1377 return NULL;
1378 p->kind = Dict_kind;
1379 p->v.Dict.keys = keys;
1380 p->v.Dict.values = values;
1381 p->lineno = lineno;
1382 p->col_offset = col_offset;
1383 return p;
1386 expr_ty
1387 ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1388 PyArena *arena)
1390 expr_ty p;
1391 if (!elt) {
1392 PyErr_SetString(PyExc_ValueError,
1393 "field elt is required for ListComp");
1394 return NULL;
1396 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1397 if (!p)
1398 return NULL;
1399 p->kind = ListComp_kind;
1400 p->v.ListComp.elt = elt;
1401 p->v.ListComp.generators = generators;
1402 p->lineno = lineno;
1403 p->col_offset = col_offset;
1404 return p;
1407 expr_ty
1408 GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1409 PyArena *arena)
1411 expr_ty p;
1412 if (!elt) {
1413 PyErr_SetString(PyExc_ValueError,
1414 "field elt is required for GeneratorExp");
1415 return NULL;
1417 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1418 if (!p)
1419 return NULL;
1420 p->kind = GeneratorExp_kind;
1421 p->v.GeneratorExp.elt = elt;
1422 p->v.GeneratorExp.generators = generators;
1423 p->lineno = lineno;
1424 p->col_offset = col_offset;
1425 return p;
1428 expr_ty
1429 Yield(expr_ty value, int lineno, int col_offset, PyArena *arena)
1431 expr_ty p;
1432 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1433 if (!p)
1434 return NULL;
1435 p->kind = Yield_kind;
1436 p->v.Yield.value = value;
1437 p->lineno = lineno;
1438 p->col_offset = col_offset;
1439 return p;
1442 expr_ty
1443 Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno,
1444 int col_offset, PyArena *arena)
1446 expr_ty p;
1447 if (!left) {
1448 PyErr_SetString(PyExc_ValueError,
1449 "field left is required for Compare");
1450 return NULL;
1452 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1453 if (!p)
1454 return NULL;
1455 p->kind = Compare_kind;
1456 p->v.Compare.left = left;
1457 p->v.Compare.ops = ops;
1458 p->v.Compare.comparators = comparators;
1459 p->lineno = lineno;
1460 p->col_offset = col_offset;
1461 return p;
1464 expr_ty
1465 Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, expr_ty starargs,
1466 expr_ty kwargs, int lineno, int col_offset, PyArena *arena)
1468 expr_ty p;
1469 if (!func) {
1470 PyErr_SetString(PyExc_ValueError,
1471 "field func is required for Call");
1472 return NULL;
1474 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1475 if (!p)
1476 return NULL;
1477 p->kind = Call_kind;
1478 p->v.Call.func = func;
1479 p->v.Call.args = args;
1480 p->v.Call.keywords = keywords;
1481 p->v.Call.starargs = starargs;
1482 p->v.Call.kwargs = kwargs;
1483 p->lineno = lineno;
1484 p->col_offset = col_offset;
1485 return p;
1488 expr_ty
1489 Repr(expr_ty value, int lineno, int col_offset, PyArena *arena)
1491 expr_ty p;
1492 if (!value) {
1493 PyErr_SetString(PyExc_ValueError,
1494 "field value is required for Repr");
1495 return NULL;
1497 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1498 if (!p)
1499 return NULL;
1500 p->kind = Repr_kind;
1501 p->v.Repr.value = value;
1502 p->lineno = lineno;
1503 p->col_offset = col_offset;
1504 return p;
1507 expr_ty
1508 Num(object n, int lineno, int col_offset, PyArena *arena)
1510 expr_ty p;
1511 if (!n) {
1512 PyErr_SetString(PyExc_ValueError,
1513 "field n is required for Num");
1514 return NULL;
1516 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1517 if (!p)
1518 return NULL;
1519 p->kind = Num_kind;
1520 p->v.Num.n = n;
1521 p->lineno = lineno;
1522 p->col_offset = col_offset;
1523 return p;
1526 expr_ty
1527 Str(string s, int lineno, int col_offset, PyArena *arena)
1529 expr_ty p;
1530 if (!s) {
1531 PyErr_SetString(PyExc_ValueError,
1532 "field s is required for Str");
1533 return NULL;
1535 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1536 if (!p)
1537 return NULL;
1538 p->kind = Str_kind;
1539 p->v.Str.s = s;
1540 p->lineno = lineno;
1541 p->col_offset = col_offset;
1542 return p;
1545 expr_ty
1546 Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int
1547 col_offset, PyArena *arena)
1549 expr_ty p;
1550 if (!value) {
1551 PyErr_SetString(PyExc_ValueError,
1552 "field value is required for Attribute");
1553 return NULL;
1555 if (!attr) {
1556 PyErr_SetString(PyExc_ValueError,
1557 "field attr is required for Attribute");
1558 return NULL;
1560 if (!ctx) {
1561 PyErr_SetString(PyExc_ValueError,
1562 "field ctx is required for Attribute");
1563 return NULL;
1565 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1566 if (!p)
1567 return NULL;
1568 p->kind = Attribute_kind;
1569 p->v.Attribute.value = value;
1570 p->v.Attribute.attr = attr;
1571 p->v.Attribute.ctx = ctx;
1572 p->lineno = lineno;
1573 p->col_offset = col_offset;
1574 return p;
1577 expr_ty
1578 Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int
1579 col_offset, PyArena *arena)
1581 expr_ty p;
1582 if (!value) {
1583 PyErr_SetString(PyExc_ValueError,
1584 "field value is required for Subscript");
1585 return NULL;
1587 if (!slice) {
1588 PyErr_SetString(PyExc_ValueError,
1589 "field slice is required for Subscript");
1590 return NULL;
1592 if (!ctx) {
1593 PyErr_SetString(PyExc_ValueError,
1594 "field ctx is required for Subscript");
1595 return NULL;
1597 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1598 if (!p)
1599 return NULL;
1600 p->kind = Subscript_kind;
1601 p->v.Subscript.value = value;
1602 p->v.Subscript.slice = slice;
1603 p->v.Subscript.ctx = ctx;
1604 p->lineno = lineno;
1605 p->col_offset = col_offset;
1606 return p;
1609 expr_ty
1610 Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena
1611 *arena)
1613 expr_ty p;
1614 if (!id) {
1615 PyErr_SetString(PyExc_ValueError,
1616 "field id is required for Name");
1617 return NULL;
1619 if (!ctx) {
1620 PyErr_SetString(PyExc_ValueError,
1621 "field ctx is required for Name");
1622 return NULL;
1624 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1625 if (!p)
1626 return NULL;
1627 p->kind = Name_kind;
1628 p->v.Name.id = id;
1629 p->v.Name.ctx = ctx;
1630 p->lineno = lineno;
1631 p->col_offset = col_offset;
1632 return p;
1635 expr_ty
1636 List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1637 *arena)
1639 expr_ty p;
1640 if (!ctx) {
1641 PyErr_SetString(PyExc_ValueError,
1642 "field ctx is required for List");
1643 return NULL;
1645 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1646 if (!p)
1647 return NULL;
1648 p->kind = List_kind;
1649 p->v.List.elts = elts;
1650 p->v.List.ctx = ctx;
1651 p->lineno = lineno;
1652 p->col_offset = col_offset;
1653 return p;
1656 expr_ty
1657 Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1658 *arena)
1660 expr_ty p;
1661 if (!ctx) {
1662 PyErr_SetString(PyExc_ValueError,
1663 "field ctx is required for Tuple");
1664 return NULL;
1666 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1667 if (!p)
1668 return NULL;
1669 p->kind = Tuple_kind;
1670 p->v.Tuple.elts = elts;
1671 p->v.Tuple.ctx = ctx;
1672 p->lineno = lineno;
1673 p->col_offset = col_offset;
1674 return p;
1677 slice_ty
1678 Ellipsis(PyArena *arena)
1680 slice_ty p;
1681 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
1682 if (!p)
1683 return NULL;
1684 p->kind = Ellipsis_kind;
1685 return p;
1688 slice_ty
1689 Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena)
1691 slice_ty p;
1692 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
1693 if (!p)
1694 return NULL;
1695 p->kind = Slice_kind;
1696 p->v.Slice.lower = lower;
1697 p->v.Slice.upper = upper;
1698 p->v.Slice.step = step;
1699 return p;
1702 slice_ty
1703 ExtSlice(asdl_seq * dims, PyArena *arena)
1705 slice_ty p;
1706 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
1707 if (!p)
1708 return NULL;
1709 p->kind = ExtSlice_kind;
1710 p->v.ExtSlice.dims = dims;
1711 return p;
1714 slice_ty
1715 Index(expr_ty value, PyArena *arena)
1717 slice_ty p;
1718 if (!value) {
1719 PyErr_SetString(PyExc_ValueError,
1720 "field value is required for Index");
1721 return NULL;
1723 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
1724 if (!p)
1725 return NULL;
1726 p->kind = Index_kind;
1727 p->v.Index.value = value;
1728 return p;
1731 comprehension_ty
1732 comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena)
1734 comprehension_ty p;
1735 if (!target) {
1736 PyErr_SetString(PyExc_ValueError,
1737 "field target is required for comprehension");
1738 return NULL;
1740 if (!iter) {
1741 PyErr_SetString(PyExc_ValueError,
1742 "field iter is required for comprehension");
1743 return NULL;
1745 p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));
1746 if (!p)
1747 return NULL;
1748 p->target = target;
1749 p->iter = iter;
1750 p->ifs = ifs;
1751 return p;
1754 excepthandler_ty
1755 excepthandler(expr_ty type, expr_ty name, asdl_seq * body, int lineno, int
1756 col_offset, PyArena *arena)
1758 excepthandler_ty p;
1759 p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
1760 if (!p)
1761 return NULL;
1762 p->type = type;
1763 p->name = name;
1764 p->body = body;
1765 p->lineno = lineno;
1766 p->col_offset = col_offset;
1767 return p;
1770 arguments_ty
1771 arguments(asdl_seq * args, identifier vararg, identifier kwarg, asdl_seq *
1772 defaults, PyArena *arena)
1774 arguments_ty p;
1775 p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
1776 if (!p)
1777 return NULL;
1778 p->args = args;
1779 p->vararg = vararg;
1780 p->kwarg = kwarg;
1781 p->defaults = defaults;
1782 return p;
1785 keyword_ty
1786 keyword(identifier arg, expr_ty value, PyArena *arena)
1788 keyword_ty p;
1789 if (!arg) {
1790 PyErr_SetString(PyExc_ValueError,
1791 "field arg is required for keyword");
1792 return NULL;
1794 if (!value) {
1795 PyErr_SetString(PyExc_ValueError,
1796 "field value is required for keyword");
1797 return NULL;
1799 p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));
1800 if (!p)
1801 return NULL;
1802 p->arg = arg;
1803 p->value = value;
1804 return p;
1807 alias_ty
1808 alias(identifier name, identifier asname, PyArena *arena)
1810 alias_ty p;
1811 if (!name) {
1812 PyErr_SetString(PyExc_ValueError,
1813 "field name is required for alias");
1814 return NULL;
1816 p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));
1817 if (!p)
1818 return NULL;
1819 p->name = name;
1820 p->asname = asname;
1821 return p;
1825 PyObject*
1826 ast2obj_mod(void* _o)
1828 mod_ty o = (mod_ty)_o;
1829 PyObject *result = NULL, *value = NULL;
1830 if (!o) {
1831 Py_INCREF(Py_None);
1832 return Py_None;
1835 switch (o->kind) {
1836 case Module_kind:
1837 result = PyType_GenericNew(Module_type, NULL, NULL);
1838 if (!result) goto failed;
1839 value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
1840 if (!value) goto failed;
1841 if (PyObject_SetAttrString(result, "body", value) == -1)
1842 goto failed;
1843 Py_DECREF(value);
1844 break;
1845 case Interactive_kind:
1846 result = PyType_GenericNew(Interactive_type, NULL, NULL);
1847 if (!result) goto failed;
1848 value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
1849 if (!value) goto failed;
1850 if (PyObject_SetAttrString(result, "body", value) == -1)
1851 goto failed;
1852 Py_DECREF(value);
1853 break;
1854 case Expression_kind:
1855 result = PyType_GenericNew(Expression_type, NULL, NULL);
1856 if (!result) goto failed;
1857 value = ast2obj_expr(o->v.Expression.body);
1858 if (!value) goto failed;
1859 if (PyObject_SetAttrString(result, "body", value) == -1)
1860 goto failed;
1861 Py_DECREF(value);
1862 break;
1863 case Suite_kind:
1864 result = PyType_GenericNew(Suite_type, NULL, NULL);
1865 if (!result) goto failed;
1866 value = ast2obj_list(o->v.Suite.body, ast2obj_stmt);
1867 if (!value) goto failed;
1868 if (PyObject_SetAttrString(result, "body", value) == -1)
1869 goto failed;
1870 Py_DECREF(value);
1871 break;
1873 return result;
1874 failed:
1875 Py_XDECREF(value);
1876 Py_XDECREF(result);
1877 return NULL;
1880 PyObject*
1881 ast2obj_stmt(void* _o)
1883 stmt_ty o = (stmt_ty)_o;
1884 PyObject *result = NULL, *value = NULL;
1885 if (!o) {
1886 Py_INCREF(Py_None);
1887 return Py_None;
1890 switch (o->kind) {
1891 case FunctionDef_kind:
1892 result = PyType_GenericNew(FunctionDef_type, NULL, NULL);
1893 if (!result) goto failed;
1894 value = ast2obj_identifier(o->v.FunctionDef.name);
1895 if (!value) goto failed;
1896 if (PyObject_SetAttrString(result, "name", value) == -1)
1897 goto failed;
1898 Py_DECREF(value);
1899 value = ast2obj_arguments(o->v.FunctionDef.args);
1900 if (!value) goto failed;
1901 if (PyObject_SetAttrString(result, "args", value) == -1)
1902 goto failed;
1903 Py_DECREF(value);
1904 value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
1905 if (!value) goto failed;
1906 if (PyObject_SetAttrString(result, "body", value) == -1)
1907 goto failed;
1908 Py_DECREF(value);
1909 value = ast2obj_list(o->v.FunctionDef.decorators, ast2obj_expr);
1910 if (!value) goto failed;
1911 if (PyObject_SetAttrString(result, "decorators", value) == -1)
1912 goto failed;
1913 Py_DECREF(value);
1914 break;
1915 case ClassDef_kind:
1916 result = PyType_GenericNew(ClassDef_type, NULL, NULL);
1917 if (!result) goto failed;
1918 value = ast2obj_identifier(o->v.ClassDef.name);
1919 if (!value) goto failed;
1920 if (PyObject_SetAttrString(result, "name", value) == -1)
1921 goto failed;
1922 Py_DECREF(value);
1923 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
1924 if (!value) goto failed;
1925 if (PyObject_SetAttrString(result, "bases", value) == -1)
1926 goto failed;
1927 Py_DECREF(value);
1928 value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
1929 if (!value) goto failed;
1930 if (PyObject_SetAttrString(result, "body", value) == -1)
1931 goto failed;
1932 Py_DECREF(value);
1933 break;
1934 case Return_kind:
1935 result = PyType_GenericNew(Return_type, NULL, NULL);
1936 if (!result) goto failed;
1937 value = ast2obj_expr(o->v.Return.value);
1938 if (!value) goto failed;
1939 if (PyObject_SetAttrString(result, "value", value) == -1)
1940 goto failed;
1941 Py_DECREF(value);
1942 break;
1943 case Delete_kind:
1944 result = PyType_GenericNew(Delete_type, NULL, NULL);
1945 if (!result) goto failed;
1946 value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
1947 if (!value) goto failed;
1948 if (PyObject_SetAttrString(result, "targets", value) == -1)
1949 goto failed;
1950 Py_DECREF(value);
1951 break;
1952 case Assign_kind:
1953 result = PyType_GenericNew(Assign_type, NULL, NULL);
1954 if (!result) goto failed;
1955 value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
1956 if (!value) goto failed;
1957 if (PyObject_SetAttrString(result, "targets", value) == -1)
1958 goto failed;
1959 Py_DECREF(value);
1960 value = ast2obj_expr(o->v.Assign.value);
1961 if (!value) goto failed;
1962 if (PyObject_SetAttrString(result, "value", value) == -1)
1963 goto failed;
1964 Py_DECREF(value);
1965 break;
1966 case AugAssign_kind:
1967 result = PyType_GenericNew(AugAssign_type, NULL, NULL);
1968 if (!result) goto failed;
1969 value = ast2obj_expr(o->v.AugAssign.target);
1970 if (!value) goto failed;
1971 if (PyObject_SetAttrString(result, "target", value) == -1)
1972 goto failed;
1973 Py_DECREF(value);
1974 value = ast2obj_operator(o->v.AugAssign.op);
1975 if (!value) goto failed;
1976 if (PyObject_SetAttrString(result, "op", value) == -1)
1977 goto failed;
1978 Py_DECREF(value);
1979 value = ast2obj_expr(o->v.AugAssign.value);
1980 if (!value) goto failed;
1981 if (PyObject_SetAttrString(result, "value", value) == -1)
1982 goto failed;
1983 Py_DECREF(value);
1984 break;
1985 case Print_kind:
1986 result = PyType_GenericNew(Print_type, NULL, NULL);
1987 if (!result) goto failed;
1988 value = ast2obj_expr(o->v.Print.dest);
1989 if (!value) goto failed;
1990 if (PyObject_SetAttrString(result, "dest", value) == -1)
1991 goto failed;
1992 Py_DECREF(value);
1993 value = ast2obj_list(o->v.Print.values, ast2obj_expr);
1994 if (!value) goto failed;
1995 if (PyObject_SetAttrString(result, "values", value) == -1)
1996 goto failed;
1997 Py_DECREF(value);
1998 value = ast2obj_bool(o->v.Print.nl);
1999 if (!value) goto failed;
2000 if (PyObject_SetAttrString(result, "nl", value) == -1)
2001 goto failed;
2002 Py_DECREF(value);
2003 break;
2004 case For_kind:
2005 result = PyType_GenericNew(For_type, NULL, NULL);
2006 if (!result) goto failed;
2007 value = ast2obj_expr(o->v.For.target);
2008 if (!value) goto failed;
2009 if (PyObject_SetAttrString(result, "target", value) == -1)
2010 goto failed;
2011 Py_DECREF(value);
2012 value = ast2obj_expr(o->v.For.iter);
2013 if (!value) goto failed;
2014 if (PyObject_SetAttrString(result, "iter", value) == -1)
2015 goto failed;
2016 Py_DECREF(value);
2017 value = ast2obj_list(o->v.For.body, ast2obj_stmt);
2018 if (!value) goto failed;
2019 if (PyObject_SetAttrString(result, "body", value) == -1)
2020 goto failed;
2021 Py_DECREF(value);
2022 value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
2023 if (!value) goto failed;
2024 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2025 goto failed;
2026 Py_DECREF(value);
2027 break;
2028 case While_kind:
2029 result = PyType_GenericNew(While_type, NULL, NULL);
2030 if (!result) goto failed;
2031 value = ast2obj_expr(o->v.While.test);
2032 if (!value) goto failed;
2033 if (PyObject_SetAttrString(result, "test", value) == -1)
2034 goto failed;
2035 Py_DECREF(value);
2036 value = ast2obj_list(o->v.While.body, ast2obj_stmt);
2037 if (!value) goto failed;
2038 if (PyObject_SetAttrString(result, "body", value) == -1)
2039 goto failed;
2040 Py_DECREF(value);
2041 value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);
2042 if (!value) goto failed;
2043 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2044 goto failed;
2045 Py_DECREF(value);
2046 break;
2047 case If_kind:
2048 result = PyType_GenericNew(If_type, NULL, NULL);
2049 if (!result) goto failed;
2050 value = ast2obj_expr(o->v.If.test);
2051 if (!value) goto failed;
2052 if (PyObject_SetAttrString(result, "test", value) == -1)
2053 goto failed;
2054 Py_DECREF(value);
2055 value = ast2obj_list(o->v.If.body, ast2obj_stmt);
2056 if (!value) goto failed;
2057 if (PyObject_SetAttrString(result, "body", value) == -1)
2058 goto failed;
2059 Py_DECREF(value);
2060 value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
2061 if (!value) goto failed;
2062 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2063 goto failed;
2064 Py_DECREF(value);
2065 break;
2066 case With_kind:
2067 result = PyType_GenericNew(With_type, NULL, NULL);
2068 if (!result) goto failed;
2069 value = ast2obj_expr(o->v.With.context_expr);
2070 if (!value) goto failed;
2071 if (PyObject_SetAttrString(result, "context_expr", value) == -1)
2072 goto failed;
2073 Py_DECREF(value);
2074 value = ast2obj_expr(o->v.With.optional_vars);
2075 if (!value) goto failed;
2076 if (PyObject_SetAttrString(result, "optional_vars", value) ==
2078 goto failed;
2079 Py_DECREF(value);
2080 value = ast2obj_list(o->v.With.body, ast2obj_stmt);
2081 if (!value) goto failed;
2082 if (PyObject_SetAttrString(result, "body", value) == -1)
2083 goto failed;
2084 Py_DECREF(value);
2085 break;
2086 case Raise_kind:
2087 result = PyType_GenericNew(Raise_type, NULL, NULL);
2088 if (!result) goto failed;
2089 value = ast2obj_expr(o->v.Raise.type);
2090 if (!value) goto failed;
2091 if (PyObject_SetAttrString(result, "type", value) == -1)
2092 goto failed;
2093 Py_DECREF(value);
2094 value = ast2obj_expr(o->v.Raise.inst);
2095 if (!value) goto failed;
2096 if (PyObject_SetAttrString(result, "inst", value) == -1)
2097 goto failed;
2098 Py_DECREF(value);
2099 value = ast2obj_expr(o->v.Raise.tback);
2100 if (!value) goto failed;
2101 if (PyObject_SetAttrString(result, "tback", value) == -1)
2102 goto failed;
2103 Py_DECREF(value);
2104 break;
2105 case TryExcept_kind:
2106 result = PyType_GenericNew(TryExcept_type, NULL, NULL);
2107 if (!result) goto failed;
2108 value = ast2obj_list(o->v.TryExcept.body, ast2obj_stmt);
2109 if (!value) goto failed;
2110 if (PyObject_SetAttrString(result, "body", value) == -1)
2111 goto failed;
2112 Py_DECREF(value);
2113 value = ast2obj_list(o->v.TryExcept.handlers,
2114 ast2obj_excepthandler);
2115 if (!value) goto failed;
2116 if (PyObject_SetAttrString(result, "handlers", value) == -1)
2117 goto failed;
2118 Py_DECREF(value);
2119 value = ast2obj_list(o->v.TryExcept.orelse, ast2obj_stmt);
2120 if (!value) goto failed;
2121 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2122 goto failed;
2123 Py_DECREF(value);
2124 break;
2125 case TryFinally_kind:
2126 result = PyType_GenericNew(TryFinally_type, NULL, NULL);
2127 if (!result) goto failed;
2128 value = ast2obj_list(o->v.TryFinally.body, ast2obj_stmt);
2129 if (!value) goto failed;
2130 if (PyObject_SetAttrString(result, "body", value) == -1)
2131 goto failed;
2132 Py_DECREF(value);
2133 value = ast2obj_list(o->v.TryFinally.finalbody, ast2obj_stmt);
2134 if (!value) goto failed;
2135 if (PyObject_SetAttrString(result, "finalbody", value) == -1)
2136 goto failed;
2137 Py_DECREF(value);
2138 break;
2139 case Assert_kind:
2140 result = PyType_GenericNew(Assert_type, NULL, NULL);
2141 if (!result) goto failed;
2142 value = ast2obj_expr(o->v.Assert.test);
2143 if (!value) goto failed;
2144 if (PyObject_SetAttrString(result, "test", value) == -1)
2145 goto failed;
2146 Py_DECREF(value);
2147 value = ast2obj_expr(o->v.Assert.msg);
2148 if (!value) goto failed;
2149 if (PyObject_SetAttrString(result, "msg", value) == -1)
2150 goto failed;
2151 Py_DECREF(value);
2152 break;
2153 case Import_kind:
2154 result = PyType_GenericNew(Import_type, NULL, NULL);
2155 if (!result) goto failed;
2156 value = ast2obj_list(o->v.Import.names, ast2obj_alias);
2157 if (!value) goto failed;
2158 if (PyObject_SetAttrString(result, "names", value) == -1)
2159 goto failed;
2160 Py_DECREF(value);
2161 break;
2162 case ImportFrom_kind:
2163 result = PyType_GenericNew(ImportFrom_type, NULL, NULL);
2164 if (!result) goto failed;
2165 value = ast2obj_identifier(o->v.ImportFrom.module);
2166 if (!value) goto failed;
2167 if (PyObject_SetAttrString(result, "module", value) == -1)
2168 goto failed;
2169 Py_DECREF(value);
2170 value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
2171 if (!value) goto failed;
2172 if (PyObject_SetAttrString(result, "names", value) == -1)
2173 goto failed;
2174 Py_DECREF(value);
2175 value = ast2obj_int(o->v.ImportFrom.level);
2176 if (!value) goto failed;
2177 if (PyObject_SetAttrString(result, "level", value) == -1)
2178 goto failed;
2179 Py_DECREF(value);
2180 break;
2181 case Exec_kind:
2182 result = PyType_GenericNew(Exec_type, NULL, NULL);
2183 if (!result) goto failed;
2184 value = ast2obj_expr(o->v.Exec.body);
2185 if (!value) goto failed;
2186 if (PyObject_SetAttrString(result, "body", value) == -1)
2187 goto failed;
2188 Py_DECREF(value);
2189 value = ast2obj_expr(o->v.Exec.globals);
2190 if (!value) goto failed;
2191 if (PyObject_SetAttrString(result, "globals", value) == -1)
2192 goto failed;
2193 Py_DECREF(value);
2194 value = ast2obj_expr(o->v.Exec.locals);
2195 if (!value) goto failed;
2196 if (PyObject_SetAttrString(result, "locals", value) == -1)
2197 goto failed;
2198 Py_DECREF(value);
2199 break;
2200 case Global_kind:
2201 result = PyType_GenericNew(Global_type, NULL, NULL);
2202 if (!result) goto failed;
2203 value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
2204 if (!value) goto failed;
2205 if (PyObject_SetAttrString(result, "names", value) == -1)
2206 goto failed;
2207 Py_DECREF(value);
2208 break;
2209 case Expr_kind:
2210 result = PyType_GenericNew(Expr_type, NULL, NULL);
2211 if (!result) goto failed;
2212 value = ast2obj_expr(o->v.Expr.value);
2213 if (!value) goto failed;
2214 if (PyObject_SetAttrString(result, "value", value) == -1)
2215 goto failed;
2216 Py_DECREF(value);
2217 break;
2218 case Pass_kind:
2219 result = PyType_GenericNew(Pass_type, NULL, NULL);
2220 if (!result) goto failed;
2221 break;
2222 case Break_kind:
2223 result = PyType_GenericNew(Break_type, NULL, NULL);
2224 if (!result) goto failed;
2225 break;
2226 case Continue_kind:
2227 result = PyType_GenericNew(Continue_type, NULL, NULL);
2228 if (!result) goto failed;
2229 break;
2231 value = ast2obj_int(o->lineno);
2232 if (!value) goto failed;
2233 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2234 goto failed;
2235 Py_DECREF(value);
2236 value = ast2obj_int(o->col_offset);
2237 if (!value) goto failed;
2238 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2239 goto failed;
2240 Py_DECREF(value);
2241 return result;
2242 failed:
2243 Py_XDECREF(value);
2244 Py_XDECREF(result);
2245 return NULL;
2248 PyObject*
2249 ast2obj_expr(void* _o)
2251 expr_ty o = (expr_ty)_o;
2252 PyObject *result = NULL, *value = NULL;
2253 if (!o) {
2254 Py_INCREF(Py_None);
2255 return Py_None;
2258 switch (o->kind) {
2259 case BoolOp_kind:
2260 result = PyType_GenericNew(BoolOp_type, NULL, NULL);
2261 if (!result) goto failed;
2262 value = ast2obj_boolop(o->v.BoolOp.op);
2263 if (!value) goto failed;
2264 if (PyObject_SetAttrString(result, "op", value) == -1)
2265 goto failed;
2266 Py_DECREF(value);
2267 value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
2268 if (!value) goto failed;
2269 if (PyObject_SetAttrString(result, "values", value) == -1)
2270 goto failed;
2271 Py_DECREF(value);
2272 break;
2273 case BinOp_kind:
2274 result = PyType_GenericNew(BinOp_type, NULL, NULL);
2275 if (!result) goto failed;
2276 value = ast2obj_expr(o->v.BinOp.left);
2277 if (!value) goto failed;
2278 if (PyObject_SetAttrString(result, "left", value) == -1)
2279 goto failed;
2280 Py_DECREF(value);
2281 value = ast2obj_operator(o->v.BinOp.op);
2282 if (!value) goto failed;
2283 if (PyObject_SetAttrString(result, "op", value) == -1)
2284 goto failed;
2285 Py_DECREF(value);
2286 value = ast2obj_expr(o->v.BinOp.right);
2287 if (!value) goto failed;
2288 if (PyObject_SetAttrString(result, "right", value) == -1)
2289 goto failed;
2290 Py_DECREF(value);
2291 break;
2292 case UnaryOp_kind:
2293 result = PyType_GenericNew(UnaryOp_type, NULL, NULL);
2294 if (!result) goto failed;
2295 value = ast2obj_unaryop(o->v.UnaryOp.op);
2296 if (!value) goto failed;
2297 if (PyObject_SetAttrString(result, "op", value) == -1)
2298 goto failed;
2299 Py_DECREF(value);
2300 value = ast2obj_expr(o->v.UnaryOp.operand);
2301 if (!value) goto failed;
2302 if (PyObject_SetAttrString(result, "operand", value) == -1)
2303 goto failed;
2304 Py_DECREF(value);
2305 break;
2306 case Lambda_kind:
2307 result = PyType_GenericNew(Lambda_type, NULL, NULL);
2308 if (!result) goto failed;
2309 value = ast2obj_arguments(o->v.Lambda.args);
2310 if (!value) goto failed;
2311 if (PyObject_SetAttrString(result, "args", value) == -1)
2312 goto failed;
2313 Py_DECREF(value);
2314 value = ast2obj_expr(o->v.Lambda.body);
2315 if (!value) goto failed;
2316 if (PyObject_SetAttrString(result, "body", value) == -1)
2317 goto failed;
2318 Py_DECREF(value);
2319 break;
2320 case IfExp_kind:
2321 result = PyType_GenericNew(IfExp_type, NULL, NULL);
2322 if (!result) goto failed;
2323 value = ast2obj_expr(o->v.IfExp.test);
2324 if (!value) goto failed;
2325 if (PyObject_SetAttrString(result, "test", value) == -1)
2326 goto failed;
2327 Py_DECREF(value);
2328 value = ast2obj_expr(o->v.IfExp.body);
2329 if (!value) goto failed;
2330 if (PyObject_SetAttrString(result, "body", value) == -1)
2331 goto failed;
2332 Py_DECREF(value);
2333 value = ast2obj_expr(o->v.IfExp.orelse);
2334 if (!value) goto failed;
2335 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2336 goto failed;
2337 Py_DECREF(value);
2338 break;
2339 case Dict_kind:
2340 result = PyType_GenericNew(Dict_type, NULL, NULL);
2341 if (!result) goto failed;
2342 value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
2343 if (!value) goto failed;
2344 if (PyObject_SetAttrString(result, "keys", value) == -1)
2345 goto failed;
2346 Py_DECREF(value);
2347 value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
2348 if (!value) goto failed;
2349 if (PyObject_SetAttrString(result, "values", value) == -1)
2350 goto failed;
2351 Py_DECREF(value);
2352 break;
2353 case ListComp_kind:
2354 result = PyType_GenericNew(ListComp_type, NULL, NULL);
2355 if (!result) goto failed;
2356 value = ast2obj_expr(o->v.ListComp.elt);
2357 if (!value) goto failed;
2358 if (PyObject_SetAttrString(result, "elt", value) == -1)
2359 goto failed;
2360 Py_DECREF(value);
2361 value = ast2obj_list(o->v.ListComp.generators,
2362 ast2obj_comprehension);
2363 if (!value) goto failed;
2364 if (PyObject_SetAttrString(result, "generators", value) == -1)
2365 goto failed;
2366 Py_DECREF(value);
2367 break;
2368 case GeneratorExp_kind:
2369 result = PyType_GenericNew(GeneratorExp_type, NULL, NULL);
2370 if (!result) goto failed;
2371 value = ast2obj_expr(o->v.GeneratorExp.elt);
2372 if (!value) goto failed;
2373 if (PyObject_SetAttrString(result, "elt", value) == -1)
2374 goto failed;
2375 Py_DECREF(value);
2376 value = ast2obj_list(o->v.GeneratorExp.generators,
2377 ast2obj_comprehension);
2378 if (!value) goto failed;
2379 if (PyObject_SetAttrString(result, "generators", value) == -1)
2380 goto failed;
2381 Py_DECREF(value);
2382 break;
2383 case Yield_kind:
2384 result = PyType_GenericNew(Yield_type, NULL, NULL);
2385 if (!result) goto failed;
2386 value = ast2obj_expr(o->v.Yield.value);
2387 if (!value) goto failed;
2388 if (PyObject_SetAttrString(result, "value", value) == -1)
2389 goto failed;
2390 Py_DECREF(value);
2391 break;
2392 case Compare_kind:
2393 result = PyType_GenericNew(Compare_type, NULL, NULL);
2394 if (!result) goto failed;
2395 value = ast2obj_expr(o->v.Compare.left);
2396 if (!value) goto failed;
2397 if (PyObject_SetAttrString(result, "left", value) == -1)
2398 goto failed;
2399 Py_DECREF(value);
2401 int i, n = asdl_seq_LEN(o->v.Compare.ops);
2402 value = PyList_New(n);
2403 if (!value) goto failed;
2404 for(i = 0; i < n; i++)
2405 PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
2407 if (!value) goto failed;
2408 if (PyObject_SetAttrString(result, "ops", value) == -1)
2409 goto failed;
2410 Py_DECREF(value);
2411 value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
2412 if (!value) goto failed;
2413 if (PyObject_SetAttrString(result, "comparators", value) == -1)
2414 goto failed;
2415 Py_DECREF(value);
2416 break;
2417 case Call_kind:
2418 result = PyType_GenericNew(Call_type, NULL, NULL);
2419 if (!result) goto failed;
2420 value = ast2obj_expr(o->v.Call.func);
2421 if (!value) goto failed;
2422 if (PyObject_SetAttrString(result, "func", value) == -1)
2423 goto failed;
2424 Py_DECREF(value);
2425 value = ast2obj_list(o->v.Call.args, ast2obj_expr);
2426 if (!value) goto failed;
2427 if (PyObject_SetAttrString(result, "args", value) == -1)
2428 goto failed;
2429 Py_DECREF(value);
2430 value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
2431 if (!value) goto failed;
2432 if (PyObject_SetAttrString(result, "keywords", value) == -1)
2433 goto failed;
2434 Py_DECREF(value);
2435 value = ast2obj_expr(o->v.Call.starargs);
2436 if (!value) goto failed;
2437 if (PyObject_SetAttrString(result, "starargs", value) == -1)
2438 goto failed;
2439 Py_DECREF(value);
2440 value = ast2obj_expr(o->v.Call.kwargs);
2441 if (!value) goto failed;
2442 if (PyObject_SetAttrString(result, "kwargs", value) == -1)
2443 goto failed;
2444 Py_DECREF(value);
2445 break;
2446 case Repr_kind:
2447 result = PyType_GenericNew(Repr_type, NULL, NULL);
2448 if (!result) goto failed;
2449 value = ast2obj_expr(o->v.Repr.value);
2450 if (!value) goto failed;
2451 if (PyObject_SetAttrString(result, "value", value) == -1)
2452 goto failed;
2453 Py_DECREF(value);
2454 break;
2455 case Num_kind:
2456 result = PyType_GenericNew(Num_type, NULL, NULL);
2457 if (!result) goto failed;
2458 value = ast2obj_object(o->v.Num.n);
2459 if (!value) goto failed;
2460 if (PyObject_SetAttrString(result, "n", value) == -1)
2461 goto failed;
2462 Py_DECREF(value);
2463 break;
2464 case Str_kind:
2465 result = PyType_GenericNew(Str_type, NULL, NULL);
2466 if (!result) goto failed;
2467 value = ast2obj_string(o->v.Str.s);
2468 if (!value) goto failed;
2469 if (PyObject_SetAttrString(result, "s", value) == -1)
2470 goto failed;
2471 Py_DECREF(value);
2472 break;
2473 case Attribute_kind:
2474 result = PyType_GenericNew(Attribute_type, NULL, NULL);
2475 if (!result) goto failed;
2476 value = ast2obj_expr(o->v.Attribute.value);
2477 if (!value) goto failed;
2478 if (PyObject_SetAttrString(result, "value", value) == -1)
2479 goto failed;
2480 Py_DECREF(value);
2481 value = ast2obj_identifier(o->v.Attribute.attr);
2482 if (!value) goto failed;
2483 if (PyObject_SetAttrString(result, "attr", value) == -1)
2484 goto failed;
2485 Py_DECREF(value);
2486 value = ast2obj_expr_context(o->v.Attribute.ctx);
2487 if (!value) goto failed;
2488 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2489 goto failed;
2490 Py_DECREF(value);
2491 break;
2492 case Subscript_kind:
2493 result = PyType_GenericNew(Subscript_type, NULL, NULL);
2494 if (!result) goto failed;
2495 value = ast2obj_expr(o->v.Subscript.value);
2496 if (!value) goto failed;
2497 if (PyObject_SetAttrString(result, "value", value) == -1)
2498 goto failed;
2499 Py_DECREF(value);
2500 value = ast2obj_slice(o->v.Subscript.slice);
2501 if (!value) goto failed;
2502 if (PyObject_SetAttrString(result, "slice", value) == -1)
2503 goto failed;
2504 Py_DECREF(value);
2505 value = ast2obj_expr_context(o->v.Subscript.ctx);
2506 if (!value) goto failed;
2507 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2508 goto failed;
2509 Py_DECREF(value);
2510 break;
2511 case Name_kind:
2512 result = PyType_GenericNew(Name_type, NULL, NULL);
2513 if (!result) goto failed;
2514 value = ast2obj_identifier(o->v.Name.id);
2515 if (!value) goto failed;
2516 if (PyObject_SetAttrString(result, "id", value) == -1)
2517 goto failed;
2518 Py_DECREF(value);
2519 value = ast2obj_expr_context(o->v.Name.ctx);
2520 if (!value) goto failed;
2521 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2522 goto failed;
2523 Py_DECREF(value);
2524 break;
2525 case List_kind:
2526 result = PyType_GenericNew(List_type, NULL, NULL);
2527 if (!result) goto failed;
2528 value = ast2obj_list(o->v.List.elts, ast2obj_expr);
2529 if (!value) goto failed;
2530 if (PyObject_SetAttrString(result, "elts", value) == -1)
2531 goto failed;
2532 Py_DECREF(value);
2533 value = ast2obj_expr_context(o->v.List.ctx);
2534 if (!value) goto failed;
2535 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2536 goto failed;
2537 Py_DECREF(value);
2538 break;
2539 case Tuple_kind:
2540 result = PyType_GenericNew(Tuple_type, NULL, NULL);
2541 if (!result) goto failed;
2542 value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
2543 if (!value) goto failed;
2544 if (PyObject_SetAttrString(result, "elts", value) == -1)
2545 goto failed;
2546 Py_DECREF(value);
2547 value = ast2obj_expr_context(o->v.Tuple.ctx);
2548 if (!value) goto failed;
2549 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2550 goto failed;
2551 Py_DECREF(value);
2552 break;
2554 value = ast2obj_int(o->lineno);
2555 if (!value) goto failed;
2556 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2557 goto failed;
2558 Py_DECREF(value);
2559 value = ast2obj_int(o->col_offset);
2560 if (!value) goto failed;
2561 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2562 goto failed;
2563 Py_DECREF(value);
2564 return result;
2565 failed:
2566 Py_XDECREF(value);
2567 Py_XDECREF(result);
2568 return NULL;
2571 PyObject* ast2obj_expr_context(expr_context_ty o)
2573 switch(o) {
2574 case Load:
2575 Py_INCREF(Load_singleton);
2576 return Load_singleton;
2577 case Store:
2578 Py_INCREF(Store_singleton);
2579 return Store_singleton;
2580 case Del:
2581 Py_INCREF(Del_singleton);
2582 return Del_singleton;
2583 case AugLoad:
2584 Py_INCREF(AugLoad_singleton);
2585 return AugLoad_singleton;
2586 case AugStore:
2587 Py_INCREF(AugStore_singleton);
2588 return AugStore_singleton;
2589 case Param:
2590 Py_INCREF(Param_singleton);
2591 return Param_singleton;
2593 return NULL; /* cannot happen */
2595 PyObject*
2596 ast2obj_slice(void* _o)
2598 slice_ty o = (slice_ty)_o;
2599 PyObject *result = NULL, *value = NULL;
2600 if (!o) {
2601 Py_INCREF(Py_None);
2602 return Py_None;
2605 switch (o->kind) {
2606 case Ellipsis_kind:
2607 result = PyType_GenericNew(Ellipsis_type, NULL, NULL);
2608 if (!result) goto failed;
2609 break;
2610 case Slice_kind:
2611 result = PyType_GenericNew(Slice_type, NULL, NULL);
2612 if (!result) goto failed;
2613 value = ast2obj_expr(o->v.Slice.lower);
2614 if (!value) goto failed;
2615 if (PyObject_SetAttrString(result, "lower", value) == -1)
2616 goto failed;
2617 Py_DECREF(value);
2618 value = ast2obj_expr(o->v.Slice.upper);
2619 if (!value) goto failed;
2620 if (PyObject_SetAttrString(result, "upper", value) == -1)
2621 goto failed;
2622 Py_DECREF(value);
2623 value = ast2obj_expr(o->v.Slice.step);
2624 if (!value) goto failed;
2625 if (PyObject_SetAttrString(result, "step", value) == -1)
2626 goto failed;
2627 Py_DECREF(value);
2628 break;
2629 case ExtSlice_kind:
2630 result = PyType_GenericNew(ExtSlice_type, NULL, NULL);
2631 if (!result) goto failed;
2632 value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice);
2633 if (!value) goto failed;
2634 if (PyObject_SetAttrString(result, "dims", value) == -1)
2635 goto failed;
2636 Py_DECREF(value);
2637 break;
2638 case Index_kind:
2639 result = PyType_GenericNew(Index_type, NULL, NULL);
2640 if (!result) goto failed;
2641 value = ast2obj_expr(o->v.Index.value);
2642 if (!value) goto failed;
2643 if (PyObject_SetAttrString(result, "value", value) == -1)
2644 goto failed;
2645 Py_DECREF(value);
2646 break;
2648 return result;
2649 failed:
2650 Py_XDECREF(value);
2651 Py_XDECREF(result);
2652 return NULL;
2655 PyObject* ast2obj_boolop(boolop_ty o)
2657 switch(o) {
2658 case And:
2659 Py_INCREF(And_singleton);
2660 return And_singleton;
2661 case Or:
2662 Py_INCREF(Or_singleton);
2663 return Or_singleton;
2665 return NULL; /* cannot happen */
2667 PyObject* ast2obj_operator(operator_ty o)
2669 switch(o) {
2670 case Add:
2671 Py_INCREF(Add_singleton);
2672 return Add_singleton;
2673 case Sub:
2674 Py_INCREF(Sub_singleton);
2675 return Sub_singleton;
2676 case Mult:
2677 Py_INCREF(Mult_singleton);
2678 return Mult_singleton;
2679 case Div:
2680 Py_INCREF(Div_singleton);
2681 return Div_singleton;
2682 case Mod:
2683 Py_INCREF(Mod_singleton);
2684 return Mod_singleton;
2685 case Pow:
2686 Py_INCREF(Pow_singleton);
2687 return Pow_singleton;
2688 case LShift:
2689 Py_INCREF(LShift_singleton);
2690 return LShift_singleton;
2691 case RShift:
2692 Py_INCREF(RShift_singleton);
2693 return RShift_singleton;
2694 case BitOr:
2695 Py_INCREF(BitOr_singleton);
2696 return BitOr_singleton;
2697 case BitXor:
2698 Py_INCREF(BitXor_singleton);
2699 return BitXor_singleton;
2700 case BitAnd:
2701 Py_INCREF(BitAnd_singleton);
2702 return BitAnd_singleton;
2703 case FloorDiv:
2704 Py_INCREF(FloorDiv_singleton);
2705 return FloorDiv_singleton;
2707 return NULL; /* cannot happen */
2709 PyObject* ast2obj_unaryop(unaryop_ty o)
2711 switch(o) {
2712 case Invert:
2713 Py_INCREF(Invert_singleton);
2714 return Invert_singleton;
2715 case Not:
2716 Py_INCREF(Not_singleton);
2717 return Not_singleton;
2718 case UAdd:
2719 Py_INCREF(UAdd_singleton);
2720 return UAdd_singleton;
2721 case USub:
2722 Py_INCREF(USub_singleton);
2723 return USub_singleton;
2725 return NULL; /* cannot happen */
2727 PyObject* ast2obj_cmpop(cmpop_ty o)
2729 switch(o) {
2730 case Eq:
2731 Py_INCREF(Eq_singleton);
2732 return Eq_singleton;
2733 case NotEq:
2734 Py_INCREF(NotEq_singleton);
2735 return NotEq_singleton;
2736 case Lt:
2737 Py_INCREF(Lt_singleton);
2738 return Lt_singleton;
2739 case LtE:
2740 Py_INCREF(LtE_singleton);
2741 return LtE_singleton;
2742 case Gt:
2743 Py_INCREF(Gt_singleton);
2744 return Gt_singleton;
2745 case GtE:
2746 Py_INCREF(GtE_singleton);
2747 return GtE_singleton;
2748 case Is:
2749 Py_INCREF(Is_singleton);
2750 return Is_singleton;
2751 case IsNot:
2752 Py_INCREF(IsNot_singleton);
2753 return IsNot_singleton;
2754 case In:
2755 Py_INCREF(In_singleton);
2756 return In_singleton;
2757 case NotIn:
2758 Py_INCREF(NotIn_singleton);
2759 return NotIn_singleton;
2761 return NULL; /* cannot happen */
2763 PyObject*
2764 ast2obj_comprehension(void* _o)
2766 comprehension_ty o = (comprehension_ty)_o;
2767 PyObject *result = NULL, *value = NULL;
2768 if (!o) {
2769 Py_INCREF(Py_None);
2770 return Py_None;
2773 result = PyType_GenericNew(comprehension_type, NULL, NULL);
2774 if (!result) return NULL;
2775 value = ast2obj_expr(o->target);
2776 if (!value) goto failed;
2777 if (PyObject_SetAttrString(result, "target", value) == -1)
2778 goto failed;
2779 Py_DECREF(value);
2780 value = ast2obj_expr(o->iter);
2781 if (!value) goto failed;
2782 if (PyObject_SetAttrString(result, "iter", value) == -1)
2783 goto failed;
2784 Py_DECREF(value);
2785 value = ast2obj_list(o->ifs, ast2obj_expr);
2786 if (!value) goto failed;
2787 if (PyObject_SetAttrString(result, "ifs", value) == -1)
2788 goto failed;
2789 Py_DECREF(value);
2790 return result;
2791 failed:
2792 Py_XDECREF(value);
2793 Py_XDECREF(result);
2794 return NULL;
2797 PyObject*
2798 ast2obj_excepthandler(void* _o)
2800 excepthandler_ty o = (excepthandler_ty)_o;
2801 PyObject *result = NULL, *value = NULL;
2802 if (!o) {
2803 Py_INCREF(Py_None);
2804 return Py_None;
2807 result = PyType_GenericNew(excepthandler_type, NULL, NULL);
2808 if (!result) return NULL;
2809 value = ast2obj_expr(o->type);
2810 if (!value) goto failed;
2811 if (PyObject_SetAttrString(result, "type", value) == -1)
2812 goto failed;
2813 Py_DECREF(value);
2814 value = ast2obj_expr(o->name);
2815 if (!value) goto failed;
2816 if (PyObject_SetAttrString(result, "name", value) == -1)
2817 goto failed;
2818 Py_DECREF(value);
2819 value = ast2obj_list(o->body, ast2obj_stmt);
2820 if (!value) goto failed;
2821 if (PyObject_SetAttrString(result, "body", value) == -1)
2822 goto failed;
2823 Py_DECREF(value);
2824 value = ast2obj_int(o->lineno);
2825 if (!value) goto failed;
2826 if (PyObject_SetAttrString(result, "lineno", value) == -1)
2827 goto failed;
2828 Py_DECREF(value);
2829 value = ast2obj_int(o->col_offset);
2830 if (!value) goto failed;
2831 if (PyObject_SetAttrString(result, "col_offset", value) == -1)
2832 goto failed;
2833 Py_DECREF(value);
2834 return result;
2835 failed:
2836 Py_XDECREF(value);
2837 Py_XDECREF(result);
2838 return NULL;
2841 PyObject*
2842 ast2obj_arguments(void* _o)
2844 arguments_ty o = (arguments_ty)_o;
2845 PyObject *result = NULL, *value = NULL;
2846 if (!o) {
2847 Py_INCREF(Py_None);
2848 return Py_None;
2851 result = PyType_GenericNew(arguments_type, NULL, NULL);
2852 if (!result) return NULL;
2853 value = ast2obj_list(o->args, ast2obj_expr);
2854 if (!value) goto failed;
2855 if (PyObject_SetAttrString(result, "args", value) == -1)
2856 goto failed;
2857 Py_DECREF(value);
2858 value = ast2obj_identifier(o->vararg);
2859 if (!value) goto failed;
2860 if (PyObject_SetAttrString(result, "vararg", value) == -1)
2861 goto failed;
2862 Py_DECREF(value);
2863 value = ast2obj_identifier(o->kwarg);
2864 if (!value) goto failed;
2865 if (PyObject_SetAttrString(result, "kwarg", value) == -1)
2866 goto failed;
2867 Py_DECREF(value);
2868 value = ast2obj_list(o->defaults, ast2obj_expr);
2869 if (!value) goto failed;
2870 if (PyObject_SetAttrString(result, "defaults", value) == -1)
2871 goto failed;
2872 Py_DECREF(value);
2873 return result;
2874 failed:
2875 Py_XDECREF(value);
2876 Py_XDECREF(result);
2877 return NULL;
2880 PyObject*
2881 ast2obj_keyword(void* _o)
2883 keyword_ty o = (keyword_ty)_o;
2884 PyObject *result = NULL, *value = NULL;
2885 if (!o) {
2886 Py_INCREF(Py_None);
2887 return Py_None;
2890 result = PyType_GenericNew(keyword_type, NULL, NULL);
2891 if (!result) return NULL;
2892 value = ast2obj_identifier(o->arg);
2893 if (!value) goto failed;
2894 if (PyObject_SetAttrString(result, "arg", value) == -1)
2895 goto failed;
2896 Py_DECREF(value);
2897 value = ast2obj_expr(o->value);
2898 if (!value) goto failed;
2899 if (PyObject_SetAttrString(result, "value", value) == -1)
2900 goto failed;
2901 Py_DECREF(value);
2902 return result;
2903 failed:
2904 Py_XDECREF(value);
2905 Py_XDECREF(result);
2906 return NULL;
2909 PyObject*
2910 ast2obj_alias(void* _o)
2912 alias_ty o = (alias_ty)_o;
2913 PyObject *result = NULL, *value = NULL;
2914 if (!o) {
2915 Py_INCREF(Py_None);
2916 return Py_None;
2919 result = PyType_GenericNew(alias_type, NULL, NULL);
2920 if (!result) return NULL;
2921 value = ast2obj_identifier(o->name);
2922 if (!value) goto failed;
2923 if (PyObject_SetAttrString(result, "name", value) == -1)
2924 goto failed;
2925 Py_DECREF(value);
2926 value = ast2obj_identifier(o->asname);
2927 if (!value) goto failed;
2928 if (PyObject_SetAttrString(result, "asname", value) == -1)
2929 goto failed;
2930 Py_DECREF(value);
2931 return result;
2932 failed:
2933 Py_XDECREF(value);
2934 Py_XDECREF(result);
2935 return NULL;
2939 PyMODINIT_FUNC
2940 init_ast(void)
2942 PyObject *m, *d;
2943 if (!init_types()) return;
2944 m = Py_InitModule3("_ast", NULL, NULL);
2945 if (!m) return;
2946 d = PyModule_GetDict(m);
2947 if (PyDict_SetItemString(d, "AST", (PyObject*)AST_type) < 0) return;
2948 if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)
2949 return;
2950 if (PyModule_AddStringConstant(m, "__version__", "53731") < 0)
2951 return;
2952 if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return;
2953 if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0)
2954 return;
2955 if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type)
2956 < 0) return;
2957 if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) <
2958 0) return;
2959 if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return;
2960 if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return;
2961 if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type)
2962 < 0) return;
2963 if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0)
2964 return;
2965 if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0)
2966 return;
2967 if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0)
2968 return;
2969 if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0)
2970 return;
2971 if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) <
2972 0) return;
2973 if (PyDict_SetItemString(d, "Print", (PyObject*)Print_type) < 0) return;
2974 if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return;
2975 if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return;
2976 if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return;
2977 if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return;
2978 if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return;
2979 if (PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) <
2980 0) return;
2981 if (PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) <
2982 0) return;
2983 if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0)
2984 return;
2985 if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0)
2986 return;
2987 if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) <
2988 0) return;
2989 if (PyDict_SetItemString(d, "Exec", (PyObject*)Exec_type) < 0) return;
2990 if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0)
2991 return;
2992 if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return;
2993 if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return;
2994 if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return;
2995 if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0)
2996 return;
2997 if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return;
2998 if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0)
2999 return;
3000 if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return;
3001 if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0)
3002 return;
3003 if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0)
3004 return;
3005 if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return;
3006 if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return;
3007 if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0)
3008 return;
3009 if (PyDict_SetItemString(d, "GeneratorExp",
3010 (PyObject*)GeneratorExp_type) < 0) return;
3011 if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return;
3012 if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0)
3013 return;
3014 if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return;
3015 if (PyDict_SetItemString(d, "Repr", (PyObject*)Repr_type) < 0) return;
3016 if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return;
3017 if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return;
3018 if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) <
3019 0) return;
3020 if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) <
3021 0) return;
3022 if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return;
3023 if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return;
3024 if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return;
3025 if (PyDict_SetItemString(d, "expr_context",
3026 (PyObject*)expr_context_type) < 0) return;
3027 if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return;
3028 if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return;
3029 if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return;
3030 if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0)
3031 return;
3032 if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0)
3033 return;
3034 if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return;
3035 if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return;
3036 if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0)
3037 return;
3038 if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return;
3039 if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0)
3040 return;
3041 if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return;
3042 if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0)
3043 return;
3044 if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return;
3045 if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return;
3046 if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0)
3047 return;
3048 if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return;
3049 if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return;
3050 if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return;
3051 if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return;
3052 if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return;
3053 if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return;
3054 if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0)
3055 return;
3056 if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0)
3057 return;
3058 if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return;
3059 if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0)
3060 return;
3061 if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0)
3062 return;
3063 if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0)
3064 return;
3065 if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0)
3066 return;
3067 if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0)
3068 return;
3069 if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return;
3070 if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return;
3071 if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return;
3072 if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return;
3073 if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return;
3074 if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return;
3075 if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return;
3076 if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return;
3077 if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return;
3078 if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return;
3079 if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return;
3080 if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return;
3081 if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return;
3082 if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return;
3083 if (PyDict_SetItemString(d, "comprehension",
3084 (PyObject*)comprehension_type) < 0) return;
3085 if (PyDict_SetItemString(d, "excepthandler",
3086 (PyObject*)excepthandler_type) < 0) return;
3087 if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) <
3088 0) return;
3089 if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0)
3090 return;
3091 if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return;
3095 PyObject* PyAST_mod2obj(mod_ty t)
3097 init_types();
3098 return ast2obj_mod(t);