blob: c4861c3ae1100177fbb8de8c7ba8511bab382d57 [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öwis577b5b92006-02-27 15:23:19 +00006PyTypeObject* AST_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00007PyTypeObject *mod_type;
8static PyObject* ast2obj_mod(void*);
9PyTypeObject *Module_type;
10char *Module_fields[]={
11 "body",
12};
13PyTypeObject *Interactive_type;
14char *Interactive_fields[]={
15 "body",
16};
17PyTypeObject *Expression_type;
18char *Expression_fields[]={
19 "body",
20};
21PyTypeObject *Suite_type;
22char *Suite_fields[]={
23 "body",
24};
25PyTypeObject *stmt_type;
Martin v. Löwis577b5b92006-02-27 15:23:19 +000026char *stmt_attributes[] = {
27 "lineno",
28};
Martin v. Löwisbd260da2006-02-26 19:42:26 +000029static PyObject* ast2obj_stmt(void*);
30PyTypeObject *FunctionDef_type;
31char *FunctionDef_fields[]={
32 "name",
33 "args",
34 "body",
35 "decorators",
36};
37PyTypeObject *ClassDef_type;
38char *ClassDef_fields[]={
39 "name",
40 "bases",
41 "body",
42};
43PyTypeObject *Return_type;
44char *Return_fields[]={
45 "value",
46};
47PyTypeObject *Delete_type;
48char *Delete_fields[]={
49 "targets",
50};
51PyTypeObject *Assign_type;
52char *Assign_fields[]={
53 "targets",
54 "value",
55};
56PyTypeObject *AugAssign_type;
57char *AugAssign_fields[]={
58 "target",
59 "op",
60 "value",
61};
62PyTypeObject *Print_type;
63char *Print_fields[]={
64 "dest",
65 "values",
66 "nl",
67};
68PyTypeObject *For_type;
69char *For_fields[]={
70 "target",
71 "iter",
72 "body",
73 "orelse",
74};
75PyTypeObject *While_type;
76char *While_fields[]={
77 "test",
78 "body",
79 "orelse",
80};
81PyTypeObject *If_type;
82char *If_fields[]={
83 "test",
84 "body",
85 "orelse",
86};
Guido van Rossumc2e20742006-02-27 22:32:47 +000087PyTypeObject *With_type;
88char *With_fields[]={
89 "context_expr",
90 "optional_vars",
91 "body",
92};
Martin v. Löwisbd260da2006-02-26 19:42:26 +000093PyTypeObject *Raise_type;
94char *Raise_fields[]={
95 "type",
96 "inst",
97 "tback",
98};
99PyTypeObject *TryExcept_type;
100char *TryExcept_fields[]={
101 "body",
102 "handlers",
103 "orelse",
104};
105PyTypeObject *TryFinally_type;
106char *TryFinally_fields[]={
107 "body",
108 "finalbody",
109};
110PyTypeObject *Assert_type;
111char *Assert_fields[]={
112 "test",
113 "msg",
114};
115PyTypeObject *Import_type;
116char *Import_fields[]={
117 "names",
118};
119PyTypeObject *ImportFrom_type;
120char *ImportFrom_fields[]={
121 "module",
122 "names",
Thomas Woutersf7f438b2006-02-28 16:09:29 +0000123 "level",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000124};
125PyTypeObject *Exec_type;
126char *Exec_fields[]={
127 "body",
128 "globals",
129 "locals",
130};
131PyTypeObject *Global_type;
132char *Global_fields[]={
133 "names",
134};
135PyTypeObject *Expr_type;
136char *Expr_fields[]={
137 "value",
138};
139PyTypeObject *Pass_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000140PyTypeObject *Break_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000141PyTypeObject *Continue_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000142PyTypeObject *expr_type;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000143char *expr_attributes[] = {
144 "lineno",
145};
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000146static PyObject* ast2obj_expr(void*);
147PyTypeObject *BoolOp_type;
148char *BoolOp_fields[]={
149 "op",
150 "values",
151};
152PyTypeObject *BinOp_type;
153char *BinOp_fields[]={
154 "left",
155 "op",
156 "right",
157};
158PyTypeObject *UnaryOp_type;
159char *UnaryOp_fields[]={
160 "op",
161 "operand",
162};
163PyTypeObject *Lambda_type;
164char *Lambda_fields[]={
165 "args",
166 "body",
167};
Thomas Woutersdca3b9c2006-02-27 00:24:13 +0000168PyTypeObject *IfExp_type;
169char *IfExp_fields[]={
170 "test",
171 "body",
172 "orelse",
173};
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000174PyTypeObject *Dict_type;
175char *Dict_fields[]={
176 "keys",
177 "values",
178};
179PyTypeObject *ListComp_type;
180char *ListComp_fields[]={
181 "elt",
182 "generators",
183};
184PyTypeObject *GeneratorExp_type;
185char *GeneratorExp_fields[]={
186 "elt",
187 "generators",
188};
189PyTypeObject *Yield_type;
190char *Yield_fields[]={
191 "value",
192};
193PyTypeObject *Compare_type;
194char *Compare_fields[]={
195 "left",
196 "ops",
197 "comparators",
198};
199PyTypeObject *Call_type;
200char *Call_fields[]={
201 "func",
202 "args",
203 "keywords",
204 "starargs",
205 "kwargs",
206};
207PyTypeObject *Repr_type;
208char *Repr_fields[]={
209 "value",
210};
211PyTypeObject *Num_type;
212char *Num_fields[]={
213 "n",
214};
215PyTypeObject *Str_type;
216char *Str_fields[]={
217 "s",
218};
219PyTypeObject *Attribute_type;
220char *Attribute_fields[]={
221 "value",
222 "attr",
223 "ctx",
224};
225PyTypeObject *Subscript_type;
226char *Subscript_fields[]={
227 "value",
228 "slice",
229 "ctx",
230};
231PyTypeObject *Name_type;
232char *Name_fields[]={
233 "id",
234 "ctx",
235};
236PyTypeObject *List_type;
237char *List_fields[]={
238 "elts",
239 "ctx",
240};
241PyTypeObject *Tuple_type;
242char *Tuple_fields[]={
243 "elts",
244 "ctx",
245};
246PyTypeObject *expr_context_type;
247static PyObject *Load_singleton, *Store_singleton, *Del_singleton,
248*AugLoad_singleton, *AugStore_singleton, *Param_singleton;
249static PyObject* ast2obj_expr_context(expr_context_ty);
250PyTypeObject *Load_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000251PyTypeObject *Store_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000252PyTypeObject *Del_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000253PyTypeObject *AugLoad_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000254PyTypeObject *AugStore_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000255PyTypeObject *Param_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000256PyTypeObject *slice_type;
257static PyObject* ast2obj_slice(void*);
258PyTypeObject *Ellipsis_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000259PyTypeObject *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;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000277PyTypeObject *Or_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000278PyTypeObject *operator_type;
279static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton,
280*Div_singleton, *Mod_singleton, *Pow_singleton, *LShift_singleton,
281*RShift_singleton, *BitOr_singleton, *BitXor_singleton, *BitAnd_singleton,
282*FloorDiv_singleton;
283static PyObject* ast2obj_operator(operator_ty);
284PyTypeObject *Add_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000285PyTypeObject *Sub_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000286PyTypeObject *Mult_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000287PyTypeObject *Div_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000288PyTypeObject *Mod_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000289PyTypeObject *Pow_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000290PyTypeObject *LShift_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000291PyTypeObject *RShift_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000292PyTypeObject *BitOr_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000293PyTypeObject *BitXor_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000294PyTypeObject *BitAnd_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000295PyTypeObject *FloorDiv_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000296PyTypeObject *unaryop_type;
297static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton,
298*USub_singleton;
299static PyObject* ast2obj_unaryop(unaryop_ty);
300PyTypeObject *Invert_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000301PyTypeObject *Not_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000302PyTypeObject *UAdd_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000303PyTypeObject *USub_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000304PyTypeObject *cmpop_type;
305static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton,
306*Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton,
307*NotIn_singleton;
308static PyObject* ast2obj_cmpop(cmpop_ty);
309PyTypeObject *Eq_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000310PyTypeObject *NotEq_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000311PyTypeObject *Lt_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000312PyTypeObject *LtE_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000313PyTypeObject *Gt_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000314PyTypeObject *GtE_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000315PyTypeObject *Is_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000316PyTypeObject *IsNot_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000317PyTypeObject *In_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000318PyTypeObject *NotIn_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000319PyTypeObject *comprehension_type;
320static PyObject* ast2obj_comprehension(void*);
321char *comprehension_fields[]={
322 "target",
323 "iter",
324 "ifs",
325};
326PyTypeObject *excepthandler_type;
327static PyObject* ast2obj_excepthandler(void*);
328char *excepthandler_fields[]={
329 "type",
330 "name",
331 "body",
332};
333PyTypeObject *arguments_type;
334static PyObject* ast2obj_arguments(void*);
335char *arguments_fields[]={
336 "args",
337 "vararg",
338 "kwarg",
339 "defaults",
340};
341PyTypeObject *keyword_type;
342static PyObject* ast2obj_keyword(void*);
343char *keyword_fields[]={
344 "arg",
345 "value",
346};
347PyTypeObject *alias_type;
348static PyObject* ast2obj_alias(void*);
349char *alias_fields[]={
350 "name",
351 "asname",
352};
353
354
355static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields)
356{
357 PyObject *fnames, *result;
358 int i;
359 if (num_fields) {
360 fnames = PyTuple_New(num_fields);
361 if (!fnames) return NULL;
362 } else {
363 fnames = Py_None;
364 Py_INCREF(Py_None);
365 }
366 for(i=0; i < num_fields; i++) {
367 PyObject *field = PyString_FromString(fields[i]);
368 if (!field) {
369 Py_DECREF(fnames);
370 return NULL;
371 }
372 PyTuple_SET_ITEM(fnames, i, field);
373 }
Thomas Wouters34aa7ba2006-02-28 19:02:24 +0000374 result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}",
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000375 type, base, "_fields", fnames, "__module__", "_ast");
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000376 Py_DECREF(fnames);
377 return (PyTypeObject*)result;
378}
379
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000380static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)
381{
382 int i;
383 PyObject *s, *l = PyList_New(num_fields);
384 if (!l) return 0;
385 for(i=0; i < num_fields; i++) {
386 s = PyString_FromString(attrs[i]);
387 if (!s) {
388 Py_DECREF(l);
389 return 0;
390 }
391 PyList_SET_ITEM(l, i, s);
392 }
393 return PyObject_SetAttrString((PyObject*)type, "_attributes", l) >=0;
394}
395
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000396static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
397{
398 int i, n = asdl_seq_LEN(seq);
399 PyObject *result = PyList_New(n);
400 PyObject *value;
401 if (!result)
402 return NULL;
403 for (i = 0; i < n; i++) {
404 value = func(asdl_seq_GET(seq, i));
405 if (!value) {
406 Py_DECREF(result);
407 return NULL;
408 }
409 PyList_SET_ITEM(result, i, value);
410 }
411 return result;
412}
413
414static PyObject* ast2obj_object(void *o)
415{
416 if (!o)
417 o = Py_None;
418 Py_INCREF((PyObject*)o);
419 return (PyObject*)o;
420}
421#define ast2obj_identifier ast2obj_object
422#define ast2obj_string ast2obj_object
423static PyObject* ast2obj_bool(bool b)
424{
425 return PyBool_FromLong(b);
426}
427
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000428static PyObject* ast2obj_int(bool b)
429{
430 return PyInt_FromLong(b);
431}
432
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000433static int initialized;
434static int init_types(void)
435{
436 if (initialized) return 1;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000437 AST_type = make_type("AST", &PyBaseObject_Type, NULL, 0);
438 mod_type = make_type("mod", AST_type, NULL, 0);
439 if (!mod_type) return 0;
440 if (!add_attributes(mod_type, NULL, 0)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000441 Module_type = make_type("Module", mod_type, Module_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000442 if (!Module_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000443 Interactive_type = make_type("Interactive", mod_type,
444 Interactive_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000445 if (!Interactive_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000446 Expression_type = make_type("Expression", mod_type, Expression_fields,
447 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000448 if (!Expression_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000449 Suite_type = make_type("Suite", mod_type, Suite_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000450 if (!Suite_type) return 0;
451 stmt_type = make_type("stmt", AST_type, NULL, 0);
452 if (!stmt_type) return 0;
453 if (!add_attributes(stmt_type, stmt_attributes, 1)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000454 FunctionDef_type = make_type("FunctionDef", stmt_type,
455 FunctionDef_fields, 4);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000456 if (!FunctionDef_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000457 ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000458 if (!ClassDef_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000459 Return_type = make_type("Return", stmt_type, Return_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000460 if (!Return_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000461 Delete_type = make_type("Delete", stmt_type, Delete_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000462 if (!Delete_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000463 Assign_type = make_type("Assign", stmt_type, Assign_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000464 if (!Assign_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000465 AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000466 if (!AugAssign_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000467 Print_type = make_type("Print", stmt_type, Print_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000468 if (!Print_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000469 For_type = make_type("For", stmt_type, For_fields, 4);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000470 if (!For_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000471 While_type = make_type("While", stmt_type, While_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000472 if (!While_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000473 If_type = make_type("If", stmt_type, If_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000474 if (!If_type) return 0;
Guido van Rossumc2e20742006-02-27 22:32:47 +0000475 With_type = make_type("With", stmt_type, With_fields, 3);
476 if (!With_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000477 Raise_type = make_type("Raise", stmt_type, Raise_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000478 if (!Raise_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000479 TryExcept_type = make_type("TryExcept", stmt_type, TryExcept_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000480 if (!TryExcept_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000481 TryFinally_type = make_type("TryFinally", stmt_type, TryFinally_fields,
482 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000483 if (!TryFinally_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000484 Assert_type = make_type("Assert", stmt_type, Assert_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000485 if (!Assert_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000486 Import_type = make_type("Import", stmt_type, Import_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000487 if (!Import_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000488 ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields,
Thomas Woutersf7f438b2006-02-28 16:09:29 +0000489 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000490 if (!ImportFrom_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000491 Exec_type = make_type("Exec", stmt_type, Exec_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000492 if (!Exec_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000493 Global_type = make_type("Global", stmt_type, Global_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000494 if (!Global_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000495 Expr_type = make_type("Expr", stmt_type, Expr_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000496 if (!Expr_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000497 Pass_type = make_type("Pass", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000498 if (!Pass_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000499 Break_type = make_type("Break", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000500 if (!Break_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000501 Continue_type = make_type("Continue", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000502 if (!Continue_type) return 0;
503 expr_type = make_type("expr", AST_type, NULL, 0);
504 if (!expr_type) return 0;
505 if (!add_attributes(expr_type, expr_attributes, 1)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000506 BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000507 if (!BoolOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000508 BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000509 if (!BinOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000510 UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000511 if (!UnaryOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000512 Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000513 if (!Lambda_type) return 0;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +0000514 IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000515 if (!IfExp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000516 Dict_type = make_type("Dict", expr_type, Dict_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000517 if (!Dict_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000518 ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000519 if (!ListComp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000520 GeneratorExp_type = make_type("GeneratorExp", expr_type,
521 GeneratorExp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000522 if (!GeneratorExp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000523 Yield_type = make_type("Yield", expr_type, Yield_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000524 if (!Yield_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000525 Compare_type = make_type("Compare", expr_type, Compare_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000526 if (!Compare_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000527 Call_type = make_type("Call", expr_type, Call_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000528 if (!Call_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000529 Repr_type = make_type("Repr", expr_type, Repr_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000530 if (!Repr_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000531 Num_type = make_type("Num", expr_type, Num_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000532 if (!Num_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000533 Str_type = make_type("Str", expr_type, Str_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000534 if (!Str_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000535 Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000536 if (!Attribute_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000537 Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000538 if (!Subscript_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000539 Name_type = make_type("Name", expr_type, Name_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000540 if (!Name_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000541 List_type = make_type("List", expr_type, List_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000542 if (!List_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000543 Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000544 if (!Tuple_type) return 0;
545 expr_context_type = make_type("expr_context", AST_type, NULL, 0);
546 if (!expr_context_type) return 0;
547 if (!add_attributes(expr_context_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000548 Load_type = make_type("Load", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000549 if (!Load_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000550 Load_singleton = PyType_GenericNew(Load_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000551 if (!Load_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000552 Store_type = make_type("Store", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000553 if (!Store_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000554 Store_singleton = PyType_GenericNew(Store_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000555 if (!Store_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000556 Del_type = make_type("Del", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000557 if (!Del_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000558 Del_singleton = PyType_GenericNew(Del_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000559 if (!Del_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000560 AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000561 if (!AugLoad_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000562 AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000563 if (!AugLoad_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000564 AugStore_type = make_type("AugStore", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000565 if (!AugStore_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000566 AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000567 if (!AugStore_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000568 Param_type = make_type("Param", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000569 if (!Param_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000570 Param_singleton = PyType_GenericNew(Param_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000571 if (!Param_singleton) return 0;
572 slice_type = make_type("slice", AST_type, NULL, 0);
573 if (!slice_type) return 0;
574 if (!add_attributes(slice_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000575 Ellipsis_type = make_type("Ellipsis", slice_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000576 if (!Ellipsis_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000577 Slice_type = make_type("Slice", slice_type, Slice_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000578 if (!Slice_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000579 ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000580 if (!ExtSlice_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000581 Index_type = make_type("Index", slice_type, Index_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000582 if (!Index_type) return 0;
583 boolop_type = make_type("boolop", AST_type, NULL, 0);
584 if (!boolop_type) return 0;
585 if (!add_attributes(boolop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000586 And_type = make_type("And", boolop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000587 if (!And_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000588 And_singleton = PyType_GenericNew(And_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000589 if (!And_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000590 Or_type = make_type("Or", boolop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000591 if (!Or_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000592 Or_singleton = PyType_GenericNew(Or_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000593 if (!Or_singleton) return 0;
594 operator_type = make_type("operator", AST_type, NULL, 0);
595 if (!operator_type) return 0;
596 if (!add_attributes(operator_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000597 Add_type = make_type("Add", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000598 if (!Add_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000599 Add_singleton = PyType_GenericNew(Add_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000600 if (!Add_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000601 Sub_type = make_type("Sub", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000602 if (!Sub_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000603 Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000604 if (!Sub_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000605 Mult_type = make_type("Mult", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000606 if (!Mult_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000607 Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000608 if (!Mult_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000609 Div_type = make_type("Div", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000610 if (!Div_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000611 Div_singleton = PyType_GenericNew(Div_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000612 if (!Div_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000613 Mod_type = make_type("Mod", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000614 if (!Mod_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000615 Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000616 if (!Mod_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000617 Pow_type = make_type("Pow", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000618 if (!Pow_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000619 Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000620 if (!Pow_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000621 LShift_type = make_type("LShift", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000622 if (!LShift_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000623 LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000624 if (!LShift_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000625 RShift_type = make_type("RShift", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000626 if (!RShift_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000627 RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000628 if (!RShift_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000629 BitOr_type = make_type("BitOr", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000630 if (!BitOr_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000631 BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000632 if (!BitOr_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000633 BitXor_type = make_type("BitXor", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000634 if (!BitXor_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000635 BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000636 if (!BitXor_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000637 BitAnd_type = make_type("BitAnd", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000638 if (!BitAnd_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000639 BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000640 if (!BitAnd_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000641 FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000642 if (!FloorDiv_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000643 FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000644 if (!FloorDiv_singleton) return 0;
645 unaryop_type = make_type("unaryop", AST_type, NULL, 0);
646 if (!unaryop_type) return 0;
647 if (!add_attributes(unaryop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000648 Invert_type = make_type("Invert", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000649 if (!Invert_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000650 Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000651 if (!Invert_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000652 Not_type = make_type("Not", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000653 if (!Not_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000654 Not_singleton = PyType_GenericNew(Not_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000655 if (!Not_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000656 UAdd_type = make_type("UAdd", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000657 if (!UAdd_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000658 UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000659 if (!UAdd_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000660 USub_type = make_type("USub", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000661 if (!USub_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000662 USub_singleton = PyType_GenericNew(USub_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000663 if (!USub_singleton) return 0;
664 cmpop_type = make_type("cmpop", AST_type, NULL, 0);
665 if (!cmpop_type) return 0;
666 if (!add_attributes(cmpop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000667 Eq_type = make_type("Eq", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000668 if (!Eq_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000669 Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000670 if (!Eq_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000671 NotEq_type = make_type("NotEq", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000672 if (!NotEq_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000673 NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000674 if (!NotEq_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000675 Lt_type = make_type("Lt", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000676 if (!Lt_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000677 Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000678 if (!Lt_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000679 LtE_type = make_type("LtE", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000680 if (!LtE_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000681 LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000682 if (!LtE_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000683 Gt_type = make_type("Gt", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000684 if (!Gt_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000685 Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000686 if (!Gt_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000687 GtE_type = make_type("GtE", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000688 if (!GtE_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000689 GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000690 if (!GtE_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000691 Is_type = make_type("Is", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000692 if (!Is_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000693 Is_singleton = PyType_GenericNew(Is_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000694 if (!Is_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000695 IsNot_type = make_type("IsNot", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000696 if (!IsNot_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000697 IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000698 if (!IsNot_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000699 In_type = make_type("In", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000700 if (!In_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000701 In_singleton = PyType_GenericNew(In_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000702 if (!In_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000703 NotIn_type = make_type("NotIn", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000704 if (!NotIn_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000705 NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000706 if (!NotIn_singleton) return 0;
707 comprehension_type = make_type("comprehension", AST_type,
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000708 comprehension_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000709 if (!comprehension_type) return 0;
710 excepthandler_type = make_type("excepthandler", AST_type,
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000711 excepthandler_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000712 if (!excepthandler_type) return 0;
713 arguments_type = make_type("arguments", AST_type, arguments_fields, 4);
714 if (!arguments_type) return 0;
715 keyword_type = make_type("keyword", AST_type, keyword_fields, 2);
716 if (!keyword_type) return 0;
717 alias_type = make_type("alias", AST_type, alias_fields, 2);
718 if (!alias_type) return 0;
719 initialized = 1;
720 return 1;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000721}
Neal Norwitz7b5a6042005-11-13 19:14:20 +0000722
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000723mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000724Module(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000725{
726 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000727 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000728 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000729 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000730 return NULL;
731 }
732 p->kind = Module_kind;
733 p->v.Module.body = body;
734 return p;
735}
736
737mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000738Interactive(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000739{
740 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000741 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000742 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000743 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000744 return NULL;
745 }
746 p->kind = Interactive_kind;
747 p->v.Interactive.body = body;
748 return p;
749}
750
751mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000752Expression(expr_ty body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000753{
754 mod_ty p;
755 if (!body) {
756 PyErr_SetString(PyExc_ValueError,
757 "field body is required for Expression");
758 return NULL;
759 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000760 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000761 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000762 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000763 return NULL;
764 }
765 p->kind = Expression_kind;
766 p->v.Expression.body = body;
767 return p;
768}
769
770mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000771Suite(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000772{
773 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000774 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000775 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000776 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000777 return NULL;
778 }
779 p->kind = Suite_kind;
780 p->v.Suite.body = body;
781 return p;
782}
783
784stmt_ty
785FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000786 decorators, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000787{
788 stmt_ty p;
789 if (!name) {
790 PyErr_SetString(PyExc_ValueError,
791 "field name is required for FunctionDef");
792 return NULL;
793 }
794 if (!args) {
795 PyErr_SetString(PyExc_ValueError,
796 "field args is required for FunctionDef");
797 return NULL;
798 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000799 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000800 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000801 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000802 return NULL;
803 }
804 p->kind = FunctionDef_kind;
805 p->v.FunctionDef.name = name;
806 p->v.FunctionDef.args = args;
807 p->v.FunctionDef.body = body;
808 p->v.FunctionDef.decorators = decorators;
809 p->lineno = lineno;
810 return p;
811}
812
813stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000814ClassDef(identifier name, asdl_seq * bases, asdl_seq * body, int lineno,
815 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000816{
817 stmt_ty p;
818 if (!name) {
819 PyErr_SetString(PyExc_ValueError,
820 "field name is required for ClassDef");
821 return NULL;
822 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000823 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000824 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000825 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000826 return NULL;
827 }
828 p->kind = ClassDef_kind;
829 p->v.ClassDef.name = name;
830 p->v.ClassDef.bases = bases;
831 p->v.ClassDef.body = body;
832 p->lineno = lineno;
833 return p;
834}
835
836stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000837Return(expr_ty value, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000838{
839 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000840 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000841 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000842 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000843 return NULL;
844 }
845 p->kind = Return_kind;
846 p->v.Return.value = value;
847 p->lineno = lineno;
848 return p;
849}
850
851stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000852Delete(asdl_seq * targets, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000853{
854 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000855 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000856 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000857 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000858 return NULL;
859 }
860 p->kind = Delete_kind;
861 p->v.Delete.targets = targets;
862 p->lineno = lineno;
863 return p;
864}
865
866stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000867Assign(asdl_seq * targets, expr_ty value, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000868{
869 stmt_ty p;
870 if (!value) {
871 PyErr_SetString(PyExc_ValueError,
872 "field value is required for Assign");
873 return NULL;
874 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000875 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000876 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000877 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000878 return NULL;
879 }
880 p->kind = Assign_kind;
881 p->v.Assign.targets = targets;
882 p->v.Assign.value = value;
883 p->lineno = lineno;
884 return p;
885}
886
887stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000888AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, PyArena
889 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000890{
891 stmt_ty p;
892 if (!target) {
893 PyErr_SetString(PyExc_ValueError,
894 "field target is required for AugAssign");
895 return NULL;
896 }
897 if (!op) {
898 PyErr_SetString(PyExc_ValueError,
899 "field op is required for AugAssign");
900 return NULL;
901 }
902 if (!value) {
903 PyErr_SetString(PyExc_ValueError,
904 "field value is required for AugAssign");
905 return NULL;
906 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000907 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000908 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000909 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000910 return NULL;
911 }
912 p->kind = AugAssign_kind;
913 p->v.AugAssign.target = target;
914 p->v.AugAssign.op = op;
915 p->v.AugAssign.value = value;
916 p->lineno = lineno;
917 return p;
918}
919
920stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000921Print(expr_ty dest, asdl_seq * values, bool nl, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000922{
923 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000924 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000925 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000926 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000927 return NULL;
928 }
929 p->kind = Print_kind;
930 p->v.Print.dest = dest;
931 p->v.Print.values = values;
932 p->v.Print.nl = nl;
933 p->lineno = lineno;
934 return p;
935}
936
937stmt_ty
938For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000939 lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000940{
941 stmt_ty p;
942 if (!target) {
943 PyErr_SetString(PyExc_ValueError,
944 "field target is required for For");
945 return NULL;
946 }
947 if (!iter) {
948 PyErr_SetString(PyExc_ValueError,
949 "field iter is required for For");
950 return NULL;
951 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000952 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000953 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000954 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000955 return NULL;
956 }
957 p->kind = For_kind;
958 p->v.For.target = target;
959 p->v.For.iter = iter;
960 p->v.For.body = body;
961 p->v.For.orelse = orelse;
962 p->lineno = lineno;
963 return p;
964}
965
966stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000967While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, PyArena
968 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000969{
970 stmt_ty p;
971 if (!test) {
972 PyErr_SetString(PyExc_ValueError,
973 "field test is required for While");
974 return NULL;
975 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000976 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000977 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000978 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000979 return NULL;
980 }
981 p->kind = While_kind;
982 p->v.While.test = test;
983 p->v.While.body = body;
984 p->v.While.orelse = orelse;
985 p->lineno = lineno;
986 return p;
987}
988
989stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000990If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000991{
992 stmt_ty p;
993 if (!test) {
994 PyErr_SetString(PyExc_ValueError,
995 "field test is required for If");
996 return NULL;
997 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000998 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000999 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001000 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001001 return NULL;
1002 }
1003 p->kind = If_kind;
1004 p->v.If.test = test;
1005 p->v.If.body = body;
1006 p->v.If.orelse = orelse;
1007 p->lineno = lineno;
1008 return p;
1009}
1010
1011stmt_ty
Guido van Rossumc2e20742006-02-27 22:32:47 +00001012With(expr_ty context_expr, expr_ty optional_vars, asdl_seq * body, int lineno,
1013 PyArena *arena)
1014{
1015 stmt_ty p;
1016 if (!context_expr) {
1017 PyErr_SetString(PyExc_ValueError,
1018 "field context_expr is required for With");
1019 return NULL;
1020 }
1021 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1022 if (!p) {
1023 PyErr_NoMemory();
1024 return NULL;
1025 }
1026 p->kind = With_kind;
1027 p->v.With.context_expr = context_expr;
1028 p->v.With.optional_vars = optional_vars;
1029 p->v.With.body = body;
1030 p->lineno = lineno;
1031 return p;
1032}
1033
1034stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001035Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001036{
1037 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001038 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001039 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001040 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001041 return NULL;
1042 }
1043 p->kind = Raise_kind;
1044 p->v.Raise.type = type;
1045 p->v.Raise.inst = inst;
1046 p->v.Raise.tback = tback;
1047 p->lineno = lineno;
1048 return p;
1049}
1050
1051stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001052TryExcept(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, int lineno,
1053 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001054{
1055 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001056 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001057 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001058 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001059 return NULL;
1060 }
1061 p->kind = TryExcept_kind;
1062 p->v.TryExcept.body = body;
1063 p->v.TryExcept.handlers = handlers;
1064 p->v.TryExcept.orelse = orelse;
1065 p->lineno = lineno;
1066 return p;
1067}
1068
1069stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001070TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001071{
1072 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001073 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001074 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001075 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001076 return NULL;
1077 }
1078 p->kind = TryFinally_kind;
1079 p->v.TryFinally.body = body;
1080 p->v.TryFinally.finalbody = finalbody;
1081 p->lineno = lineno;
1082 return p;
1083}
1084
1085stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001086Assert(expr_ty test, expr_ty msg, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001087{
1088 stmt_ty p;
1089 if (!test) {
1090 PyErr_SetString(PyExc_ValueError,
1091 "field test is required for Assert");
1092 return NULL;
1093 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001094 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001095 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001096 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001097 return NULL;
1098 }
1099 p->kind = Assert_kind;
1100 p->v.Assert.test = test;
1101 p->v.Assert.msg = msg;
1102 p->lineno = lineno;
1103 return p;
1104}
1105
1106stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001107Import(asdl_seq * names, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001108{
1109 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001110 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001111 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001112 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001113 return NULL;
1114 }
1115 p->kind = Import_kind;
1116 p->v.Import.names = names;
1117 p->lineno = lineno;
1118 return p;
1119}
1120
1121stmt_ty
Thomas Woutersf7f438b2006-02-28 16:09:29 +00001122ImportFrom(identifier module, asdl_seq * names, int level, int lineno, PyArena
1123 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001124{
1125 stmt_ty p;
1126 if (!module) {
1127 PyErr_SetString(PyExc_ValueError,
1128 "field module is required for ImportFrom");
1129 return NULL;
1130 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001131 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001132 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001133 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001134 return NULL;
1135 }
1136 p->kind = ImportFrom_kind;
1137 p->v.ImportFrom.module = module;
1138 p->v.ImportFrom.names = names;
Thomas Woutersf7f438b2006-02-28 16:09:29 +00001139 p->v.ImportFrom.level = level;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001140 p->lineno = lineno;
1141 return p;
1142}
1143
1144stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001145Exec(expr_ty body, expr_ty globals, expr_ty locals, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001146{
1147 stmt_ty p;
1148 if (!body) {
1149 PyErr_SetString(PyExc_ValueError,
1150 "field body is required for Exec");
1151 return NULL;
1152 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001153 p = (stmt_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 = Exec_kind;
1159 p->v.Exec.body = body;
1160 p->v.Exec.globals = globals;
1161 p->v.Exec.locals = locals;
1162 p->lineno = lineno;
1163 return p;
1164}
1165
1166stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001167Global(asdl_seq * names, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001168{
1169 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001170 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001171 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001172 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001173 return NULL;
1174 }
1175 p->kind = Global_kind;
1176 p->v.Global.names = names;
1177 p->lineno = lineno;
1178 return p;
1179}
1180
1181stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001182Expr(expr_ty value, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001183{
1184 stmt_ty p;
1185 if (!value) {
1186 PyErr_SetString(PyExc_ValueError,
1187 "field value is required for Expr");
1188 return NULL;
1189 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001190 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001191 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001192 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001193 return NULL;
1194 }
1195 p->kind = Expr_kind;
1196 p->v.Expr.value = value;
1197 p->lineno = lineno;
1198 return p;
1199}
1200
1201stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001202Pass(int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001203{
1204 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001205 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001206 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001207 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001208 return NULL;
1209 }
1210 p->kind = Pass_kind;
1211 p->lineno = lineno;
1212 return p;
1213}
1214
1215stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001216Break(int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001217{
1218 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001219 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001220 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001221 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001222 return NULL;
1223 }
1224 p->kind = Break_kind;
1225 p->lineno = lineno;
1226 return p;
1227}
1228
1229stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001230Continue(int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001231{
1232 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001233 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001234 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001235 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001236 return NULL;
1237 }
1238 p->kind = Continue_kind;
1239 p->lineno = lineno;
1240 return p;
1241}
1242
1243expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001244BoolOp(boolop_ty op, asdl_seq * values, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001245{
1246 expr_ty p;
1247 if (!op) {
1248 PyErr_SetString(PyExc_ValueError,
1249 "field op is required for BoolOp");
1250 return NULL;
1251 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001252 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001253 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001254 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001255 return NULL;
1256 }
1257 p->kind = BoolOp_kind;
1258 p->v.BoolOp.op = op;
1259 p->v.BoolOp.values = values;
1260 p->lineno = lineno;
1261 return p;
1262}
1263
1264expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001265BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001266{
1267 expr_ty p;
1268 if (!left) {
1269 PyErr_SetString(PyExc_ValueError,
1270 "field left is required for BinOp");
1271 return NULL;
1272 }
1273 if (!op) {
1274 PyErr_SetString(PyExc_ValueError,
1275 "field op is required for BinOp");
1276 return NULL;
1277 }
1278 if (!right) {
1279 PyErr_SetString(PyExc_ValueError,
1280 "field right is required for BinOp");
1281 return NULL;
1282 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001283 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001284 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001285 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001286 return NULL;
1287 }
1288 p->kind = BinOp_kind;
1289 p->v.BinOp.left = left;
1290 p->v.BinOp.op = op;
1291 p->v.BinOp.right = right;
1292 p->lineno = lineno;
1293 return p;
1294}
1295
1296expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001297UnaryOp(unaryop_ty op, expr_ty operand, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001298{
1299 expr_ty p;
1300 if (!op) {
1301 PyErr_SetString(PyExc_ValueError,
1302 "field op is required for UnaryOp");
1303 return NULL;
1304 }
1305 if (!operand) {
1306 PyErr_SetString(PyExc_ValueError,
1307 "field operand is required for UnaryOp");
1308 return NULL;
1309 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001310 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001311 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001312 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001313 return NULL;
1314 }
1315 p->kind = UnaryOp_kind;
1316 p->v.UnaryOp.op = op;
1317 p->v.UnaryOp.operand = operand;
1318 p->lineno = lineno;
1319 return p;
1320}
1321
1322expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001323Lambda(arguments_ty args, expr_ty body, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001324{
1325 expr_ty p;
1326 if (!args) {
1327 PyErr_SetString(PyExc_ValueError,
1328 "field args is required for Lambda");
1329 return NULL;
1330 }
1331 if (!body) {
1332 PyErr_SetString(PyExc_ValueError,
1333 "field body is required for Lambda");
1334 return NULL;
1335 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001336 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001337 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001338 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001339 return NULL;
1340 }
1341 p->kind = Lambda_kind;
1342 p->v.Lambda.args = args;
1343 p->v.Lambda.body = body;
1344 p->lineno = lineno;
1345 return p;
1346}
1347
1348expr_ty
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001349IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, PyArena *arena)
1350{
1351 expr_ty p;
1352 if (!test) {
1353 PyErr_SetString(PyExc_ValueError,
1354 "field test is required for IfExp");
1355 return NULL;
1356 }
1357 if (!body) {
1358 PyErr_SetString(PyExc_ValueError,
1359 "field body is required for IfExp");
1360 return NULL;
1361 }
1362 if (!orelse) {
1363 PyErr_SetString(PyExc_ValueError,
1364 "field orelse is required for IfExp");
1365 return NULL;
1366 }
1367 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1368 if (!p) {
1369 PyErr_NoMemory();
1370 return NULL;
1371 }
1372 p->kind = IfExp_kind;
1373 p->v.IfExp.test = test;
1374 p->v.IfExp.body = body;
1375 p->v.IfExp.orelse = orelse;
1376 p->lineno = lineno;
1377 return p;
1378}
1379
1380expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001381Dict(asdl_seq * keys, asdl_seq * values, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001382{
1383 expr_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001384 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001385 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001386 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001387 return NULL;
1388 }
1389 p->kind = Dict_kind;
1390 p->v.Dict.keys = keys;
1391 p->v.Dict.values = values;
1392 p->lineno = lineno;
1393 return p;
1394}
1395
1396expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001397ListComp(expr_ty elt, asdl_seq * generators, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001398{
1399 expr_ty p;
1400 if (!elt) {
1401 PyErr_SetString(PyExc_ValueError,
1402 "field elt is required for ListComp");
1403 return NULL;
1404 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001405 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001406 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001407 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001408 return NULL;
1409 }
1410 p->kind = ListComp_kind;
1411 p->v.ListComp.elt = elt;
1412 p->v.ListComp.generators = generators;
1413 p->lineno = lineno;
1414 return p;
1415}
1416
1417expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001418GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001419{
1420 expr_ty p;
1421 if (!elt) {
1422 PyErr_SetString(PyExc_ValueError,
1423 "field elt is required for GeneratorExp");
1424 return NULL;
1425 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001426 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001427 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001428 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001429 return NULL;
1430 }
1431 p->kind = GeneratorExp_kind;
1432 p->v.GeneratorExp.elt = elt;
1433 p->v.GeneratorExp.generators = generators;
1434 p->lineno = lineno;
1435 return p;
1436}
1437
1438expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001439Yield(expr_ty value, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001440{
1441 expr_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001442 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001443 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001444 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001445 return NULL;
1446 }
1447 p->kind = Yield_kind;
1448 p->v.Yield.value = value;
1449 p->lineno = lineno;
1450 return p;
1451}
1452
1453expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001454Compare(expr_ty left, asdl_seq * ops, asdl_seq * comparators, int lineno,
1455 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001456{
1457 expr_ty p;
1458 if (!left) {
1459 PyErr_SetString(PyExc_ValueError,
1460 "field left is required for Compare");
1461 return NULL;
1462 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001463 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001464 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001465 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001466 return NULL;
1467 }
1468 p->kind = Compare_kind;
1469 p->v.Compare.left = left;
1470 p->v.Compare.ops = ops;
1471 p->v.Compare.comparators = comparators;
1472 p->lineno = lineno;
1473 return p;
1474}
1475
1476expr_ty
1477Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, expr_ty starargs,
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001478 expr_ty kwargs, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001479{
1480 expr_ty p;
1481 if (!func) {
1482 PyErr_SetString(PyExc_ValueError,
1483 "field func is required for Call");
1484 return NULL;
1485 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001486 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001487 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001488 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001489 return NULL;
1490 }
1491 p->kind = Call_kind;
1492 p->v.Call.func = func;
1493 p->v.Call.args = args;
1494 p->v.Call.keywords = keywords;
1495 p->v.Call.starargs = starargs;
1496 p->v.Call.kwargs = kwargs;
1497 p->lineno = lineno;
1498 return p;
1499}
1500
1501expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001502Repr(expr_ty value, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001503{
1504 expr_ty p;
1505 if (!value) {
1506 PyErr_SetString(PyExc_ValueError,
1507 "field value is required for Repr");
1508 return NULL;
1509 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001510 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001511 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001512 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001513 return NULL;
1514 }
1515 p->kind = Repr_kind;
1516 p->v.Repr.value = value;
1517 p->lineno = lineno;
1518 return p;
1519}
1520
1521expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001522Num(object n, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001523{
1524 expr_ty p;
1525 if (!n) {
1526 PyErr_SetString(PyExc_ValueError,
1527 "field n is required for Num");
1528 return NULL;
1529 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001530 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001531 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001532 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001533 return NULL;
1534 }
1535 p->kind = Num_kind;
1536 p->v.Num.n = n;
1537 p->lineno = lineno;
1538 return p;
1539}
1540
1541expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001542Str(string s, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001543{
1544 expr_ty p;
1545 if (!s) {
1546 PyErr_SetString(PyExc_ValueError,
1547 "field s is required for Str");
1548 return NULL;
1549 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001550 p = (expr_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 = Str_kind;
1556 p->v.Str.s = s;
1557 p->lineno = lineno;
1558 return p;
1559}
1560
1561expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001562Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno,
1563 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001564{
1565 expr_ty p;
1566 if (!value) {
1567 PyErr_SetString(PyExc_ValueError,
1568 "field value is required for Attribute");
1569 return NULL;
1570 }
1571 if (!attr) {
1572 PyErr_SetString(PyExc_ValueError,
1573 "field attr is required for Attribute");
1574 return NULL;
1575 }
1576 if (!ctx) {
1577 PyErr_SetString(PyExc_ValueError,
1578 "field ctx is required for Attribute");
1579 return NULL;
1580 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001581 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001582 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001583 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001584 return NULL;
1585 }
1586 p->kind = Attribute_kind;
1587 p->v.Attribute.value = value;
1588 p->v.Attribute.attr = attr;
1589 p->v.Attribute.ctx = ctx;
1590 p->lineno = lineno;
1591 return p;
1592}
1593
1594expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001595Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno,
1596 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001597{
1598 expr_ty p;
1599 if (!value) {
1600 PyErr_SetString(PyExc_ValueError,
1601 "field value is required for Subscript");
1602 return NULL;
1603 }
1604 if (!slice) {
1605 PyErr_SetString(PyExc_ValueError,
1606 "field slice is required for Subscript");
1607 return NULL;
1608 }
1609 if (!ctx) {
1610 PyErr_SetString(PyExc_ValueError,
1611 "field ctx is required for Subscript");
1612 return NULL;
1613 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001614 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001615 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001616 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001617 return NULL;
1618 }
1619 p->kind = Subscript_kind;
1620 p->v.Subscript.value = value;
1621 p->v.Subscript.slice = slice;
1622 p->v.Subscript.ctx = ctx;
1623 p->lineno = lineno;
1624 return p;
1625}
1626
1627expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001628Name(identifier id, expr_context_ty ctx, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001629{
1630 expr_ty p;
1631 if (!id) {
1632 PyErr_SetString(PyExc_ValueError,
1633 "field id is required for Name");
1634 return NULL;
1635 }
1636 if (!ctx) {
1637 PyErr_SetString(PyExc_ValueError,
1638 "field ctx is required for Name");
1639 return NULL;
1640 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001641 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001642 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001643 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001644 return NULL;
1645 }
1646 p->kind = Name_kind;
1647 p->v.Name.id = id;
1648 p->v.Name.ctx = ctx;
1649 p->lineno = lineno;
1650 return p;
1651}
1652
1653expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001654List(asdl_seq * elts, expr_context_ty ctx, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001655{
1656 expr_ty p;
1657 if (!ctx) {
1658 PyErr_SetString(PyExc_ValueError,
1659 "field ctx is required for List");
1660 return NULL;
1661 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001662 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001663 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001664 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001665 return NULL;
1666 }
1667 p->kind = List_kind;
1668 p->v.List.elts = elts;
1669 p->v.List.ctx = ctx;
1670 p->lineno = lineno;
1671 return p;
1672}
1673
1674expr_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001675Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001676{
1677 expr_ty p;
1678 if (!ctx) {
1679 PyErr_SetString(PyExc_ValueError,
1680 "field ctx is required for Tuple");
1681 return NULL;
1682 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001683 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001684 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001685 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001686 return NULL;
1687 }
1688 p->kind = Tuple_kind;
1689 p->v.Tuple.elts = elts;
1690 p->v.Tuple.ctx = ctx;
1691 p->lineno = lineno;
1692 return p;
1693}
1694
1695slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001696Ellipsis(PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001697{
1698 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001699 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001700 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001701 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001702 return NULL;
1703 }
1704 p->kind = Ellipsis_kind;
1705 return p;
1706}
1707
1708slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001709Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001710{
1711 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001712 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001713 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001714 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001715 return NULL;
1716 }
1717 p->kind = Slice_kind;
1718 p->v.Slice.lower = lower;
1719 p->v.Slice.upper = upper;
1720 p->v.Slice.step = step;
1721 return p;
1722}
1723
1724slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001725ExtSlice(asdl_seq * dims, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001726{
1727 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001728 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001729 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001730 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001731 return NULL;
1732 }
1733 p->kind = ExtSlice_kind;
1734 p->v.ExtSlice.dims = dims;
1735 return p;
1736}
1737
1738slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001739Index(expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001740{
1741 slice_ty p;
1742 if (!value) {
1743 PyErr_SetString(PyExc_ValueError,
1744 "field value is required for Index");
1745 return NULL;
1746 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001747 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001748 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001749 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001750 return NULL;
1751 }
1752 p->kind = Index_kind;
1753 p->v.Index.value = value;
1754 return p;
1755}
1756
1757comprehension_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001758comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001759{
1760 comprehension_ty p;
1761 if (!target) {
1762 PyErr_SetString(PyExc_ValueError,
1763 "field target is required for comprehension");
1764 return NULL;
1765 }
1766 if (!iter) {
1767 PyErr_SetString(PyExc_ValueError,
1768 "field iter is required for comprehension");
1769 return NULL;
1770 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001771 p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001772 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001773 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001774 return NULL;
1775 }
1776 p->target = target;
1777 p->iter = iter;
1778 p->ifs = ifs;
1779 return p;
1780}
1781
1782excepthandler_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001783excepthandler(expr_ty type, expr_ty name, asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001784{
1785 excepthandler_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001786 p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001787 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001788 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001789 return NULL;
1790 }
1791 p->type = type;
1792 p->name = name;
1793 p->body = body;
1794 return p;
1795}
1796
1797arguments_ty
1798arguments(asdl_seq * args, identifier vararg, identifier kwarg, asdl_seq *
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001799 defaults, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001800{
1801 arguments_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001802 p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001803 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001804 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001805 return NULL;
1806 }
1807 p->args = args;
1808 p->vararg = vararg;
1809 p->kwarg = kwarg;
1810 p->defaults = defaults;
1811 return p;
1812}
1813
1814keyword_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001815keyword(identifier arg, expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001816{
1817 keyword_ty p;
1818 if (!arg) {
1819 PyErr_SetString(PyExc_ValueError,
1820 "field arg is required for keyword");
1821 return NULL;
1822 }
1823 if (!value) {
1824 PyErr_SetString(PyExc_ValueError,
1825 "field value is required for keyword");
1826 return NULL;
1827 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001828 p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001829 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001830 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001831 return NULL;
1832 }
1833 p->arg = arg;
1834 p->value = value;
1835 return p;
1836}
1837
1838alias_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001839alias(identifier name, identifier asname, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001840{
1841 alias_ty p;
1842 if (!name) {
1843 PyErr_SetString(PyExc_ValueError,
1844 "field name is required for alias");
1845 return NULL;
1846 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001847 p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001848 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001849 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001850 return NULL;
1851 }
1852 p->name = name;
1853 p->asname = asname;
1854 return p;
1855}
1856
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001857
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001858PyObject*
1859ast2obj_mod(void* _o)
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001860{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001861 mod_ty o = (mod_ty)_o;
1862 PyObject *result = NULL, *value = NULL;
1863 if (!o) {
1864 Py_INCREF(Py_None);
1865 return Py_None;
1866 }
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001867
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001868 switch (o->kind) {
1869 case Module_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001870 result = PyType_GenericNew(Module_type, NULL, NULL);
1871 if (!result) goto failed;
1872 value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
1873 if (!value) goto failed;
1874 if (PyObject_SetAttrString(result, "body", value) == -1)
1875 goto failed;
1876 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001877 break;
1878 case Interactive_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001879 result = PyType_GenericNew(Interactive_type, NULL, NULL);
1880 if (!result) goto failed;
1881 value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
1882 if (!value) goto failed;
1883 if (PyObject_SetAttrString(result, "body", value) == -1)
1884 goto failed;
1885 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001886 break;
1887 case Expression_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001888 result = PyType_GenericNew(Expression_type, NULL, NULL);
1889 if (!result) goto failed;
1890 value = ast2obj_expr(o->v.Expression.body);
1891 if (!value) goto failed;
1892 if (PyObject_SetAttrString(result, "body", value) == -1)
1893 goto failed;
1894 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001895 break;
1896 case Suite_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001897 result = PyType_GenericNew(Suite_type, NULL, NULL);
1898 if (!result) goto failed;
1899 value = ast2obj_list(o->v.Suite.body, ast2obj_stmt);
1900 if (!value) goto failed;
1901 if (PyObject_SetAttrString(result, "body", value) == -1)
1902 goto failed;
1903 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001904 break;
1905 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001906 return result;
1907failed:
1908 Py_XDECREF(value);
1909 Py_XDECREF(result);
1910 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001911}
1912
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001913PyObject*
1914ast2obj_stmt(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001915{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001916 stmt_ty o = (stmt_ty)_o;
1917 PyObject *result = NULL, *value = NULL;
1918 if (!o) {
1919 Py_INCREF(Py_None);
1920 return Py_None;
1921 }
1922
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001923 switch (o->kind) {
1924 case FunctionDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001925 result = PyType_GenericNew(FunctionDef_type, NULL, NULL);
1926 if (!result) goto failed;
1927 value = ast2obj_identifier(o->v.FunctionDef.name);
1928 if (!value) goto failed;
1929 if (PyObject_SetAttrString(result, "name", value) == -1)
1930 goto failed;
1931 Py_DECREF(value);
1932 value = ast2obj_arguments(o->v.FunctionDef.args);
1933 if (!value) goto failed;
1934 if (PyObject_SetAttrString(result, "args", value) == -1)
1935 goto failed;
1936 Py_DECREF(value);
1937 value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
1938 if (!value) goto failed;
1939 if (PyObject_SetAttrString(result, "body", value) == -1)
1940 goto failed;
1941 Py_DECREF(value);
1942 value = ast2obj_list(o->v.FunctionDef.decorators, ast2obj_expr);
1943 if (!value) goto failed;
1944 if (PyObject_SetAttrString(result, "decorators", value) == -1)
1945 goto failed;
1946 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001947 break;
1948 case ClassDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001949 result = PyType_GenericNew(ClassDef_type, NULL, NULL);
1950 if (!result) goto failed;
1951 value = ast2obj_identifier(o->v.ClassDef.name);
1952 if (!value) goto failed;
1953 if (PyObject_SetAttrString(result, "name", value) == -1)
1954 goto failed;
1955 Py_DECREF(value);
1956 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
1957 if (!value) goto failed;
1958 if (PyObject_SetAttrString(result, "bases", value) == -1)
1959 goto failed;
1960 Py_DECREF(value);
1961 value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
1962 if (!value) goto failed;
1963 if (PyObject_SetAttrString(result, "body", value) == -1)
1964 goto failed;
1965 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001966 break;
1967 case Return_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001968 result = PyType_GenericNew(Return_type, NULL, NULL);
1969 if (!result) goto failed;
1970 value = ast2obj_expr(o->v.Return.value);
1971 if (!value) goto failed;
1972 if (PyObject_SetAttrString(result, "value", value) == -1)
1973 goto failed;
1974 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001975 break;
1976 case Delete_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001977 result = PyType_GenericNew(Delete_type, NULL, NULL);
1978 if (!result) goto failed;
1979 value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
1980 if (!value) goto failed;
1981 if (PyObject_SetAttrString(result, "targets", value) == -1)
1982 goto failed;
1983 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001984 break;
1985 case Assign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001986 result = PyType_GenericNew(Assign_type, NULL, NULL);
1987 if (!result) goto failed;
1988 value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
1989 if (!value) goto failed;
1990 if (PyObject_SetAttrString(result, "targets", value) == -1)
1991 goto failed;
1992 Py_DECREF(value);
1993 value = ast2obj_expr(o->v.Assign.value);
1994 if (!value) goto failed;
1995 if (PyObject_SetAttrString(result, "value", value) == -1)
1996 goto failed;
1997 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001998 break;
1999 case AugAssign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002000 result = PyType_GenericNew(AugAssign_type, NULL, NULL);
2001 if (!result) goto failed;
2002 value = ast2obj_expr(o->v.AugAssign.target);
2003 if (!value) goto failed;
2004 if (PyObject_SetAttrString(result, "target", value) == -1)
2005 goto failed;
2006 Py_DECREF(value);
2007 value = ast2obj_operator(o->v.AugAssign.op);
2008 if (!value) goto failed;
2009 if (PyObject_SetAttrString(result, "op", value) == -1)
2010 goto failed;
2011 Py_DECREF(value);
2012 value = ast2obj_expr(o->v.AugAssign.value);
2013 if (!value) goto failed;
2014 if (PyObject_SetAttrString(result, "value", value) == -1)
2015 goto failed;
2016 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002017 break;
2018 case Print_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002019 result = PyType_GenericNew(Print_type, NULL, NULL);
2020 if (!result) goto failed;
2021 value = ast2obj_expr(o->v.Print.dest);
2022 if (!value) goto failed;
2023 if (PyObject_SetAttrString(result, "dest", value) == -1)
2024 goto failed;
2025 Py_DECREF(value);
2026 value = ast2obj_list(o->v.Print.values, ast2obj_expr);
2027 if (!value) goto failed;
2028 if (PyObject_SetAttrString(result, "values", value) == -1)
2029 goto failed;
2030 Py_DECREF(value);
2031 value = ast2obj_bool(o->v.Print.nl);
2032 if (!value) goto failed;
2033 if (PyObject_SetAttrString(result, "nl", value) == -1)
2034 goto failed;
2035 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002036 break;
2037 case For_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002038 result = PyType_GenericNew(For_type, NULL, NULL);
2039 if (!result) goto failed;
2040 value = ast2obj_expr(o->v.For.target);
2041 if (!value) goto failed;
2042 if (PyObject_SetAttrString(result, "target", value) == -1)
2043 goto failed;
2044 Py_DECREF(value);
2045 value = ast2obj_expr(o->v.For.iter);
2046 if (!value) goto failed;
2047 if (PyObject_SetAttrString(result, "iter", value) == -1)
2048 goto failed;
2049 Py_DECREF(value);
2050 value = ast2obj_list(o->v.For.body, ast2obj_stmt);
2051 if (!value) goto failed;
2052 if (PyObject_SetAttrString(result, "body", value) == -1)
2053 goto failed;
2054 Py_DECREF(value);
2055 value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
2056 if (!value) goto failed;
2057 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2058 goto failed;
2059 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002060 break;
2061 case While_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002062 result = PyType_GenericNew(While_type, NULL, NULL);
2063 if (!result) goto failed;
2064 value = ast2obj_expr(o->v.While.test);
2065 if (!value) goto failed;
2066 if (PyObject_SetAttrString(result, "test", value) == -1)
2067 goto failed;
2068 Py_DECREF(value);
2069 value = ast2obj_list(o->v.While.body, ast2obj_stmt);
2070 if (!value) goto failed;
2071 if (PyObject_SetAttrString(result, "body", value) == -1)
2072 goto failed;
2073 Py_DECREF(value);
2074 value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);
2075 if (!value) goto failed;
2076 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2077 goto failed;
2078 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002079 break;
2080 case If_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002081 result = PyType_GenericNew(If_type, NULL, NULL);
2082 if (!result) goto failed;
2083 value = ast2obj_expr(o->v.If.test);
2084 if (!value) goto failed;
2085 if (PyObject_SetAttrString(result, "test", value) == -1)
2086 goto failed;
2087 Py_DECREF(value);
2088 value = ast2obj_list(o->v.If.body, ast2obj_stmt);
2089 if (!value) goto failed;
2090 if (PyObject_SetAttrString(result, "body", value) == -1)
2091 goto failed;
2092 Py_DECREF(value);
2093 value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
2094 if (!value) goto failed;
2095 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2096 goto failed;
2097 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002098 break;
Guido van Rossumc2e20742006-02-27 22:32:47 +00002099 case With_kind:
2100 result = PyType_GenericNew(With_type, NULL, NULL);
2101 if (!result) goto failed;
2102 value = ast2obj_expr(o->v.With.context_expr);
2103 if (!value) goto failed;
2104 if (PyObject_SetAttrString(result, "context_expr", value) == -1)
2105 goto failed;
2106 Py_DECREF(value);
2107 value = ast2obj_expr(o->v.With.optional_vars);
2108 if (!value) goto failed;
2109 if (PyObject_SetAttrString(result, "optional_vars", value) ==
2110 -1)
2111 goto failed;
2112 Py_DECREF(value);
2113 value = ast2obj_list(o->v.With.body, ast2obj_stmt);
2114 if (!value) goto failed;
2115 if (PyObject_SetAttrString(result, "body", value) == -1)
2116 goto failed;
2117 Py_DECREF(value);
2118 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002119 case Raise_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002120 result = PyType_GenericNew(Raise_type, NULL, NULL);
2121 if (!result) goto failed;
2122 value = ast2obj_expr(o->v.Raise.type);
2123 if (!value) goto failed;
2124 if (PyObject_SetAttrString(result, "type", value) == -1)
2125 goto failed;
2126 Py_DECREF(value);
2127 value = ast2obj_expr(o->v.Raise.inst);
2128 if (!value) goto failed;
2129 if (PyObject_SetAttrString(result, "inst", value) == -1)
2130 goto failed;
2131 Py_DECREF(value);
2132 value = ast2obj_expr(o->v.Raise.tback);
2133 if (!value) goto failed;
2134 if (PyObject_SetAttrString(result, "tback", value) == -1)
2135 goto failed;
2136 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002137 break;
2138 case TryExcept_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002139 result = PyType_GenericNew(TryExcept_type, NULL, NULL);
2140 if (!result) goto failed;
2141 value = ast2obj_list(o->v.TryExcept.body, ast2obj_stmt);
2142 if (!value) goto failed;
2143 if (PyObject_SetAttrString(result, "body", value) == -1)
2144 goto failed;
2145 Py_DECREF(value);
2146 value = ast2obj_list(o->v.TryExcept.handlers,
2147 ast2obj_excepthandler);
2148 if (!value) goto failed;
2149 if (PyObject_SetAttrString(result, "handlers", value) == -1)
2150 goto failed;
2151 Py_DECREF(value);
2152 value = ast2obj_list(o->v.TryExcept.orelse, ast2obj_stmt);
2153 if (!value) goto failed;
2154 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2155 goto failed;
2156 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002157 break;
2158 case TryFinally_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002159 result = PyType_GenericNew(TryFinally_type, NULL, NULL);
2160 if (!result) goto failed;
2161 value = ast2obj_list(o->v.TryFinally.body, ast2obj_stmt);
2162 if (!value) goto failed;
2163 if (PyObject_SetAttrString(result, "body", value) == -1)
2164 goto failed;
2165 Py_DECREF(value);
2166 value = ast2obj_list(o->v.TryFinally.finalbody, ast2obj_stmt);
2167 if (!value) goto failed;
2168 if (PyObject_SetAttrString(result, "finalbody", value) == -1)
2169 goto failed;
2170 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002171 break;
2172 case Assert_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002173 result = PyType_GenericNew(Assert_type, NULL, NULL);
2174 if (!result) goto failed;
2175 value = ast2obj_expr(o->v.Assert.test);
2176 if (!value) goto failed;
2177 if (PyObject_SetAttrString(result, "test", value) == -1)
2178 goto failed;
2179 Py_DECREF(value);
2180 value = ast2obj_expr(o->v.Assert.msg);
2181 if (!value) goto failed;
2182 if (PyObject_SetAttrString(result, "msg", value) == -1)
2183 goto failed;
2184 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002185 break;
2186 case Import_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002187 result = PyType_GenericNew(Import_type, NULL, NULL);
2188 if (!result) goto failed;
2189 value = ast2obj_list(o->v.Import.names, ast2obj_alias);
2190 if (!value) goto failed;
2191 if (PyObject_SetAttrString(result, "names", value) == -1)
2192 goto failed;
2193 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002194 break;
2195 case ImportFrom_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002196 result = PyType_GenericNew(ImportFrom_type, NULL, NULL);
2197 if (!result) goto failed;
2198 value = ast2obj_identifier(o->v.ImportFrom.module);
2199 if (!value) goto failed;
2200 if (PyObject_SetAttrString(result, "module", value) == -1)
2201 goto failed;
2202 Py_DECREF(value);
2203 value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
2204 if (!value) goto failed;
2205 if (PyObject_SetAttrString(result, "names", value) == -1)
2206 goto failed;
2207 Py_DECREF(value);
Thomas Woutersf7f438b2006-02-28 16:09:29 +00002208 value = ast2obj_int(o->v.ImportFrom.level);
2209 if (!value) goto failed;
2210 if (PyObject_SetAttrString(result, "level", value) == -1)
2211 goto failed;
2212 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002213 break;
2214 case Exec_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002215 result = PyType_GenericNew(Exec_type, NULL, NULL);
2216 if (!result) goto failed;
2217 value = ast2obj_expr(o->v.Exec.body);
2218 if (!value) goto failed;
2219 if (PyObject_SetAttrString(result, "body", value) == -1)
2220 goto failed;
2221 Py_DECREF(value);
2222 value = ast2obj_expr(o->v.Exec.globals);
2223 if (!value) goto failed;
2224 if (PyObject_SetAttrString(result, "globals", value) == -1)
2225 goto failed;
2226 Py_DECREF(value);
2227 value = ast2obj_expr(o->v.Exec.locals);
2228 if (!value) goto failed;
2229 if (PyObject_SetAttrString(result, "locals", value) == -1)
2230 goto failed;
2231 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002232 break;
2233 case Global_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002234 result = PyType_GenericNew(Global_type, NULL, NULL);
2235 if (!result) goto failed;
2236 value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
2237 if (!value) goto failed;
2238 if (PyObject_SetAttrString(result, "names", value) == -1)
2239 goto failed;
2240 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002241 break;
2242 case Expr_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002243 result = PyType_GenericNew(Expr_type, NULL, NULL);
2244 if (!result) goto failed;
2245 value = ast2obj_expr(o->v.Expr.value);
2246 if (!value) goto failed;
2247 if (PyObject_SetAttrString(result, "value", value) == -1)
2248 goto failed;
2249 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002250 break;
2251 case Pass_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002252 result = PyType_GenericNew(Pass_type, NULL, NULL);
2253 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002254 break;
2255 case Break_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002256 result = PyType_GenericNew(Break_type, NULL, NULL);
2257 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002258 break;
2259 case Continue_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002260 result = PyType_GenericNew(Continue_type, NULL, NULL);
2261 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002262 break;
2263 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002264 value = ast2obj_int(o->lineno);
2265 if (!value) goto failed;
2266 PyObject_SetAttrString(result, "lineno", value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002267 return result;
2268failed:
2269 Py_XDECREF(value);
2270 Py_XDECREF(result);
2271 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002272}
2273
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002274PyObject*
2275ast2obj_expr(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002276{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002277 expr_ty o = (expr_ty)_o;
2278 PyObject *result = NULL, *value = NULL;
2279 if (!o) {
2280 Py_INCREF(Py_None);
2281 return Py_None;
2282 }
2283
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002284 switch (o->kind) {
2285 case BoolOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002286 result = PyType_GenericNew(BoolOp_type, NULL, NULL);
2287 if (!result) goto failed;
2288 value = ast2obj_boolop(o->v.BoolOp.op);
2289 if (!value) goto failed;
2290 if (PyObject_SetAttrString(result, "op", value) == -1)
2291 goto failed;
2292 Py_DECREF(value);
2293 value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
2294 if (!value) goto failed;
2295 if (PyObject_SetAttrString(result, "values", value) == -1)
2296 goto failed;
2297 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002298 break;
2299 case BinOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002300 result = PyType_GenericNew(BinOp_type, NULL, NULL);
2301 if (!result) goto failed;
2302 value = ast2obj_expr(o->v.BinOp.left);
2303 if (!value) goto failed;
2304 if (PyObject_SetAttrString(result, "left", value) == -1)
2305 goto failed;
2306 Py_DECREF(value);
2307 value = ast2obj_operator(o->v.BinOp.op);
2308 if (!value) goto failed;
2309 if (PyObject_SetAttrString(result, "op", value) == -1)
2310 goto failed;
2311 Py_DECREF(value);
2312 value = ast2obj_expr(o->v.BinOp.right);
2313 if (!value) goto failed;
2314 if (PyObject_SetAttrString(result, "right", value) == -1)
2315 goto failed;
2316 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002317 break;
2318 case UnaryOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002319 result = PyType_GenericNew(UnaryOp_type, NULL, NULL);
2320 if (!result) goto failed;
2321 value = ast2obj_unaryop(o->v.UnaryOp.op);
2322 if (!value) goto failed;
2323 if (PyObject_SetAttrString(result, "op", value) == -1)
2324 goto failed;
2325 Py_DECREF(value);
2326 value = ast2obj_expr(o->v.UnaryOp.operand);
2327 if (!value) goto failed;
2328 if (PyObject_SetAttrString(result, "operand", value) == -1)
2329 goto failed;
2330 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002331 break;
2332 case Lambda_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002333 result = PyType_GenericNew(Lambda_type, NULL, NULL);
2334 if (!result) goto failed;
2335 value = ast2obj_arguments(o->v.Lambda.args);
2336 if (!value) goto failed;
2337 if (PyObject_SetAttrString(result, "args", value) == -1)
2338 goto failed;
2339 Py_DECREF(value);
2340 value = ast2obj_expr(o->v.Lambda.body);
2341 if (!value) goto failed;
2342 if (PyObject_SetAttrString(result, "body", value) == -1)
2343 goto failed;
2344 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002345 break;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002346 case IfExp_kind:
2347 result = PyType_GenericNew(IfExp_type, NULL, NULL);
2348 if (!result) goto failed;
2349 value = ast2obj_expr(o->v.IfExp.test);
2350 if (!value) goto failed;
2351 if (PyObject_SetAttrString(result, "test", value) == -1)
2352 goto failed;
2353 Py_DECREF(value);
2354 value = ast2obj_expr(o->v.IfExp.body);
2355 if (!value) goto failed;
2356 if (PyObject_SetAttrString(result, "body", value) == -1)
2357 goto failed;
2358 Py_DECREF(value);
2359 value = ast2obj_expr(o->v.IfExp.orelse);
2360 if (!value) goto failed;
2361 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2362 goto failed;
2363 Py_DECREF(value);
2364 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002365 case Dict_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002366 result = PyType_GenericNew(Dict_type, NULL, NULL);
2367 if (!result) goto failed;
2368 value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
2369 if (!value) goto failed;
2370 if (PyObject_SetAttrString(result, "keys", value) == -1)
2371 goto failed;
2372 Py_DECREF(value);
2373 value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
2374 if (!value) goto failed;
2375 if (PyObject_SetAttrString(result, "values", value) == -1)
2376 goto failed;
2377 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002378 break;
2379 case ListComp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002380 result = PyType_GenericNew(ListComp_type, NULL, NULL);
2381 if (!result) goto failed;
2382 value = ast2obj_expr(o->v.ListComp.elt);
2383 if (!value) goto failed;
2384 if (PyObject_SetAttrString(result, "elt", value) == -1)
2385 goto failed;
2386 Py_DECREF(value);
2387 value = ast2obj_list(o->v.ListComp.generators,
2388 ast2obj_comprehension);
2389 if (!value) goto failed;
2390 if (PyObject_SetAttrString(result, "generators", value) == -1)
2391 goto failed;
2392 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002393 break;
2394 case GeneratorExp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002395 result = PyType_GenericNew(GeneratorExp_type, NULL, NULL);
2396 if (!result) goto failed;
2397 value = ast2obj_expr(o->v.GeneratorExp.elt);
2398 if (!value) goto failed;
2399 if (PyObject_SetAttrString(result, "elt", value) == -1)
2400 goto failed;
2401 Py_DECREF(value);
2402 value = ast2obj_list(o->v.GeneratorExp.generators,
2403 ast2obj_comprehension);
2404 if (!value) goto failed;
2405 if (PyObject_SetAttrString(result, "generators", value) == -1)
2406 goto failed;
2407 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002408 break;
2409 case Yield_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002410 result = PyType_GenericNew(Yield_type, NULL, NULL);
2411 if (!result) goto failed;
2412 value = ast2obj_expr(o->v.Yield.value);
2413 if (!value) goto failed;
2414 if (PyObject_SetAttrString(result, "value", value) == -1)
2415 goto failed;
2416 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002417 break;
2418 case Compare_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002419 result = PyType_GenericNew(Compare_type, NULL, NULL);
2420 if (!result) goto failed;
2421 value = ast2obj_expr(o->v.Compare.left);
2422 if (!value) goto failed;
2423 if (PyObject_SetAttrString(result, "left", value) == -1)
2424 goto failed;
2425 Py_DECREF(value);
Martin v. Löwisce1d5d22006-02-26 20:51:25 +00002426 {
2427 int i, n = asdl_seq_LEN(o->v.Compare.ops);
2428 value = PyList_New(n);
2429 if (!value) goto failed;
2430 for(i = 0; i < n; i++)
2431 PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
2432 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002433 if (!value) goto failed;
2434 if (PyObject_SetAttrString(result, "ops", value) == -1)
2435 goto failed;
2436 Py_DECREF(value);
2437 value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
2438 if (!value) goto failed;
2439 if (PyObject_SetAttrString(result, "comparators", value) == -1)
2440 goto failed;
2441 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002442 break;
2443 case Call_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002444 result = PyType_GenericNew(Call_type, NULL, NULL);
2445 if (!result) goto failed;
2446 value = ast2obj_expr(o->v.Call.func);
2447 if (!value) goto failed;
2448 if (PyObject_SetAttrString(result, "func", value) == -1)
2449 goto failed;
2450 Py_DECREF(value);
2451 value = ast2obj_list(o->v.Call.args, ast2obj_expr);
2452 if (!value) goto failed;
2453 if (PyObject_SetAttrString(result, "args", value) == -1)
2454 goto failed;
2455 Py_DECREF(value);
2456 value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
2457 if (!value) goto failed;
2458 if (PyObject_SetAttrString(result, "keywords", value) == -1)
2459 goto failed;
2460 Py_DECREF(value);
2461 value = ast2obj_expr(o->v.Call.starargs);
2462 if (!value) goto failed;
2463 if (PyObject_SetAttrString(result, "starargs", value) == -1)
2464 goto failed;
2465 Py_DECREF(value);
2466 value = ast2obj_expr(o->v.Call.kwargs);
2467 if (!value) goto failed;
2468 if (PyObject_SetAttrString(result, "kwargs", value) == -1)
2469 goto failed;
2470 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002471 break;
2472 case Repr_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002473 result = PyType_GenericNew(Repr_type, NULL, NULL);
2474 if (!result) goto failed;
2475 value = ast2obj_expr(o->v.Repr.value);
2476 if (!value) goto failed;
2477 if (PyObject_SetAttrString(result, "value", value) == -1)
2478 goto failed;
2479 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002480 break;
2481 case Num_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002482 result = PyType_GenericNew(Num_type, NULL, NULL);
2483 if (!result) goto failed;
2484 value = ast2obj_object(o->v.Num.n);
2485 if (!value) goto failed;
2486 if (PyObject_SetAttrString(result, "n", value) == -1)
2487 goto failed;
2488 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002489 break;
2490 case Str_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002491 result = PyType_GenericNew(Str_type, NULL, NULL);
2492 if (!result) goto failed;
2493 value = ast2obj_string(o->v.Str.s);
2494 if (!value) goto failed;
2495 if (PyObject_SetAttrString(result, "s", value) == -1)
2496 goto failed;
2497 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002498 break;
2499 case Attribute_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002500 result = PyType_GenericNew(Attribute_type, NULL, NULL);
2501 if (!result) goto failed;
2502 value = ast2obj_expr(o->v.Attribute.value);
2503 if (!value) goto failed;
2504 if (PyObject_SetAttrString(result, "value", value) == -1)
2505 goto failed;
2506 Py_DECREF(value);
2507 value = ast2obj_identifier(o->v.Attribute.attr);
2508 if (!value) goto failed;
2509 if (PyObject_SetAttrString(result, "attr", value) == -1)
2510 goto failed;
2511 Py_DECREF(value);
2512 value = ast2obj_expr_context(o->v.Attribute.ctx);
2513 if (!value) goto failed;
2514 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2515 goto failed;
2516 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002517 break;
2518 case Subscript_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002519 result = PyType_GenericNew(Subscript_type, NULL, NULL);
2520 if (!result) goto failed;
2521 value = ast2obj_expr(o->v.Subscript.value);
2522 if (!value) goto failed;
2523 if (PyObject_SetAttrString(result, "value", value) == -1)
2524 goto failed;
2525 Py_DECREF(value);
2526 value = ast2obj_slice(o->v.Subscript.slice);
2527 if (!value) goto failed;
2528 if (PyObject_SetAttrString(result, "slice", value) == -1)
2529 goto failed;
2530 Py_DECREF(value);
2531 value = ast2obj_expr_context(o->v.Subscript.ctx);
2532 if (!value) goto failed;
2533 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2534 goto failed;
2535 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002536 break;
2537 case Name_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002538 result = PyType_GenericNew(Name_type, NULL, NULL);
2539 if (!result) goto failed;
2540 value = ast2obj_identifier(o->v.Name.id);
2541 if (!value) goto failed;
2542 if (PyObject_SetAttrString(result, "id", value) == -1)
2543 goto failed;
2544 Py_DECREF(value);
2545 value = ast2obj_expr_context(o->v.Name.ctx);
2546 if (!value) goto failed;
2547 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2548 goto failed;
2549 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002550 break;
2551 case List_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002552 result = PyType_GenericNew(List_type, NULL, NULL);
2553 if (!result) goto failed;
2554 value = ast2obj_list(o->v.List.elts, ast2obj_expr);
2555 if (!value) goto failed;
2556 if (PyObject_SetAttrString(result, "elts", value) == -1)
2557 goto failed;
2558 Py_DECREF(value);
2559 value = ast2obj_expr_context(o->v.List.ctx);
2560 if (!value) goto failed;
2561 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2562 goto failed;
2563 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002564 break;
2565 case Tuple_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002566 result = PyType_GenericNew(Tuple_type, NULL, NULL);
2567 if (!result) goto failed;
2568 value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
2569 if (!value) goto failed;
2570 if (PyObject_SetAttrString(result, "elts", value) == -1)
2571 goto failed;
2572 Py_DECREF(value);
2573 value = ast2obj_expr_context(o->v.Tuple.ctx);
2574 if (!value) goto failed;
2575 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2576 goto failed;
2577 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002578 break;
2579 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002580 value = ast2obj_int(o->lineno);
2581 if (!value) goto failed;
2582 PyObject_SetAttrString(result, "lineno", value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002583 return result;
2584failed:
2585 Py_XDECREF(value);
2586 Py_XDECREF(result);
2587 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002588}
2589
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002590PyObject* ast2obj_expr_context(expr_context_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002591{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002592 switch(o) {
2593 case Load:
2594 Py_INCREF(Load_singleton);
2595 return Load_singleton;
2596 case Store:
2597 Py_INCREF(Store_singleton);
2598 return Store_singleton;
2599 case Del:
2600 Py_INCREF(Del_singleton);
2601 return Del_singleton;
2602 case AugLoad:
2603 Py_INCREF(AugLoad_singleton);
2604 return AugLoad_singleton;
2605 case AugStore:
2606 Py_INCREF(AugStore_singleton);
2607 return AugStore_singleton;
2608 case Param:
2609 Py_INCREF(Param_singleton);
2610 return Param_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002611 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002612 return NULL; /* cannot happen */
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002613}
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002614PyObject*
2615ast2obj_slice(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002616{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002617 slice_ty o = (slice_ty)_o;
2618 PyObject *result = NULL, *value = NULL;
2619 if (!o) {
2620 Py_INCREF(Py_None);
2621 return Py_None;
2622 }
2623
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002624 switch (o->kind) {
2625 case Ellipsis_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002626 result = PyType_GenericNew(Ellipsis_type, NULL, NULL);
2627 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002628 break;
2629 case Slice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002630 result = PyType_GenericNew(Slice_type, NULL, NULL);
2631 if (!result) goto failed;
2632 value = ast2obj_expr(o->v.Slice.lower);
2633 if (!value) goto failed;
2634 if (PyObject_SetAttrString(result, "lower", value) == -1)
2635 goto failed;
2636 Py_DECREF(value);
2637 value = ast2obj_expr(o->v.Slice.upper);
2638 if (!value) goto failed;
2639 if (PyObject_SetAttrString(result, "upper", value) == -1)
2640 goto failed;
2641 Py_DECREF(value);
2642 value = ast2obj_expr(o->v.Slice.step);
2643 if (!value) goto failed;
2644 if (PyObject_SetAttrString(result, "step", value) == -1)
2645 goto failed;
2646 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002647 break;
2648 case ExtSlice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002649 result = PyType_GenericNew(ExtSlice_type, NULL, NULL);
2650 if (!result) goto failed;
2651 value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice);
2652 if (!value) goto failed;
2653 if (PyObject_SetAttrString(result, "dims", value) == -1)
2654 goto failed;
2655 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002656 break;
2657 case Index_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002658 result = PyType_GenericNew(Index_type, NULL, NULL);
2659 if (!result) goto failed;
2660 value = ast2obj_expr(o->v.Index.value);
2661 if (!value) goto failed;
2662 if (PyObject_SetAttrString(result, "value", value) == -1)
2663 goto failed;
2664 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002665 break;
2666 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002667 return result;
2668failed:
2669 Py_XDECREF(value);
2670 Py_XDECREF(result);
2671 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002672}
2673
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002674PyObject* ast2obj_boolop(boolop_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002675{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002676 switch(o) {
2677 case And:
2678 Py_INCREF(And_singleton);
2679 return And_singleton;
2680 case Or:
2681 Py_INCREF(Or_singleton);
2682 return Or_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002683 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002684 return NULL; /* cannot happen */
2685}
2686PyObject* ast2obj_operator(operator_ty o)
2687{
2688 switch(o) {
2689 case Add:
2690 Py_INCREF(Add_singleton);
2691 return Add_singleton;
2692 case Sub:
2693 Py_INCREF(Sub_singleton);
2694 return Sub_singleton;
2695 case Mult:
2696 Py_INCREF(Mult_singleton);
2697 return Mult_singleton;
2698 case Div:
2699 Py_INCREF(Div_singleton);
2700 return Div_singleton;
2701 case Mod:
2702 Py_INCREF(Mod_singleton);
2703 return Mod_singleton;
2704 case Pow:
2705 Py_INCREF(Pow_singleton);
2706 return Pow_singleton;
2707 case LShift:
2708 Py_INCREF(LShift_singleton);
2709 return LShift_singleton;
2710 case RShift:
2711 Py_INCREF(RShift_singleton);
2712 return RShift_singleton;
2713 case BitOr:
2714 Py_INCREF(BitOr_singleton);
2715 return BitOr_singleton;
2716 case BitXor:
2717 Py_INCREF(BitXor_singleton);
2718 return BitXor_singleton;
2719 case BitAnd:
2720 Py_INCREF(BitAnd_singleton);
2721 return BitAnd_singleton;
2722 case FloorDiv:
2723 Py_INCREF(FloorDiv_singleton);
2724 return FloorDiv_singleton;
2725 }
2726 return NULL; /* cannot happen */
2727}
2728PyObject* ast2obj_unaryop(unaryop_ty o)
2729{
2730 switch(o) {
2731 case Invert:
2732 Py_INCREF(Invert_singleton);
2733 return Invert_singleton;
2734 case Not:
2735 Py_INCREF(Not_singleton);
2736 return Not_singleton;
2737 case UAdd:
2738 Py_INCREF(UAdd_singleton);
2739 return UAdd_singleton;
2740 case USub:
2741 Py_INCREF(USub_singleton);
2742 return USub_singleton;
2743 }
2744 return NULL; /* cannot happen */
2745}
2746PyObject* ast2obj_cmpop(cmpop_ty o)
2747{
2748 switch(o) {
2749 case Eq:
2750 Py_INCREF(Eq_singleton);
2751 return Eq_singleton;
2752 case NotEq:
2753 Py_INCREF(NotEq_singleton);
2754 return NotEq_singleton;
2755 case Lt:
2756 Py_INCREF(Lt_singleton);
2757 return Lt_singleton;
2758 case LtE:
2759 Py_INCREF(LtE_singleton);
2760 return LtE_singleton;
2761 case Gt:
2762 Py_INCREF(Gt_singleton);
2763 return Gt_singleton;
2764 case GtE:
2765 Py_INCREF(GtE_singleton);
2766 return GtE_singleton;
2767 case Is:
2768 Py_INCREF(Is_singleton);
2769 return Is_singleton;
2770 case IsNot:
2771 Py_INCREF(IsNot_singleton);
2772 return IsNot_singleton;
2773 case In:
2774 Py_INCREF(In_singleton);
2775 return In_singleton;
2776 case NotIn:
2777 Py_INCREF(NotIn_singleton);
2778 return NotIn_singleton;
2779 }
2780 return NULL; /* cannot happen */
2781}
2782PyObject*
2783ast2obj_comprehension(void* _o)
2784{
2785 comprehension_ty o = (comprehension_ty)_o;
2786 PyObject *result = NULL, *value = NULL;
2787 if (!o) {
2788 Py_INCREF(Py_None);
2789 return Py_None;
2790 }
2791
2792 result = PyType_GenericNew(comprehension_type, NULL, NULL);
2793 if (!result) return NULL;
2794 value = ast2obj_expr(o->target);
2795 if (!value) goto failed;
2796 if (PyObject_SetAttrString(result, "target", value) == -1)
2797 goto failed;
2798 Py_DECREF(value);
2799 value = ast2obj_expr(o->iter);
2800 if (!value) goto failed;
2801 if (PyObject_SetAttrString(result, "iter", value) == -1)
2802 goto failed;
2803 Py_DECREF(value);
2804 value = ast2obj_list(o->ifs, ast2obj_expr);
2805 if (!value) goto failed;
2806 if (PyObject_SetAttrString(result, "ifs", value) == -1)
2807 goto failed;
2808 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002809 return result;
2810failed:
2811 Py_XDECREF(value);
2812 Py_XDECREF(result);
2813 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002814}
2815
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002816PyObject*
2817ast2obj_excepthandler(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002818{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002819 excepthandler_ty o = (excepthandler_ty)_o;
2820 PyObject *result = NULL, *value = NULL;
2821 if (!o) {
2822 Py_INCREF(Py_None);
2823 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002824 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002825
2826 result = PyType_GenericNew(excepthandler_type, NULL, NULL);
2827 if (!result) return NULL;
2828 value = ast2obj_expr(o->type);
2829 if (!value) goto failed;
2830 if (PyObject_SetAttrString(result, "type", value) == -1)
2831 goto failed;
2832 Py_DECREF(value);
2833 value = ast2obj_expr(o->name);
2834 if (!value) goto failed;
2835 if (PyObject_SetAttrString(result, "name", value) == -1)
2836 goto failed;
2837 Py_DECREF(value);
2838 value = ast2obj_list(o->body, ast2obj_stmt);
2839 if (!value) goto failed;
2840 if (PyObject_SetAttrString(result, "body", value) == -1)
2841 goto failed;
2842 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002843 return result;
2844failed:
2845 Py_XDECREF(value);
2846 Py_XDECREF(result);
2847 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002848}
2849
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002850PyObject*
2851ast2obj_arguments(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002852{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002853 arguments_ty o = (arguments_ty)_o;
2854 PyObject *result = NULL, *value = NULL;
2855 if (!o) {
2856 Py_INCREF(Py_None);
2857 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002858 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002859
2860 result = PyType_GenericNew(arguments_type, NULL, NULL);
2861 if (!result) return NULL;
2862 value = ast2obj_list(o->args, ast2obj_expr);
2863 if (!value) goto failed;
2864 if (PyObject_SetAttrString(result, "args", value) == -1)
2865 goto failed;
2866 Py_DECREF(value);
2867 value = ast2obj_identifier(o->vararg);
2868 if (!value) goto failed;
2869 if (PyObject_SetAttrString(result, "vararg", value) == -1)
2870 goto failed;
2871 Py_DECREF(value);
2872 value = ast2obj_identifier(o->kwarg);
2873 if (!value) goto failed;
2874 if (PyObject_SetAttrString(result, "kwarg", value) == -1)
2875 goto failed;
2876 Py_DECREF(value);
2877 value = ast2obj_list(o->defaults, ast2obj_expr);
2878 if (!value) goto failed;
2879 if (PyObject_SetAttrString(result, "defaults", value) == -1)
2880 goto failed;
2881 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002882 return result;
2883failed:
2884 Py_XDECREF(value);
2885 Py_XDECREF(result);
2886 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002887}
2888
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002889PyObject*
2890ast2obj_keyword(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002891{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002892 keyword_ty o = (keyword_ty)_o;
2893 PyObject *result = NULL, *value = NULL;
2894 if (!o) {
2895 Py_INCREF(Py_None);
2896 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002897 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002898
2899 result = PyType_GenericNew(keyword_type, NULL, NULL);
2900 if (!result) return NULL;
2901 value = ast2obj_identifier(o->arg);
2902 if (!value) goto failed;
2903 if (PyObject_SetAttrString(result, "arg", value) == -1)
2904 goto failed;
2905 Py_DECREF(value);
2906 value = ast2obj_expr(o->value);
2907 if (!value) goto failed;
2908 if (PyObject_SetAttrString(result, "value", value) == -1)
2909 goto failed;
2910 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002911 return result;
2912failed:
2913 Py_XDECREF(value);
2914 Py_XDECREF(result);
2915 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002916}
2917
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002918PyObject*
2919ast2obj_alias(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002920{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002921 alias_ty o = (alias_ty)_o;
2922 PyObject *result = NULL, *value = NULL;
2923 if (!o) {
2924 Py_INCREF(Py_None);
2925 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002926 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002927
2928 result = PyType_GenericNew(alias_type, NULL, NULL);
2929 if (!result) return NULL;
2930 value = ast2obj_identifier(o->name);
2931 if (!value) goto failed;
2932 if (PyObject_SetAttrString(result, "name", value) == -1)
2933 goto failed;
2934 Py_DECREF(value);
2935 value = ast2obj_identifier(o->asname);
2936 if (!value) goto failed;
2937 if (PyObject_SetAttrString(result, "asname", value) == -1)
2938 goto failed;
2939 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002940 return result;
2941failed:
2942 Py_XDECREF(value);
2943 Py_XDECREF(result);
2944 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002945}
2946
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002947
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002948PyMODINIT_FUNC
2949init_ast(void)
2950{
2951 PyObject *m, *d;
2952 if (!init_types()) return;
2953 m = Py_InitModule3("_ast", NULL, NULL);
2954 if (!m) return;
2955 d = PyModule_GetDict(m);
2956 if (PyDict_SetItemString(d, "AST", (PyObject*)AST_type) < 0) return;
2957 if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)
2958 return;
Thomas Wouters34aa7ba2006-02-28 19:02:24 +00002959 if (PyModule_AddStringConstant(m, "__version__", "42649") < 0)
Martin v. Löwisace990c2006-02-28 00:32:31 +00002960 return;
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002961 if(PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return;
2962 if(PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0)
2963 return;
2964 if(PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type)
2965 < 0) return;
2966 if(PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) <
2967 0) return;
2968 if(PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return;
2969 if(PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return;
2970 if(PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type)
2971 < 0) return;
2972 if(PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0)
2973 return;
2974 if(PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0)
2975 return;
2976 if(PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0)
2977 return;
2978 if(PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0)
2979 return;
2980 if(PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) < 0)
2981 return;
2982 if(PyDict_SetItemString(d, "Print", (PyObject*)Print_type) < 0) return;
2983 if(PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return;
2984 if(PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return;
2985 if(PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return;
Guido van Rossumc2e20742006-02-27 22:32:47 +00002986 if(PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return;
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002987 if(PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return;
2988 if(PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) < 0)
2989 return;
2990 if(PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) <
2991 0) return;
2992 if(PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0)
2993 return;
2994 if(PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0)
2995 return;
2996 if(PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) <
2997 0) return;
2998 if(PyDict_SetItemString(d, "Exec", (PyObject*)Exec_type) < 0) return;
2999 if(PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0)
3000 return;
3001 if(PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return;
3002 if(PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return;
3003 if(PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return;
3004 if(PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0)
3005 return;
3006 if(PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return;
3007 if(PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0)
3008 return;
3009 if(PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return;
3010 if(PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0)
3011 return;
3012 if(PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0)
3013 return;
3014 if(PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return;
3015 if(PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return;
3016 if(PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0)
3017 return;
3018 if(PyDict_SetItemString(d, "GeneratorExp",
3019 (PyObject*)GeneratorExp_type) < 0) return;
3020 if(PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return;
3021 if(PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0)
3022 return;
3023 if(PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return;
3024 if(PyDict_SetItemString(d, "Repr", (PyObject*)Repr_type) < 0) return;
3025 if(PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return;
3026 if(PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return;
3027 if(PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) < 0)
3028 return;
3029 if(PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) < 0)
3030 return;
3031 if(PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return;
3032 if(PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return;
3033 if(PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return;
3034 if(PyDict_SetItemString(d, "expr_context",
3035 (PyObject*)expr_context_type) < 0) return;
3036 if(PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return;
3037 if(PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return;
3038 if(PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return;
3039 if(PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0)
3040 return;
3041 if(PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0)
3042 return;
3043 if(PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return;
3044 if(PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return;
3045 if(PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0)
3046 return;
3047 if(PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return;
3048 if(PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0)
3049 return;
3050 if(PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return;
3051 if(PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0)
3052 return;
3053 if(PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return;
3054 if(PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return;
3055 if(PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0)
3056 return;
3057 if(PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return;
3058 if(PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return;
3059 if(PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return;
3060 if(PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return;
3061 if(PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return;
3062 if(PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return;
3063 if(PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0)
3064 return;
3065 if(PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0)
3066 return;
3067 if(PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return;
3068 if(PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0)
3069 return;
3070 if(PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0)
3071 return;
3072 if(PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0)
3073 return;
3074 if(PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0)
3075 return;
3076 if(PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0)
3077 return;
3078 if(PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return;
3079 if(PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return;
3080 if(PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return;
3081 if(PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return;
3082 if(PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return;
3083 if(PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return;
3084 if(PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return;
3085 if(PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return;
3086 if(PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return;
3087 if(PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return;
3088 if(PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return;
3089 if(PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return;
3090 if(PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return;
3091 if(PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return;
3092 if(PyDict_SetItemString(d, "comprehension",
3093 (PyObject*)comprehension_type) < 0) return;
3094 if(PyDict_SetItemString(d, "excepthandler",
3095 (PyObject*)excepthandler_type) < 0) return;
3096 if(PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) < 0)
3097 return;
3098 if(PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0)
3099 return;
3100 if(PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return;
3101}
3102
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003103
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003104PyObject* PyAST_mod2obj(mod_ty t)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003105{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003106 init_types();
3107 return ast2obj_mod(t);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003108}
3109
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003110