blob: f881c474ba62943df7fc0eaf1bf7be413b5dc511 [file] [log] [blame]
Neal Norwitz897ff812005-12-11 21:18:22 +00001/* File automatically generated by Parser/asdl_c.py */
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002
3#include "Python.h"
4#include "Python-ast.h"
5
Martin v. Löwisbd260da2006-02-26 19:42:26 +00006PyTypeObject *mod_type;
7static PyObject* ast2obj_mod(void*);
8PyTypeObject *Module_type;
9char *Module_fields[]={
10 "body",
11};
12PyTypeObject *Interactive_type;
13char *Interactive_fields[]={
14 "body",
15};
16PyTypeObject *Expression_type;
17char *Expression_fields[]={
18 "body",
19};
20PyTypeObject *Suite_type;
21char *Suite_fields[]={
22 "body",
23};
24PyTypeObject *stmt_type;
25static PyObject* ast2obj_stmt(void*);
26PyTypeObject *FunctionDef_type;
27char *FunctionDef_fields[]={
28 "name",
29 "args",
30 "body",
31 "decorators",
32};
33PyTypeObject *ClassDef_type;
34char *ClassDef_fields[]={
35 "name",
36 "bases",
37 "body",
38};
39PyTypeObject *Return_type;
40char *Return_fields[]={
41 "value",
42};
43PyTypeObject *Delete_type;
44char *Delete_fields[]={
45 "targets",
46};
47PyTypeObject *Assign_type;
48char *Assign_fields[]={
49 "targets",
50 "value",
51};
52PyTypeObject *AugAssign_type;
53char *AugAssign_fields[]={
54 "target",
55 "op",
56 "value",
57};
58PyTypeObject *Print_type;
59char *Print_fields[]={
60 "dest",
61 "values",
62 "nl",
63};
64PyTypeObject *For_type;
65char *For_fields[]={
66 "target",
67 "iter",
68 "body",
69 "orelse",
70};
71PyTypeObject *While_type;
72char *While_fields[]={
73 "test",
74 "body",
75 "orelse",
76};
77PyTypeObject *If_type;
78char *If_fields[]={
79 "test",
80 "body",
81 "orelse",
82};
83PyTypeObject *Raise_type;
84char *Raise_fields[]={
85 "type",
86 "inst",
87 "tback",
88};
89PyTypeObject *TryExcept_type;
90char *TryExcept_fields[]={
91 "body",
92 "handlers",
93 "orelse",
94};
95PyTypeObject *TryFinally_type;
96char *TryFinally_fields[]={
97 "body",
98 "finalbody",
99};
100PyTypeObject *Assert_type;
101char *Assert_fields[]={
102 "test",
103 "msg",
104};
105PyTypeObject *Import_type;
106char *Import_fields[]={
107 "names",
108};
109PyTypeObject *ImportFrom_type;
110char *ImportFrom_fields[]={
111 "module",
112 "names",
113};
114PyTypeObject *Exec_type;
115char *Exec_fields[]={
116 "body",
117 "globals",
118 "locals",
119};
120PyTypeObject *Global_type;
121char *Global_fields[]={
122 "names",
123};
124PyTypeObject *Expr_type;
125char *Expr_fields[]={
126 "value",
127};
128PyTypeObject *Pass_type;
129char *Pass_fields[]={
130};
131PyTypeObject *Break_type;
132char *Break_fields[]={
133};
134PyTypeObject *Continue_type;
135char *Continue_fields[]={
136};
137PyTypeObject *expr_type;
138static PyObject* ast2obj_expr(void*);
139PyTypeObject *BoolOp_type;
140char *BoolOp_fields[]={
141 "op",
142 "values",
143};
144PyTypeObject *BinOp_type;
145char *BinOp_fields[]={
146 "left",
147 "op",
148 "right",
149};
150PyTypeObject *UnaryOp_type;
151char *UnaryOp_fields[]={
152 "op",
153 "operand",
154};
155PyTypeObject *Lambda_type;
156char *Lambda_fields[]={
157 "args",
158 "body",
159};
160PyTypeObject *Dict_type;
161char *Dict_fields[]={
162 "keys",
163 "values",
164};
165PyTypeObject *ListComp_type;
166char *ListComp_fields[]={
167 "elt",
168 "generators",
169};
170PyTypeObject *GeneratorExp_type;
171char *GeneratorExp_fields[]={
172 "elt",
173 "generators",
174};
175PyTypeObject *Yield_type;
176char *Yield_fields[]={
177 "value",
178};
179PyTypeObject *Compare_type;
180char *Compare_fields[]={
181 "left",
182 "ops",
183 "comparators",
184};
185PyTypeObject *Call_type;
186char *Call_fields[]={
187 "func",
188 "args",
189 "keywords",
190 "starargs",
191 "kwargs",
192};
193PyTypeObject *Repr_type;
194char *Repr_fields[]={
195 "value",
196};
197PyTypeObject *Num_type;
198char *Num_fields[]={
199 "n",
200};
201PyTypeObject *Str_type;
202char *Str_fields[]={
203 "s",
204};
205PyTypeObject *Attribute_type;
206char *Attribute_fields[]={
207 "value",
208 "attr",
209 "ctx",
210};
211PyTypeObject *Subscript_type;
212char *Subscript_fields[]={
213 "value",
214 "slice",
215 "ctx",
216};
217PyTypeObject *Name_type;
218char *Name_fields[]={
219 "id",
220 "ctx",
221};
222PyTypeObject *List_type;
223char *List_fields[]={
224 "elts",
225 "ctx",
226};
227PyTypeObject *Tuple_type;
228char *Tuple_fields[]={
229 "elts",
230 "ctx",
231};
232PyTypeObject *expr_context_type;
233static PyObject *Load_singleton, *Store_singleton, *Del_singleton,
234*AugLoad_singleton, *AugStore_singleton, *Param_singleton;
235static PyObject* ast2obj_expr_context(expr_context_ty);
236PyTypeObject *Load_type;
237char *Load_fields[]={
238};
239PyTypeObject *Store_type;
240char *Store_fields[]={
241};
242PyTypeObject *Del_type;
243char *Del_fields[]={
244};
245PyTypeObject *AugLoad_type;
246char *AugLoad_fields[]={
247};
248PyTypeObject *AugStore_type;
249char *AugStore_fields[]={
250};
251PyTypeObject *Param_type;
252char *Param_fields[]={
253};
254PyTypeObject *slice_type;
255static PyObject* ast2obj_slice(void*);
256PyTypeObject *Ellipsis_type;
257char *Ellipsis_fields[]={
258};
259PyTypeObject *Slice_type;
260char *Slice_fields[]={
261 "lower",
262 "upper",
263 "step",
264};
265PyTypeObject *ExtSlice_type;
266char *ExtSlice_fields[]={
267 "dims",
268};
269PyTypeObject *Index_type;
270char *Index_fields[]={
271 "value",
272};
273PyTypeObject *boolop_type;
274static PyObject *And_singleton, *Or_singleton;
275static PyObject* ast2obj_boolop(boolop_ty);
276PyTypeObject *And_type;
277char *And_fields[]={
278};
279PyTypeObject *Or_type;
280char *Or_fields[]={
281};
282PyTypeObject *operator_type;
283static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton,
284*Div_singleton, *Mod_singleton, *Pow_singleton, *LShift_singleton,
285*RShift_singleton, *BitOr_singleton, *BitXor_singleton, *BitAnd_singleton,
286*FloorDiv_singleton;
287static PyObject* ast2obj_operator(operator_ty);
288PyTypeObject *Add_type;
289char *Add_fields[]={
290};
291PyTypeObject *Sub_type;
292char *Sub_fields[]={
293};
294PyTypeObject *Mult_type;
295char *Mult_fields[]={
296};
297PyTypeObject *Div_type;
298char *Div_fields[]={
299};
300PyTypeObject *Mod_type;
301char *Mod_fields[]={
302};
303PyTypeObject *Pow_type;
304char *Pow_fields[]={
305};
306PyTypeObject *LShift_type;
307char *LShift_fields[]={
308};
309PyTypeObject *RShift_type;
310char *RShift_fields[]={
311};
312PyTypeObject *BitOr_type;
313char *BitOr_fields[]={
314};
315PyTypeObject *BitXor_type;
316char *BitXor_fields[]={
317};
318PyTypeObject *BitAnd_type;
319char *BitAnd_fields[]={
320};
321PyTypeObject *FloorDiv_type;
322char *FloorDiv_fields[]={
323};
324PyTypeObject *unaryop_type;
325static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton,
326*USub_singleton;
327static PyObject* ast2obj_unaryop(unaryop_ty);
328PyTypeObject *Invert_type;
329char *Invert_fields[]={
330};
331PyTypeObject *Not_type;
332char *Not_fields[]={
333};
334PyTypeObject *UAdd_type;
335char *UAdd_fields[]={
336};
337PyTypeObject *USub_type;
338char *USub_fields[]={
339};
340PyTypeObject *cmpop_type;
341static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton,
342*Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton,
343*NotIn_singleton;
344static PyObject* ast2obj_cmpop(cmpop_ty);
345PyTypeObject *Eq_type;
346char *Eq_fields[]={
347};
348PyTypeObject *NotEq_type;
349char *NotEq_fields[]={
350};
351PyTypeObject *Lt_type;
352char *Lt_fields[]={
353};
354PyTypeObject *LtE_type;
355char *LtE_fields[]={
356};
357PyTypeObject *Gt_type;
358char *Gt_fields[]={
359};
360PyTypeObject *GtE_type;
361char *GtE_fields[]={
362};
363PyTypeObject *Is_type;
364char *Is_fields[]={
365};
366PyTypeObject *IsNot_type;
367char *IsNot_fields[]={
368};
369PyTypeObject *In_type;
370char *In_fields[]={
371};
372PyTypeObject *NotIn_type;
373char *NotIn_fields[]={
374};
375PyTypeObject *comprehension_type;
376static PyObject* ast2obj_comprehension(void*);
377char *comprehension_fields[]={
378 "target",
379 "iter",
380 "ifs",
381};
382PyTypeObject *excepthandler_type;
383static PyObject* ast2obj_excepthandler(void*);
384char *excepthandler_fields[]={
385 "type",
386 "name",
387 "body",
388};
389PyTypeObject *arguments_type;
390static PyObject* ast2obj_arguments(void*);
391char *arguments_fields[]={
392 "args",
393 "vararg",
394 "kwarg",
395 "defaults",
396};
397PyTypeObject *keyword_type;
398static PyObject* ast2obj_keyword(void*);
399char *keyword_fields[]={
400 "arg",
401 "value",
402};
403PyTypeObject *alias_type;
404static PyObject* ast2obj_alias(void*);
405char *alias_fields[]={
406 "name",
407 "asname",
408};
409
410
411static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields)
412{
413 PyObject *fnames, *result;
414 int i;
415 if (num_fields) {
416 fnames = PyTuple_New(num_fields);
417 if (!fnames) return NULL;
418 } else {
419 fnames = Py_None;
420 Py_INCREF(Py_None);
421 }
422 for(i=0; i < num_fields; i++) {
423 PyObject *field = PyString_FromString(fields[i]);
424 if (!field) {
425 Py_DECREF(fnames);
426 return NULL;
427 }
428 PyTuple_SET_ITEM(fnames, i, field);
429 }
430 result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sO}", type, base, "_fields", fnames);
431 Py_DECREF(fnames);
432 return (PyTypeObject*)result;
433}
434
435static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
436{
437 int i, n = asdl_seq_LEN(seq);
438 PyObject *result = PyList_New(n);
439 PyObject *value;
440 if (!result)
441 return NULL;
442 for (i = 0; i < n; i++) {
443 value = func(asdl_seq_GET(seq, i));
444 if (!value) {
445 Py_DECREF(result);
446 return NULL;
447 }
448 PyList_SET_ITEM(result, i, value);
449 }
450 return result;
451}
452
453static PyObject* ast2obj_object(void *o)
454{
455 if (!o)
456 o = Py_None;
457 Py_INCREF((PyObject*)o);
458 return (PyObject*)o;
459}
460#define ast2obj_identifier ast2obj_object
461#define ast2obj_string ast2obj_object
462static PyObject* ast2obj_bool(bool b)
463{
464 return PyBool_FromLong(b);
465}
466
467static int initialized;
468static int init_types(void)
469{
470 if (initialized) return 1;
471 mod_type = make_type("mod", &PyBaseObject_Type, NULL, 0);
472 Module_type = make_type("Module", mod_type, Module_fields, 1);
473 Interactive_type = make_type("Interactive", mod_type,
474 Interactive_fields, 1);
475 Expression_type = make_type("Expression", mod_type, Expression_fields,
476 1);
477 Suite_type = make_type("Suite", mod_type, Suite_fields, 1);
478 stmt_type = make_type("stmt", &PyBaseObject_Type, NULL, 0);
479 FunctionDef_type = make_type("FunctionDef", stmt_type,
480 FunctionDef_fields, 4);
481 ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 3);
482 Return_type = make_type("Return", stmt_type, Return_fields, 1);
483 Delete_type = make_type("Delete", stmt_type, Delete_fields, 1);
484 Assign_type = make_type("Assign", stmt_type, Assign_fields, 2);
485 AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3);
486 Print_type = make_type("Print", stmt_type, Print_fields, 3);
487 For_type = make_type("For", stmt_type, For_fields, 4);
488 While_type = make_type("While", stmt_type, While_fields, 3);
489 If_type = make_type("If", stmt_type, If_fields, 3);
490 Raise_type = make_type("Raise", stmt_type, Raise_fields, 3);
491 TryExcept_type = make_type("TryExcept", stmt_type, TryExcept_fields, 3);
492 TryFinally_type = make_type("TryFinally", stmt_type, TryFinally_fields,
493 2);
494 Assert_type = make_type("Assert", stmt_type, Assert_fields, 2);
495 Import_type = make_type("Import", stmt_type, Import_fields, 1);
496 ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields,
497 2);
498 Exec_type = make_type("Exec", stmt_type, Exec_fields, 3);
499 Global_type = make_type("Global", stmt_type, Global_fields, 1);
500 Expr_type = make_type("Expr", stmt_type, Expr_fields, 1);
501 Pass_type = make_type("Pass", stmt_type, Pass_fields, 0);
502 Break_type = make_type("Break", stmt_type, Break_fields, 0);
503 Continue_type = make_type("Continue", stmt_type, Continue_fields, 0);
504 expr_type = make_type("expr", &PyBaseObject_Type, NULL, 0);
505 BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2);
506 BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3);
507 UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2);
508 Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2);
509 Dict_type = make_type("Dict", expr_type, Dict_fields, 2);
510 ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2);
511 GeneratorExp_type = make_type("GeneratorExp", expr_type,
512 GeneratorExp_fields, 2);
513 Yield_type = make_type("Yield", expr_type, Yield_fields, 1);
514 Compare_type = make_type("Compare", expr_type, Compare_fields, 3);
515 Call_type = make_type("Call", expr_type, Call_fields, 5);
516 Repr_type = make_type("Repr", expr_type, Repr_fields, 1);
517 Num_type = make_type("Num", expr_type, Num_fields, 1);
518 Str_type = make_type("Str", expr_type, Str_fields, 1);
519 Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3);
520 Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3);
521 Name_type = make_type("Name", expr_type, Name_fields, 2);
522 List_type = make_type("List", expr_type, List_fields, 2);
523 Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2);
524 expr_context_type = make_type("expr_context", &PyBaseObject_Type, NULL,
525 0);
526 Load_type = make_type("Load", expr_context_type, Load_fields, 0);
527 Load_singleton = PyType_GenericNew(Load_type, NULL, NULL);
528 Store_type = make_type("Store", expr_context_type, Store_fields, 0);
529 Store_singleton = PyType_GenericNew(Store_type, NULL, NULL);
530 Del_type = make_type("Del", expr_context_type, Del_fields, 0);
531 Del_singleton = PyType_GenericNew(Del_type, NULL, NULL);
532 AugLoad_type = make_type("AugLoad", expr_context_type, AugLoad_fields,
533 0);
534 AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL);
535 AugStore_type = make_type("AugStore", expr_context_type,
536 AugStore_fields, 0);
537 AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL);
538 Param_type = make_type("Param", expr_context_type, Param_fields, 0);
539 Param_singleton = PyType_GenericNew(Param_type, NULL, NULL);
540 slice_type = make_type("slice", &PyBaseObject_Type, NULL, 0);
541 Ellipsis_type = make_type("Ellipsis", slice_type, Ellipsis_fields, 0);
542 Slice_type = make_type("Slice", slice_type, Slice_fields, 3);
543 ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1);
544 Index_type = make_type("Index", slice_type, Index_fields, 1);
545 boolop_type = make_type("boolop", &PyBaseObject_Type, NULL, 0);
546 And_type = make_type("And", boolop_type, And_fields, 0);
547 And_singleton = PyType_GenericNew(And_type, NULL, NULL);
548 Or_type = make_type("Or", boolop_type, Or_fields, 0);
549 Or_singleton = PyType_GenericNew(Or_type, NULL, NULL);
550 operator_type = make_type("operator", &PyBaseObject_Type, NULL, 0);
551 Add_type = make_type("Add", operator_type, Add_fields, 0);
552 Add_singleton = PyType_GenericNew(Add_type, NULL, NULL);
553 Sub_type = make_type("Sub", operator_type, Sub_fields, 0);
554 Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL);
555 Mult_type = make_type("Mult", operator_type, Mult_fields, 0);
556 Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL);
557 Div_type = make_type("Div", operator_type, Div_fields, 0);
558 Div_singleton = PyType_GenericNew(Div_type, NULL, NULL);
559 Mod_type = make_type("Mod", operator_type, Mod_fields, 0);
560 Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL);
561 Pow_type = make_type("Pow", operator_type, Pow_fields, 0);
562 Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL);
563 LShift_type = make_type("LShift", operator_type, LShift_fields, 0);
564 LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL);
565 RShift_type = make_type("RShift", operator_type, RShift_fields, 0);
566 RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL);
567 BitOr_type = make_type("BitOr", operator_type, BitOr_fields, 0);
568 BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL);
569 BitXor_type = make_type("BitXor", operator_type, BitXor_fields, 0);
570 BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL);
571 BitAnd_type = make_type("BitAnd", operator_type, BitAnd_fields, 0);
572 BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL);
573 FloorDiv_type = make_type("FloorDiv", operator_type, FloorDiv_fields,
574 0);
575 FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL);
576 unaryop_type = make_type("unaryop", &PyBaseObject_Type, NULL, 0);
577 Invert_type = make_type("Invert", unaryop_type, Invert_fields, 0);
578 Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL);
579 Not_type = make_type("Not", unaryop_type, Not_fields, 0);
580 Not_singleton = PyType_GenericNew(Not_type, NULL, NULL);
581 UAdd_type = make_type("UAdd", unaryop_type, UAdd_fields, 0);
582 UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL);
583 USub_type = make_type("USub", unaryop_type, USub_fields, 0);
584 USub_singleton = PyType_GenericNew(USub_type, NULL, NULL);
585 cmpop_type = make_type("cmpop", &PyBaseObject_Type, NULL, 0);
586 Eq_type = make_type("Eq", cmpop_type, Eq_fields, 0);
587 Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL);
588 NotEq_type = make_type("NotEq", cmpop_type, NotEq_fields, 0);
589 NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL);
590 Lt_type = make_type("Lt", cmpop_type, Lt_fields, 0);
591 Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL);
592 LtE_type = make_type("LtE", cmpop_type, LtE_fields, 0);
593 LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL);
594 Gt_type = make_type("Gt", cmpop_type, Gt_fields, 0);
595 Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL);
596 GtE_type = make_type("GtE", cmpop_type, GtE_fields, 0);
597 GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL);
598 Is_type = make_type("Is", cmpop_type, Is_fields, 0);
599 Is_singleton = PyType_GenericNew(Is_type, NULL, NULL);
600 IsNot_type = make_type("IsNot", cmpop_type, IsNot_fields, 0);
601 IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL);
602 In_type = make_type("In", cmpop_type, In_fields, 0);
603 In_singleton = PyType_GenericNew(In_type, NULL, NULL);
604 NotIn_type = make_type("NotIn", cmpop_type, NotIn_fields, 0);
605 NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL);
606 comprehension_type = make_type("comprehension", &PyBaseObject_Type,
607 comprehension_fields, 3);
608 excepthandler_type = make_type("excepthandler", &PyBaseObject_Type,
609 excepthandler_fields, 3);
610 arguments_type = make_type("arguments", &PyBaseObject_Type,
611 arguments_fields, 4);
612 keyword_type = make_type("keyword", &PyBaseObject_Type, keyword_fields,
613 2);
614 alias_type = make_type("alias", &PyBaseObject_Type, alias_fields, 2);
615return 1;
616}
Neal Norwitz7b5a6042005-11-13 19:14:20 +0000617
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000618mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000619Module(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000620{
621 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000622 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000623 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000624 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000625 return NULL;
626 }
627 p->kind = Module_kind;
628 p->v.Module.body = body;
629 return p;
630}
631
632mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000633Interactive(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000634{
635 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000636 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000637 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000638 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000639 return NULL;
640 }
641 p->kind = Interactive_kind;
642 p->v.Interactive.body = body;
643 return p;
644}
645
646mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000647Expression(expr_ty body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000648{
649 mod_ty p;
650 if (!body) {
651 PyErr_SetString(PyExc_ValueError,
652 "field body is required for Expression");
653 return NULL;
654 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000655 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000656 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000657 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000658 return NULL;
659 }
660 p->kind = Expression_kind;
661 p->v.Expression.body = body;
662 return p;
663}
664
665mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000666Suite(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000667{
668 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000669 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000670 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000671 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000672 return NULL;
673 }
674 p->kind = Suite_kind;
675 p->v.Suite.body = body;
676 return p;
677}
678
679stmt_ty
680FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000681 decorators, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000682{
683 stmt_ty p;
684 if (!name) {
685 PyErr_SetString(PyExc_ValueError,
686 "field name is required for FunctionDef");
687 return NULL;
688 }
689 if (!args) {
690 PyErr_SetString(PyExc_ValueError,
691 "field args is required for FunctionDef");
692 return NULL;
693 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000694 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000695 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000696 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000697 return NULL;
698 }
699 p->kind = FunctionDef_kind;
700 p->v.FunctionDef.name = name;
701 p->v.FunctionDef.args = args;
702 p->v.FunctionDef.body = body;
703 p->v.FunctionDef.decorators = decorators;
704 p->lineno = lineno;
705 return p;
706}
707
708stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000709ClassDef(identifier name, asdl_seq * bases, asdl_seq * body, int lineno,
710 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000711{
712 stmt_ty p;
713 if (!name) {
714 PyErr_SetString(PyExc_ValueError,
715 "field name is required for ClassDef");
716 return NULL;
717 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000718 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000719 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000720 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000721 return NULL;
722 }
723 p->kind = ClassDef_kind;
724 p->v.ClassDef.name = name;
725 p->v.ClassDef.bases = bases;
726 p->v.ClassDef.body = body;
727 p->lineno = lineno;
728 return p;
729}
730
731stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000732Return(expr_ty value, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000733{
734 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000735 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000736 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000737 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000738 return NULL;
739 }
740 p->kind = Return_kind;
741 p->v.Return.value = value;
742 p->lineno = lineno;
743 return p;
744}
745
746stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000747Delete(asdl_seq * targets, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000748{
749 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000750 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000751 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000752 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000753 return NULL;
754 }
755 p->kind = Delete_kind;
756 p->v.Delete.targets = targets;
757 p->lineno = lineno;
758 return p;
759}
760
761stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000762Assign(asdl_seq * targets, expr_ty value, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000763{
764 stmt_ty p;
765 if (!value) {
766 PyErr_SetString(PyExc_ValueError,
767 "field value is required for Assign");
768 return NULL;
769 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000770 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000771 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000772 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000773 return NULL;
774 }
775 p->kind = Assign_kind;
776 p->v.Assign.targets = targets;
777 p->v.Assign.value = value;
778 p->lineno = lineno;
779 return p;
780}
781
782stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000783AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, PyArena
784 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000785{
786 stmt_ty p;
787 if (!target) {
788 PyErr_SetString(PyExc_ValueError,
789 "field target is required for AugAssign");
790 return NULL;
791 }
792 if (!op) {
793 PyErr_SetString(PyExc_ValueError,
794 "field op is required for AugAssign");
795 return NULL;
796 }
797 if (!value) {
798 PyErr_SetString(PyExc_ValueError,
799 "field value is required for AugAssign");
800 return NULL;
801 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000802 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000803 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000804 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000805 return NULL;
806 }
807 p->kind = AugAssign_kind;
808 p->v.AugAssign.target = target;
809 p->v.AugAssign.op = op;
810 p->v.AugAssign.value = value;
811 p->lineno = lineno;
812 return p;
813}
814
815stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000816Print(expr_ty dest, asdl_seq * values, bool nl, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000817{
818 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000819 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000820 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000821 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000822 return NULL;
823 }
824 p->kind = Print_kind;
825 p->v.Print.dest = dest;
826 p->v.Print.values = values;
827 p->v.Print.nl = nl;
828 p->lineno = lineno;
829 return p;
830}
831
832stmt_ty
833For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000834 lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000835{
836 stmt_ty p;
837 if (!target) {
838 PyErr_SetString(PyExc_ValueError,
839 "field target is required for For");
840 return NULL;
841 }
842 if (!iter) {
843 PyErr_SetString(PyExc_ValueError,
844 "field iter is required for For");
845 return NULL;
846 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000847 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000848 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000849 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000850 return NULL;
851 }
852 p->kind = For_kind;
853 p->v.For.target = target;
854 p->v.For.iter = iter;
855 p->v.For.body = body;
856 p->v.For.orelse = orelse;
857 p->lineno = lineno;
858 return p;
859}
860
861stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000862While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, PyArena
863 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000864{
865 stmt_ty p;
866 if (!test) {
867 PyErr_SetString(PyExc_ValueError,
868 "field test is required for While");
869 return NULL;
870 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000871 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000872 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000873 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000874 return NULL;
875 }
876 p->kind = While_kind;
877 p->v.While.test = test;
878 p->v.While.body = body;
879 p->v.While.orelse = orelse;
880 p->lineno = lineno;
881 return p;
882}
883
884stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000885If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000886{
887 stmt_ty p;
888 if (!test) {
889 PyErr_SetString(PyExc_ValueError,
890 "field test is required for If");
891 return NULL;
892 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000893 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000894 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000895 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000896 return NULL;
897 }
898 p->kind = If_kind;
899 p->v.If.test = test;
900 p->v.If.body = body;
901 p->v.If.orelse = orelse;
902 p->lineno = lineno;
903 return p;
904}
905
906stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000907Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000908{
909 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000910 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000911 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000912 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000913 return NULL;
914 }
915 p->kind = Raise_kind;
916 p->v.Raise.type = type;
917 p->v.Raise.inst = inst;
918 p->v.Raise.tback = tback;
919 p->lineno = lineno;
920 return p;
921}
922
923stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000924TryExcept(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, int lineno,
925 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000926{
927 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000928 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000929 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000930 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000931 return NULL;
932 }
933 p->kind = TryExcept_kind;
934 p->v.TryExcept.body = body;
935 p->v.TryExcept.handlers = handlers;
936 p->v.TryExcept.orelse = orelse;
937 p->lineno = lineno;
938 return p;
939}
940
941stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000942TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000943{
944 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000945 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000946 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000947 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000948 return NULL;
949 }
950 p->kind = TryFinally_kind;
951 p->v.TryFinally.body = body;
952 p->v.TryFinally.finalbody = finalbody;
953 p->lineno = lineno;
954 return p;
955}
956
957stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000958Assert(expr_ty test, expr_ty msg, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000959{
960 stmt_ty p;
961 if (!test) {
962 PyErr_SetString(PyExc_ValueError,
963 "field test is required for Assert");
964 return NULL;
965 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000966 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000967 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000968 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000969 return NULL;
970 }
971 p->kind = Assert_kind;
972 p->v.Assert.test = test;
973 p->v.Assert.msg = msg;
974 p->lineno = lineno;
975 return p;
976}
977
978stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000979Import(asdl_seq * names, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000980{
981 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000982 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000983 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000984 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000985 return NULL;
986 }
987 p->kind = Import_kind;
988 p->v.Import.names = names;
989 p->lineno = lineno;
990 return p;
991}
992
993stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000994ImportFrom(identifier module, asdl_seq * names, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000995{
996 stmt_ty p;
997 if (!module) {
998 PyErr_SetString(PyExc_ValueError,
999 "field module is required for ImportFrom");
1000 return NULL;
1001 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001002 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001003 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001004 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001005 return NULL;
1006 }
1007 p->kind = ImportFrom_kind;
1008 p->v.ImportFrom.module = module;
1009 p->v.ImportFrom.names = names;
1010 p->lineno = lineno;
1011 return p;
1012}
1013
1014stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001015Exec(expr_ty body, expr_ty globals, expr_ty locals, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001016{
1017 stmt_ty p;
1018 if (!body) {
1019 PyErr_SetString(PyExc_ValueError,
1020 "field body is required for Exec");
1021 return NULL;
1022 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001023 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001024 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001025 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001026 return NULL;
1027 }
1028 p->kind = Exec_kind;
1029 p->v.Exec.body = body;
1030 p->v.Exec.globals = globals;
1031 p->v.Exec.locals = locals;
1032 p->lineno = lineno;
1033 return p;
1034}
1035
1036stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001037Global(asdl_seq * names, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001038{
1039 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001040 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001041 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001042 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001043 return NULL;
1044 }
1045 p->kind = Global_kind;
1046 p->v.Global.names = names;
1047 p->lineno = lineno;
1048 return p;
1049}
1050
1051stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001052Expr(expr_ty value, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001053{
1054 stmt_ty p;
1055 if (!value) {
1056 PyErr_SetString(PyExc_ValueError,
1057 "field value is required for Expr");
1058 return NULL;
1059 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001060 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001061 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001062 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001063 return NULL;
1064 }
1065 p->kind = Expr_kind;
1066 p->v.Expr.value = value;
1067 p->lineno = lineno;
1068 return p;
1069}
1070
1071stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001072Pass(int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001073{
1074 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001075 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001076 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001077 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001078 return NULL;
1079 }
1080 p->kind = Pass_kind;
1081 p->lineno = lineno;
1082 return p;
1083}
1084
1085stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001086Break(int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001087{
1088 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001089 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001090 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001091 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001092 return NULL;
1093 }
1094 p->kind = Break_kind;
1095 p->lineno = lineno;
1096 return p;
1097}
1098
1099stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001100Continue(int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001101{
1102 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001103 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001104 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001105 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001106 return NULL;
1107 }
1108 p->kind = Continue_kind;
1109 p->lineno = lineno;
1110 return p;
1111}
1112
1113expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001114BoolOp(boolop_ty op, asdl_seq * values, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001115{
1116 expr_ty p;
1117 if (!op) {
1118 PyErr_SetString(PyExc_ValueError,
1119 "field op is required for BoolOp");
1120 return NULL;
1121 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001122 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001123 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001124 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001125 return NULL;
1126 }
1127 p->kind = BoolOp_kind;
1128 p->v.BoolOp.op = op;
1129 p->v.BoolOp.values = values;
1130 p->lineno = lineno;
1131 return p;
1132}
1133
1134expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001135BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001136{
1137 expr_ty p;
1138 if (!left) {
1139 PyErr_SetString(PyExc_ValueError,
1140 "field left is required for BinOp");
1141 return NULL;
1142 }
1143 if (!op) {
1144 PyErr_SetString(PyExc_ValueError,
1145 "field op is required for BinOp");
1146 return NULL;
1147 }
1148 if (!right) {
1149 PyErr_SetString(PyExc_ValueError,
1150 "field right is required for BinOp");
1151 return NULL;
1152 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001153 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001154 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001155 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001156 return NULL;
1157 }
1158 p->kind = BinOp_kind;
1159 p->v.BinOp.left = left;
1160 p->v.BinOp.op = op;
1161 p->v.BinOp.right = right;
1162 p->lineno = lineno;
1163 return p;
1164}
1165
1166expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001167UnaryOp(unaryop_ty op, expr_ty operand, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001168{
1169 expr_ty p;
1170 if (!op) {
1171 PyErr_SetString(PyExc_ValueError,
1172 "field op is required for UnaryOp");
1173 return NULL;
1174 }
1175 if (!operand) {
1176 PyErr_SetString(PyExc_ValueError,
1177 "field operand is required for UnaryOp");
1178 return NULL;
1179 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001180 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001181 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001182 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001183 return NULL;
1184 }
1185 p->kind = UnaryOp_kind;
1186 p->v.UnaryOp.op = op;
1187 p->v.UnaryOp.operand = operand;
1188 p->lineno = lineno;
1189 return p;
1190}
1191
1192expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001193Lambda(arguments_ty args, expr_ty body, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001194{
1195 expr_ty p;
1196 if (!args) {
1197 PyErr_SetString(PyExc_ValueError,
1198 "field args is required for Lambda");
1199 return NULL;
1200 }
1201 if (!body) {
1202 PyErr_SetString(PyExc_ValueError,
1203 "field body is required for Lambda");
1204 return NULL;
1205 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001206 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001207 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001208 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001209 return NULL;
1210 }
1211 p->kind = Lambda_kind;
1212 p->v.Lambda.args = args;
1213 p->v.Lambda.body = body;
1214 p->lineno = lineno;
1215 return p;
1216}
1217
1218expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001219Dict(asdl_seq * keys, asdl_seq * values, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001220{
1221 expr_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001222 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001223 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001224 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001225 return NULL;
1226 }
1227 p->kind = Dict_kind;
1228 p->v.Dict.keys = keys;
1229 p->v.Dict.values = values;
1230 p->lineno = lineno;
1231 return p;
1232}
1233
1234expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001235ListComp(expr_ty elt, asdl_seq * generators, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001236{
1237 expr_ty p;
1238 if (!elt) {
1239 PyErr_SetString(PyExc_ValueError,
1240 "field elt is required for ListComp");
1241 return NULL;
1242 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001243 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001244 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001245 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001246 return NULL;
1247 }
1248 p->kind = ListComp_kind;
1249 p->v.ListComp.elt = elt;
1250 p->v.ListComp.generators = generators;
1251 p->lineno = lineno;
1252 return p;
1253}
1254
1255expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001256GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001257{
1258 expr_ty p;
1259 if (!elt) {
1260 PyErr_SetString(PyExc_ValueError,
1261 "field elt is required for GeneratorExp");
1262 return NULL;
1263 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001264 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001265 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001266 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001267 return NULL;
1268 }
1269 p->kind = GeneratorExp_kind;
1270 p->v.GeneratorExp.elt = elt;
1271 p->v.GeneratorExp.generators = generators;
1272 p->lineno = lineno;
1273 return p;
1274}
1275
1276expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001277Yield(expr_ty value, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001278{
1279 expr_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001280 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001281 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001282 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001283 return NULL;
1284 }
1285 p->kind = Yield_kind;
1286 p->v.Yield.value = value;
1287 p->lineno = lineno;
1288 return p;
1289}
1290
1291expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001292Compare(expr_ty left, asdl_seq * ops, asdl_seq * comparators, int lineno,
1293 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001294{
1295 expr_ty p;
1296 if (!left) {
1297 PyErr_SetString(PyExc_ValueError,
1298 "field left is required for Compare");
1299 return NULL;
1300 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001301 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001302 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001303 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001304 return NULL;
1305 }
1306 p->kind = Compare_kind;
1307 p->v.Compare.left = left;
1308 p->v.Compare.ops = ops;
1309 p->v.Compare.comparators = comparators;
1310 p->lineno = lineno;
1311 return p;
1312}
1313
1314expr_ty
1315Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, expr_ty starargs,
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001316 expr_ty kwargs, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001317{
1318 expr_ty p;
1319 if (!func) {
1320 PyErr_SetString(PyExc_ValueError,
1321 "field func is required for Call");
1322 return NULL;
1323 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001324 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001325 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001326 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001327 return NULL;
1328 }
1329 p->kind = Call_kind;
1330 p->v.Call.func = func;
1331 p->v.Call.args = args;
1332 p->v.Call.keywords = keywords;
1333 p->v.Call.starargs = starargs;
1334 p->v.Call.kwargs = kwargs;
1335 p->lineno = lineno;
1336 return p;
1337}
1338
1339expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001340Repr(expr_ty value, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001341{
1342 expr_ty p;
1343 if (!value) {
1344 PyErr_SetString(PyExc_ValueError,
1345 "field value is required for Repr");
1346 return NULL;
1347 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001348 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001349 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001350 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001351 return NULL;
1352 }
1353 p->kind = Repr_kind;
1354 p->v.Repr.value = value;
1355 p->lineno = lineno;
1356 return p;
1357}
1358
1359expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001360Num(object n, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001361{
1362 expr_ty p;
1363 if (!n) {
1364 PyErr_SetString(PyExc_ValueError,
1365 "field n is required for Num");
1366 return NULL;
1367 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001368 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001369 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001370 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001371 return NULL;
1372 }
1373 p->kind = Num_kind;
1374 p->v.Num.n = n;
1375 p->lineno = lineno;
1376 return p;
1377}
1378
1379expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001380Str(string s, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001381{
1382 expr_ty p;
1383 if (!s) {
1384 PyErr_SetString(PyExc_ValueError,
1385 "field s is required for Str");
1386 return NULL;
1387 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001388 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001389 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001390 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001391 return NULL;
1392 }
1393 p->kind = Str_kind;
1394 p->v.Str.s = s;
1395 p->lineno = lineno;
1396 return p;
1397}
1398
1399expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001400Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno,
1401 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001402{
1403 expr_ty p;
1404 if (!value) {
1405 PyErr_SetString(PyExc_ValueError,
1406 "field value is required for Attribute");
1407 return NULL;
1408 }
1409 if (!attr) {
1410 PyErr_SetString(PyExc_ValueError,
1411 "field attr is required for Attribute");
1412 return NULL;
1413 }
1414 if (!ctx) {
1415 PyErr_SetString(PyExc_ValueError,
1416 "field ctx is required for Attribute");
1417 return NULL;
1418 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001419 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001420 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001421 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001422 return NULL;
1423 }
1424 p->kind = Attribute_kind;
1425 p->v.Attribute.value = value;
1426 p->v.Attribute.attr = attr;
1427 p->v.Attribute.ctx = ctx;
1428 p->lineno = lineno;
1429 return p;
1430}
1431
1432expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001433Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno,
1434 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001435{
1436 expr_ty p;
1437 if (!value) {
1438 PyErr_SetString(PyExc_ValueError,
1439 "field value is required for Subscript");
1440 return NULL;
1441 }
1442 if (!slice) {
1443 PyErr_SetString(PyExc_ValueError,
1444 "field slice is required for Subscript");
1445 return NULL;
1446 }
1447 if (!ctx) {
1448 PyErr_SetString(PyExc_ValueError,
1449 "field ctx is required for Subscript");
1450 return NULL;
1451 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001452 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001453 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001454 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001455 return NULL;
1456 }
1457 p->kind = Subscript_kind;
1458 p->v.Subscript.value = value;
1459 p->v.Subscript.slice = slice;
1460 p->v.Subscript.ctx = ctx;
1461 p->lineno = lineno;
1462 return p;
1463}
1464
1465expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001466Name(identifier id, expr_context_ty ctx, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001467{
1468 expr_ty p;
1469 if (!id) {
1470 PyErr_SetString(PyExc_ValueError,
1471 "field id is required for Name");
1472 return NULL;
1473 }
1474 if (!ctx) {
1475 PyErr_SetString(PyExc_ValueError,
1476 "field ctx is required for Name");
1477 return NULL;
1478 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001479 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001480 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001481 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001482 return NULL;
1483 }
1484 p->kind = Name_kind;
1485 p->v.Name.id = id;
1486 p->v.Name.ctx = ctx;
1487 p->lineno = lineno;
1488 return p;
1489}
1490
1491expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001492List(asdl_seq * elts, expr_context_ty ctx, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001493{
1494 expr_ty p;
1495 if (!ctx) {
1496 PyErr_SetString(PyExc_ValueError,
1497 "field ctx is required for List");
1498 return NULL;
1499 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001500 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001501 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001502 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001503 return NULL;
1504 }
1505 p->kind = List_kind;
1506 p->v.List.elts = elts;
1507 p->v.List.ctx = ctx;
1508 p->lineno = lineno;
1509 return p;
1510}
1511
1512expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001513Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001514{
1515 expr_ty p;
1516 if (!ctx) {
1517 PyErr_SetString(PyExc_ValueError,
1518 "field ctx is required for Tuple");
1519 return NULL;
1520 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001521 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001522 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001523 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001524 return NULL;
1525 }
1526 p->kind = Tuple_kind;
1527 p->v.Tuple.elts = elts;
1528 p->v.Tuple.ctx = ctx;
1529 p->lineno = lineno;
1530 return p;
1531}
1532
1533slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001534Ellipsis(PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001535{
1536 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001537 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001538 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001539 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001540 return NULL;
1541 }
1542 p->kind = Ellipsis_kind;
1543 return p;
1544}
1545
1546slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001547Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001548{
1549 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001550 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001551 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001552 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001553 return NULL;
1554 }
1555 p->kind = Slice_kind;
1556 p->v.Slice.lower = lower;
1557 p->v.Slice.upper = upper;
1558 p->v.Slice.step = step;
1559 return p;
1560}
1561
1562slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001563ExtSlice(asdl_seq * dims, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001564{
1565 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001566 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001567 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001568 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001569 return NULL;
1570 }
1571 p->kind = ExtSlice_kind;
1572 p->v.ExtSlice.dims = dims;
1573 return p;
1574}
1575
1576slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001577Index(expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001578{
1579 slice_ty p;
1580 if (!value) {
1581 PyErr_SetString(PyExc_ValueError,
1582 "field value is required for Index");
1583 return NULL;
1584 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001585 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001586 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001587 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001588 return NULL;
1589 }
1590 p->kind = Index_kind;
1591 p->v.Index.value = value;
1592 return p;
1593}
1594
1595comprehension_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001596comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001597{
1598 comprehension_ty p;
1599 if (!target) {
1600 PyErr_SetString(PyExc_ValueError,
1601 "field target is required for comprehension");
1602 return NULL;
1603 }
1604 if (!iter) {
1605 PyErr_SetString(PyExc_ValueError,
1606 "field iter is required for comprehension");
1607 return NULL;
1608 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001609 p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001610 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001611 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001612 return NULL;
1613 }
1614 p->target = target;
1615 p->iter = iter;
1616 p->ifs = ifs;
1617 return p;
1618}
1619
1620excepthandler_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001621excepthandler(expr_ty type, expr_ty name, asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001622{
1623 excepthandler_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001624 p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001625 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001626 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001627 return NULL;
1628 }
1629 p->type = type;
1630 p->name = name;
1631 p->body = body;
1632 return p;
1633}
1634
1635arguments_ty
1636arguments(asdl_seq * args, identifier vararg, identifier kwarg, asdl_seq *
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001637 defaults, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001638{
1639 arguments_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001640 p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001641 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001642 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001643 return NULL;
1644 }
1645 p->args = args;
1646 p->vararg = vararg;
1647 p->kwarg = kwarg;
1648 p->defaults = defaults;
1649 return p;
1650}
1651
1652keyword_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001653keyword(identifier arg, expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001654{
1655 keyword_ty p;
1656 if (!arg) {
1657 PyErr_SetString(PyExc_ValueError,
1658 "field arg is required for keyword");
1659 return NULL;
1660 }
1661 if (!value) {
1662 PyErr_SetString(PyExc_ValueError,
1663 "field value is required for keyword");
1664 return NULL;
1665 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001666 p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001667 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001668 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001669 return NULL;
1670 }
1671 p->arg = arg;
1672 p->value = value;
1673 return p;
1674}
1675
1676alias_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001677alias(identifier name, identifier asname, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001678{
1679 alias_ty p;
1680 if (!name) {
1681 PyErr_SetString(PyExc_ValueError,
1682 "field name is required for alias");
1683 return NULL;
1684 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001685 p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001686 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001687 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001688 return NULL;
1689 }
1690 p->name = name;
1691 p->asname = asname;
1692 return p;
1693}
1694
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001695
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001696PyObject*
1697ast2obj_mod(void* _o)
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001698{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001699 mod_ty o = (mod_ty)_o;
1700 PyObject *result = NULL, *value = NULL;
1701 if (!o) {
1702 Py_INCREF(Py_None);
1703 return Py_None;
1704 }
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001705
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001706 switch (o->kind) {
1707 case Module_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001708 result = PyType_GenericNew(Module_type, NULL, NULL);
1709 if (!result) goto failed;
1710 value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
1711 if (!value) goto failed;
1712 if (PyObject_SetAttrString(result, "body", value) == -1)
1713 goto failed;
1714 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001715 break;
1716 case Interactive_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001717 result = PyType_GenericNew(Interactive_type, NULL, NULL);
1718 if (!result) goto failed;
1719 value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
1720 if (!value) goto failed;
1721 if (PyObject_SetAttrString(result, "body", value) == -1)
1722 goto failed;
1723 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001724 break;
1725 case Expression_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001726 result = PyType_GenericNew(Expression_type, NULL, NULL);
1727 if (!result) goto failed;
1728 value = ast2obj_expr(o->v.Expression.body);
1729 if (!value) goto failed;
1730 if (PyObject_SetAttrString(result, "body", value) == -1)
1731 goto failed;
1732 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001733 break;
1734 case Suite_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001735 result = PyType_GenericNew(Suite_type, NULL, NULL);
1736 if (!result) goto failed;
1737 value = ast2obj_list(o->v.Suite.body, ast2obj_stmt);
1738 if (!value) goto failed;
1739 if (PyObject_SetAttrString(result, "body", value) == -1)
1740 goto failed;
1741 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001742 break;
1743 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001744
1745 return result;
1746failed:
1747 Py_XDECREF(value);
1748 Py_XDECREF(result);
1749 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001750}
1751
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001752PyObject*
1753ast2obj_stmt(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001754{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001755 stmt_ty o = (stmt_ty)_o;
1756 PyObject *result = NULL, *value = NULL;
1757 if (!o) {
1758 Py_INCREF(Py_None);
1759 return Py_None;
1760 }
1761
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001762 switch (o->kind) {
1763 case FunctionDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001764 result = PyType_GenericNew(FunctionDef_type, NULL, NULL);
1765 if (!result) goto failed;
1766 value = ast2obj_identifier(o->v.FunctionDef.name);
1767 if (!value) goto failed;
1768 if (PyObject_SetAttrString(result, "name", value) == -1)
1769 goto failed;
1770 Py_DECREF(value);
1771 value = ast2obj_arguments(o->v.FunctionDef.args);
1772 if (!value) goto failed;
1773 if (PyObject_SetAttrString(result, "args", value) == -1)
1774 goto failed;
1775 Py_DECREF(value);
1776 value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
1777 if (!value) goto failed;
1778 if (PyObject_SetAttrString(result, "body", value) == -1)
1779 goto failed;
1780 Py_DECREF(value);
1781 value = ast2obj_list(o->v.FunctionDef.decorators, ast2obj_expr);
1782 if (!value) goto failed;
1783 if (PyObject_SetAttrString(result, "decorators", value) == -1)
1784 goto failed;
1785 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001786 break;
1787 case ClassDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001788 result = PyType_GenericNew(ClassDef_type, NULL, NULL);
1789 if (!result) goto failed;
1790 value = ast2obj_identifier(o->v.ClassDef.name);
1791 if (!value) goto failed;
1792 if (PyObject_SetAttrString(result, "name", value) == -1)
1793 goto failed;
1794 Py_DECREF(value);
1795 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
1796 if (!value) goto failed;
1797 if (PyObject_SetAttrString(result, "bases", value) == -1)
1798 goto failed;
1799 Py_DECREF(value);
1800 value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
1801 if (!value) goto failed;
1802 if (PyObject_SetAttrString(result, "body", value) == -1)
1803 goto failed;
1804 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001805 break;
1806 case Return_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001807 result = PyType_GenericNew(Return_type, NULL, NULL);
1808 if (!result) goto failed;
1809 value = ast2obj_expr(o->v.Return.value);
1810 if (!value) goto failed;
1811 if (PyObject_SetAttrString(result, "value", value) == -1)
1812 goto failed;
1813 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001814 break;
1815 case Delete_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001816 result = PyType_GenericNew(Delete_type, NULL, NULL);
1817 if (!result) goto failed;
1818 value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
1819 if (!value) goto failed;
1820 if (PyObject_SetAttrString(result, "targets", value) == -1)
1821 goto failed;
1822 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001823 break;
1824 case Assign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001825 result = PyType_GenericNew(Assign_type, NULL, NULL);
1826 if (!result) goto failed;
1827 value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
1828 if (!value) goto failed;
1829 if (PyObject_SetAttrString(result, "targets", value) == -1)
1830 goto failed;
1831 Py_DECREF(value);
1832 value = ast2obj_expr(o->v.Assign.value);
1833 if (!value) goto failed;
1834 if (PyObject_SetAttrString(result, "value", value) == -1)
1835 goto failed;
1836 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001837 break;
1838 case AugAssign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001839 result = PyType_GenericNew(AugAssign_type, NULL, NULL);
1840 if (!result) goto failed;
1841 value = ast2obj_expr(o->v.AugAssign.target);
1842 if (!value) goto failed;
1843 if (PyObject_SetAttrString(result, "target", value) == -1)
1844 goto failed;
1845 Py_DECREF(value);
1846 value = ast2obj_operator(o->v.AugAssign.op);
1847 if (!value) goto failed;
1848 if (PyObject_SetAttrString(result, "op", value) == -1)
1849 goto failed;
1850 Py_DECREF(value);
1851 value = ast2obj_expr(o->v.AugAssign.value);
1852 if (!value) goto failed;
1853 if (PyObject_SetAttrString(result, "value", value) == -1)
1854 goto failed;
1855 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001856 break;
1857 case Print_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001858 result = PyType_GenericNew(Print_type, NULL, NULL);
1859 if (!result) goto failed;
1860 value = ast2obj_expr(o->v.Print.dest);
1861 if (!value) goto failed;
1862 if (PyObject_SetAttrString(result, "dest", value) == -1)
1863 goto failed;
1864 Py_DECREF(value);
1865 value = ast2obj_list(o->v.Print.values, ast2obj_expr);
1866 if (!value) goto failed;
1867 if (PyObject_SetAttrString(result, "values", value) == -1)
1868 goto failed;
1869 Py_DECREF(value);
1870 value = ast2obj_bool(o->v.Print.nl);
1871 if (!value) goto failed;
1872 if (PyObject_SetAttrString(result, "nl", value) == -1)
1873 goto failed;
1874 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001875 break;
1876 case For_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001877 result = PyType_GenericNew(For_type, NULL, NULL);
1878 if (!result) goto failed;
1879 value = ast2obj_expr(o->v.For.target);
1880 if (!value) goto failed;
1881 if (PyObject_SetAttrString(result, "target", value) == -1)
1882 goto failed;
1883 Py_DECREF(value);
1884 value = ast2obj_expr(o->v.For.iter);
1885 if (!value) goto failed;
1886 if (PyObject_SetAttrString(result, "iter", value) == -1)
1887 goto failed;
1888 Py_DECREF(value);
1889 value = ast2obj_list(o->v.For.body, ast2obj_stmt);
1890 if (!value) goto failed;
1891 if (PyObject_SetAttrString(result, "body", value) == -1)
1892 goto failed;
1893 Py_DECREF(value);
1894 value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
1895 if (!value) goto failed;
1896 if (PyObject_SetAttrString(result, "orelse", value) == -1)
1897 goto failed;
1898 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001899 break;
1900 case While_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001901 result = PyType_GenericNew(While_type, NULL, NULL);
1902 if (!result) goto failed;
1903 value = ast2obj_expr(o->v.While.test);
1904 if (!value) goto failed;
1905 if (PyObject_SetAttrString(result, "test", value) == -1)
1906 goto failed;
1907 Py_DECREF(value);
1908 value = ast2obj_list(o->v.While.body, ast2obj_stmt);
1909 if (!value) goto failed;
1910 if (PyObject_SetAttrString(result, "body", value) == -1)
1911 goto failed;
1912 Py_DECREF(value);
1913 value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);
1914 if (!value) goto failed;
1915 if (PyObject_SetAttrString(result, "orelse", value) == -1)
1916 goto failed;
1917 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001918 break;
1919 case If_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001920 result = PyType_GenericNew(If_type, NULL, NULL);
1921 if (!result) goto failed;
1922 value = ast2obj_expr(o->v.If.test);
1923 if (!value) goto failed;
1924 if (PyObject_SetAttrString(result, "test", value) == -1)
1925 goto failed;
1926 Py_DECREF(value);
1927 value = ast2obj_list(o->v.If.body, ast2obj_stmt);
1928 if (!value) goto failed;
1929 if (PyObject_SetAttrString(result, "body", value) == -1)
1930 goto failed;
1931 Py_DECREF(value);
1932 value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
1933 if (!value) goto failed;
1934 if (PyObject_SetAttrString(result, "orelse", value) == -1)
1935 goto failed;
1936 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001937 break;
1938 case Raise_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001939 result = PyType_GenericNew(Raise_type, NULL, NULL);
1940 if (!result) goto failed;
1941 value = ast2obj_expr(o->v.Raise.type);
1942 if (!value) goto failed;
1943 if (PyObject_SetAttrString(result, "type", value) == -1)
1944 goto failed;
1945 Py_DECREF(value);
1946 value = ast2obj_expr(o->v.Raise.inst);
1947 if (!value) goto failed;
1948 if (PyObject_SetAttrString(result, "inst", value) == -1)
1949 goto failed;
1950 Py_DECREF(value);
1951 value = ast2obj_expr(o->v.Raise.tback);
1952 if (!value) goto failed;
1953 if (PyObject_SetAttrString(result, "tback", value) == -1)
1954 goto failed;
1955 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001956 break;
1957 case TryExcept_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001958 result = PyType_GenericNew(TryExcept_type, NULL, NULL);
1959 if (!result) goto failed;
1960 value = ast2obj_list(o->v.TryExcept.body, ast2obj_stmt);
1961 if (!value) goto failed;
1962 if (PyObject_SetAttrString(result, "body", value) == -1)
1963 goto failed;
1964 Py_DECREF(value);
1965 value = ast2obj_list(o->v.TryExcept.handlers,
1966 ast2obj_excepthandler);
1967 if (!value) goto failed;
1968 if (PyObject_SetAttrString(result, "handlers", value) == -1)
1969 goto failed;
1970 Py_DECREF(value);
1971 value = ast2obj_list(o->v.TryExcept.orelse, ast2obj_stmt);
1972 if (!value) goto failed;
1973 if (PyObject_SetAttrString(result, "orelse", value) == -1)
1974 goto failed;
1975 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001976 break;
1977 case TryFinally_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001978 result = PyType_GenericNew(TryFinally_type, NULL, NULL);
1979 if (!result) goto failed;
1980 value = ast2obj_list(o->v.TryFinally.body, ast2obj_stmt);
1981 if (!value) goto failed;
1982 if (PyObject_SetAttrString(result, "body", value) == -1)
1983 goto failed;
1984 Py_DECREF(value);
1985 value = ast2obj_list(o->v.TryFinally.finalbody, ast2obj_stmt);
1986 if (!value) goto failed;
1987 if (PyObject_SetAttrString(result, "finalbody", value) == -1)
1988 goto failed;
1989 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001990 break;
1991 case Assert_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001992 result = PyType_GenericNew(Assert_type, NULL, NULL);
1993 if (!result) goto failed;
1994 value = ast2obj_expr(o->v.Assert.test);
1995 if (!value) goto failed;
1996 if (PyObject_SetAttrString(result, "test", value) == -1)
1997 goto failed;
1998 Py_DECREF(value);
1999 value = ast2obj_expr(o->v.Assert.msg);
2000 if (!value) goto failed;
2001 if (PyObject_SetAttrString(result, "msg", value) == -1)
2002 goto failed;
2003 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002004 break;
2005 case Import_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002006 result = PyType_GenericNew(Import_type, NULL, NULL);
2007 if (!result) goto failed;
2008 value = ast2obj_list(o->v.Import.names, ast2obj_alias);
2009 if (!value) goto failed;
2010 if (PyObject_SetAttrString(result, "names", value) == -1)
2011 goto failed;
2012 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002013 break;
2014 case ImportFrom_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002015 result = PyType_GenericNew(ImportFrom_type, NULL, NULL);
2016 if (!result) goto failed;
2017 value = ast2obj_identifier(o->v.ImportFrom.module);
2018 if (!value) goto failed;
2019 if (PyObject_SetAttrString(result, "module", value) == -1)
2020 goto failed;
2021 Py_DECREF(value);
2022 value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
2023 if (!value) goto failed;
2024 if (PyObject_SetAttrString(result, "names", value) == -1)
2025 goto failed;
2026 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002027 break;
2028 case Exec_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002029 result = PyType_GenericNew(Exec_type, NULL, NULL);
2030 if (!result) goto failed;
2031 value = ast2obj_expr(o->v.Exec.body);
2032 if (!value) goto failed;
2033 if (PyObject_SetAttrString(result, "body", value) == -1)
2034 goto failed;
2035 Py_DECREF(value);
2036 value = ast2obj_expr(o->v.Exec.globals);
2037 if (!value) goto failed;
2038 if (PyObject_SetAttrString(result, "globals", value) == -1)
2039 goto failed;
2040 Py_DECREF(value);
2041 value = ast2obj_expr(o->v.Exec.locals);
2042 if (!value) goto failed;
2043 if (PyObject_SetAttrString(result, "locals", value) == -1)
2044 goto failed;
2045 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002046 break;
2047 case Global_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002048 result = PyType_GenericNew(Global_type, NULL, NULL);
2049 if (!result) goto failed;
2050 value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
2051 if (!value) goto failed;
2052 if (PyObject_SetAttrString(result, "names", value) == -1)
2053 goto failed;
2054 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002055 break;
2056 case Expr_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002057 result = PyType_GenericNew(Expr_type, NULL, NULL);
2058 if (!result) goto failed;
2059 value = ast2obj_expr(o->v.Expr.value);
2060 if (!value) goto failed;
2061 if (PyObject_SetAttrString(result, "value", value) == -1)
2062 goto failed;
2063 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002064 break;
2065 case Pass_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002066 result = PyType_GenericNew(Pass_type, NULL, NULL);
2067 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002068 break;
2069 case Break_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002070 result = PyType_GenericNew(Break_type, NULL, NULL);
2071 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002072 break;
2073 case Continue_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002074 result = PyType_GenericNew(Continue_type, NULL, NULL);
2075 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002076 break;
2077 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002078
2079 return result;
2080failed:
2081 Py_XDECREF(value);
2082 Py_XDECREF(result);
2083 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002084}
2085
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002086PyObject*
2087ast2obj_expr(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002088{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002089 expr_ty o = (expr_ty)_o;
2090 PyObject *result = NULL, *value = NULL;
2091 if (!o) {
2092 Py_INCREF(Py_None);
2093 return Py_None;
2094 }
2095
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002096 switch (o->kind) {
2097 case BoolOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002098 result = PyType_GenericNew(BoolOp_type, NULL, NULL);
2099 if (!result) goto failed;
2100 value = ast2obj_boolop(o->v.BoolOp.op);
2101 if (!value) goto failed;
2102 if (PyObject_SetAttrString(result, "op", value) == -1)
2103 goto failed;
2104 Py_DECREF(value);
2105 value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
2106 if (!value) goto failed;
2107 if (PyObject_SetAttrString(result, "values", value) == -1)
2108 goto failed;
2109 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002110 break;
2111 case BinOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002112 result = PyType_GenericNew(BinOp_type, NULL, NULL);
2113 if (!result) goto failed;
2114 value = ast2obj_expr(o->v.BinOp.left);
2115 if (!value) goto failed;
2116 if (PyObject_SetAttrString(result, "left", value) == -1)
2117 goto failed;
2118 Py_DECREF(value);
2119 value = ast2obj_operator(o->v.BinOp.op);
2120 if (!value) goto failed;
2121 if (PyObject_SetAttrString(result, "op", value) == -1)
2122 goto failed;
2123 Py_DECREF(value);
2124 value = ast2obj_expr(o->v.BinOp.right);
2125 if (!value) goto failed;
2126 if (PyObject_SetAttrString(result, "right", value) == -1)
2127 goto failed;
2128 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002129 break;
2130 case UnaryOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002131 result = PyType_GenericNew(UnaryOp_type, NULL, NULL);
2132 if (!result) goto failed;
2133 value = ast2obj_unaryop(o->v.UnaryOp.op);
2134 if (!value) goto failed;
2135 if (PyObject_SetAttrString(result, "op", value) == -1)
2136 goto failed;
2137 Py_DECREF(value);
2138 value = ast2obj_expr(o->v.UnaryOp.operand);
2139 if (!value) goto failed;
2140 if (PyObject_SetAttrString(result, "operand", value) == -1)
2141 goto failed;
2142 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002143 break;
2144 case Lambda_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002145 result = PyType_GenericNew(Lambda_type, NULL, NULL);
2146 if (!result) goto failed;
2147 value = ast2obj_arguments(o->v.Lambda.args);
2148 if (!value) goto failed;
2149 if (PyObject_SetAttrString(result, "args", value) == -1)
2150 goto failed;
2151 Py_DECREF(value);
2152 value = ast2obj_expr(o->v.Lambda.body);
2153 if (!value) goto failed;
2154 if (PyObject_SetAttrString(result, "body", value) == -1)
2155 goto failed;
2156 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002157 break;
2158 case Dict_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002159 result = PyType_GenericNew(Dict_type, NULL, NULL);
2160 if (!result) goto failed;
2161 value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
2162 if (!value) goto failed;
2163 if (PyObject_SetAttrString(result, "keys", value) == -1)
2164 goto failed;
2165 Py_DECREF(value);
2166 value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
2167 if (!value) goto failed;
2168 if (PyObject_SetAttrString(result, "values", value) == -1)
2169 goto failed;
2170 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002171 break;
2172 case ListComp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002173 result = PyType_GenericNew(ListComp_type, NULL, NULL);
2174 if (!result) goto failed;
2175 value = ast2obj_expr(o->v.ListComp.elt);
2176 if (!value) goto failed;
2177 if (PyObject_SetAttrString(result, "elt", value) == -1)
2178 goto failed;
2179 Py_DECREF(value);
2180 value = ast2obj_list(o->v.ListComp.generators,
2181 ast2obj_comprehension);
2182 if (!value) goto failed;
2183 if (PyObject_SetAttrString(result, "generators", value) == -1)
2184 goto failed;
2185 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002186 break;
2187 case GeneratorExp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002188 result = PyType_GenericNew(GeneratorExp_type, NULL, NULL);
2189 if (!result) goto failed;
2190 value = ast2obj_expr(o->v.GeneratorExp.elt);
2191 if (!value) goto failed;
2192 if (PyObject_SetAttrString(result, "elt", value) == -1)
2193 goto failed;
2194 Py_DECREF(value);
2195 value = ast2obj_list(o->v.GeneratorExp.generators,
2196 ast2obj_comprehension);
2197 if (!value) goto failed;
2198 if (PyObject_SetAttrString(result, "generators", value) == -1)
2199 goto failed;
2200 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002201 break;
2202 case Yield_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002203 result = PyType_GenericNew(Yield_type, NULL, NULL);
2204 if (!result) goto failed;
2205 value = ast2obj_expr(o->v.Yield.value);
2206 if (!value) goto failed;
2207 if (PyObject_SetAttrString(result, "value", value) == -1)
2208 goto failed;
2209 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002210 break;
2211 case Compare_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002212 result = PyType_GenericNew(Compare_type, NULL, NULL);
2213 if (!result) goto failed;
2214 value = ast2obj_expr(o->v.Compare.left);
2215 if (!value) goto failed;
2216 if (PyObject_SetAttrString(result, "left", value) == -1)
2217 goto failed;
2218 Py_DECREF(value);
2219 value = ast2obj_list(o->v.Compare.ops,
2220 (PyObject*(*)(void*))ast2obj_cmpop);
2221 if (!value) goto failed;
2222 if (PyObject_SetAttrString(result, "ops", value) == -1)
2223 goto failed;
2224 Py_DECREF(value);
2225 value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
2226 if (!value) goto failed;
2227 if (PyObject_SetAttrString(result, "comparators", value) == -1)
2228 goto failed;
2229 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002230 break;
2231 case Call_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002232 result = PyType_GenericNew(Call_type, NULL, NULL);
2233 if (!result) goto failed;
2234 value = ast2obj_expr(o->v.Call.func);
2235 if (!value) goto failed;
2236 if (PyObject_SetAttrString(result, "func", value) == -1)
2237 goto failed;
2238 Py_DECREF(value);
2239 value = ast2obj_list(o->v.Call.args, ast2obj_expr);
2240 if (!value) goto failed;
2241 if (PyObject_SetAttrString(result, "args", value) == -1)
2242 goto failed;
2243 Py_DECREF(value);
2244 value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
2245 if (!value) goto failed;
2246 if (PyObject_SetAttrString(result, "keywords", value) == -1)
2247 goto failed;
2248 Py_DECREF(value);
2249 value = ast2obj_expr(o->v.Call.starargs);
2250 if (!value) goto failed;
2251 if (PyObject_SetAttrString(result, "starargs", value) == -1)
2252 goto failed;
2253 Py_DECREF(value);
2254 value = ast2obj_expr(o->v.Call.kwargs);
2255 if (!value) goto failed;
2256 if (PyObject_SetAttrString(result, "kwargs", value) == -1)
2257 goto failed;
2258 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002259 break;
2260 case Repr_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002261 result = PyType_GenericNew(Repr_type, NULL, NULL);
2262 if (!result) goto failed;
2263 value = ast2obj_expr(o->v.Repr.value);
2264 if (!value) goto failed;
2265 if (PyObject_SetAttrString(result, "value", value) == -1)
2266 goto failed;
2267 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002268 break;
2269 case Num_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002270 result = PyType_GenericNew(Num_type, NULL, NULL);
2271 if (!result) goto failed;
2272 value = ast2obj_object(o->v.Num.n);
2273 if (!value) goto failed;
2274 if (PyObject_SetAttrString(result, "n", value) == -1)
2275 goto failed;
2276 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002277 break;
2278 case Str_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002279 result = PyType_GenericNew(Str_type, NULL, NULL);
2280 if (!result) goto failed;
2281 value = ast2obj_string(o->v.Str.s);
2282 if (!value) goto failed;
2283 if (PyObject_SetAttrString(result, "s", value) == -1)
2284 goto failed;
2285 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002286 break;
2287 case Attribute_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002288 result = PyType_GenericNew(Attribute_type, NULL, NULL);
2289 if (!result) goto failed;
2290 value = ast2obj_expr(o->v.Attribute.value);
2291 if (!value) goto failed;
2292 if (PyObject_SetAttrString(result, "value", value) == -1)
2293 goto failed;
2294 Py_DECREF(value);
2295 value = ast2obj_identifier(o->v.Attribute.attr);
2296 if (!value) goto failed;
2297 if (PyObject_SetAttrString(result, "attr", value) == -1)
2298 goto failed;
2299 Py_DECREF(value);
2300 value = ast2obj_expr_context(o->v.Attribute.ctx);
2301 if (!value) goto failed;
2302 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2303 goto failed;
2304 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002305 break;
2306 case Subscript_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002307 result = PyType_GenericNew(Subscript_type, NULL, NULL);
2308 if (!result) goto failed;
2309 value = ast2obj_expr(o->v.Subscript.value);
2310 if (!value) goto failed;
2311 if (PyObject_SetAttrString(result, "value", value) == -1)
2312 goto failed;
2313 Py_DECREF(value);
2314 value = ast2obj_slice(o->v.Subscript.slice);
2315 if (!value) goto failed;
2316 if (PyObject_SetAttrString(result, "slice", value) == -1)
2317 goto failed;
2318 Py_DECREF(value);
2319 value = ast2obj_expr_context(o->v.Subscript.ctx);
2320 if (!value) goto failed;
2321 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2322 goto failed;
2323 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002324 break;
2325 case Name_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002326 result = PyType_GenericNew(Name_type, NULL, NULL);
2327 if (!result) goto failed;
2328 value = ast2obj_identifier(o->v.Name.id);
2329 if (!value) goto failed;
2330 if (PyObject_SetAttrString(result, "id", value) == -1)
2331 goto failed;
2332 Py_DECREF(value);
2333 value = ast2obj_expr_context(o->v.Name.ctx);
2334 if (!value) goto failed;
2335 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2336 goto failed;
2337 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002338 break;
2339 case List_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002340 result = PyType_GenericNew(List_type, NULL, NULL);
2341 if (!result) goto failed;
2342 value = ast2obj_list(o->v.List.elts, ast2obj_expr);
2343 if (!value) goto failed;
2344 if (PyObject_SetAttrString(result, "elts", value) == -1)
2345 goto failed;
2346 Py_DECREF(value);
2347 value = ast2obj_expr_context(o->v.List.ctx);
2348 if (!value) goto failed;
2349 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2350 goto failed;
2351 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002352 break;
2353 case Tuple_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002354 result = PyType_GenericNew(Tuple_type, NULL, NULL);
2355 if (!result) goto failed;
2356 value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
2357 if (!value) goto failed;
2358 if (PyObject_SetAttrString(result, "elts", value) == -1)
2359 goto failed;
2360 Py_DECREF(value);
2361 value = ast2obj_expr_context(o->v.Tuple.ctx);
2362 if (!value) goto failed;
2363 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2364 goto failed;
2365 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002366 break;
2367 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002368
2369 return result;
2370failed:
2371 Py_XDECREF(value);
2372 Py_XDECREF(result);
2373 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002374}
2375
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002376PyObject* ast2obj_expr_context(expr_context_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002377{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002378 switch(o) {
2379 case Load:
2380 Py_INCREF(Load_singleton);
2381 return Load_singleton;
2382 case Store:
2383 Py_INCREF(Store_singleton);
2384 return Store_singleton;
2385 case Del:
2386 Py_INCREF(Del_singleton);
2387 return Del_singleton;
2388 case AugLoad:
2389 Py_INCREF(AugLoad_singleton);
2390 return AugLoad_singleton;
2391 case AugStore:
2392 Py_INCREF(AugStore_singleton);
2393 return AugStore_singleton;
2394 case Param:
2395 Py_INCREF(Param_singleton);
2396 return Param_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002397 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002398 return NULL; /* cannot happen */
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002399}
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002400PyObject*
2401ast2obj_slice(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002402{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002403 slice_ty o = (slice_ty)_o;
2404 PyObject *result = NULL, *value = NULL;
2405 if (!o) {
2406 Py_INCREF(Py_None);
2407 return Py_None;
2408 }
2409
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002410 switch (o->kind) {
2411 case Ellipsis_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002412 result = PyType_GenericNew(Ellipsis_type, NULL, NULL);
2413 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002414 break;
2415 case Slice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002416 result = PyType_GenericNew(Slice_type, NULL, NULL);
2417 if (!result) goto failed;
2418 value = ast2obj_expr(o->v.Slice.lower);
2419 if (!value) goto failed;
2420 if (PyObject_SetAttrString(result, "lower", value) == -1)
2421 goto failed;
2422 Py_DECREF(value);
2423 value = ast2obj_expr(o->v.Slice.upper);
2424 if (!value) goto failed;
2425 if (PyObject_SetAttrString(result, "upper", value) == -1)
2426 goto failed;
2427 Py_DECREF(value);
2428 value = ast2obj_expr(o->v.Slice.step);
2429 if (!value) goto failed;
2430 if (PyObject_SetAttrString(result, "step", value) == -1)
2431 goto failed;
2432 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002433 break;
2434 case ExtSlice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002435 result = PyType_GenericNew(ExtSlice_type, NULL, NULL);
2436 if (!result) goto failed;
2437 value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice);
2438 if (!value) goto failed;
2439 if (PyObject_SetAttrString(result, "dims", value) == -1)
2440 goto failed;
2441 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002442 break;
2443 case Index_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002444 result = PyType_GenericNew(Index_type, NULL, NULL);
2445 if (!result) goto failed;
2446 value = ast2obj_expr(o->v.Index.value);
2447 if (!value) goto failed;
2448 if (PyObject_SetAttrString(result, "value", value) == -1)
2449 goto failed;
2450 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002451 break;
2452 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002453
2454 return result;
2455failed:
2456 Py_XDECREF(value);
2457 Py_XDECREF(result);
2458 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002459}
2460
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002461PyObject* ast2obj_boolop(boolop_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002462{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002463 switch(o) {
2464 case And:
2465 Py_INCREF(And_singleton);
2466 return And_singleton;
2467 case Or:
2468 Py_INCREF(Or_singleton);
2469 return Or_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002470 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002471 return NULL; /* cannot happen */
2472}
2473PyObject* ast2obj_operator(operator_ty o)
2474{
2475 switch(o) {
2476 case Add:
2477 Py_INCREF(Add_singleton);
2478 return Add_singleton;
2479 case Sub:
2480 Py_INCREF(Sub_singleton);
2481 return Sub_singleton;
2482 case Mult:
2483 Py_INCREF(Mult_singleton);
2484 return Mult_singleton;
2485 case Div:
2486 Py_INCREF(Div_singleton);
2487 return Div_singleton;
2488 case Mod:
2489 Py_INCREF(Mod_singleton);
2490 return Mod_singleton;
2491 case Pow:
2492 Py_INCREF(Pow_singleton);
2493 return Pow_singleton;
2494 case LShift:
2495 Py_INCREF(LShift_singleton);
2496 return LShift_singleton;
2497 case RShift:
2498 Py_INCREF(RShift_singleton);
2499 return RShift_singleton;
2500 case BitOr:
2501 Py_INCREF(BitOr_singleton);
2502 return BitOr_singleton;
2503 case BitXor:
2504 Py_INCREF(BitXor_singleton);
2505 return BitXor_singleton;
2506 case BitAnd:
2507 Py_INCREF(BitAnd_singleton);
2508 return BitAnd_singleton;
2509 case FloorDiv:
2510 Py_INCREF(FloorDiv_singleton);
2511 return FloorDiv_singleton;
2512 }
2513 return NULL; /* cannot happen */
2514}
2515PyObject* ast2obj_unaryop(unaryop_ty o)
2516{
2517 switch(o) {
2518 case Invert:
2519 Py_INCREF(Invert_singleton);
2520 return Invert_singleton;
2521 case Not:
2522 Py_INCREF(Not_singleton);
2523 return Not_singleton;
2524 case UAdd:
2525 Py_INCREF(UAdd_singleton);
2526 return UAdd_singleton;
2527 case USub:
2528 Py_INCREF(USub_singleton);
2529 return USub_singleton;
2530 }
2531 return NULL; /* cannot happen */
2532}
2533PyObject* ast2obj_cmpop(cmpop_ty o)
2534{
2535 switch(o) {
2536 case Eq:
2537 Py_INCREF(Eq_singleton);
2538 return Eq_singleton;
2539 case NotEq:
2540 Py_INCREF(NotEq_singleton);
2541 return NotEq_singleton;
2542 case Lt:
2543 Py_INCREF(Lt_singleton);
2544 return Lt_singleton;
2545 case LtE:
2546 Py_INCREF(LtE_singleton);
2547 return LtE_singleton;
2548 case Gt:
2549 Py_INCREF(Gt_singleton);
2550 return Gt_singleton;
2551 case GtE:
2552 Py_INCREF(GtE_singleton);
2553 return GtE_singleton;
2554 case Is:
2555 Py_INCREF(Is_singleton);
2556 return Is_singleton;
2557 case IsNot:
2558 Py_INCREF(IsNot_singleton);
2559 return IsNot_singleton;
2560 case In:
2561 Py_INCREF(In_singleton);
2562 return In_singleton;
2563 case NotIn:
2564 Py_INCREF(NotIn_singleton);
2565 return NotIn_singleton;
2566 }
2567 return NULL; /* cannot happen */
2568}
2569PyObject*
2570ast2obj_comprehension(void* _o)
2571{
2572 comprehension_ty o = (comprehension_ty)_o;
2573 PyObject *result = NULL, *value = NULL;
2574 if (!o) {
2575 Py_INCREF(Py_None);
2576 return Py_None;
2577 }
2578
2579 result = PyType_GenericNew(comprehension_type, NULL, NULL);
2580 if (!result) return NULL;
2581 value = ast2obj_expr(o->target);
2582 if (!value) goto failed;
2583 if (PyObject_SetAttrString(result, "target", value) == -1)
2584 goto failed;
2585 Py_DECREF(value);
2586 value = ast2obj_expr(o->iter);
2587 if (!value) goto failed;
2588 if (PyObject_SetAttrString(result, "iter", value) == -1)
2589 goto failed;
2590 Py_DECREF(value);
2591 value = ast2obj_list(o->ifs, ast2obj_expr);
2592 if (!value) goto failed;
2593 if (PyObject_SetAttrString(result, "ifs", value) == -1)
2594 goto failed;
2595 Py_DECREF(value);
2596
2597 return result;
2598failed:
2599 Py_XDECREF(value);
2600 Py_XDECREF(result);
2601 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002602}
2603
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002604PyObject*
2605ast2obj_excepthandler(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002606{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002607 excepthandler_ty o = (excepthandler_ty)_o;
2608 PyObject *result = NULL, *value = NULL;
2609 if (!o) {
2610 Py_INCREF(Py_None);
2611 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002612 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002613
2614 result = PyType_GenericNew(excepthandler_type, NULL, NULL);
2615 if (!result) return NULL;
2616 value = ast2obj_expr(o->type);
2617 if (!value) goto failed;
2618 if (PyObject_SetAttrString(result, "type", value) == -1)
2619 goto failed;
2620 Py_DECREF(value);
2621 value = ast2obj_expr(o->name);
2622 if (!value) goto failed;
2623 if (PyObject_SetAttrString(result, "name", value) == -1)
2624 goto failed;
2625 Py_DECREF(value);
2626 value = ast2obj_list(o->body, ast2obj_stmt);
2627 if (!value) goto failed;
2628 if (PyObject_SetAttrString(result, "body", value) == -1)
2629 goto failed;
2630 Py_DECREF(value);
2631
2632 return result;
2633failed:
2634 Py_XDECREF(value);
2635 Py_XDECREF(result);
2636 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002637}
2638
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002639PyObject*
2640ast2obj_arguments(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002641{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002642 arguments_ty o = (arguments_ty)_o;
2643 PyObject *result = NULL, *value = NULL;
2644 if (!o) {
2645 Py_INCREF(Py_None);
2646 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002647 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002648
2649 result = PyType_GenericNew(arguments_type, NULL, NULL);
2650 if (!result) return NULL;
2651 value = ast2obj_list(o->args, ast2obj_expr);
2652 if (!value) goto failed;
2653 if (PyObject_SetAttrString(result, "args", value) == -1)
2654 goto failed;
2655 Py_DECREF(value);
2656 value = ast2obj_identifier(o->vararg);
2657 if (!value) goto failed;
2658 if (PyObject_SetAttrString(result, "vararg", value) == -1)
2659 goto failed;
2660 Py_DECREF(value);
2661 value = ast2obj_identifier(o->kwarg);
2662 if (!value) goto failed;
2663 if (PyObject_SetAttrString(result, "kwarg", value) == -1)
2664 goto failed;
2665 Py_DECREF(value);
2666 value = ast2obj_list(o->defaults, ast2obj_expr);
2667 if (!value) goto failed;
2668 if (PyObject_SetAttrString(result, "defaults", value) == -1)
2669 goto failed;
2670 Py_DECREF(value);
2671
2672 return result;
2673failed:
2674 Py_XDECREF(value);
2675 Py_XDECREF(result);
2676 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002677}
2678
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002679PyObject*
2680ast2obj_keyword(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002681{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002682 keyword_ty o = (keyword_ty)_o;
2683 PyObject *result = NULL, *value = NULL;
2684 if (!o) {
2685 Py_INCREF(Py_None);
2686 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002687 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002688
2689 result = PyType_GenericNew(keyword_type, NULL, NULL);
2690 if (!result) return NULL;
2691 value = ast2obj_identifier(o->arg);
2692 if (!value) goto failed;
2693 if (PyObject_SetAttrString(result, "arg", value) == -1)
2694 goto failed;
2695 Py_DECREF(value);
2696 value = ast2obj_expr(o->value);
2697 if (!value) goto failed;
2698 if (PyObject_SetAttrString(result, "value", value) == -1)
2699 goto failed;
2700 Py_DECREF(value);
2701
2702 return result;
2703failed:
2704 Py_XDECREF(value);
2705 Py_XDECREF(result);
2706 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002707}
2708
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002709PyObject*
2710ast2obj_alias(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002711{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002712 alias_ty o = (alias_ty)_o;
2713 PyObject *result = NULL, *value = NULL;
2714 if (!o) {
2715 Py_INCREF(Py_None);
2716 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002717 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002718
2719 result = PyType_GenericNew(alias_type, NULL, NULL);
2720 if (!result) return NULL;
2721 value = ast2obj_identifier(o->name);
2722 if (!value) goto failed;
2723 if (PyObject_SetAttrString(result, "name", value) == -1)
2724 goto failed;
2725 Py_DECREF(value);
2726 value = ast2obj_identifier(o->asname);
2727 if (!value) goto failed;
2728 if (PyObject_SetAttrString(result, "asname", value) == -1)
2729 goto failed;
2730 Py_DECREF(value);
2731
2732 return result;
2733failed:
2734 Py_XDECREF(value);
2735 Py_XDECREF(result);
2736 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002737}
2738
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002739
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002740
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002741PyObject* PyAST_mod2obj(mod_ty t)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002742{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002743 init_types();
2744 return ast2obj_mod(t);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002745}
2746
Neal Norwitz7b5a6042005-11-13 19:14:20 +00002747