blob: 68523e4904bca215d6e70d9dc1abefc1da2c5652 [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
Neal Norwitz53d960c2006-02-28 22:47:29 +00006static PyTypeObject* AST_type;
7static PyTypeObject *mod_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00008static PyObject* ast2obj_mod(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +00009static PyTypeObject *Module_type;
10static char *Module_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000011 "body",
12};
Neal Norwitz53d960c2006-02-28 22:47:29 +000013static PyTypeObject *Interactive_type;
14static char *Interactive_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000015 "body",
16};
Neal Norwitz53d960c2006-02-28 22:47:29 +000017static PyTypeObject *Expression_type;
18static char *Expression_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000019 "body",
20};
Neal Norwitz53d960c2006-02-28 22:47:29 +000021static PyTypeObject *Suite_type;
22static char *Suite_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000023 "body",
24};
Neal Norwitz53d960c2006-02-28 22:47:29 +000025static PyTypeObject *stmt_type;
26static char *stmt_attributes[] = {
Martin v. Löwis577b5b92006-02-27 15:23:19 +000027 "lineno",
Martin v. Löwis49c5da12006-03-01 22:49:05 +000028 "col_offset",
Martin v. Löwis577b5b92006-02-27 15:23:19 +000029};
Martin v. Löwisbd260da2006-02-26 19:42:26 +000030static PyObject* ast2obj_stmt(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +000031static PyTypeObject *FunctionDef_type;
32static char *FunctionDef_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000033 "name",
34 "args",
35 "body",
36 "decorators",
37};
Neal Norwitz53d960c2006-02-28 22:47:29 +000038static PyTypeObject *ClassDef_type;
39static char *ClassDef_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000040 "name",
41 "bases",
42 "body",
43};
Neal Norwitz53d960c2006-02-28 22:47:29 +000044static PyTypeObject *Return_type;
45static char *Return_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000046 "value",
47};
Neal Norwitz53d960c2006-02-28 22:47:29 +000048static PyTypeObject *Delete_type;
49static char *Delete_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000050 "targets",
51};
Neal Norwitz53d960c2006-02-28 22:47:29 +000052static PyTypeObject *Assign_type;
53static char *Assign_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000054 "targets",
55 "value",
56};
Neal Norwitz53d960c2006-02-28 22:47:29 +000057static PyTypeObject *AugAssign_type;
58static char *AugAssign_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000059 "target",
60 "op",
61 "value",
62};
Neal Norwitz53d960c2006-02-28 22:47:29 +000063static PyTypeObject *Print_type;
64static char *Print_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000065 "dest",
66 "values",
67 "nl",
68};
Neal Norwitz53d960c2006-02-28 22:47:29 +000069static PyTypeObject *For_type;
70static char *For_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000071 "target",
72 "iter",
73 "body",
74 "orelse",
75};
Neal Norwitz53d960c2006-02-28 22:47:29 +000076static PyTypeObject *While_type;
77static char *While_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000078 "test",
79 "body",
80 "orelse",
81};
Neal Norwitz53d960c2006-02-28 22:47:29 +000082static PyTypeObject *If_type;
83static char *If_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000084 "test",
85 "body",
86 "orelse",
87};
Neal Norwitz53d960c2006-02-28 22:47:29 +000088static PyTypeObject *With_type;
89static char *With_fields[]={
Guido van Rossumc2e20742006-02-27 22:32:47 +000090 "context_expr",
91 "optional_vars",
92 "body",
93};
Neal Norwitz53d960c2006-02-28 22:47:29 +000094static PyTypeObject *Raise_type;
95static char *Raise_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +000096 "type",
97 "inst",
98 "tback",
99};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000100static PyTypeObject *TryExcept_type;
101static char *TryExcept_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000102 "body",
103 "handlers",
104 "orelse",
105};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000106static PyTypeObject *TryFinally_type;
107static char *TryFinally_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000108 "body",
109 "finalbody",
110};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000111static PyTypeObject *Assert_type;
112static char *Assert_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000113 "test",
114 "msg",
115};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000116static PyTypeObject *Import_type;
117static char *Import_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000118 "names",
119};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000120static PyTypeObject *ImportFrom_type;
121static char *ImportFrom_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000122 "module",
123 "names",
Thomas Woutersf7f438b2006-02-28 16:09:29 +0000124 "level",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000125};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000126static PyTypeObject *Exec_type;
127static char *Exec_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000128 "body",
129 "globals",
130 "locals",
131};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000132static PyTypeObject *Global_type;
133static char *Global_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000134 "names",
135};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000136static PyTypeObject *Expr_type;
137static char *Expr_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000138 "value",
139};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000140static PyTypeObject *Pass_type;
141static PyTypeObject *Break_type;
142static PyTypeObject *Continue_type;
143static PyTypeObject *expr_type;
144static char *expr_attributes[] = {
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000145 "lineno",
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000146 "col_offset",
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000147};
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000148static PyObject* ast2obj_expr(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000149static PyTypeObject *BoolOp_type;
150static char *BoolOp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000151 "op",
152 "values",
153};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000154static PyTypeObject *BinOp_type;
155static char *BinOp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000156 "left",
157 "op",
158 "right",
159};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000160static PyTypeObject *UnaryOp_type;
161static char *UnaryOp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000162 "op",
163 "operand",
164};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000165static PyTypeObject *Lambda_type;
166static char *Lambda_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000167 "args",
168 "body",
169};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000170static PyTypeObject *IfExp_type;
171static char *IfExp_fields[]={
Thomas Woutersdca3b9c2006-02-27 00:24:13 +0000172 "test",
173 "body",
174 "orelse",
175};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000176static PyTypeObject *Dict_type;
177static char *Dict_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000178 "keys",
179 "values",
180};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000181static PyTypeObject *ListComp_type;
182static char *ListComp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000183 "elt",
184 "generators",
185};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000186static PyTypeObject *GeneratorExp_type;
187static char *GeneratorExp_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000188 "elt",
189 "generators",
190};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000191static PyTypeObject *Yield_type;
192static char *Yield_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000193 "value",
194};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000195static PyTypeObject *Compare_type;
196static char *Compare_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000197 "left",
198 "ops",
199 "comparators",
200};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000201static PyTypeObject *Call_type;
202static char *Call_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000203 "func",
204 "args",
205 "keywords",
206 "starargs",
207 "kwargs",
208};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000209static PyTypeObject *Num_type;
210static char *Num_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000211 "n",
212};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000213static PyTypeObject *Str_type;
214static char *Str_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000215 "s",
216};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000217static PyTypeObject *Attribute_type;
218static char *Attribute_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000219 "value",
220 "attr",
221 "ctx",
222};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000223static PyTypeObject *Subscript_type;
224static char *Subscript_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000225 "value",
226 "slice",
227 "ctx",
228};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000229static PyTypeObject *Name_type;
230static char *Name_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000231 "id",
232 "ctx",
233};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000234static PyTypeObject *List_type;
235static char *List_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000236 "elts",
237 "ctx",
238};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000239static PyTypeObject *Tuple_type;
240static char *Tuple_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000241 "elts",
242 "ctx",
243};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000244static PyTypeObject *expr_context_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000245static PyObject *Load_singleton, *Store_singleton, *Del_singleton,
246*AugLoad_singleton, *AugStore_singleton, *Param_singleton;
247static PyObject* ast2obj_expr_context(expr_context_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000248static PyTypeObject *Load_type;
249static PyTypeObject *Store_type;
250static PyTypeObject *Del_type;
251static PyTypeObject *AugLoad_type;
252static PyTypeObject *AugStore_type;
253static PyTypeObject *Param_type;
254static PyTypeObject *slice_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000255static PyObject* ast2obj_slice(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000256static PyTypeObject *Ellipsis_type;
257static PyTypeObject *Slice_type;
258static char *Slice_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000259 "lower",
260 "upper",
261 "step",
262};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000263static PyTypeObject *ExtSlice_type;
264static char *ExtSlice_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000265 "dims",
266};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000267static PyTypeObject *Index_type;
268static char *Index_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000269 "value",
270};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000271static PyTypeObject *boolop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000272static PyObject *And_singleton, *Or_singleton;
273static PyObject* ast2obj_boolop(boolop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000274static PyTypeObject *And_type;
275static PyTypeObject *Or_type;
276static PyTypeObject *operator_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000277static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton,
278*Div_singleton, *Mod_singleton, *Pow_singleton, *LShift_singleton,
279*RShift_singleton, *BitOr_singleton, *BitXor_singleton, *BitAnd_singleton,
280*FloorDiv_singleton;
281static PyObject* ast2obj_operator(operator_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000282static PyTypeObject *Add_type;
283static PyTypeObject *Sub_type;
284static PyTypeObject *Mult_type;
285static PyTypeObject *Div_type;
286static PyTypeObject *Mod_type;
287static PyTypeObject *Pow_type;
288static PyTypeObject *LShift_type;
289static PyTypeObject *RShift_type;
290static PyTypeObject *BitOr_type;
291static PyTypeObject *BitXor_type;
292static PyTypeObject *BitAnd_type;
293static PyTypeObject *FloorDiv_type;
294static PyTypeObject *unaryop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000295static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton,
296*USub_singleton;
297static PyObject* ast2obj_unaryop(unaryop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000298static PyTypeObject *Invert_type;
299static PyTypeObject *Not_type;
300static PyTypeObject *UAdd_type;
301static PyTypeObject *USub_type;
302static PyTypeObject *cmpop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000303static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton,
304*Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton,
305*NotIn_singleton;
306static PyObject* ast2obj_cmpop(cmpop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000307static PyTypeObject *Eq_type;
308static PyTypeObject *NotEq_type;
309static PyTypeObject *Lt_type;
310static PyTypeObject *LtE_type;
311static PyTypeObject *Gt_type;
312static PyTypeObject *GtE_type;
313static PyTypeObject *Is_type;
314static PyTypeObject *IsNot_type;
315static PyTypeObject *In_type;
316static PyTypeObject *NotIn_type;
317static PyTypeObject *comprehension_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000318static PyObject* ast2obj_comprehension(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000319static char *comprehension_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000320 "target",
321 "iter",
322 "ifs",
323};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000324static PyTypeObject *excepthandler_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000325static PyObject* ast2obj_excepthandler(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000326static char *excepthandler_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000327 "type",
328 "name",
329 "body",
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000330 "lineno",
331 "col_offset",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000332};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000333static PyTypeObject *arguments_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000334static PyObject* ast2obj_arguments(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000335static char *arguments_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000336 "args",
337 "vararg",
338 "kwarg",
339 "defaults",
340};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000341static PyTypeObject *keyword_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000342static PyObject* ast2obj_keyword(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000343static char *keyword_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000344 "arg",
345 "value",
346};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000347static PyTypeObject *alias_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000348static PyObject* ast2obj_alias(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000349static char *alias_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000350 "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{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000382 int i, result;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000383 PyObject *s, *l = PyList_New(num_fields);
384 if (!l) return 0;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000385 for(i = 0; i < num_fields; i++) {
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000386 s = PyString_FromString(attrs[i]);
387 if (!s) {
388 Py_DECREF(l);
389 return 0;
390 }
391 PyList_SET_ITEM(l, i, s);
392 }
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000393 result = PyObject_SetAttrString((PyObject*)type, "_attributes", l) >= 0;
394 Py_DECREF(l);
395 return result;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000396}
397
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000398static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
399{
400 int i, n = asdl_seq_LEN(seq);
401 PyObject *result = PyList_New(n);
402 PyObject *value;
403 if (!result)
404 return NULL;
405 for (i = 0; i < n; i++) {
406 value = func(asdl_seq_GET(seq, i));
407 if (!value) {
408 Py_DECREF(result);
409 return NULL;
410 }
411 PyList_SET_ITEM(result, i, value);
412 }
413 return result;
414}
415
416static PyObject* ast2obj_object(void *o)
417{
418 if (!o)
419 o = Py_None;
420 Py_INCREF((PyObject*)o);
421 return (PyObject*)o;
422}
423#define ast2obj_identifier ast2obj_object
424#define ast2obj_string ast2obj_object
425static PyObject* ast2obj_bool(bool b)
426{
427 return PyBool_FromLong(b);
428}
429
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000430static PyObject* ast2obj_int(bool b)
431{
432 return PyInt_FromLong(b);
433}
434
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000435static int init_types(void)
436{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000437 static int initialized;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000438 if (initialized) return 1;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000439 AST_type = make_type("AST", &PyBaseObject_Type, NULL, 0);
440 mod_type = make_type("mod", AST_type, NULL, 0);
441 if (!mod_type) return 0;
442 if (!add_attributes(mod_type, NULL, 0)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000443 Module_type = make_type("Module", mod_type, Module_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000444 if (!Module_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000445 Interactive_type = make_type("Interactive", mod_type,
446 Interactive_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000447 if (!Interactive_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000448 Expression_type = make_type("Expression", mod_type, Expression_fields,
449 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000450 if (!Expression_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000451 Suite_type = make_type("Suite", mod_type, Suite_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000452 if (!Suite_type) return 0;
453 stmt_type = make_type("stmt", AST_type, NULL, 0);
454 if (!stmt_type) return 0;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000455 if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000456 FunctionDef_type = make_type("FunctionDef", stmt_type,
457 FunctionDef_fields, 4);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000458 if (!FunctionDef_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000459 ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000460 if (!ClassDef_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000461 Return_type = make_type("Return", stmt_type, Return_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000462 if (!Return_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000463 Delete_type = make_type("Delete", stmt_type, Delete_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000464 if (!Delete_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000465 Assign_type = make_type("Assign", stmt_type, Assign_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000466 if (!Assign_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000467 AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000468 if (!AugAssign_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000469 Print_type = make_type("Print", stmt_type, Print_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000470 if (!Print_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000471 For_type = make_type("For", stmt_type, For_fields, 4);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000472 if (!For_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000473 While_type = make_type("While", stmt_type, While_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000474 if (!While_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000475 If_type = make_type("If", stmt_type, If_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000476 if (!If_type) return 0;
Guido van Rossumc2e20742006-02-27 22:32:47 +0000477 With_type = make_type("With", stmt_type, With_fields, 3);
478 if (!With_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000479 Raise_type = make_type("Raise", stmt_type, Raise_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000480 if (!Raise_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000481 TryExcept_type = make_type("TryExcept", stmt_type, TryExcept_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000482 if (!TryExcept_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000483 TryFinally_type = make_type("TryFinally", stmt_type, TryFinally_fields,
484 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000485 if (!TryFinally_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000486 Assert_type = make_type("Assert", stmt_type, Assert_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000487 if (!Assert_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000488 Import_type = make_type("Import", stmt_type, Import_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000489 if (!Import_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000490 ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields,
Thomas Woutersf7f438b2006-02-28 16:09:29 +0000491 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000492 if (!ImportFrom_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000493 Exec_type = make_type("Exec", stmt_type, Exec_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000494 if (!Exec_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000495 Global_type = make_type("Global", stmt_type, Global_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000496 if (!Global_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000497 Expr_type = make_type("Expr", stmt_type, Expr_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000498 if (!Expr_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000499 Pass_type = make_type("Pass", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000500 if (!Pass_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000501 Break_type = make_type("Break", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000502 if (!Break_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000503 Continue_type = make_type("Continue", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000504 if (!Continue_type) return 0;
505 expr_type = make_type("expr", AST_type, NULL, 0);
506 if (!expr_type) return 0;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000507 if (!add_attributes(expr_type, expr_attributes, 2)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000508 BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000509 if (!BoolOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000510 BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000511 if (!BinOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000512 UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000513 if (!UnaryOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000514 Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000515 if (!Lambda_type) return 0;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +0000516 IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000517 if (!IfExp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000518 Dict_type = make_type("Dict", expr_type, Dict_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000519 if (!Dict_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000520 ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000521 if (!ListComp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000522 GeneratorExp_type = make_type("GeneratorExp", expr_type,
523 GeneratorExp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000524 if (!GeneratorExp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000525 Yield_type = make_type("Yield", expr_type, Yield_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000526 if (!Yield_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000527 Compare_type = make_type("Compare", expr_type, Compare_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000528 if (!Compare_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000529 Call_type = make_type("Call", expr_type, Call_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000530 if (!Call_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,
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000711 excepthandler_fields, 5);
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 *
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000786 decorators, int lineno, int col_offset, 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;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000810 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000811 return p;
812}
813
814stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000815ClassDef(identifier name, asdl_seq * bases, asdl_seq * body, int lineno, int
816 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000817{
818 stmt_ty p;
819 if (!name) {
820 PyErr_SetString(PyExc_ValueError,
821 "field name is required for ClassDef");
822 return NULL;
823 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000824 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000825 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000826 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000827 return NULL;
828 }
829 p->kind = ClassDef_kind;
830 p->v.ClassDef.name = name;
831 p->v.ClassDef.bases = bases;
832 p->v.ClassDef.body = body;
833 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000834 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000835 return p;
836}
837
838stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000839Return(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000840{
841 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000842 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000843 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000844 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000845 return NULL;
846 }
847 p->kind = Return_kind;
848 p->v.Return.value = value;
849 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000850 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000851 return p;
852}
853
854stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000855Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000856{
857 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000858 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000859 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000860 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000861 return NULL;
862 }
863 p->kind = Delete_kind;
864 p->v.Delete.targets = targets;
865 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000866 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000867 return p;
868}
869
870stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000871Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena
872 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000873{
874 stmt_ty p;
875 if (!value) {
876 PyErr_SetString(PyExc_ValueError,
877 "field value is required for Assign");
878 return NULL;
879 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000880 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000881 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000882 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000883 return NULL;
884 }
885 p->kind = Assign_kind;
886 p->v.Assign.targets = targets;
887 p->v.Assign.value = value;
888 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000889 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000890 return p;
891}
892
893stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000894AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
895 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000896{
897 stmt_ty p;
898 if (!target) {
899 PyErr_SetString(PyExc_ValueError,
900 "field target is required for AugAssign");
901 return NULL;
902 }
903 if (!op) {
904 PyErr_SetString(PyExc_ValueError,
905 "field op is required for AugAssign");
906 return NULL;
907 }
908 if (!value) {
909 PyErr_SetString(PyExc_ValueError,
910 "field value is required for AugAssign");
911 return NULL;
912 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000913 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000914 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000915 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000916 return NULL;
917 }
918 p->kind = AugAssign_kind;
919 p->v.AugAssign.target = target;
920 p->v.AugAssign.op = op;
921 p->v.AugAssign.value = value;
922 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000923 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000924 return p;
925}
926
927stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000928Print(expr_ty dest, asdl_seq * values, bool nl, int lineno, int col_offset,
929 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000930{
931 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000932 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000933 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000934 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000935 return NULL;
936 }
937 p->kind = Print_kind;
938 p->v.Print.dest = dest;
939 p->v.Print.values = values;
940 p->v.Print.nl = nl;
941 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000942 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000943 return p;
944}
945
946stmt_ty
947For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000948 lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000949{
950 stmt_ty p;
951 if (!target) {
952 PyErr_SetString(PyExc_ValueError,
953 "field target is required for For");
954 return NULL;
955 }
956 if (!iter) {
957 PyErr_SetString(PyExc_ValueError,
958 "field iter is required for For");
959 return NULL;
960 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000961 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000962 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000963 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000964 return NULL;
965 }
966 p->kind = For_kind;
967 p->v.For.target = target;
968 p->v.For.iter = iter;
969 p->v.For.body = body;
970 p->v.For.orelse = orelse;
971 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000972 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000973 return p;
974}
975
976stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000977While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
978 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000979{
980 stmt_ty p;
981 if (!test) {
982 PyErr_SetString(PyExc_ValueError,
983 "field test is required for While");
984 return NULL;
985 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000986 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000987 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000988 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000989 return NULL;
990 }
991 p->kind = While_kind;
992 p->v.While.test = test;
993 p->v.While.body = body;
994 p->v.While.orelse = orelse;
995 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000996 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000997 return p;
998}
999
1000stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001001If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
1002 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001003{
1004 stmt_ty p;
1005 if (!test) {
1006 PyErr_SetString(PyExc_ValueError,
1007 "field test is required for If");
1008 return NULL;
1009 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001010 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001011 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001012 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001013 return NULL;
1014 }
1015 p->kind = If_kind;
1016 p->v.If.test = test;
1017 p->v.If.body = body;
1018 p->v.If.orelse = orelse;
1019 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001020 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001021 return p;
1022}
1023
1024stmt_ty
Guido van Rossumc2e20742006-02-27 22:32:47 +00001025With(expr_ty context_expr, expr_ty optional_vars, asdl_seq * body, int lineno,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001026 int col_offset, PyArena *arena)
Guido van Rossumc2e20742006-02-27 22:32:47 +00001027{
1028 stmt_ty p;
1029 if (!context_expr) {
1030 PyErr_SetString(PyExc_ValueError,
1031 "field context_expr is required for With");
1032 return NULL;
1033 }
1034 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1035 if (!p) {
1036 PyErr_NoMemory();
1037 return NULL;
1038 }
1039 p->kind = With_kind;
1040 p->v.With.context_expr = context_expr;
1041 p->v.With.optional_vars = optional_vars;
1042 p->v.With.body = body;
1043 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001044 p->col_offset = col_offset;
Guido van Rossumc2e20742006-02-27 22:32:47 +00001045 return p;
1046}
1047
1048stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001049Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno, int col_offset,
1050 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001051{
1052 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001053 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001054 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001055 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001056 return NULL;
1057 }
1058 p->kind = Raise_kind;
1059 p->v.Raise.type = type;
1060 p->v.Raise.inst = inst;
1061 p->v.Raise.tback = tback;
1062 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001063 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001064 return p;
1065}
1066
1067stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001068TryExcept(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, int lineno,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001069 int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001070{
1071 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001072 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001073 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001074 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001075 return NULL;
1076 }
1077 p->kind = TryExcept_kind;
1078 p->v.TryExcept.body = body;
1079 p->v.TryExcept.handlers = handlers;
1080 p->v.TryExcept.orelse = orelse;
1081 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001082 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001083 return p;
1084}
1085
1086stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001087TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, int col_offset,
1088 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001089{
1090 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001091 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001092 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001093 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001094 return NULL;
1095 }
1096 p->kind = TryFinally_kind;
1097 p->v.TryFinally.body = body;
1098 p->v.TryFinally.finalbody = finalbody;
1099 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001100 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001101 return p;
1102}
1103
1104stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001105Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001106{
1107 stmt_ty p;
1108 if (!test) {
1109 PyErr_SetString(PyExc_ValueError,
1110 "field test is required for Assert");
1111 return NULL;
1112 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001113 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001114 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001115 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001116 return NULL;
1117 }
1118 p->kind = Assert_kind;
1119 p->v.Assert.test = test;
1120 p->v.Assert.msg = msg;
1121 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001122 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001123 return p;
1124}
1125
1126stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001127Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001128{
1129 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001130 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001131 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001132 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001133 return NULL;
1134 }
1135 p->kind = Import_kind;
1136 p->v.Import.names = names;
1137 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001138 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001139 return p;
1140}
1141
1142stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001143ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int
1144 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001145{
1146 stmt_ty p;
1147 if (!module) {
1148 PyErr_SetString(PyExc_ValueError,
1149 "field module is required for ImportFrom");
1150 return NULL;
1151 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001152 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001153 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001154 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001155 return NULL;
1156 }
1157 p->kind = ImportFrom_kind;
1158 p->v.ImportFrom.module = module;
1159 p->v.ImportFrom.names = names;
Thomas Woutersf7f438b2006-02-28 16:09:29 +00001160 p->v.ImportFrom.level = level;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001161 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001162 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001163 return p;
1164}
1165
1166stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001167Exec(expr_ty body, expr_ty globals, expr_ty locals, int lineno, int col_offset,
1168 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001169{
1170 stmt_ty p;
1171 if (!body) {
1172 PyErr_SetString(PyExc_ValueError,
1173 "field body is required for Exec");
1174 return NULL;
1175 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001176 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001177 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001178 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001179 return NULL;
1180 }
1181 p->kind = Exec_kind;
1182 p->v.Exec.body = body;
1183 p->v.Exec.globals = globals;
1184 p->v.Exec.locals = locals;
1185 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001186 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001187 return p;
1188}
1189
1190stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001191Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001192{
1193 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001194 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001195 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001196 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001197 return NULL;
1198 }
1199 p->kind = Global_kind;
1200 p->v.Global.names = names;
1201 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001202 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001203 return p;
1204}
1205
1206stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001207Expr(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001208{
1209 stmt_ty p;
1210 if (!value) {
1211 PyErr_SetString(PyExc_ValueError,
1212 "field value is required for Expr");
1213 return NULL;
1214 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001215 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001216 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001217 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001218 return NULL;
1219 }
1220 p->kind = Expr_kind;
1221 p->v.Expr.value = value;
1222 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001223 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001224 return p;
1225}
1226
1227stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001228Pass(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001229{
1230 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001231 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001232 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001233 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001234 return NULL;
1235 }
1236 p->kind = Pass_kind;
1237 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001238 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001239 return p;
1240}
1241
1242stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001243Break(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001244{
1245 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001246 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001247 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001248 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001249 return NULL;
1250 }
1251 p->kind = Break_kind;
1252 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001253 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001254 return p;
1255}
1256
1257stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001258Continue(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001259{
1260 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001261 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001262 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001263 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001264 return NULL;
1265 }
1266 p->kind = Continue_kind;
1267 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001268 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001269 return p;
1270}
1271
1272expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001273BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena
1274 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001275{
1276 expr_ty p;
1277 if (!op) {
1278 PyErr_SetString(PyExc_ValueError,
1279 "field op is required for BoolOp");
1280 return NULL;
1281 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001282 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001283 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001284 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001285 return NULL;
1286 }
1287 p->kind = BoolOp_kind;
1288 p->v.BoolOp.op = op;
1289 p->v.BoolOp.values = values;
1290 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001291 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001292 return p;
1293}
1294
1295expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001296BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset,
1297 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001298{
1299 expr_ty p;
1300 if (!left) {
1301 PyErr_SetString(PyExc_ValueError,
1302 "field left is required for BinOp");
1303 return NULL;
1304 }
1305 if (!op) {
1306 PyErr_SetString(PyExc_ValueError,
1307 "field op is required for BinOp");
1308 return NULL;
1309 }
1310 if (!right) {
1311 PyErr_SetString(PyExc_ValueError,
1312 "field right is required for BinOp");
1313 return NULL;
1314 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001315 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001316 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001317 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001318 return NULL;
1319 }
1320 p->kind = BinOp_kind;
1321 p->v.BinOp.left = left;
1322 p->v.BinOp.op = op;
1323 p->v.BinOp.right = right;
1324 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001325 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001326 return p;
1327}
1328
1329expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001330UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena
1331 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001332{
1333 expr_ty p;
1334 if (!op) {
1335 PyErr_SetString(PyExc_ValueError,
1336 "field op is required for UnaryOp");
1337 return NULL;
1338 }
1339 if (!operand) {
1340 PyErr_SetString(PyExc_ValueError,
1341 "field operand is required for UnaryOp");
1342 return NULL;
1343 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001344 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001345 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001346 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001347 return NULL;
1348 }
1349 p->kind = UnaryOp_kind;
1350 p->v.UnaryOp.op = op;
1351 p->v.UnaryOp.operand = operand;
1352 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001353 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001354 return p;
1355}
1356
1357expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001358Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena
1359 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001360{
1361 expr_ty p;
1362 if (!args) {
1363 PyErr_SetString(PyExc_ValueError,
1364 "field args is required for Lambda");
1365 return NULL;
1366 }
1367 if (!body) {
1368 PyErr_SetString(PyExc_ValueError,
1369 "field body is required for Lambda");
1370 return NULL;
1371 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001372 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001373 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001374 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001375 return NULL;
1376 }
1377 p->kind = Lambda_kind;
1378 p->v.Lambda.args = args;
1379 p->v.Lambda.body = body;
1380 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001381 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001382 return p;
1383}
1384
1385expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001386IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset,
1387 PyArena *arena)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001388{
1389 expr_ty p;
1390 if (!test) {
1391 PyErr_SetString(PyExc_ValueError,
1392 "field test is required for IfExp");
1393 return NULL;
1394 }
1395 if (!body) {
1396 PyErr_SetString(PyExc_ValueError,
1397 "field body is required for IfExp");
1398 return NULL;
1399 }
1400 if (!orelse) {
1401 PyErr_SetString(PyExc_ValueError,
1402 "field orelse is required for IfExp");
1403 return NULL;
1404 }
1405 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1406 if (!p) {
1407 PyErr_NoMemory();
1408 return NULL;
1409 }
1410 p->kind = IfExp_kind;
1411 p->v.IfExp.test = test;
1412 p->v.IfExp.body = body;
1413 p->v.IfExp.orelse = orelse;
1414 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001415 p->col_offset = col_offset;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001416 return p;
1417}
1418
1419expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001420Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena
1421 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001422{
1423 expr_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001424 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001425 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001426 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001427 return NULL;
1428 }
1429 p->kind = Dict_kind;
1430 p->v.Dict.keys = keys;
1431 p->v.Dict.values = values;
1432 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001433 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001434 return p;
1435}
1436
1437expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001438ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1439 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001440{
1441 expr_ty p;
1442 if (!elt) {
1443 PyErr_SetString(PyExc_ValueError,
1444 "field elt is required for ListComp");
1445 return NULL;
1446 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001447 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001448 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001449 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001450 return NULL;
1451 }
1452 p->kind = ListComp_kind;
1453 p->v.ListComp.elt = elt;
1454 p->v.ListComp.generators = generators;
1455 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001456 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001457 return p;
1458}
1459
1460expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001461GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1462 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001463{
1464 expr_ty p;
1465 if (!elt) {
1466 PyErr_SetString(PyExc_ValueError,
1467 "field elt is required for GeneratorExp");
1468 return NULL;
1469 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001470 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001471 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001472 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001473 return NULL;
1474 }
1475 p->kind = GeneratorExp_kind;
1476 p->v.GeneratorExp.elt = elt;
1477 p->v.GeneratorExp.generators = generators;
1478 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001479 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001480 return p;
1481}
1482
1483expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001484Yield(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001485{
1486 expr_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001487 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001488 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001489 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001490 return NULL;
1491 }
1492 p->kind = Yield_kind;
1493 p->v.Yield.value = value;
1494 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001495 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001496 return p;
1497}
1498
1499expr_ty
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001500Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno,
1501 int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001502{
1503 expr_ty p;
1504 if (!left) {
1505 PyErr_SetString(PyExc_ValueError,
1506 "field left is required for Compare");
1507 return NULL;
1508 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001509 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001510 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001511 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001512 return NULL;
1513 }
1514 p->kind = Compare_kind;
1515 p->v.Compare.left = left;
1516 p->v.Compare.ops = ops;
1517 p->v.Compare.comparators = comparators;
1518 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001519 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001520 return p;
1521}
1522
1523expr_ty
1524Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, expr_ty starargs,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001525 expr_ty kwargs, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001526{
1527 expr_ty p;
1528 if (!func) {
1529 PyErr_SetString(PyExc_ValueError,
1530 "field func is required for Call");
1531 return NULL;
1532 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001533 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001534 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001535 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001536 return NULL;
1537 }
1538 p->kind = Call_kind;
1539 p->v.Call.func = func;
1540 p->v.Call.args = args;
1541 p->v.Call.keywords = keywords;
1542 p->v.Call.starargs = starargs;
1543 p->v.Call.kwargs = kwargs;
1544 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001545 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001546 return p;
1547}
1548
1549expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001550Num(object n, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001551{
1552 expr_ty p;
1553 if (!n) {
1554 PyErr_SetString(PyExc_ValueError,
1555 "field n is required for Num");
1556 return NULL;
1557 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001558 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001559 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001560 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001561 return NULL;
1562 }
1563 p->kind = Num_kind;
1564 p->v.Num.n = n;
1565 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001566 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001567 return p;
1568}
1569
1570expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001571Str(string s, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001572{
1573 expr_ty p;
1574 if (!s) {
1575 PyErr_SetString(PyExc_ValueError,
1576 "field s is required for Str");
1577 return NULL;
1578 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001579 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001580 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001581 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001582 return NULL;
1583 }
1584 p->kind = Str_kind;
1585 p->v.Str.s = s;
1586 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001587 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001588 return p;
1589}
1590
1591expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001592Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int
1593 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001594{
1595 expr_ty p;
1596 if (!value) {
1597 PyErr_SetString(PyExc_ValueError,
1598 "field value is required for Attribute");
1599 return NULL;
1600 }
1601 if (!attr) {
1602 PyErr_SetString(PyExc_ValueError,
1603 "field attr is required for Attribute");
1604 return NULL;
1605 }
1606 if (!ctx) {
1607 PyErr_SetString(PyExc_ValueError,
1608 "field ctx is required for Attribute");
1609 return NULL;
1610 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001611 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001612 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001613 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001614 return NULL;
1615 }
1616 p->kind = Attribute_kind;
1617 p->v.Attribute.value = value;
1618 p->v.Attribute.attr = attr;
1619 p->v.Attribute.ctx = ctx;
1620 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001621 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001622 return p;
1623}
1624
1625expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001626Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int
1627 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001628{
1629 expr_ty p;
1630 if (!value) {
1631 PyErr_SetString(PyExc_ValueError,
1632 "field value is required for Subscript");
1633 return NULL;
1634 }
1635 if (!slice) {
1636 PyErr_SetString(PyExc_ValueError,
1637 "field slice is required for Subscript");
1638 return NULL;
1639 }
1640 if (!ctx) {
1641 PyErr_SetString(PyExc_ValueError,
1642 "field ctx is required for Subscript");
1643 return NULL;
1644 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001645 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001646 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001647 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001648 return NULL;
1649 }
1650 p->kind = Subscript_kind;
1651 p->v.Subscript.value = value;
1652 p->v.Subscript.slice = slice;
1653 p->v.Subscript.ctx = ctx;
1654 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001655 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001656 return p;
1657}
1658
1659expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001660Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena
1661 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001662{
1663 expr_ty p;
1664 if (!id) {
1665 PyErr_SetString(PyExc_ValueError,
1666 "field id is required for Name");
1667 return NULL;
1668 }
1669 if (!ctx) {
1670 PyErr_SetString(PyExc_ValueError,
1671 "field ctx is required for Name");
1672 return NULL;
1673 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001674 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001675 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001676 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001677 return NULL;
1678 }
1679 p->kind = Name_kind;
1680 p->v.Name.id = id;
1681 p->v.Name.ctx = ctx;
1682 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001683 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001684 return p;
1685}
1686
1687expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001688List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1689 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001690{
1691 expr_ty p;
1692 if (!ctx) {
1693 PyErr_SetString(PyExc_ValueError,
1694 "field ctx is required for List");
1695 return NULL;
1696 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001697 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001698 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001699 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001700 return NULL;
1701 }
1702 p->kind = List_kind;
1703 p->v.List.elts = elts;
1704 p->v.List.ctx = ctx;
1705 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001706 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001707 return p;
1708}
1709
1710expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001711Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1712 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001713{
1714 expr_ty p;
1715 if (!ctx) {
1716 PyErr_SetString(PyExc_ValueError,
1717 "field ctx is required for Tuple");
1718 return NULL;
1719 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001720 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001721 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001722 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001723 return NULL;
1724 }
1725 p->kind = Tuple_kind;
1726 p->v.Tuple.elts = elts;
1727 p->v.Tuple.ctx = ctx;
1728 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001729 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001730 return p;
1731}
1732
1733slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001734Ellipsis(PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001735{
1736 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001737 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001738 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001739 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001740 return NULL;
1741 }
1742 p->kind = Ellipsis_kind;
1743 return p;
1744}
1745
1746slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001747Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001748{
1749 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001750 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001751 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001752 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001753 return NULL;
1754 }
1755 p->kind = Slice_kind;
1756 p->v.Slice.lower = lower;
1757 p->v.Slice.upper = upper;
1758 p->v.Slice.step = step;
1759 return p;
1760}
1761
1762slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001763ExtSlice(asdl_seq * dims, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001764{
1765 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001766 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001767 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001768 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001769 return NULL;
1770 }
1771 p->kind = ExtSlice_kind;
1772 p->v.ExtSlice.dims = dims;
1773 return p;
1774}
1775
1776slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001777Index(expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001778{
1779 slice_ty p;
1780 if (!value) {
1781 PyErr_SetString(PyExc_ValueError,
1782 "field value is required for Index");
1783 return NULL;
1784 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001785 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001786 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001787 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001788 return NULL;
1789 }
1790 p->kind = Index_kind;
1791 p->v.Index.value = value;
1792 return p;
1793}
1794
1795comprehension_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001796comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001797{
1798 comprehension_ty p;
1799 if (!target) {
1800 PyErr_SetString(PyExc_ValueError,
1801 "field target is required for comprehension");
1802 return NULL;
1803 }
1804 if (!iter) {
1805 PyErr_SetString(PyExc_ValueError,
1806 "field iter is required for comprehension");
1807 return NULL;
1808 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001809 p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001810 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001811 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001812 return NULL;
1813 }
1814 p->target = target;
1815 p->iter = iter;
1816 p->ifs = ifs;
1817 return p;
1818}
1819
1820excepthandler_ty
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001821excepthandler(expr_ty type, expr_ty name, asdl_seq * body, int lineno, int
1822 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001823{
1824 excepthandler_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001825 p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001826 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001827 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001828 return NULL;
1829 }
1830 p->type = type;
1831 p->name = name;
1832 p->body = body;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001833 p->lineno = lineno;
1834 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001835 return p;
1836}
1837
1838arguments_ty
1839arguments(asdl_seq * args, identifier vararg, identifier kwarg, asdl_seq *
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001840 defaults, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001841{
1842 arguments_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001843 p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001844 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001845 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001846 return NULL;
1847 }
1848 p->args = args;
1849 p->vararg = vararg;
1850 p->kwarg = kwarg;
1851 p->defaults = defaults;
1852 return p;
1853}
1854
1855keyword_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001856keyword(identifier arg, expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001857{
1858 keyword_ty p;
1859 if (!arg) {
1860 PyErr_SetString(PyExc_ValueError,
1861 "field arg is required for keyword");
1862 return NULL;
1863 }
1864 if (!value) {
1865 PyErr_SetString(PyExc_ValueError,
1866 "field value is required for keyword");
1867 return NULL;
1868 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001869 p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001870 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001871 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001872 return NULL;
1873 }
1874 p->arg = arg;
1875 p->value = value;
1876 return p;
1877}
1878
1879alias_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001880alias(identifier name, identifier asname, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001881{
1882 alias_ty p;
1883 if (!name) {
1884 PyErr_SetString(PyExc_ValueError,
1885 "field name is required for alias");
1886 return NULL;
1887 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001888 p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001889 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001890 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001891 return NULL;
1892 }
1893 p->name = name;
1894 p->asname = asname;
1895 return p;
1896}
1897
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001898
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001899PyObject*
1900ast2obj_mod(void* _o)
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001901{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001902 mod_ty o = (mod_ty)_o;
1903 PyObject *result = NULL, *value = NULL;
1904 if (!o) {
1905 Py_INCREF(Py_None);
1906 return Py_None;
1907 }
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001908
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001909 switch (o->kind) {
1910 case Module_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001911 result = PyType_GenericNew(Module_type, NULL, NULL);
1912 if (!result) goto failed;
1913 value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
1914 if (!value) goto failed;
1915 if (PyObject_SetAttrString(result, "body", value) == -1)
1916 goto failed;
1917 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001918 break;
1919 case Interactive_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001920 result = PyType_GenericNew(Interactive_type, NULL, NULL);
1921 if (!result) goto failed;
1922 value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
1923 if (!value) goto failed;
1924 if (PyObject_SetAttrString(result, "body", value) == -1)
1925 goto failed;
1926 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001927 break;
1928 case Expression_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001929 result = PyType_GenericNew(Expression_type, NULL, NULL);
1930 if (!result) goto failed;
1931 value = ast2obj_expr(o->v.Expression.body);
1932 if (!value) goto failed;
1933 if (PyObject_SetAttrString(result, "body", value) == -1)
1934 goto failed;
1935 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001936 break;
1937 case Suite_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001938 result = PyType_GenericNew(Suite_type, NULL, NULL);
1939 if (!result) goto failed;
1940 value = ast2obj_list(o->v.Suite.body, ast2obj_stmt);
1941 if (!value) goto failed;
1942 if (PyObject_SetAttrString(result, "body", value) == -1)
1943 goto failed;
1944 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001945 break;
1946 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001947 return result;
1948failed:
1949 Py_XDECREF(value);
1950 Py_XDECREF(result);
1951 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001952}
1953
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001954PyObject*
1955ast2obj_stmt(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001956{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001957 stmt_ty o = (stmt_ty)_o;
1958 PyObject *result = NULL, *value = NULL;
1959 if (!o) {
1960 Py_INCREF(Py_None);
1961 return Py_None;
1962 }
1963
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001964 switch (o->kind) {
1965 case FunctionDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001966 result = PyType_GenericNew(FunctionDef_type, NULL, NULL);
1967 if (!result) goto failed;
1968 value = ast2obj_identifier(o->v.FunctionDef.name);
1969 if (!value) goto failed;
1970 if (PyObject_SetAttrString(result, "name", value) == -1)
1971 goto failed;
1972 Py_DECREF(value);
1973 value = ast2obj_arguments(o->v.FunctionDef.args);
1974 if (!value) goto failed;
1975 if (PyObject_SetAttrString(result, "args", value) == -1)
1976 goto failed;
1977 Py_DECREF(value);
1978 value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
1979 if (!value) goto failed;
1980 if (PyObject_SetAttrString(result, "body", value) == -1)
1981 goto failed;
1982 Py_DECREF(value);
1983 value = ast2obj_list(o->v.FunctionDef.decorators, ast2obj_expr);
1984 if (!value) goto failed;
1985 if (PyObject_SetAttrString(result, "decorators", value) == -1)
1986 goto failed;
1987 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001988 break;
1989 case ClassDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001990 result = PyType_GenericNew(ClassDef_type, NULL, NULL);
1991 if (!result) goto failed;
1992 value = ast2obj_identifier(o->v.ClassDef.name);
1993 if (!value) goto failed;
1994 if (PyObject_SetAttrString(result, "name", value) == -1)
1995 goto failed;
1996 Py_DECREF(value);
1997 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
1998 if (!value) goto failed;
1999 if (PyObject_SetAttrString(result, "bases", value) == -1)
2000 goto failed;
2001 Py_DECREF(value);
2002 value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
2003 if (!value) goto failed;
2004 if (PyObject_SetAttrString(result, "body", value) == -1)
2005 goto failed;
2006 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002007 break;
2008 case Return_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002009 result = PyType_GenericNew(Return_type, NULL, NULL);
2010 if (!result) goto failed;
2011 value = ast2obj_expr(o->v.Return.value);
2012 if (!value) goto failed;
2013 if (PyObject_SetAttrString(result, "value", value) == -1)
2014 goto failed;
2015 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002016 break;
2017 case Delete_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002018 result = PyType_GenericNew(Delete_type, NULL, NULL);
2019 if (!result) goto failed;
2020 value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
2021 if (!value) goto failed;
2022 if (PyObject_SetAttrString(result, "targets", value) == -1)
2023 goto failed;
2024 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002025 break;
2026 case Assign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002027 result = PyType_GenericNew(Assign_type, NULL, NULL);
2028 if (!result) goto failed;
2029 value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
2030 if (!value) goto failed;
2031 if (PyObject_SetAttrString(result, "targets", value) == -1)
2032 goto failed;
2033 Py_DECREF(value);
2034 value = ast2obj_expr(o->v.Assign.value);
2035 if (!value) goto failed;
2036 if (PyObject_SetAttrString(result, "value", value) == -1)
2037 goto failed;
2038 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002039 break;
2040 case AugAssign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002041 result = PyType_GenericNew(AugAssign_type, NULL, NULL);
2042 if (!result) goto failed;
2043 value = ast2obj_expr(o->v.AugAssign.target);
2044 if (!value) goto failed;
2045 if (PyObject_SetAttrString(result, "target", value) == -1)
2046 goto failed;
2047 Py_DECREF(value);
2048 value = ast2obj_operator(o->v.AugAssign.op);
2049 if (!value) goto failed;
2050 if (PyObject_SetAttrString(result, "op", value) == -1)
2051 goto failed;
2052 Py_DECREF(value);
2053 value = ast2obj_expr(o->v.AugAssign.value);
2054 if (!value) goto failed;
2055 if (PyObject_SetAttrString(result, "value", value) == -1)
2056 goto failed;
2057 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002058 break;
2059 case Print_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002060 result = PyType_GenericNew(Print_type, NULL, NULL);
2061 if (!result) goto failed;
2062 value = ast2obj_expr(o->v.Print.dest);
2063 if (!value) goto failed;
2064 if (PyObject_SetAttrString(result, "dest", value) == -1)
2065 goto failed;
2066 Py_DECREF(value);
2067 value = ast2obj_list(o->v.Print.values, ast2obj_expr);
2068 if (!value) goto failed;
2069 if (PyObject_SetAttrString(result, "values", value) == -1)
2070 goto failed;
2071 Py_DECREF(value);
2072 value = ast2obj_bool(o->v.Print.nl);
2073 if (!value) goto failed;
2074 if (PyObject_SetAttrString(result, "nl", value) == -1)
2075 goto failed;
2076 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002077 break;
2078 case For_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002079 result = PyType_GenericNew(For_type, NULL, NULL);
2080 if (!result) goto failed;
2081 value = ast2obj_expr(o->v.For.target);
2082 if (!value) goto failed;
2083 if (PyObject_SetAttrString(result, "target", value) == -1)
2084 goto failed;
2085 Py_DECREF(value);
2086 value = ast2obj_expr(o->v.For.iter);
2087 if (!value) goto failed;
2088 if (PyObject_SetAttrString(result, "iter", value) == -1)
2089 goto failed;
2090 Py_DECREF(value);
2091 value = ast2obj_list(o->v.For.body, ast2obj_stmt);
2092 if (!value) goto failed;
2093 if (PyObject_SetAttrString(result, "body", value) == -1)
2094 goto failed;
2095 Py_DECREF(value);
2096 value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
2097 if (!value) goto failed;
2098 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2099 goto failed;
2100 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002101 break;
2102 case While_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002103 result = PyType_GenericNew(While_type, NULL, NULL);
2104 if (!result) goto failed;
2105 value = ast2obj_expr(o->v.While.test);
2106 if (!value) goto failed;
2107 if (PyObject_SetAttrString(result, "test", value) == -1)
2108 goto failed;
2109 Py_DECREF(value);
2110 value = ast2obj_list(o->v.While.body, ast2obj_stmt);
2111 if (!value) goto failed;
2112 if (PyObject_SetAttrString(result, "body", value) == -1)
2113 goto failed;
2114 Py_DECREF(value);
2115 value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);
2116 if (!value) goto failed;
2117 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2118 goto failed;
2119 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002120 break;
2121 case If_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002122 result = PyType_GenericNew(If_type, NULL, NULL);
2123 if (!result) goto failed;
2124 value = ast2obj_expr(o->v.If.test);
2125 if (!value) goto failed;
2126 if (PyObject_SetAttrString(result, "test", value) == -1)
2127 goto failed;
2128 Py_DECREF(value);
2129 value = ast2obj_list(o->v.If.body, ast2obj_stmt);
2130 if (!value) goto failed;
2131 if (PyObject_SetAttrString(result, "body", value) == -1)
2132 goto failed;
2133 Py_DECREF(value);
2134 value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
2135 if (!value) goto failed;
2136 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2137 goto failed;
2138 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002139 break;
Guido van Rossumc2e20742006-02-27 22:32:47 +00002140 case With_kind:
2141 result = PyType_GenericNew(With_type, NULL, NULL);
2142 if (!result) goto failed;
2143 value = ast2obj_expr(o->v.With.context_expr);
2144 if (!value) goto failed;
2145 if (PyObject_SetAttrString(result, "context_expr", value) == -1)
2146 goto failed;
2147 Py_DECREF(value);
2148 value = ast2obj_expr(o->v.With.optional_vars);
2149 if (!value) goto failed;
2150 if (PyObject_SetAttrString(result, "optional_vars", value) ==
2151 -1)
2152 goto failed;
2153 Py_DECREF(value);
2154 value = ast2obj_list(o->v.With.body, ast2obj_stmt);
2155 if (!value) goto failed;
2156 if (PyObject_SetAttrString(result, "body", value) == -1)
2157 goto failed;
2158 Py_DECREF(value);
2159 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002160 case Raise_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002161 result = PyType_GenericNew(Raise_type, NULL, NULL);
2162 if (!result) goto failed;
2163 value = ast2obj_expr(o->v.Raise.type);
2164 if (!value) goto failed;
2165 if (PyObject_SetAttrString(result, "type", value) == -1)
2166 goto failed;
2167 Py_DECREF(value);
2168 value = ast2obj_expr(o->v.Raise.inst);
2169 if (!value) goto failed;
2170 if (PyObject_SetAttrString(result, "inst", value) == -1)
2171 goto failed;
2172 Py_DECREF(value);
2173 value = ast2obj_expr(o->v.Raise.tback);
2174 if (!value) goto failed;
2175 if (PyObject_SetAttrString(result, "tback", value) == -1)
2176 goto failed;
2177 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002178 break;
2179 case TryExcept_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002180 result = PyType_GenericNew(TryExcept_type, NULL, NULL);
2181 if (!result) goto failed;
2182 value = ast2obj_list(o->v.TryExcept.body, ast2obj_stmt);
2183 if (!value) goto failed;
2184 if (PyObject_SetAttrString(result, "body", value) == -1)
2185 goto failed;
2186 Py_DECREF(value);
2187 value = ast2obj_list(o->v.TryExcept.handlers,
2188 ast2obj_excepthandler);
2189 if (!value) goto failed;
2190 if (PyObject_SetAttrString(result, "handlers", value) == -1)
2191 goto failed;
2192 Py_DECREF(value);
2193 value = ast2obj_list(o->v.TryExcept.orelse, ast2obj_stmt);
2194 if (!value) goto failed;
2195 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2196 goto failed;
2197 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002198 break;
2199 case TryFinally_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002200 result = PyType_GenericNew(TryFinally_type, NULL, NULL);
2201 if (!result) goto failed;
2202 value = ast2obj_list(o->v.TryFinally.body, ast2obj_stmt);
2203 if (!value) goto failed;
2204 if (PyObject_SetAttrString(result, "body", value) == -1)
2205 goto failed;
2206 Py_DECREF(value);
2207 value = ast2obj_list(o->v.TryFinally.finalbody, ast2obj_stmt);
2208 if (!value) goto failed;
2209 if (PyObject_SetAttrString(result, "finalbody", value) == -1)
2210 goto failed;
2211 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002212 break;
2213 case Assert_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002214 result = PyType_GenericNew(Assert_type, NULL, NULL);
2215 if (!result) goto failed;
2216 value = ast2obj_expr(o->v.Assert.test);
2217 if (!value) goto failed;
2218 if (PyObject_SetAttrString(result, "test", value) == -1)
2219 goto failed;
2220 Py_DECREF(value);
2221 value = ast2obj_expr(o->v.Assert.msg);
2222 if (!value) goto failed;
2223 if (PyObject_SetAttrString(result, "msg", value) == -1)
2224 goto failed;
2225 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002226 break;
2227 case Import_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002228 result = PyType_GenericNew(Import_type, NULL, NULL);
2229 if (!result) goto failed;
2230 value = ast2obj_list(o->v.Import.names, ast2obj_alias);
2231 if (!value) goto failed;
2232 if (PyObject_SetAttrString(result, "names", value) == -1)
2233 goto failed;
2234 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002235 break;
2236 case ImportFrom_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002237 result = PyType_GenericNew(ImportFrom_type, NULL, NULL);
2238 if (!result) goto failed;
2239 value = ast2obj_identifier(o->v.ImportFrom.module);
2240 if (!value) goto failed;
2241 if (PyObject_SetAttrString(result, "module", value) == -1)
2242 goto failed;
2243 Py_DECREF(value);
2244 value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
2245 if (!value) goto failed;
2246 if (PyObject_SetAttrString(result, "names", value) == -1)
2247 goto failed;
2248 Py_DECREF(value);
Thomas Woutersf7f438b2006-02-28 16:09:29 +00002249 value = ast2obj_int(o->v.ImportFrom.level);
2250 if (!value) goto failed;
2251 if (PyObject_SetAttrString(result, "level", value) == -1)
2252 goto failed;
2253 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002254 break;
2255 case Exec_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002256 result = PyType_GenericNew(Exec_type, NULL, NULL);
2257 if (!result) goto failed;
2258 value = ast2obj_expr(o->v.Exec.body);
2259 if (!value) goto failed;
2260 if (PyObject_SetAttrString(result, "body", value) == -1)
2261 goto failed;
2262 Py_DECREF(value);
2263 value = ast2obj_expr(o->v.Exec.globals);
2264 if (!value) goto failed;
2265 if (PyObject_SetAttrString(result, "globals", value) == -1)
2266 goto failed;
2267 Py_DECREF(value);
2268 value = ast2obj_expr(o->v.Exec.locals);
2269 if (!value) goto failed;
2270 if (PyObject_SetAttrString(result, "locals", value) == -1)
2271 goto failed;
2272 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002273 break;
2274 case Global_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002275 result = PyType_GenericNew(Global_type, NULL, NULL);
2276 if (!result) goto failed;
2277 value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
2278 if (!value) goto failed;
2279 if (PyObject_SetAttrString(result, "names", value) == -1)
2280 goto failed;
2281 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002282 break;
2283 case Expr_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002284 result = PyType_GenericNew(Expr_type, NULL, NULL);
2285 if (!result) goto failed;
2286 value = ast2obj_expr(o->v.Expr.value);
2287 if (!value) goto failed;
2288 if (PyObject_SetAttrString(result, "value", value) == -1)
2289 goto failed;
2290 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002291 break;
2292 case Pass_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002293 result = PyType_GenericNew(Pass_type, NULL, NULL);
2294 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002295 break;
2296 case Break_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002297 result = PyType_GenericNew(Break_type, NULL, NULL);
2298 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002299 break;
2300 case Continue_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002301 result = PyType_GenericNew(Continue_type, NULL, NULL);
2302 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002303 break;
2304 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002305 value = ast2obj_int(o->lineno);
2306 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002307 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2308 goto failed;
2309 Py_DECREF(value);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002310 value = ast2obj_int(o->col_offset);
2311 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002312 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2313 goto failed;
2314 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002315 return result;
2316failed:
2317 Py_XDECREF(value);
2318 Py_XDECREF(result);
2319 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002320}
2321
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002322PyObject*
2323ast2obj_expr(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002324{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002325 expr_ty o = (expr_ty)_o;
2326 PyObject *result = NULL, *value = NULL;
2327 if (!o) {
2328 Py_INCREF(Py_None);
2329 return Py_None;
2330 }
2331
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002332 switch (o->kind) {
2333 case BoolOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002334 result = PyType_GenericNew(BoolOp_type, NULL, NULL);
2335 if (!result) goto failed;
2336 value = ast2obj_boolop(o->v.BoolOp.op);
2337 if (!value) goto failed;
2338 if (PyObject_SetAttrString(result, "op", value) == -1)
2339 goto failed;
2340 Py_DECREF(value);
2341 value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
2342 if (!value) goto failed;
2343 if (PyObject_SetAttrString(result, "values", value) == -1)
2344 goto failed;
2345 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002346 break;
2347 case BinOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002348 result = PyType_GenericNew(BinOp_type, NULL, NULL);
2349 if (!result) goto failed;
2350 value = ast2obj_expr(o->v.BinOp.left);
2351 if (!value) goto failed;
2352 if (PyObject_SetAttrString(result, "left", value) == -1)
2353 goto failed;
2354 Py_DECREF(value);
2355 value = ast2obj_operator(o->v.BinOp.op);
2356 if (!value) goto failed;
2357 if (PyObject_SetAttrString(result, "op", value) == -1)
2358 goto failed;
2359 Py_DECREF(value);
2360 value = ast2obj_expr(o->v.BinOp.right);
2361 if (!value) goto failed;
2362 if (PyObject_SetAttrString(result, "right", value) == -1)
2363 goto failed;
2364 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002365 break;
2366 case UnaryOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002367 result = PyType_GenericNew(UnaryOp_type, NULL, NULL);
2368 if (!result) goto failed;
2369 value = ast2obj_unaryop(o->v.UnaryOp.op);
2370 if (!value) goto failed;
2371 if (PyObject_SetAttrString(result, "op", value) == -1)
2372 goto failed;
2373 Py_DECREF(value);
2374 value = ast2obj_expr(o->v.UnaryOp.operand);
2375 if (!value) goto failed;
2376 if (PyObject_SetAttrString(result, "operand", value) == -1)
2377 goto failed;
2378 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002379 break;
2380 case Lambda_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002381 result = PyType_GenericNew(Lambda_type, NULL, NULL);
2382 if (!result) goto failed;
2383 value = ast2obj_arguments(o->v.Lambda.args);
2384 if (!value) goto failed;
2385 if (PyObject_SetAttrString(result, "args", value) == -1)
2386 goto failed;
2387 Py_DECREF(value);
2388 value = ast2obj_expr(o->v.Lambda.body);
2389 if (!value) goto failed;
2390 if (PyObject_SetAttrString(result, "body", value) == -1)
2391 goto failed;
2392 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002393 break;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002394 case IfExp_kind:
2395 result = PyType_GenericNew(IfExp_type, NULL, NULL);
2396 if (!result) goto failed;
2397 value = ast2obj_expr(o->v.IfExp.test);
2398 if (!value) goto failed;
2399 if (PyObject_SetAttrString(result, "test", value) == -1)
2400 goto failed;
2401 Py_DECREF(value);
2402 value = ast2obj_expr(o->v.IfExp.body);
2403 if (!value) goto failed;
2404 if (PyObject_SetAttrString(result, "body", value) == -1)
2405 goto failed;
2406 Py_DECREF(value);
2407 value = ast2obj_expr(o->v.IfExp.orelse);
2408 if (!value) goto failed;
2409 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2410 goto failed;
2411 Py_DECREF(value);
2412 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002413 case Dict_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002414 result = PyType_GenericNew(Dict_type, NULL, NULL);
2415 if (!result) goto failed;
2416 value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
2417 if (!value) goto failed;
2418 if (PyObject_SetAttrString(result, "keys", value) == -1)
2419 goto failed;
2420 Py_DECREF(value);
2421 value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
2422 if (!value) goto failed;
2423 if (PyObject_SetAttrString(result, "values", value) == -1)
2424 goto failed;
2425 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002426 break;
2427 case ListComp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002428 result = PyType_GenericNew(ListComp_type, NULL, NULL);
2429 if (!result) goto failed;
2430 value = ast2obj_expr(o->v.ListComp.elt);
2431 if (!value) goto failed;
2432 if (PyObject_SetAttrString(result, "elt", value) == -1)
2433 goto failed;
2434 Py_DECREF(value);
2435 value = ast2obj_list(o->v.ListComp.generators,
2436 ast2obj_comprehension);
2437 if (!value) goto failed;
2438 if (PyObject_SetAttrString(result, "generators", value) == -1)
2439 goto failed;
2440 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002441 break;
2442 case GeneratorExp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002443 result = PyType_GenericNew(GeneratorExp_type, NULL, NULL);
2444 if (!result) goto failed;
2445 value = ast2obj_expr(o->v.GeneratorExp.elt);
2446 if (!value) goto failed;
2447 if (PyObject_SetAttrString(result, "elt", value) == -1)
2448 goto failed;
2449 Py_DECREF(value);
2450 value = ast2obj_list(o->v.GeneratorExp.generators,
2451 ast2obj_comprehension);
2452 if (!value) goto failed;
2453 if (PyObject_SetAttrString(result, "generators", value) == -1)
2454 goto failed;
2455 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002456 break;
2457 case Yield_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002458 result = PyType_GenericNew(Yield_type, NULL, NULL);
2459 if (!result) goto failed;
2460 value = ast2obj_expr(o->v.Yield.value);
2461 if (!value) goto failed;
2462 if (PyObject_SetAttrString(result, "value", value) == -1)
2463 goto failed;
2464 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002465 break;
2466 case Compare_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002467 result = PyType_GenericNew(Compare_type, NULL, NULL);
2468 if (!result) goto failed;
2469 value = ast2obj_expr(o->v.Compare.left);
2470 if (!value) goto failed;
2471 if (PyObject_SetAttrString(result, "left", value) == -1)
2472 goto failed;
2473 Py_DECREF(value);
Martin v. Löwisce1d5d22006-02-26 20:51:25 +00002474 {
2475 int i, n = asdl_seq_LEN(o->v.Compare.ops);
2476 value = PyList_New(n);
2477 if (!value) goto failed;
2478 for(i = 0; i < n; i++)
2479 PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
2480 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002481 if (!value) goto failed;
2482 if (PyObject_SetAttrString(result, "ops", value) == -1)
2483 goto failed;
2484 Py_DECREF(value);
2485 value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
2486 if (!value) goto failed;
2487 if (PyObject_SetAttrString(result, "comparators", value) == -1)
2488 goto failed;
2489 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002490 break;
2491 case Call_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002492 result = PyType_GenericNew(Call_type, NULL, NULL);
2493 if (!result) goto failed;
2494 value = ast2obj_expr(o->v.Call.func);
2495 if (!value) goto failed;
2496 if (PyObject_SetAttrString(result, "func", value) == -1)
2497 goto failed;
2498 Py_DECREF(value);
2499 value = ast2obj_list(o->v.Call.args, ast2obj_expr);
2500 if (!value) goto failed;
2501 if (PyObject_SetAttrString(result, "args", value) == -1)
2502 goto failed;
2503 Py_DECREF(value);
2504 value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
2505 if (!value) goto failed;
2506 if (PyObject_SetAttrString(result, "keywords", value) == -1)
2507 goto failed;
2508 Py_DECREF(value);
2509 value = ast2obj_expr(o->v.Call.starargs);
2510 if (!value) goto failed;
2511 if (PyObject_SetAttrString(result, "starargs", value) == -1)
2512 goto failed;
2513 Py_DECREF(value);
2514 value = ast2obj_expr(o->v.Call.kwargs);
2515 if (!value) goto failed;
2516 if (PyObject_SetAttrString(result, "kwargs", value) == -1)
2517 goto failed;
2518 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002519 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002520 case Num_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002521 result = PyType_GenericNew(Num_type, NULL, NULL);
2522 if (!result) goto failed;
2523 value = ast2obj_object(o->v.Num.n);
2524 if (!value) goto failed;
2525 if (PyObject_SetAttrString(result, "n", value) == -1)
2526 goto failed;
2527 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002528 break;
2529 case Str_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002530 result = PyType_GenericNew(Str_type, NULL, NULL);
2531 if (!result) goto failed;
2532 value = ast2obj_string(o->v.Str.s);
2533 if (!value) goto failed;
2534 if (PyObject_SetAttrString(result, "s", value) == -1)
2535 goto failed;
2536 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002537 break;
2538 case Attribute_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002539 result = PyType_GenericNew(Attribute_type, NULL, NULL);
2540 if (!result) goto failed;
2541 value = ast2obj_expr(o->v.Attribute.value);
2542 if (!value) goto failed;
2543 if (PyObject_SetAttrString(result, "value", value) == -1)
2544 goto failed;
2545 Py_DECREF(value);
2546 value = ast2obj_identifier(o->v.Attribute.attr);
2547 if (!value) goto failed;
2548 if (PyObject_SetAttrString(result, "attr", value) == -1)
2549 goto failed;
2550 Py_DECREF(value);
2551 value = ast2obj_expr_context(o->v.Attribute.ctx);
2552 if (!value) goto failed;
2553 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2554 goto failed;
2555 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002556 break;
2557 case Subscript_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002558 result = PyType_GenericNew(Subscript_type, NULL, NULL);
2559 if (!result) goto failed;
2560 value = ast2obj_expr(o->v.Subscript.value);
2561 if (!value) goto failed;
2562 if (PyObject_SetAttrString(result, "value", value) == -1)
2563 goto failed;
2564 Py_DECREF(value);
2565 value = ast2obj_slice(o->v.Subscript.slice);
2566 if (!value) goto failed;
2567 if (PyObject_SetAttrString(result, "slice", value) == -1)
2568 goto failed;
2569 Py_DECREF(value);
2570 value = ast2obj_expr_context(o->v.Subscript.ctx);
2571 if (!value) goto failed;
2572 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2573 goto failed;
2574 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002575 break;
2576 case Name_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002577 result = PyType_GenericNew(Name_type, NULL, NULL);
2578 if (!result) goto failed;
2579 value = ast2obj_identifier(o->v.Name.id);
2580 if (!value) goto failed;
2581 if (PyObject_SetAttrString(result, "id", value) == -1)
2582 goto failed;
2583 Py_DECREF(value);
2584 value = ast2obj_expr_context(o->v.Name.ctx);
2585 if (!value) goto failed;
2586 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2587 goto failed;
2588 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002589 break;
2590 case List_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002591 result = PyType_GenericNew(List_type, NULL, NULL);
2592 if (!result) goto failed;
2593 value = ast2obj_list(o->v.List.elts, ast2obj_expr);
2594 if (!value) goto failed;
2595 if (PyObject_SetAttrString(result, "elts", value) == -1)
2596 goto failed;
2597 Py_DECREF(value);
2598 value = ast2obj_expr_context(o->v.List.ctx);
2599 if (!value) goto failed;
2600 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2601 goto failed;
2602 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002603 break;
2604 case Tuple_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002605 result = PyType_GenericNew(Tuple_type, NULL, NULL);
2606 if (!result) goto failed;
2607 value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
2608 if (!value) goto failed;
2609 if (PyObject_SetAttrString(result, "elts", value) == -1)
2610 goto failed;
2611 Py_DECREF(value);
2612 value = ast2obj_expr_context(o->v.Tuple.ctx);
2613 if (!value) goto failed;
2614 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2615 goto failed;
2616 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002617 break;
2618 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002619 value = ast2obj_int(o->lineno);
2620 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002621 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2622 goto failed;
2623 Py_DECREF(value);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002624 value = ast2obj_int(o->col_offset);
2625 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002626 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2627 goto failed;
2628 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002629 return result;
2630failed:
2631 Py_XDECREF(value);
2632 Py_XDECREF(result);
2633 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002634}
2635
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002636PyObject* ast2obj_expr_context(expr_context_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002637{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002638 switch(o) {
2639 case Load:
2640 Py_INCREF(Load_singleton);
2641 return Load_singleton;
2642 case Store:
2643 Py_INCREF(Store_singleton);
2644 return Store_singleton;
2645 case Del:
2646 Py_INCREF(Del_singleton);
2647 return Del_singleton;
2648 case AugLoad:
2649 Py_INCREF(AugLoad_singleton);
2650 return AugLoad_singleton;
2651 case AugStore:
2652 Py_INCREF(AugStore_singleton);
2653 return AugStore_singleton;
2654 case Param:
2655 Py_INCREF(Param_singleton);
2656 return Param_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002657 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002658 return NULL; /* cannot happen */
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002659}
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002660PyObject*
2661ast2obj_slice(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002662{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002663 slice_ty o = (slice_ty)_o;
2664 PyObject *result = NULL, *value = NULL;
2665 if (!o) {
2666 Py_INCREF(Py_None);
2667 return Py_None;
2668 }
2669
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002670 switch (o->kind) {
2671 case Ellipsis_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002672 result = PyType_GenericNew(Ellipsis_type, NULL, NULL);
2673 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002674 break;
2675 case Slice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002676 result = PyType_GenericNew(Slice_type, NULL, NULL);
2677 if (!result) goto failed;
2678 value = ast2obj_expr(o->v.Slice.lower);
2679 if (!value) goto failed;
2680 if (PyObject_SetAttrString(result, "lower", value) == -1)
2681 goto failed;
2682 Py_DECREF(value);
2683 value = ast2obj_expr(o->v.Slice.upper);
2684 if (!value) goto failed;
2685 if (PyObject_SetAttrString(result, "upper", value) == -1)
2686 goto failed;
2687 Py_DECREF(value);
2688 value = ast2obj_expr(o->v.Slice.step);
2689 if (!value) goto failed;
2690 if (PyObject_SetAttrString(result, "step", value) == -1)
2691 goto failed;
2692 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002693 break;
2694 case ExtSlice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002695 result = PyType_GenericNew(ExtSlice_type, NULL, NULL);
2696 if (!result) goto failed;
2697 value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice);
2698 if (!value) goto failed;
2699 if (PyObject_SetAttrString(result, "dims", value) == -1)
2700 goto failed;
2701 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002702 break;
2703 case Index_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002704 result = PyType_GenericNew(Index_type, NULL, NULL);
2705 if (!result) goto failed;
2706 value = ast2obj_expr(o->v.Index.value);
2707 if (!value) goto failed;
2708 if (PyObject_SetAttrString(result, "value", value) == -1)
2709 goto failed;
2710 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002711 break;
2712 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002713 return result;
2714failed:
2715 Py_XDECREF(value);
2716 Py_XDECREF(result);
2717 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002718}
2719
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002720PyObject* ast2obj_boolop(boolop_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002721{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002722 switch(o) {
2723 case And:
2724 Py_INCREF(And_singleton);
2725 return And_singleton;
2726 case Or:
2727 Py_INCREF(Or_singleton);
2728 return Or_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002729 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002730 return NULL; /* cannot happen */
2731}
2732PyObject* ast2obj_operator(operator_ty o)
2733{
2734 switch(o) {
2735 case Add:
2736 Py_INCREF(Add_singleton);
2737 return Add_singleton;
2738 case Sub:
2739 Py_INCREF(Sub_singleton);
2740 return Sub_singleton;
2741 case Mult:
2742 Py_INCREF(Mult_singleton);
2743 return Mult_singleton;
2744 case Div:
2745 Py_INCREF(Div_singleton);
2746 return Div_singleton;
2747 case Mod:
2748 Py_INCREF(Mod_singleton);
2749 return Mod_singleton;
2750 case Pow:
2751 Py_INCREF(Pow_singleton);
2752 return Pow_singleton;
2753 case LShift:
2754 Py_INCREF(LShift_singleton);
2755 return LShift_singleton;
2756 case RShift:
2757 Py_INCREF(RShift_singleton);
2758 return RShift_singleton;
2759 case BitOr:
2760 Py_INCREF(BitOr_singleton);
2761 return BitOr_singleton;
2762 case BitXor:
2763 Py_INCREF(BitXor_singleton);
2764 return BitXor_singleton;
2765 case BitAnd:
2766 Py_INCREF(BitAnd_singleton);
2767 return BitAnd_singleton;
2768 case FloorDiv:
2769 Py_INCREF(FloorDiv_singleton);
2770 return FloorDiv_singleton;
2771 }
2772 return NULL; /* cannot happen */
2773}
2774PyObject* ast2obj_unaryop(unaryop_ty o)
2775{
2776 switch(o) {
2777 case Invert:
2778 Py_INCREF(Invert_singleton);
2779 return Invert_singleton;
2780 case Not:
2781 Py_INCREF(Not_singleton);
2782 return Not_singleton;
2783 case UAdd:
2784 Py_INCREF(UAdd_singleton);
2785 return UAdd_singleton;
2786 case USub:
2787 Py_INCREF(USub_singleton);
2788 return USub_singleton;
2789 }
2790 return NULL; /* cannot happen */
2791}
2792PyObject* ast2obj_cmpop(cmpop_ty o)
2793{
2794 switch(o) {
2795 case Eq:
2796 Py_INCREF(Eq_singleton);
2797 return Eq_singleton;
2798 case NotEq:
2799 Py_INCREF(NotEq_singleton);
2800 return NotEq_singleton;
2801 case Lt:
2802 Py_INCREF(Lt_singleton);
2803 return Lt_singleton;
2804 case LtE:
2805 Py_INCREF(LtE_singleton);
2806 return LtE_singleton;
2807 case Gt:
2808 Py_INCREF(Gt_singleton);
2809 return Gt_singleton;
2810 case GtE:
2811 Py_INCREF(GtE_singleton);
2812 return GtE_singleton;
2813 case Is:
2814 Py_INCREF(Is_singleton);
2815 return Is_singleton;
2816 case IsNot:
2817 Py_INCREF(IsNot_singleton);
2818 return IsNot_singleton;
2819 case In:
2820 Py_INCREF(In_singleton);
2821 return In_singleton;
2822 case NotIn:
2823 Py_INCREF(NotIn_singleton);
2824 return NotIn_singleton;
2825 }
2826 return NULL; /* cannot happen */
2827}
2828PyObject*
2829ast2obj_comprehension(void* _o)
2830{
2831 comprehension_ty o = (comprehension_ty)_o;
2832 PyObject *result = NULL, *value = NULL;
2833 if (!o) {
2834 Py_INCREF(Py_None);
2835 return Py_None;
2836 }
2837
2838 result = PyType_GenericNew(comprehension_type, NULL, NULL);
2839 if (!result) return NULL;
2840 value = ast2obj_expr(o->target);
2841 if (!value) goto failed;
2842 if (PyObject_SetAttrString(result, "target", value) == -1)
2843 goto failed;
2844 Py_DECREF(value);
2845 value = ast2obj_expr(o->iter);
2846 if (!value) goto failed;
2847 if (PyObject_SetAttrString(result, "iter", value) == -1)
2848 goto failed;
2849 Py_DECREF(value);
2850 value = ast2obj_list(o->ifs, ast2obj_expr);
2851 if (!value) goto failed;
2852 if (PyObject_SetAttrString(result, "ifs", value) == -1)
2853 goto failed;
2854 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002855 return result;
2856failed:
2857 Py_XDECREF(value);
2858 Py_XDECREF(result);
2859 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002860}
2861
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002862PyObject*
2863ast2obj_excepthandler(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002864{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002865 excepthandler_ty o = (excepthandler_ty)_o;
2866 PyObject *result = NULL, *value = NULL;
2867 if (!o) {
2868 Py_INCREF(Py_None);
2869 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002870 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002871
2872 result = PyType_GenericNew(excepthandler_type, NULL, NULL);
2873 if (!result) return NULL;
2874 value = ast2obj_expr(o->type);
2875 if (!value) goto failed;
2876 if (PyObject_SetAttrString(result, "type", value) == -1)
2877 goto failed;
2878 Py_DECREF(value);
2879 value = ast2obj_expr(o->name);
2880 if (!value) goto failed;
2881 if (PyObject_SetAttrString(result, "name", value) == -1)
2882 goto failed;
2883 Py_DECREF(value);
2884 value = ast2obj_list(o->body, ast2obj_stmt);
2885 if (!value) goto failed;
2886 if (PyObject_SetAttrString(result, "body", value) == -1)
2887 goto failed;
2888 Py_DECREF(value);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002889 value = ast2obj_int(o->lineno);
2890 if (!value) goto failed;
2891 if (PyObject_SetAttrString(result, "lineno", value) == -1)
2892 goto failed;
2893 Py_DECREF(value);
2894 value = ast2obj_int(o->col_offset);
2895 if (!value) goto failed;
2896 if (PyObject_SetAttrString(result, "col_offset", value) == -1)
2897 goto failed;
2898 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002899 return result;
2900failed:
2901 Py_XDECREF(value);
2902 Py_XDECREF(result);
2903 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002904}
2905
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002906PyObject*
2907ast2obj_arguments(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002908{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002909 arguments_ty o = (arguments_ty)_o;
2910 PyObject *result = NULL, *value = NULL;
2911 if (!o) {
2912 Py_INCREF(Py_None);
2913 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002914 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002915
2916 result = PyType_GenericNew(arguments_type, NULL, NULL);
2917 if (!result) return NULL;
2918 value = ast2obj_list(o->args, ast2obj_expr);
2919 if (!value) goto failed;
2920 if (PyObject_SetAttrString(result, "args", value) == -1)
2921 goto failed;
2922 Py_DECREF(value);
2923 value = ast2obj_identifier(o->vararg);
2924 if (!value) goto failed;
2925 if (PyObject_SetAttrString(result, "vararg", value) == -1)
2926 goto failed;
2927 Py_DECREF(value);
2928 value = ast2obj_identifier(o->kwarg);
2929 if (!value) goto failed;
2930 if (PyObject_SetAttrString(result, "kwarg", value) == -1)
2931 goto failed;
2932 Py_DECREF(value);
2933 value = ast2obj_list(o->defaults, ast2obj_expr);
2934 if (!value) goto failed;
2935 if (PyObject_SetAttrString(result, "defaults", value) == -1)
2936 goto failed;
2937 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002938 return result;
2939failed:
2940 Py_XDECREF(value);
2941 Py_XDECREF(result);
2942 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002943}
2944
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002945PyObject*
2946ast2obj_keyword(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002947{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002948 keyword_ty o = (keyword_ty)_o;
2949 PyObject *result = NULL, *value = NULL;
2950 if (!o) {
2951 Py_INCREF(Py_None);
2952 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002953 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002954
2955 result = PyType_GenericNew(keyword_type, NULL, NULL);
2956 if (!result) return NULL;
2957 value = ast2obj_identifier(o->arg);
2958 if (!value) goto failed;
2959 if (PyObject_SetAttrString(result, "arg", value) == -1)
2960 goto failed;
2961 Py_DECREF(value);
2962 value = ast2obj_expr(o->value);
2963 if (!value) goto failed;
2964 if (PyObject_SetAttrString(result, "value", value) == -1)
2965 goto failed;
2966 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002967 return result;
2968failed:
2969 Py_XDECREF(value);
2970 Py_XDECREF(result);
2971 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002972}
2973
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002974PyObject*
2975ast2obj_alias(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002976{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002977 alias_ty o = (alias_ty)_o;
2978 PyObject *result = NULL, *value = NULL;
2979 if (!o) {
2980 Py_INCREF(Py_None);
2981 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002982 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002983
2984 result = PyType_GenericNew(alias_type, NULL, NULL);
2985 if (!result) return NULL;
2986 value = ast2obj_identifier(o->name);
2987 if (!value) goto failed;
2988 if (PyObject_SetAttrString(result, "name", value) == -1)
2989 goto failed;
2990 Py_DECREF(value);
2991 value = ast2obj_identifier(o->asname);
2992 if (!value) goto failed;
2993 if (PyObject_SetAttrString(result, "asname", value) == -1)
2994 goto failed;
2995 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002996 return result;
2997failed:
2998 Py_XDECREF(value);
2999 Py_XDECREF(result);
3000 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003001}
3002
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003003
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003004PyMODINIT_FUNC
3005init_ast(void)
3006{
3007 PyObject *m, *d;
3008 if (!init_types()) return;
3009 m = Py_InitModule3("_ast", NULL, NULL);
3010 if (!m) return;
3011 d = PyModule_GetDict(m);
3012 if (PyDict_SetItemString(d, "AST", (PyObject*)AST_type) < 0) return;
3013 if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)
3014 return;
Guido van Rossum0919a1a2006-08-26 20:49:04 +00003015 if (PyModule_AddStringConstant(m, "__version__", "51600") < 0)
Martin v. Löwisace990c2006-02-28 00:32:31 +00003016 return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003017 if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return;
3018 if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0)
3019 return;
3020 if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type)
3021 < 0) return;
3022 if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) <
3023 0) return;
3024 if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return;
3025 if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return;
3026 if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type)
3027 < 0) return;
3028 if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0)
3029 return;
3030 if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0)
3031 return;
3032 if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0)
3033 return;
3034 if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0)
3035 return;
3036 if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) <
3037 0) return;
3038 if (PyDict_SetItemString(d, "Print", (PyObject*)Print_type) < 0) return;
3039 if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return;
3040 if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return;
3041 if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return;
3042 if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return;
3043 if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return;
3044 if (PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) <
3045 0) return;
3046 if (PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) <
3047 0) return;
3048 if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0)
3049 return;
3050 if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0)
3051 return;
3052 if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) <
3053 0) return;
3054 if (PyDict_SetItemString(d, "Exec", (PyObject*)Exec_type) < 0) return;
3055 if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0)
3056 return;
3057 if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return;
3058 if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return;
3059 if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return;
3060 if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0)
3061 return;
3062 if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return;
3063 if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0)
3064 return;
3065 if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return;
3066 if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0)
3067 return;
3068 if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0)
3069 return;
3070 if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return;
3071 if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return;
3072 if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0)
3073 return;
3074 if (PyDict_SetItemString(d, "GeneratorExp",
3075 (PyObject*)GeneratorExp_type) < 0) return;
3076 if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return;
3077 if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0)
3078 return;
3079 if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003080 if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return;
3081 if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return;
3082 if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) <
3083 0) return;
3084 if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) <
3085 0) return;
3086 if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return;
3087 if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return;
3088 if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return;
3089 if (PyDict_SetItemString(d, "expr_context",
3090 (PyObject*)expr_context_type) < 0) return;
3091 if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return;
3092 if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return;
3093 if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return;
3094 if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0)
3095 return;
3096 if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0)
3097 return;
3098 if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return;
3099 if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return;
3100 if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0)
3101 return;
3102 if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return;
3103 if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0)
3104 return;
3105 if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return;
3106 if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0)
3107 return;
3108 if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return;
3109 if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return;
3110 if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0)
3111 return;
3112 if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return;
3113 if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return;
3114 if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return;
3115 if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return;
3116 if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return;
3117 if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return;
3118 if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0)
3119 return;
3120 if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0)
3121 return;
3122 if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return;
3123 if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0)
3124 return;
3125 if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0)
3126 return;
3127 if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0)
3128 return;
3129 if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0)
3130 return;
3131 if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0)
3132 return;
3133 if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return;
3134 if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return;
3135 if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return;
3136 if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return;
3137 if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return;
3138 if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return;
3139 if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return;
3140 if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return;
3141 if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return;
3142 if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return;
3143 if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return;
3144 if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return;
3145 if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return;
3146 if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return;
3147 if (PyDict_SetItemString(d, "comprehension",
3148 (PyObject*)comprehension_type) < 0) return;
3149 if (PyDict_SetItemString(d, "excepthandler",
3150 (PyObject*)excepthandler_type) < 0) return;
3151 if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) <
3152 0) return;
3153 if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0)
3154 return;
3155 if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return;
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003156}
3157
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003158
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003159PyObject* PyAST_mod2obj(mod_ty t)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003160{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003161 init_types();
3162 return ast2obj_mod(t);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003163}
3164
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003165