blob: d981af861cd8b3f5e9ba9e8ce84b8c58112796e8 [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 *Repr_type;
210static char *Repr_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000211 "value",
212};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000213static PyTypeObject *Num_type;
214static char *Num_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000215 "n",
216};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000217static PyTypeObject *Str_type;
218static char *Str_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000219 "s",
220};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000221static PyTypeObject *Attribute_type;
222static char *Attribute_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000223 "value",
224 "attr",
225 "ctx",
226};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000227static PyTypeObject *Subscript_type;
228static char *Subscript_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000229 "value",
230 "slice",
231 "ctx",
232};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000233static PyTypeObject *Name_type;
234static char *Name_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000235 "id",
236 "ctx",
237};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000238static PyTypeObject *List_type;
239static char *List_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000240 "elts",
241 "ctx",
242};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000243static PyTypeObject *Tuple_type;
244static char *Tuple_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000245 "elts",
246 "ctx",
247};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000248static PyTypeObject *expr_context_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000249static PyObject *Load_singleton, *Store_singleton, *Del_singleton,
250*AugLoad_singleton, *AugStore_singleton, *Param_singleton;
251static PyObject* ast2obj_expr_context(expr_context_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000252static PyTypeObject *Load_type;
253static PyTypeObject *Store_type;
254static PyTypeObject *Del_type;
255static PyTypeObject *AugLoad_type;
256static PyTypeObject *AugStore_type;
257static PyTypeObject *Param_type;
258static PyTypeObject *slice_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000259static PyObject* ast2obj_slice(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000260static PyTypeObject *Ellipsis_type;
261static PyTypeObject *Slice_type;
262static char *Slice_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000263 "lower",
264 "upper",
265 "step",
266};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000267static PyTypeObject *ExtSlice_type;
268static char *ExtSlice_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000269 "dims",
270};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000271static PyTypeObject *Index_type;
272static char *Index_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000273 "value",
274};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000275static PyTypeObject *boolop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000276static PyObject *And_singleton, *Or_singleton;
277static PyObject* ast2obj_boolop(boolop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000278static PyTypeObject *And_type;
279static PyTypeObject *Or_type;
280static PyTypeObject *operator_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000281static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton,
282*Div_singleton, *Mod_singleton, *Pow_singleton, *LShift_singleton,
283*RShift_singleton, *BitOr_singleton, *BitXor_singleton, *BitAnd_singleton,
284*FloorDiv_singleton;
285static PyObject* ast2obj_operator(operator_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000286static PyTypeObject *Add_type;
287static PyTypeObject *Sub_type;
288static PyTypeObject *Mult_type;
289static PyTypeObject *Div_type;
290static PyTypeObject *Mod_type;
291static PyTypeObject *Pow_type;
292static PyTypeObject *LShift_type;
293static PyTypeObject *RShift_type;
294static PyTypeObject *BitOr_type;
295static PyTypeObject *BitXor_type;
296static PyTypeObject *BitAnd_type;
297static PyTypeObject *FloorDiv_type;
298static PyTypeObject *unaryop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000299static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton,
300*USub_singleton;
301static PyObject* ast2obj_unaryop(unaryop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000302static PyTypeObject *Invert_type;
303static PyTypeObject *Not_type;
304static PyTypeObject *UAdd_type;
305static PyTypeObject *USub_type;
306static PyTypeObject *cmpop_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000307static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton,
308*Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton,
309*NotIn_singleton;
310static PyObject* ast2obj_cmpop(cmpop_ty);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000311static PyTypeObject *Eq_type;
312static PyTypeObject *NotEq_type;
313static PyTypeObject *Lt_type;
314static PyTypeObject *LtE_type;
315static PyTypeObject *Gt_type;
316static PyTypeObject *GtE_type;
317static PyTypeObject *Is_type;
318static PyTypeObject *IsNot_type;
319static PyTypeObject *In_type;
320static PyTypeObject *NotIn_type;
321static PyTypeObject *comprehension_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000322static PyObject* ast2obj_comprehension(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000323static char *comprehension_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000324 "target",
325 "iter",
326 "ifs",
327};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000328static PyTypeObject *excepthandler_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000329static PyObject* ast2obj_excepthandler(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000330static char *excepthandler_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000331 "type",
332 "name",
333 "body",
334};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000335static PyTypeObject *arguments_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000336static PyObject* ast2obj_arguments(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000337static char *arguments_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000338 "args",
339 "vararg",
340 "kwarg",
341 "defaults",
342};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000343static PyTypeObject *keyword_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000344static PyObject* ast2obj_keyword(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000345static char *keyword_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000346 "arg",
347 "value",
348};
Neal Norwitz53d960c2006-02-28 22:47:29 +0000349static PyTypeObject *alias_type;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000350static PyObject* ast2obj_alias(void*);
Neal Norwitz53d960c2006-02-28 22:47:29 +0000351static char *alias_fields[]={
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000352 "name",
353 "asname",
354};
355
356
357static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields)
358{
359 PyObject *fnames, *result;
360 int i;
361 if (num_fields) {
362 fnames = PyTuple_New(num_fields);
363 if (!fnames) return NULL;
364 } else {
365 fnames = Py_None;
366 Py_INCREF(Py_None);
367 }
368 for(i=0; i < num_fields; i++) {
369 PyObject *field = PyString_FromString(fields[i]);
370 if (!field) {
371 Py_DECREF(fnames);
372 return NULL;
373 }
374 PyTuple_SET_ITEM(fnames, i, field);
375 }
Thomas Wouters34aa7ba2006-02-28 19:02:24 +0000376 result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}",
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000377 type, base, "_fields", fnames, "__module__", "_ast");
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000378 Py_DECREF(fnames);
379 return (PyTypeObject*)result;
380}
381
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000382static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)
383{
Neal Norwitz19379f12006-04-03 04:50:58 +0000384 int i, result;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000385 PyObject *s, *l = PyList_New(num_fields);
386 if (!l) return 0;
Neal Norwitz19379f12006-04-03 04:50:58 +0000387 for(i = 0; i < num_fields; i++) {
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000388 s = PyString_FromString(attrs[i]);
389 if (!s) {
390 Py_DECREF(l);
391 return 0;
392 }
393 PyList_SET_ITEM(l, i, s);
394 }
Neal Norwitz19379f12006-04-03 04:50:58 +0000395 result = PyObject_SetAttrString((PyObject*)type, "_attributes", l) >= 0;
396 Py_DECREF(l);
397 return result;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000398}
399
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000400static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
401{
402 int i, n = asdl_seq_LEN(seq);
403 PyObject *result = PyList_New(n);
404 PyObject *value;
405 if (!result)
406 return NULL;
407 for (i = 0; i < n; i++) {
408 value = func(asdl_seq_GET(seq, i));
409 if (!value) {
410 Py_DECREF(result);
411 return NULL;
412 }
413 PyList_SET_ITEM(result, i, value);
414 }
415 return result;
416}
417
418static PyObject* ast2obj_object(void *o)
419{
420 if (!o)
421 o = Py_None;
422 Py_INCREF((PyObject*)o);
423 return (PyObject*)o;
424}
425#define ast2obj_identifier ast2obj_object
426#define ast2obj_string ast2obj_object
427static PyObject* ast2obj_bool(bool b)
428{
429 return PyBool_FromLong(b);
430}
431
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000432static PyObject* ast2obj_int(bool b)
433{
434 return PyInt_FromLong(b);
435}
436
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000437static int init_types(void)
438{
Neal Norwitz19379f12006-04-03 04:50:58 +0000439 static int initialized;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000440 if (initialized) return 1;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000441 AST_type = make_type("AST", &PyBaseObject_Type, NULL, 0);
442 mod_type = make_type("mod", AST_type, NULL, 0);
443 if (!mod_type) return 0;
444 if (!add_attributes(mod_type, NULL, 0)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000445 Module_type = make_type("Module", mod_type, Module_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000446 if (!Module_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000447 Interactive_type = make_type("Interactive", mod_type,
448 Interactive_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000449 if (!Interactive_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000450 Expression_type = make_type("Expression", mod_type, Expression_fields,
451 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000452 if (!Expression_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000453 Suite_type = make_type("Suite", mod_type, Suite_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000454 if (!Suite_type) return 0;
455 stmt_type = make_type("stmt", AST_type, NULL, 0);
456 if (!stmt_type) return 0;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000457 if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000458 FunctionDef_type = make_type("FunctionDef", stmt_type,
459 FunctionDef_fields, 4);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000460 if (!FunctionDef_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000461 ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000462 if (!ClassDef_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000463 Return_type = make_type("Return", stmt_type, Return_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000464 if (!Return_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000465 Delete_type = make_type("Delete", stmt_type, Delete_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000466 if (!Delete_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000467 Assign_type = make_type("Assign", stmt_type, Assign_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000468 if (!Assign_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000469 AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000470 if (!AugAssign_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000471 Print_type = make_type("Print", stmt_type, Print_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000472 if (!Print_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000473 For_type = make_type("For", stmt_type, For_fields, 4);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000474 if (!For_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000475 While_type = make_type("While", stmt_type, While_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000476 if (!While_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000477 If_type = make_type("If", stmt_type, If_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000478 if (!If_type) return 0;
Guido van Rossumc2e20742006-02-27 22:32:47 +0000479 With_type = make_type("With", stmt_type, With_fields, 3);
480 if (!With_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000481 Raise_type = make_type("Raise", stmt_type, Raise_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000482 if (!Raise_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000483 TryExcept_type = make_type("TryExcept", stmt_type, TryExcept_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000484 if (!TryExcept_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000485 TryFinally_type = make_type("TryFinally", stmt_type, TryFinally_fields,
486 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000487 if (!TryFinally_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000488 Assert_type = make_type("Assert", stmt_type, Assert_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000489 if (!Assert_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000490 Import_type = make_type("Import", stmt_type, Import_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000491 if (!Import_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000492 ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields,
Thomas Woutersf7f438b2006-02-28 16:09:29 +0000493 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000494 if (!ImportFrom_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000495 Exec_type = make_type("Exec", stmt_type, Exec_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000496 if (!Exec_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000497 Global_type = make_type("Global", stmt_type, Global_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000498 if (!Global_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000499 Expr_type = make_type("Expr", stmt_type, Expr_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000500 if (!Expr_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000501 Pass_type = make_type("Pass", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000502 if (!Pass_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000503 Break_type = make_type("Break", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000504 if (!Break_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000505 Continue_type = make_type("Continue", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000506 if (!Continue_type) return 0;
507 expr_type = make_type("expr", AST_type, NULL, 0);
508 if (!expr_type) return 0;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000509 if (!add_attributes(expr_type, expr_attributes, 2)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000510 BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000511 if (!BoolOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000512 BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000513 if (!BinOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000514 UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000515 if (!UnaryOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000516 Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000517 if (!Lambda_type) return 0;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +0000518 IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000519 if (!IfExp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000520 Dict_type = make_type("Dict", expr_type, Dict_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000521 if (!Dict_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000522 ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000523 if (!ListComp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000524 GeneratorExp_type = make_type("GeneratorExp", expr_type,
525 GeneratorExp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000526 if (!GeneratorExp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000527 Yield_type = make_type("Yield", expr_type, Yield_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000528 if (!Yield_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000529 Compare_type = make_type("Compare", expr_type, Compare_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000530 if (!Compare_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000531 Call_type = make_type("Call", expr_type, Call_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000532 if (!Call_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000533 Repr_type = make_type("Repr", expr_type, Repr_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000534 if (!Repr_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000535 Num_type = make_type("Num", expr_type, Num_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000536 if (!Num_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000537 Str_type = make_type("Str", expr_type, Str_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000538 if (!Str_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000539 Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000540 if (!Attribute_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000541 Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000542 if (!Subscript_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000543 Name_type = make_type("Name", expr_type, Name_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000544 if (!Name_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000545 List_type = make_type("List", expr_type, List_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000546 if (!List_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000547 Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000548 if (!Tuple_type) return 0;
549 expr_context_type = make_type("expr_context", AST_type, NULL, 0);
550 if (!expr_context_type) return 0;
551 if (!add_attributes(expr_context_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000552 Load_type = make_type("Load", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000553 if (!Load_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000554 Load_singleton = PyType_GenericNew(Load_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000555 if (!Load_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000556 Store_type = make_type("Store", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000557 if (!Store_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000558 Store_singleton = PyType_GenericNew(Store_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000559 if (!Store_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000560 Del_type = make_type("Del", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000561 if (!Del_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000562 Del_singleton = PyType_GenericNew(Del_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000563 if (!Del_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000564 AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000565 if (!AugLoad_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000566 AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000567 if (!AugLoad_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000568 AugStore_type = make_type("AugStore", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000569 if (!AugStore_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000570 AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000571 if (!AugStore_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000572 Param_type = make_type("Param", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000573 if (!Param_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000574 Param_singleton = PyType_GenericNew(Param_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000575 if (!Param_singleton) return 0;
576 slice_type = make_type("slice", AST_type, NULL, 0);
577 if (!slice_type) return 0;
578 if (!add_attributes(slice_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000579 Ellipsis_type = make_type("Ellipsis", slice_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000580 if (!Ellipsis_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000581 Slice_type = make_type("Slice", slice_type, Slice_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000582 if (!Slice_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000583 ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000584 if (!ExtSlice_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000585 Index_type = make_type("Index", slice_type, Index_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000586 if (!Index_type) return 0;
587 boolop_type = make_type("boolop", AST_type, NULL, 0);
588 if (!boolop_type) return 0;
589 if (!add_attributes(boolop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000590 And_type = make_type("And", boolop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000591 if (!And_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000592 And_singleton = PyType_GenericNew(And_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000593 if (!And_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000594 Or_type = make_type("Or", boolop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000595 if (!Or_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000596 Or_singleton = PyType_GenericNew(Or_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000597 if (!Or_singleton) return 0;
598 operator_type = make_type("operator", AST_type, NULL, 0);
599 if (!operator_type) return 0;
600 if (!add_attributes(operator_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000601 Add_type = make_type("Add", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000602 if (!Add_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000603 Add_singleton = PyType_GenericNew(Add_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000604 if (!Add_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000605 Sub_type = make_type("Sub", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000606 if (!Sub_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000607 Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000608 if (!Sub_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000609 Mult_type = make_type("Mult", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000610 if (!Mult_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000611 Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000612 if (!Mult_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000613 Div_type = make_type("Div", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000614 if (!Div_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000615 Div_singleton = PyType_GenericNew(Div_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000616 if (!Div_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000617 Mod_type = make_type("Mod", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000618 if (!Mod_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000619 Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000620 if (!Mod_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000621 Pow_type = make_type("Pow", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000622 if (!Pow_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000623 Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000624 if (!Pow_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000625 LShift_type = make_type("LShift", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000626 if (!LShift_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000627 LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000628 if (!LShift_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000629 RShift_type = make_type("RShift", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000630 if (!RShift_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000631 RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000632 if (!RShift_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000633 BitOr_type = make_type("BitOr", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000634 if (!BitOr_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000635 BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000636 if (!BitOr_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000637 BitXor_type = make_type("BitXor", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000638 if (!BitXor_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000639 BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000640 if (!BitXor_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000641 BitAnd_type = make_type("BitAnd", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000642 if (!BitAnd_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000643 BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000644 if (!BitAnd_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000645 FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000646 if (!FloorDiv_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000647 FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000648 if (!FloorDiv_singleton) return 0;
649 unaryop_type = make_type("unaryop", AST_type, NULL, 0);
650 if (!unaryop_type) return 0;
651 if (!add_attributes(unaryop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000652 Invert_type = make_type("Invert", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000653 if (!Invert_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000654 Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000655 if (!Invert_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000656 Not_type = make_type("Not", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000657 if (!Not_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000658 Not_singleton = PyType_GenericNew(Not_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000659 if (!Not_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000660 UAdd_type = make_type("UAdd", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000661 if (!UAdd_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000662 UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000663 if (!UAdd_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000664 USub_type = make_type("USub", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000665 if (!USub_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000666 USub_singleton = PyType_GenericNew(USub_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000667 if (!USub_singleton) return 0;
668 cmpop_type = make_type("cmpop", AST_type, NULL, 0);
669 if (!cmpop_type) return 0;
670 if (!add_attributes(cmpop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000671 Eq_type = make_type("Eq", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000672 if (!Eq_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000673 Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000674 if (!Eq_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000675 NotEq_type = make_type("NotEq", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000676 if (!NotEq_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000677 NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000678 if (!NotEq_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000679 Lt_type = make_type("Lt", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000680 if (!Lt_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000681 Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000682 if (!Lt_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000683 LtE_type = make_type("LtE", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000684 if (!LtE_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000685 LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000686 if (!LtE_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000687 Gt_type = make_type("Gt", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000688 if (!Gt_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000689 Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000690 if (!Gt_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000691 GtE_type = make_type("GtE", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000692 if (!GtE_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000693 GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000694 if (!GtE_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000695 Is_type = make_type("Is", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000696 if (!Is_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000697 Is_singleton = PyType_GenericNew(Is_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000698 if (!Is_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000699 IsNot_type = make_type("IsNot", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000700 if (!IsNot_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000701 IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000702 if (!IsNot_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000703 In_type = make_type("In", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000704 if (!In_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000705 In_singleton = PyType_GenericNew(In_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000706 if (!In_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000707 NotIn_type = make_type("NotIn", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000708 if (!NotIn_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000709 NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000710 if (!NotIn_singleton) return 0;
711 comprehension_type = make_type("comprehension", AST_type,
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000712 comprehension_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000713 if (!comprehension_type) return 0;
714 excepthandler_type = make_type("excepthandler", AST_type,
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000715 excepthandler_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000716 if (!excepthandler_type) return 0;
717 arguments_type = make_type("arguments", AST_type, arguments_fields, 4);
718 if (!arguments_type) return 0;
719 keyword_type = make_type("keyword", AST_type, keyword_fields, 2);
720 if (!keyword_type) return 0;
721 alias_type = make_type("alias", AST_type, alias_fields, 2);
722 if (!alias_type) return 0;
723 initialized = 1;
724 return 1;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000725}
Neal Norwitz7b5a6042005-11-13 19:14:20 +0000726
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000727mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000728Module(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000729{
730 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000731 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000732 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000733 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000734 return NULL;
735 }
736 p->kind = Module_kind;
737 p->v.Module.body = body;
738 return p;
739}
740
741mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000742Interactive(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000743{
744 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000745 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000746 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000747 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000748 return NULL;
749 }
750 p->kind = Interactive_kind;
751 p->v.Interactive.body = body;
752 return p;
753}
754
755mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000756Expression(expr_ty body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000757{
758 mod_ty p;
759 if (!body) {
760 PyErr_SetString(PyExc_ValueError,
761 "field body is required for Expression");
762 return NULL;
763 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000764 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000765 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000766 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000767 return NULL;
768 }
769 p->kind = Expression_kind;
770 p->v.Expression.body = body;
771 return p;
772}
773
774mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000775Suite(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000776{
777 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000778 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000779 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000780 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000781 return NULL;
782 }
783 p->kind = Suite_kind;
784 p->v.Suite.body = body;
785 return p;
786}
787
788stmt_ty
789FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000790 decorators, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000791{
792 stmt_ty p;
793 if (!name) {
794 PyErr_SetString(PyExc_ValueError,
795 "field name is required for FunctionDef");
796 return NULL;
797 }
798 if (!args) {
799 PyErr_SetString(PyExc_ValueError,
800 "field args is required for FunctionDef");
801 return NULL;
802 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000803 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000804 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000805 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000806 return NULL;
807 }
808 p->kind = FunctionDef_kind;
809 p->v.FunctionDef.name = name;
810 p->v.FunctionDef.args = args;
811 p->v.FunctionDef.body = body;
812 p->v.FunctionDef.decorators = decorators;
813 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000814 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000815 return p;
816}
817
818stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000819ClassDef(identifier name, asdl_seq * bases, asdl_seq * body, int lineno, int
820 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000821{
822 stmt_ty p;
823 if (!name) {
824 PyErr_SetString(PyExc_ValueError,
825 "field name is required for ClassDef");
826 return NULL;
827 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000828 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000829 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000830 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000831 return NULL;
832 }
833 p->kind = ClassDef_kind;
834 p->v.ClassDef.name = name;
835 p->v.ClassDef.bases = bases;
836 p->v.ClassDef.body = body;
837 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000838 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000839 return p;
840}
841
842stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000843Return(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000844{
845 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000846 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000847 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000848 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000849 return NULL;
850 }
851 p->kind = Return_kind;
852 p->v.Return.value = value;
853 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000854 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000855 return p;
856}
857
858stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000859Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000860{
861 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000862 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000863 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000864 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000865 return NULL;
866 }
867 p->kind = Delete_kind;
868 p->v.Delete.targets = targets;
869 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000870 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000871 return p;
872}
873
874stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000875Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena
876 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000877{
878 stmt_ty p;
879 if (!value) {
880 PyErr_SetString(PyExc_ValueError,
881 "field value is required for Assign");
882 return NULL;
883 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000884 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000885 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000886 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000887 return NULL;
888 }
889 p->kind = Assign_kind;
890 p->v.Assign.targets = targets;
891 p->v.Assign.value = value;
892 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000893 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000894 return p;
895}
896
897stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000898AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
899 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000900{
901 stmt_ty p;
902 if (!target) {
903 PyErr_SetString(PyExc_ValueError,
904 "field target is required for AugAssign");
905 return NULL;
906 }
907 if (!op) {
908 PyErr_SetString(PyExc_ValueError,
909 "field op is required for AugAssign");
910 return NULL;
911 }
912 if (!value) {
913 PyErr_SetString(PyExc_ValueError,
914 "field value is required for AugAssign");
915 return NULL;
916 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000917 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000918 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000919 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000920 return NULL;
921 }
922 p->kind = AugAssign_kind;
923 p->v.AugAssign.target = target;
924 p->v.AugAssign.op = op;
925 p->v.AugAssign.value = value;
926 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000927 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000928 return p;
929}
930
931stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000932Print(expr_ty dest, asdl_seq * values, bool nl, int lineno, int col_offset,
933 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000934{
935 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000936 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000937 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000938 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000939 return NULL;
940 }
941 p->kind = Print_kind;
942 p->v.Print.dest = dest;
943 p->v.Print.values = values;
944 p->v.Print.nl = nl;
945 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000946 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000947 return p;
948}
949
950stmt_ty
951For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000952 lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000953{
954 stmt_ty p;
955 if (!target) {
956 PyErr_SetString(PyExc_ValueError,
957 "field target is required for For");
958 return NULL;
959 }
960 if (!iter) {
961 PyErr_SetString(PyExc_ValueError,
962 "field iter is required for For");
963 return NULL;
964 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000965 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000966 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000967 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000968 return NULL;
969 }
970 p->kind = For_kind;
971 p->v.For.target = target;
972 p->v.For.iter = iter;
973 p->v.For.body = body;
974 p->v.For.orelse = orelse;
975 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000976 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000977 return p;
978}
979
980stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000981While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
982 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000983{
984 stmt_ty p;
985 if (!test) {
986 PyErr_SetString(PyExc_ValueError,
987 "field test is required for While");
988 return NULL;
989 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000990 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000991 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000992 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000993 return NULL;
994 }
995 p->kind = While_kind;
996 p->v.While.test = test;
997 p->v.While.body = body;
998 p->v.While.orelse = orelse;
999 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001000 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001001 return p;
1002}
1003
1004stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001005If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
1006 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001007{
1008 stmt_ty p;
1009 if (!test) {
1010 PyErr_SetString(PyExc_ValueError,
1011 "field test is required for If");
1012 return NULL;
1013 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001014 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001015 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001016 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001017 return NULL;
1018 }
1019 p->kind = If_kind;
1020 p->v.If.test = test;
1021 p->v.If.body = body;
1022 p->v.If.orelse = orelse;
1023 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001024 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001025 return p;
1026}
1027
1028stmt_ty
Guido van Rossumc2e20742006-02-27 22:32:47 +00001029With(expr_ty context_expr, expr_ty optional_vars, asdl_seq * body, int lineno,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001030 int col_offset, PyArena *arena)
Guido van Rossumc2e20742006-02-27 22:32:47 +00001031{
1032 stmt_ty p;
1033 if (!context_expr) {
1034 PyErr_SetString(PyExc_ValueError,
1035 "field context_expr is required for With");
1036 return NULL;
1037 }
1038 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1039 if (!p) {
1040 PyErr_NoMemory();
1041 return NULL;
1042 }
1043 p->kind = With_kind;
1044 p->v.With.context_expr = context_expr;
1045 p->v.With.optional_vars = optional_vars;
1046 p->v.With.body = body;
1047 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001048 p->col_offset = col_offset;
Guido van Rossumc2e20742006-02-27 22:32:47 +00001049 return p;
1050}
1051
1052stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001053Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno, int col_offset,
1054 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001055{
1056 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001057 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001058 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001059 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001060 return NULL;
1061 }
1062 p->kind = Raise_kind;
1063 p->v.Raise.type = type;
1064 p->v.Raise.inst = inst;
1065 p->v.Raise.tback = tback;
1066 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001067 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001068 return p;
1069}
1070
1071stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001072TryExcept(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, int lineno,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001073 int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001074{
1075 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001076 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001077 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001078 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001079 return NULL;
1080 }
1081 p->kind = TryExcept_kind;
1082 p->v.TryExcept.body = body;
1083 p->v.TryExcept.handlers = handlers;
1084 p->v.TryExcept.orelse = orelse;
1085 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001086 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001087 return p;
1088}
1089
1090stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001091TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, int col_offset,
1092 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001093{
1094 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001095 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001096 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001097 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001098 return NULL;
1099 }
1100 p->kind = TryFinally_kind;
1101 p->v.TryFinally.body = body;
1102 p->v.TryFinally.finalbody = finalbody;
1103 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001104 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001105 return p;
1106}
1107
1108stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001109Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001110{
1111 stmt_ty p;
1112 if (!test) {
1113 PyErr_SetString(PyExc_ValueError,
1114 "field test is required for Assert");
1115 return NULL;
1116 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001117 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001118 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001119 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001120 return NULL;
1121 }
1122 p->kind = Assert_kind;
1123 p->v.Assert.test = test;
1124 p->v.Assert.msg = msg;
1125 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001126 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001127 return p;
1128}
1129
1130stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001131Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001132{
1133 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001134 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001135 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001136 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001137 return NULL;
1138 }
1139 p->kind = Import_kind;
1140 p->v.Import.names = names;
1141 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001142 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001143 return p;
1144}
1145
1146stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001147ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int
1148 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001149{
1150 stmt_ty p;
1151 if (!module) {
1152 PyErr_SetString(PyExc_ValueError,
1153 "field module is required for ImportFrom");
1154 return NULL;
1155 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001156 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001157 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001158 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001159 return NULL;
1160 }
1161 p->kind = ImportFrom_kind;
1162 p->v.ImportFrom.module = module;
1163 p->v.ImportFrom.names = names;
Thomas Woutersf7f438b2006-02-28 16:09:29 +00001164 p->v.ImportFrom.level = level;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001165 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001166 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001167 return p;
1168}
1169
1170stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001171Exec(expr_ty body, expr_ty globals, expr_ty locals, int lineno, int col_offset,
1172 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001173{
1174 stmt_ty p;
1175 if (!body) {
1176 PyErr_SetString(PyExc_ValueError,
1177 "field body is required for Exec");
1178 return NULL;
1179 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001180 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001181 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001182 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001183 return NULL;
1184 }
1185 p->kind = Exec_kind;
1186 p->v.Exec.body = body;
1187 p->v.Exec.globals = globals;
1188 p->v.Exec.locals = locals;
1189 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001190 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001191 return p;
1192}
1193
1194stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001195Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001196{
1197 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001198 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001199 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001200 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001201 return NULL;
1202 }
1203 p->kind = Global_kind;
1204 p->v.Global.names = names;
1205 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001206 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001207 return p;
1208}
1209
1210stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001211Expr(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001212{
1213 stmt_ty p;
1214 if (!value) {
1215 PyErr_SetString(PyExc_ValueError,
1216 "field value is required for Expr");
1217 return NULL;
1218 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001219 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001220 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001221 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001222 return NULL;
1223 }
1224 p->kind = Expr_kind;
1225 p->v.Expr.value = value;
1226 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001227 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001228 return p;
1229}
1230
1231stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001232Pass(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001233{
1234 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001235 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001236 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001237 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001238 return NULL;
1239 }
1240 p->kind = Pass_kind;
1241 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001242 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001243 return p;
1244}
1245
1246stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001247Break(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001248{
1249 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001250 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001251 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001252 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001253 return NULL;
1254 }
1255 p->kind = Break_kind;
1256 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001257 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001258 return p;
1259}
1260
1261stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001262Continue(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001263{
1264 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001265 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001266 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001267 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001268 return NULL;
1269 }
1270 p->kind = Continue_kind;
1271 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001272 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001273 return p;
1274}
1275
1276expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001277BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena
1278 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001279{
1280 expr_ty p;
1281 if (!op) {
1282 PyErr_SetString(PyExc_ValueError,
1283 "field op is required for BoolOp");
1284 return NULL;
1285 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001286 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001287 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001288 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001289 return NULL;
1290 }
1291 p->kind = BoolOp_kind;
1292 p->v.BoolOp.op = op;
1293 p->v.BoolOp.values = values;
1294 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001295 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001296 return p;
1297}
1298
1299expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001300BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset,
1301 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001302{
1303 expr_ty p;
1304 if (!left) {
1305 PyErr_SetString(PyExc_ValueError,
1306 "field left is required for BinOp");
1307 return NULL;
1308 }
1309 if (!op) {
1310 PyErr_SetString(PyExc_ValueError,
1311 "field op is required for BinOp");
1312 return NULL;
1313 }
1314 if (!right) {
1315 PyErr_SetString(PyExc_ValueError,
1316 "field right is required for BinOp");
1317 return NULL;
1318 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001319 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001320 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001321 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001322 return NULL;
1323 }
1324 p->kind = BinOp_kind;
1325 p->v.BinOp.left = left;
1326 p->v.BinOp.op = op;
1327 p->v.BinOp.right = right;
1328 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001329 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001330 return p;
1331}
1332
1333expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001334UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena
1335 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001336{
1337 expr_ty p;
1338 if (!op) {
1339 PyErr_SetString(PyExc_ValueError,
1340 "field op is required for UnaryOp");
1341 return NULL;
1342 }
1343 if (!operand) {
1344 PyErr_SetString(PyExc_ValueError,
1345 "field operand is required for UnaryOp");
1346 return NULL;
1347 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001348 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001349 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001350 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001351 return NULL;
1352 }
1353 p->kind = UnaryOp_kind;
1354 p->v.UnaryOp.op = op;
1355 p->v.UnaryOp.operand = operand;
1356 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001357 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001358 return p;
1359}
1360
1361expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001362Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena
1363 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001364{
1365 expr_ty p;
1366 if (!args) {
1367 PyErr_SetString(PyExc_ValueError,
1368 "field args is required for Lambda");
1369 return NULL;
1370 }
1371 if (!body) {
1372 PyErr_SetString(PyExc_ValueError,
1373 "field body is required for Lambda");
1374 return NULL;
1375 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001376 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001377 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001378 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001379 return NULL;
1380 }
1381 p->kind = Lambda_kind;
1382 p->v.Lambda.args = args;
1383 p->v.Lambda.body = body;
1384 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001385 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001386 return p;
1387}
1388
1389expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001390IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset,
1391 PyArena *arena)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001392{
1393 expr_ty p;
1394 if (!test) {
1395 PyErr_SetString(PyExc_ValueError,
1396 "field test is required for IfExp");
1397 return NULL;
1398 }
1399 if (!body) {
1400 PyErr_SetString(PyExc_ValueError,
1401 "field body is required for IfExp");
1402 return NULL;
1403 }
1404 if (!orelse) {
1405 PyErr_SetString(PyExc_ValueError,
1406 "field orelse is required for IfExp");
1407 return NULL;
1408 }
1409 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1410 if (!p) {
1411 PyErr_NoMemory();
1412 return NULL;
1413 }
1414 p->kind = IfExp_kind;
1415 p->v.IfExp.test = test;
1416 p->v.IfExp.body = body;
1417 p->v.IfExp.orelse = orelse;
1418 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001419 p->col_offset = col_offset;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001420 return p;
1421}
1422
1423expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001424Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena
1425 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001426{
1427 expr_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001428 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001429 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001430 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001431 return NULL;
1432 }
1433 p->kind = Dict_kind;
1434 p->v.Dict.keys = keys;
1435 p->v.Dict.values = values;
1436 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001437 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001438 return p;
1439}
1440
1441expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001442ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1443 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001444{
1445 expr_ty p;
1446 if (!elt) {
1447 PyErr_SetString(PyExc_ValueError,
1448 "field elt is required for ListComp");
1449 return NULL;
1450 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001451 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001452 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001453 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001454 return NULL;
1455 }
1456 p->kind = ListComp_kind;
1457 p->v.ListComp.elt = elt;
1458 p->v.ListComp.generators = generators;
1459 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001460 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001461 return p;
1462}
1463
1464expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001465GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1466 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001467{
1468 expr_ty p;
1469 if (!elt) {
1470 PyErr_SetString(PyExc_ValueError,
1471 "field elt is required for GeneratorExp");
1472 return NULL;
1473 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001474 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001475 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001476 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001477 return NULL;
1478 }
1479 p->kind = GeneratorExp_kind;
1480 p->v.GeneratorExp.elt = elt;
1481 p->v.GeneratorExp.generators = generators;
1482 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001483 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001484 return p;
1485}
1486
1487expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001488Yield(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001489{
1490 expr_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001491 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001492 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001493 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001494 return NULL;
1495 }
1496 p->kind = Yield_kind;
1497 p->v.Yield.value = value;
1498 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001499 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001500 return p;
1501}
1502
1503expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001504Compare(expr_ty left, asdl_seq * ops, asdl_seq * comparators, int lineno, int
1505 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001506{
1507 expr_ty p;
1508 if (!left) {
1509 PyErr_SetString(PyExc_ValueError,
1510 "field left is required for Compare");
1511 return NULL;
1512 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001513 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001514 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001515 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001516 return NULL;
1517 }
1518 p->kind = Compare_kind;
1519 p->v.Compare.left = left;
1520 p->v.Compare.ops = ops;
1521 p->v.Compare.comparators = comparators;
1522 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001523 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001524 return p;
1525}
1526
1527expr_ty
1528Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, expr_ty starargs,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001529 expr_ty kwargs, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001530{
1531 expr_ty p;
1532 if (!func) {
1533 PyErr_SetString(PyExc_ValueError,
1534 "field func is required for Call");
1535 return NULL;
1536 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001537 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001538 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001539 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001540 return NULL;
1541 }
1542 p->kind = Call_kind;
1543 p->v.Call.func = func;
1544 p->v.Call.args = args;
1545 p->v.Call.keywords = keywords;
1546 p->v.Call.starargs = starargs;
1547 p->v.Call.kwargs = kwargs;
1548 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001549 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001550 return p;
1551}
1552
1553expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001554Repr(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001555{
1556 expr_ty p;
1557 if (!value) {
1558 PyErr_SetString(PyExc_ValueError,
1559 "field value is required for Repr");
1560 return NULL;
1561 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001562 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001563 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001564 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001565 return NULL;
1566 }
1567 p->kind = Repr_kind;
1568 p->v.Repr.value = value;
1569 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001570 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001571 return p;
1572}
1573
1574expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001575Num(object n, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001576{
1577 expr_ty p;
1578 if (!n) {
1579 PyErr_SetString(PyExc_ValueError,
1580 "field n is required for Num");
1581 return NULL;
1582 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001583 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001584 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001585 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001586 return NULL;
1587 }
1588 p->kind = Num_kind;
1589 p->v.Num.n = n;
1590 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001591 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001592 return p;
1593}
1594
1595expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001596Str(string s, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001597{
1598 expr_ty p;
1599 if (!s) {
1600 PyErr_SetString(PyExc_ValueError,
1601 "field s is required for Str");
1602 return NULL;
1603 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001604 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001605 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001606 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001607 return NULL;
1608 }
1609 p->kind = Str_kind;
1610 p->v.Str.s = s;
1611 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001612 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001613 return p;
1614}
1615
1616expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001617Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int
1618 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001619{
1620 expr_ty p;
1621 if (!value) {
1622 PyErr_SetString(PyExc_ValueError,
1623 "field value is required for Attribute");
1624 return NULL;
1625 }
1626 if (!attr) {
1627 PyErr_SetString(PyExc_ValueError,
1628 "field attr is required for Attribute");
1629 return NULL;
1630 }
1631 if (!ctx) {
1632 PyErr_SetString(PyExc_ValueError,
1633 "field ctx is required for Attribute");
1634 return NULL;
1635 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001636 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001637 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001638 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001639 return NULL;
1640 }
1641 p->kind = Attribute_kind;
1642 p->v.Attribute.value = value;
1643 p->v.Attribute.attr = attr;
1644 p->v.Attribute.ctx = ctx;
1645 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001646 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001647 return p;
1648}
1649
1650expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001651Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int
1652 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001653{
1654 expr_ty p;
1655 if (!value) {
1656 PyErr_SetString(PyExc_ValueError,
1657 "field value is required for Subscript");
1658 return NULL;
1659 }
1660 if (!slice) {
1661 PyErr_SetString(PyExc_ValueError,
1662 "field slice is required for Subscript");
1663 return NULL;
1664 }
1665 if (!ctx) {
1666 PyErr_SetString(PyExc_ValueError,
1667 "field ctx is required for Subscript");
1668 return NULL;
1669 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001670 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001671 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001672 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001673 return NULL;
1674 }
1675 p->kind = Subscript_kind;
1676 p->v.Subscript.value = value;
1677 p->v.Subscript.slice = slice;
1678 p->v.Subscript.ctx = ctx;
1679 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001680 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001681 return p;
1682}
1683
1684expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001685Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena
1686 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001687{
1688 expr_ty p;
1689 if (!id) {
1690 PyErr_SetString(PyExc_ValueError,
1691 "field id is required for Name");
1692 return NULL;
1693 }
1694 if (!ctx) {
1695 PyErr_SetString(PyExc_ValueError,
1696 "field ctx is required for Name");
1697 return NULL;
1698 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001699 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001700 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001701 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001702 return NULL;
1703 }
1704 p->kind = Name_kind;
1705 p->v.Name.id = id;
1706 p->v.Name.ctx = ctx;
1707 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001708 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001709 return p;
1710}
1711
1712expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001713List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1714 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001715{
1716 expr_ty p;
1717 if (!ctx) {
1718 PyErr_SetString(PyExc_ValueError,
1719 "field ctx is required for List");
1720 return NULL;
1721 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001722 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001723 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001724 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001725 return NULL;
1726 }
1727 p->kind = List_kind;
1728 p->v.List.elts = elts;
1729 p->v.List.ctx = ctx;
1730 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001731 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001732 return p;
1733}
1734
1735expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001736Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1737 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001738{
1739 expr_ty p;
1740 if (!ctx) {
1741 PyErr_SetString(PyExc_ValueError,
1742 "field ctx is required for Tuple");
1743 return NULL;
1744 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001745 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001746 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001747 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001748 return NULL;
1749 }
1750 p->kind = Tuple_kind;
1751 p->v.Tuple.elts = elts;
1752 p->v.Tuple.ctx = ctx;
1753 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001754 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001755 return p;
1756}
1757
1758slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001759Ellipsis(PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001760{
1761 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001762 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001763 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001764 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001765 return NULL;
1766 }
1767 p->kind = Ellipsis_kind;
1768 return p;
1769}
1770
1771slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001772Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001773{
1774 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001775 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001776 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001777 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001778 return NULL;
1779 }
1780 p->kind = Slice_kind;
1781 p->v.Slice.lower = lower;
1782 p->v.Slice.upper = upper;
1783 p->v.Slice.step = step;
1784 return p;
1785}
1786
1787slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001788ExtSlice(asdl_seq * dims, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001789{
1790 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001791 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001792 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001793 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001794 return NULL;
1795 }
1796 p->kind = ExtSlice_kind;
1797 p->v.ExtSlice.dims = dims;
1798 return p;
1799}
1800
1801slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001802Index(expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001803{
1804 slice_ty p;
1805 if (!value) {
1806 PyErr_SetString(PyExc_ValueError,
1807 "field value is required for Index");
1808 return NULL;
1809 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001810 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001811 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001812 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001813 return NULL;
1814 }
1815 p->kind = Index_kind;
1816 p->v.Index.value = value;
1817 return p;
1818}
1819
1820comprehension_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001821comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001822{
1823 comprehension_ty p;
1824 if (!target) {
1825 PyErr_SetString(PyExc_ValueError,
1826 "field target is required for comprehension");
1827 return NULL;
1828 }
1829 if (!iter) {
1830 PyErr_SetString(PyExc_ValueError,
1831 "field iter is required for comprehension");
1832 return NULL;
1833 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001834 p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001835 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001836 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001837 return NULL;
1838 }
1839 p->target = target;
1840 p->iter = iter;
1841 p->ifs = ifs;
1842 return p;
1843}
1844
1845excepthandler_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001846excepthandler(expr_ty type, expr_ty name, asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001847{
1848 excepthandler_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001849 p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001850 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001851 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001852 return NULL;
1853 }
1854 p->type = type;
1855 p->name = name;
1856 p->body = body;
1857 return p;
1858}
1859
1860arguments_ty
1861arguments(asdl_seq * args, identifier vararg, identifier kwarg, asdl_seq *
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001862 defaults, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001863{
1864 arguments_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001865 p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001866 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001867 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001868 return NULL;
1869 }
1870 p->args = args;
1871 p->vararg = vararg;
1872 p->kwarg = kwarg;
1873 p->defaults = defaults;
1874 return p;
1875}
1876
1877keyword_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001878keyword(identifier arg, expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001879{
1880 keyword_ty p;
1881 if (!arg) {
1882 PyErr_SetString(PyExc_ValueError,
1883 "field arg is required for keyword");
1884 return NULL;
1885 }
1886 if (!value) {
1887 PyErr_SetString(PyExc_ValueError,
1888 "field value is required for keyword");
1889 return NULL;
1890 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001891 p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001892 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001893 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001894 return NULL;
1895 }
1896 p->arg = arg;
1897 p->value = value;
1898 return p;
1899}
1900
1901alias_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001902alias(identifier name, identifier asname, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001903{
1904 alias_ty p;
1905 if (!name) {
1906 PyErr_SetString(PyExc_ValueError,
1907 "field name is required for alias");
1908 return NULL;
1909 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001910 p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001911 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001912 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001913 return NULL;
1914 }
1915 p->name = name;
1916 p->asname = asname;
1917 return p;
1918}
1919
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001920
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001921PyObject*
1922ast2obj_mod(void* _o)
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001923{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001924 mod_ty o = (mod_ty)_o;
1925 PyObject *result = NULL, *value = NULL;
1926 if (!o) {
1927 Py_INCREF(Py_None);
1928 return Py_None;
1929 }
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001930
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001931 switch (o->kind) {
1932 case Module_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001933 result = PyType_GenericNew(Module_type, NULL, NULL);
1934 if (!result) goto failed;
1935 value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
1936 if (!value) goto failed;
1937 if (PyObject_SetAttrString(result, "body", value) == -1)
1938 goto failed;
1939 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001940 break;
1941 case Interactive_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001942 result = PyType_GenericNew(Interactive_type, NULL, NULL);
1943 if (!result) goto failed;
1944 value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
1945 if (!value) goto failed;
1946 if (PyObject_SetAttrString(result, "body", value) == -1)
1947 goto failed;
1948 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001949 break;
1950 case Expression_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001951 result = PyType_GenericNew(Expression_type, NULL, NULL);
1952 if (!result) goto failed;
1953 value = ast2obj_expr(o->v.Expression.body);
1954 if (!value) goto failed;
1955 if (PyObject_SetAttrString(result, "body", value) == -1)
1956 goto failed;
1957 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001958 break;
1959 case Suite_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001960 result = PyType_GenericNew(Suite_type, NULL, NULL);
1961 if (!result) goto failed;
1962 value = ast2obj_list(o->v.Suite.body, ast2obj_stmt);
1963 if (!value) goto failed;
1964 if (PyObject_SetAttrString(result, "body", value) == -1)
1965 goto failed;
1966 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001967 break;
1968 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001969 return result;
1970failed:
1971 Py_XDECREF(value);
1972 Py_XDECREF(result);
1973 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001974}
1975
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001976PyObject*
1977ast2obj_stmt(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001978{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001979 stmt_ty o = (stmt_ty)_o;
1980 PyObject *result = NULL, *value = NULL;
1981 if (!o) {
1982 Py_INCREF(Py_None);
1983 return Py_None;
1984 }
1985
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001986 switch (o->kind) {
1987 case FunctionDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001988 result = PyType_GenericNew(FunctionDef_type, NULL, NULL);
1989 if (!result) goto failed;
1990 value = ast2obj_identifier(o->v.FunctionDef.name);
1991 if (!value) goto failed;
1992 if (PyObject_SetAttrString(result, "name", value) == -1)
1993 goto failed;
1994 Py_DECREF(value);
1995 value = ast2obj_arguments(o->v.FunctionDef.args);
1996 if (!value) goto failed;
1997 if (PyObject_SetAttrString(result, "args", value) == -1)
1998 goto failed;
1999 Py_DECREF(value);
2000 value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
2001 if (!value) goto failed;
2002 if (PyObject_SetAttrString(result, "body", value) == -1)
2003 goto failed;
2004 Py_DECREF(value);
2005 value = ast2obj_list(o->v.FunctionDef.decorators, ast2obj_expr);
2006 if (!value) goto failed;
2007 if (PyObject_SetAttrString(result, "decorators", value) == -1)
2008 goto failed;
2009 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002010 break;
2011 case ClassDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002012 result = PyType_GenericNew(ClassDef_type, NULL, NULL);
2013 if (!result) goto failed;
2014 value = ast2obj_identifier(o->v.ClassDef.name);
2015 if (!value) goto failed;
2016 if (PyObject_SetAttrString(result, "name", value) == -1)
2017 goto failed;
2018 Py_DECREF(value);
2019 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
2020 if (!value) goto failed;
2021 if (PyObject_SetAttrString(result, "bases", value) == -1)
2022 goto failed;
2023 Py_DECREF(value);
2024 value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
2025 if (!value) goto failed;
2026 if (PyObject_SetAttrString(result, "body", value) == -1)
2027 goto failed;
2028 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002029 break;
2030 case Return_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002031 result = PyType_GenericNew(Return_type, NULL, NULL);
2032 if (!result) goto failed;
2033 value = ast2obj_expr(o->v.Return.value);
2034 if (!value) goto failed;
2035 if (PyObject_SetAttrString(result, "value", value) == -1)
2036 goto failed;
2037 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002038 break;
2039 case Delete_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002040 result = PyType_GenericNew(Delete_type, NULL, NULL);
2041 if (!result) goto failed;
2042 value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
2043 if (!value) goto failed;
2044 if (PyObject_SetAttrString(result, "targets", value) == -1)
2045 goto failed;
2046 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002047 break;
2048 case Assign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002049 result = PyType_GenericNew(Assign_type, NULL, NULL);
2050 if (!result) goto failed;
2051 value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
2052 if (!value) goto failed;
2053 if (PyObject_SetAttrString(result, "targets", value) == -1)
2054 goto failed;
2055 Py_DECREF(value);
2056 value = ast2obj_expr(o->v.Assign.value);
2057 if (!value) goto failed;
2058 if (PyObject_SetAttrString(result, "value", value) == -1)
2059 goto failed;
2060 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002061 break;
2062 case AugAssign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002063 result = PyType_GenericNew(AugAssign_type, NULL, NULL);
2064 if (!result) goto failed;
2065 value = ast2obj_expr(o->v.AugAssign.target);
2066 if (!value) goto failed;
2067 if (PyObject_SetAttrString(result, "target", value) == -1)
2068 goto failed;
2069 Py_DECREF(value);
2070 value = ast2obj_operator(o->v.AugAssign.op);
2071 if (!value) goto failed;
2072 if (PyObject_SetAttrString(result, "op", value) == -1)
2073 goto failed;
2074 Py_DECREF(value);
2075 value = ast2obj_expr(o->v.AugAssign.value);
2076 if (!value) goto failed;
2077 if (PyObject_SetAttrString(result, "value", value) == -1)
2078 goto failed;
2079 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002080 break;
2081 case Print_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002082 result = PyType_GenericNew(Print_type, NULL, NULL);
2083 if (!result) goto failed;
2084 value = ast2obj_expr(o->v.Print.dest);
2085 if (!value) goto failed;
2086 if (PyObject_SetAttrString(result, "dest", value) == -1)
2087 goto failed;
2088 Py_DECREF(value);
2089 value = ast2obj_list(o->v.Print.values, ast2obj_expr);
2090 if (!value) goto failed;
2091 if (PyObject_SetAttrString(result, "values", value) == -1)
2092 goto failed;
2093 Py_DECREF(value);
2094 value = ast2obj_bool(o->v.Print.nl);
2095 if (!value) goto failed;
2096 if (PyObject_SetAttrString(result, "nl", value) == -1)
2097 goto failed;
2098 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002099 break;
2100 case For_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002101 result = PyType_GenericNew(For_type, NULL, NULL);
2102 if (!result) goto failed;
2103 value = ast2obj_expr(o->v.For.target);
2104 if (!value) goto failed;
2105 if (PyObject_SetAttrString(result, "target", value) == -1)
2106 goto failed;
2107 Py_DECREF(value);
2108 value = ast2obj_expr(o->v.For.iter);
2109 if (!value) goto failed;
2110 if (PyObject_SetAttrString(result, "iter", value) == -1)
2111 goto failed;
2112 Py_DECREF(value);
2113 value = ast2obj_list(o->v.For.body, ast2obj_stmt);
2114 if (!value) goto failed;
2115 if (PyObject_SetAttrString(result, "body", value) == -1)
2116 goto failed;
2117 Py_DECREF(value);
2118 value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
2119 if (!value) goto failed;
2120 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2121 goto failed;
2122 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002123 break;
2124 case While_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002125 result = PyType_GenericNew(While_type, NULL, NULL);
2126 if (!result) goto failed;
2127 value = ast2obj_expr(o->v.While.test);
2128 if (!value) goto failed;
2129 if (PyObject_SetAttrString(result, "test", value) == -1)
2130 goto failed;
2131 Py_DECREF(value);
2132 value = ast2obj_list(o->v.While.body, ast2obj_stmt);
2133 if (!value) goto failed;
2134 if (PyObject_SetAttrString(result, "body", value) == -1)
2135 goto failed;
2136 Py_DECREF(value);
2137 value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);
2138 if (!value) goto failed;
2139 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2140 goto failed;
2141 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002142 break;
2143 case If_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002144 result = PyType_GenericNew(If_type, NULL, NULL);
2145 if (!result) goto failed;
2146 value = ast2obj_expr(o->v.If.test);
2147 if (!value) goto failed;
2148 if (PyObject_SetAttrString(result, "test", value) == -1)
2149 goto failed;
2150 Py_DECREF(value);
2151 value = ast2obj_list(o->v.If.body, ast2obj_stmt);
2152 if (!value) goto failed;
2153 if (PyObject_SetAttrString(result, "body", value) == -1)
2154 goto failed;
2155 Py_DECREF(value);
2156 value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
2157 if (!value) goto failed;
2158 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2159 goto failed;
2160 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002161 break;
Guido van Rossumc2e20742006-02-27 22:32:47 +00002162 case With_kind:
2163 result = PyType_GenericNew(With_type, NULL, NULL);
2164 if (!result) goto failed;
2165 value = ast2obj_expr(o->v.With.context_expr);
2166 if (!value) goto failed;
2167 if (PyObject_SetAttrString(result, "context_expr", value) == -1)
2168 goto failed;
2169 Py_DECREF(value);
2170 value = ast2obj_expr(o->v.With.optional_vars);
2171 if (!value) goto failed;
2172 if (PyObject_SetAttrString(result, "optional_vars", value) ==
2173 -1)
2174 goto failed;
2175 Py_DECREF(value);
2176 value = ast2obj_list(o->v.With.body, ast2obj_stmt);
2177 if (!value) goto failed;
2178 if (PyObject_SetAttrString(result, "body", value) == -1)
2179 goto failed;
2180 Py_DECREF(value);
2181 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002182 case Raise_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002183 result = PyType_GenericNew(Raise_type, NULL, NULL);
2184 if (!result) goto failed;
2185 value = ast2obj_expr(o->v.Raise.type);
2186 if (!value) goto failed;
2187 if (PyObject_SetAttrString(result, "type", value) == -1)
2188 goto failed;
2189 Py_DECREF(value);
2190 value = ast2obj_expr(o->v.Raise.inst);
2191 if (!value) goto failed;
2192 if (PyObject_SetAttrString(result, "inst", value) == -1)
2193 goto failed;
2194 Py_DECREF(value);
2195 value = ast2obj_expr(o->v.Raise.tback);
2196 if (!value) goto failed;
2197 if (PyObject_SetAttrString(result, "tback", value) == -1)
2198 goto failed;
2199 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002200 break;
2201 case TryExcept_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002202 result = PyType_GenericNew(TryExcept_type, NULL, NULL);
2203 if (!result) goto failed;
2204 value = ast2obj_list(o->v.TryExcept.body, ast2obj_stmt);
2205 if (!value) goto failed;
2206 if (PyObject_SetAttrString(result, "body", value) == -1)
2207 goto failed;
2208 Py_DECREF(value);
2209 value = ast2obj_list(o->v.TryExcept.handlers,
2210 ast2obj_excepthandler);
2211 if (!value) goto failed;
2212 if (PyObject_SetAttrString(result, "handlers", value) == -1)
2213 goto failed;
2214 Py_DECREF(value);
2215 value = ast2obj_list(o->v.TryExcept.orelse, ast2obj_stmt);
2216 if (!value) goto failed;
2217 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2218 goto failed;
2219 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002220 break;
2221 case TryFinally_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002222 result = PyType_GenericNew(TryFinally_type, NULL, NULL);
2223 if (!result) goto failed;
2224 value = ast2obj_list(o->v.TryFinally.body, ast2obj_stmt);
2225 if (!value) goto failed;
2226 if (PyObject_SetAttrString(result, "body", value) == -1)
2227 goto failed;
2228 Py_DECREF(value);
2229 value = ast2obj_list(o->v.TryFinally.finalbody, ast2obj_stmt);
2230 if (!value) goto failed;
2231 if (PyObject_SetAttrString(result, "finalbody", value) == -1)
2232 goto failed;
2233 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002234 break;
2235 case Assert_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002236 result = PyType_GenericNew(Assert_type, NULL, NULL);
2237 if (!result) goto failed;
2238 value = ast2obj_expr(o->v.Assert.test);
2239 if (!value) goto failed;
2240 if (PyObject_SetAttrString(result, "test", value) == -1)
2241 goto failed;
2242 Py_DECREF(value);
2243 value = ast2obj_expr(o->v.Assert.msg);
2244 if (!value) goto failed;
2245 if (PyObject_SetAttrString(result, "msg", value) == -1)
2246 goto failed;
2247 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002248 break;
2249 case Import_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002250 result = PyType_GenericNew(Import_type, NULL, NULL);
2251 if (!result) goto failed;
2252 value = ast2obj_list(o->v.Import.names, ast2obj_alias);
2253 if (!value) goto failed;
2254 if (PyObject_SetAttrString(result, "names", value) == -1)
2255 goto failed;
2256 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002257 break;
2258 case ImportFrom_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002259 result = PyType_GenericNew(ImportFrom_type, NULL, NULL);
2260 if (!result) goto failed;
2261 value = ast2obj_identifier(o->v.ImportFrom.module);
2262 if (!value) goto failed;
2263 if (PyObject_SetAttrString(result, "module", value) == -1)
2264 goto failed;
2265 Py_DECREF(value);
2266 value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
2267 if (!value) goto failed;
2268 if (PyObject_SetAttrString(result, "names", value) == -1)
2269 goto failed;
2270 Py_DECREF(value);
Thomas Woutersf7f438b2006-02-28 16:09:29 +00002271 value = ast2obj_int(o->v.ImportFrom.level);
2272 if (!value) goto failed;
2273 if (PyObject_SetAttrString(result, "level", value) == -1)
2274 goto failed;
2275 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002276 break;
2277 case Exec_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002278 result = PyType_GenericNew(Exec_type, NULL, NULL);
2279 if (!result) goto failed;
2280 value = ast2obj_expr(o->v.Exec.body);
2281 if (!value) goto failed;
2282 if (PyObject_SetAttrString(result, "body", value) == -1)
2283 goto failed;
2284 Py_DECREF(value);
2285 value = ast2obj_expr(o->v.Exec.globals);
2286 if (!value) goto failed;
2287 if (PyObject_SetAttrString(result, "globals", value) == -1)
2288 goto failed;
2289 Py_DECREF(value);
2290 value = ast2obj_expr(o->v.Exec.locals);
2291 if (!value) goto failed;
2292 if (PyObject_SetAttrString(result, "locals", value) == -1)
2293 goto failed;
2294 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002295 break;
2296 case Global_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002297 result = PyType_GenericNew(Global_type, NULL, NULL);
2298 if (!result) goto failed;
2299 value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
2300 if (!value) goto failed;
2301 if (PyObject_SetAttrString(result, "names", value) == -1)
2302 goto failed;
2303 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002304 break;
2305 case Expr_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002306 result = PyType_GenericNew(Expr_type, NULL, NULL);
2307 if (!result) goto failed;
2308 value = ast2obj_expr(o->v.Expr.value);
2309 if (!value) goto failed;
2310 if (PyObject_SetAttrString(result, "value", value) == -1)
2311 goto failed;
2312 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002313 break;
2314 case Pass_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002315 result = PyType_GenericNew(Pass_type, NULL, NULL);
2316 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002317 break;
2318 case Break_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002319 result = PyType_GenericNew(Break_type, NULL, NULL);
2320 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002321 break;
2322 case Continue_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002323 result = PyType_GenericNew(Continue_type, NULL, NULL);
2324 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002325 break;
2326 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002327 value = ast2obj_int(o->lineno);
2328 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002329 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2330 goto failed;
2331 Py_DECREF(value);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002332 value = ast2obj_int(o->col_offset);
2333 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002334 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2335 goto failed;
2336 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002337 return result;
2338failed:
2339 Py_XDECREF(value);
2340 Py_XDECREF(result);
2341 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002342}
2343
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002344PyObject*
2345ast2obj_expr(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002346{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002347 expr_ty o = (expr_ty)_o;
2348 PyObject *result = NULL, *value = NULL;
2349 if (!o) {
2350 Py_INCREF(Py_None);
2351 return Py_None;
2352 }
2353
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002354 switch (o->kind) {
2355 case BoolOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002356 result = PyType_GenericNew(BoolOp_type, NULL, NULL);
2357 if (!result) goto failed;
2358 value = ast2obj_boolop(o->v.BoolOp.op);
2359 if (!value) goto failed;
2360 if (PyObject_SetAttrString(result, "op", value) == -1)
2361 goto failed;
2362 Py_DECREF(value);
2363 value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
2364 if (!value) goto failed;
2365 if (PyObject_SetAttrString(result, "values", value) == -1)
2366 goto failed;
2367 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002368 break;
2369 case BinOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002370 result = PyType_GenericNew(BinOp_type, NULL, NULL);
2371 if (!result) goto failed;
2372 value = ast2obj_expr(o->v.BinOp.left);
2373 if (!value) goto failed;
2374 if (PyObject_SetAttrString(result, "left", value) == -1)
2375 goto failed;
2376 Py_DECREF(value);
2377 value = ast2obj_operator(o->v.BinOp.op);
2378 if (!value) goto failed;
2379 if (PyObject_SetAttrString(result, "op", value) == -1)
2380 goto failed;
2381 Py_DECREF(value);
2382 value = ast2obj_expr(o->v.BinOp.right);
2383 if (!value) goto failed;
2384 if (PyObject_SetAttrString(result, "right", value) == -1)
2385 goto failed;
2386 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002387 break;
2388 case UnaryOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002389 result = PyType_GenericNew(UnaryOp_type, NULL, NULL);
2390 if (!result) goto failed;
2391 value = ast2obj_unaryop(o->v.UnaryOp.op);
2392 if (!value) goto failed;
2393 if (PyObject_SetAttrString(result, "op", value) == -1)
2394 goto failed;
2395 Py_DECREF(value);
2396 value = ast2obj_expr(o->v.UnaryOp.operand);
2397 if (!value) goto failed;
2398 if (PyObject_SetAttrString(result, "operand", value) == -1)
2399 goto failed;
2400 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002401 break;
2402 case Lambda_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002403 result = PyType_GenericNew(Lambda_type, NULL, NULL);
2404 if (!result) goto failed;
2405 value = ast2obj_arguments(o->v.Lambda.args);
2406 if (!value) goto failed;
2407 if (PyObject_SetAttrString(result, "args", value) == -1)
2408 goto failed;
2409 Py_DECREF(value);
2410 value = ast2obj_expr(o->v.Lambda.body);
2411 if (!value) goto failed;
2412 if (PyObject_SetAttrString(result, "body", value) == -1)
2413 goto failed;
2414 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002415 break;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002416 case IfExp_kind:
2417 result = PyType_GenericNew(IfExp_type, NULL, NULL);
2418 if (!result) goto failed;
2419 value = ast2obj_expr(o->v.IfExp.test);
2420 if (!value) goto failed;
2421 if (PyObject_SetAttrString(result, "test", value) == -1)
2422 goto failed;
2423 Py_DECREF(value);
2424 value = ast2obj_expr(o->v.IfExp.body);
2425 if (!value) goto failed;
2426 if (PyObject_SetAttrString(result, "body", value) == -1)
2427 goto failed;
2428 Py_DECREF(value);
2429 value = ast2obj_expr(o->v.IfExp.orelse);
2430 if (!value) goto failed;
2431 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2432 goto failed;
2433 Py_DECREF(value);
2434 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002435 case Dict_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002436 result = PyType_GenericNew(Dict_type, NULL, NULL);
2437 if (!result) goto failed;
2438 value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
2439 if (!value) goto failed;
2440 if (PyObject_SetAttrString(result, "keys", value) == -1)
2441 goto failed;
2442 Py_DECREF(value);
2443 value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
2444 if (!value) goto failed;
2445 if (PyObject_SetAttrString(result, "values", value) == -1)
2446 goto failed;
2447 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002448 break;
2449 case ListComp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002450 result = PyType_GenericNew(ListComp_type, NULL, NULL);
2451 if (!result) goto failed;
2452 value = ast2obj_expr(o->v.ListComp.elt);
2453 if (!value) goto failed;
2454 if (PyObject_SetAttrString(result, "elt", value) == -1)
2455 goto failed;
2456 Py_DECREF(value);
2457 value = ast2obj_list(o->v.ListComp.generators,
2458 ast2obj_comprehension);
2459 if (!value) goto failed;
2460 if (PyObject_SetAttrString(result, "generators", value) == -1)
2461 goto failed;
2462 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002463 break;
2464 case GeneratorExp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002465 result = PyType_GenericNew(GeneratorExp_type, NULL, NULL);
2466 if (!result) goto failed;
2467 value = ast2obj_expr(o->v.GeneratorExp.elt);
2468 if (!value) goto failed;
2469 if (PyObject_SetAttrString(result, "elt", value) == -1)
2470 goto failed;
2471 Py_DECREF(value);
2472 value = ast2obj_list(o->v.GeneratorExp.generators,
2473 ast2obj_comprehension);
2474 if (!value) goto failed;
2475 if (PyObject_SetAttrString(result, "generators", value) == -1)
2476 goto failed;
2477 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002478 break;
2479 case Yield_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002480 result = PyType_GenericNew(Yield_type, NULL, NULL);
2481 if (!result) goto failed;
2482 value = ast2obj_expr(o->v.Yield.value);
2483 if (!value) goto failed;
2484 if (PyObject_SetAttrString(result, "value", value) == -1)
2485 goto failed;
2486 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002487 break;
2488 case Compare_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002489 result = PyType_GenericNew(Compare_type, NULL, NULL);
2490 if (!result) goto failed;
2491 value = ast2obj_expr(o->v.Compare.left);
2492 if (!value) goto failed;
2493 if (PyObject_SetAttrString(result, "left", value) == -1)
2494 goto failed;
2495 Py_DECREF(value);
Martin v. Löwisce1d5d22006-02-26 20:51:25 +00002496 {
2497 int i, n = asdl_seq_LEN(o->v.Compare.ops);
2498 value = PyList_New(n);
2499 if (!value) goto failed;
2500 for(i = 0; i < n; i++)
2501 PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
2502 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002503 if (!value) goto failed;
2504 if (PyObject_SetAttrString(result, "ops", value) == -1)
2505 goto failed;
2506 Py_DECREF(value);
2507 value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
2508 if (!value) goto failed;
2509 if (PyObject_SetAttrString(result, "comparators", value) == -1)
2510 goto failed;
2511 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002512 break;
2513 case Call_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002514 result = PyType_GenericNew(Call_type, NULL, NULL);
2515 if (!result) goto failed;
2516 value = ast2obj_expr(o->v.Call.func);
2517 if (!value) goto failed;
2518 if (PyObject_SetAttrString(result, "func", value) == -1)
2519 goto failed;
2520 Py_DECREF(value);
2521 value = ast2obj_list(o->v.Call.args, ast2obj_expr);
2522 if (!value) goto failed;
2523 if (PyObject_SetAttrString(result, "args", value) == -1)
2524 goto failed;
2525 Py_DECREF(value);
2526 value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
2527 if (!value) goto failed;
2528 if (PyObject_SetAttrString(result, "keywords", value) == -1)
2529 goto failed;
2530 Py_DECREF(value);
2531 value = ast2obj_expr(o->v.Call.starargs);
2532 if (!value) goto failed;
2533 if (PyObject_SetAttrString(result, "starargs", value) == -1)
2534 goto failed;
2535 Py_DECREF(value);
2536 value = ast2obj_expr(o->v.Call.kwargs);
2537 if (!value) goto failed;
2538 if (PyObject_SetAttrString(result, "kwargs", value) == -1)
2539 goto failed;
2540 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002541 break;
2542 case Repr_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002543 result = PyType_GenericNew(Repr_type, NULL, NULL);
2544 if (!result) goto failed;
2545 value = ast2obj_expr(o->v.Repr.value);
2546 if (!value) goto failed;
2547 if (PyObject_SetAttrString(result, "value", value) == -1)
2548 goto failed;
2549 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002550 break;
2551 case Num_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002552 result = PyType_GenericNew(Num_type, NULL, NULL);
2553 if (!result) goto failed;
2554 value = ast2obj_object(o->v.Num.n);
2555 if (!value) goto failed;
2556 if (PyObject_SetAttrString(result, "n", value) == -1)
2557 goto failed;
2558 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002559 break;
2560 case Str_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002561 result = PyType_GenericNew(Str_type, NULL, NULL);
2562 if (!result) goto failed;
2563 value = ast2obj_string(o->v.Str.s);
2564 if (!value) goto failed;
2565 if (PyObject_SetAttrString(result, "s", value) == -1)
2566 goto failed;
2567 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002568 break;
2569 case Attribute_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002570 result = PyType_GenericNew(Attribute_type, NULL, NULL);
2571 if (!result) goto failed;
2572 value = ast2obj_expr(o->v.Attribute.value);
2573 if (!value) goto failed;
2574 if (PyObject_SetAttrString(result, "value", value) == -1)
2575 goto failed;
2576 Py_DECREF(value);
2577 value = ast2obj_identifier(o->v.Attribute.attr);
2578 if (!value) goto failed;
2579 if (PyObject_SetAttrString(result, "attr", value) == -1)
2580 goto failed;
2581 Py_DECREF(value);
2582 value = ast2obj_expr_context(o->v.Attribute.ctx);
2583 if (!value) goto failed;
2584 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2585 goto failed;
2586 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002587 break;
2588 case Subscript_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002589 result = PyType_GenericNew(Subscript_type, NULL, NULL);
2590 if (!result) goto failed;
2591 value = ast2obj_expr(o->v.Subscript.value);
2592 if (!value) goto failed;
2593 if (PyObject_SetAttrString(result, "value", value) == -1)
2594 goto failed;
2595 Py_DECREF(value);
2596 value = ast2obj_slice(o->v.Subscript.slice);
2597 if (!value) goto failed;
2598 if (PyObject_SetAttrString(result, "slice", value) == -1)
2599 goto failed;
2600 Py_DECREF(value);
2601 value = ast2obj_expr_context(o->v.Subscript.ctx);
2602 if (!value) goto failed;
2603 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2604 goto failed;
2605 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002606 break;
2607 case Name_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002608 result = PyType_GenericNew(Name_type, NULL, NULL);
2609 if (!result) goto failed;
2610 value = ast2obj_identifier(o->v.Name.id);
2611 if (!value) goto failed;
2612 if (PyObject_SetAttrString(result, "id", value) == -1)
2613 goto failed;
2614 Py_DECREF(value);
2615 value = ast2obj_expr_context(o->v.Name.ctx);
2616 if (!value) goto failed;
2617 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2618 goto failed;
2619 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002620 break;
2621 case List_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002622 result = PyType_GenericNew(List_type, NULL, NULL);
2623 if (!result) goto failed;
2624 value = ast2obj_list(o->v.List.elts, ast2obj_expr);
2625 if (!value) goto failed;
2626 if (PyObject_SetAttrString(result, "elts", value) == -1)
2627 goto failed;
2628 Py_DECREF(value);
2629 value = ast2obj_expr_context(o->v.List.ctx);
2630 if (!value) goto failed;
2631 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2632 goto failed;
2633 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002634 break;
2635 case Tuple_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002636 result = PyType_GenericNew(Tuple_type, NULL, NULL);
2637 if (!result) goto failed;
2638 value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
2639 if (!value) goto failed;
2640 if (PyObject_SetAttrString(result, "elts", value) == -1)
2641 goto failed;
2642 Py_DECREF(value);
2643 value = ast2obj_expr_context(o->v.Tuple.ctx);
2644 if (!value) goto failed;
2645 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2646 goto failed;
2647 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002648 break;
2649 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002650 value = ast2obj_int(o->lineno);
2651 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002652 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2653 goto failed;
2654 Py_DECREF(value);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002655 value = ast2obj_int(o->col_offset);
2656 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002657 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2658 goto failed;
2659 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002660 return result;
2661failed:
2662 Py_XDECREF(value);
2663 Py_XDECREF(result);
2664 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002665}
2666
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002667PyObject* ast2obj_expr_context(expr_context_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002668{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002669 switch(o) {
2670 case Load:
2671 Py_INCREF(Load_singleton);
2672 return Load_singleton;
2673 case Store:
2674 Py_INCREF(Store_singleton);
2675 return Store_singleton;
2676 case Del:
2677 Py_INCREF(Del_singleton);
2678 return Del_singleton;
2679 case AugLoad:
2680 Py_INCREF(AugLoad_singleton);
2681 return AugLoad_singleton;
2682 case AugStore:
2683 Py_INCREF(AugStore_singleton);
2684 return AugStore_singleton;
2685 case Param:
2686 Py_INCREF(Param_singleton);
2687 return Param_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002688 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002689 return NULL; /* cannot happen */
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002690}
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002691PyObject*
2692ast2obj_slice(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002693{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002694 slice_ty o = (slice_ty)_o;
2695 PyObject *result = NULL, *value = NULL;
2696 if (!o) {
2697 Py_INCREF(Py_None);
2698 return Py_None;
2699 }
2700
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002701 switch (o->kind) {
2702 case Ellipsis_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002703 result = PyType_GenericNew(Ellipsis_type, NULL, NULL);
2704 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002705 break;
2706 case Slice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002707 result = PyType_GenericNew(Slice_type, NULL, NULL);
2708 if (!result) goto failed;
2709 value = ast2obj_expr(o->v.Slice.lower);
2710 if (!value) goto failed;
2711 if (PyObject_SetAttrString(result, "lower", value) == -1)
2712 goto failed;
2713 Py_DECREF(value);
2714 value = ast2obj_expr(o->v.Slice.upper);
2715 if (!value) goto failed;
2716 if (PyObject_SetAttrString(result, "upper", value) == -1)
2717 goto failed;
2718 Py_DECREF(value);
2719 value = ast2obj_expr(o->v.Slice.step);
2720 if (!value) goto failed;
2721 if (PyObject_SetAttrString(result, "step", value) == -1)
2722 goto failed;
2723 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002724 break;
2725 case ExtSlice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002726 result = PyType_GenericNew(ExtSlice_type, NULL, NULL);
2727 if (!result) goto failed;
2728 value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice);
2729 if (!value) goto failed;
2730 if (PyObject_SetAttrString(result, "dims", value) == -1)
2731 goto failed;
2732 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002733 break;
2734 case Index_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002735 result = PyType_GenericNew(Index_type, NULL, NULL);
2736 if (!result) goto failed;
2737 value = ast2obj_expr(o->v.Index.value);
2738 if (!value) goto failed;
2739 if (PyObject_SetAttrString(result, "value", value) == -1)
2740 goto failed;
2741 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002742 break;
2743 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002744 return result;
2745failed:
2746 Py_XDECREF(value);
2747 Py_XDECREF(result);
2748 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002749}
2750
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002751PyObject* ast2obj_boolop(boolop_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002752{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002753 switch(o) {
2754 case And:
2755 Py_INCREF(And_singleton);
2756 return And_singleton;
2757 case Or:
2758 Py_INCREF(Or_singleton);
2759 return Or_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002760 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002761 return NULL; /* cannot happen */
2762}
2763PyObject* ast2obj_operator(operator_ty o)
2764{
2765 switch(o) {
2766 case Add:
2767 Py_INCREF(Add_singleton);
2768 return Add_singleton;
2769 case Sub:
2770 Py_INCREF(Sub_singleton);
2771 return Sub_singleton;
2772 case Mult:
2773 Py_INCREF(Mult_singleton);
2774 return Mult_singleton;
2775 case Div:
2776 Py_INCREF(Div_singleton);
2777 return Div_singleton;
2778 case Mod:
2779 Py_INCREF(Mod_singleton);
2780 return Mod_singleton;
2781 case Pow:
2782 Py_INCREF(Pow_singleton);
2783 return Pow_singleton;
2784 case LShift:
2785 Py_INCREF(LShift_singleton);
2786 return LShift_singleton;
2787 case RShift:
2788 Py_INCREF(RShift_singleton);
2789 return RShift_singleton;
2790 case BitOr:
2791 Py_INCREF(BitOr_singleton);
2792 return BitOr_singleton;
2793 case BitXor:
2794 Py_INCREF(BitXor_singleton);
2795 return BitXor_singleton;
2796 case BitAnd:
2797 Py_INCREF(BitAnd_singleton);
2798 return BitAnd_singleton;
2799 case FloorDiv:
2800 Py_INCREF(FloorDiv_singleton);
2801 return FloorDiv_singleton;
2802 }
2803 return NULL; /* cannot happen */
2804}
2805PyObject* ast2obj_unaryop(unaryop_ty o)
2806{
2807 switch(o) {
2808 case Invert:
2809 Py_INCREF(Invert_singleton);
2810 return Invert_singleton;
2811 case Not:
2812 Py_INCREF(Not_singleton);
2813 return Not_singleton;
2814 case UAdd:
2815 Py_INCREF(UAdd_singleton);
2816 return UAdd_singleton;
2817 case USub:
2818 Py_INCREF(USub_singleton);
2819 return USub_singleton;
2820 }
2821 return NULL; /* cannot happen */
2822}
2823PyObject* ast2obj_cmpop(cmpop_ty o)
2824{
2825 switch(o) {
2826 case Eq:
2827 Py_INCREF(Eq_singleton);
2828 return Eq_singleton;
2829 case NotEq:
2830 Py_INCREF(NotEq_singleton);
2831 return NotEq_singleton;
2832 case Lt:
2833 Py_INCREF(Lt_singleton);
2834 return Lt_singleton;
2835 case LtE:
2836 Py_INCREF(LtE_singleton);
2837 return LtE_singleton;
2838 case Gt:
2839 Py_INCREF(Gt_singleton);
2840 return Gt_singleton;
2841 case GtE:
2842 Py_INCREF(GtE_singleton);
2843 return GtE_singleton;
2844 case Is:
2845 Py_INCREF(Is_singleton);
2846 return Is_singleton;
2847 case IsNot:
2848 Py_INCREF(IsNot_singleton);
2849 return IsNot_singleton;
2850 case In:
2851 Py_INCREF(In_singleton);
2852 return In_singleton;
2853 case NotIn:
2854 Py_INCREF(NotIn_singleton);
2855 return NotIn_singleton;
2856 }
2857 return NULL; /* cannot happen */
2858}
2859PyObject*
2860ast2obj_comprehension(void* _o)
2861{
2862 comprehension_ty o = (comprehension_ty)_o;
2863 PyObject *result = NULL, *value = NULL;
2864 if (!o) {
2865 Py_INCREF(Py_None);
2866 return Py_None;
2867 }
2868
2869 result = PyType_GenericNew(comprehension_type, NULL, NULL);
2870 if (!result) return NULL;
2871 value = ast2obj_expr(o->target);
2872 if (!value) goto failed;
2873 if (PyObject_SetAttrString(result, "target", value) == -1)
2874 goto failed;
2875 Py_DECREF(value);
2876 value = ast2obj_expr(o->iter);
2877 if (!value) goto failed;
2878 if (PyObject_SetAttrString(result, "iter", value) == -1)
2879 goto failed;
2880 Py_DECREF(value);
2881 value = ast2obj_list(o->ifs, ast2obj_expr);
2882 if (!value) goto failed;
2883 if (PyObject_SetAttrString(result, "ifs", value) == -1)
2884 goto failed;
2885 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002886 return result;
2887failed:
2888 Py_XDECREF(value);
2889 Py_XDECREF(result);
2890 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002891}
2892
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002893PyObject*
2894ast2obj_excepthandler(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002895{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002896 excepthandler_ty o = (excepthandler_ty)_o;
2897 PyObject *result = NULL, *value = NULL;
2898 if (!o) {
2899 Py_INCREF(Py_None);
2900 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002901 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002902
2903 result = PyType_GenericNew(excepthandler_type, NULL, NULL);
2904 if (!result) return NULL;
2905 value = ast2obj_expr(o->type);
2906 if (!value) goto failed;
2907 if (PyObject_SetAttrString(result, "type", value) == -1)
2908 goto failed;
2909 Py_DECREF(value);
2910 value = ast2obj_expr(o->name);
2911 if (!value) goto failed;
2912 if (PyObject_SetAttrString(result, "name", value) == -1)
2913 goto failed;
2914 Py_DECREF(value);
2915 value = ast2obj_list(o->body, ast2obj_stmt);
2916 if (!value) goto failed;
2917 if (PyObject_SetAttrString(result, "body", value) == -1)
2918 goto failed;
2919 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002920 return result;
2921failed:
2922 Py_XDECREF(value);
2923 Py_XDECREF(result);
2924 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002925}
2926
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002927PyObject*
2928ast2obj_arguments(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002929{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002930 arguments_ty o = (arguments_ty)_o;
2931 PyObject *result = NULL, *value = NULL;
2932 if (!o) {
2933 Py_INCREF(Py_None);
2934 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002935 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002936
2937 result = PyType_GenericNew(arguments_type, NULL, NULL);
2938 if (!result) return NULL;
2939 value = ast2obj_list(o->args, ast2obj_expr);
2940 if (!value) goto failed;
2941 if (PyObject_SetAttrString(result, "args", value) == -1)
2942 goto failed;
2943 Py_DECREF(value);
2944 value = ast2obj_identifier(o->vararg);
2945 if (!value) goto failed;
2946 if (PyObject_SetAttrString(result, "vararg", value) == -1)
2947 goto failed;
2948 Py_DECREF(value);
2949 value = ast2obj_identifier(o->kwarg);
2950 if (!value) goto failed;
2951 if (PyObject_SetAttrString(result, "kwarg", value) == -1)
2952 goto failed;
2953 Py_DECREF(value);
2954 value = ast2obj_list(o->defaults, ast2obj_expr);
2955 if (!value) goto failed;
2956 if (PyObject_SetAttrString(result, "defaults", value) == -1)
2957 goto failed;
2958 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002959 return result;
2960failed:
2961 Py_XDECREF(value);
2962 Py_XDECREF(result);
2963 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002964}
2965
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002966PyObject*
2967ast2obj_keyword(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002968{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002969 keyword_ty o = (keyword_ty)_o;
2970 PyObject *result = NULL, *value = NULL;
2971 if (!o) {
2972 Py_INCREF(Py_None);
2973 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002974 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002975
2976 result = PyType_GenericNew(keyword_type, NULL, NULL);
2977 if (!result) return NULL;
2978 value = ast2obj_identifier(o->arg);
2979 if (!value) goto failed;
2980 if (PyObject_SetAttrString(result, "arg", value) == -1)
2981 goto failed;
2982 Py_DECREF(value);
2983 value = ast2obj_expr(o->value);
2984 if (!value) goto failed;
2985 if (PyObject_SetAttrString(result, "value", value) == -1)
2986 goto failed;
2987 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002988 return result;
2989failed:
2990 Py_XDECREF(value);
2991 Py_XDECREF(result);
2992 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002993}
2994
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002995PyObject*
2996ast2obj_alias(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002997{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002998 alias_ty o = (alias_ty)_o;
2999 PyObject *result = NULL, *value = NULL;
3000 if (!o) {
3001 Py_INCREF(Py_None);
3002 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003003 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003004
3005 result = PyType_GenericNew(alias_type, NULL, NULL);
3006 if (!result) return NULL;
3007 value = ast2obj_identifier(o->name);
3008 if (!value) goto failed;
3009 if (PyObject_SetAttrString(result, "name", value) == -1)
3010 goto failed;
3011 Py_DECREF(value);
3012 value = ast2obj_identifier(o->asname);
3013 if (!value) goto failed;
3014 if (PyObject_SetAttrString(result, "asname", value) == -1)
3015 goto failed;
3016 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003017 return result;
3018failed:
3019 Py_XDECREF(value);
3020 Py_XDECREF(result);
3021 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003022}
3023
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003024
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003025PyMODINIT_FUNC
3026init_ast(void)
3027{
3028 PyObject *m, *d;
3029 if (!init_types()) return;
3030 m = Py_InitModule3("_ast", NULL, NULL);
3031 if (!m) return;
3032 d = PyModule_GetDict(m);
3033 if (PyDict_SetItemString(d, "AST", (PyObject*)AST_type) < 0) return;
3034 if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)
3035 return;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00003036 if (PyModule_AddStringConstant(m, "__version__", "42753") < 0)
Martin v. Löwisace990c2006-02-28 00:32:31 +00003037 return;
Neal Norwitz19379f12006-04-03 04:50:58 +00003038 if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return;
3039 if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0)
3040 return;
3041 if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type)
3042 < 0) return;
3043 if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) <
3044 0) return;
3045 if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return;
3046 if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return;
3047 if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type)
3048 < 0) return;
3049 if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0)
3050 return;
3051 if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0)
3052 return;
3053 if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0)
3054 return;
3055 if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0)
3056 return;
3057 if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) <
3058 0) return;
3059 if (PyDict_SetItemString(d, "Print", (PyObject*)Print_type) < 0) return;
3060 if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return;
3061 if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return;
3062 if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return;
3063 if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return;
3064 if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return;
3065 if (PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) <
3066 0) return;
3067 if (PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) <
3068 0) return;
3069 if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0)
3070 return;
3071 if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0)
3072 return;
3073 if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) <
3074 0) return;
3075 if (PyDict_SetItemString(d, "Exec", (PyObject*)Exec_type) < 0) return;
3076 if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0)
3077 return;
3078 if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return;
3079 if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return;
3080 if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return;
3081 if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0)
3082 return;
3083 if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return;
3084 if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0)
3085 return;
3086 if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return;
3087 if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0)
3088 return;
3089 if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0)
3090 return;
3091 if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return;
3092 if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return;
3093 if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0)
3094 return;
3095 if (PyDict_SetItemString(d, "GeneratorExp",
3096 (PyObject*)GeneratorExp_type) < 0) return;
3097 if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return;
3098 if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0)
3099 return;
3100 if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return;
3101 if (PyDict_SetItemString(d, "Repr", (PyObject*)Repr_type) < 0) return;
3102 if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return;
3103 if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return;
3104 if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) <
3105 0) return;
3106 if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) <
3107 0) return;
3108 if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return;
3109 if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return;
3110 if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return;
3111 if (PyDict_SetItemString(d, "expr_context",
3112 (PyObject*)expr_context_type) < 0) return;
3113 if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return;
3114 if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return;
3115 if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return;
3116 if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0)
3117 return;
3118 if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0)
3119 return;
3120 if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return;
3121 if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return;
3122 if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0)
3123 return;
3124 if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return;
3125 if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0)
3126 return;
3127 if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return;
3128 if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0)
3129 return;
3130 if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return;
3131 if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return;
3132 if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0)
3133 return;
3134 if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return;
3135 if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return;
3136 if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return;
3137 if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return;
3138 if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return;
3139 if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return;
3140 if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0)
3141 return;
3142 if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0)
3143 return;
3144 if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return;
3145 if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0)
3146 return;
3147 if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0)
3148 return;
3149 if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0)
3150 return;
3151 if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0)
3152 return;
3153 if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0)
3154 return;
3155 if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return;
3156 if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return;
3157 if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return;
3158 if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return;
3159 if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return;
3160 if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return;
3161 if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return;
3162 if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return;
3163 if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return;
3164 if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return;
3165 if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return;
3166 if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return;
3167 if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return;
3168 if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return;
3169 if (PyDict_SetItemString(d, "comprehension",
3170 (PyObject*)comprehension_type) < 0) return;
3171 if (PyDict_SetItemString(d, "excepthandler",
3172 (PyObject*)excepthandler_type) < 0) return;
3173 if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) <
3174 0) return;
3175 if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0)
3176 return;
3177 if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return;
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003178}
3179
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003180
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003181PyObject* PyAST_mod2obj(mod_ty t)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003182{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003183 init_types();
3184 return ast2obj_mod(t);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003185}
3186
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003187