blob: 3f8345ebf483107499593052c841e5afd813c61a [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{
384 int i;
385 PyObject *s, *l = PyList_New(num_fields);
386 if (!l) return 0;
387 for(i=0; i < num_fields; i++) {
388 s = PyString_FromString(attrs[i]);
389 if (!s) {
390 Py_DECREF(l);
391 return 0;
392 }
393 PyList_SET_ITEM(l, i, s);
394 }
395 return PyObject_SetAttrString((PyObject*)type, "_attributes", l) >=0;
396}
397
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000398static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
399{
400 int i, n = asdl_seq_LEN(seq);
401 PyObject *result = PyList_New(n);
402 PyObject *value;
403 if (!result)
404 return NULL;
405 for (i = 0; i < n; i++) {
406 value = func(asdl_seq_GET(seq, i));
407 if (!value) {
408 Py_DECREF(result);
409 return NULL;
410 }
411 PyList_SET_ITEM(result, i, value);
412 }
413 return result;
414}
415
416static PyObject* ast2obj_object(void *o)
417{
418 if (!o)
419 o = Py_None;
420 Py_INCREF((PyObject*)o);
421 return (PyObject*)o;
422}
423#define ast2obj_identifier ast2obj_object
424#define ast2obj_string ast2obj_object
425static PyObject* ast2obj_bool(bool b)
426{
427 return PyBool_FromLong(b);
428}
429
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000430static PyObject* ast2obj_int(bool b)
431{
432 return PyInt_FromLong(b);
433}
434
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000435static int initialized;
436static int init_types(void)
437{
438 if (initialized) return 1;
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000439 AST_type = make_type("AST", &PyBaseObject_Type, NULL, 0);
440 mod_type = make_type("mod", AST_type, NULL, 0);
441 if (!mod_type) return 0;
442 if (!add_attributes(mod_type, NULL, 0)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000443 Module_type = make_type("Module", mod_type, Module_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000444 if (!Module_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000445 Interactive_type = make_type("Interactive", mod_type,
446 Interactive_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000447 if (!Interactive_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000448 Expression_type = make_type("Expression", mod_type, Expression_fields,
449 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000450 if (!Expression_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000451 Suite_type = make_type("Suite", mod_type, Suite_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000452 if (!Suite_type) return 0;
453 stmt_type = make_type("stmt", AST_type, NULL, 0);
454 if (!stmt_type) return 0;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000455 if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000456 FunctionDef_type = make_type("FunctionDef", stmt_type,
457 FunctionDef_fields, 4);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000458 if (!FunctionDef_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000459 ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000460 if (!ClassDef_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000461 Return_type = make_type("Return", stmt_type, Return_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000462 if (!Return_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000463 Delete_type = make_type("Delete", stmt_type, Delete_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000464 if (!Delete_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000465 Assign_type = make_type("Assign", stmt_type, Assign_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000466 if (!Assign_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000467 AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000468 if (!AugAssign_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000469 Print_type = make_type("Print", stmt_type, Print_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000470 if (!Print_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000471 For_type = make_type("For", stmt_type, For_fields, 4);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000472 if (!For_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000473 While_type = make_type("While", stmt_type, While_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000474 if (!While_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000475 If_type = make_type("If", stmt_type, If_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000476 if (!If_type) return 0;
Guido van Rossumc2e20742006-02-27 22:32:47 +0000477 With_type = make_type("With", stmt_type, With_fields, 3);
478 if (!With_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000479 Raise_type = make_type("Raise", stmt_type, Raise_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000480 if (!Raise_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000481 TryExcept_type = make_type("TryExcept", stmt_type, TryExcept_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000482 if (!TryExcept_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000483 TryFinally_type = make_type("TryFinally", stmt_type, TryFinally_fields,
484 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000485 if (!TryFinally_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000486 Assert_type = make_type("Assert", stmt_type, Assert_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000487 if (!Assert_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000488 Import_type = make_type("Import", stmt_type, Import_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000489 if (!Import_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000490 ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields,
Thomas Woutersf7f438b2006-02-28 16:09:29 +0000491 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000492 if (!ImportFrom_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000493 Exec_type = make_type("Exec", stmt_type, Exec_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000494 if (!Exec_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000495 Global_type = make_type("Global", stmt_type, Global_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000496 if (!Global_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000497 Expr_type = make_type("Expr", stmt_type, Expr_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000498 if (!Expr_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000499 Pass_type = make_type("Pass", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000500 if (!Pass_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000501 Break_type = make_type("Break", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000502 if (!Break_type) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000503 Continue_type = make_type("Continue", stmt_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000504 if (!Continue_type) return 0;
505 expr_type = make_type("expr", AST_type, NULL, 0);
506 if (!expr_type) return 0;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000507 if (!add_attributes(expr_type, expr_attributes, 2)) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000508 BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000509 if (!BoolOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000510 BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000511 if (!BinOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000512 UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000513 if (!UnaryOp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000514 Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000515 if (!Lambda_type) return 0;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +0000516 IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000517 if (!IfExp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000518 Dict_type = make_type("Dict", expr_type, Dict_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000519 if (!Dict_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000520 ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000521 if (!ListComp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000522 GeneratorExp_type = make_type("GeneratorExp", expr_type,
523 GeneratorExp_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000524 if (!GeneratorExp_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000525 Yield_type = make_type("Yield", expr_type, Yield_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000526 if (!Yield_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000527 Compare_type = make_type("Compare", expr_type, Compare_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000528 if (!Compare_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000529 Call_type = make_type("Call", expr_type, Call_fields, 5);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000530 if (!Call_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000531 Repr_type = make_type("Repr", expr_type, Repr_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000532 if (!Repr_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000533 Num_type = make_type("Num", expr_type, Num_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000534 if (!Num_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000535 Str_type = make_type("Str", expr_type, Str_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000536 if (!Str_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000537 Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000538 if (!Attribute_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000539 Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000540 if (!Subscript_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000541 Name_type = make_type("Name", expr_type, Name_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000542 if (!Name_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000543 List_type = make_type("List", expr_type, List_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000544 if (!List_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000545 Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000546 if (!Tuple_type) return 0;
547 expr_context_type = make_type("expr_context", AST_type, NULL, 0);
548 if (!expr_context_type) return 0;
549 if (!add_attributes(expr_context_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000550 Load_type = make_type("Load", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000551 if (!Load_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000552 Load_singleton = PyType_GenericNew(Load_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000553 if (!Load_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000554 Store_type = make_type("Store", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000555 if (!Store_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000556 Store_singleton = PyType_GenericNew(Store_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000557 if (!Store_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000558 Del_type = make_type("Del", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000559 if (!Del_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000560 Del_singleton = PyType_GenericNew(Del_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000561 if (!Del_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000562 AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000563 if (!AugLoad_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000564 AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000565 if (!AugLoad_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000566 AugStore_type = make_type("AugStore", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000567 if (!AugStore_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000568 AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000569 if (!AugStore_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000570 Param_type = make_type("Param", expr_context_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000571 if (!Param_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000572 Param_singleton = PyType_GenericNew(Param_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000573 if (!Param_singleton) return 0;
574 slice_type = make_type("slice", AST_type, NULL, 0);
575 if (!slice_type) return 0;
576 if (!add_attributes(slice_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000577 Ellipsis_type = make_type("Ellipsis", slice_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000578 if (!Ellipsis_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000579 Slice_type = make_type("Slice", slice_type, Slice_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000580 if (!Slice_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000581 ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000582 if (!ExtSlice_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000583 Index_type = make_type("Index", slice_type, Index_fields, 1);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000584 if (!Index_type) return 0;
585 boolop_type = make_type("boolop", AST_type, NULL, 0);
586 if (!boolop_type) return 0;
587 if (!add_attributes(boolop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000588 And_type = make_type("And", boolop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000589 if (!And_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000590 And_singleton = PyType_GenericNew(And_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000591 if (!And_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000592 Or_type = make_type("Or", boolop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000593 if (!Or_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000594 Or_singleton = PyType_GenericNew(Or_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000595 if (!Or_singleton) return 0;
596 operator_type = make_type("operator", AST_type, NULL, 0);
597 if (!operator_type) return 0;
598 if (!add_attributes(operator_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000599 Add_type = make_type("Add", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000600 if (!Add_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000601 Add_singleton = PyType_GenericNew(Add_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000602 if (!Add_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000603 Sub_type = make_type("Sub", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000604 if (!Sub_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000605 Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000606 if (!Sub_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000607 Mult_type = make_type("Mult", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000608 if (!Mult_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000609 Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000610 if (!Mult_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000611 Div_type = make_type("Div", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000612 if (!Div_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000613 Div_singleton = PyType_GenericNew(Div_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000614 if (!Div_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000615 Mod_type = make_type("Mod", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000616 if (!Mod_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000617 Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000618 if (!Mod_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000619 Pow_type = make_type("Pow", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000620 if (!Pow_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000621 Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000622 if (!Pow_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000623 LShift_type = make_type("LShift", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000624 if (!LShift_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000625 LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000626 if (!LShift_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000627 RShift_type = make_type("RShift", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000628 if (!RShift_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000629 RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000630 if (!RShift_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000631 BitOr_type = make_type("BitOr", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000632 if (!BitOr_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000633 BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000634 if (!BitOr_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000635 BitXor_type = make_type("BitXor", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000636 if (!BitXor_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000637 BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000638 if (!BitXor_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000639 BitAnd_type = make_type("BitAnd", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000640 if (!BitAnd_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000641 BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000642 if (!BitAnd_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000643 FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000644 if (!FloorDiv_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000645 FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000646 if (!FloorDiv_singleton) return 0;
647 unaryop_type = make_type("unaryop", AST_type, NULL, 0);
648 if (!unaryop_type) return 0;
649 if (!add_attributes(unaryop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000650 Invert_type = make_type("Invert", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000651 if (!Invert_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000652 Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000653 if (!Invert_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000654 Not_type = make_type("Not", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000655 if (!Not_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000656 Not_singleton = PyType_GenericNew(Not_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000657 if (!Not_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000658 UAdd_type = make_type("UAdd", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000659 if (!UAdd_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000660 UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000661 if (!UAdd_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000662 USub_type = make_type("USub", unaryop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000663 if (!USub_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000664 USub_singleton = PyType_GenericNew(USub_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000665 if (!USub_singleton) return 0;
666 cmpop_type = make_type("cmpop", AST_type, NULL, 0);
667 if (!cmpop_type) return 0;
668 if (!add_attributes(cmpop_type, NULL, 0)) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000669 Eq_type = make_type("Eq", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000670 if (!Eq_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000671 Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000672 if (!Eq_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000673 NotEq_type = make_type("NotEq", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000674 if (!NotEq_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000675 NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000676 if (!NotEq_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000677 Lt_type = make_type("Lt", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000678 if (!Lt_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000679 Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000680 if (!Lt_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000681 LtE_type = make_type("LtE", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000682 if (!LtE_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000683 LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000684 if (!LtE_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000685 Gt_type = make_type("Gt", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000686 if (!Gt_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000687 Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000688 if (!Gt_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000689 GtE_type = make_type("GtE", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000690 if (!GtE_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000691 GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000692 if (!GtE_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000693 Is_type = make_type("Is", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000694 if (!Is_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000695 Is_singleton = PyType_GenericNew(Is_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000696 if (!Is_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000697 IsNot_type = make_type("IsNot", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000698 if (!IsNot_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000699 IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000700 if (!IsNot_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000701 In_type = make_type("In", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000702 if (!In_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000703 In_singleton = PyType_GenericNew(In_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000704 if (!In_singleton) return 0;
Martin v. Löwis8d0701d2006-02-26 23:40:20 +0000705 NotIn_type = make_type("NotIn", cmpop_type, NULL, 0);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000706 if (!NotIn_type) return 0;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000707 NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000708 if (!NotIn_singleton) return 0;
709 comprehension_type = make_type("comprehension", AST_type,
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000710 comprehension_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000711 if (!comprehension_type) return 0;
712 excepthandler_type = make_type("excepthandler", AST_type,
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000713 excepthandler_fields, 3);
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000714 if (!excepthandler_type) return 0;
715 arguments_type = make_type("arguments", AST_type, arguments_fields, 4);
716 if (!arguments_type) return 0;
717 keyword_type = make_type("keyword", AST_type, keyword_fields, 2);
718 if (!keyword_type) return 0;
719 alias_type = make_type("alias", AST_type, alias_fields, 2);
720 if (!alias_type) return 0;
721 initialized = 1;
722 return 1;
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000723}
Neal Norwitz7b5a6042005-11-13 19:14:20 +0000724
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000725mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000726Module(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000727{
728 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000729 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000730 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000731 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000732 return NULL;
733 }
734 p->kind = Module_kind;
735 p->v.Module.body = body;
736 return p;
737}
738
739mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000740Interactive(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000741{
742 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000743 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000744 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000745 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000746 return NULL;
747 }
748 p->kind = Interactive_kind;
749 p->v.Interactive.body = body;
750 return p;
751}
752
753mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000754Expression(expr_ty body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000755{
756 mod_ty p;
757 if (!body) {
758 PyErr_SetString(PyExc_ValueError,
759 "field body is required for Expression");
760 return NULL;
761 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000762 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000763 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000764 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000765 return NULL;
766 }
767 p->kind = Expression_kind;
768 p->v.Expression.body = body;
769 return p;
770}
771
772mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000773Suite(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000774{
775 mod_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000776 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000777 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000778 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000779 return NULL;
780 }
781 p->kind = Suite_kind;
782 p->v.Suite.body = body;
783 return p;
784}
785
786stmt_ty
787FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000788 decorators, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000789{
790 stmt_ty p;
791 if (!name) {
792 PyErr_SetString(PyExc_ValueError,
793 "field name is required for FunctionDef");
794 return NULL;
795 }
796 if (!args) {
797 PyErr_SetString(PyExc_ValueError,
798 "field args is required for FunctionDef");
799 return NULL;
800 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000801 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000802 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000803 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000804 return NULL;
805 }
806 p->kind = FunctionDef_kind;
807 p->v.FunctionDef.name = name;
808 p->v.FunctionDef.args = args;
809 p->v.FunctionDef.body = body;
810 p->v.FunctionDef.decorators = decorators;
811 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000812 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000813 return p;
814}
815
816stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000817ClassDef(identifier name, asdl_seq * bases, asdl_seq * body, int lineno, int
818 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000819{
820 stmt_ty p;
821 if (!name) {
822 PyErr_SetString(PyExc_ValueError,
823 "field name is required for ClassDef");
824 return NULL;
825 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000826 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000827 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000828 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000829 return NULL;
830 }
831 p->kind = ClassDef_kind;
832 p->v.ClassDef.name = name;
833 p->v.ClassDef.bases = bases;
834 p->v.ClassDef.body = body;
835 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000836 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000837 return p;
838}
839
840stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000841Return(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000842{
843 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000844 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000845 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000846 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000847 return NULL;
848 }
849 p->kind = Return_kind;
850 p->v.Return.value = value;
851 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000852 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000853 return p;
854}
855
856stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000857Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000858{
859 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000860 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000861 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000862 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000863 return NULL;
864 }
865 p->kind = Delete_kind;
866 p->v.Delete.targets = targets;
867 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000868 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000869 return p;
870}
871
872stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000873Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena
874 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000875{
876 stmt_ty p;
877 if (!value) {
878 PyErr_SetString(PyExc_ValueError,
879 "field value is required for Assign");
880 return NULL;
881 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000882 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000883 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000884 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000885 return NULL;
886 }
887 p->kind = Assign_kind;
888 p->v.Assign.targets = targets;
889 p->v.Assign.value = value;
890 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000891 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000892 return p;
893}
894
895stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000896AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
897 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000898{
899 stmt_ty p;
900 if (!target) {
901 PyErr_SetString(PyExc_ValueError,
902 "field target is required for AugAssign");
903 return NULL;
904 }
905 if (!op) {
906 PyErr_SetString(PyExc_ValueError,
907 "field op is required for AugAssign");
908 return NULL;
909 }
910 if (!value) {
911 PyErr_SetString(PyExc_ValueError,
912 "field value is required for AugAssign");
913 return NULL;
914 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000915 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000916 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000917 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000918 return NULL;
919 }
920 p->kind = AugAssign_kind;
921 p->v.AugAssign.target = target;
922 p->v.AugAssign.op = op;
923 p->v.AugAssign.value = value;
924 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000925 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000926 return p;
927}
928
929stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000930Print(expr_ty dest, asdl_seq * values, bool nl, int lineno, int col_offset,
931 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000932{
933 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000934 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000935 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000936 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000937 return NULL;
938 }
939 p->kind = Print_kind;
940 p->v.Print.dest = dest;
941 p->v.Print.values = values;
942 p->v.Print.nl = nl;
943 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000944 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000945 return p;
946}
947
948stmt_ty
949For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000950 lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000951{
952 stmt_ty p;
953 if (!target) {
954 PyErr_SetString(PyExc_ValueError,
955 "field target is required for For");
956 return NULL;
957 }
958 if (!iter) {
959 PyErr_SetString(PyExc_ValueError,
960 "field iter is required for For");
961 return NULL;
962 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000963 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000964 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000965 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000966 return NULL;
967 }
968 p->kind = For_kind;
969 p->v.For.target = target;
970 p->v.For.iter = iter;
971 p->v.For.body = body;
972 p->v.For.orelse = orelse;
973 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000974 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000975 return p;
976}
977
978stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000979While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
980 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000981{
982 stmt_ty p;
983 if (!test) {
984 PyErr_SetString(PyExc_ValueError,
985 "field test is required for While");
986 return NULL;
987 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +0000988 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000989 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +0000990 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000991 return NULL;
992 }
993 p->kind = While_kind;
994 p->v.While.test = test;
995 p->v.While.body = body;
996 p->v.While.orelse = orelse;
997 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +0000998 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000999 return p;
1000}
1001
1002stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001003If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
1004 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001005{
1006 stmt_ty p;
1007 if (!test) {
1008 PyErr_SetString(PyExc_ValueError,
1009 "field test is required for If");
1010 return NULL;
1011 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001012 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001013 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001014 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001015 return NULL;
1016 }
1017 p->kind = If_kind;
1018 p->v.If.test = test;
1019 p->v.If.body = body;
1020 p->v.If.orelse = orelse;
1021 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001022 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001023 return p;
1024}
1025
1026stmt_ty
Guido van Rossumc2e20742006-02-27 22:32:47 +00001027With(expr_ty context_expr, expr_ty optional_vars, asdl_seq * body, int lineno,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001028 int col_offset, PyArena *arena)
Guido van Rossumc2e20742006-02-27 22:32:47 +00001029{
1030 stmt_ty p;
1031 if (!context_expr) {
1032 PyErr_SetString(PyExc_ValueError,
1033 "field context_expr is required for With");
1034 return NULL;
1035 }
1036 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1037 if (!p) {
1038 PyErr_NoMemory();
1039 return NULL;
1040 }
1041 p->kind = With_kind;
1042 p->v.With.context_expr = context_expr;
1043 p->v.With.optional_vars = optional_vars;
1044 p->v.With.body = body;
1045 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001046 p->col_offset = col_offset;
Guido van Rossumc2e20742006-02-27 22:32:47 +00001047 return p;
1048}
1049
1050stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001051Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno, int col_offset,
1052 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001053{
1054 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001055 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001056 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001057 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001058 return NULL;
1059 }
1060 p->kind = Raise_kind;
1061 p->v.Raise.type = type;
1062 p->v.Raise.inst = inst;
1063 p->v.Raise.tback = tback;
1064 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001065 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001066 return p;
1067}
1068
1069stmt_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001070TryExcept(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, int lineno,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001071 int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001072{
1073 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001074 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001075 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001076 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001077 return NULL;
1078 }
1079 p->kind = TryExcept_kind;
1080 p->v.TryExcept.body = body;
1081 p->v.TryExcept.handlers = handlers;
1082 p->v.TryExcept.orelse = orelse;
1083 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001084 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001085 return p;
1086}
1087
1088stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001089TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, int col_offset,
1090 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001091{
1092 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001093 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001094 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001095 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001096 return NULL;
1097 }
1098 p->kind = TryFinally_kind;
1099 p->v.TryFinally.body = body;
1100 p->v.TryFinally.finalbody = finalbody;
1101 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001102 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001103 return p;
1104}
1105
1106stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001107Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001108{
1109 stmt_ty p;
1110 if (!test) {
1111 PyErr_SetString(PyExc_ValueError,
1112 "field test is required for Assert");
1113 return NULL;
1114 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001115 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001116 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001117 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001118 return NULL;
1119 }
1120 p->kind = Assert_kind;
1121 p->v.Assert.test = test;
1122 p->v.Assert.msg = msg;
1123 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001124 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001125 return p;
1126}
1127
1128stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001129Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001130{
1131 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001132 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001133 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001134 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001135 return NULL;
1136 }
1137 p->kind = Import_kind;
1138 p->v.Import.names = names;
1139 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001140 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001141 return p;
1142}
1143
1144stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001145ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int
1146 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001147{
1148 stmt_ty p;
1149 if (!module) {
1150 PyErr_SetString(PyExc_ValueError,
1151 "field module is required for ImportFrom");
1152 return NULL;
1153 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001154 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001155 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001156 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001157 return NULL;
1158 }
1159 p->kind = ImportFrom_kind;
1160 p->v.ImportFrom.module = module;
1161 p->v.ImportFrom.names = names;
Thomas Woutersf7f438b2006-02-28 16:09:29 +00001162 p->v.ImportFrom.level = level;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001163 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001164 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001165 return p;
1166}
1167
1168stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001169Exec(expr_ty body, expr_ty globals, expr_ty locals, int lineno, int col_offset,
1170 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001171{
1172 stmt_ty p;
1173 if (!body) {
1174 PyErr_SetString(PyExc_ValueError,
1175 "field body is required for Exec");
1176 return NULL;
1177 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001178 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001179 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001180 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001181 return NULL;
1182 }
1183 p->kind = Exec_kind;
1184 p->v.Exec.body = body;
1185 p->v.Exec.globals = globals;
1186 p->v.Exec.locals = locals;
1187 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001188 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001189 return p;
1190}
1191
1192stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001193Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001194{
1195 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001196 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001197 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001198 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001199 return NULL;
1200 }
1201 p->kind = Global_kind;
1202 p->v.Global.names = names;
1203 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001204 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001205 return p;
1206}
1207
1208stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001209Expr(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001210{
1211 stmt_ty p;
1212 if (!value) {
1213 PyErr_SetString(PyExc_ValueError,
1214 "field value is required for Expr");
1215 return NULL;
1216 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001217 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001218 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001219 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001220 return NULL;
1221 }
1222 p->kind = Expr_kind;
1223 p->v.Expr.value = value;
1224 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001225 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001226 return p;
1227}
1228
1229stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001230Pass(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001231{
1232 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001233 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001234 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001235 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001236 return NULL;
1237 }
1238 p->kind = Pass_kind;
1239 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001240 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001241 return p;
1242}
1243
1244stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001245Break(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001246{
1247 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001248 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001249 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001250 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001251 return NULL;
1252 }
1253 p->kind = Break_kind;
1254 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001255 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001256 return p;
1257}
1258
1259stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001260Continue(int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001261{
1262 stmt_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001263 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001264 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001265 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001266 return NULL;
1267 }
1268 p->kind = Continue_kind;
1269 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001270 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001271 return p;
1272}
1273
1274expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001275BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena
1276 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001277{
1278 expr_ty p;
1279 if (!op) {
1280 PyErr_SetString(PyExc_ValueError,
1281 "field op is required for BoolOp");
1282 return NULL;
1283 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001284 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001285 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001286 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001287 return NULL;
1288 }
1289 p->kind = BoolOp_kind;
1290 p->v.BoolOp.op = op;
1291 p->v.BoolOp.values = values;
1292 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001293 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001294 return p;
1295}
1296
1297expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001298BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset,
1299 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001300{
1301 expr_ty p;
1302 if (!left) {
1303 PyErr_SetString(PyExc_ValueError,
1304 "field left is required for BinOp");
1305 return NULL;
1306 }
1307 if (!op) {
1308 PyErr_SetString(PyExc_ValueError,
1309 "field op is required for BinOp");
1310 return NULL;
1311 }
1312 if (!right) {
1313 PyErr_SetString(PyExc_ValueError,
1314 "field right is required for BinOp");
1315 return NULL;
1316 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001317 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001318 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001319 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001320 return NULL;
1321 }
1322 p->kind = BinOp_kind;
1323 p->v.BinOp.left = left;
1324 p->v.BinOp.op = op;
1325 p->v.BinOp.right = right;
1326 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001327 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001328 return p;
1329}
1330
1331expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001332UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena
1333 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001334{
1335 expr_ty p;
1336 if (!op) {
1337 PyErr_SetString(PyExc_ValueError,
1338 "field op is required for UnaryOp");
1339 return NULL;
1340 }
1341 if (!operand) {
1342 PyErr_SetString(PyExc_ValueError,
1343 "field operand is required for UnaryOp");
1344 return NULL;
1345 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001346 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001347 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001348 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001349 return NULL;
1350 }
1351 p->kind = UnaryOp_kind;
1352 p->v.UnaryOp.op = op;
1353 p->v.UnaryOp.operand = operand;
1354 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001355 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001356 return p;
1357}
1358
1359expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001360Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena
1361 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001362{
1363 expr_ty p;
1364 if (!args) {
1365 PyErr_SetString(PyExc_ValueError,
1366 "field args is required for Lambda");
1367 return NULL;
1368 }
1369 if (!body) {
1370 PyErr_SetString(PyExc_ValueError,
1371 "field body is required for Lambda");
1372 return NULL;
1373 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001374 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001375 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001376 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001377 return NULL;
1378 }
1379 p->kind = Lambda_kind;
1380 p->v.Lambda.args = args;
1381 p->v.Lambda.body = body;
1382 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001383 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001384 return p;
1385}
1386
1387expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001388IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset,
1389 PyArena *arena)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001390{
1391 expr_ty p;
1392 if (!test) {
1393 PyErr_SetString(PyExc_ValueError,
1394 "field test is required for IfExp");
1395 return NULL;
1396 }
1397 if (!body) {
1398 PyErr_SetString(PyExc_ValueError,
1399 "field body is required for IfExp");
1400 return NULL;
1401 }
1402 if (!orelse) {
1403 PyErr_SetString(PyExc_ValueError,
1404 "field orelse is required for IfExp");
1405 return NULL;
1406 }
1407 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1408 if (!p) {
1409 PyErr_NoMemory();
1410 return NULL;
1411 }
1412 p->kind = IfExp_kind;
1413 p->v.IfExp.test = test;
1414 p->v.IfExp.body = body;
1415 p->v.IfExp.orelse = orelse;
1416 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001417 p->col_offset = col_offset;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00001418 return p;
1419}
1420
1421expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001422Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena
1423 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001424{
1425 expr_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001426 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001427 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001428 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001429 return NULL;
1430 }
1431 p->kind = Dict_kind;
1432 p->v.Dict.keys = keys;
1433 p->v.Dict.values = values;
1434 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001435 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001436 return p;
1437}
1438
1439expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001440ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1441 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001442{
1443 expr_ty p;
1444 if (!elt) {
1445 PyErr_SetString(PyExc_ValueError,
1446 "field elt is required for ListComp");
1447 return NULL;
1448 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001449 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001450 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001451 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001452 return NULL;
1453 }
1454 p->kind = ListComp_kind;
1455 p->v.ListComp.elt = elt;
1456 p->v.ListComp.generators = generators;
1457 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001458 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001459 return p;
1460}
1461
1462expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001463GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
1464 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001465{
1466 expr_ty p;
1467 if (!elt) {
1468 PyErr_SetString(PyExc_ValueError,
1469 "field elt is required for GeneratorExp");
1470 return NULL;
1471 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001472 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001473 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001474 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001475 return NULL;
1476 }
1477 p->kind = GeneratorExp_kind;
1478 p->v.GeneratorExp.elt = elt;
1479 p->v.GeneratorExp.generators = generators;
1480 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001481 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001482 return p;
1483}
1484
1485expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001486Yield(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001487{
1488 expr_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001489 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001490 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001491 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001492 return NULL;
1493 }
1494 p->kind = Yield_kind;
1495 p->v.Yield.value = value;
1496 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001497 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001498 return p;
1499}
1500
1501expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001502Compare(expr_ty left, asdl_seq * ops, asdl_seq * comparators, int lineno, int
1503 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001504{
1505 expr_ty p;
1506 if (!left) {
1507 PyErr_SetString(PyExc_ValueError,
1508 "field left is required for Compare");
1509 return NULL;
1510 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001511 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001512 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001513 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001514 return NULL;
1515 }
1516 p->kind = Compare_kind;
1517 p->v.Compare.left = left;
1518 p->v.Compare.ops = ops;
1519 p->v.Compare.comparators = comparators;
1520 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001521 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001522 return p;
1523}
1524
1525expr_ty
1526Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, expr_ty starargs,
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001527 expr_ty kwargs, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001528{
1529 expr_ty p;
1530 if (!func) {
1531 PyErr_SetString(PyExc_ValueError,
1532 "field func is required for Call");
1533 return NULL;
1534 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001535 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001536 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001537 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001538 return NULL;
1539 }
1540 p->kind = Call_kind;
1541 p->v.Call.func = func;
1542 p->v.Call.args = args;
1543 p->v.Call.keywords = keywords;
1544 p->v.Call.starargs = starargs;
1545 p->v.Call.kwargs = kwargs;
1546 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001547 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001548 return p;
1549}
1550
1551expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001552Repr(expr_ty value, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001553{
1554 expr_ty p;
1555 if (!value) {
1556 PyErr_SetString(PyExc_ValueError,
1557 "field value is required for Repr");
1558 return NULL;
1559 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001560 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001561 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001562 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001563 return NULL;
1564 }
1565 p->kind = Repr_kind;
1566 p->v.Repr.value = value;
1567 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001568 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001569 return p;
1570}
1571
1572expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001573Num(object n, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001574{
1575 expr_ty p;
1576 if (!n) {
1577 PyErr_SetString(PyExc_ValueError,
1578 "field n is required for Num");
1579 return NULL;
1580 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001581 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001582 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001583 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001584 return NULL;
1585 }
1586 p->kind = Num_kind;
1587 p->v.Num.n = n;
1588 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001589 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001590 return p;
1591}
1592
1593expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001594Str(string s, int lineno, int col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001595{
1596 expr_ty p;
1597 if (!s) {
1598 PyErr_SetString(PyExc_ValueError,
1599 "field s is required for Str");
1600 return NULL;
1601 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001602 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001603 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001604 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001605 return NULL;
1606 }
1607 p->kind = Str_kind;
1608 p->v.Str.s = s;
1609 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001610 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001611 return p;
1612}
1613
1614expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001615Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int
1616 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001617{
1618 expr_ty p;
1619 if (!value) {
1620 PyErr_SetString(PyExc_ValueError,
1621 "field value is required for Attribute");
1622 return NULL;
1623 }
1624 if (!attr) {
1625 PyErr_SetString(PyExc_ValueError,
1626 "field attr is required for Attribute");
1627 return NULL;
1628 }
1629 if (!ctx) {
1630 PyErr_SetString(PyExc_ValueError,
1631 "field ctx is required for Attribute");
1632 return NULL;
1633 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001634 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001635 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001636 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001637 return NULL;
1638 }
1639 p->kind = Attribute_kind;
1640 p->v.Attribute.value = value;
1641 p->v.Attribute.attr = attr;
1642 p->v.Attribute.ctx = ctx;
1643 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001644 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001645 return p;
1646}
1647
1648expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001649Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int
1650 col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001651{
1652 expr_ty p;
1653 if (!value) {
1654 PyErr_SetString(PyExc_ValueError,
1655 "field value is required for Subscript");
1656 return NULL;
1657 }
1658 if (!slice) {
1659 PyErr_SetString(PyExc_ValueError,
1660 "field slice is required for Subscript");
1661 return NULL;
1662 }
1663 if (!ctx) {
1664 PyErr_SetString(PyExc_ValueError,
1665 "field ctx is required for Subscript");
1666 return NULL;
1667 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001668 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001669 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001670 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001671 return NULL;
1672 }
1673 p->kind = Subscript_kind;
1674 p->v.Subscript.value = value;
1675 p->v.Subscript.slice = slice;
1676 p->v.Subscript.ctx = ctx;
1677 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001678 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001679 return p;
1680}
1681
1682expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001683Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena
1684 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001685{
1686 expr_ty p;
1687 if (!id) {
1688 PyErr_SetString(PyExc_ValueError,
1689 "field id is required for Name");
1690 return NULL;
1691 }
1692 if (!ctx) {
1693 PyErr_SetString(PyExc_ValueError,
1694 "field ctx is required for Name");
1695 return NULL;
1696 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001697 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001698 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001699 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001700 return NULL;
1701 }
1702 p->kind = Name_kind;
1703 p->v.Name.id = id;
1704 p->v.Name.ctx = ctx;
1705 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001706 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001707 return p;
1708}
1709
1710expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001711List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1712 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001713{
1714 expr_ty p;
1715 if (!ctx) {
1716 PyErr_SetString(PyExc_ValueError,
1717 "field ctx is required for List");
1718 return NULL;
1719 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001720 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001721 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001722 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001723 return NULL;
1724 }
1725 p->kind = List_kind;
1726 p->v.List.elts = elts;
1727 p->v.List.ctx = ctx;
1728 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001729 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001730 return p;
1731}
1732
1733expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001734Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
1735 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001736{
1737 expr_ty p;
1738 if (!ctx) {
1739 PyErr_SetString(PyExc_ValueError,
1740 "field ctx is required for Tuple");
1741 return NULL;
1742 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001743 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001744 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001745 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001746 return NULL;
1747 }
1748 p->kind = Tuple_kind;
1749 p->v.Tuple.elts = elts;
1750 p->v.Tuple.ctx = ctx;
1751 p->lineno = lineno;
Martin v. Löwis49c5da12006-03-01 22:49:05 +00001752 p->col_offset = col_offset;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001753 return p;
1754}
1755
1756slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001757Ellipsis(PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001758{
1759 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001760 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001761 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001762 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001763 return NULL;
1764 }
1765 p->kind = Ellipsis_kind;
1766 return p;
1767}
1768
1769slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001770Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001771{
1772 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001773 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001774 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001775 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001776 return NULL;
1777 }
1778 p->kind = Slice_kind;
1779 p->v.Slice.lower = lower;
1780 p->v.Slice.upper = upper;
1781 p->v.Slice.step = step;
1782 return p;
1783}
1784
1785slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001786ExtSlice(asdl_seq * dims, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001787{
1788 slice_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001789 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001790 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001791 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001792 return NULL;
1793 }
1794 p->kind = ExtSlice_kind;
1795 p->v.ExtSlice.dims = dims;
1796 return p;
1797}
1798
1799slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001800Index(expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001801{
1802 slice_ty p;
1803 if (!value) {
1804 PyErr_SetString(PyExc_ValueError,
1805 "field value is required for Index");
1806 return NULL;
1807 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001808 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001809 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001810 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001811 return NULL;
1812 }
1813 p->kind = Index_kind;
1814 p->v.Index.value = value;
1815 return p;
1816}
1817
1818comprehension_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001819comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001820{
1821 comprehension_ty p;
1822 if (!target) {
1823 PyErr_SetString(PyExc_ValueError,
1824 "field target is required for comprehension");
1825 return NULL;
1826 }
1827 if (!iter) {
1828 PyErr_SetString(PyExc_ValueError,
1829 "field iter is required for comprehension");
1830 return NULL;
1831 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001832 p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001833 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001834 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001835 return NULL;
1836 }
1837 p->target = target;
1838 p->iter = iter;
1839 p->ifs = ifs;
1840 return p;
1841}
1842
1843excepthandler_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001844excepthandler(expr_ty type, expr_ty name, asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001845{
1846 excepthandler_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001847 p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001848 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001849 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001850 return NULL;
1851 }
1852 p->type = type;
1853 p->name = name;
1854 p->body = body;
1855 return p;
1856}
1857
1858arguments_ty
1859arguments(asdl_seq * args, identifier vararg, identifier kwarg, asdl_seq *
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001860 defaults, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001861{
1862 arguments_ty p;
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001863 p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001864 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001865 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001866 return NULL;
1867 }
1868 p->args = args;
1869 p->vararg = vararg;
1870 p->kwarg = kwarg;
1871 p->defaults = defaults;
1872 return p;
1873}
1874
1875keyword_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001876keyword(identifier arg, expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001877{
1878 keyword_ty p;
1879 if (!arg) {
1880 PyErr_SetString(PyExc_ValueError,
1881 "field arg is required for keyword");
1882 return NULL;
1883 }
1884 if (!value) {
1885 PyErr_SetString(PyExc_ValueError,
1886 "field value is required for keyword");
1887 return NULL;
1888 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001889 p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001890 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001891 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001892 return NULL;
1893 }
1894 p->arg = arg;
1895 p->value = value;
1896 return p;
1897}
1898
1899alias_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001900alias(identifier name, identifier asname, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001901{
1902 alias_ty p;
1903 if (!name) {
1904 PyErr_SetString(PyExc_ValueError,
1905 "field name is required for alias");
1906 return NULL;
1907 }
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001908 p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001909 if (!p) {
Neal Norwitz12ebfd72005-10-23 19:22:48 +00001910 PyErr_NoMemory();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001911 return NULL;
1912 }
1913 p->name = name;
1914 p->asname = asname;
1915 return p;
1916}
1917
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001918
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001919PyObject*
1920ast2obj_mod(void* _o)
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001921{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001922 mod_ty o = (mod_ty)_o;
1923 PyObject *result = NULL, *value = NULL;
1924 if (!o) {
1925 Py_INCREF(Py_None);
1926 return Py_None;
1927 }
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001928
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001929 switch (o->kind) {
1930 case Module_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001931 result = PyType_GenericNew(Module_type, NULL, NULL);
1932 if (!result) goto failed;
1933 value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
1934 if (!value) goto failed;
1935 if (PyObject_SetAttrString(result, "body", value) == -1)
1936 goto failed;
1937 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001938 break;
1939 case Interactive_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001940 result = PyType_GenericNew(Interactive_type, NULL, NULL);
1941 if (!result) goto failed;
1942 value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
1943 if (!value) goto failed;
1944 if (PyObject_SetAttrString(result, "body", value) == -1)
1945 goto failed;
1946 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001947 break;
1948 case Expression_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001949 result = PyType_GenericNew(Expression_type, NULL, NULL);
1950 if (!result) goto failed;
1951 value = ast2obj_expr(o->v.Expression.body);
1952 if (!value) goto failed;
1953 if (PyObject_SetAttrString(result, "body", value) == -1)
1954 goto failed;
1955 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001956 break;
1957 case Suite_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001958 result = PyType_GenericNew(Suite_type, NULL, NULL);
1959 if (!result) goto failed;
1960 value = ast2obj_list(o->v.Suite.body, ast2obj_stmt);
1961 if (!value) goto failed;
1962 if (PyObject_SetAttrString(result, "body", value) == -1)
1963 goto failed;
1964 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001965 break;
1966 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001967 return result;
1968failed:
1969 Py_XDECREF(value);
1970 Py_XDECREF(result);
1971 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001972}
1973
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001974PyObject*
1975ast2obj_stmt(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001976{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001977 stmt_ty o = (stmt_ty)_o;
1978 PyObject *result = NULL, *value = NULL;
1979 if (!o) {
1980 Py_INCREF(Py_None);
1981 return Py_None;
1982 }
1983
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001984 switch (o->kind) {
1985 case FunctionDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001986 result = PyType_GenericNew(FunctionDef_type, NULL, NULL);
1987 if (!result) goto failed;
1988 value = ast2obj_identifier(o->v.FunctionDef.name);
1989 if (!value) goto failed;
1990 if (PyObject_SetAttrString(result, "name", value) == -1)
1991 goto failed;
1992 Py_DECREF(value);
1993 value = ast2obj_arguments(o->v.FunctionDef.args);
1994 if (!value) goto failed;
1995 if (PyObject_SetAttrString(result, "args", value) == -1)
1996 goto failed;
1997 Py_DECREF(value);
1998 value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
1999 if (!value) goto failed;
2000 if (PyObject_SetAttrString(result, "body", value) == -1)
2001 goto failed;
2002 Py_DECREF(value);
2003 value = ast2obj_list(o->v.FunctionDef.decorators, ast2obj_expr);
2004 if (!value) goto failed;
2005 if (PyObject_SetAttrString(result, "decorators", value) == -1)
2006 goto failed;
2007 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002008 break;
2009 case ClassDef_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002010 result = PyType_GenericNew(ClassDef_type, NULL, NULL);
2011 if (!result) goto failed;
2012 value = ast2obj_identifier(o->v.ClassDef.name);
2013 if (!value) goto failed;
2014 if (PyObject_SetAttrString(result, "name", value) == -1)
2015 goto failed;
2016 Py_DECREF(value);
2017 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
2018 if (!value) goto failed;
2019 if (PyObject_SetAttrString(result, "bases", value) == -1)
2020 goto failed;
2021 Py_DECREF(value);
2022 value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
2023 if (!value) goto failed;
2024 if (PyObject_SetAttrString(result, "body", value) == -1)
2025 goto failed;
2026 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002027 break;
2028 case Return_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002029 result = PyType_GenericNew(Return_type, NULL, NULL);
2030 if (!result) goto failed;
2031 value = ast2obj_expr(o->v.Return.value);
2032 if (!value) goto failed;
2033 if (PyObject_SetAttrString(result, "value", value) == -1)
2034 goto failed;
2035 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002036 break;
2037 case Delete_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002038 result = PyType_GenericNew(Delete_type, NULL, NULL);
2039 if (!result) goto failed;
2040 value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
2041 if (!value) goto failed;
2042 if (PyObject_SetAttrString(result, "targets", value) == -1)
2043 goto failed;
2044 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002045 break;
2046 case Assign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002047 result = PyType_GenericNew(Assign_type, NULL, NULL);
2048 if (!result) goto failed;
2049 value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
2050 if (!value) goto failed;
2051 if (PyObject_SetAttrString(result, "targets", value) == -1)
2052 goto failed;
2053 Py_DECREF(value);
2054 value = ast2obj_expr(o->v.Assign.value);
2055 if (!value) goto failed;
2056 if (PyObject_SetAttrString(result, "value", value) == -1)
2057 goto failed;
2058 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002059 break;
2060 case AugAssign_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002061 result = PyType_GenericNew(AugAssign_type, NULL, NULL);
2062 if (!result) goto failed;
2063 value = ast2obj_expr(o->v.AugAssign.target);
2064 if (!value) goto failed;
2065 if (PyObject_SetAttrString(result, "target", value) == -1)
2066 goto failed;
2067 Py_DECREF(value);
2068 value = ast2obj_operator(o->v.AugAssign.op);
2069 if (!value) goto failed;
2070 if (PyObject_SetAttrString(result, "op", value) == -1)
2071 goto failed;
2072 Py_DECREF(value);
2073 value = ast2obj_expr(o->v.AugAssign.value);
2074 if (!value) goto failed;
2075 if (PyObject_SetAttrString(result, "value", value) == -1)
2076 goto failed;
2077 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002078 break;
2079 case Print_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002080 result = PyType_GenericNew(Print_type, NULL, NULL);
2081 if (!result) goto failed;
2082 value = ast2obj_expr(o->v.Print.dest);
2083 if (!value) goto failed;
2084 if (PyObject_SetAttrString(result, "dest", value) == -1)
2085 goto failed;
2086 Py_DECREF(value);
2087 value = ast2obj_list(o->v.Print.values, ast2obj_expr);
2088 if (!value) goto failed;
2089 if (PyObject_SetAttrString(result, "values", value) == -1)
2090 goto failed;
2091 Py_DECREF(value);
2092 value = ast2obj_bool(o->v.Print.nl);
2093 if (!value) goto failed;
2094 if (PyObject_SetAttrString(result, "nl", value) == -1)
2095 goto failed;
2096 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002097 break;
2098 case For_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002099 result = PyType_GenericNew(For_type, NULL, NULL);
2100 if (!result) goto failed;
2101 value = ast2obj_expr(o->v.For.target);
2102 if (!value) goto failed;
2103 if (PyObject_SetAttrString(result, "target", value) == -1)
2104 goto failed;
2105 Py_DECREF(value);
2106 value = ast2obj_expr(o->v.For.iter);
2107 if (!value) goto failed;
2108 if (PyObject_SetAttrString(result, "iter", value) == -1)
2109 goto failed;
2110 Py_DECREF(value);
2111 value = ast2obj_list(o->v.For.body, ast2obj_stmt);
2112 if (!value) goto failed;
2113 if (PyObject_SetAttrString(result, "body", value) == -1)
2114 goto failed;
2115 Py_DECREF(value);
2116 value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
2117 if (!value) goto failed;
2118 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2119 goto failed;
2120 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002121 break;
2122 case While_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002123 result = PyType_GenericNew(While_type, NULL, NULL);
2124 if (!result) goto failed;
2125 value = ast2obj_expr(o->v.While.test);
2126 if (!value) goto failed;
2127 if (PyObject_SetAttrString(result, "test", value) == -1)
2128 goto failed;
2129 Py_DECREF(value);
2130 value = ast2obj_list(o->v.While.body, ast2obj_stmt);
2131 if (!value) goto failed;
2132 if (PyObject_SetAttrString(result, "body", value) == -1)
2133 goto failed;
2134 Py_DECREF(value);
2135 value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);
2136 if (!value) goto failed;
2137 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2138 goto failed;
2139 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002140 break;
2141 case If_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002142 result = PyType_GenericNew(If_type, NULL, NULL);
2143 if (!result) goto failed;
2144 value = ast2obj_expr(o->v.If.test);
2145 if (!value) goto failed;
2146 if (PyObject_SetAttrString(result, "test", value) == -1)
2147 goto failed;
2148 Py_DECREF(value);
2149 value = ast2obj_list(o->v.If.body, ast2obj_stmt);
2150 if (!value) goto failed;
2151 if (PyObject_SetAttrString(result, "body", value) == -1)
2152 goto failed;
2153 Py_DECREF(value);
2154 value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
2155 if (!value) goto failed;
2156 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2157 goto failed;
2158 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002159 break;
Guido van Rossumc2e20742006-02-27 22:32:47 +00002160 case With_kind:
2161 result = PyType_GenericNew(With_type, NULL, NULL);
2162 if (!result) goto failed;
2163 value = ast2obj_expr(o->v.With.context_expr);
2164 if (!value) goto failed;
2165 if (PyObject_SetAttrString(result, "context_expr", value) == -1)
2166 goto failed;
2167 Py_DECREF(value);
2168 value = ast2obj_expr(o->v.With.optional_vars);
2169 if (!value) goto failed;
2170 if (PyObject_SetAttrString(result, "optional_vars", value) ==
2171 -1)
2172 goto failed;
2173 Py_DECREF(value);
2174 value = ast2obj_list(o->v.With.body, ast2obj_stmt);
2175 if (!value) goto failed;
2176 if (PyObject_SetAttrString(result, "body", value) == -1)
2177 goto failed;
2178 Py_DECREF(value);
2179 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002180 case Raise_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002181 result = PyType_GenericNew(Raise_type, NULL, NULL);
2182 if (!result) goto failed;
2183 value = ast2obj_expr(o->v.Raise.type);
2184 if (!value) goto failed;
2185 if (PyObject_SetAttrString(result, "type", value) == -1)
2186 goto failed;
2187 Py_DECREF(value);
2188 value = ast2obj_expr(o->v.Raise.inst);
2189 if (!value) goto failed;
2190 if (PyObject_SetAttrString(result, "inst", value) == -1)
2191 goto failed;
2192 Py_DECREF(value);
2193 value = ast2obj_expr(o->v.Raise.tback);
2194 if (!value) goto failed;
2195 if (PyObject_SetAttrString(result, "tback", value) == -1)
2196 goto failed;
2197 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002198 break;
2199 case TryExcept_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002200 result = PyType_GenericNew(TryExcept_type, NULL, NULL);
2201 if (!result) goto failed;
2202 value = ast2obj_list(o->v.TryExcept.body, ast2obj_stmt);
2203 if (!value) goto failed;
2204 if (PyObject_SetAttrString(result, "body", value) == -1)
2205 goto failed;
2206 Py_DECREF(value);
2207 value = ast2obj_list(o->v.TryExcept.handlers,
2208 ast2obj_excepthandler);
2209 if (!value) goto failed;
2210 if (PyObject_SetAttrString(result, "handlers", value) == -1)
2211 goto failed;
2212 Py_DECREF(value);
2213 value = ast2obj_list(o->v.TryExcept.orelse, ast2obj_stmt);
2214 if (!value) goto failed;
2215 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2216 goto failed;
2217 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002218 break;
2219 case TryFinally_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002220 result = PyType_GenericNew(TryFinally_type, NULL, NULL);
2221 if (!result) goto failed;
2222 value = ast2obj_list(o->v.TryFinally.body, ast2obj_stmt);
2223 if (!value) goto failed;
2224 if (PyObject_SetAttrString(result, "body", value) == -1)
2225 goto failed;
2226 Py_DECREF(value);
2227 value = ast2obj_list(o->v.TryFinally.finalbody, ast2obj_stmt);
2228 if (!value) goto failed;
2229 if (PyObject_SetAttrString(result, "finalbody", value) == -1)
2230 goto failed;
2231 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002232 break;
2233 case Assert_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002234 result = PyType_GenericNew(Assert_type, NULL, NULL);
2235 if (!result) goto failed;
2236 value = ast2obj_expr(o->v.Assert.test);
2237 if (!value) goto failed;
2238 if (PyObject_SetAttrString(result, "test", value) == -1)
2239 goto failed;
2240 Py_DECREF(value);
2241 value = ast2obj_expr(o->v.Assert.msg);
2242 if (!value) goto failed;
2243 if (PyObject_SetAttrString(result, "msg", value) == -1)
2244 goto failed;
2245 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002246 break;
2247 case Import_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002248 result = PyType_GenericNew(Import_type, NULL, NULL);
2249 if (!result) goto failed;
2250 value = ast2obj_list(o->v.Import.names, ast2obj_alias);
2251 if (!value) goto failed;
2252 if (PyObject_SetAttrString(result, "names", value) == -1)
2253 goto failed;
2254 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002255 break;
2256 case ImportFrom_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002257 result = PyType_GenericNew(ImportFrom_type, NULL, NULL);
2258 if (!result) goto failed;
2259 value = ast2obj_identifier(o->v.ImportFrom.module);
2260 if (!value) goto failed;
2261 if (PyObject_SetAttrString(result, "module", value) == -1)
2262 goto failed;
2263 Py_DECREF(value);
2264 value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
2265 if (!value) goto failed;
2266 if (PyObject_SetAttrString(result, "names", value) == -1)
2267 goto failed;
2268 Py_DECREF(value);
Thomas Woutersf7f438b2006-02-28 16:09:29 +00002269 value = ast2obj_int(o->v.ImportFrom.level);
2270 if (!value) goto failed;
2271 if (PyObject_SetAttrString(result, "level", value) == -1)
2272 goto failed;
2273 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002274 break;
2275 case Exec_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002276 result = PyType_GenericNew(Exec_type, NULL, NULL);
2277 if (!result) goto failed;
2278 value = ast2obj_expr(o->v.Exec.body);
2279 if (!value) goto failed;
2280 if (PyObject_SetAttrString(result, "body", value) == -1)
2281 goto failed;
2282 Py_DECREF(value);
2283 value = ast2obj_expr(o->v.Exec.globals);
2284 if (!value) goto failed;
2285 if (PyObject_SetAttrString(result, "globals", value) == -1)
2286 goto failed;
2287 Py_DECREF(value);
2288 value = ast2obj_expr(o->v.Exec.locals);
2289 if (!value) goto failed;
2290 if (PyObject_SetAttrString(result, "locals", value) == -1)
2291 goto failed;
2292 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002293 break;
2294 case Global_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002295 result = PyType_GenericNew(Global_type, NULL, NULL);
2296 if (!result) goto failed;
2297 value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
2298 if (!value) goto failed;
2299 if (PyObject_SetAttrString(result, "names", value) == -1)
2300 goto failed;
2301 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002302 break;
2303 case Expr_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002304 result = PyType_GenericNew(Expr_type, NULL, NULL);
2305 if (!result) goto failed;
2306 value = ast2obj_expr(o->v.Expr.value);
2307 if (!value) goto failed;
2308 if (PyObject_SetAttrString(result, "value", value) == -1)
2309 goto failed;
2310 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002311 break;
2312 case Pass_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002313 result = PyType_GenericNew(Pass_type, NULL, NULL);
2314 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002315 break;
2316 case Break_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002317 result = PyType_GenericNew(Break_type, NULL, NULL);
2318 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002319 break;
2320 case Continue_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002321 result = PyType_GenericNew(Continue_type, NULL, NULL);
2322 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002323 break;
2324 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002325 value = ast2obj_int(o->lineno);
2326 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002327 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2328 goto failed;
2329 Py_DECREF(value);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002330 value = ast2obj_int(o->col_offset);
2331 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002332 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2333 goto failed;
2334 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002335 return result;
2336failed:
2337 Py_XDECREF(value);
2338 Py_XDECREF(result);
2339 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002340}
2341
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002342PyObject*
2343ast2obj_expr(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002344{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002345 expr_ty o = (expr_ty)_o;
2346 PyObject *result = NULL, *value = NULL;
2347 if (!o) {
2348 Py_INCREF(Py_None);
2349 return Py_None;
2350 }
2351
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002352 switch (o->kind) {
2353 case BoolOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002354 result = PyType_GenericNew(BoolOp_type, NULL, NULL);
2355 if (!result) goto failed;
2356 value = ast2obj_boolop(o->v.BoolOp.op);
2357 if (!value) goto failed;
2358 if (PyObject_SetAttrString(result, "op", value) == -1)
2359 goto failed;
2360 Py_DECREF(value);
2361 value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
2362 if (!value) goto failed;
2363 if (PyObject_SetAttrString(result, "values", value) == -1)
2364 goto failed;
2365 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002366 break;
2367 case BinOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002368 result = PyType_GenericNew(BinOp_type, NULL, NULL);
2369 if (!result) goto failed;
2370 value = ast2obj_expr(o->v.BinOp.left);
2371 if (!value) goto failed;
2372 if (PyObject_SetAttrString(result, "left", value) == -1)
2373 goto failed;
2374 Py_DECREF(value);
2375 value = ast2obj_operator(o->v.BinOp.op);
2376 if (!value) goto failed;
2377 if (PyObject_SetAttrString(result, "op", value) == -1)
2378 goto failed;
2379 Py_DECREF(value);
2380 value = ast2obj_expr(o->v.BinOp.right);
2381 if (!value) goto failed;
2382 if (PyObject_SetAttrString(result, "right", value) == -1)
2383 goto failed;
2384 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002385 break;
2386 case UnaryOp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002387 result = PyType_GenericNew(UnaryOp_type, NULL, NULL);
2388 if (!result) goto failed;
2389 value = ast2obj_unaryop(o->v.UnaryOp.op);
2390 if (!value) goto failed;
2391 if (PyObject_SetAttrString(result, "op", value) == -1)
2392 goto failed;
2393 Py_DECREF(value);
2394 value = ast2obj_expr(o->v.UnaryOp.operand);
2395 if (!value) goto failed;
2396 if (PyObject_SetAttrString(result, "operand", value) == -1)
2397 goto failed;
2398 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002399 break;
2400 case Lambda_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002401 result = PyType_GenericNew(Lambda_type, NULL, NULL);
2402 if (!result) goto failed;
2403 value = ast2obj_arguments(o->v.Lambda.args);
2404 if (!value) goto failed;
2405 if (PyObject_SetAttrString(result, "args", value) == -1)
2406 goto failed;
2407 Py_DECREF(value);
2408 value = ast2obj_expr(o->v.Lambda.body);
2409 if (!value) goto failed;
2410 if (PyObject_SetAttrString(result, "body", value) == -1)
2411 goto failed;
2412 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002413 break;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002414 case IfExp_kind:
2415 result = PyType_GenericNew(IfExp_type, NULL, NULL);
2416 if (!result) goto failed;
2417 value = ast2obj_expr(o->v.IfExp.test);
2418 if (!value) goto failed;
2419 if (PyObject_SetAttrString(result, "test", value) == -1)
2420 goto failed;
2421 Py_DECREF(value);
2422 value = ast2obj_expr(o->v.IfExp.body);
2423 if (!value) goto failed;
2424 if (PyObject_SetAttrString(result, "body", value) == -1)
2425 goto failed;
2426 Py_DECREF(value);
2427 value = ast2obj_expr(o->v.IfExp.orelse);
2428 if (!value) goto failed;
2429 if (PyObject_SetAttrString(result, "orelse", value) == -1)
2430 goto failed;
2431 Py_DECREF(value);
2432 break;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002433 case Dict_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002434 result = PyType_GenericNew(Dict_type, NULL, NULL);
2435 if (!result) goto failed;
2436 value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
2437 if (!value) goto failed;
2438 if (PyObject_SetAttrString(result, "keys", value) == -1)
2439 goto failed;
2440 Py_DECREF(value);
2441 value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
2442 if (!value) goto failed;
2443 if (PyObject_SetAttrString(result, "values", value) == -1)
2444 goto failed;
2445 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002446 break;
2447 case ListComp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002448 result = PyType_GenericNew(ListComp_type, NULL, NULL);
2449 if (!result) goto failed;
2450 value = ast2obj_expr(o->v.ListComp.elt);
2451 if (!value) goto failed;
2452 if (PyObject_SetAttrString(result, "elt", value) == -1)
2453 goto failed;
2454 Py_DECREF(value);
2455 value = ast2obj_list(o->v.ListComp.generators,
2456 ast2obj_comprehension);
2457 if (!value) goto failed;
2458 if (PyObject_SetAttrString(result, "generators", value) == -1)
2459 goto failed;
2460 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002461 break;
2462 case GeneratorExp_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002463 result = PyType_GenericNew(GeneratorExp_type, NULL, NULL);
2464 if (!result) goto failed;
2465 value = ast2obj_expr(o->v.GeneratorExp.elt);
2466 if (!value) goto failed;
2467 if (PyObject_SetAttrString(result, "elt", value) == -1)
2468 goto failed;
2469 Py_DECREF(value);
2470 value = ast2obj_list(o->v.GeneratorExp.generators,
2471 ast2obj_comprehension);
2472 if (!value) goto failed;
2473 if (PyObject_SetAttrString(result, "generators", value) == -1)
2474 goto failed;
2475 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002476 break;
2477 case Yield_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002478 result = PyType_GenericNew(Yield_type, NULL, NULL);
2479 if (!result) goto failed;
2480 value = ast2obj_expr(o->v.Yield.value);
2481 if (!value) goto failed;
2482 if (PyObject_SetAttrString(result, "value", value) == -1)
2483 goto failed;
2484 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002485 break;
2486 case Compare_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002487 result = PyType_GenericNew(Compare_type, NULL, NULL);
2488 if (!result) goto failed;
2489 value = ast2obj_expr(o->v.Compare.left);
2490 if (!value) goto failed;
2491 if (PyObject_SetAttrString(result, "left", value) == -1)
2492 goto failed;
2493 Py_DECREF(value);
Martin v. Löwisce1d5d22006-02-26 20:51:25 +00002494 {
2495 int i, n = asdl_seq_LEN(o->v.Compare.ops);
2496 value = PyList_New(n);
2497 if (!value) goto failed;
2498 for(i = 0; i < n; i++)
2499 PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
2500 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002501 if (!value) goto failed;
2502 if (PyObject_SetAttrString(result, "ops", value) == -1)
2503 goto failed;
2504 Py_DECREF(value);
2505 value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
2506 if (!value) goto failed;
2507 if (PyObject_SetAttrString(result, "comparators", value) == -1)
2508 goto failed;
2509 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002510 break;
2511 case Call_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002512 result = PyType_GenericNew(Call_type, NULL, NULL);
2513 if (!result) goto failed;
2514 value = ast2obj_expr(o->v.Call.func);
2515 if (!value) goto failed;
2516 if (PyObject_SetAttrString(result, "func", value) == -1)
2517 goto failed;
2518 Py_DECREF(value);
2519 value = ast2obj_list(o->v.Call.args, ast2obj_expr);
2520 if (!value) goto failed;
2521 if (PyObject_SetAttrString(result, "args", value) == -1)
2522 goto failed;
2523 Py_DECREF(value);
2524 value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
2525 if (!value) goto failed;
2526 if (PyObject_SetAttrString(result, "keywords", value) == -1)
2527 goto failed;
2528 Py_DECREF(value);
2529 value = ast2obj_expr(o->v.Call.starargs);
2530 if (!value) goto failed;
2531 if (PyObject_SetAttrString(result, "starargs", value) == -1)
2532 goto failed;
2533 Py_DECREF(value);
2534 value = ast2obj_expr(o->v.Call.kwargs);
2535 if (!value) goto failed;
2536 if (PyObject_SetAttrString(result, "kwargs", value) == -1)
2537 goto failed;
2538 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002539 break;
2540 case Repr_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002541 result = PyType_GenericNew(Repr_type, NULL, NULL);
2542 if (!result) goto failed;
2543 value = ast2obj_expr(o->v.Repr.value);
2544 if (!value) goto failed;
2545 if (PyObject_SetAttrString(result, "value", value) == -1)
2546 goto failed;
2547 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002548 break;
2549 case Num_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002550 result = PyType_GenericNew(Num_type, NULL, NULL);
2551 if (!result) goto failed;
2552 value = ast2obj_object(o->v.Num.n);
2553 if (!value) goto failed;
2554 if (PyObject_SetAttrString(result, "n", value) == -1)
2555 goto failed;
2556 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002557 break;
2558 case Str_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002559 result = PyType_GenericNew(Str_type, NULL, NULL);
2560 if (!result) goto failed;
2561 value = ast2obj_string(o->v.Str.s);
2562 if (!value) goto failed;
2563 if (PyObject_SetAttrString(result, "s", value) == -1)
2564 goto failed;
2565 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002566 break;
2567 case Attribute_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002568 result = PyType_GenericNew(Attribute_type, NULL, NULL);
2569 if (!result) goto failed;
2570 value = ast2obj_expr(o->v.Attribute.value);
2571 if (!value) goto failed;
2572 if (PyObject_SetAttrString(result, "value", value) == -1)
2573 goto failed;
2574 Py_DECREF(value);
2575 value = ast2obj_identifier(o->v.Attribute.attr);
2576 if (!value) goto failed;
2577 if (PyObject_SetAttrString(result, "attr", value) == -1)
2578 goto failed;
2579 Py_DECREF(value);
2580 value = ast2obj_expr_context(o->v.Attribute.ctx);
2581 if (!value) goto failed;
2582 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2583 goto failed;
2584 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002585 break;
2586 case Subscript_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002587 result = PyType_GenericNew(Subscript_type, NULL, NULL);
2588 if (!result) goto failed;
2589 value = ast2obj_expr(o->v.Subscript.value);
2590 if (!value) goto failed;
2591 if (PyObject_SetAttrString(result, "value", value) == -1)
2592 goto failed;
2593 Py_DECREF(value);
2594 value = ast2obj_slice(o->v.Subscript.slice);
2595 if (!value) goto failed;
2596 if (PyObject_SetAttrString(result, "slice", value) == -1)
2597 goto failed;
2598 Py_DECREF(value);
2599 value = ast2obj_expr_context(o->v.Subscript.ctx);
2600 if (!value) goto failed;
2601 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2602 goto failed;
2603 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002604 break;
2605 case Name_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002606 result = PyType_GenericNew(Name_type, NULL, NULL);
2607 if (!result) goto failed;
2608 value = ast2obj_identifier(o->v.Name.id);
2609 if (!value) goto failed;
2610 if (PyObject_SetAttrString(result, "id", value) == -1)
2611 goto failed;
2612 Py_DECREF(value);
2613 value = ast2obj_expr_context(o->v.Name.ctx);
2614 if (!value) goto failed;
2615 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2616 goto failed;
2617 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002618 break;
2619 case List_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002620 result = PyType_GenericNew(List_type, NULL, NULL);
2621 if (!result) goto failed;
2622 value = ast2obj_list(o->v.List.elts, ast2obj_expr);
2623 if (!value) goto failed;
2624 if (PyObject_SetAttrString(result, "elts", value) == -1)
2625 goto failed;
2626 Py_DECREF(value);
2627 value = ast2obj_expr_context(o->v.List.ctx);
2628 if (!value) goto failed;
2629 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2630 goto failed;
2631 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002632 break;
2633 case Tuple_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002634 result = PyType_GenericNew(Tuple_type, NULL, NULL);
2635 if (!result) goto failed;
2636 value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
2637 if (!value) goto failed;
2638 if (PyObject_SetAttrString(result, "elts", value) == -1)
2639 goto failed;
2640 Py_DECREF(value);
2641 value = ast2obj_expr_context(o->v.Tuple.ctx);
2642 if (!value) goto failed;
2643 if (PyObject_SetAttrString(result, "ctx", value) == -1)
2644 goto failed;
2645 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002646 break;
2647 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00002648 value = ast2obj_int(o->lineno);
2649 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002650 if (PyObject_SetAttrString(result, "lineno", value) < 0)
2651 goto failed;
2652 Py_DECREF(value);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002653 value = ast2obj_int(o->col_offset);
2654 if (!value) goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00002655 if (PyObject_SetAttrString(result, "col_offset", value) < 0)
2656 goto failed;
2657 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002658 return result;
2659failed:
2660 Py_XDECREF(value);
2661 Py_XDECREF(result);
2662 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002663}
2664
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002665PyObject* ast2obj_expr_context(expr_context_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002666{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002667 switch(o) {
2668 case Load:
2669 Py_INCREF(Load_singleton);
2670 return Load_singleton;
2671 case Store:
2672 Py_INCREF(Store_singleton);
2673 return Store_singleton;
2674 case Del:
2675 Py_INCREF(Del_singleton);
2676 return Del_singleton;
2677 case AugLoad:
2678 Py_INCREF(AugLoad_singleton);
2679 return AugLoad_singleton;
2680 case AugStore:
2681 Py_INCREF(AugStore_singleton);
2682 return AugStore_singleton;
2683 case Param:
2684 Py_INCREF(Param_singleton);
2685 return Param_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002686 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002687 return NULL; /* cannot happen */
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002688}
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002689PyObject*
2690ast2obj_slice(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002691{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002692 slice_ty o = (slice_ty)_o;
2693 PyObject *result = NULL, *value = NULL;
2694 if (!o) {
2695 Py_INCREF(Py_None);
2696 return Py_None;
2697 }
2698
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002699 switch (o->kind) {
2700 case Ellipsis_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002701 result = PyType_GenericNew(Ellipsis_type, NULL, NULL);
2702 if (!result) goto failed;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002703 break;
2704 case Slice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002705 result = PyType_GenericNew(Slice_type, NULL, NULL);
2706 if (!result) goto failed;
2707 value = ast2obj_expr(o->v.Slice.lower);
2708 if (!value) goto failed;
2709 if (PyObject_SetAttrString(result, "lower", value) == -1)
2710 goto failed;
2711 Py_DECREF(value);
2712 value = ast2obj_expr(o->v.Slice.upper);
2713 if (!value) goto failed;
2714 if (PyObject_SetAttrString(result, "upper", value) == -1)
2715 goto failed;
2716 Py_DECREF(value);
2717 value = ast2obj_expr(o->v.Slice.step);
2718 if (!value) goto failed;
2719 if (PyObject_SetAttrString(result, "step", value) == -1)
2720 goto failed;
2721 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002722 break;
2723 case ExtSlice_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002724 result = PyType_GenericNew(ExtSlice_type, NULL, NULL);
2725 if (!result) goto failed;
2726 value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice);
2727 if (!value) goto failed;
2728 if (PyObject_SetAttrString(result, "dims", value) == -1)
2729 goto failed;
2730 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002731 break;
2732 case Index_kind:
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002733 result = PyType_GenericNew(Index_type, NULL, NULL);
2734 if (!result) goto failed;
2735 value = ast2obj_expr(o->v.Index.value);
2736 if (!value) goto failed;
2737 if (PyObject_SetAttrString(result, "value", value) == -1)
2738 goto failed;
2739 Py_DECREF(value);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002740 break;
2741 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002742 return result;
2743failed:
2744 Py_XDECREF(value);
2745 Py_XDECREF(result);
2746 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002747}
2748
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002749PyObject* ast2obj_boolop(boolop_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002750{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002751 switch(o) {
2752 case And:
2753 Py_INCREF(And_singleton);
2754 return And_singleton;
2755 case Or:
2756 Py_INCREF(Or_singleton);
2757 return Or_singleton;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002758 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002759 return NULL; /* cannot happen */
2760}
2761PyObject* ast2obj_operator(operator_ty o)
2762{
2763 switch(o) {
2764 case Add:
2765 Py_INCREF(Add_singleton);
2766 return Add_singleton;
2767 case Sub:
2768 Py_INCREF(Sub_singleton);
2769 return Sub_singleton;
2770 case Mult:
2771 Py_INCREF(Mult_singleton);
2772 return Mult_singleton;
2773 case Div:
2774 Py_INCREF(Div_singleton);
2775 return Div_singleton;
2776 case Mod:
2777 Py_INCREF(Mod_singleton);
2778 return Mod_singleton;
2779 case Pow:
2780 Py_INCREF(Pow_singleton);
2781 return Pow_singleton;
2782 case LShift:
2783 Py_INCREF(LShift_singleton);
2784 return LShift_singleton;
2785 case RShift:
2786 Py_INCREF(RShift_singleton);
2787 return RShift_singleton;
2788 case BitOr:
2789 Py_INCREF(BitOr_singleton);
2790 return BitOr_singleton;
2791 case BitXor:
2792 Py_INCREF(BitXor_singleton);
2793 return BitXor_singleton;
2794 case BitAnd:
2795 Py_INCREF(BitAnd_singleton);
2796 return BitAnd_singleton;
2797 case FloorDiv:
2798 Py_INCREF(FloorDiv_singleton);
2799 return FloorDiv_singleton;
2800 }
2801 return NULL; /* cannot happen */
2802}
2803PyObject* ast2obj_unaryop(unaryop_ty o)
2804{
2805 switch(o) {
2806 case Invert:
2807 Py_INCREF(Invert_singleton);
2808 return Invert_singleton;
2809 case Not:
2810 Py_INCREF(Not_singleton);
2811 return Not_singleton;
2812 case UAdd:
2813 Py_INCREF(UAdd_singleton);
2814 return UAdd_singleton;
2815 case USub:
2816 Py_INCREF(USub_singleton);
2817 return USub_singleton;
2818 }
2819 return NULL; /* cannot happen */
2820}
2821PyObject* ast2obj_cmpop(cmpop_ty o)
2822{
2823 switch(o) {
2824 case Eq:
2825 Py_INCREF(Eq_singleton);
2826 return Eq_singleton;
2827 case NotEq:
2828 Py_INCREF(NotEq_singleton);
2829 return NotEq_singleton;
2830 case Lt:
2831 Py_INCREF(Lt_singleton);
2832 return Lt_singleton;
2833 case LtE:
2834 Py_INCREF(LtE_singleton);
2835 return LtE_singleton;
2836 case Gt:
2837 Py_INCREF(Gt_singleton);
2838 return Gt_singleton;
2839 case GtE:
2840 Py_INCREF(GtE_singleton);
2841 return GtE_singleton;
2842 case Is:
2843 Py_INCREF(Is_singleton);
2844 return Is_singleton;
2845 case IsNot:
2846 Py_INCREF(IsNot_singleton);
2847 return IsNot_singleton;
2848 case In:
2849 Py_INCREF(In_singleton);
2850 return In_singleton;
2851 case NotIn:
2852 Py_INCREF(NotIn_singleton);
2853 return NotIn_singleton;
2854 }
2855 return NULL; /* cannot happen */
2856}
2857PyObject*
2858ast2obj_comprehension(void* _o)
2859{
2860 comprehension_ty o = (comprehension_ty)_o;
2861 PyObject *result = NULL, *value = NULL;
2862 if (!o) {
2863 Py_INCREF(Py_None);
2864 return Py_None;
2865 }
2866
2867 result = PyType_GenericNew(comprehension_type, NULL, NULL);
2868 if (!result) return NULL;
2869 value = ast2obj_expr(o->target);
2870 if (!value) goto failed;
2871 if (PyObject_SetAttrString(result, "target", value) == -1)
2872 goto failed;
2873 Py_DECREF(value);
2874 value = ast2obj_expr(o->iter);
2875 if (!value) goto failed;
2876 if (PyObject_SetAttrString(result, "iter", value) == -1)
2877 goto failed;
2878 Py_DECREF(value);
2879 value = ast2obj_list(o->ifs, ast2obj_expr);
2880 if (!value) goto failed;
2881 if (PyObject_SetAttrString(result, "ifs", value) == -1)
2882 goto failed;
2883 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002884 return result;
2885failed:
2886 Py_XDECREF(value);
2887 Py_XDECREF(result);
2888 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002889}
2890
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002891PyObject*
2892ast2obj_excepthandler(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002893{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002894 excepthandler_ty o = (excepthandler_ty)_o;
2895 PyObject *result = NULL, *value = NULL;
2896 if (!o) {
2897 Py_INCREF(Py_None);
2898 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002899 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002900
2901 result = PyType_GenericNew(excepthandler_type, NULL, NULL);
2902 if (!result) return NULL;
2903 value = ast2obj_expr(o->type);
2904 if (!value) goto failed;
2905 if (PyObject_SetAttrString(result, "type", value) == -1)
2906 goto failed;
2907 Py_DECREF(value);
2908 value = ast2obj_expr(o->name);
2909 if (!value) goto failed;
2910 if (PyObject_SetAttrString(result, "name", value) == -1)
2911 goto failed;
2912 Py_DECREF(value);
2913 value = ast2obj_list(o->body, ast2obj_stmt);
2914 if (!value) goto failed;
2915 if (PyObject_SetAttrString(result, "body", value) == -1)
2916 goto failed;
2917 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002918 return result;
2919failed:
2920 Py_XDECREF(value);
2921 Py_XDECREF(result);
2922 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002923}
2924
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002925PyObject*
2926ast2obj_arguments(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002927{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002928 arguments_ty o = (arguments_ty)_o;
2929 PyObject *result = NULL, *value = NULL;
2930 if (!o) {
2931 Py_INCREF(Py_None);
2932 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002933 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002934
2935 result = PyType_GenericNew(arguments_type, NULL, NULL);
2936 if (!result) return NULL;
2937 value = ast2obj_list(o->args, ast2obj_expr);
2938 if (!value) goto failed;
2939 if (PyObject_SetAttrString(result, "args", value) == -1)
2940 goto failed;
2941 Py_DECREF(value);
2942 value = ast2obj_identifier(o->vararg);
2943 if (!value) goto failed;
2944 if (PyObject_SetAttrString(result, "vararg", value) == -1)
2945 goto failed;
2946 Py_DECREF(value);
2947 value = ast2obj_identifier(o->kwarg);
2948 if (!value) goto failed;
2949 if (PyObject_SetAttrString(result, "kwarg", value) == -1)
2950 goto failed;
2951 Py_DECREF(value);
2952 value = ast2obj_list(o->defaults, ast2obj_expr);
2953 if (!value) goto failed;
2954 if (PyObject_SetAttrString(result, "defaults", value) == -1)
2955 goto failed;
2956 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002957 return result;
2958failed:
2959 Py_XDECREF(value);
2960 Py_XDECREF(result);
2961 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002962}
2963
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002964PyObject*
2965ast2obj_keyword(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002966{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002967 keyword_ty o = (keyword_ty)_o;
2968 PyObject *result = NULL, *value = NULL;
2969 if (!o) {
2970 Py_INCREF(Py_None);
2971 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002972 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002973
2974 result = PyType_GenericNew(keyword_type, NULL, NULL);
2975 if (!result) return NULL;
2976 value = ast2obj_identifier(o->arg);
2977 if (!value) goto failed;
2978 if (PyObject_SetAttrString(result, "arg", value) == -1)
2979 goto failed;
2980 Py_DECREF(value);
2981 value = ast2obj_expr(o->value);
2982 if (!value) goto failed;
2983 if (PyObject_SetAttrString(result, "value", value) == -1)
2984 goto failed;
2985 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002986 return result;
2987failed:
2988 Py_XDECREF(value);
2989 Py_XDECREF(result);
2990 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002991}
2992
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002993PyObject*
2994ast2obj_alias(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002995{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002996 alias_ty o = (alias_ty)_o;
2997 PyObject *result = NULL, *value = NULL;
2998 if (!o) {
2999 Py_INCREF(Py_None);
3000 return Py_None;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003001 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003002
3003 result = PyType_GenericNew(alias_type, NULL, NULL);
3004 if (!result) return NULL;
3005 value = ast2obj_identifier(o->name);
3006 if (!value) goto failed;
3007 if (PyObject_SetAttrString(result, "name", value) == -1)
3008 goto failed;
3009 Py_DECREF(value);
3010 value = ast2obj_identifier(o->asname);
3011 if (!value) goto failed;
3012 if (PyObject_SetAttrString(result, "asname", value) == -1)
3013 goto failed;
3014 Py_DECREF(value);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003015 return result;
3016failed:
3017 Py_XDECREF(value);
3018 Py_XDECREF(result);
3019 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003020}
3021
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003022
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003023PyMODINIT_FUNC
3024init_ast(void)
3025{
3026 PyObject *m, *d;
3027 if (!init_types()) return;
3028 m = Py_InitModule3("_ast", NULL, NULL);
3029 if (!m) return;
3030 d = PyModule_GetDict(m);
3031 if (PyDict_SetItemString(d, "AST", (PyObject*)AST_type) < 0) return;
3032 if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)
3033 return;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00003034 if (PyModule_AddStringConstant(m, "__version__", "42753") < 0)
Martin v. Löwisace990c2006-02-28 00:32:31 +00003035 return;
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003036 if(PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return;
3037 if(PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0)
3038 return;
3039 if(PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type)
3040 < 0) return;
3041 if(PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) <
3042 0) return;
3043 if(PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return;
3044 if(PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return;
3045 if(PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type)
3046 < 0) return;
3047 if(PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0)
3048 return;
3049 if(PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0)
3050 return;
3051 if(PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0)
3052 return;
3053 if(PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0)
3054 return;
3055 if(PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) < 0)
3056 return;
3057 if(PyDict_SetItemString(d, "Print", (PyObject*)Print_type) < 0) return;
3058 if(PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return;
3059 if(PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return;
3060 if(PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return;
Guido van Rossumc2e20742006-02-27 22:32:47 +00003061 if(PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return;
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003062 if(PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return;
3063 if(PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) < 0)
3064 return;
3065 if(PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) <
3066 0) return;
3067 if(PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0)
3068 return;
3069 if(PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0)
3070 return;
3071 if(PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) <
3072 0) return;
3073 if(PyDict_SetItemString(d, "Exec", (PyObject*)Exec_type) < 0) return;
3074 if(PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0)
3075 return;
3076 if(PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return;
3077 if(PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return;
3078 if(PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return;
3079 if(PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0)
3080 return;
3081 if(PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return;
3082 if(PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0)
3083 return;
3084 if(PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return;
3085 if(PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0)
3086 return;
3087 if(PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0)
3088 return;
3089 if(PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return;
3090 if(PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return;
3091 if(PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0)
3092 return;
3093 if(PyDict_SetItemString(d, "GeneratorExp",
3094 (PyObject*)GeneratorExp_type) < 0) return;
3095 if(PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return;
3096 if(PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0)
3097 return;
3098 if(PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return;
3099 if(PyDict_SetItemString(d, "Repr", (PyObject*)Repr_type) < 0) return;
3100 if(PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return;
3101 if(PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return;
3102 if(PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) < 0)
3103 return;
3104 if(PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) < 0)
3105 return;
3106 if(PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return;
3107 if(PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return;
3108 if(PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return;
3109 if(PyDict_SetItemString(d, "expr_context",
3110 (PyObject*)expr_context_type) < 0) return;
3111 if(PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return;
3112 if(PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return;
3113 if(PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return;
3114 if(PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0)
3115 return;
3116 if(PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0)
3117 return;
3118 if(PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return;
3119 if(PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return;
3120 if(PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0)
3121 return;
3122 if(PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return;
3123 if(PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0)
3124 return;
3125 if(PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return;
3126 if(PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0)
3127 return;
3128 if(PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return;
3129 if(PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return;
3130 if(PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0)
3131 return;
3132 if(PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return;
3133 if(PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return;
3134 if(PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return;
3135 if(PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return;
3136 if(PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return;
3137 if(PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return;
3138 if(PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0)
3139 return;
3140 if(PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0)
3141 return;
3142 if(PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return;
3143 if(PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0)
3144 return;
3145 if(PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0)
3146 return;
3147 if(PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0)
3148 return;
3149 if(PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0)
3150 return;
3151 if(PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0)
3152 return;
3153 if(PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return;
3154 if(PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return;
3155 if(PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return;
3156 if(PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return;
3157 if(PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return;
3158 if(PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return;
3159 if(PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return;
3160 if(PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return;
3161 if(PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return;
3162 if(PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return;
3163 if(PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return;
3164 if(PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return;
3165 if(PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return;
3166 if(PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return;
3167 if(PyDict_SetItemString(d, "comprehension",
3168 (PyObject*)comprehension_type) < 0) return;
3169 if(PyDict_SetItemString(d, "excepthandler",
3170 (PyObject*)excepthandler_type) < 0) return;
3171 if(PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) < 0)
3172 return;
3173 if(PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0)
3174 return;
3175 if(PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return;
3176}
3177
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003178
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003179PyObject* PyAST_mod2obj(mod_ty t)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003180{
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003181 init_types();
3182 return ast2obj_mod(t);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003183}
3184
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003185